mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Make recapitalizing internal mod folders possible without changing behaviour otherwise.
This commit is contained in:
parent
7e7e74a534
commit
6df82fdf18
3 changed files with 227 additions and 220 deletions
|
|
@ -1,14 +1,13 @@
|
|||
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
|
||||
{
|
||||
public delegate void OnModFileSystemChange();
|
||||
|
||||
public static partial class ModFileSystem
|
||||
{
|
||||
// The root folder that should be used as the base for all structured mods.
|
||||
public static ModFolder Root = ModFolder.CreateRoot();
|
||||
|
||||
|
|
@ -119,11 +118,11 @@ namespace Penumbra.Mods
|
|||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Internal stuff.
|
||||
public static partial class ModFileSystem
|
||||
{
|
||||
// Internal stuff.
|
||||
public static partial class ModFileSystem
|
||||
{
|
||||
// Reset all sort orders for all descendants of the given folder.
|
||||
// Assumes that it is not called on Root, and thus does not remove unnecessary SortOrder entries.
|
||||
private static void SaveModChildren( ModFolder target )
|
||||
|
|
@ -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;
|
||||
|
|
@ -256,5 +258,4 @@ namespace Penumbra.Mods
|
|||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -300,16 +300,18 @@ public partial class SettingsInterface
|
|||
var targetUri = new Uri( newDir.FullName );
|
||||
if( sourceUri.Equals( targetUri ) )
|
||||
{
|
||||
var tmpFolder = new DirectoryInfo(TempFile.TempFileName( dir.Parent! ).FullName);
|
||||
var tmpFolder = new DirectoryInfo( TempFile.TempFileName( dir.Parent! ).FullName );
|
||||
if( _modManager.RenameModFolder( Mod.Data, tmpFolder ) )
|
||||
{
|
||||
if( !_modManager.RenameModFolder( Mod.Data, newDir ) )
|
||||
{
|
||||
PluginLog.Error("Could not recapitalize folder after renaming, reverting rename." );
|
||||
PluginLog.Error( "Could not recapitalize folder after renaming, reverting rename." );
|
||||
_modManager.RenameModFolder( Mod.Data, dir );
|
||||
}
|
||||
|
||||
_selector.ReloadCurrentMod();
|
||||
}
|
||||
|
||||
ImGui.CloseCurrentPopup();
|
||||
}
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue