Skip to content

Commit

Permalink
Merge pull request #35 from ChrisFeline/dev
Browse files Browse the repository at this point in the history
Backup Save on Import Error
  • Loading branch information
ChrisFeline authored Jul 16, 2024
2 parents 3816dd2 + 009016c commit d027e5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Models/Objective.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using Newtonsoft.Json;
using System.Globalization;

namespace ToNSaveManager.Models
{
internal struct LegacyObjective
{
public bool IsCompleted;
public string Name;

public LegacyObjective()
{
IsCompleted = false;
Name = string.Empty;
}
}

internal class Objective
Expand Down
12 changes: 11 additions & 1 deletion Models/SaveData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public static SaveData Import()

SaveData? data = null;

string filePath = string.Empty;
try
{
if (File.Exists(Destination) && !File.Exists(destination))
Expand All @@ -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))
Expand All @@ -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)
Expand Down

0 comments on commit d027e5d

Please sign in to comment.