Пример #1
0
        /**
         * Handles the start migration button's functionality.
         */
        public static void StartMigrationHandler()
        {
            string isStarted = SettingsHandler.GetSetting("started");

            if (isStarted.Equals("1"))
            {
                if (HistoryHandler.RevertChanges())
                {
                    SettingsHandler.SetSetting("started", "0");
                    startMigrateButton.Text = START_MIGRATION_TEXT;
                    EnableMigrationCombos();
                    StopSpecialAddonListeners();
                }
                else
                {
                    MessageBox.Show("An error has occured, please try again or contact the developer for support.");
                }
            }
            else
            {
                DisableMigrationCombos();

                if (!FileListeners.InitStaticListeners())
                {
                    HistoryHandler.RevertChanges();
                    MessageBox.Show("An error has occured, please try again or contact the developer for support.");
                    EnableMigrationCombos();

                    return;
                }

                if (!RegistryHandler.SetSourceAsTarget())
                {
                    FileListeners.RemoveListeners();
                    HistoryHandler.RevertChanges();
                    MessageBox.Show("An error has occured, please try again or contact the developer for support.");
                    EnableMigrationCombos();

                    return;
                }

                StartSpecialAddonListeners();

                FilesHandler.CreateFakeFsxExecutable(GetSelectedTargetSimulator().GetSimPath());

                startMigrateButton.Text = STOP_MIGRATION_TEXT;
                SettingsHandler.SetSetting("started", "1");
            }
        }
Пример #2
0
        /**
         * Handles the main form's load functionality.
         */
        public static void OnLoadHandler()
        {
            CloseIfAlreadyRunning();

            MigrationComboFunctions.FillSourceMigrationComboOptions();
            MigrationComboFunctions.FillTargetMigrationComboOptions();

            //If the settings exist, we initialize the selected options from the settings
            string migrationSourceVal = SettingsHandler.GetSetting("migrationSource");
            string migrationTargetVal = SettingsHandler.GetSetting("migrationTarget");

            if (!migrationSourceVal.Equals(""))
            {
                SimulatorOptions.SetSelectedOptionByVal(MainForm.GetMigrateSourceCombo(), Int32.Parse(migrationSourceVal));
            }

            if (!migrationTargetVal.Equals(""))
            {
                SimulatorOptions.SetSelectedOptionByVal(MainForm.GetMigrateTargetCombo(), Int32.Parse(migrationTargetVal));
            }

            string isStarted = SettingsHandler.GetSetting("started");
            string autoStart = SettingsHandler.GetSetting("autoStart");

            //Initializes the listeners if the auto start option is available and the migration is in started mode.
            if (isStarted.Equals("1") && autoStart.Equals("1"))
            {
                startMigrateButton.Text = STOP_MIGRATION_TEXT;

                DisableMigrationCombos();
                FileListeners.InitStaticListeners();
            }
            else
            {
                SettingsHandler.SetSetting("started", "0");
                FilesHandler.RestoreSourceConfigFiles(GetSelectedSourceSimulator()); //Restores the source config files if exist
            }

            InitializeDefaultSettings();
        }
Пример #3
0
        /**
         * Reverts all changes according to the history file.
         */
        public static bool RevertChanges()
        {
            FileListeners.RemoveListeners();

            List <string> history = GetHistory();

            history.Reverse();
            List <string> newHistory = new List <string>(history);

            foreach (string item in history)
            {
                if (!IsValidHistoryRow(item))
                {
                    newHistory.Remove(item);

                    continue;
                }

                string[]        itemData = item.Split(',');
                int             itemType = Int32.Parse(itemData[0]);
                int             simOptionVal;
                SimulatorOption simOption;

                switch (itemType)
                {
                case 1:
                    //Revert registry changes.
                    simOptionVal = Int32.Parse(itemData[1]);
                    simOption    = SimulatorOptions.GetOptionByVal(simOptionVal);

                    if (simOption != null)
                    {
                        bool deleteKey     = itemData.Length < 4 || itemData[3].Equals("") || itemData[3].Equals("0");
                        int  registryIndex = Int32.Parse(itemData[2]);
                        int  counter       = 0;

                        foreach (string registryPath in simOption.GetRegistryPaths())
                        {
                            if (registryIndex != counter)
                            {
                                counter++;
                                continue;
                            }

                            if (deleteKey)
                            {
                                RegistryInterface.DeleteRegistryKey(registryPath);
                            }
                            else
                            {
                                string sourcePath = itemData[3];

                                RegistryInterface.SetRegistryValue(registryPath, sourcePath, true);
                            }

                            counter++;
                        }
                    }

                    newHistory.Remove(item);

                    break;

                case 2:
                    //Delete the fake FSX executable file.
                    simOption = MainFormHandler.GetSelectedTargetSimulator();
                    FilesHandler.DeleteFakeFsxExecutable(simOption.GetSimPath());
                    newHistory.Remove(item);

                    break;

                case 3:
                    //Restore the config files from the migrationBackup folder and delete the file from the backup folder.
                    simOptionVal = Int32.Parse(itemData[1]);
                    simOption    = SimulatorOptions.GetOptionByVal(simOptionVal);

                    FilesHandler.RestoreSourceConfigFiles(simOption);

                    newHistory.Remove(item);

                    break;
                }
            }

            //Sets the history file content.
            SetHistory(newHistory);

            return(true);
        }