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 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()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user