mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
tmp
This commit is contained in:
parent
4a4d93baf3
commit
0eff4e2e67
3 changed files with 44 additions and 19 deletions
|
|
@ -21,7 +21,7 @@ public delegate void CollectionChangeDelegate( ModCollection? oldCollection, Mod
|
|||
string? characterName = null );
|
||||
|
||||
// Contains all collections and respective functions, as well as the collection settings.
|
||||
public class CollectionManager
|
||||
public class CollectionManager : IDisposable
|
||||
{
|
||||
private readonly ModManager _manager;
|
||||
|
||||
|
|
@ -42,10 +42,43 @@ public class CollectionManager
|
|||
{
|
||||
_manager = manager;
|
||||
|
||||
_manager.ModsRediscovered += OnModsRediscovered;
|
||||
ReadCollections();
|
||||
LoadConfigCollections( Penumbra.Config );
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_manager.ModsRediscovered -= OnModsRediscovered;
|
||||
}
|
||||
|
||||
private void OnModsRediscovered()
|
||||
{
|
||||
RecreateCaches();
|
||||
DefaultCollection.SetFiles();
|
||||
}
|
||||
|
||||
private void OnModChanged( ModChangeType type, int idx, ModData mod )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case ModChangeType.Added:
|
||||
foreach( var collection in Collections.Values )
|
||||
{
|
||||
collection.AddMod( mod );
|
||||
}
|
||||
|
||||
break;
|
||||
case ModChangeType.Removed:
|
||||
RemoveModFromCaches( mod.BasePath );
|
||||
break;
|
||||
case ModChangeType.Changed:
|
||||
// TODO
|
||||
break;
|
||||
default: throw new ArgumentOutOfRangeException( nameof( type ), type, null );
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateNecessaryCaches()
|
||||
{
|
||||
AddCache( DefaultCollection );
|
||||
|
|
|
|||
|
|
@ -32,9 +32,8 @@ public class ModManager
|
|||
|
||||
public ModFolder StructuredMods { get; } = ModFileSystem.Root;
|
||||
|
||||
public CollectionManager Collections { get; }
|
||||
|
||||
public event ModChangeDelegate? ModChange;
|
||||
public event Action? ModsRediscovered;
|
||||
|
||||
public bool Valid { get; private set; }
|
||||
|
||||
|
|
@ -82,18 +81,14 @@ public class ModManager
|
|||
Config.ModDirectory = BasePath.FullName;
|
||||
Config.Save();
|
||||
}
|
||||
|
||||
if( !firstTime )
|
||||
{
|
||||
Collections.RecreateCaches();
|
||||
}
|
||||
}
|
||||
|
||||
ModsRediscovered?.Invoke();
|
||||
}
|
||||
|
||||
public ModManager()
|
||||
{
|
||||
SetBaseDirectory( Config.ModDirectory, true );
|
||||
Collections = new CollectionManager( this );
|
||||
}
|
||||
|
||||
private bool SetSortOrderPath( ModData mod, string path )
|
||||
|
|
@ -161,8 +156,7 @@ public class ModManager
|
|||
SetModStructure();
|
||||
}
|
||||
|
||||
Collections.RecreateCaches();
|
||||
Collections.DefaultCollection.SetFiles();
|
||||
ModsRediscovered?.Invoke();
|
||||
}
|
||||
|
||||
public void DeleteMod( DirectoryInfo modFolder )
|
||||
|
|
@ -185,7 +179,6 @@ public class ModManager
|
|||
var mod = ModsInternal[ idx ];
|
||||
mod.SortOrder.ParentFolder.RemoveMod( mod );
|
||||
ModsInternal.RemoveAt( idx );
|
||||
Collections.RemoveModFromCaches( modFolder );
|
||||
ModChange?.Invoke( ModChangeType.Removed, idx, mod );
|
||||
}
|
||||
}
|
||||
|
|
@ -213,10 +206,6 @@ public class ModManager
|
|||
|
||||
ModsInternal.Add( mod );
|
||||
ModChange?.Invoke( ModChangeType.Added, ModsInternal.Count - 1, mod );
|
||||
foreach( var collection in Collections.Collections.Values )
|
||||
{
|
||||
collection.AddMod( mod );
|
||||
}
|
||||
|
||||
return ModsInternal.Count - 1;
|
||||
}
|
||||
|
|
@ -261,7 +250,7 @@ public class ModManager
|
|||
mod.Resources.MetaManipulations.SaveToFile( MetaCollection.FileName( mod.BasePath ) );
|
||||
}
|
||||
|
||||
Collections.UpdateCollections( mod, metaChanges, fileChanges, nameChange, reloadMeta );
|
||||
Penumbra.CollectionManager.UpdateCollections( mod, metaChanges, fileChanges, nameChange, reloadMeta ); // TODO
|
||||
ModChange?.Invoke( ModChangeType.Changed, idx, mod );
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ public class Penumbra : IDalamudPlugin
|
|||
public static CharacterUtility CharacterUtility { get; private set; } = null!;
|
||||
|
||||
public static ModManager ModManager { get; private set; } = null!;
|
||||
public static CollectionManager CollectionManager { get; private set; } = null!;
|
||||
|
||||
public static ResourceLoader ResourceLoader { get; set; } = null!;
|
||||
public ResourceLogger ResourceLogger { get; }
|
||||
|
|
@ -66,8 +67,9 @@ public class Penumbra : IDalamudPlugin
|
|||
ResourceLogger = new ResourceLogger( ResourceLoader );
|
||||
ModManager = new ModManager();
|
||||
ModManager.DiscoverMods();
|
||||
ObjectReloader = new ObjectReloader();
|
||||
PathResolver = new PathResolver( ResourceLoader );
|
||||
CollectionManager = new CollectionManager( ModManager );
|
||||
ObjectReloader = new ObjectReloader();
|
||||
PathResolver = new PathResolver( ResourceLoader );
|
||||
|
||||
Dalamud.Commands.AddHandler( CommandName, new CommandInfo( OnCommand )
|
||||
{
|
||||
|
|
@ -193,6 +195,7 @@ public class Penumbra : IDalamudPlugin
|
|||
Api.Dispose();
|
||||
SettingsInterface.Dispose();
|
||||
ObjectReloader.Dispose();
|
||||
CollectionManager.Dispose();
|
||||
|
||||
Dalamud.Commands.RemoveHandler( CommandName );
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue