From 5063a64d18fcbf8f5f29e56667c3069a2dd98840 Mon Sep 17 00:00:00 2001 From: Miepee Date: Fri, 9 Dec 2022 17:42:17 +0100 Subject: [PATCH] Fix custom saves on Linux --- AM2RModPacker/ModPacker.cs | 40 +++++++++++++++++++++++++------------- AM2RModPackerLib/Core.cs | 3 +-- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/AM2RModPacker/ModPacker.cs b/AM2RModPacker/ModPacker.cs index ca6824b..4df10d2 100644 --- a/AM2RModPacker/ModPacker.cs +++ b/AM2RModPacker/ModPacker.cs @@ -32,32 +32,44 @@ public partial class ModPacker : Form private void CustomSaveDataButton_Click(object sender, EventArgs e) { bool wasSuccessful = false; - // TODO: make sure that the validation works on other platforms too - var winSaveRegex = 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 linSaveRegex = new Regex(@"$/\.config"); // Linux users can set their home directory wherever they want to, for each individual application - //TODO: var macSaveRegex + var winSaveRegex = 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 linSaveRegex = new Regex($@"{Environment.GetEnvironmentVariable("HOME")}/\.config/.*"); // GMS hardcodes save into ~/.config on linux + + //TODO: var macSaveRegex = ???? var dialog = new SelectFolderDialog(); - // TODO: .config on linux + string initialDir = ""; + if (OS.IsWindows) + initialDir = Environment.GetEnvironmentVariable("LocalAppData"); + else if (OS.IsLinux) + initialDir = Environment.GetEnvironmentVariable("HOME") + "/.config"; + else if (OS.IsMac) + initialDir = ""; //TODO! - dialog.Directory = Environment.GetEnvironmentVariable("LocalAppData"); + dialog.Directory = initialDir; while (!wasSuccessful) { if (dialog.ShowDialog(this) == DialogResult.Ok) { - Match match; - match = winSaveRegex.Match(dialog.Directory); + Match match = Match.Empty; + if (OS.IsWindows) + match = winSaveRegex.Match(dialog.Directory); + else if (OS.IsLinux) + match = linSaveRegex.Match(dialog.Directory); + else if (OS.IsMac) + match = winSaveRegex.Match(dialog.Directory); //TODO! + if (match.Success == false) - { - // TODO: different error messages - MessageBox.Show("Invalid Save Directory! Please choose one in %LocalAppData%"); - } + MessageBox.Show("Invalid Save Directory! Please consult the GameMaker: Studio 1.4 documentation for valid save directories!"); else { - //TODO: needs to be OS specific + //TODO: figure out mac 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 (OS.IsWindows) + { + 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/"; diff --git a/AM2RModPackerLib/Core.cs b/AM2RModPackerLib/Core.cs index f94fcc4..d22f533 100644 --- a/AM2RModPackerLib/Core.cs +++ b/AM2RModPackerLib/Core.cs @@ -19,8 +19,7 @@ public static class Core public static readonly string Version = "2.0.3"; private const string originalMD5 = "f2b84fe5ba64cb64e284be1066ca08ee"; private static readonly string[] DATAFILES_BLACKLIST = { "data.win", "AM2R.exe", "D3DX9_43.dll", "game.unx", "game.ios" }; - // todo: dont do this, cwd is unreliable - private static readonly string localPath = Directory.GetCurrentDirectory(); + private static readonly string localPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); // TODO: go over thhis and clean public static (bool, string) CreateModPack(ModProfileXML profile, string originalZipPath, string modZipPath, string apkPath, string output)