Add debug code and update version

This commit is contained in:
Norbi Peti 2022-03-20 20:45:25 +01:00
parent 4eeec67ac4
commit 62963b6fd2
2 changed files with 12 additions and 1 deletions

View file

@ -109,6 +109,7 @@ namespace TBMM
private void HandleGameExit(object sender, EventArgs e) private void HandleGameExit(object sender, EventArgs e)
{ {
Debug.WriteLine("Handling game exit");
_gameProcess = (null, false); _gameProcess = (null, false);
if (InvokeMethod(CheckIfPatched) != GameState.Patched || Configuration.KeepPatched) if (InvokeMethod(CheckIfPatched) != GameState.Patched || Configuration.KeepPatched)
return; return;
@ -128,27 +129,37 @@ namespace TBMM
private bool CheckIfGameIsRunning() private bool CheckIfGameIsRunning()
{ {
Debug.WriteLine($"Check if game is running: {_gameProcess}");
switch (_gameProcess.Process) switch (_gameProcess.Process)
{ {
case { HasExited: false }: case { HasExited: false }:
Debug.WriteLine("Game has not exited");
return true; return true;
case { HasExited: true }: case { HasExited: true }:
Debug.WriteLine("Game has exited, dialog shown");
MessageBox.Show("Game has exited without handling... Please report."); MessageBox.Show("Game has exited without handling... Please report.");
HandleGameExit(null, EventArgs.Empty); HandleGameExit(null, EventArgs.Empty);
return false; return false;
default: default:
Debug.WriteLine($"Process seems to be null: {_gameProcess}");
if (_gameProcess.Process?.HasExited ?? true) if (_gameProcess.Process?.HasExited ?? true)
{
_gameProcess = (Process.GetProcessesByName(GetExe(withExtension: false)).FirstOrDefault(), false); _gameProcess = (Process.GetProcessesByName(GetExe(withExtension: false)).FirstOrDefault(), false);
Debug.WriteLine($"Game process exited already, got new process object: {_gameProcess}");
}
if (_gameProcess.Process == null) return false; if (_gameProcess.Process == null) return false;
if (_gameProcess.Process.HasExited) if (_gameProcess.Process.HasExited)
{ {
Debug.WriteLine($"Game has exited already: {_gameProcess}");
HandleGameExit(null, EventArgs.Empty); HandleGameExit(null, EventArgs.Empty);
return false; return false;
} }
else else
{ {
Debug.WriteLine($"Game is still running");
if (_gameProcess.ExitHandlerAdded) return true; if (_gameProcess.ExitHandlerAdded) return true;
Debug.WriteLine("Game running and no exit handler yet, adding it");
_gameProcess.Process.Exited += HandleGameExit; _gameProcess.Process.Exited += HandleGameExit;
_gameProcess.Process.EnableRaisingEvents = true; _gameProcess.Process.EnableRaisingEvents = true;
_gameProcess.ExitHandlerAdded = true; _gameProcess.ExitHandlerAdded = true;

View file

@ -6,7 +6,7 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<SignAssembly>false</SignAssembly> <SignAssembly>false</SignAssembly>
<ApplicationIcon>favicon.ico</ApplicationIcon> <ApplicationIcon>favicon.ico</ApplicationIcon>
<Version>1.5.0</Version> <Version>1.6.0</Version>
<Authors>NorbiPeti</Authors> <Authors>NorbiPeti</Authors>
<Company>ExMods</Company> <Company>ExMods</Company>
<Description>A mod manager for Techblox. It automatically downloads and runs GCIPA and allows the user to install mods.</Description> <Description>A mod manager for Techblox. It automatically downloads and runs GCIPA and allows the user to install mods.</Description>