/** * 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); }
/** * 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()); } } }