Ejemplo n.º 1
0
        public FileStream(string Path, FileStreamMode Mode)
        {
            try
            {
                this.path = Path;
                this.mode = Mode;
                switch (this.mode)
                {
                case FileStreamMode.Read:
                    this.length = (uint)FileSystem.GetFileSize(this.path);
                    if (this.length > 0U)
                    {
                        this.hFile = Win32.CreateFile(this.path, (FileAccess)2147483648U, ShareMode.Read | ShareMode.Write, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Normal, IntPtr.Zero);
                    }
                    break;

                case FileStreamMode.Write:
                    this.hFile = Win32.CreateFile(this.path, FileAccess.GenericWrite, ShareMode.None, IntPtr.Zero, CreationDisposition.CreateAlways, FileAttributes.Normal, IntPtr.Zero);
                    break;

                case FileStreamMode.ReadWrite:
                    if (FileSystem.FileExists(this.path))
                    {
                        this.length = (uint)FileSystem.GetFileSize(this.path);
                    }
                    this.hFile = Win32.CreateFile(this.path, (FileAccess)3221225472U, ShareMode.None, IntPtr.Zero, CreationDisposition.OpenAlways, FileAttributes.Normal, IntPtr.Zero);
                    break;
                }
                this.open = true;
            }
            catch
            {
                throw;
            }
        }
 public AdvancedFileStream(string filename, FileStreamMode mode)
 {
     this.mode = mode;
     switch (mode)
     {
         case FileStreamMode.Overwrite:
             _file = new FileStream(filename, System.IO.FileMode.Create);
             break;
         case FileStreamMode.Read:
             _file = new FileStream(filename, System.IO.FileMode.Open);
             break;
         case FileStreamMode.Write:
             _file = new FileStream(filename, System.IO.FileMode.Append);
             break;
         default:
             throw new Exception("Invalid value for FileStreamMode");
     }
     Position = 0;
 }
        public AdvancedFileStream(string filename, FileStreamMode mode)
        {
            this.mode = mode;
            switch (mode)
            {
            case FileStreamMode.Overwrite:
                _file = new FileStream(filename, System.IO.FileMode.Create);
                break;

            case FileStreamMode.Read:
                _file = new FileStream(filename, System.IO.FileMode.Open);
                break;

            case FileStreamMode.Write:
                _file = new FileStream(filename, System.IO.FileMode.Append);
                break;

            default:
                throw new Exception("Invalid value for FileStreamMode");
            }
            Position = 0;
        }