/// <summary> /// Load ID3v1 information from file /// </summary> public void Load() { FileStreamEx FS = new FileStreamEx(_FilePath, FileMode.Open); if (!FS.HaveID3v1()) { FS.Close(); _HaveTag = false; return; } _Title = FS.ReadText(30, TextEncodings.Ascii); FS.Seek(-95, SeekOrigin.End); _Artist = FS.ReadText(30, TextEncodings.Ascii); FS.Seek(-65, SeekOrigin.End); _Album = FS.ReadText(30, TextEncodings.Ascii); FS.Seek(-35, SeekOrigin.End); _Year = FS.ReadText(4, TextEncodings.Ascii); FS.Seek(-31, SeekOrigin.End); _Comment = FS.ReadText(28, TextEncodings.Ascii); FS.Seek(-2, SeekOrigin.End); _TrackNumber = FS.ReadByte(); _Genre = (Genre)FS.ReadByte(); FS.Close(); _HaveTag = true; }
private void bOpen_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "XeEngine entity definition|*.ent"; openFileDialog.AddExtension = true; openFileDialog.CheckPathExists = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { FileStreamEx f; try { f = new FileStreamEx(openFileDialog.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read); FileName = openFileDialog.FileName; } catch (System.Exception ex) { LaunchError(ex.Message); return; } entity.Load(f); f.Close(); RefreshGUI(); } }
/// <summary> /// Save ID3v1 information to file /// </summary> public void Save() { FileStreamEx fs = new FileStreamEx(_FilePath, FileMode.Open); bool HTag = fs.HaveID3v1(); if (HTag && !_HaveTag) // just delete ID3 { fs.SetLength(fs.Length - 128); } else if (!HTag && _HaveTag) { fs.Seek(0, SeekOrigin.End); fs.Write(GetTagBytes, 0, 128); } else if (HTag && _HaveTag) { fs.Seek(-128, SeekOrigin.End); fs.Write(GetTagBytes, 0, 128); } else { fs.Seek(0, SeekOrigin.End); fs.Write(GetTagBytes, 0, 128); } fs.Close(); }
/// <summary> /// Sector refers to physical disk blocks, we can only read complete blocks /// </summary> public byte[] ReadSectorsUnbuffered(long sectorIndex, int sectorCount) { bool releaseHandle; SafeFileHandle handle = PhysicalDiskHandlePool.ObtainHandle(m_physicalDiskIndex, FileAccess.Read, ShareMode.ReadWrite, out releaseHandle); if (!handle.IsInvalid) { FileStreamEx stream = new FileStreamEx(handle, FileAccess.Read); byte[] buffer = new byte[m_bytesPerSector * sectorCount]; try { stream.Seek(sectorIndex * m_bytesPerSector, SeekOrigin.Begin); stream.Read(buffer, 0, m_bytesPerSector * sectorCount); } finally { stream.Close(releaseHandle); if (releaseHandle) { PhysicalDiskHandlePool.ReleaseHandle(m_physicalDiskIndex); } } return(buffer); } else { // we always release invalid handle PhysicalDiskHandlePool.ReleaseHandle(m_physicalDiskIndex); // get error code and throw int errorCode = Marshal.GetLastWin32Error(); string message = String.Format("Failed to read sector {0} from disk {1}.", sectorIndex, m_physicalDiskIndex); IOExceptionHelper.ThrowIOError(errorCode, message); return(null); // this line will not be reached } }
private void bSave_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "XeEngine entity definition|*.ent"; saveFileDialog.AddExtension = true; saveFileDialog.CheckPathExists = true; saveFileDialog.FileName = filename; if (saveFileDialog.ShowDialog() == DialogResult.OK) { FileStreamEx f; try { f = new FileStreamEx(saveFileDialog.FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write); FileName = saveFileDialog.FileName; } catch (System.Exception ex) { LaunchError(ex.Message); return; } entity.Animation.RemoveEmptyAnimations(); entity.Save(f); f.Close(); } }
public void SaveProject(string filename) { FileStreamEx f = new FileStreamEx(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write); f.Write8((byte)animList.Count); f.Write8((byte)animList[0].source.Resolution); f.Write16((ushort)(animList[0].source.BitsPerPixel * animList[0].source.Resolution * 16 * 16 / 8)); for (int i = 0; i < animList.Count; i++) { animList[i].Save(f); } for (int i = 0; i < animList.Count; i++) { int j = 0; do { f.Write8(animList[i].pat[j]); } while (animList[i].pat[j] != 0xFF); } for (int i = 0; i < animList.Count; i++) { animList[i].source.SaveRawData(ref animList[i].bmp, f); } f.Close(); }
/// <summary> /// Sector refers to physical disk blocks, we can only read complete blocks /// </summary> public byte[] ReadSectorsUnbuffered(long sectorIndex, int sectorCount) { bool releaseHandle; SafeFileHandle handle = VolumeHandlePool.ObtainHandle(m_volumeGuid, FileAccess.Read, ShareMode.ReadWrite, out releaseHandle); if (!handle.IsInvalid) { FileStreamEx stream = new FileStreamEx(handle, FileAccess.Read); byte[] buffer = new byte[m_bytesPerSector * sectorCount]; try { stream.Seek(sectorIndex * m_bytesPerSector, SeekOrigin.Begin); stream.Read(buffer, 0, m_bytesPerSector * sectorCount); } finally { stream.Close(releaseHandle); if (releaseHandle) { VolumeHandlePool.ReleaseHandle(m_volumeGuid); } } return(buffer); } else { // we always release invalid handle VolumeHandlePool.ReleaseHandle(m_volumeGuid); // get error code and throw int errorCode = Marshal.GetLastWin32Error(); string message = String.Format("Can't read sector {0} from volume {1}, Win32 Error: {2}", sectorIndex, m_volumeGuid, errorCode); throw new IOException(message); } }
public void LoadProject(string filename) { FileStreamEx f = new FileStreamEx(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read); f.Close(); }
public void WriteSectorsUnbuffered(long sectorIndex, byte[] data) { if (data.Length % m_bytesPerSector > 0) { throw new IOException("Cannot write partial sectors"); } if (IsReadOnly) { throw new UnauthorizedAccessException("Attempted to perform write on a readonly disk"); } bool releaseHandle; SafeFileHandle handle = PhysicalDiskHandlePool.ObtainHandle(m_physicalDiskIndex, FileAccess.ReadWrite, ShareMode.Read, out releaseHandle); if (!handle.IsInvalid) { FileStreamEx stream = new FileStreamEx(handle, FileAccess.Write); try { stream.Seek(sectorIndex * m_bytesPerSector, SeekOrigin.Begin); stream.Write(data, 0, data.Length); stream.Flush(); } finally { stream.Close(releaseHandle); if (releaseHandle) { PhysicalDiskHandlePool.ReleaseHandle(m_physicalDiskIndex); } } } else { // we always release invalid handle PhysicalDiskHandlePool.ReleaseHandle(m_physicalDiskIndex); // get error code and throw int errorCode = Marshal.GetLastWin32Error(); string message = String.Format("Failed to write to sector {0} of disk {1}.", sectorIndex, m_physicalDiskIndex); IOExceptionHelper.ThrowIOError(errorCode, message); } }
public void WriteSectorsUnbuffered(long sectorIndex, byte[] data) { if (data.Length % m_bytesPerSector > 0) { throw new IOException("Cannot write partial sectors"); } if (!m_isReadOnly) { bool releaseHandle; SafeFileHandle handle = VolumeHandlePool.ObtainHandle(m_volumeGuid, FileAccess.ReadWrite, ShareMode.None, out releaseHandle); if (!handle.IsInvalid) { FileStreamEx stream = new FileStreamEx(handle, FileAccess.Write); try { stream.Seek(sectorIndex * m_bytesPerSector, SeekOrigin.Begin); stream.Write(data, 0, data.Length); stream.Flush(); } finally { stream.Close(releaseHandle); if (releaseHandle) { VolumeHandlePool.ReleaseHandle(m_volumeGuid); } } } else { // we always release invalid handle VolumeHandlePool.ReleaseHandle(m_volumeGuid); // get error code and throw int errorCode = Marshal.GetLastWin32Error(); string message = String.Format("Can't write to sector {0} of volume {1}, Win32 errorCode: {2}", sectorIndex, m_volumeGuid, errorCode); throw new IOException(message); } } }