diff --git a/Models/Objective.cs b/Models/Objective.cs index 7a18982..ceed9eb 100644 --- a/Models/Objective.cs +++ b/Models/Objective.cs @@ -1,5 +1,4 @@ using Newtonsoft.Json; -using System.Globalization; namespace ToNSaveManager.Models { @@ -7,6 +6,12 @@ internal struct LegacyObjective { public bool IsCompleted; public string Name; + + public LegacyObjective() + { + IsCompleted = false; + Name = string.Empty; + } } internal class Objective diff --git a/Models/SaveData.cs b/Models/SaveData.cs index 6cc9f42..fe41324 100644 --- a/Models/SaveData.cs +++ b/Models/SaveData.cs @@ -182,6 +182,7 @@ public static SaveData Import() SaveData? data = null; + string filePath = string.Empty; try { if (File.Exists(Destination) && !File.Exists(destination)) @@ -191,7 +192,7 @@ public static SaveData Import() } Destination = destination; - string filePath = readFromLegacy ? LegacyLocation : Destination; + filePath = readFromLegacy ? LegacyLocation : Destination; Debug.WriteLine("Reading from: " + filePath); if (File.Exists(filePath)) @@ -203,6 +204,15 @@ public static SaveData Import() catch (Exception ex) { MessageBox.Show("Error trying to import your save:\n\n" + ex, "Import Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + + try + { + File.Copy(filePath, filePath + $".backup-{DateTime.Now.Year}-{DateTime.Now.Month}-{DateTime.Now.Day}-{DateTime.Now.Hour}{DateTime.Now.Minute}{DateTime.Now.Second}"); + } catch + { + Application.Exit(); + return new SaveData(); + } } if (data == null)