コード例 #1
0
ファイル: DataStream.cs プロジェクト: priverop/Yarhl
        /// <summary>
        /// Initializes a new instance of the <see cref="DataStream"/> class.
        /// </summary>
        /// <param name="filePath">File path.</param>
        /// <param name="mode">File open mode.</param>
        /// <param name="offset">Offset from the start of the file.</param>
        /// <param name="length">Length of this DataStream.</param>
        public DataStream(string filePath, FileOpenMode mode, long offset, long length)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            long fileSize = new FileInfo(filePath).Length;

            if (offset < 0 || offset > fileSize)
            {
                throw new ArgumentOutOfRangeException(nameof(offset));
            }
            if (length < 0 || offset + length > fileSize)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }

            BaseStream  = new FileStream(filePath, mode.ToFileMode(), mode.ToFileAccess());
            isSubstream = true;
            Offset      = offset;
            this.length = length;

            IncreaseStreamCounter(BaseStream);
        }
コード例 #2
0
        /// <summary>
        /// Opens a file
        /// </summary>
        /// <param name="mode">File open mode</param>
        public void Open(FileOpenMode mode)
        {
            if (IsOpen)
            {
                throw new IOException($"File {FilePath} is already opened");
            }

            if (!File.Exists(FilePath))
            {
                throw new FileNotFoundException("Cannot open the file", FilePath);
            }

            var microfocusResult = VisionLibrary.V6_open(FilePath, (int)mode);

            // Open sucessful
            if (microfocusResult.StatusCode.IsOkStatus() &&
                microfocusResult.Result != IntPtr.Zero)
            {
                FilePointer     = microfocusResult.Result;
                CurrentOpenMode = mode;
                return;
            }

            // Error
            throw new VisionFileException((int)microfocusResult.StatusCode, $"Error {(int)microfocusResult.StatusCode} opening file {FilePath}");
        }
コード例 #3
0
        public void Open(FileOpenMode mode)
        {
            Contract.Requires(!open);

            this.mode = mode;
            open      = true;
        }
コード例 #4
0
ファイル: ManagedFileSystem.cs プロジェクト: rjshaver/Emby
        private FileMode GetFileMode(FileOpenMode mode)
        {
            switch (mode)
            {
            case FileOpenMode.Append:
                return(FileMode.Append);

            case FileOpenMode.Create:
                return(FileMode.Create);

            case FileOpenMode.CreateNew:
                return(FileMode.CreateNew);

            case FileOpenMode.Open:
                return(FileMode.Open);

            case FileOpenMode.OpenOrCreate:
                return(FileMode.OpenOrCreate);

            case FileOpenMode.Truncate:
                return(FileMode.Truncate);

            default:
                throw new Exception("Unrecognized FileOpenMode");
            }
        }
