Skip to content

Commit

Permalink
Merge branch 'feature/issue-1867/backup-settings' into release
Browse files Browse the repository at this point in the history
Closes #1867
phw198 committed Jun 16, 2024
2 parents 66d9e5d + a4df018 commit 515b7b4
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/OutlookGoogleCalendarSync/SettingsStore/Settings.cs
Original file line number Diff line number Diff line change
@@ -312,6 +312,7 @@ [DataMember] public Int32 CompletedSyncs {
/// </summary>
public static void Load(String XMLfile = null) {
try {
throw new System.ApplicationException();
Settings.Instance = XMLManager.Import<Settings>(XMLfile ?? ConfigFile);
log.Fine("User settings loaded.");
Settings.AreLoaded = true;
@@ -330,8 +331,21 @@ public static void Load(String XMLfile = null) {
}

public static void ResetFile(String XMLfile = null) {
Ogcs.Extensions.MessageBox.Show("Your OGCS settings appear to be corrupt and will have to be reset.",
Ogcs.Extensions.MessageBox.Show("Your OGCS settings appear to be corrupt and will have to be reset.\r\n\r\n" +
"After clicking 'OK', you will have the opportunity to backup the corrupted settings before they are reset.",
"Corrupt OGCS Settings", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
System.Windows.Forms.SaveFileDialog backupFile = new System.Windows.Forms.SaveFileDialog {
Title = "Backup Corrupt OGCS Settings to File",
FileName = "OGCS_corrupt_settings.xml",
Filter = "XML File|*.xml|All Files|*",
DefaultExt = "xml",
AddExtension = true,
OverwritePrompt = true
};
if (backupFile.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
log.Info("Backing up corrupt settings to " + backupFile.FileName);
System.IO.File.Copy(XMLfile ?? ConfigFile, backupFile.FileName);
}
log.Warn("Resetting settings.xml file to defaults.");
System.IO.File.Delete(XMLfile ?? ConfigFile);
Settings.Instance.Save(XMLfile ?? ConfigFile);
2 changes: 1 addition & 1 deletion src/OutlookGoogleCalendarSync/XMLManager.cs
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ public static class XMLManager {
/// <param name="obj">The object that is to be serialized/exported to XML.</param>
/// <param name="filename">The filename of the xml file to be written.</param>
public static void Export(Object obj, string filename) {
XmlTextWriter writer = new XmlTextWriter(filename, null) {
XmlTextWriter writer = new XmlTextWriter(filename, System.Text.Encoding.UTF8) {
Formatting = Formatting.Indented,
Indentation = 4
};

0 comments on commit 515b7b4

Please sign in to comment.