Further tries to fix.

This commit is contained in:
Ottermandias 2021-12-13 21:26:59 +01:00
parent 7b5e5f6815
commit 8064376d3d
2 changed files with 357 additions and 356 deletions

View file

@ -7,8 +7,8 @@ using Penumbra.Interop;
using Penumbra.Mod; using Penumbra.Mod;
using Penumbra.Util; using Penumbra.Util;
namespace Penumbra.Mods namespace Penumbra.Mods;
{
// Contains all collections and respective functions, as well as the collection settings. // Contains all collections and respective functions, as well as the collection settings.
public class CollectionManager public class CollectionManager
{ {
@ -16,12 +16,11 @@ namespace Penumbra.Mods
public string CollectionChangedTo { get; private set; } = string.Empty; public string CollectionChangedTo { get; private set; } = string.Empty;
public Dictionary< string, ModCollection > Collections { get; } = new(); 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 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 ModCollection ActiveCollection { get; private set; }
public CollectionManager( ModManager manager ) public CollectionManager( ModManager manager )
@ -56,20 +55,12 @@ namespace Penumbra.Mods
public void CreateNecessaryCaches() public void CreateNecessaryCaches()
{ {
if( !_manager.TempWritable ) AddCache( DefaultCollection );
AddCache( ForcedCollection );
foreach( var (_, collection) in CharacterCollection )
{ {
PluginLog.Error( "No temporary directory available." ); AddCache( collection );
return;
} }
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() public void RecreateCaches()
@ -148,8 +139,11 @@ namespace Penumbra.Mods
return false; return false;
} }
if( Collections.TryGetValue( name, out var collection ) ) if( !Collections.TryGetValue( name, out var collection ) )
{ {
return false;
}
if( CurrentCollection == collection ) if( CurrentCollection == collection )
{ {
SetCurrentCollection( Collections[ ModCollection.DefaultCollection ] ); SetCurrentCollection( Collections[ ModCollection.DefaultCollection ] );
@ -165,20 +159,18 @@ namespace Penumbra.Mods
SetDefaultCollection( ModCollection.Empty ); 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(); collection.Delete();
Collections.Remove( name ); Collections.Remove( name );
return true; return true;
}
return false;
} }
private void AddCache( ModCollection collection ) 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." ); PluginLog.Error( $"Last choice of CurrentCollection {config.CurrentCollection} is not available, reset to Default." );
CurrentCollection = Collections[ ModCollection.DefaultCollection ]; CurrentCollection = Collections[ ModCollection.DefaultCollection ];
if( CurrentCollection.Cache == null )
{
CurrentCollection.CreateCache( _manager.TempPath, _manager.StructuredMods.AllMods( _manager.Config.SortFoldersFirst ) );
}
config.CurrentCollection = ModCollection.DefaultCollection; config.CurrentCollection = ModCollection.DefaultCollection;
return true; return true;
} }
@ -345,23 +342,23 @@ namespace Penumbra.Mods
private bool LoadCharacterCollections( Configuration config ) private bool LoadCharacterCollections( Configuration config )
{ {
var configChanged = false; var configChanged = false;
foreach( var kvp in config.CharacterCollections.ToArray() ) foreach( var (player, collectionName) in config.CharacterCollections.ToArray() )
{ {
Penumbra.PlayerWatcher.AddPlayerToWatch( kvp.Key ); Penumbra.PlayerWatcher.AddPlayerToWatch( player );
if( kvp.Value == string.Empty ) 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 ); AddCache( charCollection );
CharacterCollection.Add( kvp.Key, charCollection ); CharacterCollection.Add( player, charCollection );
} }
else else
{ {
PluginLog.Error( $"Last choice of <{kvp.Key}>'s Collection {kvp.Value} is not available, reset to None." ); PluginLog.Error( $"Last choice of <{player}>'s Collection {collectionName} is not available, reset to None." );
CharacterCollection.Add( kvp.Key, ModCollection.Empty ); CharacterCollection.Add( player, ModCollection.Empty );
config.CharacterCollections[ kvp.Key ] = string.Empty; config.CharacterCollections[ player ] = string.Empty;
configChanged = true; configChanged = true;
} }
} }
@ -390,8 +387,11 @@ namespace Penumbra.Mods
foreach( var file in collectionDir.EnumerateFiles( "*.json" ) ) foreach( var file in collectionDir.EnumerateFiles( "*.json" ) )
{ {
var collection = ModCollection.LoadFromFile( file ); var collection = ModCollection.LoadFromFile( file );
if( collection != null ) if( collection == null || collection.Name == string.Empty )
{ {
continue;
}
if( file.Name != $"{collection.Name.RemoveInvalidPathSymbols()}.json" ) if( file.Name != $"{collection.Name.RemoveInvalidPathSymbols()}.json" )
{ {
PluginLog.Warning( $"Collection {file.Name} does not correspond to {collection.Name}." ); PluginLog.Warning( $"Collection {file.Name} does not correspond to {collection.Name}." );
@ -407,7 +407,6 @@ namespace Penumbra.Mods
} }
} }
} }
}
if( !Collections.ContainsKey( ModCollection.DefaultCollection ) ) if( !Collections.ContainsKey( ModCollection.DefaultCollection ) )
{ {
@ -417,4 +416,3 @@ namespace Penumbra.Mods
} }
} }
} }
}

View file

@ -130,7 +130,10 @@ namespace Penumbra.Mods
} }
} }
Collections?.RecreateCaches(); if( !firstTime )
{
Collections.RecreateCaches();
}
} }
} }