mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Put locks bc im afraid
This commit is contained in:
parent
f6dcf2f4b8
commit
bdc4c4d170
17
NewHorizons/External/NewHorizonsData.cs
vendored
17
NewHorizons/External/NewHorizonsData.cs
vendored
@ -11,10 +11,14 @@ namespace NewHorizons.External
|
||||
private static string _activeProfileName;
|
||||
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
|
||||
public static string GetProfileName() => StandaloneProfileManager.SharedInstance?.currentProfile?.profileName;
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
_activeProfileName = GetProfileName();
|
||||
if (_activeProfileName == null)
|
||||
@ -48,12 +52,25 @@ namespace NewHorizons.External
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Save()
|
||||
{
|
||||
if (_saveFile == null) return;
|
||||
|
||||
// Threads exist
|
||||
lock (_lock)
|
||||
{
|
||||
try
|
||||
{
|
||||
Main.Instance.ModHelper.Storage.Save(_saveFile, FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"Couldn't save data:\n{ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user