Show an error dialog when the game fails to launch

Profile.RunGame never checked the child process's exit code, so if
the game binary crashed immediately (e.g. a missing shared library),
the launcher silently returned to the main screen with no feedback,
even though the failure reason was already being written to the
profile's log file.

RunGame now throws when the process exits with a non-zero code, and
the Play button handler shows that in an error dialog instead of
swallowing it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
pull/119/head
Jeremy Lu 3 months ago
parent f9bd0a3e0b
commit 5d336981c6

@ -207,6 +207,12 @@ namespace AM2RLauncher.Language {
}
}
public static string GameLaunchFailed {
get {
return ResourceManager.GetString("GameLaunchFailed", resourceCulture);
}
}
public static string GithubToolTip {
get {
return ResourceManager.GetString("GithubToolTip", resourceCulture);

@ -198,6 +198,9 @@
<data name="ErrorWindowTitle" xml:space="preserve">
<value>Error</value>
</data>
<data name="GameLaunchFailed" xml:space="preserve">
<value>The game failed to launch.</value>
</data>
<data name="GithubToolTip" xml:space="preserve">
<value>The Community-Developers GitHub Page</value>
</data>

@ -469,7 +469,8 @@ public partial class MainForm : Form
}
catch (Exception ex)
{
MessageBox.Show($"{Text.UnhandledException}\n*****Stack Trace*****\n\n{ex}", Text.ErrorWindowTitle, MessageBoxType.Error);
log.Error(ex.Message);
MessageBox.Show($"{Text.GameLaunchFailed}\n\n{ex.Message}", Text.ErrorWindowTitle, MessageBoxType.Error);
}
ShowInTaskbar = true;

@ -738,6 +738,7 @@ public static class Profile
string gameDirectory = $"{Core.ProfilesPath}/{profile.Name}";
log.Info($"Launching game profile {profile.Name}.");
int exitCode = 0;
if (OS.IsWindows)
{
// Sets the arguments to empty, or to the profiles' logs folder to create time based logs.
@ -777,6 +778,7 @@ public static class Profile
process.Start();
Core.SetForegroundWindow(process.MainWindowHandle);
process.WaitForExit();
exitCode = process.ExitCode;
}
else if (OS.IsLinux)
{
@ -847,6 +849,7 @@ public static class Profile
process.BeginErrorReadLine();
}
process.WaitForExit();
exitCode = process.ExitCode;
}
else if (OS.IsMac)
{
@ -882,10 +885,19 @@ public static class Profile
using Process process = new Process { StartInfo = processStartInfo };
process.Start();
process.WaitForExit();
exitCode = process.ExitCode;
}
else
log.Error($"{OS.Name} cannot run games!");
log.Info($"Profile {profile.Name} process exited.");
if (exitCode != 0)
{
string message = $"Game process for profile \"{profile.Name}\" exited with code {exitCode}, it likely failed to launch.";
if (useLogging)
message += $" Check the log file for more details: {logFile}";
throw new Exception(message);
}
}
}

Loading…
Cancel
Save