/** * 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; } }
/** * Selects a specific item in the combo box if exists according to its value. */ protected static void SelectItemByVal(ComboBox combo, int val) { MainFormHandler.SetIgnoreSourceMigrationChange(true); MainFormHandler.SetIgnoreTargetMigrationChange(true); int counter = 0; foreach (SimulatorOption simOption in combo.Items) { if (simOption.GetValue() == val) { combo.SelectedIndex = counter; break; } counter++; } MainFormHandler.SetIgnoreSourceMigrationChange(false); MainFormHandler.SetIgnoreTargetMigrationChange(false); }
/** * 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); }
/** * 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); }