Put locks bc im afraid

This commit is contained in:
Nick 2022-12-24 12:31:50 -05:00
parent f6dcf2f4b8
commit bdc4c4d170

View File

@ -11,10 +11,14 @@ namespace NewHorizons.External
private static string _activeProfileName; private static string _activeProfileName;
private static readonly string FileName = "save.json"; private static readonly string FileName = "save.json";
private static object _lock;
// This is its own method so it can be patched by NH-QSB compat // This is its own method so it can be patched by NH-QSB compat
public static string GetProfileName() => StandaloneProfileManager.SharedInstance?.currentProfile?.profileName; public static string GetProfileName() => StandaloneProfileManager.SharedInstance?.currentProfile?.profileName;
public static void Load() public static void Load()
{
lock (_lock)
{ {
_activeProfileName = GetProfileName(); _activeProfileName = GetProfileName();
if (_activeProfileName == null) if (_activeProfileName == null)
@ -48,12 +52,25 @@ namespace NewHorizons.External
} }
} }
} }
}
public static void Save() public static void Save()
{ {
if (_saveFile == null) return; if (_saveFile == null) return;
// Threads exist
lock (_lock)
{
try
{
Main.Instance.ModHelper.Storage.Save(_saveFile, FileName); Main.Instance.ModHelper.Storage.Save(_saveFile, FileName);
} }
catch (Exception ex)
{
Logger.LogError($"Couldn't save data:\n{ex}");
}
}
}
public static void Reset() public static void Reset()
{ {