Skip to content

Commit 0d64384

Browse files
committed
Add cleanup buttons to PCP, add option to turn off PCP IPC.
1 parent 10894d4 commit 0d64384

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

Penumbra/Services/PcpService.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class PcpService : IApiService, IDisposable
3838
private readonly CommunicatorService _communicator;
3939
private readonly SHA1 _sha1 = SHA1.Create();
4040
private readonly ModFileSystem _fileSystem;
41+
private readonly ModManager _mods;
4142

4243
public PcpService(Configuration config,
4344
SaveService files,
@@ -50,7 +51,8 @@ public PcpService(Configuration config,
5051
ModCreator modCreator,
5152
ModExportManager modExport,
5253
CommunicatorService communicator,
53-
ModFileSystem fileSystem)
54+
ModFileSystem fileSystem,
55+
ModManager mods)
5456
{
5557
_config = config;
5658
_files = files;
@@ -64,10 +66,27 @@ public PcpService(Configuration config,
6466
_modExport = modExport;
6567
_communicator = communicator;
6668
_fileSystem = fileSystem;
69+
_mods = mods;
6770

6871
_communicator.ModPathChanged.Subscribe(OnModPathChange, ModPathChanged.Priority.PcpService);
6972
}
7073

74+
public void CleanPcpMods()
75+
{
76+
var mods = _mods.Where(m => m.ModTags.Contains("PCP")).ToList();
77+
Penumbra.Log.Information($"[PCPService] Deleting {mods.Count} mods containing the tag PCP.");
78+
foreach (var mod in mods)
79+
_mods.DeleteMod(mod);
80+
}
81+
82+
public void CleanPcpCollections()
83+
{
84+
var collections = _collections.Storage.Where(c => c.Identity.Name.StartsWith("PCP/")).ToList();
85+
Penumbra.Log.Information($"[PCPService] Deleting {collections.Count} mods containing the tag PCP.");
86+
foreach (var collection in collections)
87+
_collections.Storage.Delete(collection);
88+
}
89+
7190
private void OnModPathChange(ModPathChangeType type, Mod mod, DirectoryInfo? oldDirectory, DirectoryInfo? newDirectory)
7291
{
7392
if (type is not ModPathChangeType.Added || _config.DisablePcpHandling || newDirectory is null)
@@ -80,12 +99,14 @@ private void OnModPathChange(ModPathChangeType type, Mod mod, DirectoryInfo? old
8099
{
81100
// First version had collection.json, changed.
82101
var oldFile = Path.Combine(newDirectory.FullName, "collection.json");
102+
Penumbra.Log.Information("[PCPService] Renaming old PCP file from collection.json to character.json.");
83103
if (File.Exists(oldFile))
84104
File.Move(oldFile, file, true);
85105
else
86106
return;
87107
}
88108

109+
Penumbra.Log.Information($"[PCPService] Found a PCP file for {mod.Name}, applying.");
89110
var text = File.ReadAllText(file);
90111
var jObj = JObject.Parse(text);
91112
var identifier = _actors.FromJson(jObj["Actor"] as JObject);
@@ -116,6 +137,7 @@ private void OnModPathChange(ModPathChangeType type, Mod mod, DirectoryInfo? old
116137
// ignored.
117138
}
118139
}
140+
119141
if (_config.AllowPcpIpc)
120142
_communicator.PcpParsing.Invoke(jObj, mod.Identifier, collection.Identity.Id);
121143
}
@@ -132,6 +154,7 @@ public void Dispose()
132154
{
133155
try
134156
{
157+
Penumbra.Log.Information($"[PCPService] Creating PCP file for game object {objectIndex.Index}.");
135158
var (identifier, tree, collection) = await _framework.Framework.RunOnFrameworkThread(() =>
136159
{
137160
var (actor, identifier) = CheckActor(objectIndex);
@@ -178,6 +201,7 @@ private async Task CreateCollectionInfo(DirectoryInfo directory, ObjectIndex ind
178201
{
179202
["Version"] = 1,
180203
["Actor"] = actor.ToJson(),
204+
["Mod"] = directory.Name,
181205
["Collection"] = note.Length > 0 ? $"{actor.ToName()}: {note}" : actor.ToName(),
182206
["Time"] = time,
183207
["Note"] = note,

Penumbra/UI/Tabs/SettingsTab.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public ReadOnlySpan<byte> Label
5252
private readonly CollectionAutoSelector _autoSelector;
5353
private readonly CleanupService _cleanupService;
5454
private readonly AttributeHook _attributeHook;
55+
private readonly PcpService _pcpService;
5556

5657
private int _minimumX = int.MaxValue;
5758
private int _minimumY = int.MaxValue;
@@ -64,7 +65,7 @@ public SettingsTab(IDalamudPluginInterface pluginInterface, Configuration config
6465
DalamudSubstitutionProvider dalamudSubstitutionProvider, FileCompactor compactor, DalamudConfigService dalamudConfig,
6566
IDataManager gameData, PredefinedTagManager predefinedTagConfig, CrashHandlerService crashService,
6667
MigrationSectionDrawer migrationDrawer, CollectionAutoSelector autoSelector, CleanupService cleanupService,
67-
AttributeHook attributeHook)
68+
AttributeHook attributeHook, PcpService pcpService)
6869
{
6970
_pluginInterface = pluginInterface;
7071
_config = config;
@@ -90,6 +91,7 @@ public SettingsTab(IDalamudPluginInterface pluginInterface, Configuration config
9091
_autoSelector = autoSelector;
9192
_cleanupService = cleanupService;
9293
_attributeHook = attributeHook;
94+
_pcpService = pcpService;
9395
}
9496

9597
public void DrawHeader()
@@ -601,6 +603,23 @@ private void DrawModHandlingSettings()
601603
Checkbox("Handle PCP Files",
602604
"When encountering specific mods, usually but not necessarily denoted by a .pcp file ending, Penumbra will automatically try to create an associated collection and assign it to a specific character for this mod package. This can turn this behaviour off if unwanted.",
603605
!_config.DisablePcpHandling, v => _config.DisablePcpHandling = !v);
606+
607+
var active = _config.DeleteModModifier.IsActive();
608+
ImGui.SameLine();
609+
if (ImUtf8.ButtonEx("Delete all PCP Mods"u8, "Deletes all mods tagged with 'PCP' from the mod list."u8, disabled: !active))
610+
_pcpService.CleanPcpMods();
611+
if (!active)
612+
ImUtf8.HoverTooltip(ImGuiHoveredFlags.AllowWhenDisabled, $"Hold {_config.DeleteModModifier} while clicking.");
613+
614+
ImGui.SameLine();
615+
if (ImUtf8.ButtonEx("Delete all PCP Collections"u8, "Deletes all collections whose name starts with 'PCP/' from the collection list."u8, disabled: !active))
616+
_pcpService.CleanPcpCollections();
617+
if (!active)
618+
ImUtf8.HoverTooltip(ImGuiHoveredFlags.AllowWhenDisabled, $"Hold {_config.DeleteModModifier} while clicking.");
619+
620+
Checkbox("Allow Other Plugins Access to PCP Handling",
621+
"When creating or importing PCP files, other plugins can add and interpret their own data to the character.json file.",
622+
_config.AllowPcpIpc, v => _config.AllowPcpIpc = v);
604623
DrawDefaultModImportPath();
605624
DrawDefaultModAuthor();
606625
DrawDefaultModImportFolder();

0 commit comments

Comments
 (0)