コード例 #5
0
ファイル: File.cs プロジェクト: michaelgwelch/mbasic99
        public CasetteStream(IDeviceMapping deviceMap, String tiFileName, FileType fileType, 
                             FileOpenMode fileMode, int recSize)
        {
            String nativeFileName = deviceMap.GetNativeFileName(tiFileName);

            if (recordSize > allowableRecordSizes[allowableRecordSizes.Length-1]) throw new ArgumentOutOfRangeException("recordSize");
            if (fileType == FileType.Display) throw new NotImplementedException("Display mode not yet supported");

            foreach(int i in allowableRecordSizes)
            {
                if (i > recSize)
                {
                    this.recordSize = i;
                    break;
                }
            }
            this.fileType = fileType;
            this.fileMode = fileMode;

            if (this.fileMode == FileOpenMode.Output)
            {
                CreateBuffer();
                stream = NativeFile.Open(nativeFileName, FileMode.Create, FileAccess.Write, FileShare.Read);
            }
            else
            {
                buffer = new byte[this.recordSize];
                stream = NativeFile.Open(nativeFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
        }
コード例 #6
0
ファイル: File.cs プロジェクト: PlumpMath/sharpuv
        public void Open(string path, FileAccessMode access, FileOpenMode mode, FilePermissions permissions, Action <UvArgs> callback = null)
        {
            if (this.IsDisposed)
            {
                throw new InvalidOperationException("Cannot open a stream after it has been disposed");
            }

            if (this.Status != FileStatus.Closed)
            {
                throw new InvalidOperationException(String.Format("Cannot open a file handle when it's status is {0}", this.Status));
            }

            IntPtr req = IntPtr.Zero;

            try
            {
                req = this.CreateRequest();
                CheckError(uv_fs_open(this.Loop, req, path, access, mode, permissions, _openDelegate));
                this.Status   = FileStatus.Opening;
                _openCallback = new UvCallback(this, callback);
            }
            catch (Exception)
            {
                this.FreeRequest(req);
                throw;
            }
        }
コード例 #7
0
 public OutStreamer(string filename, FileOpenMode openMode)
 {
     if (openMode == FileOpenMode.RewriteMode)
     {
         File.Delete(filename);
     }
     sw = File.AppendText(filename);
 }
コード例 #8
0
 public override File OpenFile(string path, FilePermissions permissions, FileOpenMode mode)
 {
     using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
     {
         var stream = isolatedStorage.OpenFile(path, EnumConverters.ToFileMode(mode), EnumConverters.ToFileAccess(permissions));
         return(new PhoneFile(path, permissions, stream));
     }
 }
コード例 #9
0
ファイル: FileSystem.cs プロジェクト: jakobharder/burntime
        // return virtual file
        static public File GetFile(FilePath path, FileOpenMode mode)
        {
            if (!path.IsValid)
            {
                Log.Warning("File path invalid: " + path);
                return(null);
            }

            if ((mode & FileOpenMode.NoPackage) == FileOpenMode.NoPackage)
            {
                PackageFactory factory = new PackageFactory();
                return(factory.OpenFileDirectly(GetBasedPath(path.Package), path.PathWithoutPackage, mode));
            }
            else
            {
                if (mode == FileOpenMode.Write)
                {
                    // if we need write access then always use the user package
                    path.Package = "user";
                }

                if (!path.PackageSpecified)
                {
                    File file = vfs.GetFile(path, mode);
                    if (file == null)
                    {
                        Log.Warning("File not found: " + path);
                    }

                    return(file);
                }
                else
                {
                    return(vfs.GetFile(path, mode));
                }
            }

            //    string[] token = path.Package.Split(new char[] { '\\', '/' });
            //if (!dicPackages.ContainsKey(token[token.Length - 1].ToLower()))
            //{
            //    if (PackagePak.IsPak(basePath + path.Package))
            //    {
            //        PackagePak pak = new PackagePak("", basePath + path.Package);
            //        File file = pak.GetFile(path.PathWithoutPackage, false);
            //        pak.Close();

            //        return file;
            //    }
            //    else
            //    {
            //        SystemFile file = new SystemFile(basePath + path.Package + "/" + path.PathWithoutPackage, path, false);
            //        return file;
            //    }
            //}

            //IPackage p = dicPackages[token[token.Length - 1].ToLower()];
            //return p.GetFile(path, WriteAccess);
        }
コード例 #10
0
        // get file from virtual file system
        public File GetFile(FilePath path, FileOpenMode mode)
        {
            if (!path.IsValid)
            {
                return(null);
            }

            // package is specified, look up in package file map
            if (path.PackageSpecified)
            {
                if ((mode & FileOpenMode.NoPackage) == FileOpenMode.NoPackage)
                {
                    PackageFactory factory = new PackageFactory();
                    return(factory.OpenFileDirectly(path.Package, path.PathWithoutPackage, mode));
                }
                else
                {
                    if (!nameMountMap.ContainsKey(path.Package))
                    {
                        return(null);
                    }

                    // translate file name from global name to package name
                    if (nameMountMap[path.Package].FileMap.ContainsKey(path.PathWithoutPackage))
                    {
                        string filepath = nameMountMap[path.Package].FileMap[path.PathWithoutPackage];
                        return(nameMountMap[path.Package].Package.GetFile(filepath, mode));
                    }
                    // if file not found and in write mode directly access package
                    else if (mode == FileOpenMode.Write)
                    {
                        nameMountMap[path.Package].Package.AddFile(path.PathWithoutPackage);
                        RefreshFileMountMap();
                        return(nameMountMap[path.Package].Package.GetFile(path.PathWithoutPackage, mode));
                    }
                }
            }
            // package is not specified, look up in global map
            else
            {
                if ((mode & FileOpenMode.NoPackage) == FileOpenMode.NoPackage)
                {
                    return(null);
                }

                if (fileMountMap.ContainsKey(path.PathWithoutPackage))
                {
                    LinkInfo link = fileMountMap[path.PathWithoutPackage];
                    if (link.FilePath == null)
                    {
                        return(link.Mount.Package.GetFile(path.PathWithoutPackage, mode));
                    }
                    return(link.Mount.Package.GetFile(link.FilePath, mode));
                }
            }

            return(null);
        }
コード例 #11
0
ファイル: File.cs プロジェクト: ashmind/gallery
 public Stream Open(FileLockMode lockMode, FileOpenMode openMode)
 {
     return System.IO.File.Open(
         this.path,
         fileMode[openMode],
         fileAccess[openMode],
         fileShare[lockMode]
     );
 }
コード例 #12
0
        /// <summary>
        /// Gets the file stream.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="access">The access.</param>
        /// <param name="share">The share.</param>
        /// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
        /// <returns>FileStream.</returns>
        public virtual Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, bool isAsync = false)
        {
            if (isAsync)
            {
                return(GetFileStream(path, mode, access, share, FileOpenOptions.Asynchronous));
            }

            return(GetFileStream(path, mode, access, share, FileOpenOptions.None));
        }
コード例 #13
0
ファイル: ManagedFileSystem.cs プロジェクト: rjshaver/Emby
        /// <summary>
        /// Gets the file stream.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="access">The access.</param>
        /// <param name="share">The share.</param>
        /// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
        /// <returns>FileStream.</returns>
        public Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, bool isAsync = false)
        {
            if (_supportsAsyncFileStreams && isAsync)
            {
                return(new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 262144, true));
            }

            return(new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 262144));
        }
 private void menuItemClose_Click(object sender, RoutedEventArgs e)
 {
     if (PromptToSaveUnsavedChanges())
     {
         FileOpen       = FileOpenMode.None;
         UnsavedChanges = false;
         CurrentFile    = new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Starbound Player.player"));
     }
 }
        private void RefreshPropertyGrid()
        {
            if (FileOpen != Prev_FileOpen)
            {
                propertyGrid.SelectedObject = (FileOpen != FileOpenMode.None) ? CurrentPlayerFile : null;
            }

            Prev_FileOpen = FileOpen;
        }
