mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 05:04:15 +01:00
fix: synchronize all writes to ReliableFileStorage
This commit is contained in:
parent
4487ef85f4
commit
38e4fd2673
1 changed files with 28 additions and 26 deletions
|
|
@ -1,10 +1,8 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using Dalamud.Logging.Internal;
|
using Dalamud.Logging.Internal;
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
using PInvoke;
|
|
||||||
using SQLite;
|
using SQLite;
|
||||||
|
|
||||||
namespace Dalamud.Storage;
|
namespace Dalamud.Storage;
|
||||||
|
|
@ -28,6 +26,7 @@ public class ReliableFileStorage : IServiceType, IDisposable
|
||||||
{
|
{
|
||||||
private static readonly ModuleLog Log = new("VFS");
|
private static readonly ModuleLog Log = new("VFS");
|
||||||
|
|
||||||
|
private readonly object syncRoot = new();
|
||||||
private SQLiteConnection? db;
|
private SQLiteConnection? db;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -118,34 +117,37 @@ public class ReliableFileStorage : IServiceType, IDisposable
|
||||||
{
|
{
|
||||||
ArgumentException.ThrowIfNullOrEmpty(path);
|
ArgumentException.ThrowIfNullOrEmpty(path);
|
||||||
|
|
||||||
if (this.db == null)
|
lock (this.syncRoot)
|
||||||
{
|
{
|
||||||
Util.WriteAllBytesSafe(path, bytes);
|
if (this.db == null)
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.db.RunInTransaction(() =>
|
|
||||||
{
|
|
||||||
var normalizedPath = NormalizePath(path);
|
|
||||||
var file = this.db.Table<DbFile>().FirstOrDefault(f => f.Path == normalizedPath && f.ContainerId == containerId);
|
|
||||||
if (file == null)
|
|
||||||
{
|
{
|
||||||
file = new DbFile
|
Util.WriteAllBytesSafe(path, bytes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.db.RunInTransaction(() =>
|
||||||
|
{
|
||||||
|
var normalizedPath = NormalizePath(path);
|
||||||
|
var file = this.db.Table<DbFile>().FirstOrDefault(f => f.Path == normalizedPath && f.ContainerId == containerId);
|
||||||
|
if (file == null)
|
||||||
{
|
{
|
||||||
ContainerId = containerId,
|
file = new DbFile
|
||||||
Path = normalizedPath,
|
{
|
||||||
Data = bytes,
|
ContainerId = containerId,
|
||||||
};
|
Path = normalizedPath,
|
||||||
this.db.Insert(file);
|
Data = bytes,
|
||||||
}
|
};
|
||||||
else
|
this.db.Insert(file);
|
||||||
{
|
}
|
||||||
file.Data = bytes;
|
else
|
||||||
this.db.Update(file);
|
{
|
||||||
}
|
file.Data = bytes;
|
||||||
|
this.db.Update(file);
|
||||||
|
}
|
||||||
|
|
||||||
Util.WriteAllBytesSafe(path, bytes);
|
Util.WriteAllBytesSafe(path, bytes);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue