delay start scan to ingame login, show what is halting scans in settings ui and allow resetting it
This commit is contained in:
@@ -17,9 +17,9 @@ public class PeriodicFileScanner : IDisposable
|
|||||||
private readonly FileCacheManager _fileDbManager;
|
private readonly FileCacheManager _fileDbManager;
|
||||||
private readonly ApiController _apiController;
|
private readonly ApiController _apiController;
|
||||||
private readonly DalamudUtil _dalamudUtil;
|
private readonly DalamudUtil _dalamudUtil;
|
||||||
private int haltScanRequests = 0;
|
|
||||||
private CancellationTokenSource? _scanCancellationTokenSource;
|
private CancellationTokenSource? _scanCancellationTokenSource;
|
||||||
private Task? _fileScannerTask = null;
|
private Task? _fileScannerTask = null;
|
||||||
|
public ConcurrentDictionary<string, int> haltScanLocks = new();
|
||||||
public PeriodicFileScanner(IpcManager ipcManager, Configuration pluginConfiguration, FileCacheManager fileDbManager, ApiController apiController, DalamudUtil dalamudUtil)
|
public PeriodicFileScanner(IpcManager ipcManager, Configuration pluginConfiguration, FileCacheManager fileDbManager, ApiController apiController, DalamudUtil dalamudUtil)
|
||||||
{
|
{
|
||||||
Logger.Verbose("Creating " + nameof(PeriodicFileScanner));
|
Logger.Verbose("Creating " + nameof(PeriodicFileScanner));
|
||||||
@@ -30,32 +30,57 @@ public class PeriodicFileScanner : IDisposable
|
|||||||
_apiController = apiController;
|
_apiController = apiController;
|
||||||
_dalamudUtil = dalamudUtil;
|
_dalamudUtil = dalamudUtil;
|
||||||
_ipcManager.PenumbraInitialized += StartScan;
|
_ipcManager.PenumbraInitialized += StartScan;
|
||||||
if (!string.IsNullOrEmpty(_ipcManager.PenumbraModDirectory()))
|
_apiController.DownloadStarted += ApiHaltScan;
|
||||||
{
|
_apiController.DownloadFinished += ApiResumeScan;
|
||||||
StartScan();
|
_dalamudUtil.ZoneSwitchStart += ZoneSwitchHaltScan;
|
||||||
}
|
_dalamudUtil.ZoneSwitchEnd += ZoneSwitchResumeScan;
|
||||||
_apiController.DownloadStarted += HaltScan;
|
|
||||||
_apiController.DownloadFinished += ResumeScan;
|
|
||||||
_dalamudUtil.ZoneSwitchStart += HaltScan;
|
|
||||||
_dalamudUtil.ZoneSwitchEnd += ResumeScan;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResumeScan()
|
private void ApiHaltScan()
|
||||||
{
|
{
|
||||||
Interlocked.Decrement(ref haltScanRequests);
|
HaltScan("Download");
|
||||||
|
}
|
||||||
|
|
||||||
if (fileScanWasRunning && haltScanRequests == 0)
|
private void ApiResumeScan()
|
||||||
|
{
|
||||||
|
ResumeScan("Download");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ZoneSwitchHaltScan()
|
||||||
|
{
|
||||||
|
HaltScan("Zoning/Gpose");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ZoneSwitchResumeScan()
|
||||||
|
{
|
||||||
|
ResumeScan("Zoning/Gpose");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetLocks()
|
||||||
|
{
|
||||||
|
haltScanLocks.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResumeScan(string source)
|
||||||
|
{
|
||||||
|
if (!haltScanLocks.ContainsKey(source)) haltScanLocks[source] = 0;
|
||||||
|
|
||||||
|
haltScanLocks[source]--;
|
||||||
|
if (haltScanLocks[source] < 0) haltScanLocks[source] = 0;
|
||||||
|
|
||||||
|
if (fileScanWasRunning && haltScanLocks.All(f => f.Value == 0))
|
||||||
{
|
{
|
||||||
fileScanWasRunning = false;
|
fileScanWasRunning = false;
|
||||||
InvokeScan(true);
|
InvokeScan(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HaltScan()
|
public void HaltScan(string source)
|
||||||
{
|
{
|
||||||
Interlocked.Increment(ref haltScanRequests);
|
if (!haltScanLocks.ContainsKey(source)) haltScanLocks[source] = 0;
|
||||||
|
haltScanLocks[source]++;
|
||||||
|
|
||||||
if (IsScanRunning && haltScanRequests >= 0)
|
if (IsScanRunning && haltScanLocks.Any(f => f.Value > 0))
|
||||||
{
|
{
|
||||||
_scanCancellationTokenSource?.Cancel();
|
_scanCancellationTokenSource?.Cancel();
|
||||||
fileScanWasRunning = true;
|
fileScanWasRunning = true;
|
||||||
@@ -81,10 +106,10 @@ public class PeriodicFileScanner : IDisposable
|
|||||||
Logger.Verbose("Disposing " + nameof(PeriodicFileScanner));
|
Logger.Verbose("Disposing " + nameof(PeriodicFileScanner));
|
||||||
|
|
||||||
_ipcManager.PenumbraInitialized -= StartScan;
|
_ipcManager.PenumbraInitialized -= StartScan;
|
||||||
_apiController.DownloadStarted -= HaltScan;
|
_apiController.DownloadStarted -= ApiHaltScan;
|
||||||
_apiController.DownloadFinished -= ResumeScan;
|
_apiController.DownloadFinished -= ApiResumeScan;
|
||||||
_dalamudUtil.ZoneSwitchStart -= HaltScan;
|
_dalamudUtil.ZoneSwitchStart -= ZoneSwitchHaltScan;
|
||||||
_dalamudUtil.ZoneSwitchEnd -= ResumeScan;
|
_dalamudUtil.ZoneSwitchEnd -= ZoneSwitchResumeScan;
|
||||||
_scanCancellationTokenSource?.Cancel();
|
_scanCancellationTokenSource?.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +125,7 @@ public class PeriodicFileScanner : IDisposable
|
|||||||
{
|
{
|
||||||
while (!token.IsCancellationRequested)
|
while (!token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
while (haltScanRequests > 0)
|
while (haltScanLocks.Any(f => f.Value > 0))
|
||||||
{
|
{
|
||||||
await Task.Delay(TimeSpan.FromSeconds(1));
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
||||||
}
|
}
|
||||||
@@ -125,11 +150,6 @@ public class PeriodicFileScanner : IDisposable
|
|||||||
}, token);
|
}, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void StartWatchers()
|
|
||||||
{
|
|
||||||
InvokeScan();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool RecalculateFileCacheSize()
|
public bool RecalculateFileCacheSize()
|
||||||
{
|
{
|
||||||
FileCacheSize = Directory.EnumerateFiles(_pluginConfiguration.CacheFolder).Sum(f =>
|
FileCacheSize = Directory.EnumerateFiles(_pluginConfiguration.CacheFolder).Sum(f =>
|
||||||
@@ -306,10 +326,10 @@ public class PeriodicFileScanner : IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartScan()
|
public void StartScan()
|
||||||
{
|
{
|
||||||
if (!_ipcManager.Initialized || !_pluginConfiguration.HasValidSetup()) return;
|
if (!_ipcManager.Initialized || !_pluginConfiguration.HasValidSetup()) return;
|
||||||
Logger.Verbose("Penumbra is active, configuration is valid, starting watchers and scan");
|
Logger.Verbose("Penumbra is active, configuration is valid, scan");
|
||||||
InvokeScan(true);
|
InvokeScan(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,14 +235,14 @@ namespace MareSynchronos.Managers
|
|||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
_periodicFileScanner.HaltScan();
|
_periodicFileScanner.HaltScan("Character creation");
|
||||||
foreach (var item in unprocessedObjects)
|
foreach (var item in unprocessedObjects)
|
||||||
{
|
{
|
||||||
_dalamudUtil.WaitWhileCharacterIsDrawing("self " + item.ObjectKind.ToString(), item.Address, 10000, token);
|
_dalamudUtil.WaitWhileCharacterIsDrawing("self " + item.ObjectKind.ToString(), item.Address, 10000, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
CharacterCacheDto? cacheDto = (await CreateFullCharacterCacheDto(token));
|
CharacterCacheDto? cacheDto = (await CreateFullCharacterCacheDto(token));
|
||||||
_periodicFileScanner.ResumeScan();
|
_periodicFileScanner.ResumeScan("Character creation");
|
||||||
if (cacheDto == null || token.IsCancellationRequested) return;
|
if (cacheDto == null || token.IsCancellationRequested) return;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Authors></Authors>
|
<Authors></Authors>
|
||||||
<Company></Company>
|
<Company></Company>
|
||||||
<Version>0.4.20</Version>
|
<Version>0.4.21</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>
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ namespace MareSynchronos
|
|||||||
{
|
{
|
||||||
_introUi.IsOpen = false;
|
_introUi.IsOpen = false;
|
||||||
_compactUi.IsOpen = true;
|
_compactUi.IsOpen = true;
|
||||||
_periodicFileScanner.StartWatchers();
|
_periodicFileScanner.StartScan();
|
||||||
ReLaunchCharacterManager();
|
ReLaunchCharacterManager();
|
||||||
};
|
};
|
||||||
_compactUi.OpenSettingsUi += () =>
|
_compactUi.OpenSettingsUi += () =>
|
||||||
@@ -146,6 +146,7 @@ namespace MareSynchronos
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_periodicFileScanner.StartScan();
|
||||||
ReLaunchCharacterManager();
|
ReLaunchCharacterManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
@@ -165,6 +166,15 @@ namespace MareSynchronos.UI
|
|||||||
_cacheScanner.InvokeScan(true);
|
_cacheScanner.InvokeScan(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (_cacheScanner.haltScanLocks.Any(f => f.Value > 0))
|
||||||
|
{
|
||||||
|
ImGui.Text("Halted (" + string.Join(", ", _cacheScanner.haltScanLocks.Where(f => f.Value > 0).Select(locker => locker.Key + ": " + locker.Value + " halt requests")) + ")");
|
||||||
|
ImGui.SameLine();
|
||||||
|
if (ImGui.Button("Reset halt requests##clearlocks"))
|
||||||
|
{
|
||||||
|
_cacheScanner.ResetLocks();
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ImGui.Text("Next scan in " + _cacheScanner.TimeUntilNextScan);
|
ImGui.Text("Next scan in " + _cacheScanner.TimeUntilNextScan);
|
||||||
@@ -455,7 +465,7 @@ namespace MareSynchronos.UI
|
|||||||
{
|
{
|
||||||
_pluginConfiguration.CacheFolder = path;
|
_pluginConfiguration.CacheFolder = path;
|
||||||
_pluginConfiguration.Save();
|
_pluginConfiguration.Save();
|
||||||
_cacheScanner.StartWatchers();
|
_cacheScanner.StartScan();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user