예제 #1
0
        /// <summary>
        /// The main method for startup and initialization.
        /// </summary>
        public void Execute()
        {
            string themePath = ClientConfiguration.Instance.GetThemePath(UserINISettings.Instance.ClientTheme);

            if (themePath == null)
            {
                themePath = ClientConfiguration.Instance.GetThemeInfoFromIndex(0)[1];
            }

            ProgramConstants.RESOURCES_DIR = "Resources/" + themePath;

            if (!Directory.Exists(ProgramConstants.RESOURCES_DIR))
            {
                throw new DirectoryNotFoundException("Theme directory not found!" + Environment.NewLine + ProgramConstants.RESOURCES_DIR);
            }

            Logger.Log("Initializing updater.");

            File.Delete(ProgramConstants.GamePath + "version_u");

            CUpdater.Initialize(ClientConfiguration.Instance.LocalGame);

            Logger.Log("Operating system: " + Environment.OSVersion.VersionString);
            Logger.Log("Selected OS profile: " + MainClientConstants.OSId.ToString());

            // The query in CheckSystemSpecifications takes lots of time,
            // so we'll do it in a separate thread to make startup faster
            Thread thread = new Thread(CheckSystemSpecifications);

            thread.Start();

            Thread idThread = new Thread(GenerateOnlineId);

            idThread.Start();

            Task.Factory.StartNew(MigrateOldLogFiles);

            if (Directory.Exists(ProgramConstants.GamePath + "Updater"))
            {
                Logger.Log("Attempting to delete temporary updater directory.");
                try
                {
                    Directory.Delete(ProgramConstants.GamePath + "Updater", true);
                }
                catch
                {
                }
            }

            if (ClientConfiguration.Instance.CreateSavedGamesDirectory)
            {
                if (!Directory.Exists(ProgramConstants.GamePath + "Saved Games"))
                {
                    Logger.Log("Saved Games directory does not exist - attempting to create one.");
                    try
                    {
                        Directory.CreateDirectory(ProgramConstants.GamePath + "Saved Games");
                    }
                    catch
                    {
                    }
                }
            }

            if (CUpdater.CustomComponents != null)
            {
                Logger.Log("Removing partial custom component downloads.");
                foreach (CustomComponent component in CUpdater.CustomComponents)
                {
                    try
                    {
                        File.Delete(ProgramConstants.GamePath + component.LocalPath + "_u");
                    }
                    catch
                    {
                    }
                }
            }

            FinalSunSettings.WriteFinalSunIni();

            GameSessionManager.CheckForSavesInMainSaveDirectory();

            WriteInstallPathToRegistry();

            ClientConfiguration.Instance.RefreshSettings();

            // Start INI file preprocessor
            PreprocessorBackgroundTask.Instance.Run();

            GameClass gameClass = new GameClass();

            gameClass.Run();
        }