mirror of
https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor.git
synced 2026-05-10 06:01:05 -05:00
- Add NSBTX and Remove NSBTX buttons also add/remove building configuration file [NSBTX Editor] - Changed format of Script Editor display - Added highlighting of 'Script', 'Function' and 'Action' keywords (only upon reloading) - Changed Endcodes database to HashSet (PokeDatabase -> ScriptEditor) - Minor refactor
42 lines
1.7 KiB
C#
42 lines
1.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using static DSPRE.RomInfo;
|
|
|
|
namespace DSPRE.ROMFiles {
|
|
public abstract class RomFile {
|
|
public abstract byte[] ToByteArray();
|
|
public void SaveToFile(string path, bool showSuccessMessage = true) {
|
|
|
|
byte[] romFileToByteArray = ToByteArray();
|
|
if (romFileToByteArray == null) {
|
|
Console.WriteLine(GetType().Name + " couldn't be saved!");
|
|
return;
|
|
}
|
|
|
|
using (BinaryWriter writer = new BinaryWriter(new FileStream(path, FileMode.Create))) {
|
|
writer.Write(romFileToByteArray);
|
|
}
|
|
|
|
if (showSuccessMessage)
|
|
MessageBox.Show(GetType().Name + " saved successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
protected internal void SaveToFileDefaultDir(DirNames dir, int IDtoReplace, bool showSuccessMessage = true) {
|
|
string path = RomInfo.gameDirs[dir].unpackedDir + "\\" + IDtoReplace.ToString("D4");
|
|
this.SaveToFile(path, showSuccessMessage);
|
|
}
|
|
protected internal void SaveToFileExplorePath(string fileType, string fileExtension, string suggestedFileName, bool showSuccessMessage = true) {
|
|
SaveFileDialog sf = new SaveFileDialog {
|
|
Filter = fileType + ' ' + "(*." + fileExtension + '|' + "(*." + fileExtension
|
|
};
|
|
|
|
if (!string.IsNullOrEmpty(suggestedFileName))
|
|
sf.FileName = suggestedFileName;
|
|
if (sf.ShowDialog() != DialogResult.OK)
|
|
return;
|
|
|
|
this.SaveToFile(sf.FileName, showSuccessMessage);
|
|
}
|
|
}
|
|
}
|