コード例 #16
0
        public static int FileOpen(this IPiGPIO client, string file, FileOpenMode mode)
        {
            int iMode = (int)mode;

            if ((iMode & (int)FileOpenMode.ReadWrite) == 0)
            {
                throw new InvalidOperationException("Must specify read and/or write");
            }
            return(client.FileOpen(file, iMode));
        }
コード例 #17
0
        public static Stream OpenFileStream(this IPiGPIO client, string file, FileOpenMode mode)
        {
            int handle = client.FileOpen(file, mode);

            if (handle < 0)
            {
                throw new PiGPIOException(handle);
            }
            return(new ClientFileStream(client, handle, mode.HasFlag(FileOpenMode.Read), true, mode.HasFlag(FileOpenMode.Write)));
        }
コード例 #18
0
        /// <summary>
        /// 파일 스트림을 데코레이션한 버퍼 스트림을 생성한다.
        /// </summary>
        /// <param name="filename">파일 경로 명</param>
        /// <param name="openMode">열기 모드</param>
        /// <returns>버퍼링되는 파일 스트림, 실패시에는 null 반환</returns>
        public static BufferedStream GetBufferedFileStream(string filename, FileOpenMode openMode)
        {
            filename.ShouldNotBeWhiteSpace("filename");

            if (IsDebugEnabled)
            {
                log.Debug("파일에 대한 BufferedStream을 생성합니다... filename=[{0}], openMode=[{1}]", filename, openMode);
            }

            return(new BufferedStream(GetFileStream(filename, openMode)));
        }
