DS-Pokemon-Rom-Editor/DS_Map/ROMFiles/RomFile.cs
AdAstra-LD 5e14b76ec6 Major Trainer Editor cleanup
[+] Fixed Trainer Class Save button updating class name in combobox

[-] Party Data import is still buggy

TO FIX:
button of search in script icons [CTRL+F]
text size columns [camera editor]
trainer table combo update [combobox]
2021-11-26 03:33:14 +01:00

44 lines
1.6 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 is null) {
Console.WriteLine(GetType().Name + " couldn't be saved!");
return;
}
File.WriteAllBytes(path, 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);
}
}
}