mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-14 12:44:19 +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;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Penumbra.Mod;
|
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.
|
// The root folder that should be used as the base for all structured mods.
|
||||||
public static ModFolder Root = ModFolder.CreateRoot();
|
public static ModFolder Root = ModFolder.CreateRoot();
|
||||||
|
|
||||||
|
|
@ -119,11 +118,11 @@ namespace Penumbra.Mods
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal stuff.
|
// Internal stuff.
|
||||||
public static partial class ModFileSystem
|
public static partial class ModFileSystem
|
||||||
{
|
{
|
||||||
// Reset all sort orders for all descendants of the given folder.
|
// 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.
|
// Assumes that it is not called on Root, and thus does not remove unnecessary SortOrder entries.
|
||||||
private static void SaveModChildren( ModFolder target )
|
private static void SaveModChildren( ModFolder target )
|
||||||
|
|
@ -167,12 +166,15 @@ namespace Penumbra.Mods
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModFolder.FolderComparer.CompareType = StringComparison.InvariantCulture;
|
||||||
if( target.Parent!.FindSubFolder( newName, out var preExisting ) )
|
if( target.Parent!.FindSubFolder( newName, out var preExisting ) )
|
||||||
{
|
{
|
||||||
MergeNoSave( target, preExisting );
|
MergeNoSave( target, preExisting );
|
||||||
|
ModFolder.FolderComparer.CompareType = StringComparison.InvariantCultureIgnoreCase;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ModFolder.FolderComparer.CompareType = StringComparison.InvariantCultureIgnoreCase;
|
||||||
var parent = target.Parent;
|
var parent = target.Parent;
|
||||||
parent.RemoveFolderIgnoreEmpty( target );
|
parent.RemoveFolderIgnoreEmpty( target );
|
||||||
target.Name = newName;
|
target.Name = newName;
|
||||||
|
|
@ -256,5 +258,4 @@ namespace Penumbra.Mods
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -148,15 +148,19 @@ namespace Penumbra.Mods
|
||||||
|
|
||||||
internal class ModFolderComparer : IComparer< ModFolder >
|
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.
|
// 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 )
|
public int Compare( ModFolder? x, ModFolder? y )
|
||||||
=> ReferenceEquals( x, y )
|
=> ReferenceEquals( x, y )
|
||||||
? 0
|
? 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 >
|
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.
|
// 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.
|
// 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 )
|
public int Compare( ModData? x, ModData? y )
|
||||||
|
|
@ -166,7 +170,7 @@ namespace Penumbra.Mods
|
||||||
return 0;
|
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 )
|
if( cmp != 0 )
|
||||||
{
|
{
|
||||||
return cmp;
|
return cmp;
|
||||||
|
|
@ -176,8 +180,8 @@ namespace Penumbra.Mods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly ModFolderComparer FolderComparer = new();
|
internal static readonly ModFolderComparer FolderComparer = new();
|
||||||
private static readonly ModDataComparer ModComparer = new();
|
internal static readonly ModDataComparer ModComparer = new();
|
||||||
|
|
||||||
// Get an enumerator for actually sorted objects instead of folder-first objects.
|
// Get an enumerator for actually sorted objects instead of folder-first objects.
|
||||||
private IEnumerable< object > GetSortedEnumerator()
|
private IEnumerable< object > GetSortedEnumerator()
|
||||||
|
|
|
||||||
|
|
@ -300,16 +300,18 @@ public partial class SettingsInterface
|
||||||
var targetUri = new Uri( newDir.FullName );
|
var targetUri = new Uri( newDir.FullName );
|
||||||
if( sourceUri.Equals( targetUri ) )
|
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, tmpFolder ) )
|
||||||
{
|
{
|
||||||
if( !_modManager.RenameModFolder( Mod.Data, newDir ) )
|
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 );
|
_modManager.RenameModFolder( Mod.Data, dir );
|
||||||
}
|
}
|
||||||
|
|
||||||
_selector.ReloadCurrentMod();
|
_selector.ReloadCurrentMod();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.CloseCurrentPopup();
|
ImGui.CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue