mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Add temp collection stuff.
This commit is contained in:
parent
e9b12da97e
commit
cceab7d98d
2 changed files with 74 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
|
|
@ -62,7 +63,6 @@ public class IpcTester : IDisposable
|
|||
{
|
||||
if( !_subscribed )
|
||||
{
|
||||
|
||||
_initialized.Subscribe( AddInitialized );
|
||||
_disposed.Subscribe( AddDisposed );
|
||||
_redrawn.Subscribe( SetLastRedrawn );
|
||||
|
|
@ -911,7 +911,7 @@ public class IpcTester : IDisposable
|
|||
return;
|
||||
}
|
||||
|
||||
using var table = ImRaii.Table( "##collTree", 4 );
|
||||
using var table = ImRaii.Table( "##collTree", 5 );
|
||||
if( !table )
|
||||
{
|
||||
return;
|
||||
|
|
@ -927,6 +927,11 @@ public class IpcTester : IDisposable
|
|||
ImGui.TextUnformatted( collection.ResolvedFiles.Count.ToString() );
|
||||
ImGui.TableNextColumn();
|
||||
ImGui.TextUnformatted( collection.MetaCache?.Count.ToString() ?? "0" );
|
||||
ImGui.TableNextColumn();
|
||||
if( ImGui.Button( $"Save##{character}" ) )
|
||||
{
|
||||
Mod.TemporaryMod.SaveTempCollection( collection, character );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Dalamud.Logging;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
||||
using OtterGui.Classes;
|
||||
using Penumbra.Collections;
|
||||
using Penumbra.GameData.ByteString;
|
||||
using Penumbra.Meta.Manipulations;
|
||||
|
||||
|
|
@ -42,5 +47,67 @@ public sealed partial class Mod
|
|||
_default.FileData = dict;
|
||||
_default.ManipulationData = manips;
|
||||
}
|
||||
|
||||
public static void SaveTempCollection( ModCollection collection, string? character = null )
|
||||
{
|
||||
DirectoryInfo? dir = null;
|
||||
try
|
||||
{
|
||||
dir = CreateModFolder( Penumbra.ModManager.BasePath, collection.Name );
|
||||
var fileDir = Directory.CreateDirectory( Path.Combine( dir.FullName, "files" ) );
|
||||
CreateMeta( dir, collection.Name, character ?? Penumbra.Config.DefaultModAuthor,
|
||||
$"Mod generated from temporary collection {collection.Name} for {character ?? "Unknown Character"}.", null, null );
|
||||
var mod = new Mod( dir );
|
||||
var defaultMod = mod._default;
|
||||
foreach( var (gamePath, fullPath) in collection.ResolvedFiles )
|
||||
{
|
||||
if( gamePath.Path.EndsWith( '.', 'i', 'm', 'c' ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var targetPath = fullPath.Path.FullName;
|
||||
if( fullPath.Path.Name.StartsWith( '|' ) )
|
||||
{
|
||||
targetPath = targetPath.Split( '|', 3, StringSplitOptions.RemoveEmptyEntries ).Last();
|
||||
}
|
||||
|
||||
if( Path.IsPathRooted(targetPath) )
|
||||
{
|
||||
var target = Path.Combine( fileDir.FullName, Path.GetFileName(targetPath) );
|
||||
File.Copy( targetPath, target, true );
|
||||
defaultMod.FileData[ gamePath ] = new FullPath( target );
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultMod.FileSwapData[ gamePath ] = new FullPath(targetPath);
|
||||
}
|
||||
}
|
||||
|
||||
foreach( var manip in collection.MetaCache?.Manipulations ?? Array.Empty< MetaManipulation >() )
|
||||
{
|
||||
defaultMod.ManipulationData.Add( manip );
|
||||
}
|
||||
|
||||
mod.SaveDefaultMod();
|
||||
Penumbra.ModManager.AddMod( dir );
|
||||
PluginLog.Information( $"Successfully generated mod {mod.Name} at {mod.ModPath.FullName} for collection {collection.Name}." );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
PluginLog.Error( $"Could not save temporary collection {collection.Name} to permanent Mod:\n{e}" );
|
||||
if( dir != null && Directory.Exists( dir.FullName ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.Delete( dir.FullName, true );
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue