/// <summary> /// Merges two QuizProgDataRoots into one, by adding all quiz progress datas into one. If duplicates exist, the one with best progress will be selected. /// If same, progressFile1 will have priority /// </summary> /// <param name="progressFile1">The path to the first quiz progress data file. This one has priority over progressFile2</param> /// <param name="progressFile2">The path to the second quiz progress data file.</param> /// <param name="savePath">The path where the merged file should be saved</param> /// <returns>True if the merge was successful, otherwise false</returns> public static bool Merge(string progressFile1, string progressFile2, string savePath) { BackupHelper.BackupFile(progressFile1, Path.Combine(Path.GetDirectoryName(progressFile1), "SteelQuiz Progress Backups"), false); BackupHelper.BackupFile(progressFile2, Path.Combine(Path.GetDirectoryName(progressFile2), "SteelQuiz Progress Backups"), false); if (File.Exists(savePath) && savePath != progressFile1 && savePath != progressFile2) { BackupHelper.BackupFile(savePath, Path.Combine(Path.GetDirectoryName(savePath), "SteelQuiz Progress Backups")); } QuizProgressDataRoot prog1; QuizProgressDataRoot prog2; try { prog1 = JsonConvert.DeserializeObject <QuizProgressDataRoot>(AtomicIO.AtomicRead(progressFile1)); prog2 = JsonConvert.DeserializeObject <QuizProgressDataRoot>(AtomicIO.AtomicRead(progressFile2)); } catch (AtomicException ex) { MessageBox.Show("Could not load progress data files:\r\n\r\n" + ex.ToString(), "SteelQuiz", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } QuizProgressDataRoot merged = Merge(prog1, prog2); #if DEBUG AtomicIO.AtomicWrite(savePath, JsonConvert.SerializeObject(merged, Formatting.Indented)); #else AtomicIO.AtomicWrite(savePath, JsonConvert.SerializeObject(merged)); #endif return(true); }
public static void BackupProgress() { if (!File.Exists(ConfigManager.Config.StorageConfig.QuizProgressFile)) { return; } string destDir = Path.Combine(Path.GetDirectoryName(ConfigManager.Config.StorageConfig.QuizProgressFile), "SteelQuiz Progress Backups"); BackupHelper.BackupFile(ConfigManager.Config.StorageConfig.QuizProgressFile, destDir); }
public static void BackupConfig() { BackupHelper.BackupFile(CONFIG_FILE, CONFIG_BKP_DIR); }