-//
-// FileSystem.cs
-//
-// Authors:
-//
-// Daniel Campos ( danielcampos@netcourrier.com )
-// Rafael Teixeira (rafaelteixeirabr@hotmail.com)
-//
-//
+/*
+ * Copyright (c) 2002-2003 Mainsoft Corporation.
+ * Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
using System;
using System.IO;
+using System.Text;
+using System.Collections;
using System.Globalization;
+using Microsoft.VisualBasic;
+using System.Runtime.InteropServices;
using Microsoft.VisualBasic.CompilerServices;
-namespace Microsoft.VisualBasic
+/**
+ * CURRENT LIMITATIONS
+ * @limit TAB(int) - not supported.
+ * @limit not all file attributes are supported. supported are: Hidden, Directory, ReadOnly
+ * @limit ChDir(..) - not supported.
+ * @limit ChDrive - not supported.
+ * @limit CurDir(Char) - ignores the parameter.
+ */
+
+namespace Microsoft.VisualBasic
{
- [StandardModuleAttribute]
- sealed public class FileSystem {
- private static FileStream [] FHandle = new FileStream [255];
- private static OpenMode [] FMode= new OpenMode [255];
- private static string InitialPath = Environment.CurrentDirectory;
- // Declarations
- // Constructors
- // Properties
- // Methods
- [MonoTODO("If path is another drive, it should change the default folder for that drive, but not switch to it.")]
- public static void ChDir (string Path)
+ [StandardModuleAttribute]
+ sealed public class FileSystem
+ {
+ private FileSystem () {}
+
+ private static Hashtable _fileNameIdMap = new Hashtable();
+ private static Hashtable _openFilesMap = new Hashtable();
+ private static Hashtable _randomRecordLength = new Hashtable();
+
+ static String _pattern;
+ static int _fileAttrs;
+ private static int _fileIndex;
+ private static FileInfo[] _files;
+ private static bool _isEndOfFiles = true;
+
+
+ public static void Reset()
{
- if ((Path=="") || (Path==null))
- throw new ArgumentException (Utils.GetResourceString ("Argument_PathNullOrEmpty"));
- try {
- Environment.CurrentDirectory = Path;
- }
- catch {
- throw new FileNotFoundException (Utils.GetResourceString ("FileSystem_PathNotFound1", Path));
- }
- }
-
- public static void ChDrive (char Drive)
- {
- Console.WriteLine("SWITCHING TO: " + Drive);
- Drive = Char.ToUpper (Drive, CultureInfo.InvariantCulture);
-
- if( (Drive < 65) || (Drive > 90) ) {
- throw new FileNotFoundException (Utils.GetResourceString ("Argument_InvalidValue1", "Drive"));
- }
-
- try {
- string path = Drive.ToString() + Path.VolumeSeparatorChar.ToString();
- Environment.CurrentDirectory = path;
- }
- catch {
- throw new FileNotFoundException (Utils.GetResourceString("Argument_InvalidValue1", "Drive"));
- }
- }
-
- public static void ChDrive (string Drive)
- {
- if (Drive != null && Drive.Length != 0)
- ChDrive(Drive[0]);
- }
-
- public static string CurDir()
- {
- return Environment.CurrentDirectory;
+ ICollection s = _openFilesMap.Keys;
+
+ int [] iArr = new int[s.Count];
+ s.CopyTo(iArr, 0);
+ close(iArr);
}
-
- [MonoTODO("Needs Testing for other drives")]
- public static string CurDir (char Drive)
+
+ public static void FileClose(int[] fileNumbers)
{
- bool ok = false;
- string myDrive = (Drive.ToString ()).ToLower ();
- string [] buf= Directory.GetLogicalDrives ();
- for (int lookfor = 0;lookfor < buf.Length || !ok; lookfor++) {
- if (buf [lookfor].Substring (0,1).ToLower () == myDrive)
- ok = true;
+ int[] iArr = null;
+ if (fileNumbers.Length == 0)
+ {
+ ICollection keySet = FileSystem._openFilesMap.Keys;
+ iArr = new int[keySet.Count];
+ keySet.CopyTo(iArr, 0);
}
- if (!ok)
- throw new System.ArgumentException (Utils.GetResourceString ("Argument_InvalidValue1", "Drive"));
- if (Environment.CurrentDirectory.Substring (0,1).ToLower () == myDrive)
- return Environment.CurrentDirectory;
else
{
- // TODO: not right. It should return the complete directory of another drive.
- if (InitialPath.Substring (0,1).ToLower () == myDrive)
- return InitialPath;
- else
- return (myDrive.ToUpper () + Path.VolumeSeparatorChar + Path.DirectorySeparatorChar);
+ iArr = new int[fileNumbers.Length];
+ for (int i = 0; i < fileNumbers.Length; i++)
+ iArr[i] = fileNumbers[i];
}
+ close(iArr);
}
-
- private class FileFinder {
- public string Pathname;
- public FileAttribute Attributes;
- public FileFinder(string pathname, FileAttribute attributes) {
- Pathname = pathname;
- Attributes = attributes;
- }
+ private static void close(int [] keys)
+ {
+ Object obj;
- public string Next() {
- return "";
- }
- }
+ for (int i = 0; i < keys.Length; i++)
+ {
+ if (keys[i] < 0 || keys[i] > 255)
+ {
+ ExceptionUtils.VbMakeException(
+ VBErrors.IllegalFuncCall);
+ throw new ArgumentOutOfRangeException();
+ }
+ obj = _openFilesMap[keys[i]];
- private static FileFinder CurrentFileFinder = null;
+ if (obj == null)
+ {
+ String message = VBUtils.GetResourceString(52);
+ throw (IOException)VBUtils.VBException(new IOException(message), 52);
+ }
+ String fileName = null;
+ if (obj is VBFile)
+ {
+ ((VBFile)obj).closeFile();
+ fileName = ((VBFile)obj).getFullPath();
+ }
- [MonoTODO]
- public static System.String Dir (
- System.String Pathname,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(0)]
- Microsoft.VisualBasic.FileAttribute Attributes) {
- CurrentFileFinder = new FileFinder(Pathname, Attributes);
- return Dir();
+
+ _openFilesMap.Remove(keys[i]);
+ _fileNameIdMap.Remove(fileName);
+ }
}
- [MonoTODO]
- public static System.String Dir () {
- if (CurrentFileFinder == null)
- throw new ArgumentException();
- string filename = CurrentFileFinder.Next();
- if (filename == "")
- CurrentFileFinder = null; // to cause an error next time
- return filename;
- }
-
-
- [MonoTODO("Needs testing")]
- public static void MkDir (System.String Path)
- {
- // if a file called like 'path' does exist
- // no exception is generated using .net
- // A little extrange?
- if (Path==null || Path=="")
+ public static void FileOpen(
+ int fileNumber,
+ String fileName,
+ OpenMode mode,
+ [Optional, __DefaultArgumentValue((int)(-1))] OpenAccess access,
+ [Optional, __DefaultArgumentValue((int)(-1))] OpenShare share,
+ [Optional, __DefaultArgumentValue(-1)] int recordLength)
+
+ {
+ if (!isFileNumberFree(fileNumber))
+ throw ExceptionUtils.VbMakeException(VBErrors.FileAlreadyOpen);
+ if (fileNumber < 0 || fileNumber > 255)
+ throw ExceptionUtils.VbMakeException(VBErrors.BadFileNameOrNumber);
+ if (recordLength != -1 && recordLength <= 0)
+ throw ExceptionUtils.VbMakeException(VBErrors.IllegalFuncCall);
+ if (share != OpenShare.Shared && _fileNameIdMap.ContainsKey(Path.GetFullPath(string.Intern(fileName))))
+ throw ExceptionUtils.VbMakeException(VBErrors.FileAlreadyOpen);
+ if (mode == OpenMode.Input)
{
- throw new System.ArgumentException();
+ VBFile vbFile = new InputVBFile(fileName, (FileAccess) access,(recordLength == -1)? 4096:recordLength);
+ _openFilesMap.Add(fileNumber, vbFile);
}
- else
+ else if (mode == OpenMode.Output || mode == OpenMode.Append)
{
- if (System.IO.Directory.Exists (Path))
- throw new System.IO.IOException("Directory already exists");
- else
- System.IO.Directory.CreateDirectory(Path);
+ VBFile vbFile = new OutPutVBFile(fileName,mode,access,recordLength);
+ _openFilesMap.Add(fileNumber, vbFile);
+ }
+ else if (mode == OpenMode.Random)
+ {
+ VBFile vbFile = new RandomVBFile(fileName,mode,access,recordLength);
+ _openFilesMap.Add(fileNumber, vbFile);
+ }
+ else if (mode == OpenMode.Binary)
+ {
+ VBFile vbFile = new BinaryVBFile(fileName,mode,access,recordLength);
+ _openFilesMap.Add(fileNumber, vbFile);
}
+ _fileNameIdMap.Add(Path.GetFullPath(string.Intern(fileName)),fileNumber);
}
-
- [MonoTODO("Needs testing")]
- public static void RmDir (System.String Path)
- {
- System.IO.Directory.Delete(Path);
+
+ public static void FilePut(int fileNumber,
+ bool value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+ {
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber);
}
-
- [MonoTODO("Needs testing")]
- public static void FileCopy (System.String Source, System.String Destination)
- {
- // using VB, filecopy always overwrites Destination
- System.IO.File.Copy(Source,Destination,true);
+
+
+ public static void FilePut(int fileNumber,
+ byte value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+ {
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber);
}
-
- [MonoTODO("Needs testing")]
- public static System.DateTime FileDateTime (System.String PathName)
+
+ public static void FilePut(int fileNumber,
+ short value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
{
- // A better exception handling is needed : exceptions
- // are not the same as 'GetLastWriteTime'
- return System.IO.File.GetLastWriteTime (PathName);
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber);
}
-
- [MonoTODO("Needs Testing")]
- public static System.Int64 FileLen(System.String PathName)
+
+
+ public static void FilePut(int fileNumber,
+ char value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
{
- FileInfo MyFile=new FileInfo(PathName);
- if ( !MyFile.Exists )
- throw new System.ArgumentException(PathName + " does not exists");
- return (System.Int64)MyFile.Length;
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber);
}
- [MonoTODO]
- public static Microsoft.VisualBasic.FileAttribute GetAttr (System.String PathName) {
- throw new NotImplementedException ();
+
+ public static void FilePut(int fileNumber,
+ int value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+ {
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber);
}
-
- [MonoTODO("Needs testing")]
- public static void Kill (System.String PathName)
+
+ public static void FilePut(int fileNumber,
+ long value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
{
- if (!System.IO.File.Exists(PathName))
- throw new System.IO.FileNotFoundException();
- else
- System.IO.File.Delete(PathName);
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber);
}
-
- [MonoTODO]
- public static void SetAttr (System.String PathName, Microsoft.VisualBasic.FileAttribute Attributes) {
- throw new NotImplementedException ();
- }
-
- [MonoTODO("Needs testing")]
- public static void FileOpen (System.Int32 FileNumber,
- System.String FileName,
- Microsoft.VisualBasic.OpenMode Mode,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] Microsoft.VisualBasic.OpenAccess Access,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] Microsoft.VisualBasic.OpenShare Share,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int32 RecordLength)
- {
- // at this moment you can open a file
- // only for Append, Input or Output
- System.IO.FileMode MyMode;
- System.IO.FileAccess MyAccess;
- System.IO.FileShare MyShare;
- //
- // exceptions
- //
- if ( RecordLength < -1 )
- throw new System.ArgumentException("Record Length is negative (nad not equal to -1)");
- if ( RecordLength > 32767)
- throw new System.ArgumentException ("Invalid Record Length");
- if (FileNumber <0 || FileNumber > 255)
- throw new System.IO.IOException(FileNumber.ToString() + " is invalid (<-1 or >255)",5);
- if ( (Mode == OpenMode.Output) && ( Access != OpenAccess.Default ) && ( Access != OpenAccess.Write ) )
- throw new System.ArgumentException("To use Output Mode, you have to use OpenAccess.Write or OpenAccess.Default");
- if ( (Mode == OpenMode.Input) && ( Access != OpenAccess.Default ) && ( Access != OpenAccess.Read ) )
- throw new System.ArgumentException("To use Input Mode, you have to use OpenAccess.Read or OpenAccess.Default");
- //
- // implementation
- //
- FileNumber--;
- if (FHandle[FileNumber] != null)
- throw new System.IO.IOException (FileNumber.ToString() + " is in use",5);
-
- switch (Mode) {
- case Microsoft.VisualBasic.OpenMode.Append :
- MyMode=System.IO.FileMode.Append ;
- break;
- case Microsoft.VisualBasic.OpenMode.Binary :
- throw new NotImplementedException ();
-
- case Microsoft.VisualBasic.OpenMode.Input :
- MyMode=System.IO.FileMode.Open ;
- break;
- case Microsoft.VisualBasic.OpenMode.Output :
- MyMode=System.IO.FileMode.OpenOrCreate ;
- break;
- case Microsoft.VisualBasic.OpenMode.Random :
- throw new NotImplementedException ();
- default:
- throw new System.ArgumentException("Invalid Share");
- }
- switch (Access) {
- case Microsoft.VisualBasic.OpenAccess.ReadWrite :
- case Microsoft.VisualBasic.OpenAccess.Default :
- MyAccess=System.IO.FileAccess.ReadWrite;
- break;
- case Microsoft.VisualBasic.OpenAccess.Read :
- MyAccess=System.IO.FileAccess.Read;
- break;
- case Microsoft.VisualBasic.OpenAccess.Write :
- MyAccess=System.IO.FileAccess.Write;
- break;
- default:
- throw new System.ArgumentException("Invalid Access");
-
- }
- switch(Share) {
- case Microsoft.VisualBasic.OpenShare.Default :
- case Microsoft.VisualBasic.OpenShare.Shared :
- MyShare=System.IO.FileShare.ReadWrite ;
- break;
- case Microsoft.VisualBasic.OpenShare.LockRead :
- MyShare=System.IO.FileShare.Write;
- break;
- case Microsoft.VisualBasic.OpenShare.LockReadWrite :
- MyShare=System.IO.FileShare.None ;
- break;
- case Microsoft.VisualBasic.OpenShare.LockWrite :
- MyShare=System.IO.FileShare.Read;
- break;
- default:
- throw new System.ArgumentException("Invalid Share");
- }
+ public static void FilePut(int fileNumber,
+ float value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+ {
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber);
+ }
- FHandle[FileNumber]=new System.IO.FileStream (FileName,MyMode,MyAccess,MyShare);
- FMode[FileNumber]=Mode;
+ public static void FilePut(int fileNumber,
+ double value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+ {
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber);
}
-
- [MonoTODO("Needs testing")]
- public static void FileClose (params System.Int32[] FileNumbers)
- {
- int bucle=0;
- if (FileNumbers.Length == 0)
- Microsoft.VisualBasic.FileSystem.Reset();
- else {
- for(bucle=0;bucle<FileNumbers.Length;bucle++) {
- if ( FHandle [ FileNumbers[bucle] - 1 ] != null ) {
- if (FileNumbers[bucle]>0 && FileNumbers[bucle]<256) {
- try {
- FHandle[ FileNumbers[bucle] - 1].Close();
- FHandle[ FileNumbers[bucle] - 1]=null;
- }
- catch (Exception e){e.GetType (); FHandle[ FileNumbers[bucle] - 1]= null ;}
- }
- else
- throw new System.IO.IOException (FileNumbers[bucle].ToString() + " Does not exist",52);
- }
- else
- throw new System.IO.IOException (FileNumbers[bucle].ToString() + " Does not exist",52);
- }
- }
- }
- [MonoTODO]
- public static void FileGetObject (System.Int32 FileNumber,
- ref System.Object Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.ValueType Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.Array Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(false)] ref System.Boolean ArrayIsDynamic,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(false)] ref System.Boolean StringIsFixedLength)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.Boolean Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
- {
- throw new NotImplementedException ();
+ public static void FilePut(int fileNumber,
+ String value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber,
+ [Optional, __DefaultArgumentValue(false)] bool stringIsFixedLength)
+ {
+ checkRecordNumber(recordNumber,true);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber,stringIsFixedLength);
}
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.Byte Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.Int16 Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
+ public static void FilePut(int fileNumber,
+ DateTime value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber);
}
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.Int32 Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
+
+ private static void checkRecordNumber(long recordNumber,bool throwArgExc)
{
- throw new NotImplementedException ();
+ if ((recordNumber < 1) && (recordNumber != -1))
+ {
+ if (!throwArgExc)
+ throw (IOException) ExceptionUtils.VbMakeException(
+ new ArgumentException(
+ Utils.GetResourceString(
+ "Argument_InvalidValue1",
+ "RecordNumber")),
+ VBErrors.BadRecordNum);
+ else
+ {
+ ExceptionUtils.VbMakeException(VBErrors.BadRecordNum);
+ throw new ArgumentException(
+ Utils.GetResourceString(
+ "Argument_InvalidValue1",
+ "RecordNumber"));
+ }
+
+ }
}
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.Int64 Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
+
+ private static VBFile getVBFile(int fileNumber)
{
- throw new NotImplementedException ();
+ if ((fileNumber < 1) || (fileNumber > 255))
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.BadFileNameOrNumber);
+ Object obj = _openFilesMap[fileNumber];
+ if (obj == null)
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.BadFileNameOrNumber);
+ return (VBFile)obj;
}
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.Char Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
+
+ private static VBFile getVBFile(String pathName)
+ {
+ object o = _fileNameIdMap[pathName];
+ int fileNumber = o == null ? 0 : (int) o ;
+ if (fileNumber == 0)
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.BadFileNameOrNumber);
+ Object obj = _openFilesMap[fileNumber];
+ if (obj == null)
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.BadFileNameOrNumber);
+ return (VBFile)obj;
+ }
+
+ public static void FileGet(
+ int fileNumber,
+ ref byte value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(out value,recordNumber);
}
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.Single Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
+
+ public static void FileGet(
+ int fileNumber,
+ ref bool value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(out value,recordNumber);
}
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.Double Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
+
+ public static void FileGet(
+ int fileNumber,
+ ref short value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(out value,recordNumber);
}
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.Decimal Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
+
+ public static void FileGet(
+ int fileNumber,
+ ref char value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+
+
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(out value,recordNumber);
}
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.String Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(false)] ref System.Boolean StringIsFixedLength)
+
+
+ public static void FileGet(
+ int fileNumber,
+ ref int value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(out value,recordNumber);
}
-
- [MonoTODO]
- public static void FileGet (System.Int32 FileNumber,
- ref System.DateTime Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] ref System.Int64 RecordNumber)
+
+ public static void FileGet(
+ int fileNumber,
+ ref long value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(out value,recordNumber);
}
-
- [MonoTODO]
- public static void FilePutObject (System.Int32 FileNumber,
- System.Object Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static void FileGet(
+ int fileNumber,
+ ref float value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(out value,recordNumber);
}
-
- [MonoTODO]
- [System.ObsoleteAttribute("Use FilePutObject to write Object types, or coerce FileNumber and RecordNumber to Integer for writing non-Object types", false)]
- public static void FilePut (System.Object FileNumber,
- System.Object Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Object RecordNumber)
+
+ public static void FileGet(
+ int fileNumber,
+ ref double value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(out value,recordNumber);
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.ValueType Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static void FileGet(
+ int fileNumber,
+ ref Decimal value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,false);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(out value,recordNumber);
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.Array Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(false)] System.Boolean ArrayIsDynamic,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(false)] System.Boolean StringIsFixedLength)
- {
- throw new NotImplementedException ();
- }
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.Boolean Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static void FileGet(
+ int fileNumber,
+ ref string value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber,
+ [Optional, __DefaultArgumentValue(false)] bool stringIsFixedLength)
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,true);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(ref value,recordNumber,stringIsFixedLength);
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.Byte Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static void FileGet(
+ int fileNumber,
+ ref DateTime value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,true);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(out value,recordNumber);
}
-
+
[MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.Int16 Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+ public static void FileGet(
+ int fileNumber,
+ ref ValueType value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
{
- throw new NotImplementedException ();
+ throw new NotImplementedException();
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.Int32 Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static void FileGet(
+ int fileNumber,
+ ref Array value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber,
+ [Optional, __DefaultArgumentValue(false)] bool arrayIsDynamic,
+ [Optional, __DefaultArgumentValue(false)] bool stringIsFixedLength)
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,true);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.get(ref value,recordNumber,arrayIsDynamic,stringIsFixedLength);
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.Int64 Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static long Seek(int fileNumber)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+ return vbFile.seek();
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.Char Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static void Seek(int fileNumber, long position)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.seek(position);
+
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.Single Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static long Loc(int fileNumber)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+ return vbFile.getPosition();
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.Double Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static long LOF(int fileNumber)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+ return vbFile.getLength();
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.Decimal Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static void Input(int fileNumber, ref Object value)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+ if (value != null)
+ {
+ if (value is bool) {
+ bool tmp;
+ vbFile.Input(out tmp);
+ value = tmp;
+ }
+ else if (value is byte) {
+ byte tmp;
+ vbFile.Input(out tmp);
+ value = tmp;
+ }
+ else if (value is char) {
+ char tmp;
+ vbFile.Input(out tmp);
+ value = tmp;
+ }
+ else if (value is double) {
+ double tmp;
+ vbFile.Input(out tmp);
+ value = tmp;
+ }
+ else if (value is short) {
+ short tmp;
+ vbFile.Input(out tmp);
+ value = tmp;
+ }
+ else if (value is int) {
+ int tmp;
+ vbFile.Input(out tmp);
+ value = tmp;
+ }
+ else if (value is long) {
+ long tmp;
+ vbFile.Input(out tmp);
+ value = tmp;
+ }
+ else if (value is float) {
+ float tmp;
+ vbFile.Input(out tmp);
+ value = tmp;
+ }
+ else if (value is Decimal) {
+ Decimal tmp;
+ vbFile.Input(out tmp);
+ value = tmp;
+ }
+ else if (value is string)
+ vbFile.Input((string)value);
+ // Come back to it later
+ // else if (type.get_IsByRef())
+ // vbFile.Input((ObjectRefWrapper)value[i],false);
+
+ }
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.String Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(false)] System.Boolean StringIsFixedLength)
+
+ public static String InputString(int fileNumber, int count)
{
- throw new NotImplementedException ();
+ if (count < 0)
+ throw (ArgumentException)ExceptionUtils.VbMakeException(VBErrors.IllegalFuncCall);
+ VBFile vbFile = getVBFile(fileNumber);
+ if (vbFile.getLength()- vbFile.getPosition() < count)
+ throw (EndOfStreamException)ExceptionUtils.VbMakeException(VBErrors.EndOfFile);
+ return vbFile.InputString(count);
}
-
- [MonoTODO]
- public static void FilePut (System.Int32 FileNumber,
- System.DateTime Value,
- [System.Runtime.InteropServices.Optional]
- [System.ComponentModel.DefaultValue(-1)] System.Int64 RecordNumber)
+
+ public static String LineInput(int fileNumber)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+
+ if (EOF(fileNumber))
+ throw new EndOfStreamException("Input past end of file.");
+
+ return vbFile.readLine();
}
-
- [MonoTODO]
- public static void Print (System.Int32 FileNumber,
- params System.Object[] Output)
+
+ public static void Print(int fileNumber, Object[] output)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.print(output);
}
-
- [MonoTODO]
- public static void PrintLine (System.Int32 FileNumber,
- params System.Object[] Output)
+
+// Seems not to exist in MS's 1.1 implementation as told by class status pages
+// public static void PrintLine(int fileNumber)
+// {
+// VBFile vbFile = getVBFile(fileNumber);
+// vbFile.printLine(null);
+// }
+
+ public static void PrintLine(int fileNumber, Object[] output)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.printLine(output);
}
-
- [MonoTODO]
- public static void Input (System.Int32 FileNumber,
- ref System.Object Value)
+
+ public static void Write(int fileNumber, Object[] output)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.write(output);
}
-
- [MonoTODO("Needs Testing")]
- public static void Input (System.Int32 FileNumber,
- ref System.Boolean Value)
+
+ public static void WriteLine(int fileNumber, Object[] output)
{
- string buffer="";
- InternalInputExceptions(FileNumber);
- buffer=InternalInput(FileNumber,3);
- if (buffer=="True")
- Value=true;
- else
- Value=false;
- }
-
- [MonoTODO("Needs Testing")]
- public static void Input (System.Int32 FileNumber, ref System.Byte Value)
- {
- string buffer="";
- InternalInputExceptions(FileNumber);
- buffer=InternalInput(FileNumber,1);
- if (buffer[0]=='-')
- throw new System.OverflowException();
- Value=0;
- for (int addnumber=0; addnumber < buffer.Length;addnumber++)
- {
- checked {
- Value*=10;
- Value += Byte.Parse(buffer.Substring(addnumber,1));
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.writeLine(output);
+ }
- }
+ public static void Rename(String oldPath, String newPath)
+ {
+ FileInfo file = new FileInfo(newPath);
+ if (file.Exists)
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.FileAlreadyExists);
+ try
+ {
+ Directory.Move(oldPath, newPath);
+ }catch (DirectoryNotFoundException e){
+ throw (ArgumentException)ExceptionUtils.VbMakeException(VBErrors.IllegalFuncCall);
}
}
-
- [MonoTODO("Needs Testing")]
- public static void Input (System.Int32 FileNumber, ref System.Int16 Value)
+
+ public static void FileCopy(String source, String destination)
{
- string buffer="";
- System.Int16 factor=1;
- InternalInputExceptions(FileNumber);
- buffer=InternalInput(FileNumber,1);
- if (buffer[0]=='-')
+ DirectoryInfo dir;
+
+ if ((source == null) || (source.Length == 0))
{
- factor=-1;
- buffer=buffer.Substring(1);
+ ExceptionUtils.VbMakeException(VBErrors.BadFileNameOrNumber);
+ throw new ArgumentException(
+ Utils.GetResourceString("Argument_PathNullOrEmpty"));
}
- Value=0;
- for (int addnumber=0; addnumber < buffer.Length;addnumber++)
+
+ if ((destination == null) || (destination.Length == 0))
{
- checked {
- Value*=10;
- Value += Int16.Parse(buffer.Substring(addnumber,1));
+ ExceptionUtils.VbMakeException(VBErrors.BadFileNameOrNumber);
+ throw new ArgumentException(
+ Utils.GetResourceString("Argument_PathNullOrEmpty"));
+ }
+
+ FileInfo f = new FileInfo(source);
+ if (!f.Exists)
+ throw (FileNotFoundException) ExceptionUtils.VbMakeException(
+ VBErrors.FileNotFound);
+ if (_fileNameIdMap[source] != null)
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.FileAlreadyOpen);
+ int lastIndex = destination.LastIndexOf('/');
+
+ if(lastIndex == -1)
+ dir = new DirectoryInfo(".");
+ else
+ dir = new DirectoryInfo(destination.Substring(0,lastIndex));
+
+ if (!dir.Exists)
+ {
+ ExceptionUtils.VbMakeException(VBErrors.FileAlreadyOpen);
+ throw new DirectoryNotFoundException();
+ }
+
+ // the file name length is 0
+ if (destination.Length == lastIndex +1)
+ {
+ throw (IOException)ExceptionUtils.VbMakeException(VBErrors.FileAlreadyOpen);
- }
}
- Value*=factor;
+ f = new FileInfo(destination);
+ if (f.Exists)
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.FileAlreadyExists);
+ File.Copy(source, destination);
}
-
- [MonoTODO("Needs Testing")]
- public static void Input (System.Int32 FileNumber, ref System.Int32 Value)
+
+ public static void MkDir(String path)
{
- string buffer="";
- int factor=1;
- InternalInputExceptions(FileNumber);
- buffer=InternalInput(FileNumber,1);
- if (buffer[0]=='-')
+ if ((path == null) || (path.Length == 0))
{
- factor=-1;
- buffer=buffer.Substring(1);
+ ExceptionUtils.VbMakeException(VBErrors.BadFileNameOrNumber);
+ throw new ArgumentException(
+ Utils.GetResourceString("Argument_PathNullOrEmpty"));
}
- Value=0;
- for (int addnumber=0; addnumber < buffer.Length;addnumber++)
- {
- checked {
- Value*=10;
- Value += Int32.Parse(buffer.Substring(addnumber,1));
+ if (Directory.Exists(path))
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.PathFileAccess);
- }
- }
- Value*=factor;
+ Directory.CreateDirectory(path);
+ }
+ public static void Kill(String pathName)
+ {
+ if (_fileNameIdMap[pathName] != null)
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.FileAlreadyOpen);
+ if (!File.Exists(pathName))
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.FileNotFound);
+ File.Delete(pathName);
}
-
- [MonoTODO("Needs Testing")]
- public static void Input (System.Int32 FileNumber, ref System.Int64 Value)
+
+ public static void RmDir(String pathName)
{
- string buffer="";
- int factor=1;
- InternalInputExceptions(FileNumber);
- buffer=InternalInput(FileNumber,1);
- if (buffer[0]=='-')
+ if (pathName == null || pathName.Length == 0 )
{
- factor=-1;
- buffer=buffer.Substring(1);
+ ExceptionUtils.VbMakeException(VBErrors.BadFileNameOrNumber);
+ throw new ArgumentException(pathName);
}
- Value=0;
- for (int addnumber=0; addnumber < buffer.Length;addnumber++)
+ DirectoryInfo dir = new DirectoryInfo(pathName);
+ if (!dir.Exists)
{
- checked {
- Value*=10;
- Value += Int64.Parse(buffer.Substring(addnumber,1));
-
- }
+ ExceptionUtils.VbMakeException(VBErrors.PathNotFound);
+ throw new DirectoryNotFoundException();
}
- Value*=factor;
-
+ if (dir.GetFiles().Length != 0)
+ throw (IOException) ExceptionUtils.VbMakeException(
+ VBErrors.PathFileAccess);
+ Directory.Delete(pathName);
}
-
- [MonoTODO]
- public static void Input (System.Int32 FileNumber, ref System.Char Value)
+
+ public static FileAttribute GetAttr(String pathName)
{
- throw new NotImplementedException ();
+ if (pathName == null || pathName.Length == 0 ||
+ pathName.IndexOf('*') != -1 || pathName.IndexOf('?') != -1)
+ {
+ throw (IOException)ExceptionUtils.VbMakeException(VBErrors.BadFileNameOrNumber);
+ }
+ // File f = new File(pathName);
+ // if (!f.exists())
+ // throw (FileNotFoundException)
+ // ExceptionUtils.VbMakeException(VBErrors.FileNotFound);
+ return (FileAttribute) File.GetAttributes(pathName);
}
-
- [MonoTODO("Needs Testing")]
- public static void Input (System.Int32 FileNumber, ref System.Single Value)
+
+ public static void SetAttr(String pathName, FileAttribute fileAttr)
{
- System.Single DecimalValue=0;
- string buffer="";
- //int factor=1;
- string BufDecimal="";
- InternalInputExceptions(FileNumber);
- buffer=InternalInput(FileNumber,2);
- if (buffer[0]=='-')
+ if (pathName == null || pathName.Length == 0 ||
+ pathName.IndexOf('*') != -1 || pathName.IndexOf('?') != -1)
{
- //factor=-1;
- buffer=buffer.Substring(1);
+ throw (ArgumentException)ExceptionUtils.VbMakeException(VBErrors.IllegalFuncCall);
}
- if ( buffer.IndexOf(".")>=0)
+ FileInfo f = new FileInfo(pathName);
+ if (!f.Directory.Exists)
{
- if ( buffer.IndexOf(".") < (buffer.Length -1) )
- BufDecimal=buffer.Substring(buffer.IndexOf(".")+1);
- if ( buffer.IndexOf(".") > 0)
- buffer=buffer.Substring(0,buffer.IndexOf("."));
- else
- buffer="";
-
+ ExceptionUtils.VbMakeException(VBErrors.PathNotFound);
+ throw new DirectoryNotFoundException();
}
- Value=0;
- if ( BufDecimal.Length > 0)
+ if (!f.Exists)
{
- for (int addnumber=BufDecimal.Length-1; addnumber >=0;addnumber--)
- {
- checked {
- DecimalValue += System.Single.Parse(BufDecimal.Substring(addnumber,1));
- DecimalValue /= 10;
+ throw (FileNotFoundException)
+ ExceptionUtils.VbMakeException(VBErrors.FileNotFound);
+ }
- }
- }
+ try
+ {
+ File.SetAttributes(pathName, (FileAttributes)fileAttr);
}
- if (buffer.Length >0)
+ catch (ArgumentException e)
{
- for (int addnumber=0; addnumber < buffer.Length;addnumber++)
- {
- checked {
- Value*=10;
- Value += System.Single.Parse(buffer.Substring(addnumber,1));
-
- }
- }
+ throw (ArgumentException) ExceptionUtils.VbMakeException(
+ VBErrors.IllegalFuncCall);
}
- Value+=DecimalValue;
- }
-
- [MonoTODO("Needs Testing")]
- public static void Input (System.Int32 FileNumber, ref System.Double Value)
- {
- double DecimalValue=0;
- string buffer="";
- //int factor=1;
- string BufDecimal="";
- InternalInputExceptions(FileNumber);
- buffer=InternalInput(FileNumber,2);
- if (buffer[0]=='-')
+ catch (DirectoryNotFoundException ex)
{
- //factor=-1;
- buffer=buffer.Substring(1);
+ ExceptionUtils.VbMakeException(VBErrors.PathNotFound);
+ throw ex;
}
- if ( buffer.IndexOf(".")>=0)
+ catch (FileNotFoundException ex)
{
- if ( buffer.IndexOf(".") < (buffer.Length -1) )
- BufDecimal=buffer.Substring(buffer.IndexOf(".")+1);
- if ( buffer.IndexOf(".") > 0)
- buffer=buffer.Substring(0,buffer.IndexOf("."));
- else
- buffer="";
+ throw (FileNotFoundException)
+ ExceptionUtils.VbMakeException(VBErrors.FileNotFound);
+ }
+
+ }
+
+
+ public static /*synchronized*/ String Dir(String pathName,
+ [Optional, __DefaultArgumentValue((int)0)]
+ FileAttribute fileAttribute)
+ {
+ _fileIndex = 0;
+ _files = null;
+ _pattern = null;
+ _fileAttrs = (int)fileAttribute;
+
+ if (pathName == null || pathName.Equals(""))
+ {
+ return "";
}
- Value=0;
- if ( BufDecimal.Length > 0)
+
+ if (FileAttribute.Volume == fileAttribute)
+ return "";
+
+
+ int lastBabkSlashInx = pathName.LastIndexOf('\\');
+ int lastSlashInx = pathName.LastIndexOf('/');
+ int maxIndex = (lastSlashInx>lastBabkSlashInx)?lastSlashInx:lastBabkSlashInx;
+ String dir = pathName.Substring(0, maxIndex + 1);
+ String fileName = pathName.Substring(1 + maxIndex);
+ if (fileName == null || fileName.Length == 0)
+ fileName = "*";
+
+ // int astricsInx = fileName.indexOf('*');
+ // int questionInx = fileName.indexOf('?');
+
+ // String pattern;
+ DirectoryInfo directory = new DirectoryInfo(dir);
+ // java.io.File directory = new java.io.File(dir);
+ // java.io.File file;
+ if (!directory.Exists)
{
- for (int addnumber=BufDecimal.Length-1; addnumber >=0;addnumber--)
- {
- checked {
- DecimalValue += Double.Parse(BufDecimal.Substring(addnumber,1));
- DecimalValue /= 10;
+ // path not found - return empty string
+ return "";
+ }
+
+ // if (astricsInx == -1 && questionInx == -1)
+ // {
+ // pattern = fileName;
+ // }
+ // else
+ // {
+ // pattern = Strings.Replace(fileName, ".", "\\.", 1, -1, CompareMethod.Binary);
+ // pattern = Strings.Replace(pattern, "*", ".*", 1, -1, CompareMethod.Binary);
+ // pattern = Strings.Replace(pattern, "?", ".?", 1, -1, CompareMethod.Binary);
+ // }
+
+ _pattern = fileName;
+ // _pattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
- }
+ _files = directory.GetFiles(_pattern);
+ String answer;
+ if (_files == null || _files.Length == 0)
+ {
+ DirectoryInfo[] dirs = directory.GetDirectories(_pattern);
+ if (dirs == null || dirs.Length == 0)
+ {
+ return "";
}
+ answer = dirs[0].Name;
+ }
+ else
+ {
+ answer = _files[0].Name;
+ }
+
+ _fileIndex++;
+ _isEndOfFiles = false;
+
+
+ return answer;
+
+ }
+
+ public static /*synchronized*/ String Dir()
+ {
+ String name;
+ if (_files == null || _isEndOfFiles)
+ throw new /*Illegal*/ArgumentException("no path has been initiated");
+
+ if (_fileIndex < _files.Length)
+ {
+ name = _files[_fileIndex].Name;
+ _fileIndex++;
}
- if (buffer.Length >0)
+ else
{
- for (int addnumber=0; addnumber < buffer.Length;addnumber++)
- {
- checked {
- Value*=10;
- Value += Double.Parse(buffer.Substring(addnumber,1));
+ _isEndOfFiles = true;
+ name = "";
+ }
- }
- }
+ return name;
+ }
+
+ public static DateTime FileDateTime(String pathName)
+ {
+ if (pathName == null || pathName.Length == 0 ||
+ pathName.IndexOf('*') != -1 || pathName.IndexOf('?') != -1)
+ {
+ ExceptionUtils.VbMakeException(VBErrors.BadFileNameOrNumber);
+ throw new ArgumentException(
+ VBUtils.GetResourceString(
+ "Argument_InvalidValue1",
+ "PathName"));
}
- Value+=DecimalValue;
+ FileInfo f = new FileInfo(pathName);
+ if (!f.Exists)
+ {
+ DirectoryInfo d = new DirectoryInfo(pathName);
+ if (!d.Exists)
+ throw (FileNotFoundException)
+ ExceptionUtils.VbMakeException(VBErrors.FileNotFound);
+ return d.LastWriteTime;
+ }
+ return f.LastWriteTime;
}
-
- [MonoTODO]
- public static void Input (System.Int32 FileNumber, ref System.Decimal Value)
+
+ public static long FileLen(String pathName)
{
- throw new NotImplementedException ();
+ FileInfo f = new FileInfo(pathName);
+ if (!f.Exists)
+ throw new FileNotFoundException(
+ "file not exists: " + pathName);
+
+ return f.Length;
}
-
- [MonoTODO("Needs Testing")]
- public static void Input (System.Int32 FileNumber, ref System.String Value)
+
+
+ internal static String SPC(int count)
{
- //string buffer="";
- InternalInputExceptions(FileNumber);
- Value=InternalInput(FileNumber,0);
+ StringBuilder sb = new StringBuilder(count);
+ for (int i = 0; i < count; i++)
+ sb.Append(' ');
+
+ return sb.ToString();
}
-
- [MonoTODO]
- public static void Input (System.Int32 FileNumber, ref System.DateTime Value)
- {
- throw new NotImplementedException ();
- }
- private static void InternalInputExceptions(System.Int32 FileNumber)
- {
- if ( FileNumber < 0 || FileNumber > 255 )
- throw new System.ArgumentException("File Number is not valid");
- if ( FHandle[FileNumber - 1] == null)
- throw new System.ArgumentException("File Number is not valid");
- if ( FMode[FileNumber - 1] != OpenMode.Input && FMode[FileNumber-1] != OpenMode.Binary )
- throw new System.IO.IOException("File Mode is invalid");
- if ( FHandle[FileNumber - 1].Position == FHandle[FileNumber - 1].Length)
- throw new System.IO.EndOfStreamException();
- }
- private static string InternalInput(System.Int32 FileNumber,int DataType)
- {
-
- // DataType : an additional filter
- // to know if conversion is possible
- // 0 --> string
- // 1 --> To a numeric (integer) value
- // 2 --> To a numeric (not integer) value
- // 3 --> To Boolean
- bool found=false;
- bool firstzone=true;
- bool literal=false;
- bool MyOK=true;
- bool DecimalFound=false;
- bool SignFound=false;
- string retval="";
- string retval2="";
- byte[] BufByte=new byte[1];
- while ( !found && ( FHandle[FileNumber-1].Position < FHandle[FileNumber-1].Length ))
+
+ public static int FreeFile()
+ {
+ ICollection s = _openFilesMap.Keys;
+
+ if (s.Count == 0)
+ return 1;
+
+ int [] keyArr = new int[s.Count];
+
+ s.CopyTo(keyArr, 0);
+
+ Array.Sort(keyArr);
+ int i = 0;
+ for (; i < keyArr.Length - 1; i++)
{
- FHandle[FileNumber-1].Read (BufByte,0,1);
- switch ((char)BufByte[0])
- {
- case ' ':
- if (literal)
- retval+=" ";
- else {
- if (!firstzone && (DataType==1 || DataType==2))
- found=true;
- else
- retval+=" ";
- }
- break;
- case '\t':
- if (literal) retval+="\t";
- else if (!firstzone) found=true;
+ if ((keyArr[i]+ 1) < keyArr[i + 1])
break;
- case '"':
- retval+="\"";
- if (literal) literal=!literal;
- else
- {
- if (!firstzone) found=true;
- else literal=!literal;
- }
- break;
- case ',':
- if (!literal) found=true;
- else retval+=",";
- break;
- case '\x0d':
- if (!literal)
- {
- found=true;
- if (FHandle[FileNumber - 1].Length > FHandle[FileNumber - 1].Position )
- {
- FHandle[FileNumber - 1].Read (BufByte,0,1);
- if (BufByte[0] != 10 )
- FHandle[FileNumber - 1].Seek (-1,SeekOrigin.Current );
- }
-
- }
- else { retval+="\x0d"; }
- break;
- case '\x0a':
- if (literal) retval+="\x0a";
- break;
- default:
- firstzone=false;
- retval+=((char)BufByte[0]).ToString();
- break;
- }
}
- switch (DataType)
+
+ int retVal = keyArr[i]+ 1;
+
+ if (retVal > 255)
{
- case 0:
- retval=retval.Trim();
- if (retval.Substring(0,1)=="\"")
- {
- if (retval.Length > 1) retval=retval.Substring (1);
- else retval="";
- }
- if (retval.Length >=1)
- {
- if (retval.Substring (retval.Length -1 ,1)=="\"")
- {
- if (retval.Length > 1) retval=retval.Substring (0,retval.Length -1);
- else retval="";
- }
- }
- retval2=retval;
- break;
- case 1:
- case 2:
- retval=retval.Trim();
- for (int myloop=0; (myloop<retval.Length) && MyOK ;myloop++)
- switch(retval[myloop])
- {
- case '+':
- case '-':
- if (myloop==0 || myloop == (retval.Length -1))
- {
- if (!SignFound)
- {
- retval2=retval[myloop].ToString() + retval2;
- SignFound=true;
- }
- else
- MyOK=false;
- }
- else
- MyOK=false;
- break;
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- retval2+=retval.Substring (myloop,1);
- break;
- case '.':
- if (DataType==2)
- {
- if (!DecimalFound)
- {
- retval2+="." ;
- DecimalFound=true;
- }
- else
- MyOK=false;
- }
- break;
- default:
- MyOK=false;
- break;
- }
- if (MyOK && (retval2.Length >=1 ) )
- {
- if (retval2[retval2.Length-1]=='.' )
- {
- if (retval2.Length >1)
- retval2=retval2.Substring (0,retval2.Length -1);
- else
- MyOK=false;
- }
- }
- else
- MyOK=false;
- break;
- case 3:
- retval=retval.Trim();
- retval2="False";
- retval=retval.Trim();
- if (retval=="#TRUE#" || retval=="#FALSE#" ||
- retval.ToUpper() =="TRUE" || retval.ToUpper() =="FALSE" ||
- retval.ToUpper() == "\"TRUE\"" || retval.ToUpper() == "\"FALSE\"")
- {
- if (retval=="#TRUE#" || retval.ToUpper() == "TRUE" || retval.ToUpper () == "\"TRUE\"")
- retval2="True";
- }
- else
- {
- if (retval.Substring(0,1)=="\"")
- {
- if (retval.Length > 1) retval=retval.Substring (1);
- else retval="";
- }
- if (retval.Length >=1)
- {
- if (retval.Substring (retval.Length -1 ,1)=="\"")
- {
- if (retval.Length > 1) retval=retval.Substring (0,retval.Length -1);
- else retval="";
- }
- }
- for (int myloop=0; (myloop<retval.Length) && MyOK ;myloop++)
- switch(retval[myloop])
- {
- case '0':
- break;
- case '1': case '2': case '3': case '4': case '5':
- case '6': case '7': case '8': case '9':
- retval2="True";
- break;
- case '.': break;
- case '-':
- if ( (myloop!=0) && (myloop!=retval.Length-1) )
- MyOK=false;
- break;
- default:
- MyOK=false;
- break;
- }
- }
- break;
+ String message = VBUtils.GetResourceString(67);
+ throw (IOException)VBUtils.VBException(
+ new IOException(message),
+ 67);
}
- if (MyOK)
- {
- return retval2;
+
+ return retVal;
+
+ }
+
+ public static bool EOF(int fileNumber)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ return vbFile.isEndOfFile();
+ }
+
+ // check if a specific number is free
+ private static bool isFileNumberFree(int fileNumber)
+ {
+ return !_openFilesMap.ContainsKey(fileNumber);
+ }
+
+ [MonoTODO("If path is another drive, it should change the default folder for that drive, but not switch to it.")]
+ public static void ChDir (string Path)
+ {
+ if ((Path=="") || (Path==null))
+ throw new ArgumentException (Utils.GetResourceString ("Argument_PathNullOrEmpty"));
+ try {
+ Environment.CurrentDirectory = Path;
}
- else // TODO : string explaining cast exception
- throw new System.InvalidCastException();
- }
-
- [MonoTODO("Needs Testing")]
- public static void Write (System.Int32 FileNumber, params System.Object[] Output)
- {
- string MyBuf=null;
- byte[] Separator=new byte[1];
- byte[] bufout=new Byte[1];
- Separator[0]=(byte)',';
- if (FileNumber<1 || FileNumber>255)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- if (FHandle[FileNumber - 1]==null)
- throw new System.IO.IOException(FileNumber + " does not exists",52);
- if ( FMode[ FileNumber - 1] != OpenMode.Output )
- throw new System.IO.IOException ("FileMode is invalid");
- if (Output.Length == 0)
- {
- FHandle[FileNumber - 1].Write(Separator,0,1);
+ catch {
+ throw new FileNotFoundException (Utils.GetResourceString ("FileSystem_PathNotFound1", Path));
}
- else
+ }
+
+
+ public static void ChDrive(char Drive)
+ {
+ Drive = char.ToUpper(Drive, CultureInfo.InvariantCulture);
+ if ((Drive < 65) || (Drive > 90))
{
- for (int MyArgs=0;MyArgs<Output.Length;MyArgs++)
- {
- MyBuf=WriteAuxiliar(Output[MyArgs]);
- for (int PutsData=0;PutsData<MyBuf.Length;PutsData++)
- {
- bufout[0]=(byte)MyBuf[PutsData];
- FHandle[FileNumber-1].Write(bufout,0,1);
- }
- FHandle[FileNumber - 1].Write(Separator,0,1);
- }
+ throw new ArgumentException(
+ Utils.GetResourceString("Argument_InvalidValue1", "Drive"));
}
+ Directory.SetCurrentDirectory(String.Concat(StringType.FromChar(Drive), StringType.FromChar(Path.VolumeSeparatorChar)));
}
-
- [MonoTODO("Needs Testing")]
- public static void WriteLine (System.Int32 FileNumber, params System.Object[] Output)
- {
- byte[] Separator=new byte[1];
- byte[] bufout=new Byte[1];
- byte[] NewLine=new Byte[2];
- string MyBuf="";
- Separator[0]=(byte)',';
- NewLine[0]=(byte)'\x0D';
- NewLine[1]=(byte)'\x0A';
- if (FileNumber<1 || FileNumber>255)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- if (FHandle[FileNumber - 1]==null)
- throw new System.IO.IOException(FileNumber + " does not exists",52);
- if ( FMode[ FileNumber - 1] != OpenMode.Output )
- throw new System.IO.IOException ("FileMode is invalid");
- if (Output.Length == 0)
- {
- FHandle[FileNumber - 1].Write(NewLine,0,2);
+
+ public static void ChDrive(String Drive)
+ {
+ if (Drive != null && Drive.Length != 0)
+ FileSystem.ChDrive(Drive[0]);
+ }
+
+ public static String CurDir()
+ {
+ return Environment.CurrentDirectory;
+ }
+
+ public static String CurDir(char Drive)
+ {
+ return Directory.GetCurrentDirectory();
+ }
+
+ [MonoTODO("How to deal with Array types?")]
+ public static void FileGetObject(
+ int fileNumber,
+ ref object value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+ {
+ checkRecordNumber(recordNumber,true);
+ VBFile vbFile = getVBFile(fileNumber);
+
+ Type type = value.GetType();
+
+ if (type == null || value is string) {
+ string tmp = null;
+ vbFile.get(ref tmp, recordNumber, false);
+ value = tmp;
}
- else
- {
- for (int MyArgs=0;MyArgs<Output.Length;MyArgs++)
- {
- MyBuf=WriteAuxiliar(Output[MyArgs]);
- for (int PutsData=0;PutsData<MyBuf.Length;PutsData++)
- {
- bufout[0]=(byte)MyBuf[PutsData];
- FHandle[FileNumber-1].Write(bufout,0,1);
- }
- if (MyArgs < (Output.Length -1))
- {
- FHandle[FileNumber - 1].Write(Separator,0,1);
- }
- else
- {
- FHandle[FileNumber - 1].Write(NewLine,0,2);
- }
- }
+ else if ( value is bool) {
+ bool tmp;
+ vbFile.get(out tmp,recordNumber);
+ value = tmp;
+ }
+ else if ( value is char) {
+ char tmp;
+ vbFile.get(out tmp,recordNumber);
+ value = tmp;
+ }
+ else if ( value is byte) {
+ byte tmp;
+ vbFile.get(out tmp,recordNumber);
+ value = tmp;
+ }
+ else if ( value is short) {
+ short tmp;
+ vbFile.get(out tmp,recordNumber);
+ value = tmp;
}
+ else if ( value is int) {
+ int tmp;
+ vbFile.get(out tmp,recordNumber);
+ value = tmp;
+ }
+ else if ( value is long) {
+ long tmp;
+ vbFile.get(out tmp,recordNumber);
+ value = tmp;
+ }
+ else if ( value is float) {
+ float tmp;
+ vbFile.get(out tmp,recordNumber);
+ value = tmp;
+ }
+ else if ( value is double) {
+ double tmp;
+ vbFile.get(out tmp,recordNumber);
+ value = tmp;
+ }
+ else if ( value is Decimal) {
+ Decimal tmp;
+ vbFile.get(out tmp,recordNumber);
+ value = tmp;
+ }
+ else if ( value is DateTime) {
+ DateTime tmp;
+ vbFile.get(out tmp,recordNumber);
+ value = tmp;
+ }
+ else if (type.IsArray) {
+ // need to figure out how to convert from Object& to Array&
+ // vbFile.get(out value, recordNumber,true,false);
+ // value = tmp;
+ throw new NotImplementedException();
+ }
+ else
+ throw new NotSupportedException();
}
- private static string WriteAuxiliar(Object Argument)
+
+ public static void FilePutObject(int fileNumber,
+ Object value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
+
{
- string retval="";
- if (Argument==null)
- retval="#NULL#";
- else
- {
- switch (Argument.GetType().ToString())
- {
- case "System.Boolean":
- if ( (bool)Argument == true)
- retval="#TRUE#";
- else
- retval="#FALSE#";
- break;
- case "System.String":
- retval="\"" + (string)Argument + "\"";
- break;
- case "System.Int64":
- case "System.UInt64":
- case "System.Int32":
- case "System.UInt32":
- case "System.Int16":
- case "System.UInt16":
- case "System.Sbyte":
- case "System.Byte":
- retval = Argument.ToString();
- break;
- case "System.Single":
- case "System.Double":
- case "System.Decimal":
- string buf= (Argument.ToString()) ;
- if ( buf.IndexOf(",")>=0)
- retval=buf.Substring(0, buf.IndexOf(","))
- + "." + buf.Substring(1+buf.IndexOf(","));
- break;
- case "System.Exception":
- retval=((Exception)Argument).ToString();
- break;
- case "System.Char":
- retval=((char)Argument).ToString();
- break;
- case "System.DateTime":
- retval=((System.DateTime )Argument).ToString("u");
- retval=retval.Substring(0,retval.Length -1);
- if (retval.Substring(11,8)=="00:00:00")
- retval=retval.Substring(0,10);
- retval= "#" + retval + "#";
- break;
- default :
- throw new NotImplementedException ();
-
- }
+ checkRecordNumber(recordNumber,true);
+ VBFile vbFile = getVBFile(fileNumber);
+ Type type = value.GetType();
+ if(value is string || value == null)
+ vbFile.put((String)value,recordNumber,false);
+ else if( value is bool) {
+ vbFile.put((bool)value, recordNumber);
}
- return retval;
- }
-
- [MonoTODO("Needs Testing")]
- public static System.String InputString (System.Int32 FileNumber, System.Int32 CharCount)
- {
- byte[] Buf;
- string retval="";
- //
- // exceptions
- if ( FileNumber<1 || FileNumber>255)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- if ( FHandle[FileNumber - 1] == null)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- if ( (FMode[FileNumber - 1] != OpenMode.Input) && (FMode[FileNumber - 1] != OpenMode.Binary ))
- throw new System.IO.IOException ("FileMode is invalid");
- if (CharCount <0 || CharCount>2e14 )
- throw new System.ArgumentException();
- if ( (CharCount + FHandle[FileNumber - 1].Position) > FHandle[FileNumber - 1].Length)
- throw new System.IO.EndOfStreamException();
- //
- // implementation
- Buf=new byte[CharCount];
- FHandle[FileNumber - 1].Read(Buf,0,Buf.Length);
- for (int myloop=0;myloop<Buf.Length;myloop++)
- retval+=((char)Buf[myloop]).ToString();
- return retval;
- }
-
- [MonoTODO("Needs testing")]
- public static System.String LineInput (System.Int32 FileNumber)
- {
- string retval="";
- int buf='\x00';
- bool found=false;
- if ( FileNumber<1 || FileNumber>255)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- if ( FHandle[FileNumber - 1] == null)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
-
- if ( EOF(FileNumber) )
- throw new System.IO.EndOfStreamException();
-
- while (!found)
- {
-
- buf=FHandle[FileNumber - 1].ReadByte();
- if ( (buf == -1) || (buf == '\x0A' ) )
- found=true;
- else
- retval+= ((char)buf).ToString();
+ else if( value is char) {
+ vbFile.put((char)value,recordNumber);
+ }
+ else if( value is byte) {
+ vbFile.put((byte)value, recordNumber);
+ }
+ else if( value is short) {
+ vbFile.put((short)value, recordNumber);
+ }
+ else if( value is int) {
+ vbFile.put((int)value, recordNumber);
+ }
+ else if( value is long) {
+ vbFile.put((long)value, recordNumber);
+ }
+ else if( value is float) {
+ vbFile.put((float)value, recordNumber);
}
- if ( retval.Length > 0 )
- if ( (buf == '\x0A') && (retval[retval.Length -1 ] == '\x0D') )
- retval=retval.Substring(0,retval.Length -1) ;
- return retval;
-
+ else if( value is double) {
+ vbFile.put((double)value, recordNumber);
+ }
+ else if( value is Decimal) {
+ vbFile.put((Decimal)value,recordNumber);
+ }
+ else if( value is DateTime) {
+ vbFile.put((DateTime)value, recordNumber);
+ }
+ else if(type.IsArray) {
+ vbFile.put(value,recordNumber,true,false);
+ }
+ else {
+ throw new NotSupportedException();
+ }
+
}
-
- [MonoTODO]
- public static void Lock (System.Int32 FileNumber)
+
+ private const string obsoleteMsg1 = "Use FilePutObject to write Object types, or";
+ private const string obsoleteMsg2 = "coerce FileNumber and RecordNumber to Integer for writing non-Object types";
+ private const string obsoleteMsg = obsoleteMsg1 + obsoleteMsg2;
+
+ [System.ObsoleteAttribute(obsoleteMsg, false)]
+ public static void FilePut(Object FileNumber,
+ Object Value,
+ [Optional, __DefaultArgumentValue(-1)] System.Object RecordNumber)
{
- throw new NotImplementedException ();
+ throw new ArgumentException(Utils.GetResourceString("UseFilePutObject"));
}
-
+
[MonoTODO]
- public static void Lock (System.Int32 FileNumber, System.Int64 Record)
+ public static void FilePut(int FileNumber,
+ ValueType Value,
+ [Optional, __DefaultArgumentValue((long)-1)] System.Int64 RecordNumber)
+
{
- throw new NotImplementedException ();
+ throw new NotImplementedException();
}
-
- [MonoTODO]
- public static void Lock (System.Int32 FileNumber, System.Int64 FromRecord, System.Int64 ToRecord)
+
+ public static void FilePut(int fileNumber,
+ Array value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber,
+ [Optional, __DefaultArgumentValue(false)] bool arrayIsDynamic,
+ [Optional, __DefaultArgumentValue(false)] bool stringIsFixedLength)
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,true);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber,arrayIsDynamic,stringIsFixedLength);
}
-
- [MonoTODO]
- public static void Unlock (System.Int32 FileNumber)
+
+ public static void FilePut(int fileNumber,
+ Decimal value,
+ [Optional, __DefaultArgumentValue((long)-1)] long recordNumber)
{
- throw new NotImplementedException ();
+ checkRecordNumber(recordNumber,true);
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.put(value,recordNumber);
}
-
- [MonoTODO]
- public static void Unlock (System.Int32 FileNumber, System.Int64 Record)
+
+ public static void Input(int fileNumber, ref bool Value)
{
- throw new NotImplementedException ();
+
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
}
-
- [MonoTODO]
- public static void Unlock (System.Int32 FileNumber, System.Int64 FromRecord, System.Int64 ToRecord)
+
+ public static void Input(int fileNumber, ref byte Value)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
}
-
- [MonoTODO]
- public static void FileWidth (System.Int32 FileNumber, System.Int32 RecordWidth)
- {
- throw new NotImplementedException ();
- }
-
-
- [MonoTODO("Needs testing")]
- public static System.Int32 FreeFile ()
- {
- int bucle=0;
- bool found=false;
- for (bucle=0;bucle<255;bucle++)
- if (FHandle[bucle]==null)
- {
- found=true;
- break;
- }
- if (!found)
- throw new System.IO.IOException ("More than 255 files are in use",67);
- else
- return bucle+1;
+
+ public static void Input(int fileNumber, ref short Value)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
}
-
- [MonoTODO]
- public static void Seek (System.Int32 FileNumber, System.Int64 Position)
+
+ public static void Input(int fileNumber, ref int Value)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
+ }
+
+ public static void Input(int fileNumber, ref long Value)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
+ }
+
+ public static void Input(int fileNumber, ref char Value)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
+ }
+
+ public static void Input(int fileNumber, ref float Value)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
+ }
+
+ public static void Input(int fileNumber, ref double Value)
{
- throw new NotImplementedException ();
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
}
-
+
+ public static void Input(int fileNumber, ref Decimal Value)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
+ }
+
+ public static void Input(int fileNumber, ref DateTime Value)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
+ }
+
+ public static void Input(int fileNumber, ref string Value)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.Input(out Value);
+ }
+
+
+ // public static void Input$V$FileSystem$ILSystem_Object$$$(int fileNumber, ObjectRefWrapper Value)
+ // {
+ // VBFile vbFile = getVBFile(fileNumber);
+ // vbFile.Input(Value,false);
+ // }
+
[MonoTODO]
- public static System.Int64 Seek (System.Int32 FileNumber)
- {
- throw new NotImplementedException ();
- }
-
-
- [MonoTODO("Needs testing")]
- public static System.Boolean EOF ( System.Int32 FileNumber)
- {
- if (FileNumber<1 || FileNumber>255)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- if ( FHandle[FileNumber - 1] == null)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- if ( FHandle[FileNumber - 1].Length == FHandle[FileNumber - 1].Position)
- return true;
- else
- return false;
-
+ public static void Lock(int fileNumber)
+ {
+ throw new NotImplementedException("The method Lock in class FileSystem is not supported");
}
-
-
+
[MonoTODO]
- public static System.Int64 Loc (System.Int32 FileNumber)
+ public static void Lock(int FileNumber, long Record)
{
- throw new NotImplementedException ();
+ throw new NotImplementedException("The method Lock in class FileSystem is not supported");
}
-
+
[MonoTODO]
- public static System.Int64 LOF (System.Int32 FileNumber)
+ public static void Lock(int FileNumber, long FromRecord, long ToRecord)
{
- if (FileNumber<1 || FileNumber>255)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- if ( FHandle[FileNumber - 1] == null)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- return (System.Int64)FHandle[FileNumber - 1].Length;
+ throw new NotImplementedException("The method Lock in class FileSystem is not supported");
}
-
+
[MonoTODO]
- public static Microsoft.VisualBasic.TabInfo TAB ()
+ public static void Unlock(int FileNumber)
{
- throw new NotImplementedException ();
+ throw new NotImplementedException("The method Unlock in class FileSystem is not supported");
}
-
+
[MonoTODO]
- public static Microsoft.VisualBasic.TabInfo TAB (System.Int16 Column)
+ public static void Unlock(int FileNumber, long Record)
{
- throw new NotImplementedException ();
+ throw new NotImplementedException("The method Unlock in class FileSystem is not supported");
}
-
+
[MonoTODO]
- public static Microsoft.VisualBasic.SpcInfo SPC (System.Int16 Count)
+ public static void Unlock(int FileNumber, long FromRecord, long ToRecord)
{
- throw new NotImplementedException ();
+ throw new NotImplementedException("The method Unlock in class FileSystem is not supported");
}
-
- [MonoTODO("Needs Testing")]
- public static Microsoft.VisualBasic.OpenMode FileAttr (System.Int32 FileNumber)
- {
- if (FileNumber<1 || FileNumber>255)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- if ( FHandle[FileNumber - 1] == null)
- throw new System.IO.IOException (FileNumber.ToString() + " does not exists",52);
- return FMode[FileNumber - 1];
+
+ public static void FileWidth(int fileNumber, int RecordWidth)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ vbFile.width(fileNumber,RecordWidth);
}
-
- [MonoTODO("Needs Testing")]
- public static void Reset ()
+
+ public static TabInfo TAB()
{
- for(int bucle=0;bucle<255;bucle++)
- {
- if (FHandle[bucle]!=null)
- try
- {
- FHandle[bucle].Close();
- }
- catch /*(Exception e) */
- {
- FHandle[bucle]=null ;
- }
- }
+ return new TabInfo((short) - 1);
}
-
- [MonoTODO("Needs Testing")]
- public static void Rename (System.String OldPath, System.String NewPath)
+
+ public static TabInfo TAB(short Column)
+ {
+ return new TabInfo(Column);
+ }
+
+ public static SpcInfo SPC(short Count)
+ {
+ return new SpcInfo(Count);
+ }
+
+ public static OpenMode FileAttr(int fileNumber)
+ {
+ VBFile vbFile = getVBFile(fileNumber);
+ return (OpenMode) vbFile.getMode();
+ }
+ }
+
+ class VBStreamWriter : StreamWriter
+ {
+ int _currentColumn;
+ int _width;
+
+ public VBStreamWriter(string fileName):base(fileName)
{
- if ( !File.Exists (OldPath) && !Directory.Exists( OldPath))
- throw new System.ArgumentException ( OldPath + " does not exist");
- if ( File.Exists ( NewPath) || Directory.Exists ( NewPath))
- throw new System.IO.IOException ( NewPath + " already exists");
- if ( File.Exists (OldPath))
- File.Move (OldPath, NewPath);
- else
- Directory.Move (OldPath, NewPath);
}
- // Events
-
- };
+
+ public VBStreamWriter(string fileName, bool append):base(fileName, append)
+ {
+ }
+ }
+
+ //TODO: FileFilters from Mainsoft code
+
}