//TODO: Implement better crash or failure to launch recognition /// <summary> /// Launches the game. /// </summary> public void LaunchGame() { //start new process of the game executable try { ProcessStartInfo gameStartInfo = new ProcessStartInfo(); gameStartInfo.UseShellExecute = false; gameStartInfo.FileName = Config.GetGameExecutable(); GameExitArgs.GameName = Config.GetGameName(); Log.Info($"Launching game. \n\tExecutable path: {gameStartInfo.FileName}"); Process game = Process.Start(gameStartInfo); game.EnableRaisingEvents = true; game.Exited += delegate { if (game.ExitCode != 0) { Log.Info($"The game exited with an exit code of {game.ExitCode}. " + "There may have been issues during runtime, or the game may not have started at all."); } GameExitArgs.ExitCode = game.ExitCode; OnGameExited(); }; } catch (IOException ioex) { Log.Warn($"Game launch failed (IOException): {ioex.Message}"); GameExitArgs.ExitCode = 1; OnGameLaunchFailed(); } }
//TODO: Implement better crash or failure to launch recognition /// <summary> /// Launches the game. /// </summary> public void LaunchGame() { //start new process of the game executable try { ProcessStartInfo gameStartInfo = new ProcessStartInfo(); gameStartInfo.UseShellExecute = false; gameStartInfo.FileName = Config.GetGameExecutable(); GameExitArgs.GameName = Config.GetGameName(); Process game = Process.Start(gameStartInfo); game.EnableRaisingEvents = true; game.Exited += delegate { GameExitArgs.ExitCode = game.ExitCode; OnGameExited(); }; } catch (IOException ioex) { Console.WriteLine("IOException in LaunchGame(): " + ioex.Message); GameExitArgs.ExitCode = 1; OnGameLaunchFailed(); } }
/// <summary> /// Sends the usage stats to the official launchpad server. /// </summary> public static void SendUsageStats() { WebResponse sendStatsResponse = null; try { string formattedURL = $"{BaseURL}guid={Config.GetGameGUID()}" + $"&launcherVersion={Config.GetLocalLauncherVersion()}" + $"&gameName={Config.GetGameName()}" + $"&systemType={Config.GetSystemTarget()}" + $"&officialUpdates={Config.GetDoOfficialUpdates()}" + $"&installguid={ConfigHandler.GetInstallGUID()}"; WebRequest sendStatsRequest = WebRequest.Create(formattedURL); sendStatsResponse = sendStatsRequest.GetResponse(); } catch (WebException wex) { Log.Warn("Could not send usage stats (WebException): " + wex.Message); } finally { sendStatsResponse?.Dispose(); } }
/// <summary> /// Sends the usage stats to the official launchpad server. /// </summary> static public void SendUsageStats() { try { const string baseURL = "http://directorate.asuscomm.com/launchpad/stats.php?"; string formattedURL = String.Format(baseURL + "guid={0}&launcherVersion={1}&gameName={2}&systemType={3}&officialUpdates={4}&installguid={5}", Config.GetGameGUID(), Config.GetLocalLauncherVersion(), Config.GetGameName(), Config.GetSystemTarget(), Config.GetDoOfficialUpdates(), Config.GetInstallGUID() ); WebRequest sendStatsRequest = WebRequest.Create(formattedURL); sendStatsRequest.GetResponse(); } catch (WebException wex) { Console.WriteLine("WebException in SendUsageStats(): " + wex.Message); } }
/// <summary> /// Launches the game. /// </summary> public void LaunchGame() { //start new process of the game executable try { // Do not move the argument assignment inside the gameStartInfo initializer. // It causes a TargetInvocationException crash through black magic. string gameArguments = string.Join(" ", ConfigHandler.GetGameArguments()); ProcessStartInfo gameStartInfo = new ProcessStartInfo { UseShellExecute = false, FileName = Config.GetGameExecutable(), Arguments = gameArguments }; this.GameExitArgs.GameName = Config.GetGameName(); Log.Info($"Launching game. \n\tExecutable path: {gameStartInfo.FileName}"); Process gameProcess = new Process { StartInfo = gameStartInfo, EnableRaisingEvents = true }; gameProcess.Exited += delegate { if (gameProcess.ExitCode != 0) { Log.Info($"The game exited with an exit code of {gameProcess.ExitCode}. " + "There may have been issues during runtime, or the game may not have started at all."); } this.GameExitArgs.ExitCode = gameProcess.ExitCode; OnGameExited(); // Manual disposing gameProcess.Dispose(); }; // Make sure the game executable is flagged as such on Unix if (SystemInformation.IsRunningOnUnix()) { Process.Start("chmod", $"+x {Config.GetGameExecutable()}"); } gameProcess.Start(); } catch (FileNotFoundException fex) { Log.Warn($"Game launch failed (FileNotFoundException): {fex.Message}"); Log.Warn("If the game executable is there, try overriding the executable name in the configuration file."); this.GameExitArgs.ExitCode = 2; OnGameLaunchFailed(); } catch (IOException ioex) { Log.Warn($"Game launch failed (IOException): {ioex.Message}"); this.GameExitArgs.ExitCode = 1; OnGameLaunchFailed(); } }