get rid of save folder in modinfo, rename modinfo to standards

pull/9/head
Miepee 4 years ago
parent 235ee287a3
commit 4ad0c7a9d4

@ -4,16 +4,15 @@ using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using AM2RModPackerLib; using AM2RModPackerLib;
using AM2RModPackerLib.XML;
using Eto.Forms; using Eto.Forms;
namespace AM2RModPacker; namespace AM2RModPacker;
public partial class ModPacker : Form public partial class ModPacker : Form
{ {
private static readonly string version = Core.Version; private const string version = Core.Version;
private ModCreationInfo modinfo = new ModCreationInfo(); private ModCreationInfo modInfo = new ModCreationInfo();
private readonly FileFilter zipFileFilter = new FileFilter("zip archives (*.zip)", ".zip"); private readonly FileFilter zipFileFilter = new FileFilter("zip archives (*.zip)", ".zip");
private readonly FileFilter apkFileFilter = new FileFilter("Android application packages (*.apk)", ".apk"); private readonly FileFilter apkFileFilter = new FileFilter("Android application packages (*.apk)", ".apk");
@ -44,6 +43,7 @@ public partial class ModPacker : Form
initialDir = $@"{home}/Library/Application Support/"; initialDir = $@"{home}/Library/Application Support/";
dialog.Directory = initialDir; dialog.Directory = initialDir;
string saveFolderPath = null;
while (!wasSuccessful) while (!wasSuccessful)
{ {
if (dialog.ShowDialog(this) == DialogResult.Ok) if (dialog.ShowDialog(this) == DialogResult.Ok)
@ -61,31 +61,28 @@ public partial class ModPacker : Form
else else
{ {
wasSuccessful = true; wasSuccessful = true;
string saveFilePath = dialog.Directory.Replace(match.Value, "%localappdata%/"); saveFolderPath = dialog.Directory.Replace(match.Value, "%localappdata%/");
// If we don't do this, custom save locations are going to fail on Linux // If we don't do this, custom save locations are going to fail on Linux
if (OS.IsWindows) if (OS.IsWindows)
saveFilePath = saveFilePath.Replace("\\", "/"); saveFolderPath = saveFolderPath.Replace("\\", "/");
// On Mac, we need to adjust the path // On Mac, we need to adjust the path
if (OS.IsMac) if (OS.IsMac)
saveFilePath = saveFilePath.Replace("com.yoyogames.am2r", "AM2R"); saveFolderPath = saveFolderPath.Replace("com.yoyogames.am2r", "AM2R");
// 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
const string vanillaPrefix = "%localappdata%/AM2R/"; const string vanillaPrefix = "%localappdata%/AM2R/";
if (saveFilePath.Contains(vanillaPrefix)) if (saveFolderPath.Contains(vanillaPrefix))
saveFilePath = vanillaPrefix + saveFilePath.Substring(vanillaPrefix.Length).ToLower(); saveFolderPath = vanillaPrefix + saveFolderPath.Substring(vanillaPrefix.Length).ToLower();
modinfo.SaveFolderPath = saveFilePath;
} }
} }
else else
{ {
wasSuccessful = true; wasSuccessful = true;
modinfo.SaveFolderPath = null;
} }
} }
customSaveTextBox.Text = modinfo.SaveFolderPath; customSaveTextBox.Text = saveFolderPath;
} }
private void YYCCheckBox_CheckedChanged(object sender, EventArgs e) private void YYCCheckBox_CheckedChanged(object sender, EventArgs e)
@ -97,9 +94,10 @@ public partial class ModPacker : Form
macCheckBox.Checked = false; macCheckBox.Checked = false;
macLabel.Visible = false; macLabel.Visible = false;
macButton.Enabled = false; macButton.Enabled = false;
modinfo.MacModPath = null; modInfo.MacModPath = null;
} }
// TODO: replace checked changed and click with a generic method to avoid copy paste
private void WindowsCheckBox_CheckedChanged(object sender, EventArgs e) private void WindowsCheckBox_CheckedChanged(object sender, EventArgs e)
{ {
windowsButton.Enabled = windowsCheckBox.Checked.Value; windowsButton.Enabled = windowsCheckBox.Checked.Value;
@ -107,7 +105,7 @@ public partial class ModPacker : Form
if (!windowsCheckBox.Checked.Value) if (!windowsCheckBox.Checked.Value)
{ {
windowsLabel.Visible = false; windowsLabel.Visible = false;
modinfo.WindowsModPath = null; modInfo.WindowsModPath = null;
} }
UpdateCreateButton(); UpdateCreateButton();
} }
@ -115,8 +113,8 @@ public partial class ModPacker : Form
private void WindowsButton_Click(object sender, EventArgs e) private void WindowsButton_Click(object sender, EventArgs e)
{ {
// Open window to select modded Linux .zip // Open window to select modded Linux .zip
modinfo.WindowsModPath = SelectFile("Please select your custom Windows AM2R .zip", zipFileFilter); modInfo.WindowsModPath = SelectFile("Please select your custom Windows AM2R .zip", zipFileFilter);
windowsLabel.Visible = modinfo.IsWindowsModLoaded; windowsLabel.Visible = modInfo.IsWindowsModLoaded;
UpdateCreateButton(); UpdateCreateButton();
} }
@ -127,7 +125,7 @@ public partial class ModPacker : Form
if (!apkCheckBox.Checked.Value) if (!apkCheckBox.Checked.Value)
{ {
apkLabel.Visible = false; apkLabel.Visible = false;
modinfo.ApkModPath = null; modInfo.ApkModPath = null;
} }
UpdateCreateButton(); UpdateCreateButton();
} }
@ -135,8 +133,8 @@ public partial class ModPacker : Form
private void ApkButton_Click(object sender, EventArgs e) private void ApkButton_Click(object sender, EventArgs e)
{ {
// Open window to select modded AM2R APK // Open window to select modded AM2R APK
modinfo.ApkModPath = SelectFile("Please select your custom AM2R .apk", apkFileFilter); modInfo.ApkModPath = SelectFile("Please select your custom AM2R .apk", apkFileFilter);
apkLabel.Visible = modinfo.IsApkModLoaded; apkLabel.Visible = modInfo.IsApkModLoaded;
UpdateCreateButton(); UpdateCreateButton();
} }
@ -147,7 +145,7 @@ public partial class ModPacker : Form
if (!linuxCheckBox.Checked.Value) if (!linuxCheckBox.Checked.Value)
{ {
linuxLabel.Visible = false; linuxLabel.Visible = false;
modinfo.LinuxModPath = null; modInfo.LinuxModPath = null;
} }
UpdateCreateButton(); UpdateCreateButton();
} }
@ -155,8 +153,8 @@ public partial class ModPacker : Form
private void LinuxButton_Click(object sender, EventArgs e) private void LinuxButton_Click(object sender, EventArgs e)
{ {
// Open window to select modded Linux .zip // Open window to select modded Linux .zip
modinfo.LinuxModPath = SelectFile("Please select your custom Linux AM2R .zip", zipFileFilter); modInfo.LinuxModPath = SelectFile("Please select your custom Linux AM2R .zip", zipFileFilter);
linuxLabel.Visible = modinfo.IsLinuxModLoaded; linuxLabel.Visible = modInfo.IsLinuxModLoaded;
UpdateCreateButton(); UpdateCreateButton();
} }
@ -169,7 +167,7 @@ public partial class ModPacker : Form
if (!macCheckBox.Checked.Value) if (!macCheckBox.Checked.Value)
{ {
macLabel.Visible = false; macLabel.Visible = false;
modinfo.MacModPath = null; modInfo.MacModPath = null;
} }
UpdateCreateButton(); UpdateCreateButton();
} }
@ -183,16 +181,16 @@ public partial class ModPacker : Form
private void macButton_Click(object sender, EventArgs e) private void macButton_Click(object sender, EventArgs e)
{ {
// Open window to select modded Mac .zip // Open window to select modded Mac .zip
modinfo.MacModPath = SelectFile("Please select your custom Mac AM2R .zip", zipFileFilter); modInfo.MacModPath = SelectFile("Please select your custom Mac AM2R .zip", zipFileFilter);
macLabel.Visible = modinfo.IsMacModLoaded; macLabel.Visible = modInfo.IsMacModLoaded;
UpdateCreateButton(); UpdateCreateButton();
} }
private void OriginalZipButton_Click(object sender, EventArgs e) private void OriginalZipButton_Click(object sender, EventArgs e)
{ {
// Open window to select AM2R 1.1 // Open window to select AM2R 1.1
modinfo.AM2R11Path = SelectFile("Please select AM2R_11.zip", zipFileFilter); modInfo.AM2R11Path = SelectFile("Please select AM2R_11.zip", zipFileFilter);
originalZipLabel.Visible = modinfo.IsAM2R11Loaded; originalZipLabel.Visible = modInfo.IsAM2R11Loaded;
UpdateCreateButton(); UpdateCreateButton();
} }
@ -211,7 +209,7 @@ public partial class ModPacker : Form
} }
// Verify 1.1 // Verify 1.1
var result11 = Core.CheckIfZipIsAM2R11(modinfo.AM2R11Path); var result11 = Core.CheckIfZipIsAM2R11(modInfo.AM2R11Path);
if (result11 != IsZipAM2R11ReturnCodes.Successful) if (result11 != IsZipAM2R11ReturnCodes.Successful)
{ {
MessageBox.Show("AM2R 1.1 zip is invalid! Error code: " + result11); MessageBox.Show("AM2R 1.1 zip is invalid! Error code: " + result11);
@ -226,9 +224,9 @@ public partial class ModPacker : Form
{ {
string modZipPath = os switch string modZipPath = os switch
{ {
ProfileOperatingSystems.Windows => modinfo.WindowsModPath, ProfileOperatingSystems.Windows => modInfo.WindowsModPath,
ProfileOperatingSystems.Linux => modinfo.LinuxModPath, ProfileOperatingSystems.Linux => modInfo.LinuxModPath,
ProfileOperatingSystems.Mac => modinfo.MacModPath, ProfileOperatingSystems.Mac => modInfo.MacModPath,
_ => null _ => null
}; };
string output; string output;
@ -249,7 +247,7 @@ public partial class ModPacker : Form
LoadProfileParameters(os); LoadProfileParameters(os);
try try
{ {
Core.CreateModPack(modinfo.Profile, modinfo.AM2R11Path, modZipPath, modinfo.ApkModPath, output); Core.CreateModPack(modInfo.Profile, modInfo.AM2R11Path, modZipPath, modInfo.ApkModPath, output);
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -273,7 +271,7 @@ public partial class ModPacker : Form
if (windowsCheckBox.Checked.Value) if (windowsCheckBox.Checked.Value)
{ {
var windowsZip = ZipFile.Open(modinfo.WindowsModPath, ZipArchiveMode.Read); var windowsZip = ZipFile.Open(modInfo.WindowsModPath, ZipArchiveMode.Read);
if (windowsZip.Entries.All(f => f.FullName != "AM2R.exe")) if (windowsZip.Entries.All(f => f.FullName != "AM2R.exe"))
{ {
var result = MessageBox.Show("Modded game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning); var result = MessageBox.Show("Modded game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
@ -293,7 +291,7 @@ public partial class ModPacker : Form
if (linuxCheckBox.Checked.Value) if (linuxCheckBox.Checked.Value)
{ {
var linuxZip = ZipFile.Open(modinfo.LinuxModPath, ZipArchiveMode.Read); var linuxZip = ZipFile.Open(modInfo.LinuxModPath, ZipArchiveMode.Read);
if (linuxZip.Entries.All(f => f.FullName != "AM2R") && linuxZip.Entries.All(f => f.FullName != "runner")) if (linuxZip.Entries.All(f => f.FullName != "AM2R") && linuxZip.Entries.All(f => f.FullName != "runner"))
{ {
var result = MessageBox.Show("Modded Linux game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning); var result = MessageBox.Show("Modded Linux game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
@ -312,7 +310,7 @@ public partial class ModPacker : Form
} }
if (macCheckBox.Checked.Value) if (macCheckBox.Checked.Value)
{ {
var macZip = ZipFile.Open(modinfo.MacModPath, ZipArchiveMode.Read); var macZip = ZipFile.Open(modInfo.MacModPath, ZipArchiveMode.Read);
if (macZip.Entries.All(f => f.Name != "AM2R.app/Contents/MacOS/Mac_Runner")) if (macZip.Entries.All(f => f.Name != "AM2R.app/Contents/MacOS/Mac_Runner"))
{ {
var result = MessageBox.Show("Modded Mac game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning); var result = MessageBox.Show("Modded Mac game not found, make sure it's not placed in any subfolders.\nCreated profile will likely not be installable, are you sure you want to continue?", "WARNING", MessageBoxButtons.YesNo, MessageBoxType.Warning);
@ -332,26 +330,26 @@ public partial class ModPacker : Form
private void LoadProfileParameters(ProfileOperatingSystems operatingSystem) private void LoadProfileParameters(ProfileOperatingSystems operatingSystem)
{ {
modinfo.Profile.Name = nameTextBox.Text; modInfo.Profile.Name = nameTextBox.Text;
modinfo.Profile.Author = authorTextBox.Text; modInfo.Profile.Author = authorTextBox.Text;
modinfo.Profile.Version = versionTextBox.Text; modInfo.Profile.Version = versionTextBox.Text;
modinfo.Profile.UsesCustomMusic = musicCheckBox.Checked.Value; modInfo.Profile.UsesCustomMusic = musicCheckBox.Checked.Value;
modinfo.Profile.UsesYYC = yycCheckBox.Checked.Value; modInfo.Profile.UsesYYC = yycCheckBox.Checked.Value;
modinfo.Profile.SupportsAndroid = apkCheckBox.Checked.Value; modInfo.Profile.SupportsAndroid = apkCheckBox.Checked.Value;
modinfo.Profile.ProfileNotes = modNotesTextBox.Text; modInfo.Profile.ProfileNotes = modNotesTextBox.Text;
modinfo.Profile.OperatingSystem = operatingSystem.ToString(); modInfo.Profile.OperatingSystem = operatingSystem.ToString();
if (customSaveCheckBox.Checked.Value && customSaveTextBox.Text != "") if (customSaveCheckBox.Checked.Value && !String.IsNullOrWhiteSpace(customSaveTextBox.Text))
modinfo.Profile.SaveLocation = customSaveTextBox.Text; modInfo.Profile.SaveLocation = customSaveTextBox.Text;
else else
modinfo.Profile.SaveLocation = "%localappdata%/AM2R"; modInfo.Profile.SaveLocation = "%localappdata%/AM2R";
if (operatingSystem == ProfileOperatingSystems.Linux) if (operatingSystem == ProfileOperatingSystems.Linux)
modinfo.Profile.SaveLocation = modinfo.Profile.SaveLocation.Replace("%localappdata%", "~/.config"); modInfo.Profile.SaveLocation = modInfo.Profile.SaveLocation.Replace("%localappdata%", "~/.config");
else if (operatingSystem == ProfileOperatingSystems.Mac) else if (operatingSystem == ProfileOperatingSystems.Mac)
{ {
if (modinfo.Profile.SaveLocation.Contains("%localappdata%/AM2R")) if (modInfo.Profile.SaveLocation.Contains("%localappdata%/AM2R"))
modinfo.Profile.SaveLocation = modinfo.Profile.SaveLocation.Replace("%localappdata%/AM2R", "~/Library/Application Support/com.yoyogames.am2r"); modInfo.Profile.SaveLocation = modInfo.Profile.SaveLocation.Replace("%localappdata%/AM2R", "~/Library/Application Support/com.yoyogames.am2r");
else else
modinfo.Profile.SaveLocation = "~/Library/Application Support/com.yoyogames." + new DirectoryInfo(modinfo.Profile.SaveLocation).Name.ToLower(); modInfo.Profile.SaveLocation = "~/Library/Application Support/com.yoyogames." + new DirectoryInfo(modInfo.Profile.SaveLocation).Name.ToLower();
} }
} }
@ -367,12 +365,12 @@ public partial class ModPacker : Form
private void UpdateCreateButton() private void UpdateCreateButton()
{ {
if (modinfo.IsAM2R11Loaded && // AM2R_11 zip must be provided if (modInfo.IsAM2R11Loaded && // AM2R_11 zip must be provided
(!windowsCheckBox.Checked.Value || modinfo.IsWindowsModLoaded) && // either Windows is disabled OR windows is provided (!windowsCheckBox.Checked.Value || modInfo.IsWindowsModLoaded) && // either Windows is disabled OR windows is provided
(!apkCheckBox.Checked.Value || modinfo.IsApkModLoaded) && // either APK is disabled OR APK is provided (!apkCheckBox.Checked.Value || modInfo.IsApkModLoaded) && // either APK is disabled OR APK is provided
(!linuxCheckBox.Checked.Value || modinfo.IsLinuxModLoaded) && // either Linux is disabled OR linux is provided (!linuxCheckBox.Checked.Value || modInfo.IsLinuxModLoaded) && // either Linux is disabled OR linux is provided
(!macCheckBox.Checked.Value || modinfo.IsMacModLoaded) && // either Mac is disabled OR mac is provided (!macCheckBox.Checked.Value || modInfo.IsMacModLoaded) && // either Mac is disabled OR mac is provided
(modinfo.IsWindowsModLoaded || modinfo.IsLinuxModLoaded || modinfo.IsMacModLoaded) && // one desktop OS has to be selected (modInfo.IsWindowsModLoaded || modInfo.IsLinuxModLoaded || modInfo.IsMacModLoaded) && // one desktop OS has to be selected
(!customSaveCheckBox.Checked.Value || customSaveTextBox.Text != "")) // either custom saves are disabled OR custom save is provided (!customSaveCheckBox.Checked.Value || customSaveTextBox.Text != "")) // either custom saves are disabled OR custom save is provided
createButton.Enabled = true; createButton.Enabled = true;
else else

@ -18,6 +18,4 @@ public class ModCreationInfo
public string ApkModPath; public string ApkModPath;
public string LinuxModPath; public string LinuxModPath;
public string MacModPath; public string MacModPath;
public string SaveFolderPath;
} }
Loading…
Cancel
Save