/**
         * Fills the toMigrationCombo ComboBox data.
         */
        public static void FillTargetMigrationComboOptions()
        {
            ComboBox migrateSourceCombo = MainForm.GetMigrateSourceCombo();
            ComboBox migrateTargetCombo = MainForm.GetMigrateTargetCombo();

            if (migrateTargetCombo.Items.Count <= 0)
            {
                FillMigrationComboOptions(migrateTargetCombo, defaultIgnoreToMigrationItems, true);

                //Making sure we have at least 1 simulator to migrate to, else we exit the program.
                if (migrateTargetCombo.Items.Count == 0)
                {
                    MessageBox.Show("The program could not identify any simulators to migrate to on this computer.\nThe application will now exit.");
                    Application.Exit();
                }

                //We don't need to return because we want to check if we need to remove un-needed options from the "from" combo box.
            }

            int ignoreID = 0;
            int currentMigrateFromSelectedValue = GetSelectedItemValue(migrateSourceCombo);

            if (migrateTargetCombo.SelectedIndex >= 0)
            {
                SimulatorOption selectedItem = GetSelectedItem(migrateTargetCombo);

                foreach (SimulatorOption migrateFromComboItem in migrateSourceCombo.Items)
                {
                    if (selectedItem.Equals(migrateFromComboItem))
                    {
                        ignoreID = selectedItem.GetValue();
                    }
                }
            }

            if (ignoreID > 0)
            {
                int defaultLength = defaultIgnoreFromMigrationItems.Length;

                int[] ignoreIDs = new int[defaultLength + 1];
                defaultIgnoreFromMigrationItems.CopyTo(ignoreIDs, 0);
                ignoreIDs[defaultLength] = ignoreID;

                FillMigrationComboOptions(migrateSourceCombo, ignoreIDs, false);
            }
            else
            {
                FillMigrationComboOptions(migrateSourceCombo, defaultIgnoreFromMigrationItems, false);
            }

            if (SettingsHandler.GetSetting("migrationTarget").Equals("") && migrateTargetCombo.SelectedIndex >= 0 && !defaultTargetChosen)
            {
                SelectItemByVal(migrateTargetCombo, defaultMigrateTo);
                defaultTargetChosen = true;
            }

            SelectItemByVal(migrateSourceCombo, currentMigrateFromSelectedValue);
        }
Esempio n. 2
0
        /**
         * Creates a backup of the target simulator's config files.
         */
        public static bool CreateTargetSimulatorBackup()
        {
            SimulatorOption simOption = MainFormHandler.GetSelectedTargetSimulator();

            if (simOption == null)
            {
                return(false);
            }

            return(CreateConfigFilesBackup(simOption.GetProgramDataPath(), simOption.GetAppDataPath(), true));
        }
