Пример #1
0
 public static string T(string o)
 {
     return(Translator.GetText(o));
 }
Пример #2
0
        public static StartGameResult StartGame(string profile, bool startLauncher, bool firstStart)
        {
            if (!TryRestorePermissions())
            {
                return(StartGameResult.PermissionsNeeded);
            }
            GameUtils.RedetectGames();
            StarterProfile e = null;

            try
            {
                e = new StarterProfile(profile);
            }
            catch (Exception)
            {
            }

            if (e == null)
            {
                return(StartGameResult.ProfileNotFound);
            }

            CreateSystemRestore();

            try
            {
                foreach (var game in GameUtils.InstalledGames)
                {
                    if (game != GameUtils.BaseGame && !e.InstalledGames.Contains(game.Name) && game.RegistryKey != null)
                    {
                        RemovePermissions(game.RegistryKey);
                    }
                }
            }
            catch (SecurityException)
            {
                return(StartGameResult.PermissionsNeeded);
            }
            var oldlocale = GameUtils.Locale;

            try
            {
                GameUtils.Locale = e.Locale;
            }
            catch (SecurityException)
            {
                return(StartGameResult.PermissionsNeeded);
            }

            string fname = e.Executable;

            if (startLauncher)
            {
                var games = new List <Game>();
                foreach (Game game in GameUtils.InstalledGames)
                {
                    if (e.InstalledGames.Contains(game.Name))
                    {
                        games.Add(game);
                    }
                }
                fname = GameUtils.UnifiedLauncherExecutable;
            }
            string oldMyDocuments;
            string folder;

            try {
                folder = AdjustMyDocuments(e.VirtualAppDataFolder, out oldMyDocuments);
            }
            catch (ArgumentException) {
                GameUtils.Locale = oldlocale;
                foreach (var game in GameUtils.InstalledGames)
                {
                    if (game.RegistryKey != null)
                    {
                        RestorePermissions(game.RegistryKey);
                    }
                }
                RemoveSystemRestore();
                return(StartGameResult.Success);
            }
            folder = folder.Replace("%USERPROFILE%", e.VirtualAppDataFolder);
            try
            {
                Directory.CreateDirectory(folder);
                Process p = new Process()
                {
                    StartInfo = new ProcessStartInfo(fname)
                    {
                        UseShellExecute = false
                    }
                };
                p.StartInfo.EnvironmentVariables["userprofile"] = e.VirtualAppDataFolder;
                p.StartInfo.WorkingDirectory = Path.GetDirectoryName(fname);
                p.Start();
                try {
                    p.WaitForInputIdle();
                    if (p.MainWindowTitle == "" || startLauncher)
                    {
                        if (firstStart && !startLauncher)
                        {
                            p.Kill();
                        }
                        else
                        {
                            p.WaitForExit();
                        }
                        p.Close();
                        return(StartGameResult.Success);
                    }
                    else
                    {
                        p.WaitForExit();
                        p.Close();
                        return(StartGameResult.EarlyGameExit);
                    }
                }
                catch (Exception)
                {
                    p.Close();
                    return(StartGameResult.Success);
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, Translator.GetText("StartGameErrorDialog"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(StartGameResult.Failure);
            }
            finally
            {
                try {
                    AdjustMyDocuments(oldMyDocuments);
                }
                finally {
                    GameUtils.Locale = oldlocale;
                    foreach (var game in GameUtils.InstalledGames)
                    {
                        if (game.RegistryKey != null)
                        {
                            RestorePermissions(game.RegistryKey);
                        }
                    }
                    RemoveSystemRestore();
                }
            }
        }