adjust disposal behavior, recalculate cache

This commit is contained in:
rootdarkarchon
2023-03-18 11:28:00 +01:00
parent fe61b5044b
commit f8e647b242
4 changed files with 54 additions and 28 deletions

View File

@@ -66,7 +66,7 @@ public sealed class FileCacheManager : IDisposable
var fullName = fi.FullName.ToLowerInvariant();
if (!fullName.Contains(_configService.Current.CacheFolder.ToLowerInvariant(), StringComparison.Ordinal)) return null;
string prefixedPath = fullName.Replace(_configService.Current.CacheFolder.ToLowerInvariant(), _cachePrefix + "\\", StringComparison.Ordinal).Replace("\\\\", "\\", StringComparison.Ordinal);
return CreateFileCacheEntity(fi, prefixedPath, fi.Name.ToUpper(CultureInfo.InvariantCulture));
return CreateFileCacheEntity(fi, prefixedPath);
}
public FileCacheEntity? CreateFileEntry(string path)

View File

@@ -3,7 +3,7 @@
<PropertyGroup>
<Authors></Authors>
<Company></Company>
<Version>0.8.9</Version>
<Version>0.8.10</Version>
<Description></Description>
<Copyright></Copyright>
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>

View File

@@ -158,7 +158,14 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
_charaHandler?.Dispose();
_charaHandler = null;
if (!_lifetime.ApplicationStopping.IsCancellationRequested && !_dalamudUtil.IsZoning && !_dalamudUtil.IsInCutscene)
if (!_lifetime.ApplicationStopping.IsCancellationRequested)
{
if (_dalamudUtil.IsZoning)
{
Logger.LogTrace("[{applicationId}] Removing temp collection for {name} ({OnlineUser})", applicationId, name, OnlineUser);
_ipcManager.PenumbraRemoveTemporaryCollection(Logger, applicationId, name);
}
else if (!_dalamudUtil.IsZoning && !_dalamudUtil.IsInCutscene)
{
Logger.LogTrace("[{applicationId}] Restoring state for {name} ({OnlineUser})", applicationId, name, OnlineUser);
_ipcManager.PenumbraRemoveTemporaryCollection(Logger, applicationId, name);
@@ -177,6 +184,7 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
}
}
}
}
catch (Exception ex)
{
Logger.LogWarning(ex, "Error on disposal of {name}", name);
@@ -408,7 +416,7 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
while ((!_applicationTask?.IsCompleted ?? false) && !downloadToken.IsCancellationRequested && !_applicationCancellationTokenSource.IsCancellationRequested)
{
// block until current application is done
Logger.LogDebug("Waiting for current data application (Id: {id}) to finish", _applicationId);
Logger.LogDebug("Waiting for current data application (Id: {id}) for player ({handler}) to finish", _applicationId, PlayerName);
await Task.Delay(250).ConfigureAwait(false);
}
@@ -418,10 +426,17 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
_applicationCancellationTokenSource = new();
var token = _applicationCancellationTokenSource.Token;
_applicationTask = Task.Run(async () =>
{
try
{
_applicationId = Guid.NewGuid();
Logger.LogDebug("[{applicationId}] Starting application task", _applicationId);
Logger.LogDebug("[{applicationId}] Waiting for initial draw for for {handler}", _applicationId, _charaHandler);
await _dalamudUtil.WaitWhileCharacterIsDrawing(Logger, _charaHandler, _applicationId, 30000, token).ConfigureAwait(false);
token.ThrowIfCancellationRequested();
if (updateModdedPaths && (moddedPaths.Any() || !string.IsNullOrEmpty(charaData.ManipulationData)))
{
await ApplyBaseData(_applicationId, moddedPaths, charaData.ManipulationData, token).ConfigureAwait(false);
@@ -435,6 +450,11 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
}
Logger.LogDebug("[{applicationId}] Application finished", _applicationId);
}
catch (Exception ex)
{
Logger.LogInformation("[{applicationId}] Cancelled, reason: {msg}", _applicationId, ex.Message);
}
}, token);
}, downloadToken);
}

View File

@@ -242,7 +242,13 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
fi.LastWriteTime = RandomDayInThePast().Invoke();
try
{
_ = _fileDbManager.CreateCacheEntry(filePath);
var entry = _fileDbManager.CreateCacheEntry(filePath);
if (!string.Equals(entry?.Hash, file.Hash, StringComparison.OrdinalIgnoreCase))
{
Logger.LogError("Hash mismatch after extracting, got {hash}, expected {expectedHash}, deleting file", entry?.Hash, file.Hash);
File.Delete(filePath);
_fileDbManager.RemoveHash(entry);
}
}
catch (Exception ex)
{