///<summary> /// Load the buffer with a file ///</summary> public void Load(string filename) { if (reader != null) { reader.Close(); } OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; if (pid == PlatformID.Unix) { UnixFileInfo fsInfo = new UnixFileInfo(filename); if (!fsInfo.Exists) { throw new FileNotFoundException(fsInfo.FullName); } // get the size of the file or device if (fsInfo.IsRegularFile) { FileLength = fsInfo.Length; isResizable = true; } else if (fsInfo.IsBlockDevice) { UnixStream unixStream = fsInfo.OpenRead(); ioctl(unixStream.Handle, BLKGETSIZE64, ref FileLength); unixStream.Close(); isResizable = false; } else { throw new NotSupportedException("File object isn't a regular or block device."); } } Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read); if (stream.CanSeek == false) { throw new NotSupportedException("File object doesn't support seeking."); } if (pid != PlatformID.Unix) { FileLength = stream.Seek(0, SeekOrigin.End); stream.Seek(0, SeekOrigin.Begin); isResizable = false; } reader = new BinaryReader(stream); winOccupied = reader.Read(window, 0, window.Length); winOffset = 0; }
///<summary> /// Load the buffer with a file ///</summary> public void Load(string filename) { if (reader != null) { reader.Close(); } #if ENABLE_UNIX_SPECIFIC UnixFileInfo fsInfo = new UnixFileInfo(filename); if (!fsInfo.Exists) { throw new FileNotFoundException(fsInfo.FullName); } // get the size of the file or device if (fsInfo.IsRegularFile) { FileLength = fsInfo.Length; isResizable = true; } else if (fsInfo.IsBlockDevice) { UnixStream unixStream = fsInfo.OpenRead(); ioctl(unixStream.Handle, BLKGETSIZE64, ref FileLength); unixStream.Close(); isResizable = false; } else { throw new NotSupportedException("File object isn't a regular or block device."); } #endif Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); if (stream.CanSeek == false) { throw new NotSupportedException("File object doesn't support seeking."); } #if !ENABLE_UNIX_SPECIFIC FileLength = stream.Seek(0, SeekOrigin.End); stream.Seek(0, SeekOrigin.Begin); isResizable = false; #endif reader = new BinaryReader(stream); winOccupied = reader.Read(window, 0, window.Length); winOffset = 0; }