rough impl of FSW, goodbye periodic filescan

This commit is contained in:
rootdarkarchon
2024-02-13 00:56:27 +01:00
parent ac11ec087a
commit 6f397d9b12
11 changed files with 525 additions and 254 deletions

View File

@@ -16,7 +16,7 @@ namespace MareSynchronos.UI;
public class IntroUi : WindowMediatorSubscriberBase
{
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;
@@ -29,11 +29,11 @@ public class IntroUi : WindowMediatorSubscriberBase
private string[]? _tosParagraphs;
public IntroUi(ILogger<IntroUi> logger, UiSharedService uiShared, MareConfigService configService,
PeriodicFileScanner fileCacheManager, ServerConfigurationManager serverConfigurationManager, MareMediator mareMediator) : base(logger, mareMediator, "Mare Synchronos Setup")
CacheMonitor fileCacheManager, ServerConfigurationManager serverConfigurationManager, MareMediator mareMediator) : base(logger, mareMediator, "Mare Synchronos Setup")
{
_uiShared = uiShared;
_configService = configService;
_fileCacheManager = fileCacheManager;
_cacheMonitor = fileCacheManager;
_serverConfigurationManager = serverConfigurationManager;
IsOpen = false;
@@ -163,11 +163,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

@@ -7,6 +7,7 @@ using ImGuiNET;
using MareSynchronos.API.Data;
using MareSynchronos.API.Data.Comparer;
using MareSynchronos.FileCache;
using MareSynchronos.Interop;
using MareSynchronos.MareConfiguration;
using MareSynchronos.MareConfiguration.Models;
using MareSynchronos.PlayerData.Export;
@@ -30,6 +31,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;
@@ -64,7 +67,8 @@ public class SettingsUi : WindowMediatorSubscriberBase
FileUploadManager fileTransferManager,
FileTransferOrchestrator fileTransferOrchestrator,
FileCacheManager fileCacheManager,
FileCompactor fileCompactor, ApiController apiController) : base(logger, mediator, "Mare Synchronos Settings")
FileCompactor fileCompactor, ApiController apiController,
IpcManager ipcManager, CacheMonitor cacheMonitor) : base(logger, mediator, "Mare Synchronos Settings")
{
_configService = configService;
_mareCharaFileManager = mareCharaFileManager;
@@ -75,6 +79,8 @@ public class SettingsUi : WindowMediatorSubscriberBase
_fileTransferOrchestrator = fileTransferOrchestrator;
_fileCacheManager = fileCacheManager;
_apiController = apiController;
_ipcManager = ipcManager;
_cacheMonitor = cacheMonitor;
_fileCompactor = fileCompactor;
_uiShared = uiShared;
AllowClickthrough = false;
@@ -479,7 +485,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();
@@ -579,8 +635,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

@@ -40,7 +40,7 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
private readonly ApiController _apiController;
private readonly PeriodicFileScanner _cacheScanner;
private readonly CacheMonitor _cacheMonitor;
private readonly MareConfigService _configService;
@@ -74,13 +74,13 @@ 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, DalamudPluginInterface pluginInterface, Dalamud.Localization localization,
ServerConfigurationManager serverManager, MareMediator mediator) : base(logger, mediator)
{
_ipcManager = ipcManager;
_apiController = apiController;
_cacheScanner = cacheScanner;
_cacheMonitor = cacheMonitor;
FileDialogManager = fileDialogManager;
_configService = configService;
_dalamudUtil = dalamudUtil;
@@ -109,7 +109,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);
@@ -583,7 +583,8 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
{
_configService.Current.CacheFolder = path;
_configService.Save();
_cacheScanner.StartScan();
_cacheMonitor.StartMareWatcher(path);
_cacheMonitor.InvokeScan();
}
});
}
@@ -657,41 +658,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();
}
}
}
}
@@ -833,35 +838,12 @@ public partial class UiSharedService : DisposableMediatorSubscriberBase
return _serverSelectionIndex;
}
public void DrawTimeSpanBetweenScansSetting()
{
var timeSpan = _configService.Current.TimeSpanBetweenScansInSeconds;
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 Mare cache directories. Use this to move the Mare 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);