mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-01-02 05:43:42 +01:00
tmp
This commit is contained in:
parent
a806dd28c3
commit
d906e5aedf
13 changed files with 279 additions and 102 deletions
12
Penumbra/Mods/Mod2.Manager.FileSystem.cs
Normal file
12
Penumbra/Mods/Mod2.Manager.FileSystem.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System.IO;
|
||||
|
||||
namespace Penumbra.Mods;
|
||||
|
||||
public sealed partial class Mod2
|
||||
{
|
||||
public sealed partial class Manager
|
||||
{
|
||||
public static string ModFileSystemFile
|
||||
=> Path.Combine( Dalamud.PluginInterface.GetPluginConfigDirectory(), "sort_order.json" );
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Penumbra.Mods;
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ public static partial class ModFileSystem
|
|||
{
|
||||
foreach( var mod in target.AllMods( true ) )
|
||||
{
|
||||
Penumbra.Config.ModSortOrder[ mod.BasePath.Name ] = mod.Order.FullName;
|
||||
Penumbra.ModManager.TemporaryModSortOrder[ mod.BasePath.Name ] = mod.Order.FullName;
|
||||
}
|
||||
|
||||
Penumbra.Config.Save();
|
||||
|
|
@ -136,16 +136,16 @@ public static partial class ModFileSystem
|
|||
}
|
||||
|
||||
// Sets and saves the sort order of a single mod, removing the entry if it is unnecessary.
|
||||
private static void SaveMod( global::Penumbra.Mods.Mod mod )
|
||||
private static void SaveMod( Mod mod )
|
||||
{
|
||||
if( ReferenceEquals( mod.Order.ParentFolder, Root )
|
||||
&& string.Equals( mod.Order.SortOrderName, mod.Meta.Name.Text.Replace( '/', '\\' ), StringComparison.InvariantCultureIgnoreCase ) )
|
||||
{
|
||||
Penumbra.Config.ModSortOrder.Remove( mod.BasePath.Name );
|
||||
Penumbra.ModManager.TemporaryModSortOrder.Remove( mod.BasePath.Name );
|
||||
}
|
||||
else
|
||||
{
|
||||
Penumbra.Config.ModSortOrder[ mod.BasePath.Name ] = mod.Order.FullName;
|
||||
Penumbra.ModManager.TemporaryModSortOrder[ mod.BasePath.Name ] = mod.Order.FullName;
|
||||
}
|
||||
|
||||
Penumbra.Config.Save();
|
||||
|
|
@ -183,7 +183,7 @@ public static partial class ModFileSystem
|
|||
return true;
|
||||
}
|
||||
|
||||
private static bool RenameNoSave( global::Penumbra.Mods.Mod mod, string newName )
|
||||
private static bool RenameNoSave( Mod mod, string newName )
|
||||
{
|
||||
newName = newName.Replace( '/', '\\' );
|
||||
if( mod.Order.SortOrderName == newName )
|
||||
|
|
@ -192,12 +192,12 @@ public static partial class ModFileSystem
|
|||
}
|
||||
|
||||
mod.Order.ParentFolder.RemoveModIgnoreEmpty( mod );
|
||||
mod.Order = new global::Penumbra.Mods.Mod.SortOrder( mod.Order.ParentFolder, newName );
|
||||
mod.Order = new Mod.SortOrder( mod.Order.ParentFolder, newName );
|
||||
mod.Order.ParentFolder.AddMod( mod );
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool MoveNoSave( global::Penumbra.Mods.Mod mod, ModFolder target )
|
||||
private static bool MoveNoSave( Mod mod, ModFolder target )
|
||||
{
|
||||
var oldParent = mod.Order.ParentFolder;
|
||||
if( ReferenceEquals( target, oldParent ) )
|
||||
|
|
@ -206,7 +206,7 @@ public static partial class ModFileSystem
|
|||
}
|
||||
|
||||
oldParent.RemoveMod( mod );
|
||||
mod.Order = new global::Penumbra.Mods.Mod.SortOrder( target, mod.Order.SortOrderName );
|
||||
mod.Order = new Mod.SortOrder( target, mod.Order.SortOrderName );
|
||||
target.AddMod( mod );
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using Dalamud.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Penumbra.GameData.ByteString;
|
||||
using Penumbra.Meta;
|
||||
using Penumbra.Mods;
|
||||
|
|
@ -103,21 +104,35 @@ public partial class Mod
|
|||
public Manager()
|
||||
{
|
||||
SetBaseDirectory( Config.ModDirectory, true );
|
||||
// TODO
|
||||
try
|
||||
{
|
||||
var data = JObject.Parse( File.ReadAllText( Path.Combine( Dalamud.PluginInterface.GetPluginConfigDirectory(),
|
||||
"sort_order.json" ) ) );
|
||||
TemporaryModSortOrder = data["Data"]?.ToObject<Dictionary<string, string>>() ?? new Dictionary<string, string>();
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
TemporaryModSortOrder = new Dictionary<string, string>();
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<string, string> TemporaryModSortOrder;
|
||||
|
||||
private bool SetSortOrderPath( Mod mod, string path )
|
||||
{
|
||||
mod.Move( path );
|
||||
var fixedPath = mod.Order.FullPath;
|
||||
if( fixedPath.Length == 0 || string.Equals( fixedPath, mod.Meta.Name, StringComparison.InvariantCultureIgnoreCase ) )
|
||||
{
|
||||
Config.ModSortOrder.Remove( mod.BasePath.Name );
|
||||
Penumbra.ModManager.TemporaryModSortOrder.Remove( mod.BasePath.Name );
|
||||
return true;
|
||||
}
|
||||
|
||||
if( path != fixedPath )
|
||||
{
|
||||
Config.ModSortOrder[ mod.BasePath.Name ] = fixedPath;
|
||||
TemporaryModSortOrder[ mod.BasePath.Name ] = fixedPath;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +143,7 @@ public partial class Mod
|
|||
{
|
||||
var changes = false;
|
||||
|
||||
foreach( var (folder, path) in Config.ModSortOrder.ToArray() )
|
||||
foreach( var (folder, path) in TemporaryModSortOrder.ToArray() )
|
||||
{
|
||||
if( path.Length > 0 && _mods.FindFirst( m => m.BasePath.Name == folder, out var mod ) )
|
||||
{
|
||||
|
|
@ -137,7 +152,7 @@ public partial class Mod
|
|||
else if( removeOldPaths )
|
||||
{
|
||||
changes = true;
|
||||
Config.ModSortOrder.Remove( folder );
|
||||
TemporaryModSortOrder.Remove( folder );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -212,7 +227,7 @@ public partial class Mod
|
|||
return -1;
|
||||
}
|
||||
|
||||
if( Config.ModSortOrder.TryGetValue( mod.BasePath.Name, out var sortOrder ) )
|
||||
if( TemporaryModSortOrder.TryGetValue( mod.BasePath.Name, out var sortOrder ) )
|
||||
{
|
||||
if( SetSortOrderPath( mod, sortOrder ) )
|
||||
{
|
||||
|
|
@ -246,13 +261,13 @@ public partial class Mod
|
|||
if( metaChanges || fileChanges.HasFlag( ResourceChange.Files ) )
|
||||
{
|
||||
mod.ComputeChangedItems();
|
||||
if( Config.ModSortOrder.TryGetValue( mod.BasePath.Name, out var sortOrder ) )
|
||||
if( TemporaryModSortOrder.TryGetValue( mod.BasePath.Name, out var sortOrder ) )
|
||||
{
|
||||
mod.Move( sortOrder );
|
||||
var path = mod.Order.FullPath;
|
||||
if( path != sortOrder )
|
||||
{
|
||||
Config.ModSortOrder[ mod.BasePath.Name ] = path;
|
||||
TemporaryModSortOrder[ mod.BasePath.Name ] = path;
|
||||
Config.Save();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,12 +35,12 @@ public static class ModManagerEditExtensions
|
|||
if( newSortOrder == string.Empty || newSortOrder == inRoot.SortOrderName )
|
||||
{
|
||||
mod.Order = inRoot;
|
||||
manager.Config.ModSortOrder.Remove( mod.BasePath.Name );
|
||||
manager.TemporaryModSortOrder.Remove( mod.BasePath.Name );
|
||||
}
|
||||
else
|
||||
{
|
||||
mod.Move( newSortOrder );
|
||||
manager.Config.ModSortOrder[ mod.BasePath.Name ] = mod.Order.FullPath;
|
||||
manager.TemporaryModSortOrder[ mod.BasePath.Name ] = mod.Order.FullPath;
|
||||
}
|
||||
|
||||
manager.Config.Save();
|
||||
|
|
@ -75,10 +75,10 @@ public static class ModManagerEditExtensions
|
|||
mod.MetaFile = Mod.MetaFileInfo( newDir );
|
||||
manager.UpdateMod( mod );
|
||||
|
||||
if( manager.Config.ModSortOrder.ContainsKey( oldBasePath.Name ) )
|
||||
if( manager.TemporaryModSortOrder.ContainsKey( oldBasePath.Name ) )
|
||||
{
|
||||
manager.Config.ModSortOrder[ newDir.Name ] = manager.Config.ModSortOrder[ oldBasePath.Name ];
|
||||
manager.Config.ModSortOrder.Remove( oldBasePath.Name );
|
||||
manager.TemporaryModSortOrder[ newDir.Name ] = manager.TemporaryModSortOrder[ oldBasePath.Name ];
|
||||
manager.TemporaryModSortOrder.Remove( oldBasePath.Name );
|
||||
manager.Config.Save();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue