mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-19 00:51:30 -07:00
fix potential race condition with RobloxState
This commit is contained in:
parent
bff40a40a7
commit
2f651e6c35
@ -1259,8 +1259,17 @@ namespace Bloxstrap
|
||||
}
|
||||
}
|
||||
|
||||
App.RobloxState.Prop.ModManifest = modFolderFiles;
|
||||
App.RobloxState.Save();
|
||||
// make sure we're not overwriting a new update
|
||||
// if we're the background update process, always overwrite
|
||||
if (App.LaunchSettings.BackgroundUpdaterFlag.Active || !App.RobloxState.HasFileOnDiskChanged())
|
||||
{
|
||||
App.RobloxState.Prop.ModManifest = modFolderFiles;
|
||||
App.RobloxState.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
App.Logger.WriteLine(LOG_IDENT, "RobloxState disk mismatch, not saving ModManifest");
|
||||
}
|
||||
|
||||
App.Logger.WriteLine(LOG_IDENT, $"Finished checking file mods");
|
||||
|
||||
|
@ -8,6 +8,11 @@ namespace Bloxstrap
|
||||
|
||||
public T Prop { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// The file hash when last retrieved from disk
|
||||
/// </summary>
|
||||
public string? LastFileHash { get; private set; }
|
||||
|
||||
public virtual string ClassName => typeof(T).Name;
|
||||
|
||||
public virtual string FileLocation => Path.Combine(Paths.Base, $"{ClassName}.json");
|
||||
@ -22,12 +27,15 @@ namespace Bloxstrap
|
||||
|
||||
try
|
||||
{
|
||||
T? settings = JsonSerializer.Deserialize<T>(File.ReadAllText(FileLocation));
|
||||
string contents = File.ReadAllText(FileLocation);
|
||||
|
||||
T? settings = JsonSerializer.Deserialize<T>(contents);
|
||||
|
||||
if (settings is null)
|
||||
throw new ArgumentNullException("Deserialization returned null");
|
||||
|
||||
Prop = settings;
|
||||
LastFileHash = MD5Hash.FromString(contents);
|
||||
|
||||
App.Logger.WriteLine(LOG_IDENT, "Loaded successfully!");
|
||||
}
|
||||
@ -74,7 +82,11 @@ namespace Bloxstrap
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllText(FileLocation, JsonSerializer.Serialize(Prop, new JsonSerializerOptions { WriteIndented = true }));
|
||||
string contents = JsonSerializer.Serialize(Prop, new JsonSerializerOptions { WriteIndented = true });
|
||||
|
||||
File.WriteAllText(FileLocation, contents);
|
||||
|
||||
LastFileHash = MD5Hash.FromString(contents);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
@ -89,5 +101,13 @@ namespace Bloxstrap
|
||||
|
||||
App.Logger.WriteLine(LOG_IDENT, "Save complete!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is the file on disk different to the one deserialised during this session?
|
||||
/// </summary>
|
||||
public bool HasFileOnDiskChanged()
|
||||
{
|
||||
return LastFileHash != MD5Hash.FromFile(FileLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,11 @@ namespace Bloxstrap.Utility
|
||||
return FromStream(stream);
|
||||
}
|
||||
|
||||
public static string FromString(string str)
|
||||
{
|
||||
return FromBytes(Encoding.UTF8.GetBytes(str));
|
||||
}
|
||||
|
||||
public static string Stringify(byte[] hash)
|
||||
{
|
||||
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||
|
Loading…
Reference in New Issue
Block a user