コード例 #19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LazyFileStream"/> class.
        /// </summary>
        /// <param name="path">Path to the file.</param>
        /// <param name="mode">Mode to open the file.</param>
        public LazyFileStream(string path, FileOpenMode mode)
        {
            this.path = path;
            this.mode = mode;

            // Before the stream is initialized, we can get the
            // length so we can report it wihthout opening the file.
            var info = new FileInfo(path);

            initialLength = info.Exists ? info.Length : 0;
        }
コード例 #20
0
 /// <inheritdoc/>
 public async Task <IFileContent> OpenFileAsync(FileOpenMode mode = FileOpenMode.Read)
 {
     if (mode == FileOpenMode.ReadWrite)
     {
         return(new BaseFileContent(File, mode));
     }
     else
     {
         return(new BaseFileContent(File, mode));
     }
 }
コード例 #21
0
ファイル: ManagedFileSystem.cs プロジェクト: vadsaaa/Emby
        public Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, FileOpenOptions fileOpenOptions)
        {
            if (_sharpCifsFileSystem.IsEnabledForPath(path))
            {
                return(_sharpCifsFileSystem.GetFileStream(path, mode, access, share));
            }

            var defaultBufferSize = 4096;

            return(new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), defaultBufferSize, GetFileOptions(fileOpenOptions)));
        }
コード例 #22
0
        /// <summary>
        /// Creates a new <see cref="DataStream"/> from a file.
        /// </summary>
        /// <param name="path">The path of the file.</param>
        /// <param name="mode">The mode to open the file.</param>
        /// <returns>A new <see cref="DataStream"/>.</returns>
        public static DataStream FromFile(string path, FileOpenMode mode)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            var baseStream = new LazyFileStream(path, mode);

            return(new DataStream(baseStream));
        }
コード例 #23
0
        public async Task <Stream> OpenAsync(FileOpenMode mode, CancellationToken cancellation)
        {
            if (mode != FileOpenMode.OPEN_OR_NEW)
            {
                throw new NotSupportedException();
            }

            var raw = await YandexDisk.PerformDownloadRequestAsync(_publicUrl, _rawData.path, cancellation);

            var file = await Utils.DownloadAsync(raw.href, cancellation);

            return(new MemoryStream(file));
        }
コード例 #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataStream"/> class.
        /// </summary>
        /// <param name="filePath">File path.</param>
        /// <param name="mode">File open mode.</param>
        public DataStream(string filePath, FileOpenMode mode)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException(nameof(filePath));
            }

            BaseStream = new FileStream(filePath, mode.ToFileMode(), mode.ToFileAccess());
            Offset     = 0;
            Length     = BaseStream.Length;

            IncreaseStreamCounter(BaseStream);
        }
コード例 #25
0
ファイル: PackageFolder.cs プロジェクト: jakobharder/burntime
        public File GetFile(FilePath filePath, FileOpenMode mode)
        {
            if ((mode & FileOpenMode.NoPackage) == FileOpenMode.NoPackage)
            {
                throw new InvalidOperationException();
            }

            if (!dicFiles.ContainsKey(filePath.PathWithoutPackage))
            {
                return(null);
            }
            return(new SystemFile(path + "/" + subPath + filePath.PathWithoutPackage, name + ":" + filePath.PathWithoutPackage, mode == FileOpenMode.Write));
        }
コード例 #26
0
ファイル: ManagedFileSystem.cs プロジェクト: voxadam/Emby
        /// <summary>
        /// Gets the file stream.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="access">The access.</param>
        /// <param name="share">The share.</param>
        /// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
        /// <returns>FileStream.</returns>
        public Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, bool isAsync = false)
        {
            if (_sharpCifsFileSystem.IsEnabledForPath(path))
            {
                return(_sharpCifsFileSystem.GetFileStream(path, mode, access, share));
            }

            if (_supportsAsyncFileStreams && isAsync)
            {
                return(new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 262144, true));
            }

            return(new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 262144));
        }
コード例 #27
0
ファイル: ManagedFileSystem.cs プロジェクト: vadsaaa/Emby
        /// <summary>
        /// Gets the file stream.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="access">The access.</param>
        /// <param name="share">The share.</param>
        /// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
        /// <returns>FileStream.</returns>
        public Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, bool isAsync = false)
        {
            if (_sharpCifsFileSystem.IsEnabledForPath(path))
            {
                return(_sharpCifsFileSystem.GetFileStream(path, mode, access, share));
            }

            if (_supportsAsyncFileStreams && isAsync)
            {
                return(GetFileStream(path, mode, access, share, FileOpenOptions.Asynchronous));
            }

            return(GetFileStream(path, mode, access, share, FileOpenOptions.None));
        }
コード例 #28
0
        public static FileAccessMode ToUwp(this FileOpenMode openMode)
        {
            switch (openMode)
            {
            case FileOpenMode.Read:
                return(FileAccessMode.Read);

            case FileOpenMode.ReadWrite:
                return(FileAccessMode.ReadWrite);

            default:
                throw new StorageAccessException($"Failed to find the FileAccessMode to access the file content in mode {openMode}");
            }
        }
 private void menuItemOpen_Click(object sender, RoutedEventArgs e)
 {
     if (PromptToSaveUnsavedChanges())
     {
         OpenFileDialog ofd = GetOpenFileDialog();
         ofd.ShowDialog();
         if (!string.IsNullOrEmpty(ofd.FileName))
         {
             CurrentFile = new FileInfo(ofd.FileName);
             LoadCurrentFile();
             FileOpen       = FileOpenMode.Opened;
             UnsavedChanges = false;
         }
     }
 }
コード例 #30
0
    /// <summary>
    /// Opens a file for reading/saving
    /// </summary>
    /// <param name="path">File path</param>
    /// <param name="mode">Whether to open the file for reading or writing</param>
    /// <param name="encodeType">Encoding type to use for string based values</param>
    public FileHandler(string path, FileOpenMode mode, Encoding encodeType)
    {
        encoding     = encodeType;
        fileOpenMode = mode;

        if (fileOpenMode == FileOpenMode.Reading)
        {
            fileStream   = File.OpenRead(path);
            binaryReader = new BinaryReader(fileStream);
        }
        else if (fileOpenMode == FileOpenMode.Writing)
        {
            fileStream   = File.OpenWrite(path);
            binaryWriter = new BinaryWriter(fileStream);
        }
    }
