rough impl of FSW, goodbye periodic filescan

This commit is contained in:
rootdarkarchon
2024-02-13 00:56:27 +01:00
committed by Loporrit
parent 136257eecf
commit 739c02cf0b
11 changed files with 525 additions and 255 deletions

View File

@@ -24,7 +24,7 @@ public class IntroUi : WindowMediatorSubscriberBase
{
private readonly ApiController _apiController;
private readonly MareConfigService _configService;
private readonly PeriodicFileScanner _fileCacheManager;
private readonly CacheMonitor _cacheMonitor;
private readonly Dictionary<string, string> _languages = new(StringComparer.Ordinal) { { "English", "en" }, { "Deutsch", "de" }, { "Français", "fr" } };
private readonly ServerConfigurationManager _serverConfigurationManager;
private readonly UiSharedService _uiShared;
@@ -41,12 +41,12 @@ public class IntroUi : WindowMediatorSubscriberBase
private RegisterReplyDto? _registrationReply;
public IntroUi(ILogger<IntroUi> logger, UiSharedService uiShared, MareConfigService configService, ApiController apiController,
PeriodicFileScanner fileCacheManager, ServerConfigurationManager serverConfigurationManager, MareMediator mareMediator) : base(logger, mareMediator, "Loporrit Setup")
CacheMonitor fileCacheManager, ServerConfigurationManager serverConfigurationManager, MareMediator mareMediator) : base(logger, mareMediator, "Loporrit Setup")
{
_uiShared = uiShared;
_configService = configService;
_apiController = apiController;
_fileCacheManager = fileCacheManager;
_cacheMonitor = fileCacheManager;
_serverConfigurationManager = serverConfigurationManager;
IsOpen = false;
@@ -176,11 +176,11 @@ public class IntroUi : WindowMediatorSubscriberBase
_uiShared.DrawCacheDirectorySetting();
}
if (!_fileCacheManager.IsScanRunning && !string.IsNullOrEmpty(_configService.Current.CacheFolder) && _uiShared.HasValidPenumbraModPath && Directory.Exists(_configService.Current.CacheFolder))
if (!_cacheMonitor.IsScanRunning && !string.IsNullOrEmpty(_configService.Current.CacheFolder) && _uiShared.HasValidPenumbraModPath && Directory.Exists(_configService.Current.CacheFolder))
{
if (ImGui.Button("Start Scan##startScan"))
{
_fileCacheManager.InvokeScan(forced: true);
_cacheMonitor.InvokeScan();
}
}
else

View File

