Make recapitalizing internal mod folders possible without changing behaviour otherwise.

This commit is contained in:
Ottermandias 2022-02-24 14:02:45 +01:00
parent 7e7e74a534
commit 6df82fdf18
3 changed files with 227 additions and 220 deletions

View file

@ -1,10 +1,9 @@
using System;
using System.Linq;
using Penumbra.Mod;
using Penumbra.Util;
namespace Penumbra.Mods
{
namespace Penumbra.Mods;
public delegate void OnModFileSystemChange();
public static partial class ModFileSystem
@ -167,12 +166,15 @@ namespace Penumbra.Mods
return false;
}
ModFolder.FolderComparer.CompareType = StringComparison.InvariantCulture;
if( target.Parent!.FindSubFolder( newName, out var preExisting ) )
{
MergeNoSave( target, preExisting );
ModFolder.FolderComparer.CompareType = StringComparison.InvariantCultureIgnoreCase;
}
else
{
ModFolder.FolderComparer.CompareType = StringComparison.InvariantCultureIgnoreCase;
var parent = target.Parent;
parent.RemoveFolderIgnoreEmpty( target );
target.Name = newName;
@ -257,4 +259,3 @@ namespace Penumbra.Mods
return true;
}
}
}

View file

@ -148,15 +148,19 @@ namespace Penumbra.Mods
internal class ModFolderComparer : IComparer< ModFolder >
{
public StringComparison CompareType = StringComparison.InvariantCultureIgnoreCase;
// Compare only the direct folder names since this is only used inside an enumeration of subfolders of one folder.
public int Compare( ModFolder? x, ModFolder? y )
=> ReferenceEquals( x, y )
? 0
: string.Compare( x?.Name ?? string.Empty, y?.Name ?? string.Empty, StringComparison.InvariantCultureIgnoreCase );
: string.Compare( x?.Name ?? string.Empty, y?.Name ?? string.Empty, CompareType );
}
internal class ModDataComparer : IComparer< ModData >
{
public StringComparison CompareType = StringComparison.InvariantCultureIgnoreCase;
// Compare only the direct SortOrderNames since this is only used inside an enumeration of direct mod children of one folder.
// Since mod SortOrderNames do not have to be unique inside a folder, also compare their BasePaths (and thus their identity) if necessary.
public int Compare( ModData? x, ModData? y )
@ -166,7 +170,7 @@ namespace Penumbra.Mods
return 0;
}
var cmp = string.Compare( x?.SortOrder.SortOrderName, y?.SortOrder.SortOrderName, StringComparison.InvariantCultureIgnoreCase );
var cmp = string.Compare( x?.SortOrder.SortOrderName, y?.SortOrder.SortOrderName, CompareType );
if( cmp != 0 )
{
return cmp;
@ -176,8 +180,8 @@ namespace Penumbra.Mods
}
}
private static readonly ModFolderComparer FolderComparer = new();
private static readonly ModDataComparer ModComparer = new();
internal static readonly ModFolderComparer FolderComparer = new();
internal static readonly ModDataComparer ModComparer = new();
// Get an enumerator for actually sorted objects instead of folder-first objects.
private IEnumerable< object > GetSortedEnumerator()

View file

@ -308,8 +308,10 @@ public partial class SettingsInterface
PluginLog.Error( "Could not recapitalize folder after renaming, reverting rename." );
_modManager.RenameModFolder( Mod.Data, dir );
}
_selector.ReloadCurrentMod();
}
ImGui.CloseCurrentPopup();
}
else