mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
reload player resources once a mod reload has occurred, wip api
This commit is contained in:
parent
f1d8ce0221
commit
77cda604c6
6 changed files with 109 additions and 8 deletions
41
Penumbra/API/ModsController.cs
Normal file
41
Penumbra/API/ModsController.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using EmbedIO;
|
||||
using EmbedIO.Routing;
|
||||
using EmbedIO.WebApi;
|
||||
|
||||
namespace Penumbra.API
|
||||
{
|
||||
public class ModsController : WebApiController
|
||||
{
|
||||
private readonly Plugin _plugin;
|
||||
|
||||
public ModsController( Plugin plugin )
|
||||
{
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
[Route( HttpVerbs.Get, "/mods" )]
|
||||
public object GetMods()
|
||||
{
|
||||
return _plugin.ModManager.Mods.ModSettings.Select( x => new
|
||||
{
|
||||
x.Enabled,
|
||||
x.Priority,
|
||||
x.FolderName,
|
||||
x.Mod.Meta,
|
||||
BasePath = x.Mod.ModBasePath.FullName,
|
||||
Files = x.Mod.ModFiles.Select( x => x.FullName )
|
||||
} );
|
||||
}
|
||||
|
||||
[Route( HttpVerbs.Get, "/files" )]
|
||||
public object CreateMod()
|
||||
{
|
||||
return _plugin.ModManager.ResolvedFiles.ToDictionary(
|
||||
o => o.Key,
|
||||
o => o.Value.FullName
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,8 @@ namespace Penumbra
|
|||
|
||||
public bool DisableFileSystemNotifications { get; set; } = false;
|
||||
|
||||
public bool EnableHttpApi { get; set; } = false;
|
||||
|
||||
public string CurrentCollection { get; set; } = @"D:/ffxiv/fs_mods/";
|
||||
|
||||
public List< string > ModCollections { get; set; } = new();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace Penumbra.Mods
|
|||
{
|
||||
public class ModManager : IDisposable
|
||||
{
|
||||
private readonly Plugin _plugin;
|
||||
public readonly Dictionary< string, FileInfo > ResolvedFiles = new();
|
||||
public readonly Dictionary< string, string > SwappedFiles = new();
|
||||
|
||||
|
|
@ -14,6 +15,11 @@ namespace Penumbra.Mods
|
|||
|
||||
private DirectoryInfo _basePath;
|
||||
|
||||
public ModManager( Plugin plugin )
|
||||
{
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
public void DiscoverMods()
|
||||
{
|
||||
if( _basePath == null )
|
||||
|
|
@ -92,6 +98,9 @@ namespace Penumbra.Mods
|
|||
Mods.Save();
|
||||
|
||||
CalculateEffectiveFileList();
|
||||
|
||||
// Needed to reload body textures with mods
|
||||
_plugin.GameUtils.ReloadPlayerResources();
|
||||
}
|
||||
|
||||
public void CalculateEffectiveFileList()
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="EmbedIO" Version="3.4.3" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="Reloaded.Hooks" Version="2.4.1" />
|
||||
<PackageReference Include="SharpZipLib" Version="1.3.1" />
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
using Dalamud.Game.Command;
|
||||
using Dalamud.Plugin;
|
||||
using EmbedIO;
|
||||
using EmbedIO.Actions;
|
||||
using EmbedIO.WebApi;
|
||||
using Penumbra.API;
|
||||
using Penumbra.Game;
|
||||
using Penumbra.Mods;
|
||||
using Penumbra.UI;
|
||||
|
|
@ -26,7 +30,7 @@ namespace Penumbra
|
|||
|
||||
public string PluginDebugTitleStr { get; private set; }
|
||||
|
||||
public bool ImportInProgress => SettingsInterface?.IsImportRunning ?? true;
|
||||
private WebServer _webServer;
|
||||
|
||||
public void Initialize( DalamudPluginInterface pluginInterface )
|
||||
{
|
||||
|
|
@ -37,7 +41,7 @@ namespace Penumbra
|
|||
|
||||
GameUtils = new GameUtils( PluginInterface );
|
||||
|
||||
ModManager = new ModManager();
|
||||
ModManager = new ModManager( this );
|
||||
ModManager.DiscoverMods( Configuration.CurrentCollection );
|
||||
|
||||
ResourceLoader = new ResourceLoader( this );
|
||||
|
|
@ -50,13 +54,39 @@ namespace Penumbra
|
|||
ResourceLoader.Init();
|
||||
ResourceLoader.Enable();
|
||||
|
||||
// Needed to reload body textures with mods
|
||||
GameUtils.ReloadPlayerResources();
|
||||
|
||||
SettingsInterface = new SettingsInterface( this );
|
||||
PluginInterface.UiBuilder.OnBuildUi += SettingsInterface.Draw;
|
||||
|
||||
PluginDebugTitleStr = $"{Name} - Debug Build";
|
||||
|
||||
if( Configuration.EnableHttpApi )
|
||||
{
|
||||
CreateWebServer();
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateWebServer()
|
||||
{
|
||||
var prefix = "http://localhost:45800/";
|
||||
|
||||
ShutdownWebServer();
|
||||
|
||||
_webServer = new WebServer( o => o
|
||||
.WithUrlPrefix( prefix )
|
||||
.WithMode( HttpListenerMode.EmbedIO ) )
|
||||
.WithCors( prefix )
|
||||
.WithWebApi( "/api", m => m
|
||||
.WithController( () => new ModsController( this ) ) );
|
||||
|
||||
_webServer.StateChanged += ( s, e ) => PluginLog.Information( $"WebServer New State - {e.NewState}" );
|
||||
|
||||
_webServer.RunAsync();
|
||||
}
|
||||
|
||||
public void ShutdownWebServer()
|
||||
{
|
||||
_webServer?.Dispose();
|
||||
_webServer = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
@ -69,6 +99,8 @@ namespace Penumbra
|
|||
PluginInterface.Dispose();
|
||||
|
||||
ResourceLoader.Dispose();
|
||||
|
||||
ShutdownWebServer();
|
||||
}
|
||||
|
||||
private void OnCommand( string command, string rawArgs )
|
||||
|
|
|
|||
|
|
@ -299,6 +299,22 @@ namespace Penumbra.UI
|
|||
dirty = true;
|
||||
}
|
||||
|
||||
var http = _plugin.Configuration.EnableHttpApi;
|
||||
if( ImGui.Checkbox( "Enable HTTP API", ref http ) )
|
||||
{
|
||||
if( http )
|
||||
{
|
||||
_plugin.CreateWebServer();
|
||||
}
|
||||
else
|
||||
{
|
||||
_plugin.ShutdownWebServer();
|
||||
}
|
||||
|
||||
_plugin.Configuration.EnableHttpApi = http;
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
if( ImGui.Button( "Reload Player Resource" ) )
|
||||
{
|
||||
_plugin.GameUtils.ReloadPlayerResources();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue