mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +01:00
Make API/IPC correctly disposable.
This commit is contained in:
parent
e7d2cb0c10
commit
ca7c997606
3 changed files with 30 additions and 15 deletions
|
|
@ -14,14 +14,15 @@ namespace Penumbra.Api
|
||||||
public class PenumbraApi : IDisposable, IPenumbraApi
|
public class PenumbraApi : IDisposable, IPenumbraApi
|
||||||
{
|
{
|
||||||
public int ApiVersion { get; } = 3;
|
public int ApiVersion { get; } = 3;
|
||||||
private readonly Penumbra _penumbra;
|
private Penumbra? _penumbra;
|
||||||
private readonly Lumina.GameData? _lumina;
|
private Lumina.GameData? _lumina;
|
||||||
public bool Valid { get; private set; } = false;
|
|
||||||
|
public bool Valid
|
||||||
|
=> _penumbra != null;
|
||||||
|
|
||||||
public PenumbraApi( Penumbra penumbra )
|
public PenumbraApi( Penumbra penumbra )
|
||||||
{
|
{
|
||||||
_penumbra = penumbra;
|
_penumbra = penumbra;
|
||||||
Valid = true;
|
|
||||||
_lumina = ( Lumina.GameData? )Dalamud.GameData.GetType()
|
_lumina = ( Lumina.GameData? )Dalamud.GameData.GetType()
|
||||||
.GetField( "gameData", BindingFlags.Instance | BindingFlags.NonPublic )
|
.GetField( "gameData", BindingFlags.Instance | BindingFlags.NonPublic )
|
||||||
?.GetValue( Dalamud.GameData );
|
?.GetValue( Dalamud.GameData );
|
||||||
|
|
@ -29,7 +30,8 @@ namespace Penumbra.Api
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Valid = false;
|
_penumbra = null;
|
||||||
|
_lumina = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public event ChangedItemClick? ChangedItemClicked;
|
public event ChangedItemClick? ChangedItemClicked;
|
||||||
|
|
@ -57,21 +59,21 @@ namespace Penumbra.Api
|
||||||
{
|
{
|
||||||
CheckInitialized();
|
CheckInitialized();
|
||||||
|
|
||||||
_penumbra.ObjectReloader.RedrawObject( name, setting );
|
_penumbra!.ObjectReloader.RedrawObject( name, setting );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RedrawObject( GameObject? gameObject, RedrawType setting )
|
public void RedrawObject( GameObject? gameObject, RedrawType setting )
|
||||||
{
|
{
|
||||||
CheckInitialized();
|
CheckInitialized();
|
||||||
|
|
||||||
_penumbra.ObjectReloader.RedrawObject( gameObject, setting );
|
_penumbra!.ObjectReloader.RedrawObject( gameObject, setting );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RedrawAll( RedrawType setting )
|
public void RedrawAll( RedrawType setting )
|
||||||
{
|
{
|
||||||
CheckInitialized();
|
CheckInitialized();
|
||||||
|
|
||||||
_penumbra.ObjectReloader.RedrawAll( setting );
|
_penumbra!.ObjectReloader.RedrawAll( setting );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ResolvePath( string path, ModManager manager, ModCollection collection )
|
private static string ResolvePath( string path, ModManager manager, ModCollection collection )
|
||||||
|
|
@ -80,6 +82,7 @@ namespace Penumbra.Api
|
||||||
{
|
{
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
var gamePath = new GamePath( path );
|
var gamePath = new GamePath( path );
|
||||||
var ret = collection.Cache?.ResolveSwappedOrReplacementPath( gamePath );
|
var ret = collection.Cache?.ResolveSwappedOrReplacementPath( gamePath );
|
||||||
ret ??= manager.Collections.ForcedCollection.Cache?.ResolveSwappedOrReplacementPath( gamePath );
|
ret ??= manager.Collections.ForcedCollection.Cache?.ResolveSwappedOrReplacementPath( gamePath );
|
||||||
|
|
@ -89,12 +92,14 @@ namespace Penumbra.Api
|
||||||
|
|
||||||
public string ResolvePath( string path )
|
public string ResolvePath( string path )
|
||||||
{
|
{
|
||||||
|
CheckInitialized();
|
||||||
var modManager = Service< ModManager >.Get();
|
var modManager = Service< ModManager >.Get();
|
||||||
return ResolvePath( path, modManager, modManager.Collections.DefaultCollection );
|
return ResolvePath( path, modManager, modManager.Collections.DefaultCollection );
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ResolvePath( string path, string characterName )
|
public string ResolvePath( string path, string characterName )
|
||||||
{
|
{
|
||||||
|
CheckInitialized();
|
||||||
var modManager = Service< ModManager >.Get();
|
var modManager = Service< ModManager >.Get();
|
||||||
return ResolvePath( path, modManager,
|
return ResolvePath( path, modManager,
|
||||||
modManager.Collections.CharacterCollection.TryGetValue( characterName, out var collection )
|
modManager.Collections.CharacterCollection.TryGetValue( characterName, out var collection )
|
||||||
|
|
@ -104,6 +109,7 @@ namespace Penumbra.Api
|
||||||
|
|
||||||
private T? GetFileIntern< T >( string resolvedPath ) where T : FileResource
|
private T? GetFileIntern< T >( string resolvedPath ) where T : FileResource
|
||||||
{
|
{
|
||||||
|
CheckInitialized();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if( Path.IsPathRooted( resolvedPath ) )
|
if( Path.IsPathRooted( resolvedPath ) )
|
||||||
|
|
@ -113,7 +119,7 @@ namespace Penumbra.Api
|
||||||
|
|
||||||
return Dalamud.GameData.GetFile< T >( resolvedPath );
|
return Dalamud.GameData.GetFile< T >( resolvedPath );
|
||||||
}
|
}
|
||||||
catch( Exception e)
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
PluginLog.Warning( $"Could not load file {resolvedPath}:\n{e}" );
|
PluginLog.Warning( $"Could not load file {resolvedPath}:\n{e}" );
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ using Penumbra.GameData.Enums;
|
||||||
|
|
||||||
namespace Penumbra.Api
|
namespace Penumbra.Api
|
||||||
{
|
{
|
||||||
public class PenumbraIpc
|
public class PenumbraIpc : IDisposable
|
||||||
{
|
{
|
||||||
public const string LabelProviderApiVersion = "Penumbra.ApiVersion";
|
public const string LabelProviderApiVersion = "Penumbra.ApiVersion";
|
||||||
public const string LabelProviderRedrawName = "Penumbra.RedrawObjectByName";
|
public const string LabelProviderRedrawName = "Penumbra.RedrawObjectByName";
|
||||||
|
|
@ -91,11 +91,7 @@ namespace Penumbra.Api
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProviderRedrawAll = pi.GetIpcProvider< int, object >( LabelProviderRedrawAll );
|
ProviderRedrawAll = pi.GetIpcProvider< int, object >( LabelProviderRedrawAll );
|
||||||
ProviderRedrawAll.RegisterFunc( i =>
|
ProviderRedrawAll.RegisterAction( i => api.RedrawAll( CheckRedrawType( i ) ) );
|
||||||
{
|
|
||||||
api.RedrawAll( CheckRedrawType( i ) );
|
|
||||||
return null!;
|
|
||||||
} );
|
|
||||||
}
|
}
|
||||||
catch( Exception e )
|
catch( Exception e )
|
||||||
{
|
{
|
||||||
|
|
@ -142,5 +138,17 @@ namespace Penumbra.Api
|
||||||
PluginLog.Error( $"Error registering IPC provider for {LabelProviderChangedItemClick}:\n{e}" );
|
PluginLog.Error( $"Error registering IPC provider for {LabelProviderChangedItemClick}:\n{e}" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
ProviderApiVersion?.UnregisterFunc();
|
||||||
|
ProviderRedrawName?.UnregisterAction();
|
||||||
|
ProviderRedrawObject?.UnregisterAction();
|
||||||
|
ProviderRedrawAll?.UnregisterAction();
|
||||||
|
ProviderResolveDefault?.UnregisterFunc();
|
||||||
|
ProviderResolveCharacter?.UnregisterFunc();
|
||||||
|
Api.ChangedItemClicked -= OnClick;
|
||||||
|
Api.ChangedItemTooltip -= OnTooltip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -134,6 +134,7 @@ namespace Penumbra
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
Ipc.Dispose();
|
||||||
Api.Dispose();
|
Api.Dispose();
|
||||||
SettingsInterface.Dispose();
|
SettingsInterface.Dispose();
|
||||||
ObjectReloader.Dispose();
|
ObjectReloader.Dispose();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue