diff --git a/GCMM/GCMM.csproj b/GCMM/GCMM.csproj index 645e151..c8c2435 100644 --- a/GCMM/GCMM.csproj +++ b/GCMM/GCMM.csproj @@ -1,4 +1,4 @@ - + WinExe @@ -22,6 +22,7 @@ + diff --git a/GCMM/MainModInstaller.cs b/GCMM/MainModInstaller.cs index 0fda43a..80e147f 100644 --- a/GCMM/MainModInstaller.cs +++ b/GCMM/MainModInstaller.cs @@ -16,21 +16,21 @@ namespace GCMM public async Task InstallMod(ModInfo mod) { if (mod.DownloadURL == null) return; - if (!File.Exists(Settings.Default.GamePath + @"\Gamecraft.exe")) + if (!File.Exists(GamePath(@"\Gamecraft.exe"))) { MessageBox.Show("Gamecraft not found. Set the correct path in Settings."); return; } var tmp = Directory.CreateDirectory("temp"); - var plugins = Directory.CreateDirectory(Settings.Default.GamePath + @"\Plugins"); - string tmppath = tmp.FullName + "\\" + mod.Name; + var plugins = Directory.CreateDirectory(GamePath(@"\Plugins")); + string tmppath = tmp.FullName + Path.DirectorySeparatorChar + mod.Name; using (var client = GetClient()) { await client.DownloadFileTaskAsync(mod.DownloadURL, tmppath); string disposition = client.ResponseHeaders["Content-Disposition"]; string filename = disposition.Substring(disposition.IndexOf("filename=") + 10).Replace("\"", ""); if (filename.EndsWith(".dll")) - File.Move(tmppath, plugins.FullName + "\\" + mod.Name + ".dll"); //Force mod name to make uninstalls & identifying easier + File.Move(tmppath, plugins.FullName + Path.DirectorySeparatorChar + mod.Name + ".dll"); //Force mod name to make uninstalls & identifying easier else if (filename.EndsWith(".zip")) { bool pluginOnly = true; @@ -120,7 +120,7 @@ namespace GCMM { LoadFileList(mod); if (mod.ModFiles.Count == 0) //A single DLL - File.Delete(Settings.Default.GamePath + @"\Plugins\" + mod.Name + ".dll"); + File.Delete(GamePath(@"\Plugins\" + mod.Name + ".dll")); else //A ZIP { foreach (string file in mod.ModFiles) diff --git a/GCMM/MainModList.cs b/GCMM/MainModList.cs index a867e99..1396fe7 100644 --- a/GCMM/MainModList.cs +++ b/GCMM/MainModList.cs @@ -19,7 +19,7 @@ namespace GCMM public void GetInstalledMods() { - foreach (var modPath in Directory.GetFiles(Settings.Default.GamePath + @"\Plugins", "*.dll")) + foreach (var modPath in Directory.GetFiles(GamePath(@"\Plugins"), "*.dll")) { try { @@ -122,6 +122,8 @@ namespace GCMM } if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion) item.ForeColor = Color.Blue; + else + item.ForeColor = modlist.ForeColor; } public void RemoveModFromList(ModInfo mod) diff --git a/GCMM/MainPatcher.cs b/GCMM/MainPatcher.cs index 17d8539..cf7fffb 100644 --- a/GCMM/MainPatcher.cs +++ b/GCMM/MainPatcher.cs @@ -17,24 +17,25 @@ namespace GCMM { public bool? CheckIfPatched() { - if (!File.Exists(Settings.Default.GamePath + @"\IPA.exe")) + if (!File.Exists(GamePath(@"\IPA.exe"))) { status.Text = "Status: Patcher missing\nClicking Play will install it"; return null; } string nopatch = "Status: Unpatched" + (unpatched.Checked ? "" : "\nClicking Play patches it"); - if (!Directory.Exists(Settings.Default.GamePath + @"\IPA\Backups\Gamecraft")) + string backups = GamePath(@"\IPA\Backups\Gamecraft"); + if (!Directory.Exists(backups)) { status.Text = nopatch; return false; } - string backup = Directory.EnumerateDirectories(Settings.Default.GamePath + @"\IPA\Backups\Gamecraft").OrderByDescending(s => s).FirstOrDefault(); + string backup = Directory.EnumerateDirectories(backups).OrderByDescending(s => s).FirstOrDefault(); if (backup == null) { status.Text = nopatch; return false; } - if (File.GetLastWriteTime(Settings.Default.GamePath + @"\Gamecraft_Data\Managed\Assembly-CSharp.dll") + if (File.GetLastWriteTime(GamePath(@"\Gamecraft_Data\Managed\Assembly-CSharp.dll")) > //If the file was updated at least 2 minutes after patching Directory.GetLastWriteTime(backup).AddMinutes(2)) { @@ -75,8 +76,8 @@ namespace GCMM return; } if (!status.Value ^ unpatched.Checked) - { - var psi = new ProcessStartInfo(Settings.Default.GamePath + @"\IPA.exe", "Gamecraft.exe " + { //TODO: Wine + var psi = new ProcessStartInfo(GamePath(@"\IPA.exe"), "Gamecraft.exe " + (unpatched.Checked ? "--revert " : "") + "--nowait") { UseShellExecute = false, diff --git a/GCMM/MainUtils.cs b/GCMM/MainUtils.cs index 9d4cc54..6679872 100644 --- a/GCMM/MainUtils.cs +++ b/GCMM/MainUtils.cs @@ -32,7 +32,7 @@ namespace GCMM } public string GetGameFolder() - { + { //TODO string libs; if (Environment.OSVersion.Platform == PlatformID.Win32NT) libs = @"C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf"; @@ -59,7 +59,7 @@ namespace GCMM var ofd = new OpenFileDialog(); ofd.Filter = "Gamecraft executable|Gamecraft.exe"; ofd.Title = "Game location"; - ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\"; + ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\"; //TODO ofd.CheckFileExists = true; ofd.ShowDialog(); if (string.IsNullOrWhiteSpace(ofd.FileName)) @@ -77,7 +77,10 @@ namespace GCMM return; } if ((CheckIfPatched() ?? false) || unpatched.Checked) - Process.Start("steam://run/1078000/"); + if (Environment.OSVersion.Platform == PlatformID.Win32NT) + Process.Start("steam://run/1078000/"); + else + Process.Start("xdg-open", "steam://run/1078000/"); }; if (InvokeRequired) Invoke(act); @@ -121,5 +124,10 @@ namespace GCMM if (desc) modlist_SelectedIndexChanged(modlist, null); } + + public string GamePath(string path) + { + return (Settings.Default.GamePath + path).Replace('\\', Path.DirectorySeparatorChar); + } } }