コード例 #31
0
        public async Task <Stream> OpenAsync(FileOpenMode mode, CancellationToken cancellation)
        {
            switch (Access)
            {
            case IOAccess.READ_ONLY:
                break;

            case IOAccess.FULL:
                IOUtils.CreateDirectoryIfNotExist(Path.GetDirectoryName(_path));
                break;

            default:
                throw new NotSupportedException();
            }

            return(File.Open(_path, mapMode(), mapAccess(Access)));

            FileMode mapMode()
            {
                switch (mode)
                {
                case FileOpenMode.OPEN_OR_NEW:
                    return(FileMode.OpenOrCreate);

                case FileOpenMode.NEW:
                    return(FileMode.Create);

                default:
                    throw new NotSupportedException();
                }
            }

            System.IO.FileAccess mapAccess(IOAccess access)
            {
                switch (access)
                {
                case IOAccess.READ_ONLY:
                    return(System.IO.FileAccess.Read);

                case IOAccess.FULL:
                    return(System.IO.FileAccess.ReadWrite);

                default:
                    throw new NotSupportedException();
                }
            }
        }
        private bool SaveAs()
        {
            SaveFileDialog sfd = GetSaveFileDialog();

            DialogResult dr = sfd.ShowDialog();

            if (dr == System.Windows.Forms.DialogResult.OK && !string.IsNullOrEmpty(sfd.FileName))
            {
                CurrentFile = new FileInfo(sfd.FileName);
                FileOpen    = FileOpenMode.Opened;
                SaveCurrentFile();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #33
0
ファイル: MemoryFile.cs プロジェクト: ashmind/gallery
        public Stream Open(FileLockMode lockMode, FileOpenMode openMode)
        {
            if (!this.stream.CanWrite) // disposed
                this.ReopenStream();

            if (openMode == FileOpenMode.Append) {
                this.stream.Seek(0, SeekOrigin.End);
                return this.stream;
            }

            if (openMode == FileOpenMode.ReadOrWrite) {
                this.stream.Seek(0, SeekOrigin.Begin);
                return this.stream;
            }

            if (openMode == FileOpenMode.Recreate) {
                this.stream = new MemoryStream();
                return this.stream;
            }

            throw new ArgumentOutOfRangeException("openMode");
        }
コード例 #34
0
ファイル: File.cs プロジェクト: michaelgwelch/mbasic99
        private File(IDeviceMapping deviceMap, String fileName, FileOrganization org, FileType fileType,
                     FileOpenMode mode, FileRecordType recordType)
        {
            //if (fileName != CS1 && fileName != CS2) throw new InvalidOperationException("Only fileNames of CS1 and CS2 are currently supported");

            String nativeFileName = deviceMap.GetNativeFileName(fileName);
            //if (fileName == CS2 && mode == FileOpenMode.Input) throw new InvalidOperationException("Can't use CS2 for Input");
            if (org != FileOrganization.Sequential) throw new InvalidOperationException("CS1 and CS2 only support sequential");
            if (recordType != FileRecordType.Fixed) throw new InvalidOperationException("CS1 and CS2 only support Fixed");
            if (fileType != FileType.Internal) throw new NotImplementedException("Internal is preferred for casettes, Display is not yet implemented.");
            if (mode == FileOpenMode.Input)
            {
                FileStream stream = NativeFile.Open(nativeFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                reader = new StreamReader(stream, encoding);
            }
            else
            {
                FileStream stream = NativeFile.Open(nativeFileName, FileMode.Create, FileAccess.Write, FileShare.Read);

                writer = new StreamWriter(stream, encoding);
                writer.AutoFlush = true;

            }

            isCasette = true;
        }
コード例 #35
0
ファイル: File.cs プロジェクト: michaelgwelch/mbasic99
 public static File Open(IDeviceMapping deviceMap, String fileName, FileOrganization org, FileType fileType, 
                         FileOpenMode mode, FileRecordType recordType)
 {
     return new File(deviceMap, fileName, org, fileType, mode, recordType);
 }
コード例 #36
0
        public void Open(string path, FileAccessMode rw, FileOpenMode open, FilePermissions permissions)
        {
            if (this.Status != FileHandleStatus.Closed)
                return;

            var req = this.CreateRequest();

            try
            {
                CheckError(Uvi.uv_fs_open(this.Loop.Handle, req, path, rw, open, permissions, this.OnOpen));
                this.Status = FileHandleStatus.Opening;
            }
            catch (Exception)
            {
                this.FreeRequest(req, false);
                throw;
            }
        }
コード例 #37
0
ファイル: AFC.cs プロジェクト: exaphaser/iOSLib
        internal static AFCError openPhoto(Photo photo, string photoPath, iDevice device, FileOpenMode openMode, out IntPtr afcClient, out ulong fileHandle)
        {
            fileHandle = 0;
            AFCError returnCode = afc_client_start_service(device.handle, out afcClient, "iOSLib");
            if (returnCode != AFCError.AFC_E_SUCCESS)
            {
                return returnCode;
            }

            if ((returnCode = afc_file_open(afcClient, photoPath + photo.getName(), openMode, out fileHandle))
                != AFCError.AFC_E_SUCCESS)
            {
                afc_client_free(afcClient);
            }

            return returnCode;
        }
コード例 #38
0
ファイル: FileTool.cs プロジェクト: debop/NFramework
        /// <summary>
        /// 파일 스트림 <see cref="System.IO.FileStream"/>을 생성해 준다.
        /// </summary>
        /// <param name="filename">대상 파일 경로</param>
        /// <param name="openMode">열기 모드</param>
        /// <returns>파일 스트림, 실패시에는 null 반환</returns>
        /// <exception cref="FileNotFoundException">파일이 존재하지 않을 때</exception>
        public static FileStream GetFileStream(string filename, FileOpenMode openMode) {
            filename.ShouldNotBeWhiteSpace("filename");

            if(openMode == FileOpenMode.Read && !FileExists(filename))
                throw new FileNotFoundException("파일이 존재하지 않습니다.", filename);

            switch(openMode) {
                case FileOpenMode.Read:
                    return new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);

                case FileOpenMode.ReadWrite:
                    return new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);

                case FileOpenMode.Write:
                    return new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);

                default:
                    return new FileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read);
            }
        }
