예제 #1
0
        /// <summary>
        /// Initializes GlobalSettings class.
        /// Used for all settings that we want to persist, even if the user decides to delete the
        /// json settings file or starts AML from different folders.
        /// </summary>
        private static void InitAppSettings()
        {
            var appSettings    = GlobalSettings.Instance;
            var currentVersion = new Version(GitVersionInfo.MajorMinorPatch);

            if (appSettings.MaxVersion < currentVersion)
            {
                appSettings.MaxVersion = currentVersion;
            }

            // AML will either be used for XCOM2 or Chimera Squad
            // Create Steam application id file if it does not exist (depending on game choice of the user)
            if (!File.Exists(Workshop.APPID_FILENAME))
            {
                // Show Welcome Dialog and ask user to opt-in for Sentry error reporting.
                WelcomeDialog dlg = new WelcomeDialog();
                dlg.ShowDialog();
                appSettings.IsSentryEnabled = dlg.UseSentry;

                try
                {
                    using (var file = File.CreateText(Workshop.APPID_FILENAME))
                    {
                        file.WriteLine((uint)dlg.Game);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Unable to create {Workshop.APPID_FILENAME}. {Environment.NewLine} {ex.Message} ");
                    return;
                }
            }

            // Use Steam Application id file to determine which game this AML installation is used for.
            string appIdStr;

            try
            {
                appIdStr = File.ReadAllText(Workshop.APPID_FILENAME);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Unable to access {Workshop.APPID_FILENAME}. {Environment.NewLine} {ex.Message} ");
                return;
            }

            if (uint.TryParse(appIdStr, out uint appId))
            {
                switch ((GameId)appId)
                {
                case GameId.X2:
                    XEnv = new Xcom2Env();
                    break;

                case GameId.ChimeraSquad:
                    XEnv = new XComChimeraSquadEnv();
                    break;

                default:
                    MessageBox.Show($"The {Workshop.APPID_FILENAME} file contains an unexpected application id: {appId}.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }


            appSettings.Save();
        }