more fixes
This commit is contained in:
@@ -57,6 +57,7 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
|||||||
if (configService.Current.HasValidSetup())
|
if (configService.Current.HasValidSetup())
|
||||||
{
|
{
|
||||||
StartMareWatcher(configService.Current.CacheFolder);
|
StartMareWatcher(configService.Current.CacheFolder);
|
||||||
|
InvokeScan();
|
||||||
}
|
}
|
||||||
|
|
||||||
var token = _periodicCalculationTokenSource.Token;
|
var token = _periodicCalculationTokenSource.Token;
|
||||||
@@ -350,11 +351,11 @@ public sealed class CacheMonitor : DisposableMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
TotalFiles = 0;
|
TotalFiles = 0;
|
||||||
_currentFileProgress = 0;
|
_currentFileProgress = 0;
|
||||||
_scanCancellationTokenSource?.Cancel();
|
_scanCancellationTokenSource = _scanCancellationTokenSource?.CancelRecreate() ?? new CancellationTokenSource();
|
||||||
_scanCancellationTokenSource = new CancellationTokenSource();
|
|
||||||
var token = _scanCancellationTokenSource.Token;
|
var token = _scanCancellationTokenSource.Token;
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
|
Logger.LogDebug("Starting Full File Scan");
|
||||||
TotalFiles = 0;
|
TotalFiles = 0;
|
||||||
_currentFileProgress = 0;
|
_currentFileProgress = 0;
|
||||||
while (_dalamudUtil.IsOnFrameworkThread)
|
while (_dalamudUtil.IsOnFrameworkThread)
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ public sealed class FileCacheManager : IHostedService
|
|||||||
|
|
||||||
public FileCacheEntity? CreateCacheEntry(string path)
|
public FileCacheEntity? CreateCacheEntry(string path)
|
||||||
{
|
{
|
||||||
_logger.LogTrace("Creating cache entry for {path}", path);
|
|
||||||
FileInfo fi = new(path);
|
FileInfo fi = new(path);
|
||||||
if (!fi.Exists) return null;
|
if (!fi.Exists) return null;
|
||||||
|
_logger.LogTrace("Creating cache entry for {path}", path);
|
||||||
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);
|
||||||
@@ -49,9 +49,9 @@ public sealed class FileCacheManager : IHostedService
|
|||||||
|
|
||||||
public FileCacheEntity? CreateFileEntry(string path)
|
public FileCacheEntity? CreateFileEntry(string path)
|
||||||
{
|
{
|
||||||
_logger.LogTrace("Creating file entry for {path}", path);
|
|
||||||
FileInfo fi = new(path);
|
FileInfo fi = new(path);
|
||||||
if (!fi.Exists) return null;
|
if (!fi.Exists) return null;
|
||||||
|
_logger.LogTrace("Creating file entry for {path}", path);
|
||||||
var fullName = fi.FullName.ToLowerInvariant();
|
var fullName = fi.FullName.ToLowerInvariant();
|
||||||
if (!fullName.Contains(_ipcManager.PenumbraModDirectory!.ToLowerInvariant(), StringComparison.Ordinal)) return null;
|
if (!fullName.Contains(_ipcManager.PenumbraModDirectory!.ToLowerInvariant(), StringComparison.Ordinal)) return null;
|
||||||
string prefixedPath = fullName.Replace(_ipcManager.PenumbraModDirectory!.ToLowerInvariant(), PenumbraPrefix + "\\", StringComparison.Ordinal).Replace("\\\\", "\\", StringComparison.Ordinal);
|
string prefixedPath = fullName.Replace(_ipcManager.PenumbraModDirectory!.ToLowerInvariant(), PenumbraPrefix + "\\", StringComparison.Ordinal).Replace("\\\\", "\\", StringComparison.Ordinal);
|
||||||
@@ -159,7 +159,7 @@ public sealed class FileCacheManager : IHostedService
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileCacheEntity? GetFileCacheByPath(string path)
|
private FileCacheEntity? GetFileCacheByPath(string path)
|
||||||
{
|
{
|
||||||
var cleanedPath = path.Replace("/", "\\", StringComparison.OrdinalIgnoreCase).ToLowerInvariant().Replace(_ipcManager.PenumbraModDirectory!.ToLowerInvariant(), "", StringComparison.OrdinalIgnoreCase);
|
var cleanedPath = path.Replace("/", "\\", StringComparison.OrdinalIgnoreCase).ToLowerInvariant().Replace(_ipcManager.PenumbraModDirectory!.ToLowerInvariant(), "", StringComparison.OrdinalIgnoreCase);
|
||||||
var entry = _fileCaches.SelectMany(v => v.Value).FirstOrDefault(f => f.ResolvedFilepath.EndsWith(cleanedPath, StringComparison.OrdinalIgnoreCase));
|
var entry = _fileCaches.SelectMany(v => v.Value).FirstOrDefault(f => f.ResolvedFilepath.EndsWith(cleanedPath, StringComparison.OrdinalIgnoreCase));
|
||||||
@@ -183,18 +183,25 @@ public sealed class FileCacheManager : IHostedService
|
|||||||
{
|
{
|
||||||
var cleanedPaths = paths.Distinct(StringComparer.OrdinalIgnoreCase).ToDictionary(p => p,
|
var cleanedPaths = paths.Distinct(StringComparer.OrdinalIgnoreCase).ToDictionary(p => p,
|
||||||
p => p.Replace("/", "\\", StringComparison.OrdinalIgnoreCase)
|
p => p.Replace("/", "\\", StringComparison.OrdinalIgnoreCase)
|
||||||
.Replace(_ipcManager.PenumbraModDirectory!, PenumbraPrefix, StringComparison.OrdinalIgnoreCase)
|
.Replace(_ipcManager.PenumbraModDirectory!, _ipcManager.PenumbraModDirectory!.EndsWith('\\') ? PenumbraPrefix + '\\' : PenumbraPrefix, StringComparison.OrdinalIgnoreCase)
|
||||||
.Replace(_configService.Current.CacheFolder, CachePrefix, StringComparison.OrdinalIgnoreCase)
|
.Replace(_configService.Current.CacheFolder, _configService.Current.CacheFolder.EndsWith('\\') ? CachePrefix + '\\' : CachePrefix, StringComparison.OrdinalIgnoreCase)
|
||||||
.Replace("\\\\", "\\", StringComparison.Ordinal),
|
.Replace("\\\\", "\\", StringComparison.Ordinal),
|
||||||
StringComparer.OrdinalIgnoreCase);
|
StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
foreach (var entry in cleanedPaths)
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Getting FileCache by Cleaned Path: {path}", entry.Value);
|
||||||
|
}
|
||||||
|
|
||||||
Dictionary<string, FileCacheEntity?> result = new(StringComparer.OrdinalIgnoreCase);
|
Dictionary<string, FileCacheEntity?> result = new(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
var dict = _fileCaches.SelectMany(f => f.Value)
|
var dict = _fileCaches.SelectMany(f => f.Value)
|
||||||
.ToDictionary(d => d.PrefixedFilePath, d => d, StringComparer.Ordinal);
|
.ToDictionary(d => d.PrefixedFilePath, d => d, StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
foreach (var entry in cleanedPaths)
|
foreach (var entry in cleanedPaths)
|
||||||
{
|
{
|
||||||
|
_logger.LogDebug("Validating {path}", entry.Value);
|
||||||
|
|
||||||
if (dict.TryGetValue(entry.Value, out var entity))
|
if (dict.TryGetValue(entry.Value, out var entity))
|
||||||
{
|
{
|
||||||
var validatedCache = GetValidatedFileCache(entity);
|
var validatedCache = GetValidatedFileCache(entity);
|
||||||
@@ -221,10 +228,12 @@ public sealed class FileCacheManager : IHostedService
|
|||||||
{
|
{
|
||||||
if (_fileCaches.TryGetValue(hash, out var caches))
|
if (_fileCaches.TryGetValue(hash, out var caches))
|
||||||
{
|
{
|
||||||
caches?.RemoveAll(c => string.Equals(c.PrefixedFilePath, prefixedFilePath, StringComparison.Ordinal));
|
var removedCount = caches?.RemoveAll(c => string.Equals(c.PrefixedFilePath, prefixedFilePath, StringComparison.Ordinal));
|
||||||
|
_logger.LogDebug("Removed {count} files with hash {hash} and file cache {path}", removedCount, hash, prefixedFilePath);
|
||||||
|
|
||||||
if (caches?.Count == 0)
|
if (caches?.Count == 0)
|
||||||
{
|
{
|
||||||
_fileCaches.Remove(hash, out _);
|
_fileCaches.Remove(hash, out var entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,7 +343,7 @@ public sealed class FileCacheManager : IHostedService
|
|||||||
File.AppendAllLines(_csvPath, new[] { entity.CsvEntry });
|
File.AppendAllLines(_csvPath, new[] { entity.CsvEntry });
|
||||||
}
|
}
|
||||||
var result = GetFileCacheByPath(fileInfo.FullName);
|
var result = GetFileCacheByPath(fileInfo.FullName);
|
||||||
_logger.LogDebug("Creating file cache for {name} success: {success}", fileInfo.FullName, (result != null));
|
_logger.LogDebug("Creating cache entity for {name} success: {success}", fileInfo.FullName, (result != null));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ public class MarePlugin : MediatorSubscriberBase, IHostedService
|
|||||||
Mediator.Subscribe<DalamudLoginMessage>(this, (_) => DalamudUtilOnLogIn());
|
Mediator.Subscribe<DalamudLoginMessage>(this, (_) => DalamudUtilOnLogIn());
|
||||||
Mediator.Subscribe<DalamudLogoutMessage>(this, (_) => DalamudUtilOnLogOut());
|
Mediator.Subscribe<DalamudLogoutMessage>(this, (_) => DalamudUtilOnLogOut());
|
||||||
|
|
||||||
|
Mediator.StartQueueProcessing();
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -146,13 +146,13 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
s.GetRequiredService<ILogger<GameChatHooks>>(), gameInteropProvider, chatGui,
|
s.GetRequiredService<ILogger<GameChatHooks>>(), gameInteropProvider, chatGui,
|
||||||
s.GetRequiredService<MareConfigService>(), s.GetRequiredService<ServerConfigurationManager>()));
|
s.GetRequiredService<MareConfigService>(), s.GetRequiredService<ServerConfigurationManager>()));
|
||||||
|
|
||||||
collection.AddHostedService(p => p.GetRequiredService<MarePlugin>());
|
|
||||||
collection.AddHostedService(p => p.GetRequiredService<FileCacheManager>());
|
collection.AddHostedService(p => p.GetRequiredService<FileCacheManager>());
|
||||||
|
collection.AddHostedService(p => p.GetRequiredService<MareMediator>());
|
||||||
collection.AddHostedService(p => p.GetRequiredService<ConfigurationMigrator>());
|
collection.AddHostedService(p => p.GetRequiredService<ConfigurationMigrator>());
|
||||||
collection.AddHostedService(p => p.GetRequiredService<DalamudUtilService>());
|
collection.AddHostedService(p => p.GetRequiredService<DalamudUtilService>());
|
||||||
collection.AddHostedService(p => p.GetRequiredService<PerformanceCollectorService>());
|
collection.AddHostedService(p => p.GetRequiredService<PerformanceCollectorService>());
|
||||||
collection.AddHostedService(p => p.GetRequiredService<DtrEntry>());
|
collection.AddHostedService(p => p.GetRequiredService<DtrEntry>());
|
||||||
collection.AddHostedService(p => p.GetRequiredService<MareMediator>());
|
collection.AddHostedService(p => p.GetRequiredService<MarePlugin>());
|
||||||
})
|
})
|
||||||
.Build()
|
.Build()
|
||||||
.RunAsync(_pluginCts.Token);
|
.RunAsync(_pluginCts.Token);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public sealed class MareMediator : IHostedService
|
|||||||
private readonly ConcurrentQueue<MessageBase> _messageQueue = new();
|
private readonly ConcurrentQueue<MessageBase> _messageQueue = new();
|
||||||
private readonly PerformanceCollectorService _performanceCollector;
|
private readonly PerformanceCollectorService _performanceCollector;
|
||||||
private readonly Dictionary<Type, HashSet<SubscriberAction>> _subscriberDict = [];
|
private readonly Dictionary<Type, HashSet<SubscriberAction>> _subscriberDict = [];
|
||||||
|
private bool _processQueue = false;
|
||||||
|
|
||||||
public MareMediator(ILogger<MareMediator> logger, PerformanceCollectorService performanceCollector)
|
public MareMediator(ILogger<MareMediator> logger, PerformanceCollectorService performanceCollector)
|
||||||
{
|
{
|
||||||
@@ -60,6 +61,11 @@ public sealed class MareMediator : IHostedService
|
|||||||
{
|
{
|
||||||
while (!_loopCts.Token.IsCancellationRequested)
|
while (!_loopCts.Token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
|
while (!_processQueue)
|
||||||
|
{
|
||||||
|
await Task.Delay(100, _loopCts.Token).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
await Task.Delay(100, _loopCts.Token).ConfigureAwait(false);
|
await Task.Delay(100, _loopCts.Token).ConfigureAwait(false);
|
||||||
|
|
||||||
HashSet<MessageBase> processedMessages = [];
|
HashSet<MessageBase> processedMessages = [];
|
||||||
@@ -167,6 +173,12 @@ public sealed class MareMediator : IHostedService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void StartQueueProcessing()
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Starting Message Queue Processing");
|
||||||
|
_processQueue = true;
|
||||||
|
}
|
||||||
|
|
||||||
private sealed class SubscriberAction
|
private sealed class SubscriberAction
|
||||||
{
|
{
|
||||||
public SubscriberAction(IMediatorSubscriber subscriber, object action)
|
public SubscriberAction(IMediatorSubscriber subscriber, object action)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public static class VariousExtensions
|
|||||||
|
|
||||||
public static CancellationTokenSource CancelRecreate(this CancellationTokenSource? cts)
|
public static CancellationTokenSource CancelRecreate(this CancellationTokenSource? cts)
|
||||||
{
|
{
|
||||||
cts.CancelDispose();
|
cts?.CancelDispose();
|
||||||
return new CancellationTokenSource();
|
return new CancellationTokenSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user