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(); var fullName = fi.FullName.ToLowerInvariant();
if (!fullName.Contains(_configService.Current.CacheFolder.ToLowerInvariant(), StringComparison.Ordinal)) return null; 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); 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) public FileCacheEntity? CreateFileEntry(string path)

View File

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

View File

@@ -158,21 +158,29 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
_charaHandler?.Dispose(); _charaHandler?.Dispose();
_charaHandler = null; _charaHandler = null;
if (!_lifetime.ApplicationStopping.IsCancellationRequested && !_dalamudUtil.IsZoning && !_dalamudUtil.IsInCutscene) if (!_lifetime.ApplicationStopping.IsCancellationRequested)
{ {
Logger.LogTrace("[{applicationId}] Restoring state for {name} ({OnlineUser})", applicationId, name, OnlineUser); if (_dalamudUtil.IsZoning)
_ipcManager.PenumbraRemoveTemporaryCollection(Logger, applicationId, name);
foreach (KeyValuePair<ObjectKind, List<FileReplacementData>> item in _cachedData.FileReplacements)
{ {
try 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);
foreach (KeyValuePair<ObjectKind, List<FileReplacementData>> item in _cachedData.FileReplacements)
{ {
RevertCustomizationData(item.Key, name, applicationId).GetAwaiter().GetResult(); try
} {
catch (InvalidOperationException ex) RevertCustomizationData(item.Key, name, applicationId).GetAwaiter().GetResult();
{ }
Logger.LogWarning("Failed disposing player (not present anymore?)", ex); catch (InvalidOperationException ex)
break; {
Logger.LogWarning("Failed disposing player (not present anymore?)", ex);
break;
}
} }
} }
} }
@@ -408,7 +416,7 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
while ((!_applicationTask?.IsCompleted ?? false) && !downloadToken.IsCancellationRequested && !_applicationCancellationTokenSource.IsCancellationRequested) while ((!_applicationTask?.IsCompleted ?? false) && !downloadToken.IsCancellationRequested && !_applicationCancellationTokenSource.IsCancellationRequested)
{ {
// block until current application is done // 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); await Task.Delay(250).ConfigureAwait(false);
} }
@@ -419,22 +427,34 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
var token = _applicationCancellationTokenSource.Token; var token = _applicationCancellationTokenSource.Token;
_applicationTask = Task.Run(async () => _applicationTask = Task.Run(async () =>
{ {
_applicationId = Guid.NewGuid(); try
Logger.LogDebug("[{applicationId}] Starting application task", _applicationId);
if (updateModdedPaths && (moddedPaths.Any() || !string.IsNullOrEmpty(charaData.ManipulationData)))
{ {
await ApplyBaseData(_applicationId, moddedPaths, charaData.ManipulationData, token).ConfigureAwait(false); _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);
}
token.ThrowIfCancellationRequested();
foreach (var kind in updatedData)
{
await ApplyCustomizationData(_applicationId, kind, charaData, token).ConfigureAwait(false);
}
Logger.LogDebug("[{applicationId}] Application finished", _applicationId);
} }
catch (Exception ex)
token.ThrowIfCancellationRequested();
foreach (var kind in updatedData)
{ {
await ApplyCustomizationData(_applicationId, kind, charaData, token).ConfigureAwait(false); Logger.LogInformation("[{applicationId}] Cancelled, reason: {msg}", _applicationId, ex.Message);
} }
Logger.LogDebug("[{applicationId}] Application finished", _applicationId);
}, token); }, token);
}, downloadToken); }, downloadToken);
} }

View File

@@ -242,7 +242,13 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
fi.LastWriteTime = RandomDayInThePast().Invoke(); fi.LastWriteTime = RandomDayInThePast().Invoke();
try 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) catch (Exception ex)
{ {