Rename variables to make more sense, apply formatting

pull/7/head
Miepee 4 years ago
parent 1cd56416cb
commit 8f3947b4ee

@ -10,16 +10,7 @@ public partial class ModPacker : Form
public ModPacker() public ModPacker()
{ {
profile = new ModProfileXML("", 1, "", "", "", false, "", false, false, ""); // (1, "", "", false, "default", false, false); profile = new ModProfileXML("", 1, "", "", "", false, "", false, false, ""); // (1, "", "", false, "default", false, false);
isOriginalLoaded = false; localPath =
isModLoaded = false;
isApkLoaded = false;
isLinuxLoaded = false;
localPath = Directory.GetCurrentDirectory();
originalPath = "";
modPath = "";
linuxPath = "";
apkPath = "";
Title = "AM2R ModPacker " + VERSION; Title = "AM2R ModPacker " + VERSION;
// Currently broken as I don't know how to do this from Rider // Currently broken as I don't know how to do this from Rider
@ -33,8 +24,8 @@ public partial class ModPacker : Form
// Left side // Left side
var modInfoPanel = new DynamicLayout() { Spacing = new Size(5, 5) }; var modInfoPanel = new DynamicLayout() { Spacing = new Size(5, 5) };
modInfoPanel.AddRow(nameLabel, NameTextBox); modInfoPanel.AddRow(nameLabel, nameTextBox);
modInfoPanel.AddRow(authorLabel, AuthorTextBox); modInfoPanel.AddRow(authorLabel, authorTextBox);
modInfoPanel.AddRow(versionLabel, versionTextBox); modInfoPanel.AddRow(versionLabel, versionTextBox);
modInfoPanel.AddRow(modNotesLabel); modInfoPanel.AddRow(modNotesLabel);
@ -47,26 +38,26 @@ public partial class ModPacker : Form
// Right Side // Right Side
var savePanel = new DynamicLayout(); var savePanel = new DynamicLayout();
savePanel.AddRow(SaveCheckBox, null, winSaveButton); savePanel.AddRow(customSaveCheckBox, null, customSaveButton);
var saveTextPanel = new DynamicLayout(); var saveTextPanel = new DynamicLayout();
saveTextPanel.AddRow(saveTextBox); saveTextPanel.AddRow(customSaveTextBox);
var miscOptionsPanel = new DynamicLayout() { Spacing = new Size(5, 5) }; var miscOptionsPanel = new DynamicLayout() { Spacing = new Size(5, 5) };
miscOptionsPanel.AddRow(MusicCheckBox); miscOptionsPanel.AddRow(musicCheckBox);
miscOptionsPanel.AddRow(YYCCheckBox); miscOptionsPanel.AddRow(yycCheckBox);
miscOptionsPanel.AddRow(AndroidCheckBox); miscOptionsPanel.AddRow(apkCheckBox);
miscOptionsPanel.AddRow(ApkButton, ApkLabel); miscOptionsPanel.AddRow(apkButton, apkLabel);
miscOptionsPanel.AddRow(linuxCheckBox); miscOptionsPanel.AddRow(linuxCheckBox);
miscOptionsPanel.AddRow(linuxButton, linuxLabel); miscOptionsPanel.AddRow(linuxButton, linuxLabel);
var loadZipsPanel = new DynamicLayout() { Spacing = new Size(5, 5) }; var loadZipsPanel = new DynamicLayout() { Spacing = new Size(5, 5) };
loadZipsPanel.AddRow(OriginalButton, null, ModButton); loadZipsPanel.AddRow(originalZipButton, null, modZipButton);
loadZipsPanel.AddRow(OriginalLabel, null, ModLabel); loadZipsPanel.AddRow(originalZipLabel, null, modZipLabel);
var resultPanel = new DynamicLayout() { Spacing = new Size(5, 5) }; var resultPanel = new DynamicLayout() { Spacing = new Size(5, 5) };
resultPanel.AddRow(CreateButton); resultPanel.AddRow(createButton);
resultPanel.AddRow(CreateLabel); resultPanel.AddRow(createLabel);
// Combine together // Combine together
rightSide.AddRow(savePanel); rightSide.AddRow(savePanel);
@ -88,47 +79,47 @@ public partial class ModPacker : Form
Content = mainContent; Content = mainContent;
// Assign events // Assign events
OriginalButton.Click += OriginalButton_Click; originalZipButton.Click += OriginalZipButton_Click;
ModButton.Click += ModButton_Click; modZipButton.Click += ModZipButton_Click;
CreateButton.Click += CreateButton_Click; createButton.Click += CreateButton_Click;
ApkButton.Click += ApkButton_Click; apkButton.Click += ApkButton_Click;
AndroidCheckBox.CheckedChanged += AndroidCheckBox_CheckedChanged; apkCheckBox.CheckedChanged += ApkCheckBoxCheckedChanged;
SaveCheckBox.CheckedChanged += SaveCheckBox_CheckedChanged; customSaveCheckBox.CheckedChanged += CustomSaveCheckBoxChecked_Changed;
linuxCheckBox.CheckedChanged += linuxCheckBox_CheckedChanged; linuxCheckBox.CheckedChanged += LinuxCheckBox_CheckedChanged;
linuxButton.Click += linuxButton_Click; linuxButton.Click += LinuxButton_Click;
winSaveButton.Click += CustomSaveDataButton_Click; customSaveButton.Click += CustomSaveDataButton_Click;
} }
#region Design Elements #region Design Elements
private Label nameLabel = new Label() { Text = "Mod name:" }; private Label nameLabel = new Label() { Text = "Mod name:" };
private TextBox NameTextBox = new TextBox(); private TextBox nameTextBox = new TextBox();
private Label authorLabel = new Label() { Text = "Author:" }; private Label authorLabel = new Label() { Text = "Author:" };
private TextBox AuthorTextBox = new TextBox(); private TextBox authorTextBox = new TextBox();
private Label versionLabel = new Label() { Text = "Version:" }; private Label versionLabel = new Label() { Text = "Version:" };
private TextBox versionTextBox = new TextBox(); private TextBox versionTextBox = new TextBox();
private Label modNotesLabel = new Label() { Text = "Mod notes:" }; private Label modNotesLabel = new Label() { Text = "Mod notes:" };
private TextArea modNotesTextBox = new TextArea() { }; private TextArea modNotesTextBox = new TextArea() { };
private CheckBox SaveCheckBox = new CheckBox() { Text = "Uses custom save directory" }; private CheckBox customSaveCheckBox = new CheckBox() { Text = "Uses custom save directory" };
private Button winSaveButton = new Button() { Text = "Select folder", Enabled = false }; private Button customSaveButton = new Button() { Text = "Select folder", Enabled = false };
private TextBox saveTextBox = new TextBox(); private TextBox customSaveTextBox = new TextBox();
private CheckBox MusicCheckBox = new CheckBox() { Text = "Uses custom music" }; private CheckBox musicCheckBox = new CheckBox() { Text = "Uses custom music" };
private CheckBox YYCCheckBox = new CheckBox() { Text = "Uses the YoYo Compiler" }; private CheckBox yycCheckBox = new CheckBox() { Text = "Uses the YoYo Compiler" };
private CheckBox AndroidCheckBox = new CheckBox() { Text = "Supports Android" }; private CheckBox apkCheckBox = new CheckBox() { Text = "Supports Android" };
private Button ApkButton = new Button() { Text = "Load modded Android APK", Enabled = false }; private Button apkButton = new Button() { Text = "Load modded Android APK", Enabled = false };
private Label ApkLabel = new Label() { Text = "Modded APK loaded!", Visible = false }; private Label apkLabel = new Label() { Text = "Modded APK loaded!", Visible = false };
private CheckBox linuxCheckBox = new CheckBox() { Text = "Supports Linux" }; private CheckBox linuxCheckBox = new CheckBox() { Text = "Supports Linux" };
private Button linuxButton = new Button() { Text = "Load modded Linux .zip", Enabled = false }; private Button linuxButton = new Button() { Text = "Load modded Linux .zip", Enabled = false };
private Label linuxLabel = new Label() { Text = "Modded Linux game loaded!", Visible = false }; private Label linuxLabel = new Label() { Text = "Modded Linux game loaded!", Visible = false };
private Button OriginalButton = new Button() { Text = "Load 1.1" }; private Button originalZipButton = new Button() { Text = "Load 1.1" };
private Label OriginalLabel = new Label() { Text = "1.1 loaded!", Visible = false}; private Label originalZipLabel = new Label() { Text = "1.1 loaded!", Visible = false};
private Button ModButton = new Button() { Text = "Load modded game" }; private Button modZipButton = new Button() { Text = "Load modded game" };
private Label ModLabel = new Label() { Text = "Mod loaded!", Visible = false }; private Label modZipLabel = new Label() { Text = "Mod loaded!", Visible = false };
private Button CreateButton = new Button() { Text = "Create mod package(s)", Enabled = false }; private Button createButton = new Button() { Text = "Create mod package(s)", Enabled = false };
private Label CreateLabel = new Label() { Text = "Mod package created!", Visible = false}; private Label createLabel = new Label() { Text = "Mod package created!", Visible = false};
#endregion #endregion
} }

