diff --git a/Penumbra/Mods/Manager/ModDataEditor.cs b/Penumbra/Mods/Manager/ModDataEditor.cs index 7a0467d0..933620d9 100644 --- a/Penumbra/Mods/Manager/ModDataEditor.cs +++ b/Penumbra/Mods/Manager/ModDataEditor.cs @@ -249,6 +249,17 @@ public void ChangeModFavorite(Mod mod, bool state) communicatorService.ModDataChanged.Invoke(ModDataChangeType.Favorite, mod, null); } + public void ResetModImportDate(Mod mod) + { + var newDate = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); + if (mod.ImportDate == newDate) + return; + + mod.ImportDate = newDate; + saveService.QueueSave(new ModLocalData(mod)); + communicatorService.ModDataChanged.Invoke(ModDataChangeType.ImportDate, mod, null); + } + public void ChangeModNote(Mod mod, string newNote) { if (mod.Note == newNote) diff --git a/Penumbra/Mods/ModCreator.cs b/Penumbra/Mods/ModCreator.cs index 8cfdc9a7..fe027ca4 100644 --- a/Penumbra/Mods/ModCreator.cs +++ b/Penumbra/Mods/ModCreator.cs @@ -77,7 +77,7 @@ public bool ReloadMod(Mod mod, bool incorporateMetaChanges, bool deleteDefaultMe if (modDataChange.HasFlag(ModDataChangeType.Deletion) || mod.Name.Length == 0) return false; - dataEditor.LoadLocalData(mod); + modDataChange |= dataEditor.LoadLocalData(mod); LoadDefaultOption(mod); LoadAllGroups(mod); if (incorporateMetaChanges) diff --git a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs index 7a165feb..0781312c 100644 --- a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs +++ b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs @@ -447,16 +447,15 @@ private void OnSettingChange(ModCollection collection, ModSettingChange type, Mo private void OnModDataChange(ModDataChangeType type, Mod mod, string? oldName) { - switch (type) - { - case ModDataChangeType.Name: - case ModDataChangeType.Author: - case ModDataChangeType.ModTags: - case ModDataChangeType.LocalTags: - case ModDataChangeType.Favorite: - SetFilterDirty(); - break; - } + const ModDataChangeType relevantFlags = + ModDataChangeType.Name + | ModDataChangeType.Author + | ModDataChangeType.ModTags + | ModDataChangeType.LocalTags + | ModDataChangeType.Favorite + | ModDataChangeType.ImportDate; + if ((type & relevantFlags) != 0) + SetFilterDirty(); } private void OnInheritanceChange(ModCollection collection, bool _) diff --git a/Penumbra/UI/ModsTab/ModPanelEditTab.cs b/Penumbra/UI/ModsTab/ModPanelEditTab.cs index 90d8fb74..1ccee2cb 100644 --- a/Penumbra/UI/ModsTab/ModPanelEditTab.cs +++ b/Penumbra/UI/ModsTab/ModPanelEditTab.cs @@ -7,6 +7,7 @@ using OtterGui.Widgets; using OtterGui.Classes; using OtterGui.Services; +using OtterGui.Text; using Penumbra.Mods; using Penumbra.Mods.Editor; using Penumbra.Mods.Manager; @@ -50,6 +51,8 @@ public void DrawContent() EditButtons(); EditRegularMeta(); UiHelpers.DefaultLineSpace(); + EditLocalData(); + UiHelpers.DefaultLineSpace(); if (Input.Text("Mod Path", Input.Path, Input.None, _leaf.FullName(), out var newPath, 256, UiHelpers.InputTextWidth.X)) try @@ -182,6 +185,40 @@ private void EditRegularMeta() DrawOpenDefaultMod(); } + private void EditLocalData() + { + DrawImportDate(); + DrawOpenLocalData(); + } + + private void DrawImportDate() + { + ImUtf8.TextFramed($"{DateTimeOffset.FromUnixTimeMilliseconds(_mod.ImportDate).ToLocalTime():yyyy/MM/dd HH:mm}", + ImGui.GetColorU32(ImGuiCol.FrameBg, 0.5f), new Vector2(UiHelpers.InputTextMinusButton3, 0)); + ImGui.SameLine(0, 3 * ImUtf8.GlobalScale); + + var canRefresh = config.DeleteModModifier.IsActive(); + var tt = canRefresh + ? "Reset the import date to the current date and time." + : $"Reset the import date to the current date and time.\nHold {config.DeleteModModifier} while clicking to refresh."; + + if (ImUtf8.IconButton(FontAwesomeIcon.Sync, tt, disabled: !canRefresh)) + modManager.DataEditor.ResetModImportDate(_mod); + ImUtf8.SameLineInner(); + ImUtf8.Text("Import Date"u8); + } + + private void DrawOpenLocalData() + { + var file = filenames.LocalDataFile(_mod); + var fileExists = File.Exists(file); + var tt = fileExists + ? "Open the local mod data file in the text editor of your choice."u8 + : "The local mod data file does not exist."u8; + if (ImUtf8.ButtonEx("Open Local Data"u8, tt, UiHelpers.InputTextWidth, !fileExists)) + Process.Start(new ProcessStartInfo(file) { UseShellExecute = true }); + } + private void DrawOpenDefaultMod() { var file = filenames.OptionGroupFile(_mod, -1, false);