diff --git a/GCMM/MainForm.Designer.cs b/GCMM/MainForm.Designer.cs index a130da9..a483125 100644 --- a/GCMM/MainForm.Designer.cs +++ b/GCMM/MainForm.Designer.cs @@ -273,6 +273,7 @@ this.Name = "MainForm"; this.Text = "Gamecraft Mod Manager"; this.Load += new System.EventHandler(this.Form1_Load); + this.Shown += new System.EventHandler(this.MainForm_Shown); this.ResumeLayout(false); this.PerformLayout(); diff --git a/GCMM/MainForm.cs b/GCMM/MainForm.cs index bf4f934..4210fab 100644 --- a/GCMM/MainForm.cs +++ b/GCMM/MainForm.cs @@ -47,7 +47,12 @@ If you encounter an issue while any mods are installed, report it to us. If you You may also want to verify the game's files by right clicking the game in Steam and choosing Properties, going to Local files and clicking Verify integrity of game files. "; - private void Form1_Load(object sender, EventArgs e) + private async void Form1_Load(object sender, EventArgs e) + { + await LoadEverything(); + } + + public async Task LoadEverything() { if (Settings.Default.NeedsUpdate) { @@ -56,6 +61,7 @@ You may also want to verify the game's files by right clicking the game in Steam Settings.Default.Save(); } modlist.Items.Clear(); + mods.Clear(); //This method may get called twice when ran from the command line UpdateButton(installbtn, false); modinfobox.Text = defaultInfo; if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null) @@ -75,7 +81,7 @@ 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 - refreshbtn_Click(refreshbtn, null); + await RefreshEverything(); } private async void playbtn_Click(object sender, EventArgs e) @@ -243,6 +249,11 @@ You may also want to verify the game's files by right clicking the game in Steam } private async void refreshbtn_Click(object sender, EventArgs e) + { + await RefreshEverything(); + } + + private async Task RefreshEverything() { CheckIfPatched(); //Set from placeholder lastGameUpdateTime = await GetLastGameUpdateTime(); @@ -265,5 +276,10 @@ You may also want to verify the game's files by right clicking the game in Steam else Process.Start("xdg-open", "steam://validate/1078000/"); } + + private void MainForm_Shown(object sender, EventArgs e) + { + Focus(); + } } } diff --git a/GCMM/MainModList.cs b/GCMM/MainModList.cs index a199fc8..6cea0cc 100644 --- a/GCMM/MainModList.cs +++ b/GCMM/MainModList.cs @@ -190,7 +190,7 @@ namespace GCMM } if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion) item.ForeColor = Color.Blue; - else if (mod.LastUpdated < lastGameUpdateTime) + else if (mod.LastUpdated != default && mod.LastUpdated < lastGameUpdateTime) item.ForeColor = Color.DarkOrange; else item.ForeColor = modlist.ForeColor; diff --git a/GCMM/MainPatcher.cs b/GCMM/MainPatcher.cs index 6ddf6b1..1b57a24 100644 --- a/GCMM/MainPatcher.cs +++ b/GCMM/MainPatcher.cs @@ -66,18 +66,27 @@ namespace GCMM return GameState.Patched; } - public async Task PatchStartGame() + public async Task PatchStartGame(string command = null) { - if (!BeginWork()) return; + if (!BeginWork()) return false; foreach (ListViewItem item in modlist.SelectedItems) item.Selected = false; + bool? retOpenedWindowShouldStay = null; + void EnsureShown(bool stay) + { + if (!Visible) + { + Show(); + retOpenedWindowShouldStay = stay; + } + } var status = CheckIfPatched(); switch (status) { case GameState.NotFound: MessageBox.Show("Gamecraft not found! Set the correct path in Settings."); EndWork(false); - return; + return retOpenedWindowShouldStay; case GameState.NoPatcher: case GameState.OldPatcher: { @@ -88,9 +97,10 @@ namespace GCMM "Patcher download needed", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { EndWork(); - return; + return retOpenedWindowShouldStay; } this.status.Text = "Status: Patching..."; + EnsureShown(false); using (WebClient client = GetClient()) { string url = gcipa.DownloadURL; @@ -110,9 +120,10 @@ namespace GCMM case GameState.NoPatcher: //Make sure it actually worked case GameState.OldPatcher: EndWork(false); - return; + return retOpenedWindowShouldStay; case GameState.Unpatched: { //TODO: Wine + EnsureShown(false); var psi = new ProcessStartInfo(GamePath(@"\IPA.exe"), GetExe() + " --nowait") { UseShellExecute = false, @@ -132,13 +143,23 @@ namespace GCMM }; process.OutputDataReceived += onoutput; process.ErrorDataReceived += onoutput; - process.Exited += CheckStartGame; + process.Exited += command != null ? (EventHandler) ((sender, e) => StartGameUsingCommand(command)) : CheckStartGame; //target-typed conditional expression - C# 9.0 } break; case GameState.Patched: - CheckStartGame(null, null); + if (command != null) + StartGameUsingCommand(command); + else + CheckStartGame(null, null); break; } + return retOpenedWindowShouldStay; + } + + private void StartGameUsingCommand(string command) + { + Process.Start(command); + EndWork(false); } public enum GameState diff --git a/GCMM/MainUtils.cs b/GCMM/MainUtils.cs index af36d49..013eab9 100644 --- a/GCMM/MainUtils.cs +++ b/GCMM/MainUtils.cs @@ -113,6 +113,7 @@ namespace GCMM UpdateButton(installbtn, false); UpdateButton(uninstallbtn, false); UpdateButton(settingsbtn, false); + unpatched.Enabled = false; return true; } @@ -123,6 +124,7 @@ namespace GCMM UpdateButton(settingsbtn, true); if (desc) modlist_SelectedIndexChanged(modlist, null); + unpatched.Enabled = true; } /// @@ -172,7 +174,8 @@ namespace GCMM return default; return new DateTime(1970, 1, 1).AddSeconds(long.Parse(match.Groups[1].Value)); }*/ - return new DateTime(2020, 12, 28); + //return new DateTime(2020, 12, 28); + return default; } } } diff --git a/GCMM/Program.cs b/GCMM/Program.cs index 49684f4..0fa3c01 100644 --- a/GCMM/Program.cs +++ b/GCMM/Program.cs @@ -12,12 +12,40 @@ namespace GCMM /// The main entry point for the application. /// [STAThread] - static void Main() + static void Main(string[] args) { //Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + if (args.Length > 0) + { + DealWithCommandLineAsync(args); + Application.Run(); + return; + } Application.Run(new MainForm()); } + + private static async void DealWithCommandLineAsync(string[] args) + { + var form = new MainForm(); + await form.LoadEverything(); + bool? shouldStay = null; + if (args[0] == "-start" && args.Length > 1) + shouldStay = await form.PatchStartGame(args[1]); + else + MessageBox.Show("Supported options:\n-start - Starts the game using the given command"); + if (shouldStay.HasValue) + { + form.FormClosed += (sender, e) => Application.Exit(); + if (!shouldStay.Value) + { + await Task.Delay(2000); + form.Close(); + } + } + else + Application.Exit(); + } } } diff --git a/GCMM/Properties/launchSettings.json b/GCMM/Properties/launchSettings.json new file mode 100644 index 0000000..cc3d28e --- /dev/null +++ b/GCMM/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "GCMM": { + "commandName": "Project" + } + } +} \ No newline at end of file