Esempio n. 3
0
        /**
         * Copies the config files from the target sim to the source sim.
         */
        public static bool CopyTargetSimFilesToSource()
        {
            SimulatorOption sourceOption = MainFormHandler.GetSelectedSourceSimulator();
            SimulatorOption targetOption = MainFormHandler.GetSelectedTargetSimulator();

            if (sourceOption == null || targetOption == null)
            {
                return(false);
            }

            CreateTargetSimulatorBackup();
            CreateSourceSimulatorBackup();

            string sourceAppDataFolder     = sourceOption.GetAppDataPath(true);
            string sourceProgramDataFolder = sourceOption.GetProgramDataPath(true);
            string targetAppDataFolder     = targetOption.GetAppDataPath(true);
            string targetProgramDataFolder = targetOption.GetProgramDataPath(true);

            foreach (string configFile in configFiles)
            {
                string sourceConfigFile = configFile;

                //Handling Prepar3d.CFG and FSX.CFG files.
                if (configFile.Equals(targetOption.GetSimConfigFile()))
                {
                    sourceConfigFile = sourceOption.GetSimConfigFile();
                }

                try
                {
                    if (File.Exists(targetAppDataFolder + "\\" + configFile))
                    {
                        File.Copy(targetAppDataFolder + "\\" + configFile, sourceAppDataFolder + "\\" + sourceConfigFile, true);
                    }

                    if (File.Exists(targetProgramDataFolder + "\\" + configFile))
                    {
                        File.Copy(targetProgramDataFolder + "\\" + configFile, sourceProgramDataFolder + "\\" + sourceConfigFile, true);
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError("Could not copy file, function copyTargetSimFilesToSource() - " + e.ToString());
                    continue;
                }
            }

            HistoryHandler.AppendHistory("3," + sourceOption.GetValue());

            return(true);
        }
Esempio n. 4
0
        /**
         * Initializes the backup dates.
         */
        public static void OnLoadHandler()
        {
            SimulatorOption targetSimulator = MainFormHandler.GetSelectedTargetSimulator();

            string appDataPath     = targetSimulator.GetAppDataPath(true) + "\\migrationBackup";
            string programDataPath = targetSimulator.GetProgramDataPath(true) + "\\migrationBackup";

            List <string> dates             = new List <string>();
            bool          appDataExists     = Directory.Exists(appDataPath);
            bool          programDataExists = Directory.Exists(programDataPath);

            if (appDataExists || programDataExists)
            {
                if (appDataExists)
                {
                    string[] appDataDirectories = Directory.GetDirectories(appDataPath);

                    foreach (string dir in appDataDirectories)
                    {
                        AddDateToList(dates, dir);
                    }
                }

                if (programDataExists)
                {
                    string[] programDataDirectories = Directory.GetDirectories(programDataPath);

                    foreach (string dir in programDataDirectories)
                    {
                        AddDateToList(dates, dir);
                    }
                }
            }

            if (dates.Count > 0)
            {
                ComboBox restoreDatesCombo = FileRestorationForm.GetRestoreDatesCombo();
                Button   restoreButton     = FileRestorationForm.GetRestoreButton();

                dates.Reverse();

                foreach (string date in dates)
                {
                    restoreDatesCombo.Items.Add(date);
                }

                restoreButton.Enabled = true;
            }
        }
Esempio n. 5
0
        /**
         * Handles the target migration change event.
         */
        public static void TargetMigrationChangeHandler()
        {
            SimulatorOption simOption;

            if (!ignoreTargetMigrationChange)
            {
                MigrationComboFunctions.FillTargetMigrationComboOptions();

                simOption = SimulatorOptions.GetOptionBySelectedItem(MainForm.GetMigrateTargetCombo());
                SettingsHandler.SetSetting("migrationTarget", simOption.GetValue().ToString());
            }

            simOption = SimulatorOptions.GetOptionBySelectedItem(MainForm.GetMigrateTargetCombo());
            selectedTargetSimulator = simOption;
        }
        /**
         * Fills the fromMigrationCombo ComboBox data.
         */
        public static void FillSourceMigrationComboOptions()
        {
            ComboBox migrateSourceCombo = MainForm.GetMigrateSourceCombo();
            ComboBox migrateTargetCombo = MainForm.GetMigrateTargetCombo();

            if (migrateSourceCombo.Items.Count <= 0)
            {
                FillMigrationComboOptions(migrateSourceCombo, defaultIgnoreFromMigrationItems, false);
                return;
            }

            int ignoreID = 0;
            int currentMigrateToSelectedValue = GetSelectedItemValue(migrateTargetCombo);

            if (migrateSourceCombo.SelectedIndex >= 0)
            {
                SimulatorOption selectedItem = GetSelectedItem(migrateSourceCombo);

                foreach (SimulatorOption migrateToComboItem in migrateTargetCombo.Items)
                {
                    if (selectedItem.Equals(migrateToComboItem))
                    {
                        ignoreID = selectedItem.GetValue();
                        break;
                    }
                }
            }

            if (ignoreID > 0)
            {
                int   defaultLength = defaultIgnoreToMigrationItems.Length;
                int[] ignoreIDs     = new int[defaultLength + 1];

                defaultIgnoreToMigrationItems.CopyTo(ignoreIDs, 0);
                ignoreIDs[defaultLength] = ignoreID;

                FillMigrationComboOptions(migrateTargetCombo, ignoreIDs, true);
            }
            else
            {
                FillMigrationComboOptions(migrateTargetCombo, defaultIgnoreToMigrationItems, true);
            }

            SelectItemByVal(migrateTargetCombo, currentMigrateToSelectedValue);
        }
Esempio n. 7
0
        /**
         * Restores the source config files. Should be called on program startup.
         */
        public static bool RestoreSourceConfigFiles(SimulatorOption simOption)
        {
            if (simOption == null)
            {
                return(false);
            }

            string sourceAppDataFolder     = simOption.GetAppDataPath(true);
            string sourceProgramDataFolder = simOption.GetProgramDataPath(true);

            foreach (string configFile in configFiles)
            {
                string completeAppDataBackupFilePath     = sourceAppDataFolder + @"\migrationBackup\" + configFile;
                string completeProgramDataBackupFilePath = sourceProgramDataFolder + @"\migrationBackup\" + configFile;

                try{
                    if (File.Exists(completeAppDataBackupFilePath))
                    {
                        File.Copy(completeAppDataBackupFilePath, sourceAppDataFolder + "\\" + configFile, true);
                        File.Delete(completeAppDataBackupFilePath);
                    }
                }
                catch (Exception e) {
                    ErrorLogger.LogError("Could not copy or delete file at function restoreSourceConfigFiles() - " + e);
                }

                try
                {
                    if (File.Exists(completeProgramDataBackupFilePath))
                    {
                        File.Copy(completeProgramDataBackupFilePath, sourceProgramDataFolder + "\\" + configFile, true);
                        File.Delete(completeProgramDataBackupFilePath);
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError("Could not copy or delete file at function restoreSourceConfigFiles() - " + e);
                }
            }

            return(true);
        }
        /**
         * Fills a specific combo box with the migration options.
         */
        protected static void FillMigrationComboOptions(ComboBox combo, int[] ignoreIDs, bool onlyInPC)
        {
            combo.Items.Clear();

            for (int i = 0; i < allSimulatorOptions.Count; i++)
            {
                SimulatorOption optionObject = allSimulatorOptions[i];

                if (optionObject == null)
                {
                    continue;
                }

                if (ignoreIDs.Contains(optionObject.GetValue()))
                {
                    continue;
                }

                if (onlyInPC && !simOptionsInPC.Contains(optionObject))
                {
                    continue;
                }

                combo.Items.Add(optionObject);
            }

            //Making sure the migration change event does not fire, or else an endless recursion will occur.
            MainFormHandler.SetIgnoreSourceMigrationChange(true);
            MainFormHandler.SetIgnoreTargetMigrationChange(true);

            if (combo.Items.Count > 0)
            {
                combo.SelectedIndex = 0;
            }

            MainFormHandler.SetIgnoreSourceMigrationChange(false);
            MainFormHandler.SetIgnoreTargetMigrationChange(false);
        }
Esempio n. 9
0
        /**
         * Sets the path of the source simulator as the target.
         */
        public static bool SetSourceAsTarget()
        {
            SimulatorOption sourceOption = MainFormHandler.GetSelectedSourceSimulator();
            SimulatorOption targetOption = MainFormHandler.GetSelectedTargetSimulator();

            if (sourceOption == null || targetOption == null)
            {
                return(false);
            }

            string targetPath    = targetOption.GetSimPath();
            int    registryIndex = 0;

            foreach (string registryPath in sourceOption.GetRegistryPaths())
            {
                string sourcePath = RegistryInterface.GetRegistryValue(registryPath);
                RegistryInterface.SetRegistryValue(registryPath, targetPath, true);

                string log = "";

                if (!sourcePath.Equals("") && sourcePath != null)
                {
                    log = "1," + sourceOption.GetValue() + "," + registryIndex + "," + sourcePath;
                }
                else
                {
                    log = "1," + sourceOption.GetValue() + "," + registryIndex + ",0";
                }

                HistoryHandler.AppendHistory(log);

                registryIndex++;
            }

            return(true);
        }
Esempio n. 10
0
        /**
         * The actual listener's functionality.
         */
        private void FileListener(string configFile, System.Timers.Timer currentTimer)
        {
            SimulatorOption sourceOption = MainFormHandler.GetSelectedSourceSimulator();
            SimulatorOption targetOption = MainFormHandler.GetSelectedTargetSimulator();

            //Should never happen but just in case...
            if (sourceOption == null || targetOption == null)
            {
                currentTimer.Stop();
                timers.Remove(currentTimer);

                return;
            }

            string targetConfigFile = configFile;

            //Handling Prepare3D.CFG and FSX.CFG.
            if (configFile.Equals(sourceOption.GetSimConfigFile()))
            {
                targetConfigFile = targetOption.GetSimConfigFile();
            }

            string sourceAppDataPath     = sourceOption.GetAppDataPath(true) + "\\" + configFile;
            string sourceProgramDataPath = sourceOption.GetProgramDataPath(true) + "\\" + configFile;
            string targetAppDataPath     = targetOption.GetAppDataPath(true) + "\\" + targetConfigFile;
            string targetProgramDataPath = targetOption.GetProgramDataPath(true) + "\\" + targetConfigFile;

            bool sourceAppDataExists     = File.Exists(sourceAppDataPath);
            bool sourceProgramDataExists = File.Exists(sourceProgramDataPath);
            bool targetAppDataExists     = File.Exists(targetAppDataPath);
            bool targetProgramDataExists = File.Exists(targetProgramDataPath);

            //If the config file does not exist at all we skip it
            if (!sourceAppDataExists && !sourceProgramDataExists && !targetAppDataExists && !targetProgramDataExists)
            {
                currentTimer.Stop();
                timers.Remove(currentTimer);

                return;
            }

            if (!targetAppDataExists && !targetProgramDataExists)
            {
                currentTimer.Stop();
                timers.Remove(currentTimer);

                return;
            }

            if (targetAppDataExists)
            {
                try
                {
                    if (ShouldCopyFile(targetAppDataPath))
                    {
                        File.Copy(targetAppDataPath, sourceAppDataPath, true);
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError("Could not copy file, function fileListener() - " + e.ToString());
                }
            }

            if (targetProgramDataExists)
            {
                try
                {
                    if (ShouldCopyFile(targetProgramDataPath))
                    {
                        File.Copy(targetProgramDataPath, sourceProgramDataPath, true);
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError("Could not copy file, function fileListener() - " + e.ToString());
                }
            }

            if (sourceAppDataExists)
            {
                try
                {
                    if (ShouldCopyFile(sourceAppDataPath))
                    {
                        File.Copy(sourceAppDataPath, targetAppDataPath, true);
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError("Could not copy file, function fileListener() - " + e.ToString());
                }
            }

            if (sourceProgramDataExists)
            {
                try
                {
                    if (ShouldCopyFile(sourceProgramDataPath))
                    {
                        File.Copy(sourceProgramDataPath, targetProgramDataPath, true);
                    }
                }
                catch (Exception e)
                {
                    ErrorLogger.LogError("Could not copy file, function fileListener() - " + e.ToString());
                }
            }
        }
Esempio n. 11
0
        /**
         * Restores the files according to the date.
         */
        public static bool RestoreFiles(string date)
        {
            SimulatorOption targetSimulator = MainFormHandler.GetSelectedTargetSimulator();

            string appDataPath     = targetSimulator.GetAppDataPath(true);
            string programDataPath = targetSimulator.GetProgramDataPath(true);

            string appDataBackupPath     = targetSimulator.GetAppDataPath(true) + "\\migrationBackup";
            string programDataBackupPath = targetSimulator.GetProgramDataPath(true) + "\\migrationBackup";

            string[] fullDateSplitted = date.Split(' ');
            string[] timeSplitted     = fullDateSplitted[1].Split(':');
            string[] dateSplitted     = fullDateSplitted[0].Split('/');

            string folderName = dateSplitted[2] + "_" + dateSplitted[0] + "_" + dateSplitted[1] + "_" + timeSplitted[0] + "_" + timeSplitted[1] + "_" + timeSplitted[2];

            appDataBackupPath     += "\\" + folderName;
            programDataBackupPath += "\\" + programDataPath;

            bool appDataExists     = Directory.Exists(appDataBackupPath);
            bool programDataExists = Directory.Exists(programDataBackupPath);
            int  filesRestored     = 0;

            if (appDataExists)
            {
                string[] appDataFiles = Directory.GetFiles(appDataBackupPath);

                foreach (string file in appDataFiles)
                {
                    string appDataFileName = Path.GetFileName(file);

                    try
                    {
                        File.Copy(file, appDataPath + "\\" + appDataFileName, true);
                        filesRestored++;
                    }
                    catch (Exception e)
                    {
                        ErrorLogger.LogError("Could not copy file from migrationBackup, function restoreFiles() - " + e.ToString());
                    }
                }
            }

            if (programDataExists)
            {
                string[] programDataBackupFiles = Directory.GetFiles(programDataBackupPath);

                foreach (string file in programDataBackupFiles)
                {
                    string programDataFileName = Path.GetFileName(file);

                    try
                    {
                        File.Copy(file, programDataPath + "\\" + programDataFileName, true);
                        filesRestored++;
                    }
                    catch (Exception e)
                    {
                        ErrorLogger.LogError("Could not copy file from migrationBackup, function restoreFiles() - " + e.ToString());
                    }
                }
            }

            return((appDataExists || programDataExists) && filesRestored > 0);
        }