-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathKamiToolKitLibrary.cs
More file actions
84 lines (65 loc) · 2.88 KB
/
KamiToolKitLibrary.cs
File metadata and controls
84 lines (65 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Concurrent;
using System.Globalization;
using System.Resources;
using Dalamud.Plugin;
using KamiToolKit.Dalamud;
using Serilog.Events;
namespace KamiToolKit;
public static class KamiToolKitLibrary {
internal static bool IsInitialized { get; private set; }
internal static IDalamudPluginInterface? PluginInterface { get; private set; }
internal static ConcurrentDictionary<nint, Type>? AllocatedNodes;
internal static string? DefaultWindowSubtitle;
internal static Experimental Experimental = new();
internal static ResourceManager? ResourceManager;
internal static CultureInfo? CurrentCulture;
/// <summary>
/// Main initialization method for KamiToolKit. This method is required to be invoked before any KamiToolKit features are used.
/// Failure to do so will not result in any direct warnings, but will result in undefined behavior.
/// </summary>
public static void Initialize(IDalamudPluginInterface pluginInterface, string? defaultWindowSubtitle = null) {
IsInitialized = true;
DefaultWindowSubtitle = defaultWindowSubtitle;
PluginInterface = pluginInterface;
// Inject non-Experimental Properties
PluginInterface.Create<Services>();
Services.GameInteropProvider.InitializeFromAttributes(Experimental);
// Create node data share
AllocatedNodes = PluginInterface.GetOrCreateData("KamiToolKitAllocatedNodes", () => new ConcurrentDictionary<nint, Type>());
// Force enable Verbose so that users are able to get advanced logging information on request.
Services.Log.MinimumLogLevel = LogEventLevel.Verbose;
Services.Log.Info($"KamiToolKit initialized for {PluginInterface.InternalName}");
NativeAddon.InitializeCloseCallback();
}
/// <summary>
/// Sets the resource manager that KTK will use to resolve enums.
/// </summary>
public static void SetResourceManager(ResourceManager resourceManager) {
ResourceManager = resourceManager;
}
/// <summary>
/// Sets the current culture that KTK will use to resolve enums.
/// </summary>
public static void SetCurrentCulture(CultureInfo culture) {
CurrentCulture = culture;
}
/// <summary>
/// Alias for Cleanup
/// </summary>
public static void Dispose() => Cleanup();
/// <summary>
/// Alias for Cleanup
/// </summary>
public static void Shutdown() => Cleanup();
/// <summary>
/// Cleans up any potentially leaked resources that KamiToolKit has allocated.
/// </summary>
public static void Cleanup() {
NodeBase.DisposeNodes();
NativeAddon.DisposeAddons();
NativeAddon.DisposeCloseCallback();
if (MainThreadSafety.TryAssertMainThread()) return;
Services.PluginInterface.RelinquishData("KamiToolKitAllocatedNodes");
}
}