コード例 #39
0
ファイル: File.cs プロジェクト: gigi81/sharpuv
        public void Open(string path, FileAccessMode access, FileOpenMode mode, FilePermissions permissions, Action<UvArgs> callback = null)
        {
            if (this.IsDisposed)
                throw new InvalidOperationException("Cannot open a stream after it has been disposed");

            if (this.Status != FileStatus.Closed)
                throw new InvalidOperationException(String.Format("Cannot open a file handle when it's status is {0}", this.Status));

            IntPtr req = IntPtr.Zero;

            try
            {
                req = this.CreateRequest();
                CheckError(uv_fs_open(this.Loop, req, path, access, mode, permissions, _openDelegate));
                this.Status = FileStatus.Opening;
                _openCallback = new UvCallback(this, callback);
            }
            catch (Exception)
            {
                this.FreeRequest(req);
                throw;
            }
        }
コード例 #40
0
ファイル: FileTool.cs プロジェクト: debop/NFramework
        /// <summary>
        /// 파일 스트림을 데코레이션한 버퍼 스트림을 생성한다.
        /// </summary>
        /// <param name="filename">파일 경로 명</param>
        /// <param name="openMode">열기 모드</param>
        /// <returns>버퍼링되는 파일 스트림, 실패시에는 null 반환</returns>
        public static BufferedStream GetBufferedFileStream(string filename, FileOpenMode openMode) {
            filename.ShouldNotBeWhiteSpace("filename");

            if(IsDebugEnabled)
                log.Debug("파일에 대한 BufferedStream을 생성합니다... filename=[{0}], openMode=[{1}]", filename, openMode);

            return new BufferedStream(GetFileStream(filename, openMode));
        }
コード例 #41
0
ファイル: Resource.cs プロジェクト: ashmind/gallery
 public Stream Open(FileLockMode lockMode, FileOpenMode openMode)
 {
     throw new NotImplementedException();
 }
コード例 #42
0
ファイル: AFC.cs プロジェクト: rajeshwarn/iOSLibDataCollector
 static extern AFCError afc_file_open(IntPtr client, string fileName, FileOpenMode fileMode, out ulong handle);
コード例 #43
0
ファイル: File.cs プロジェクト: gigi81/sharpuv
 private static int uv_fs_open(Loop loop, IntPtr req, string path, FileAccessMode rw, FileOpenMode open, FilePermissions permissions, uv_fs_cb cb)
 {
     return Uvi.uv_fs_open(loop.Handle, req, path, (int)rw | (int)open, (int)permissions, cb);
 }