Ejemplo n.º 1
0
        /**
         * Handles the form load functions.
         */
        private void MainForm_Load(object sender, EventArgs e)
        {
            staticSourceMigrationCombo = MigrateSourceCombo;
            staticTargetMigrationCombo = MigrateTargetCombo;
            staticStartMigrationButton = StartMigrationButton;

            MainFormHandler.OnLoadHandler();
        }
Ejemplo n.º 2
0
        /**
         * Handles closing the form (via the X button).
         */
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            MainFormHandler.ExitHandler();

            if (e.CloseReason == CloseReason.WindowsShutDown)
            {
                return;
            }
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
 /**
  * Handles click of the startMigrationButton.
  */
 private void StartMigrationButton_Click(object sender, EventArgs e)
 {
     MainFormHandler.StartMigrationHandler();
 }
Ejemplo n.º 7
0
 /**
  * Handles change of the migrateTargetCombo.
  */
 protected void MigrateTargetCombo_SelectedIndexChanged(object sender, EventArgs e)
 {
     MainFormHandler.TargetMigrationChangeHandler();
 }
Ejemplo n.º 8
0
 /**
  * Handles change of the migrateSourceCombo.
  */
 protected void MigrateSourceCombo_SelectedIndexChanged(object sender, EventArgs e)
 {
     MainFormHandler.SourceMigrationChangeHandler();
 }
Ejemplo n.º 9
0
 /**
  * Handles pressing on the exit button in the menu strip.
  */
 private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
 {
     MainFormHandler.ExitHandler();
 }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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());
                }
            }
        }