/// <summary> /// Save the current file under a different name. /// ! NOT really efficient, should only be used for small files ! /// </summary> public void CommitChangesAs() { if (rpHexEditor.ByteDataSource.GetType() == typeof(RPHexEditor.MemoryByteData)) { this.CommitChanges(); return; } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); saveFileDialog.Filter = _fileFilter; if (saveFileDialog.ShowDialog(this) != DialogResult.OK) { return; } RPHexEditor.FileByteData fileByteData = rpHexEditor.ByteDataSource as RPHexEditor.FileByteData; FileStream _fileStream = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.ReadWrite); for (int i = 0; i < fileByteData.Length; i++) { _fileStream.WriteByte(fileByteData.ReadByte(i)); } _fileStream.Dispose(); RPHexEditorForm childForm = new RPHexEditorForm(); childForm.MdiParent = this.MdiParent; childForm.Text = saveFileDialog.FileName; childForm.LoadFile(saveFileDialog.FileName); childForm.Show(); }
/// <summary> /// Save the current file. /// </summary> public void CommitChanges() { if (rpHexEditor.ByteDataSource.GetType() == typeof(RPHexEditor.MemoryByteData)) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); saveFileDialog.Filter = _fileFilter; if (saveFileDialog.ShowDialog(this) != DialogResult.OK) { return; } FileStream _fileDataStream = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.ReadWrite); RPHexEditor.MemoryByteData md = rpHexEditor.ByteDataSource as RPHexEditor.MemoryByteData; _fileDataStream.Write(md.Bytes.ToArray(), 0, md.Bytes.Count); _fileDataStream.Dispose(); this._fileByteData = new RPHexEditor.FileByteData(saveFileDialog.FileName); this._fileByteData.DataChanged += new EventHandler(OnFileByteDataDataChanged); this._fileByteData.DataLengthChanged += new EventHandler(OnFileByteDataDataLengthChanged); rpHexEditor.ByteDataSource = _fileByteData; this.Text = saveFileDialog.FileName; } rpHexEditor.CommitChanges(); }
public string GetFileName() { if (rpHexEditor.ByteDataSource.GetType() == typeof(RPHexEditor.MemoryByteData)) { return("Untitled"); } else { RPHexEditor.FileByteData fd = rpHexEditor.ByteDataSource as RPHexEditor.FileByteData; return(fd.FileName); } }
public bool LoadFile(string fileName, bool readOnly = false) { bool bRet = false; try { this._fileByteData = new RPHexEditor.FileByteData(fileName, readOnly); rpHexEditor.ByteDataSource = this._fileByteData; _fileByteData.DataChanged += new EventHandler(OnFileByteDataDataChanged); _fileByteData.DataLengthChanged += new EventHandler(OnFileByteDataDataLengthChanged); bRet = true; } catch (Exception ex) { string msg = string.Format("Failed to open file '{0}'.\n{1}", fileName, ex.Message); MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(bRet); }