mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 05:04:15 +01:00
Further tries to fix.
This commit is contained in:
parent
7b5e5f6815
commit
8064376d3d
2 changed files with 357 additions and 356 deletions
|
|
@ -7,21 +7,20 @@ using Penumbra.Interop;
|
|||
using Penumbra.Mod;
|
||||
using Penumbra.Util;
|
||||
|
||||
namespace Penumbra.Mods
|
||||
namespace Penumbra.Mods;
|
||||
|
||||
// Contains all collections and respective functions, as well as the collection settings.
|
||||
public class CollectionManager
|
||||
{
|
||||
// Contains all collections and respective functions, as well as the collection settings.
|
||||
public class CollectionManager
|
||||
{
|
||||
private readonly ModManager _manager;
|
||||
|
||||
public string CollectionChangedTo { get; private set; } = string.Empty;
|
||||
public Dictionary< string, ModCollection > Collections { get; } = new();
|
||||
|
||||
public ModCollection CurrentCollection { get; private set; } = null!;
|
||||
public ModCollection DefaultCollection { get; private set; } = null!;
|
||||
public ModCollection ForcedCollection { get; private set; } = ModCollection.Empty;
|
||||
public Dictionary< string, ModCollection > CharacterCollection { get; } = new();
|
||||
|
||||
public ModCollection CurrentCollection { get; private set; } = ModCollection.Empty;
|
||||
public ModCollection DefaultCollection { get; private set; } = ModCollection.Empty;
|
||||
public ModCollection ForcedCollection { get; private set; } = ModCollection.Empty;
|
||||
public ModCollection ActiveCollection { get; private set; }
|
||||
|
||||
public CollectionManager( ModManager manager )
|
||||
|
|
@ -56,20 +55,12 @@ namespace Penumbra.Mods
|
|||
|
||||
public void CreateNecessaryCaches()
|
||||
{
|
||||
if( !_manager.TempWritable )
|
||||
AddCache( DefaultCollection );
|
||||
AddCache( ForcedCollection );
|
||||
foreach( var (_, collection) in CharacterCollection )
|
||||
{
|
||||
PluginLog.Error( "No temporary directory available." );
|
||||
return;
|
||||
AddCache( collection );
|
||||
}
|
||||
|
||||
if( DefaultCollection.Name != ModCollection.Empty.Name && DefaultCollection.Cache == null )
|
||||
DefaultCollection.CreateCache( _manager.TempPath, _manager.StructuredMods.AllMods( _manager.Config.SortFoldersFirst ));
|
||||
|
||||
if( ForcedCollection.Name != ModCollection.Empty.Name && ForcedCollection.Cache == null )
|
||||
ForcedCollection.CreateCache( _manager.TempPath, _manager.StructuredMods.AllMods( _manager.Config.SortFoldersFirst ) );
|
||||
|
||||
foreach (var (_, collection) in CharacterCollection.Where( kvp => kvp.Value.Name != ModCollection.Empty.Name && kvp.Value.Cache == null ))
|
||||
collection.CreateCache( _manager.TempPath, _manager.StructuredMods.AllMods( _manager.Config.SortFoldersFirst ) );
|
||||
}
|
||||
|
||||
public void RecreateCaches()
|
||||
|
|
@ -148,8 +139,11 @@ namespace Penumbra.Mods
|
|||
return false;
|
||||
}
|
||||
|
||||
if( Collections.TryGetValue( name, out var collection ) )
|
||||
if( !Collections.TryGetValue( name, out var collection ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( CurrentCollection == collection )
|
||||
{
|
||||
SetCurrentCollection( Collections[ ModCollection.DefaultCollection ] );
|
||||
|
|
@ -165,20 +159,18 @@ namespace Penumbra.Mods
|
|||
SetDefaultCollection( ModCollection.Empty );
|
||||
}
|
||||
|
||||
foreach( var kvp in CharacterCollection.ToArray() )
|
||||
foreach( var (characterName, characterCollection) in CharacterCollection.ToArray() )
|
||||
{
|
||||
if( kvp.Value == collection )
|
||||
if( characterCollection == collection )
|
||||
{
|
||||
SetCharacterCollection( kvp.Key, ModCollection.Empty );
|
||||
SetCharacterCollection( characterName, ModCollection.Empty );
|
||||
}
|
||||
}
|
||||
|
||||
collection.Delete();
|
||||
Collections.Remove( name );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void AddCache( ModCollection collection )
|
||||
|
|
@ -296,6 +288,11 @@ namespace Penumbra.Mods
|
|||
|
||||
PluginLog.Error( $"Last choice of CurrentCollection {config.CurrentCollection} is not available, reset to Default." );
|
||||
CurrentCollection = Collections[ ModCollection.DefaultCollection ];
|
||||
if( CurrentCollection.Cache == null )
|
||||
{
|
||||
CurrentCollection.CreateCache( _manager.TempPath, _manager.StructuredMods.AllMods( _manager.Config.SortFoldersFirst ) );
|
||||
}
|
||||
|
||||
config.CurrentCollection = ModCollection.DefaultCollection;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -345,23 +342,23 @@ namespace Penumbra.Mods
|
|||
private bool LoadCharacterCollections( Configuration config )
|
||||
{
|
||||
var configChanged = false;
|
||||
foreach( var kvp in config.CharacterCollections.ToArray() )
|
||||
foreach( var (player, collectionName) in config.CharacterCollections.ToArray() )
|
||||
{
|
||||
Penumbra.PlayerWatcher.AddPlayerToWatch( kvp.Key );
|
||||
if( kvp.Value == string.Empty )
|
||||
Penumbra.PlayerWatcher.AddPlayerToWatch( player );
|
||||
if( collectionName == string.Empty )
|
||||
{
|
||||
CharacterCollection.Add( kvp.Key, ModCollection.Empty );
|
||||
CharacterCollection.Add( player, ModCollection.Empty );
|
||||
}
|
||||
else if( Collections.TryGetValue( kvp.Value, out var charCollection ) )
|
||||
else if( Collections.TryGetValue( collectionName, out var charCollection ) )
|
||||
{
|
||||
AddCache( charCollection );
|
||||
CharacterCollection.Add( kvp.Key, charCollection );
|
||||
CharacterCollection.Add( player, charCollection );
|
||||
}
|
||||
else
|
||||
{
|
||||
PluginLog.Error( $"Last choice of <{kvp.Key}>'s Collection {kvp.Value} is not available, reset to None." );
|
||||
CharacterCollection.Add( kvp.Key, ModCollection.Empty );
|
||||
config.CharacterCollections[ kvp.Key ] = string.Empty;
|
||||
PluginLog.Error( $"Last choice of <{player}>'s Collection {collectionName} is not available, reset to None." );
|
||||
CharacterCollection.Add( player, ModCollection.Empty );
|
||||
config.CharacterCollections[ player ] = string.Empty;
|
||||
configChanged = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -390,8 +387,11 @@ namespace Penumbra.Mods
|
|||
foreach( var file in collectionDir.EnumerateFiles( "*.json" ) )
|
||||
{
|
||||
var collection = ModCollection.LoadFromFile( file );
|
||||
if( collection != null )
|
||||
if( collection == null || collection.Name == string.Empty )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( file.Name != $"{collection.Name.RemoveInvalidPathSymbols()}.json" )
|
||||
{
|
||||
PluginLog.Warning( $"Collection {file.Name} does not correspond to {collection.Name}." );
|
||||
|
|
@ -407,7 +407,6 @@ namespace Penumbra.Mods
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !Collections.ContainsKey( ModCollection.DefaultCollection ) )
|
||||
{
|
||||
|
|
@ -416,5 +415,4 @@ namespace Penumbra.Mods
|
|||
Collections.Add( defaultCollection.Name, defaultCollection );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -130,7 +130,10 @@ namespace Penumbra.Mods
|
|||
}
|
||||
}
|
||||
|
||||
Collections?.RecreateCaches();
|
||||
if( !firstTime )
|
||||
{
|
||||
Collections.RecreateCaches();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue