diff --git a/GCMM/MainForm.cs b/GCMM/MainForm.cs index 4210fab..f2e55f0 100644 --- a/GCMM/MainForm.cs +++ b/GCMM/MainForm.cs @@ -81,6 +81,34 @@ You may also want to verify the game's files by right clicking the game in Steam DeleteEmptyPluginsDir(out bool pexists, out bool dexists); if (!pexists && dexists) unpatched.Checked = true; //It will call the event but that won't do anything + if(Settings.Default.AutoLaunch && string.IsNullOrWhiteSpace(Settings.Default.SteamConfigFileForAutoLaunch)) + { + string path = @"C:\Program Files (x86)\Steam\userdata"; + if(MessageBox.Show("Do you want GCMM to change the game's launch settings so it can ensure the game is patched?\n\n" + + "If you say yes, GCMM will do a quick check before the game is launched and updates if necessary. " + + "This way you (hopefully) won't see crashes after a Gamecraft update.\n\n" + + "Note that this also means that if you (re)move GCMM without disabling this then you won't be able to launch Gamecraft.", + "GCMM auto-patching", MessageBoxButtons.YesNo)==DialogResult.Yes) + { + var dirs = Directory.GetDirectories(path); + var goodPaths = (from dir in dirs + where File.Exists(dir + @"\config\localconfig.vdf") + select dir + @"\config\localconfig.vdf").ToArray(); + if (goodPaths.Length != 1) + path = SelectSteamConfigFile(); + else + path = goodPaths[0]; + //if (path is not null) + if (path != null) + { + Settings.Default.SteamConfigFileForAutoLaunch = path; + UpdateSteamConfigToAutoStart(true); + } + else + Settings.Default.AutoLaunch = false; + Settings.Default.Save(); + } + } await RefreshEverything(); } diff --git a/GCMM/MainPatcher.cs b/GCMM/MainPatcher.cs index 1b57a24..62e3599 100644 --- a/GCMM/MainPatcher.cs +++ b/GCMM/MainPatcher.cs @@ -143,25 +143,16 @@ namespace GCMM }; process.OutputDataReceived += onoutput; process.ErrorDataReceived += onoutput; - process.Exited += command != null ? (EventHandler) ((sender, e) => StartGameUsingCommand(command)) : CheckStartGame; //target-typed conditional expression - C# 9.0 + process.Exited += CheckStartGame; //target-typed conditional expression - C# 9.0 } break; case GameState.Patched: - if (command != null) - StartGameUsingCommand(command); - else - CheckStartGame(null, null); + CheckStartGame(command, null); //Command may be null but that's okay break; } return retOpenedWindowShouldStay; } - private void StartGameUsingCommand(string command) - { - Process.Start(command); - EndWork(false); - } - public enum GameState { NotFound, diff --git a/GCMM/MainUtils.cs b/GCMM/MainUtils.cs index 013eab9..b09987e 100644 --- a/GCMM/MainUtils.cs +++ b/GCMM/MainUtils.cs @@ -35,7 +35,7 @@ namespace GCMM { //TODO string libs; if (Environment.OSVersion.Platform == PlatformID.Win32NT) - libs = @"C:\Program Files (x86)\Steam\steamapps\libraryfolders.vdf"; + libs = Settings.Default.SteamConfigFileForAutoLaunch + @"\steamapps\libraryfolders.vdf"; else return null; foreach (var line in File.ReadAllLines(libs).Concat(new[] {@"C:\Program Files (x86)\Steam\"})) @@ -67,6 +67,25 @@ namespace GCMM return Directory.GetParent(ofd.FileName).FullName; } + public string SelectSteamConfigFile() + { + MessageBox.Show("Please select your Steam config location in the next dialog. It's at Steam\\userdata\\\\config\\localconfig.vdf"); + var ofd = new OpenFileDialog(); + ofd.Filter = "Steam config|localconfig.vdf"; + ofd.Title = "Steam config location (Steam\\userdata\\\\config\\localconfig.vdf)"; + ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\\userdata\"; //TODO + ofd.CheckFileExists = true; + ofd.ShowDialog(); + if (string.IsNullOrWhiteSpace(ofd.FileName)) + return null; + return ofd.FileName; + } + + private void UpdateSteamConfigToAutoStart(bool autoLaunch) + { + + } + private void CheckStartGame(object sender, EventArgs e) { Action act = () => @@ -77,7 +96,9 @@ namespace GCMM return; } if (CheckIfPatched() == GameState.Patched || unpatched.Checked) - if (Environment.OSVersion.Platform == PlatformID.Win32NT) + if (sender is string command) + Process.Start(command); + else if (Environment.OSVersion.Platform == PlatformID.Win32NT) Process.Start("steam://run/1078000/"); else Process.Start("xdg-open", "steam://run/1078000/"); diff --git a/GCMM/Properties/Settings.Designer.cs b/GCMM/Properties/Settings.Designer.cs index fc3f037..c7dae02 100644 --- a/GCMM/Properties/Settings.Designer.cs +++ b/GCMM/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace GCMM.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.5.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -70,5 +70,29 @@ namespace GCMM.Properties { this["NeedsUpdate"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string SteamConfigFileForAutoLaunch { + get { + return ((string)(this["SteamConfigFileForAutoLaunch"])); + } + set { + this["SteamConfigFileForAutoLaunch"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool AutoLaunch { + get { + return ((bool)(this["AutoLaunch"])); + } + set { + this["AutoLaunch"] = value; + } + } } } diff --git a/GCMM/Properties/Settings.settings b/GCMM/Properties/Settings.settings index 25bd9a4..d610e10 100644 --- a/GCMM/Properties/Settings.settings +++ b/GCMM/Properties/Settings.settings @@ -14,5 +14,11 @@ True + + + + + True + \ No newline at end of file