예제 #1
0
        /// <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();
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the deprecated old manifests' path on disk.
        /// </summary>
        /// <returns>The deprecated old manifest's path.</returns>
        private static string GetDeprecatedOldGameManifestPath()
        {
            string oldManifestPath = $@"{ConfigHandler.GetLocalDir()}LauncherManifest.txt.old";

            return(oldManifestPath);
        }
예제 #3
0
        /// <summary>
        /// Gets the old launchpad manifests' path on disk.
        /// </summary>
        /// <returns>The old launchpad manifest's path.</returns>
        public static string GetOldLaunchpadManifestPath()
        {
            string oldManifestPath = $@"{ConfigHandler.GetLocalDir()}LaunchpadManifest.txt.old";

            return(oldManifestPath);
        }
예제 #4
0
        /// <summary>
        /// Gets the launchpad manifests' path on disk.
        /// </summary>
        /// <returns>The launchpad manifest path.</returns>
        public static string GetLaunchpadManifestPath()
        {
            string manifestPath = $@"{ConfigHandler.GetLocalDir()}LaunchpadManifest.txt";

            return(manifestPath);
        }
예제 #5
0
 /// <summary>
 /// Determines whether this is the first time the launcher starts.
 /// </summary>
 /// <returns><c>true</c> if this is the first time; otherwise, <c>false</c>.</returns>
 public static bool IsInitialStartup()
 {
     // We use an empty file to determine if this is the first launch or not
     return(!File.Exists(ConfigHandler.GetLauncherCookiePath()));
 }
예제 #6
0
        /// <summary>
        /// Extracts the bundled update script and populates the variables in it
        /// with the data needed for the update procedure.
        /// </summary>
        private static string GetUpdateScriptSource()
        {
            // Load the script from the embedded resources
            Assembly localAssembly = Assembly.GetExecutingAssembly();

            string scriptSource = "";
            string resourceName = GetUpdateScriptResourceName();

            using (Stream resourceStream = localAssembly.GetManifestResourceStream(resourceName))
            {
                if (resourceStream != null)
                {
                    using (StreamReader reader = new StreamReader(resourceStream))
                    {
                        scriptSource = reader.ReadToEnd();
                    }
                }
            }

            string transientScriptSource = scriptSource;

            transientScriptSource = transientScriptSource.Replace(TempDirectoryVariable, Path.GetTempPath());
            transientScriptSource = transientScriptSource.Replace(LocalInstallDirectoryVariable, ConfigHandler.GetLocalDir());
            transientScriptSource = transientScriptSource.Replace(LocalExecutableName, Path.GetFileName(localAssembly.Location));

            return(transientScriptSource);
        }