private void Btn_resetProgData_Click(object sender, EventArgs e) { var msg = MessageBox.Show("Are you sure you want to reset the quiz progress data? This will remove ALL progress for ALL quizzes. " + "Intelligent Learning will forget EVERYTHING you have done", "Reset Quiz Progress Data - SteelQuiz", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (msg == DialogResult.Yes) { QuizCore.BackupProgress(); try { System.IO.File.Delete(ConfigManager.Config.StorageConfig.QuizProgressFile); } catch (Exception ex) { MessageBox.Show($"An error occurred while resetting quiz progress data:\r\n\r\n{ex.ToString()}", "SteelQuiz", MessageBoxButtons.OK, MessageBoxIcon.Error); } Application.Restart(); } }
public bool Save(bool writeToDisk) { if (!Directory.Exists(txt_defaultQuizSaveFolder.Text)) { MessageBox.Show("Specified default quiz save folder path doesn't exist", "SteelQuiz", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } ConfigManager.Config.StorageConfig.DefaultQuizSaveFolder = txt_defaultQuizSaveFolder.Text; var oldPath = ConfigManager.Config.StorageConfig.QuizProgressFile; string newPath; if (txt_quizProgPath.Text == Path.GetDirectoryName(QuizCore.PROGRESS_FILE_DEFAULT)) { // quiz progress file should have the filename "QuizProgress.json" in the default folder, for compatibility reasons newPath = QuizCore.PROGRESS_FILE_DEFAULT; } else { newPath = Path.Combine(txt_quizProgPath.Text, "SteelQuizProgress.json"); } if (newPath == oldPath) { return(true); } if (!Directory.Exists(Path.GetDirectoryName(newPath))) { MessageBox.Show("Selected directory to store quiz progress data in does not exist", "SteelQuiz", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } try { QuizCore.BackupProgress(); } catch (Exception ex) { txt_quizProgPath.Text = Path.GetDirectoryName(oldPath); throw ex; } if (File.Exists(newPath) && File.Exists(oldPath)) { var conflictSolution = new QuizProgressConflict(); if (conflictSolution.ShowDialog() != DialogResult.OK) { txt_quizProgPath.Text = Path.GetDirectoryName(oldPath); return(false); } if (conflictSolution.ConflictResult == ConflictResult.MergePrioTarget) { var merge = QuizProgressMerger.Merge(newPath, oldPath, newPath); if (!merge) { return(false); } File.Delete(oldPath); } else if (conflictSolution.ConflictResult == ConflictResult.MergePrioCurrent) { var merge = QuizProgressMerger.Merge(oldPath, newPath, newPath); if (!merge) { return(false); } File.Delete(oldPath); } else if (conflictSolution.ConflictResult == ConflictResult.KeepTarget) { try { QuizCore.BackupProgress(); } catch (Exception ex) { txt_quizProgPath.Text = Path.GetDirectoryName(oldPath); throw ex; } File.Delete(oldPath); } else if (conflictSolution.ConflictResult == ConflictResult.OverwriteTarget) { try { QuizCore.BackupProgress(); } catch (Exception ex) { txt_quizProgPath.Text = Path.GetDirectoryName(oldPath); throw ex; } File.Delete(newPath); File.Move(oldPath, newPath); } } else if (File.Exists(oldPath)) { File.Move(oldPath, newPath); } ConfigManager.Config.StorageConfig.QuizProgressFile = newPath; if (writeToDisk) { ConfigManager.SaveConfig(); } QuizCore.LoadQuizAccessData(); Program.frmDashboard.PopulateQuizList(); if (Program.frmDashboard.LoadedQuiz != null) { // Reload quiz Program.frmDashboard.LoadedQuiz = QuizCore.LoadQuiz(Program.frmDashboard.LoadedQuiz.QuizIdentity.FindQuizPath()); Program.frmDashboard.UpdateQuizOverview(); } return(true); }