@ -12,58 +12,98 @@ namespace AM2RModPacker;
public partial class ModPacker : Form public partial class ModPacker : Form
{ {
private static readonly string VERSION = "2.0.3"; private const string VERSION = "2.0.3";
private static readonly string ORIGINAL_MD5 = "f2b84fe5ba64cb64e284be1066ca08ee"; private const string ORIGINAL_MD5 = "f2b84fe5ba64cb64e284be1066ca08ee";
private bool isOriginalLoaded, isModLoaded, isApkLoaded, isLinuxLoaded; private bool isOriginalLoaded, isModLoaded, isApkLoaded, isLinuxLoaded;
private string localPath, originalPath, modPath, apkPath, linuxPath; // TODO: do not get current directory, wont end well
private static readonly string[] DATAFILES_BLACKLIST = { "data.win", "AM2R.exe", "D3DX9_43.dll", "game.unx" }; private readonly string localPath = Directory.GetCurrentDirectory();
private static string saveFilePath = null; private string originalPath, modPath, apkPath, linuxPath;
private ModProfileXML profile; private readonly string[] DATAFILES_BLACKLIST = { "data.win", "AM2R.exe", "D3DX9_43.dll", "game.unx" };
private string saveFilePath;
private readonly ModProfileXML profile;
private FileFilter zipFileFilter = new FileFilter("zip archives (*.zip)", ".zip"); private readonly FileFilter zipFileFilter = new FileFilter("zip archives (*.zip)", ".zip");
#region Eto events #region Eto events
private void CustomSaveCheckBoxChecked_Changed(object sender, EventArgs e)
{
customSaveButton.Enabled = customSaveCheckBox.Checked.Value;
customSaveTextBox.Enabled = customSaveCheckBox.Checked.Value;
UpdateCreateButton();
}
private void ApkButton_Click(object sender, EventArgs e)
{
// Open window to select modded AM2R APK
(isApkLoaded, apkPath) = SelectFile("Please select your custom AM2R .apk", "android application packages (*.apk)|*.apk");
apkLabel.Visible = isApkLoaded;
private void OriginalButton_Click(object sender, EventArgs e) UpdateCreateButton();
}
private void ApkCheckBoxCheckedChanged(object sender, EventArgs e)
{
apkButton.Enabled = apkCheckBox.Checked.Value;
UpdateCreateButton();
}
private void LinuxCheckBox_CheckedChanged(object sender, EventArgs e)
{
linuxButton.Enabled = linuxCheckBox.Checked.Value;
UpdateCreateButton();
}
private void LinuxButton_Click(object sender, EventArgs e)
{
// Open window to select modded Linux .zip
(isLinuxLoaded, linuxPath) = SelectFile("Please select your custom Linux AM2R .zip", zipFileFilter);
linuxLabel.Visible = isLinuxLoaded;
UpdateCreateButton();
}
private void OriginalZipButton_Click(object sender, EventArgs e)
{ {
// Open window to select AM2R 1.1 // Open window to select AM2R 1.1
(isOriginalLoaded, originalPath) = SelectFile("Please select AM2R_11.zip", zipFileFilter); (isOriginalLoaded, originalPath) = SelectFile("Please select AM2R_11.zip", zipFileFilter);
OriginalLabel.Visible = isOriginalLoaded; originalZipLabel.Visible = isOriginalLoaded;
UpdateCreateButton(); UpdateCreateButton();
} }
private void ModButton_Click(object sender, EventArgs e) private void ModZipButton_Click(object sender, EventArgs e)
{ {
// Open window to select modded AM2R // Open window to select modded AM2R
(isModLoaded, modPath) = SelectFile("Please select your custom AM2R .zip", zipFileFilter); (isModLoaded, modPath) = SelectFile("Please select your custom AM2R .zip", zipFileFilter);
ModLabel.Visible = isModLoaded; modZipLabel.Visible = isModLoaded;
UpdateCreateButton(); UpdateCreateButton();
} }
private void CreateButton_Click(object sender, EventArgs e) private void CreateButton_Click(object sender, EventArgs e)
{ {
if (NameTextBox.Text == "" || AuthorTextBox.Text == "" || versionTextBox.Text == "") if (nameTextBox.Text == "" || authorTextBox.Text == "" || versionTextBox.Text == "")
{ {
MessageBox.Show("Text field missing! Mod packaging aborted.", "Error", MessageBoxButtons.OK, MessageBoxType.Error); MessageBox.Show("Text field missing! Mod packaging aborted.", "Error", MessageBoxButtons.OK, MessageBoxType.Error);
return; return;
} }
if (Path.GetInvalidFileNameChars().Any(NameTextBox.Text.Contains)) if (Path.GetInvalidFileNameChars().Any(nameTextBox.Text.Contains))
{ {
MessageBox.Show("Name contains invalid characters! These characters are not allowed:\n" + string.Join("\n", Path.GetInvalidFileNameChars())); MessageBox.Show("Name contains invalid characters! These characters are not allowed:\n" + String.Join("\n", Path.GetInvalidFileNameChars()));
return; return;
} }
CreateLabel.Visible = true; createLabel.Visible = true;
CreateLabel.Text = "Packaging mod(s)... This could take a while!"; createLabel.Text = "Packaging mod(s)... This could take a while!";
string output; string output;
using (SaveFileDialog saveFile = new SaveFileDialog { Title = "Save Windows mod profile", Filters = {zipFileFilter} }) using (var saveFile = new SaveFileDialog { Title = "Save Windows mod profile", Filters = { zipFileFilter } })
{ {
if (saveFile.ShowDialog(this) == DialogResult.Ok) if (saveFile.ShowDialog(this) == DialogResult.Ok)
{ {
@ -71,7 +111,7 @@ public partial class ModPacker : Form
} }
else else
{ {
CreateLabel.Text = "Mod packaging aborted!"; createLabel.Text = "Mod packaging aborted!";
return; return;
} }
} }
@ -80,7 +120,7 @@ public partial class ModPacker : Form
if (linuxCheckBox.Checked.Value) if (linuxCheckBox.Checked.Value)
{ {
using (SaveFileDialog saveFile = new SaveFileDialog { Title = "Save Linux mod profile", Filters = {zipFileFilter} }) using (var saveFile = new SaveFileDialog { Title = "Save Linux mod profile", Filters = { zipFileFilter } })
{ {
if (saveFile.ShowDialog(this) == DialogResult.Ok) if (saveFile.ShowDialog(this) == DialogResult.Ok)
{ {
@ -88,7 +128,7 @@ public partial class ModPacker : Form
} }
else else
{ {
CreateLabel.Text = "Mod packaging aborted!"; createLabel.Text = "Mod packaging aborted!";
return; return;
} }
} }
@ -96,8 +136,9 @@ public partial class ModPacker : Form
CreateModPack("Linux", linuxPath, output); CreateModPack("Linux", linuxPath, output);
} }
CreateLabel.Text = "Mod package(s) created!"; createLabel.Text = "Mod package(s) created!";
} }
#endregion
private void CreateModPack(string operatingSystem, string input, string output) private void CreateModPack(string operatingSystem, string input, string output)
{ {
@ -105,15 +146,13 @@ public partial class ModPacker : Form
// Cleanup in case of previous errors // Cleanup in case of previous errors
if (Directory.Exists(Path.GetTempPath() + "\\AM2RModPacker")) if (Directory.Exists(Path.GetTempPath() + "\\AM2RModPacker"))
{
Directory.Delete(Path.GetTempPath() + "\\AM2RModPacker", true); Directory.Delete(Path.GetTempPath() + "\\AM2RModPacker", true);
}
// Create temp work folders // Create temp work folders
string tempPath = "", string tempPath,
tempOriginalPath = "", tempOriginalPath,
tempModPath = "", tempModPath,
tempProfilePath = ""; tempProfilePath;
// We might not have permission to access to the temp directory, so we need to catch the exception. // We might not have permission to access to the temp directory, so we need to catch the exception.
try try
@ -223,7 +262,7 @@ public partial class ModPacker : Form
// - java -jar apktool.jar d "%~dp0AM2RWrapper_old.apk" // - java -jar apktool.jar d "%~dp0AM2RWrapper_old.apk"
// Process startInfo // Process startInfo
ProcessStartInfo procStartInfo = new ProcessStartInfo var procStartInfo = new ProcessStartInfo
{ {
FileName = "cmd.exe", FileName = "cmd.exe",
WorkingDirectory = tempAndroid, WorkingDirectory = tempAndroid,
@ -233,7 +272,7 @@ public partial class ModPacker : Form
}; };
// Run process // Run process
using (Process proc = new Process { StartInfo = procStartInfo }) using (var proc = new Process { StartInfo = procStartInfo })
{ {
proc.Start(); proc.Start();
@ -249,40 +288,32 @@ public partial class ModPacker : Form
string[] whitelist = { "splash.png", "portrait_splash.png" }; string[] whitelist = { "splash.png", "portrait_splash.png" };
// Get directory // Get directory
DirectoryInfo androidAssets = new DirectoryInfo(tempAndroid + "\\assets"); var androidAssets = new DirectoryInfo(tempAndroid + "\\assets");
// Delete files // Delete files
foreach (FileInfo file in androidAssets.GetFiles()) foreach (var file in androidAssets.GetFiles())
{ {
if (file.Name.EndsWith(".ini") && file.Name != "modifiers.ini") if (file.Name.EndsWith(".ini") && file.Name != "modifiers.ini")
{ {
if (File.Exists(tempProfilePath + "\\AM2R.ini")) if (File.Exists(tempProfilePath + "\\AM2R.ini"))
{
// This shouldn't be a problem... normally... // This shouldn't be a problem... normally...
File.Delete(tempProfilePath + "\\AM2R.ini"); File.Delete(tempProfilePath + "\\AM2R.ini");
}
File.Copy(file.FullName, tempProfilePath + "\\AM2R.ini"); File.Copy(file.FullName, tempProfilePath + "\\AM2R.ini");
} }
if (!whitelist.Contains(file.Name)) if (!whitelist.Contains(file.Name))
{
File.Delete(file.FullName); File.Delete(file.FullName);
} }
}
foreach (DirectoryInfo dir in androidAssets.GetDirectories()) foreach (var dir in androidAssets.GetDirectories())
{
Directory.Delete(dir.FullName, true); Directory.Delete(dir.FullName, true);
}
// Create wrapper // Create wrapper
// Process startInfo // Process startInfo
// - java -jar apktool.jar b "%~dp0AM2RWrapper_old" -o "%~dp0AM2RWrapper.apk" // - java -jar apktool.jar b "%~dp0AM2RWrapper_old" -o "%~dp0AM2RWrapper.apk"
ProcessStartInfo procStartInfo2 = new ProcessStartInfo var procStartInfo2 = new ProcessStartInfo
{ {
FileName = "cmd.exe", FileName = "cmd.exe",
WorkingDirectory = tempAndroid, WorkingDirectory = tempAndroid,
@ -292,7 +323,7 @@ public partial class ModPacker : Form
}; };
// Run process // Run process
using (Process proc = new Process { StartInfo = procStartInfo2 }) using (var proc = new Process { StartInfo = procStartInfo2 })
{ {
proc.Start(); proc.Start();
@ -309,16 +340,16 @@ public partial class ModPacker : Form
// Copy datafiles (exclude .ogg if custom music is not selected) // Copy datafiles (exclude .ogg if custom music is not selected)
DirectoryInfo dinfo = new DirectoryInfo(tempModPath); var dirInfo = new DirectoryInfo(tempModPath);
if (profile.OperatingSystem == "Linux") if (profile.OperatingSystem == "Linux")
dinfo = new DirectoryInfo(tempModPath + "\\assets"); dirInfo = new DirectoryInfo(tempModPath + "\\assets");
Directory.CreateDirectory(tempProfilePath + "\\files_to_copy"); Directory.CreateDirectory(tempProfilePath + "\\files_to_copy");
if (profile.UsesCustomMusic) if (profile.UsesCustomMusic)
{ {
// Copy files, excluding the blacklist // Copy files, excluding the blacklist
CopyFilesRecursive(dinfo, DATAFILES_BLACKLIST, tempProfilePath + "\\files_to_copy"); CopyFilesRecursive(dirInfo, DATAFILES_BLACKLIST, tempProfilePath + "\\files_to_copy");
} }
else else
{ {
@ -333,7 +364,7 @@ public partial class ModPacker : Form
string[] blacklist = musFiles.Concat(DATAFILES_BLACKLIST).ToArray(); string[] blacklist = musFiles.Concat(DATAFILES_BLACKLIST).ToArray();
// Copy files, excluding the blacklist // Copy files, excluding the blacklist
CopyFilesRecursive(dinfo, blacklist, tempProfilePath + "\\files_to_copy"); CopyFilesRecursive(dirInfo, blacklist, tempProfilePath + "\\files_to_copy");
} }
// Export profile as XML // Export profile as XML
@ -342,9 +373,7 @@ public partial class ModPacker : Form
// Compress temp folder to .zip // Compress temp folder to .zip
if (File.Exists(output)) if (File.Exists(output))
{
File.Delete(output); File.Delete(output);
}
ZipFile.CreateFromDirectory(tempProfilePath, output); ZipFile.CreateFromDirectory(tempProfilePath, output);
@ -352,54 +381,23 @@ public partial class ModPacker : Form
Directory.Delete(tempPath, true); Directory.Delete(tempPath, true);
} }
private void ApkButton_Click(object sender, EventArgs e)
{
// Open window to select modded AM2R APK
(isApkLoaded, apkPath) = SelectFile("Please select your custom AM2R .apk", "android application packages (*.apk)|*.apk");
ApkLabel.Visible = isApkLoaded;
UpdateCreateButton();
}
private void AndroidCheckBox_CheckedChanged(object sender, EventArgs e)
{
ApkButton.Enabled = AndroidCheckBox.Checked.Value;
UpdateCreateButton();
}
private void SaveCheckBox_CheckedChanged(object sender, EventArgs e)
{
winSaveButton.Enabled = SaveCheckBox.Checked.Value;
saveTextBox.Enabled = SaveCheckBox.Checked.Value;
UpdateCreateButton();
}
#endregion
private void LoadProfileParameters(string operatingSystem) private void LoadProfileParameters(string operatingSystem)
{ {
profile.Name = NameTextBox.Text; profile.Name = nameTextBox.Text;
profile.Author = AuthorTextBox.Text; profile.Author = authorTextBox.Text;
profile.Version = versionTextBox.Text; profile.Version = versionTextBox.Text;
profile.UsesCustomMusic = MusicCheckBox.Checked.Value; profile.UsesCustomMusic = musicCheckBox.Checked.Value;
profile.UsesYYC = YYCCheckBox.Checked.Value; profile.UsesYYC = yycCheckBox.Checked.Value;
profile.Android = AndroidCheckBox.Checked.Value; profile.Android = apkCheckBox.Checked.Value;
profile.ProfileNotes = modNotesTextBox.Text; profile.ProfileNotes = modNotesTextBox.Text;
profile.OperatingSystem = operatingSystem; profile.OperatingSystem = operatingSystem;
if (SaveCheckBox.Checked.Value && saveTextBox.Text != "") if (customSaveCheckBox.Checked.Value && customSaveTextBox.Text != "")
{ profile.SaveLocation = customSaveTextBox.Text;
profile.SaveLocation = saveTextBox.Text;
}
else else
{
profile.SaveLocation = "%localappdata%/AM2R"; profile.SaveLocation = "%localappdata%/AM2R";
}
if (operatingSystem == "Linux") if (operatingSystem == "Linux")
{
profile.SaveLocation = profile.SaveLocation.Replace("%localappdata%", "~/.config"); profile.SaveLocation = profile.SaveLocation.Replace("%localappdata%", "~/.config");
} }
}
private void AbortPatch() private void AbortPatch()
{ {
@ -415,83 +413,66 @@ public partial class ModPacker : Form
saveFilePath = null; saveFilePath = null;
// Set labels // Set labels
CreateLabel.Text = "Mod packaging aborted!"; createLabel.Text = "Mod packaging aborted!";
OriginalLabel.Visible = false; originalZipLabel.Visible = false;
ModLabel.Visible = false; modZipLabel.Visible = false;
ApkLabel.Visible = false; apkLabel.Visible = false;
linuxLabel.Visible = false; linuxLabel.Visible = false;
// Remove temp directory // Remove temp directory
if (Directory.Exists(Path.GetTempPath() + "\\AM2RModPacker")) if (Directory.Exists(Path.GetTempPath() + "\\AM2RModPacker"))
{
Directory.Delete(Path.GetTempPath() + "\\AM2RModPacker", true); Directory.Delete(Path.GetTempPath() + "\\AM2RModPacker", true);
} }
}
private void linuxCheckBox_CheckedChanged(object sender, EventArgs e)
{
linuxButton.Enabled = linuxCheckBox.Checked.Value;
UpdateCreateButton();
}
private void linuxButton_Click(object sender, EventArgs e)
{
// Open window to select modded Linux .zip
(isLinuxLoaded, linuxPath) = SelectFile("Please select your custom Linux AM2R .zip", zipFileFilter);
linuxLabel.Visible = isLinuxLoaded;
UpdateCreateButton();
}
private void CustomSaveDataButton_Click(object sender, EventArgs e) private void CustomSaveDataButton_Click(object sender, EventArgs e)
{ {
bool wasSuccessfull = false; bool wasSuccessful = false;
Regex saveRegex = new Regex(@"C:\\Users\\.*\\AppData\\Local\\"); //this is to ensure, that the save directory is valid. so far, this is only important for windows // TODO: make sure that the validation works on other platforms too
var saveRegex = new Regex(@"C:\\Users\\.*\\AppData\\Local\\"); //this is to ensure, that the save directory is valid. so far, this is only important for windows
SelectFolderDialog dialog = new SelectFolderDialog(); var dialog = new SelectFolderDialog();
// currently not implemented in eto // currently not implemented in eto
//dialog.InitialDirectory = Environment.GetEnvironmentVariable("LocalAppData"); //dialog.InitialDirectory = Environment.GetEnvironmentVariable("LocalAppData");
while (!wasSuccessfull) while (!wasSuccessful)
{ {
if (dialog.ShowDialog(this) == DialogResult.Ok) if (dialog.ShowDialog(this) == DialogResult.Ok)
{ {
Match match = saveRegex.Match(dialog.Directory); var match = saveRegex.Match(dialog.Directory);
if (match.Success == false) if (match.Success == false)
{
MessageBox.Show("Invalid Save Directory! Please choose one in %LocalAppData%"); MessageBox.Show("Invalid Save Directory! Please choose one in %LocalAppData%");
}
else else
{ {
wasSuccessfull = true; wasSuccessful = true;
saveFilePath = dialog.Directory.Replace(match.Value, "%localappdata%/"); saveFilePath = dialog.Directory.Replace(match.Value, "%localappdata%/");
saveFilePath = saveFilePath.Replace("\\", "/"); // if we don't do this, custom save locations are going to fail on Linux saveFilePath = saveFilePath.Replace("\\", "/"); // if we don't do this, custom save locations are going to fail on Linux
// if someone has a custom save path inside of am2r and creates these whithin game maker, they will always be lower case // if someone has a custom save path inside of am2r and creates these whithin game maker, they will always be lower case
// we need to adjust them here to lowercase as well, as otherwise launcher gets problems on nix systems // we need to adjust them here to lowercase as well, as otherwise launcher gets problems on nix systems
string vanillaPrefix = "%localappdata%/AM2R/"; const string vanillaPrefix = "%localappdata%/AM2R/";
if (saveFilePath.Contains(vanillaPrefix)) if (saveFilePath.Contains(vanillaPrefix))
saveFilePath = vanillaPrefix + saveFilePath.Substring(vanillaPrefix.Length).ToLower(); saveFilePath = vanillaPrefix + saveFilePath.Substring(vanillaPrefix.Length).ToLower();
} }
} }
else else
{ {
wasSuccessfull = true; wasSuccessful = true;
saveFilePath = null; saveFilePath = null;
} }
} }
saveTextBox.Text = saveFilePath; customSaveTextBox.Text = saveFilePath;
} }
private void CopyFilesRecursive(DirectoryInfo source, string[] blacklist, string destination) private static void CopyFilesRecursive(DirectoryInfo source, string[] blacklist, string destination)
{ {
foreach (FileInfo file in source.GetFiles()) foreach (var file in source.GetFiles())
{ {
if (!blacklist.Contains(file.Name)) if (!blacklist.Contains(file.Name))
{
file.CopyTo(destination + "\\" + file.Name); file.CopyTo(destination + "\\" + file.Name);
} }
}
foreach (DirectoryInfo dir in source.GetDirectories()) foreach (var dir in source.GetDirectories())
{ {
// Folders need to be lowercase, because GM only reads from lowercase names on *nix systems. Windows is case-insensitive so doesnt matter for them // Folders need to be lowercase, because GM only reads from lowercase names on *nix systems. Windows is case-insensitive so doesnt matter for them
string newDir = Directory.CreateDirectory(destination + "\\" + dir.Name.ToLower()).FullName; string newDir = Directory.CreateDirectory(destination + "\\" + dir.Name.ToLower()).FullName;
@ -503,35 +484,27 @@ public partial class ModPacker : Form
{ {
if (isOriginalLoaded && if (isOriginalLoaded &&
isModLoaded && isModLoaded &&
(!AndroidCheckBox.Checked.Value || isApkLoaded) && (!apkCheckBox.Checked.Value || isApkLoaded) &&
(!linuxCheckBox.Checked.Value || isLinuxLoaded) && (!linuxCheckBox.Checked.Value || isLinuxLoaded) &&
(!SaveCheckBox.Checked.Value || saveTextBox.Text != "")) (!customSaveCheckBox.Checked.Value || customSaveTextBox.Text != ""))
{ createButton.Enabled = true;
CreateButton.Enabled = true;
}
else else
{ createButton.Enabled = false;
CreateButton.Enabled = false;
}
} }
// Thanks, stackoverflow: https://stackoverflow.com/questions/10520048/calculate-md5-checksum-for-a-file // Thanks, stackoverflow: https://stackoverflow.com/questions/10520048/calculate-md5-checksum-for-a-file
private string CalculateMD5(string filename) private static string CalculateMD5(string filename)
{ {
using (var stream = File.OpenRead(filename)) using var stream = File.OpenRead(filename);
{ using var md5 = MD5.Create();
using (var md5 = MD5.Create()) byte[] hash = md5.ComputeHash(stream);
{
var hash = md5.ComputeHash(stream);
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
} }
}
}
private void CreatePatch(string original, string modified, string output) private void CreatePatch(string original, string modified, string output)
{ {
// Specify process start info // Specify process start info
ProcessStartInfo parameters = new ProcessStartInfo var parameters = new ProcessStartInfo
{ {
FileName = localPath + "\\utilities\\xdelta\\xdelta3.exe", FileName = localPath + "\\utilities\\xdelta\\xdelta3.exe",
WorkingDirectory = localPath, WorkingDirectory = localPath,
@ -541,29 +514,22 @@ public partial class ModPacker : Form
}; };
// Launch process and wait for exit. using statement automatically disposes the object for us! // Launch process and wait for exit. using statement automatically disposes the object for us!
using (Process proc = new Process { StartInfo = parameters }) using var proc = new Process { StartInfo = parameters };
{
proc.Start(); proc.Start();
proc.WaitForExit(); proc.WaitForExit();
} }
}
private (bool, string) SelectFile(string title, FileFilter filter) private (bool, string) SelectFile(string title, FileFilter filter)
{ {
using (OpenFileDialog fileFinder = new OpenFileDialog() {Filters = { filter }}) using var fileFinder = new OpenFileDialog { Filters = { filter } };
{
fileFinder.Title = title; fileFinder.Title = title;
fileFinder.CurrentFilter = fileFinder.Filters.First(); fileFinder.CurrentFilter = fileFinder.Filters.First();
fileFinder.CheckFileExists = true; fileFinder.CheckFileExists = true;
if (fileFinder.ShowDialog(this) == DialogResult.Ok) if (fileFinder.ShowDialog(this) != DialogResult.Ok)
{ return (false, "");
string location = fileFinder.FileName; string location = fileFinder.FileName;
return (true, location); return (true, location);
}
else return (false, "");
}
} }
} }

@ -1,15 +1,16 @@
using System; using System;
using System.Xml.Serialization; using System.Xml.Serialization;
namespace AM2RModPacker.XML namespace AM2RModPacker.XML;
//TODO: sync this with the launcher xml, a bunch more comments are in there.
/// <summary>
/// Class that handles how the modmeta settings are saved as XML.
/// </summary>
[Serializable]
[XmlRoot("message")]
public class ModProfileXML
{ {
/// <summary>
/// Class that handles how the modmeta settings are saved as XML.
/// </summary>
[Serializable]
[XmlRoot("message")]
public class ModProfileXML
{
[XmlAttribute("OperatingSystem")] [XmlAttribute("OperatingSystem")]
public string OperatingSystem public string OperatingSystem
{ get; set; } { get; set; }
@ -55,6 +56,7 @@ namespace AM2RModPacker.XML
public string ProfileNotes public string ProfileNotes
{ get; set; } { get; set; }
// TODO: this should fill in sensible default values
public ModProfileXML() public ModProfileXML()
{ } { }
@ -72,5 +74,4 @@ namespace AM2RModPacker.XML
ProfileNotes = profileNotes; ProfileNotes = profileNotes;
Installable = installable; Installable = installable;
} }
}
} }

@ -2,13 +2,13 @@
using System.IO; using System.IO;
using System.Text; using System.Text;
namespace AM2RModPacker.XML namespace AM2RModPacker.XML;
/// <summary>
/// The <c>Serializer</c> class, that serializes to and deserializes from XML files.
/// </summary>
public class Serializer
{ {
/// <summary>
/// The <c>Serializer</c> class, that serializes to and deserializes from XML files.
/// </summary>
public class Serializer
{
/// <summary> /// <summary>
/// Serializes <paramref name="item"/> as a <typeparamref name="T"/> to XML. /// Serializes <paramref name="item"/> as a <typeparamref name="T"/> to XML.
/// </summary> /// </summary>
@ -48,5 +48,4 @@ namespace AM2RModPacker.XML
return (T)serializer.Deserialize(memStream); return (T)serializer.Deserialize(memStream);
} }
} }
}
} }
Loading…
Cancel
Save