mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 13:14:17 +01:00
178 lines
No EOL
5.1 KiB
C#
178 lines
No EOL
5.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Threading;
|
|
using Dalamud.Logging;
|
|
using OtterGui.Classes;
|
|
using Penumbra.GameData.ByteString;
|
|
using Penumbra.Meta.Manager;
|
|
|
|
namespace Penumbra.Collections;
|
|
|
|
public partial class ModCollection
|
|
{
|
|
// Only active collections need to have a cache.
|
|
private Cache? _cache;
|
|
|
|
public bool HasCache
|
|
=> _cache != null;
|
|
|
|
public int RecomputeCounter
|
|
=> _cache?.RecomputeCounter ?? 0;
|
|
|
|
// Only create, do not update.
|
|
private void CreateCache( bool isDefault )
|
|
{
|
|
if( _cache == null )
|
|
{
|
|
CalculateEffectiveFileList( true, isDefault );
|
|
PluginLog.Verbose( "Created new cache for collection {Name:l}.", Name );
|
|
}
|
|
}
|
|
|
|
// Force an update with metadata for this cache.
|
|
private void ForceCacheUpdate( bool isDefault )
|
|
=> CalculateEffectiveFileList( true, isDefault );
|
|
|
|
|
|
// Clear the current cache.
|
|
private void ClearCache()
|
|
{
|
|
_cache?.Dispose();
|
|
_cache = null;
|
|
PluginLog.Verbose( "Cleared cache of collection {Name:l}.", Name );
|
|
}
|
|
|
|
|
|
public FullPath? ResolvePath( Utf8GamePath path )
|
|
=> _cache?.ResolvePath( path );
|
|
|
|
// Force a file to be resolved to a specific path regardless of conflicts.
|
|
internal void ForceFile( Utf8GamePath path, FullPath fullPath )
|
|
=> _cache!.ResolvedFiles[ path ] = fullPath;
|
|
|
|
// Force a file resolve to be removed.
|
|
internal void RemoveFile( Utf8GamePath path )
|
|
=> _cache!.ResolvedFiles.Remove( path );
|
|
|
|
// Obtain data from the cache.
|
|
internal MetaManager? MetaCache
|
|
=> _cache?.MetaManipulations;
|
|
|
|
internal IReadOnlyDictionary< Utf8GamePath, FullPath > ResolvedFiles
|
|
=> _cache?.ResolvedFiles ?? new Dictionary< Utf8GamePath, FullPath >();
|
|
|
|
internal IReadOnlyDictionary< string, object? > ChangedItems
|
|
=> _cache?.ChangedItems ?? new Dictionary< string, object? >();
|
|
|
|
internal IReadOnlyList< ConflictCache.Conflict > Conflicts
|
|
=> _cache?.Conflicts.Conflicts ?? Array.Empty< ConflictCache.Conflict >();
|
|
|
|
internal SubList< ConflictCache.Conflict > ModConflicts( int modIdx )
|
|
=> _cache?.Conflicts.ModConflicts( modIdx ) ?? SubList< ConflictCache.Conflict >.Empty;
|
|
|
|
// Update the effective file list for the given cache.
|
|
// Creates a cache if necessary.
|
|
public void CalculateEffectiveFileList( bool withMetaManipulations, bool reloadDefault )
|
|
=> Penumbra.Framework.RegisterImportant( nameof( CalculateEffectiveFileList ) + Name,
|
|
() => CalculateEffectiveFileListInternal( withMetaManipulations, reloadDefault ) );
|
|
|
|
private void CalculateEffectiveFileListInternal( bool withMetaManipulations, bool reloadDefault )
|
|
{
|
|
// Skip the empty collection.
|
|
if( Index == 0 )
|
|
{
|
|
return;
|
|
}
|
|
|
|
PluginLog.Debug( "[{Thread}] Recalculating effective file list for {CollectionName:l} [{WithMetaManipulations}] [{ReloadDefault}]", Thread.CurrentThread.ManagedThreadId, Name,
|
|
withMetaManipulations, reloadDefault );
|
|
_cache ??= new Cache( this );
|
|
_cache.CalculateEffectiveFileList( withMetaManipulations );
|
|
if( reloadDefault )
|
|
{
|
|
SetFiles();
|
|
Penumbra.ResidentResources.Reload();
|
|
}
|
|
PluginLog.Debug( "[{Thread}] Recalculation of effective file list for {CollectionName:l} finished.", Thread.CurrentThread.ManagedThreadId, Name);
|
|
}
|
|
|
|
// Set Metadata files.
|
|
[Conditional( "USE_EQP" )]
|
|
public void SetEqpFiles()
|
|
{
|
|
if( _cache == null )
|
|
{
|
|
MetaManager.MetaManagerEqp.ResetFiles();
|
|
}
|
|
else
|
|
{
|
|
_cache.MetaManipulations.Eqp.SetFiles();
|
|
}
|
|
}
|
|
|
|
[Conditional( "USE_EQDP" )]
|
|
public void SetEqdpFiles()
|
|
{
|
|
if( _cache == null )
|
|
{
|
|
MetaManager.MetaManagerEqdp.ResetFiles();
|
|
}
|
|
else
|
|
{
|
|
_cache.MetaManipulations.Eqdp.SetFiles();
|
|
}
|
|
}
|
|
|
|
[Conditional( "USE_GMP" )]
|
|
public void SetGmpFiles()
|
|
{
|
|
if( _cache == null )
|
|
{
|
|
MetaManager.MetaManagerGmp.ResetFiles();
|
|
}
|
|
else
|
|
{
|
|
_cache.MetaManipulations.Gmp.SetFiles();
|
|
}
|
|
}
|
|
|
|
[Conditional( "USE_EST" )]
|
|
public void SetEstFiles()
|
|
{
|
|
if( _cache == null )
|
|
{
|
|
MetaManager.MetaManagerEst.ResetFiles();
|
|
}
|
|
else
|
|
{
|
|
_cache.MetaManipulations.Est.SetFiles();
|
|
}
|
|
}
|
|
|
|
[Conditional( "USE_CMP" )]
|
|
public void SetCmpFiles()
|
|
{
|
|
if( _cache == null )
|
|
{
|
|
MetaManager.MetaManagerCmp.ResetFiles();
|
|
}
|
|
else
|
|
{
|
|
_cache.MetaManipulations.Cmp.SetFiles();
|
|
}
|
|
}
|
|
|
|
public void SetFiles()
|
|
{
|
|
if( _cache == null )
|
|
{
|
|
Penumbra.CharacterUtility.ResetAll();
|
|
}
|
|
else
|
|
{
|
|
_cache.MetaManipulations.SetFiles();
|
|
PluginLog.Debug( "Set CharacterUtility resources for collection {Name:l}.", Name );
|
|
}
|
|
}
|
|
} |