document more

pull/9/head
Miepee 4 years ago
parent 697b5c5dce
commit 86c3475679

@ -32,6 +32,47 @@ public partial class ModPacker : Form
customSaveTextBox.Enabled = customSaveCheckBox.Checked.Value; customSaveTextBox.Enabled = customSaveCheckBox.Checked.Value;
UpdateCreateButton(); UpdateCreateButton();
} }
//TODO: go through this method
private void CustomSaveDataButton_Click(object sender, EventArgs e)
{
bool wasSuccessful = false;
// 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
var dialog = new SelectFolderDialog();
// currently not implemented in eto
//dialog.InitialDirectory = Environment.GetEnvironmentVariable("LocalAppData");
while (!wasSuccessful)
{
if (dialog.ShowDialog(this) == DialogResult.Ok)
{
var match = saveRegex.Match(dialog.Directory);
if (match.Success == false)
{
MessageBox.Show("Invalid Save Directory! Please choose one in %LocalAppData%");
}
else
{
wasSuccessful = true;
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
// 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
const string vanillaPrefix = "%localappdata%/AM2R/";
if (saveFilePath.Contains(vanillaPrefix))
saveFilePath = vanillaPrefix + saveFilePath.Substring(vanillaPrefix.Length).ToLower();
}
}
else
{
wasSuccessful = true;
saveFilePath = null;
}
}
customSaveTextBox.Text = saveFilePath;
}
private void ApkCheckBoxCheckedChanged(object sender, EventArgs e) private void ApkCheckBoxCheckedChanged(object sender, EventArgs e)
{ {
@ -76,7 +117,7 @@ public partial class ModPacker : Form
modZipLabel.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 == "")
@ -93,41 +134,37 @@ public partial class ModPacker : Form
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!";
// TODO: move most of this into seperate method?
string output; string output;
// TODO: make windows optional
using (var 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)
{
output = saveFile.FileName; output = saveFile.FileName;
}
else else
{ {
createLabel.Text = "Mod packaging aborted!"; createLabel.Text = "Mod packaging aborted!";
return; return;
} }
} }
LoadProfileParameters(ProfileOperatingSystems.Windows);
CreateModPack("Windows", modPath, output); CreateModPack(profile, modPath, output);
if (linuxCheckBox.Checked.Value) if (linuxCheckBox.Checked.Value)
{ {
using (var 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)
{
output = saveFile.FileName; output = saveFile.FileName;
}
else else
{ {
createLabel.Text = "Mod packaging aborted!"; createLabel.Text = "Mod packaging aborted!";
return; return;
} }
} }
LoadProfileParameters(ProfileOperatingSystems.Linux);
CreateModPack("Linux", linuxPath, output); CreateModPack(profile, linuxPath, output);
} }
//TODO: mac //TODO: mac
@ -135,11 +172,9 @@ public partial class ModPacker : Form
} }
#endregion #endregion
private void CreateModPack(string operatingSystem, string input, string output) // TODO: go over thhis
private void CreateModPack( ModProfileXML profile, string input, string output)
{ {
// TODO: go over thhis
LoadProfileParameters(operatingSystem);
// 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);
@ -161,9 +196,7 @@ public partial class ModPacker : Form
catch (System.Security.SecurityException) catch (System.Security.SecurityException)
{ {
MessageBox.Show("Could not create temp directory! Please run the application with administrator rights.", "Error", MessageBoxButtons.OK, MessageBoxType.Error); MessageBox.Show("Could not create temp directory! Please run the application with administrator rights.", "Error", MessageBoxButtons.OK, MessageBoxType.Error);
AbortPatch(); AbortPatch();
return; return;
} }
@ -184,9 +217,7 @@ public partial class ModPacker : Form
{ {
// Show error box // Show error box
MessageBox.Show("1.1 data.win does not meet MD5 checksum! Mod packaging aborted.\n1.1 MD5: " + originalMD5 + "\nYour MD5: " + newMD5, "Error", MessageBoxButtons.OK, MessageBoxType.Error); MessageBox.Show("1.1 data.win does not meet MD5 checksum! Mod packaging aborted.\n1.1 MD5: " + originalMD5 + "\nYour MD5: " + newMD5, "Error", MessageBoxButtons.OK, MessageBoxType.Error);
AbortPatch(); AbortPatch();
return; return;
} }
} }
@ -194,9 +225,7 @@ public partial class ModPacker : Form
{ {
// Show error message // Show error message
MessageBox.Show("data.win not found! Are you sure you selected AM2R 1.1? Mod packaging aborted.", "Error", MessageBoxButtons.OK, MessageBoxType.Error); MessageBox.Show("data.win not found! Are you sure you selected AM2R 1.1? Mod packaging aborted.", "Error", MessageBoxButtons.OK, MessageBoxType.Error);
AbortPatch(); AbortPatch();
return; return;
} }
@ -224,7 +253,6 @@ public partial class ModPacker : Form
else else
{ {
Core.CreatePatch(tempOriginalPath + "/data.win", tempModPath + "/data.win", tempProfilePath + "/data.xdelta"); Core.CreatePatch(tempOriginalPath + "/data.win", tempModPath + "/data.win", tempProfilePath + "/data.xdelta");
Core.CreatePatch(tempOriginalPath + "/AM2R.exe", tempModPath + "/AM2R.exe", tempProfilePath + "/AM2R.xdelta"); Core.CreatePatch(tempOriginalPath + "/AM2R.exe", tempModPath + "/AM2R.exe", tempProfilePath + "/AM2R.xdelta");
} }
} }
@ -249,6 +277,7 @@ public partial class ModPacker : Form
Core.CreatePatch(tempOriginalPath + "/data.win", tempModPath + "/assets/game.unx", tempProfilePath + "/game.xdelta"); Core.CreatePatch(tempOriginalPath + "/data.win", tempModPath + "/assets/game.unx", tempProfilePath + "/game.xdelta");
Core.CreatePatch(tempOriginalPath + "/AM2R.exe", tempModPath + "/" + runnerName, tempProfilePath + "/AM2R.xdelta"); Core.CreatePatch(tempOriginalPath + "/AM2R.exe", tempModPath + "/" + runnerName, tempProfilePath + "/AM2R.xdelta");
} }
// todo: mac
// Create game.droid patch and wrapper if Android is supported // Create game.droid patch and wrapper if Android is supported
if (profile.Android) if (profile.Android)
@ -259,6 +288,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
// TODO: cross platform
var procStartInfo = new ProcessStartInfo var procStartInfo = new ProcessStartInfo
{ {
FileName = "cmd.exe", FileName = "cmd.exe",
@ -272,7 +302,6 @@ public partial class ModPacker : Form
using (var proc = new Process { StartInfo = procStartInfo }) using (var proc = new Process { StartInfo = procStartInfo })
{ {
proc.Start(); proc.Start();
proc.WaitForExit(); proc.WaitForExit();
} }
@ -323,7 +352,6 @@ public partial class ModPacker : Form
using (var proc = new Process { StartInfo = procStartInfo2 }) using (var proc = new Process { StartInfo = procStartInfo2 })
{ {
proc.Start(); proc.Start();
proc.WaitForExit(); proc.WaitForExit();
} }
@ -378,7 +406,7 @@ public partial class ModPacker : Form
Directory.Delete(tempPath, true); Directory.Delete(tempPath, true);
} }
private void LoadProfileParameters(string operatingSystem) private void LoadProfileParameters(ProfileOperatingSystems operatingSystem)
{ {
profile.Name = nameTextBox.Text; profile.Name = nameTextBox.Text;
profile.Author = authorTextBox.Text; profile.Author = authorTextBox.Text;
@ -387,12 +415,12 @@ public partial class ModPacker : Form
profile.UsesYYC = yycCheckBox.Checked.Value; profile.UsesYYC = yycCheckBox.Checked.Value;
profile.Android = apkCheckBox.Checked.Value; profile.Android = apkCheckBox.Checked.Value;
profile.ProfileNotes = modNotesTextBox.Text; profile.ProfileNotes = modNotesTextBox.Text;
profile.OperatingSystem = operatingSystem; profile.OperatingSystem = operatingSystem.ToString();
if (customSaveCheckBox.Checked.Value && customSaveTextBox.Text != "") if (customSaveCheckBox.Checked.Value && customSaveTextBox.Text != "")
profile.SaveLocation = customSaveTextBox.Text; profile.SaveLocation = customSaveTextBox.Text;
else else
profile.SaveLocation = "%localappdata%/AM2R"; profile.SaveLocation = "%localappdata%/AM2R";
if (operatingSystem == "Linux") if (operatingSystem == ProfileOperatingSystems.Linux)
profile.SaveLocation = profile.SaveLocation.Replace("%localappdata%", "~/.config"); profile.SaveLocation = profile.SaveLocation.Replace("%localappdata%", "~/.config");
} }
@ -421,53 +449,15 @@ public partial class ModPacker : Form
Directory.Delete(Path.GetTempPath() + "/AM2RModPacker", true); Directory.Delete(Path.GetTempPath() + "/AM2RModPacker", true);
} }
private void CustomSaveDataButton_Click(object sender, EventArgs e)
{
bool wasSuccessful = false;
// 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
var dialog = new SelectFolderDialog();
// currently not implemented in eto
//dialog.InitialDirectory = Environment.GetEnvironmentVariable("LocalAppData");
while (!wasSuccessful)
{
if (dialog.ShowDialog(this) == DialogResult.Ok)
{
var match = saveRegex.Match(dialog.Directory);
if (match.Success == false)
{
MessageBox.Show("Invalid Save Directory! Please choose one in %LocalAppData%");
}
else
{
wasSuccessful = true;
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
// 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
const string vanillaPrefix = "%localappdata%/AM2R/";
if (saveFilePath.Contains(vanillaPrefix))
saveFilePath = vanillaPrefix + saveFilePath.Substring(vanillaPrefix.Length).ToLower();
}
}
else
{
wasSuccessful = true;
saveFilePath = null;
}
}
customSaveTextBox.Text = saveFilePath;
}
private void UpdateCreateButton() private void UpdateCreateButton()
{ {
if (isOriginalLoaded && if (isOriginalLoaded && // AM2R_11 zip must be provided
isModLoaded && isModLoaded && // Modded zip must be provided
(!apkCheckBox.Checked.Value || isApkLoaded) && (!apkCheckBox.Checked.Value || isApkLoaded) && // either APK is disabled OR APK is provided
(!linuxCheckBox.Checked.Value || isLinuxLoaded) && (!linuxCheckBox.Checked.Value || isLinuxLoaded) && // either Linux is disabled OR linux is provided
(!customSaveCheckBox.Checked.Value || customSaveTextBox.Text != "")) (!customSaveCheckBox.Checked.Value || customSaveTextBox.Text != "")) // either custom saves are disabled OR custom save is provided
createButton.Enabled = true; createButton.Enabled = true;
else else
createButton.Enabled = false; createButton.Enabled = false;

@ -4,7 +4,12 @@ using System.Security.Cryptography;
namespace AM2RModPackerLib; namespace AM2RModPackerLib;
public enum ProfileOperatingSystems
{
Windows,
Linux,
Mac
}
public static class Core public static class Core
{ {

Loading…
Cancel
Save