TitleDb loading is handled for multithreading
Fix some memory leaks
This commit is contained in:
@@ -543,9 +543,16 @@ public sealed class SnapshotService : IDisposable, ISnapshotService, IHostedServ
|
||||
|
||||
public void RebuildSnapshot()
|
||||
{
|
||||
// Build a fresh snapshot and persist it.
|
||||
BuildSnapshotAsync(); // private method inside the same class
|
||||
PersistSnapshotAsync(); // private method inside the same class
|
||||
// 1️⃣ Flush the old in‑memory snapshot
|
||||
_cache.Clear();
|
||||
_hashCache.Clear();
|
||||
_archiveLookup.Clear();
|
||||
_sizeLookup.Clear();
|
||||
//_failedAttempts.Clear(); // if you keep per‑user counters
|
||||
|
||||
// 2️⃣ Re‑build from disk again
|
||||
BuildSnapshotAsync().Wait(); // synchronous – we already own the lock
|
||||
PersistSnapshotAsync().Wait(); // same
|
||||
SnapshotRebuilt?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
#endregion
|
||||
@@ -602,7 +609,6 @@ public sealed class SnapshotService : IDisposable, ISnapshotService, IHostedServ
|
||||
var ext = Path.GetExtension(filePath).ToLowerInvariant();
|
||||
if (ext is not ".nsp" and not ".xci" and not ".xcz")
|
||||
{
|
||||
|
||||
// Open the NSP/XCI with LibHac and read the first stream.
|
||||
// The first stream is the first entry returned by GetContentInfos().
|
||||
try
|
||||
@@ -612,12 +618,16 @@ public sealed class SnapshotService : IDisposable, ISnapshotService, IHostedServ
|
||||
var first = reader.GetEntries().FirstOrDefault();
|
||||
if (first == null) return ComputeFullHash(filePath);
|
||||
|
||||
return _nspExtractor.ExtractHashFromStream(first.Stream);
|
||||
using var firstStream = first.Stream;
|
||||
var hash = _nspExtractor.ExtractHashFromStream(firstStream);
|
||||
return hash;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// On error, fall back to the full file hash
|
||||
return ComputeFullHash(filePath);
|
||||
using var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
var ncaMetadataWithHash = _nspExtractor.ExtractFromStream(fs);
|
||||
return ncaMetadataWithHash?.Hash ?? string.Empty;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user