Add some migration things.

This commit is contained in:
Ottermandias 2024-07-08 14:55:49 +02:00
parent 0d939b12f4
commit 56e284a99e
17 changed files with 515 additions and 80 deletions

View file

@ -3,6 +3,7 @@ using Dalamud.Interface.Utility;
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using OtterGui.Text;
using OtterGui.Widgets;
using Penumbra.GameData.Files;
using Penumbra.String.Classes;
@ -16,6 +17,7 @@ public partial class ModEditWindow
private bool DrawMaterialPanel(MtrlTab tab, bool disabled)
{
DrawVersionUpdate(tab, disabled);
DrawMaterialLivePreviewRebind(tab, disabled);
ImGui.Dummy(new Vector2(ImGui.GetTextLineHeight() / 2));
@ -34,6 +36,20 @@ public partial class ModEditWindow
return !disabled && ret;
}
private void DrawVersionUpdate(MtrlTab tab, bool disabled)
{
if (disabled || tab.Mtrl.IsDawnTrail)
return;
if (!ImUtf8.ButtonEx("Update MTRL Version to Dawntrail"u8,
"Try using this if the material can not be loaded or should use legacy shaders.\n\nThis is not revertible."u8,
new Vector2(-0.1f, 0), false, 0, Colors.PressEnterWarningBg))
return;
tab.Mtrl.MigrateToDawntrail();
_materialTab.SaveFile();
}
private static void DrawMaterialLivePreviewRebind(MtrlTab tab, bool disabled)
{
if (disabled)

View file

@ -37,6 +37,8 @@ public partial class ModEditWindow : Window, IDisposable, IUiService
{
private const string WindowBaseLabel = "###SubModEdit";
public readonly MigrationManager MigrationManager;
private readonly PerformanceTracker _performance;
private readonly ModEditor _editor;
private readonly Configuration _config;
@ -588,7 +590,7 @@ public partial class ModEditWindow : Window, IDisposable, IUiService
StainService stainService, ActiveCollections activeCollections, ModMergeTab modMergeTab,
CommunicatorService communicator, TextureManager textures, ModelManager models, IDragDropManager dragDropManager,
ResourceTreeViewerFactory resourceTreeViewerFactory, ObjectManager objects, IFramework framework,
CharacterBaseDestructor characterBaseDestructor, MetaDrawers metaDrawers)
CharacterBaseDestructor characterBaseDestructor, MetaDrawers metaDrawers, MigrationManager migrationManager)
: base(WindowBaseLabel)
{
_performance = performance;
@ -608,6 +610,7 @@ public partial class ModEditWindow : Window, IDisposable, IUiService
_objects = objects;
_framework = framework;
_characterBaseDestructor = characterBaseDestructor;
MigrationManager = migrationManager;
_metaDrawers = metaDrawers;
_materialTab = new FileEditor<MtrlTab>(this, _communicator, gameData, config, _editor.Compactor, _fileDialog, "Materials", ".mtrl",
() => PopulateIsOnPlayer(_editor.Files.Mtrl, ResourceType.Mtrl), DrawMaterialPanel, () => Mod?.ModPath.FullName ?? string.Empty,

View file

@ -37,9 +37,9 @@ public class CollectionSelectHeader : IUiService
var buttonSize = new Vector2(comboWidth * 3f / 4f, 0f);
using (var _ = ImRaii.Group())
{
DrawCollectionButton(buttonSize, GetDefaultCollectionInfo(), 1);
DrawCollectionButton(buttonSize, GetDefaultCollectionInfo(), 1);
DrawCollectionButton(buttonSize, GetInterfaceCollectionInfo(), 2);
DrawCollectionButton(buttonSize, GetPlayerCollectionInfo(), 3);
DrawCollectionButton(buttonSize, GetPlayerCollectionInfo(), 3);
DrawCollectionButton(buttonSize, GetInheritedCollectionInfo(), 4);
_collectionCombo.Draw("##collectionSelector", comboWidth, ColorId.SelectedCollection.Value());

View file

@ -0,0 +1,121 @@
using ImGuiNET;
using OtterGui.Services;
using OtterGui.Text;
using Penumbra.Services;
namespace Penumbra.UI.Classes;
public class MigrationSectionDrawer(MigrationManager migrationManager, Configuration config) : IUiService
{
private bool _createBackups = true;
private Vector2 _buttonSize;
public void Draw()
{
using var header = ImUtf8.CollapsingHeaderId("Migration"u8);
if (!header)
return;
_buttonSize = UiHelpers.InputTextWidth;
DrawSettings();
ImGui.Separator();
DrawMigration();
ImGui.Separator();
DrawCleanup();
ImGui.Separator();
DrawRestore();
}
private void DrawSettings()
{
var value = config.MigrateImportedModelsToV6;
if (ImUtf8.Checkbox("Automatically Migrate V5 Models to V6 on Import"u8, ref value))
{
config.MigrateImportedModelsToV6 = value;
config.Save();
}
}
private void DrawMigration()
{
ImUtf8.Checkbox("Create Backups During Manual Migration", ref _createBackups);
if (ImUtf8.ButtonEx("Migrate Model Files From V5 to V6"u8, "\0"u8, _buttonSize, migrationManager.IsRunning))
migrationManager.MigrateDirectory(config.ModDirectory, _createBackups);
ImUtf8.SameLineInner();
DrawCancelButton(0, "Cancel the migration. This does not revert already finished migrations."u8);
DrawSpinner(migrationManager is { IsMigrationTask: true, IsRunning: true });
if (!migrationManager.HasMigrationTask)
{
ImUtf8.IconDummy();
return;
}
var total = migrationManager.Failed + migrationManager.Migrated + migrationManager.Unchanged;
if (total == 0)
ImUtf8.TextFrameAligned("No model files found."u8);
else
ImUtf8.TextFrameAligned($"{migrationManager.Migrated} files migrated, {migrationManager.Failed} files failed, {total} total files.");
}
private void DrawCleanup()
{
if (ImUtf8.ButtonEx("Delete Existing Model Backup Files"u8, "\0"u8, _buttonSize, migrationManager.IsRunning))
migrationManager.CleanBackups(config.ModDirectory);
ImUtf8.SameLineInner();
DrawCancelButton(1, "Cancel the cleanup. This is not revertible."u8);
DrawSpinner(migrationManager is { IsCleanupTask: true, IsRunning: true });
if (!migrationManager.HasCleanUpTask)
{
ImUtf8.IconDummy();
return;
}
var total = migrationManager.CleanedUp + migrationManager.CleanupFails;
if (total == 0)
ImUtf8.TextFrameAligned("No model backup files found."u8);
else
ImUtf8.TextFrameAligned(
$"{migrationManager.CleanedUp} backups deleted, {migrationManager.CleanupFails} deletions failed, {total} total backups.");
}
private void DrawSpinner(bool enabled)
{
if (!enabled)
return;
ImGui.SameLine();
ImUtf8.Spinner("Spinner"u8, ImGui.GetTextLineHeight() / 2, 2, ImGui.GetColorU32(ImGuiCol.Text));
}
private void DrawRestore()
{
if (ImUtf8.ButtonEx("Restore Model Backups"u8, "\0"u8, _buttonSize, migrationManager.IsRunning))
migrationManager.RestoreBackups(config.ModDirectory);
ImUtf8.SameLineInner();
DrawCancelButton(2, "Cancel the restoration. This does not revert already finished restoration."u8);
DrawSpinner(migrationManager is { IsRestorationTask: true, IsRunning: true });
if (!migrationManager.HasRestoreTask)
{
ImUtf8.IconDummy();
return;
}
var total = migrationManager.Restored + migrationManager.RestoreFails;
if (total == 0)
ImUtf8.TextFrameAligned("No model backup files found."u8);
else
ImUtf8.TextFrameAligned(
$"{migrationManager.Restored} backups restored, {migrationManager.RestoreFails} restorations failed, {total} total backups.");
}
private void DrawCancelButton(int id, ReadOnlySpan<byte> tooltip)
{
using var _ = ImUtf8.PushId(id);
if (ImUtf8.ButtonEx("Cancel"u8, tooltip, disabled: !migrationManager.IsRunning))
migrationManager.Cancel();
}
}

View file

@ -41,10 +41,11 @@ public class SettingsTab : ITab, IUiService
private readonly DalamudSubstitutionProvider _dalamudSubstitutionProvider;
private readonly FileCompactor _compactor;
private readonly DalamudConfigService _dalamudConfig;
private readonly IDalamudPluginInterface _pluginInterface;
private readonly IDalamudPluginInterface _pluginInterface;
private readonly IDataManager _gameData;
private readonly PredefinedTagManager _predefinedTagManager;
private readonly CrashHandlerService _crashService;
private readonly MigrationSectionDrawer _migrationDrawer;
private int _minimumX = int.MaxValue;
private int _minimumY = int.MaxValue;
@ -55,7 +56,8 @@ public class SettingsTab : ITab, IUiService
Penumbra penumbra, FileDialogService fileDialog, ModManager modManager, ModFileSystemSelector selector,
CharacterUtility characterUtility, ResidentResourceManager residentResources, ModExportManager modExportManager, HttpApi httpApi,
DalamudSubstitutionProvider dalamudSubstitutionProvider, FileCompactor compactor, DalamudConfigService dalamudConfig,
IDataManager gameData, PredefinedTagManager predefinedTagConfig, CrashHandlerService crashService)
IDataManager gameData, PredefinedTagManager predefinedTagConfig, CrashHandlerService crashService,
MigrationSectionDrawer migrationDrawer)
{
_pluginInterface = pluginInterface;
_config = config;
@ -77,6 +79,7 @@ public class SettingsTab : ITab, IUiService
_compactor.Enabled = _config.UseFileSystemCompression;
_predefinedTagManager = predefinedTagConfig;
_crashService = crashService;
_migrationDrawer = migrationDrawer;
}
public void DrawHeader()
@ -102,6 +105,7 @@ public class SettingsTab : ITab, IUiService
ImGui.NewLine();
DrawGeneralSettings();
_migrationDrawer.Draw();
DrawColorSettings();
DrawPredefinedTagsSection();
DrawAdvancedSettings();