@@ -10,6 +10,7 @@ using MareSynchronos.API.Data.Comparer;
using MareSynchronos.API.Dto.Account;
using MareSynchronos.API.Routes;
using MareSynchronos.FileCache;
using MareSynchronos.Interop;
using MareSynchronos.MareConfiguration;
using MareSynchronos.MareConfiguration.Models;
using MareSynchronos.PlayerData.Export;
@@ -36,6 +37,8 @@ namespace MareSynchronos.UI;
public class SettingsUi : WindowMediatorSubscriberBase
{
private readonly ApiController _apiController;
private readonly IpcManager _ipcManager;
private readonly CacheMonitor _cacheMonitor;
private readonly MareConfigService _configService;
private readonly ConcurrentDictionary<GameObjectHandler, Dictionary<string, FileDownloadStatus>> _currentDownloads = new();
private readonly FileCompactor _fileCompactor;
@@ -77,7 +80,8 @@ public class SettingsUi : WindowMediatorSubscriberBase
FileUploadManager fileTransferManager,
FileTransferOrchestrator fileTransferOrchestrator,
FileCacheManager fileCacheManager,
FileCompactor fileCompactor, ApiController apiController) : base(logger, mediator, "Loporrit Settings")
FileCompactor fileCompactor, ApiController apiController,
IpcManager ipcManager, CacheMonitor cacheMonitor) : base(logger, mediator, "Loporrit Settings")
{
_configService = configService;
_mareCharaFileManager = mareCharaFileManager;
@@ -90,6 +94,8 @@ public class SettingsUi : WindowMediatorSubscriberBase
_fileTransferOrchestrator = fileTransferOrchestrator;
_fileCacheManager = fileCacheManager;
_apiController = apiController;
_ipcManager = ipcManager;
_cacheMonitor = cacheMonitor;
_fileCompactor = fileCompactor;
_uiShared = uiShared;
AllowClickthrough = false;
@@ -727,7 +733,57 @@ public class SettingsUi : WindowMediatorSubscriberBase
"The storage governs itself by clearing data beyond the set storage size. Please set the storage size accordingly. It is not necessary to manually clear the storage.");
_uiShared.DrawFileScanState();
_uiShared.DrawTimeSpanBetweenScansSetting();
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted("Monitoring Penumbra Folder: " + (_cacheMonitor.PenumbraWatcher?.Path ?? "Not monitoring"));
if (string.IsNullOrEmpty(_cacheMonitor.PenumbraWatcher?.Path))
{
ImGui.SameLine();
using var id = ImRaii.PushId("penumbraMonitor");
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.ArrowsToCircle, "Try to reinitialize Monitor"))
{
_cacheMonitor.StartPenumbraWatcher(_ipcManager.PenumbraModDirectory);
}
}
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted("Monitoring Mare Storage Folder: " + (_cacheMonitor.MareWatcher?.Path ?? "Not monitoring"));
if (string.IsNullOrEmpty(_cacheMonitor.MareWatcher?.Path))
{
ImGui.SameLine();
using var id = ImRaii.PushId("mareMonitor");
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.ArrowsToCircle, "Try to reinitialize Monitor"))
{
_cacheMonitor.StartMareWatcher(_configService.Current.CacheFolder);
}
}
if (_cacheMonitor.MareWatcher == null || _cacheMonitor.PenumbraWatcher == null)
{
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.Play, "Resume Monitoring"))
{
_cacheMonitor.StartMareWatcher(_configService.Current.CacheFolder);
_cacheMonitor.StartPenumbraWatcher(_ipcManager.PenumbraModDirectory);
_cacheMonitor.InvokeScan();
}
UiSharedService.AttachToolTip("Attempts to resume monitoring for both Penumbra and Mare Storage. "
+ "Resuming the monitoring will also force a full scan to run." + Environment.NewLine
+ "If the button remains present after clicking it, consult /xllog for errors");
}
else
{
using (ImRaii.Disabled(!UiSharedService.CtrlPressed()))
{
if (UiSharedService.NormalizedIconTextButton(FontAwesomeIcon.Stop, "Stop Monitoring"))
{
_cacheMonitor.StopMonitoring();
}
}
UiSharedService.AttachToolTip("Stops the monitoring for both Penumbra and Mare Storage. "
+ "Do not stop the monitoring, unless you plan to move the Penumbra and Mare Storage folders, to ensure correct functionality of Mare." + Environment.NewLine
+ "If you stop the monitoring to move folders around, resume it after you are finished moving the files."
+ UiSharedService.TooltipSeparator + "Hold CTRL to enable this button");
}
_uiShared.DrawCacheDirectorySetting();
ImGui.TextUnformatted($"Currently utilized local storage: {UiSharedService.ByteToString(_uiShared.FileCacheSize)}");
bool isLinux = Util.IsWine();
@@ -827,8 +883,6 @@ public class SettingsUi : WindowMediatorSubscriberBase
{
File.Delete(file);
}
_uiShared.RecalculateFileCacheSize();
});
}
UiSharedService.AttachToolTip("You normally do not need to do this. THIS IS NOT SOMETHING YOU SHOULD BE DOING TO TRY TO FIX SYNC ISSUES." + Environment.NewLine

View File

@@ -43,7 +43,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
private readonly ApiController _apiController;
private readonly PeriodicFileScanner _cacheScanner;
private readonly CacheMonitor _cacheMonitor;
private readonly MareConfigService _configService;
@@ -79,14 +79,14 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
private int _serverSelectionIndex = -1;
public UiSharedService(ILogger<UiSharedService> logger, IpcManager ipcManager, ApiController apiController,
PeriodicFileScanner cacheScanner, FileDialogManager fileDialogManager,
CacheMonitor cacheMonitor, FileDialogManager fileDialogManager,
MareConfigService configService, DalamudUtilService dalamudUtil, IDalamudPluginInterface pluginInterface,
ITextureProvider textureProvider, Dalamud.Localization localization,
ServerConfigurationManager serverManager, MareMediator mediator) : base(logger, mediator)
{
_ipcManager = ipcManager;
_apiController = apiController;
_cacheScanner = cacheScanner;
_cacheMonitor = cacheMonitor;
FileDialogManager = fileDialogManager;
_configService = configService;
_dalamudUtil = dalamudUtil;
@@ -123,7 +123,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public bool EditTrackerPosition { get; set; }
public long FileCacheSize => _cacheScanner.FileCacheSize;
public long FileCacheSize => _cacheMonitor.FileCacheSize;
public bool HasValidPenumbraModPath => !(_ipcManager.PenumbraModDirectory ?? string.Empty).IsNullOrEmpty() && Directory.Exists(_ipcManager.PenumbraModDirectory);
@@ -618,7 +618,8 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
{
_configService.Current.CacheFolder = path;
_configService.Save();
_cacheScanner.StartScan();
_cacheMonitor.StartMareWatcher(path);
_cacheMonitor.InvokeScan();
}
});
}
@@ -742,41 +743,45 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
public void DrawFileScanState()
{
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted("File Scanner Status");
ImGui.SameLine();
if (_cacheScanner.IsScanRunning)
if (_cacheMonitor.IsScanRunning)
{
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted("Scan is running");
ImGui.TextUnformatted("Current Progress:");
ImGui.SameLine();
ImGui.TextUnformatted(_cacheScanner.TotalFiles == 1
ImGui.TextUnformatted(_cacheMonitor.TotalFiles == 1
? "Collecting files"
: $"Processing {_cacheScanner.CurrentFileProgress}/{_cacheScanner.TotalFilesStorage} from storage ({_cacheScanner.TotalFiles} scanned in)");
: $"Processing {_cacheMonitor.CurrentFileProgress}/{_cacheMonitor.TotalFilesStorage} from storage ({_cacheMonitor.TotalFiles} scanned in)");
AttachToolTip("Note: it is possible to have more files in storage than scanned in, " +
"this is due to the scanner normally ignoring those files but the game loading them in and using them on your character, so they get " +
"added to the local storage.");
}
else if (_configService.Current.FileScanPaused)
else if (_cacheMonitor.HaltScanLocks.Any(f => f.Value > 0))
{
ImGui.TextUnformatted("File scanner is paused");
ImGui.SameLine();
if (ImGui.Button("Force Rescan##forcedrescan"))
{
_cacheScanner.InvokeScan(forced: true);
}
}
else if (_cacheScanner.HaltScanLocks.Any(f => f.Value > 0))
{
ImGui.TextUnformatted("Halted (" + string.Join(", ", _cacheScanner.HaltScanLocks.Where(f => f.Value > 0).Select(locker => locker.Key + ": " + locker.Value + " halt requests")) + ")");
ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted("Halted (" + string.Join(", ", _cacheMonitor.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();
_cacheMonitor.ResetLocks();
}
}
else
{
ImGui.TextUnformatted("Next scan in " + _cacheScanner.TimeUntilNextScan);
ImGui.TextUnformatted("Idle");
if (_configService.Current.InitialScanComplete)
{
ImGui.SameLine();
if (NormalizedIconTextButton(FontAwesomeIcon.Play, "Force rescan"))
{
_cacheMonitor.InvokeScan();
}
}
}
}
@@ -940,36 +945,12 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
return _serverSelectionIndex;
}
public void DrawTimeSpanBetweenScansSetting()
{
var timeSpan = _configService.Current.TimeSpanBetweenScansInSeconds;
ImGui.SetNextItemWidth(250 * ImGuiHelpers.GlobalScale);
if (ImGui.SliderInt("Seconds between scans##timespan", ref timeSpan, 20, 60))
{
_configService.Current.TimeSpanBetweenScansInSeconds = timeSpan;
_configService.Save();
}
DrawHelpText("This is the time in seconds between file scans. Increase it to reduce system load. A too high setting can cause issues when manually fumbling about in the cache or Penumbra mods folders.");
var isPaused = _configService.Current.FileScanPaused;
if (ImGui.Checkbox("Pause periodic file scan##filescanpause", ref isPaused))
{
_configService.Current.FileScanPaused = isPaused;
_configService.Save();
}
DrawHelpText("This allows you to stop the periodic scans of your Penumbra and Loporrit cache directories. Use this to move the Loporrit cache and Penumbra mod folders around. If you enable this permanently, run a Force rescan after adding mods to Penumbra.");
}
public void LoadLocalization(string languageCode)
{
_localization.SetupWithLangCode(languageCode);
Strings.ToS = new Strings.ToSStrings();
}
public void RecalculateFileCacheSize()
{
_cacheScanner.InvokeScan(forced: true);
}
[LibraryImport("user32")]
internal static partial short GetKeyState(int nVirtKey);