|
| 1 | +using CustomizePlus.Armatures.Services; |
| 2 | +using CustomizePlus.Configuration.Data; |
| 3 | +using CustomizePlus.Core.Data; |
| 4 | +using CustomizePlus.Core.Extensions; |
| 5 | +using CustomizePlus.Profiles; |
| 6 | +using CustomizePlus.Templates; |
| 7 | +using Dalamud.Plugin; |
| 8 | +using OtterGui.Services; |
| 9 | +using System; |
| 10 | +using System.Collections.Generic; |
| 11 | +using System.Linq; |
| 12 | +using System.Reflection; |
| 13 | +using System.Text; |
| 14 | +using System.Threading.Tasks; |
| 15 | + |
| 16 | +namespace CustomizePlus.Core.Services; |
| 17 | + |
| 18 | +//Based on Penumbra's support log |
| 19 | +public class SupportLogBuilderService |
| 20 | +{ |
| 21 | + private readonly PluginConfiguration _configuration; |
| 22 | + private readonly TemplateManager _templateManager; |
| 23 | + private readonly ProfileManager _profileManager; |
| 24 | + private readonly ArmatureManager _armatureManager; |
| 25 | + private readonly DalamudPluginInterface _dalamudPluginInterface; |
| 26 | + |
| 27 | + public SupportLogBuilderService( |
| 28 | + PluginConfiguration configuration, |
| 29 | + TemplateManager templateManager, |
| 30 | + ProfileManager profileManager, |
| 31 | + ArmatureManager armatureManager, |
| 32 | + DalamudPluginInterface dalamudPluginInterface) |
| 33 | + { |
| 34 | + _configuration = configuration; |
| 35 | + _templateManager = templateManager; |
| 36 | + _profileManager = profileManager; |
| 37 | + _armatureManager = armatureManager; |
| 38 | + _dalamudPluginInterface = dalamudPluginInterface; |
| 39 | + } |
| 40 | + |
| 41 | + public string BuildSupportLog() |
| 42 | + { |
| 43 | + var sb = new StringBuilder(10240); |
| 44 | + sb.AppendLine("**Settings**"); |
| 45 | + sb.Append($"> **`Plugin Version: `** {Plugin.Version}\n"); |
| 46 | + sb.Append($"> **`Commit Hash: `** {ThisAssembly.Git.Commit}+{ThisAssembly.Git.Sha}\n"); |
| 47 | + sb.Append($"> **`Root editing: `** {_configuration.EditorConfiguration.RootPositionEditingEnabled}\n"); |
| 48 | + sb.AppendLine("**Settings -> Editor Settings**"); |
| 49 | + sb.Append($"> **`Limit to my creatures (editor): `** {_configuration.EditorConfiguration.LimitLookupToOwnedObjects}\n"); |
| 50 | + sb.Append($"> **`Preview character (editor): `** {_configuration.EditorConfiguration.PreviewCharacterName?.Incognify() ?? "Not set"}\n"); |
| 51 | + sb.AppendLine("**Settings -> Profile application**"); |
| 52 | + sb.Append($"> **`Character window: `** {_configuration.ProfileApplicationSettings.ApplyInCharacterWindow}\n"); |
| 53 | + sb.Append($"> **`Try On: `** {_configuration.ProfileApplicationSettings.ApplyInTryOn}\n"); |
| 54 | + sb.Append($"> **`Cards: `** {_configuration.ProfileApplicationSettings.ApplyInCards}\n"); |
| 55 | + sb.Append($"> **`Inspect: `** {_configuration.ProfileApplicationSettings.ApplyInInspect}\n"); |
| 56 | + sb.Append($"> **`Lobby: `** {_configuration.ProfileApplicationSettings.ApplyInLobby}\n"); |
| 57 | + sb.AppendLine("**Relevant plugins**"); |
| 58 | + GatherRelevantPlugins(sb); |
| 59 | + sb.AppendLine("**Templates**"); |
| 60 | + sb.Append($"> **`Count: `** {_templateManager.Templates.Count}\n"); |
| 61 | + foreach (var template in _templateManager.Templates) |
| 62 | + { |
| 63 | + sb.Append($"> > **`{template.ToString(),-29}`**\n"); |
| 64 | + } |
| 65 | + sb.AppendLine("**Profiles**"); |
| 66 | + sb.Append($"> **`Count: `** {_profileManager.Profiles.Count}\n"); |
| 67 | + foreach (var profile in _profileManager.Profiles) |
| 68 | + { |
| 69 | + sb.Append($"> > =====\n"); |
| 70 | + sb.Append($"> > **`{profile.ToString(),-29}`*\n"); |
| 71 | + sb.Append($"> > **`Name: {profile.Name.Text.Incognify()}`**\n"); |
| 72 | + sb.Append($"> > **`Type: {profile.ProfileType}`**\n"); |
| 73 | + sb.Append($"> > **`Character name: {profile.CharacterName.Text.Incognify()}`**\n"); |
| 74 | + sb.Append($"> > **`Limit to my creatures: {profile.LimitLookupToOwnedObjects}`**\n"); |
| 75 | + sb.Append($"> > **`Templates:`**\n"); |
| 76 | + sb.Append($"> > > **`Count: {profile.Templates.Count}`**\n"); |
| 77 | + foreach (var template in profile.Templates) |
| 78 | + { |
| 79 | + sb.Append($"> > > **`{template.ToString()}`**\n"); |
| 80 | + } |
| 81 | + sb.Append($"> > **`Armatures:`**\n"); |
| 82 | + sb.Append($"> > > **`Count: {profile.Armatures.Count}`**\n"); |
| 83 | + foreach (var armature in profile.Armatures) |
| 84 | + { |
| 85 | + sb.Append($"> > > **`{armature.ToString()}`**\n"); |
| 86 | + } |
| 87 | + sb.Append($"> > =====\n"); |
| 88 | + } |
| 89 | + sb.AppendLine("**Armatures**"); |
| 90 | + sb.Append($"> **`Count: `** {_armatureManager.Armatures.Count}\n"); |
| 91 | + foreach (var kvPair in _armatureManager.Armatures) |
| 92 | + { |
| 93 | + var identifier = kvPair.Key; |
| 94 | + var armature = kvPair.Value; |
| 95 | + sb.Append($"> > =====\n"); |
| 96 | + sb.Append($"> > **`{armature.ToString(),-29}`**\n"); |
| 97 | + sb.Append($"> > **`Actor: {armature.ActorIdentifier.Incognito(null) ?? "None"}`**\n"); |
| 98 | + sb.Append($"> > **`Built: {armature.IsBuilt}`**\n"); |
| 99 | + sb.Append($"> > **`Visible: {armature.IsVisible}`**\n"); |
| 100 | + sb.Append($"> > **`Pending rebind: {armature.IsPendingProfileRebind}`**\n"); |
| 101 | + sb.Append($"> > **`Last seen: {armature.LastSeen}`**\n"); |
| 102 | + sb.Append($"> > **`Profile: {armature.Profile?.ToString() ?? "None"}`**\n"); |
| 103 | + sb.Append($"> > **`Main Root Bone/Total Bones/Partial Skeleton Count: {armature.MainRootBone}/{armature.TotalBoneCount}/{armature.PartialSkeletonCount}`**\n"); |
| 104 | + sb.Append($"> > **`Bone template bindings:`**\n"); |
| 105 | + foreach (var bindingKvPair in armature.BoneTemplateBinding) |
| 106 | + { |
| 107 | + sb.Append($"> > > **`{BoneData.GetBoneDisplayName(bindingKvPair.Key)} ({bindingKvPair.Key}) -> {bindingKvPair.Value.ToString()}`**\n"); |
| 108 | + } |
| 109 | + sb.Append($"> > =====\n"); |
| 110 | + } |
| 111 | + return sb.ToString(); |
| 112 | + } |
| 113 | + |
| 114 | + |
| 115 | + private void GatherRelevantPlugins(StringBuilder sb) |
| 116 | + { |
| 117 | + ReadOnlySpan<string> relevantPlugins = |
| 118 | + [ |
| 119 | + "MareSynchronos", "Ktisis", "Brio", "DynamicBridge" |
| 120 | + ]; |
| 121 | + var plugins = _dalamudPluginInterface.InstalledPlugins |
| 122 | + .GroupBy(p => p.InternalName) |
| 123 | + .ToDictionary(g => g.Key, g => |
| 124 | + { |
| 125 | + var item = g.OrderByDescending(p => p.IsLoaded).ThenByDescending(p => p.Version).First(); |
| 126 | + return (item.IsLoaded, item.Version, item.Name); |
| 127 | + }); |
| 128 | + foreach (var plugin in relevantPlugins) |
| 129 | + { |
| 130 | + if (plugins.TryGetValue(plugin, out var data)) |
| 131 | + sb.Append($"> **`{data.Name + ':',-29}`** {data.Version}{(data.IsLoaded ? string.Empty : " (Disabled)")}\n"); |
| 132 | + } |
| 133 | + } |
| 134 | +} |
0 commit comments