-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCkCommonsHost.cs
More file actions
69 lines (58 loc) · 2.36 KB
/
Copy pathCkCommonsHost.cs
File metadata and controls
69 lines (58 loc) · 2.36 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
using CkCommons.RichText;
using CkCommons.Textures;
using Dalamud.Plugin;
using Serilog.Events;
using System.Reflection;
namespace CkCommons;
#nullable disable
[Flags]
public enum CkLogFilter
{
None = 0,
AudioSystem = 1 << 0,
RichText = 1 << 1,
DrawSystem = 1 << 2,
All = AudioSystem | RichText | DrawSystem,
}
/// <summary>
/// The main hoster for CkCommons. <see cref="Init(IDalamudPluginInterface, IDalamudPlugin)"/> must
/// be called during your <see cref="IDalamudPlugin"/> entry point. <para/>
///
/// Likewise, it's <see cref="Dispose"/> should be called once <see cref="IDalamudPlugin"/> falls
/// out of plugin scope.
/// </summary>
public static class CkCommonsHost
{
public static IDalamudPlugin Instance = null;
public static bool Disposed { get; private set; } = false;
/// <summary>
/// CkCommons sections that use <see cref="IDalamudPlugin"/> accessors WON'T WORK calling this on plugin entry.
/// </summary>
public static void Init(IDalamudPluginInterface pluginInterface, IDalamudPlugin instance, CkLogFilter logFilter = CkLogFilter.All)
{
Instance = instance;
Svc.Init(pluginInterface);
Svc.Log.MinimumLogLevel = LogEventLevel.Debug;
Svc.Log.Information($"This is CkCommons v{typeof(CkCommonsHost).Assembly.GetName().Version} " +
$"and {Svc.PluginInterface.InternalName} v{instance.GetType().Assembly.GetName().Version}.");
// AudioSystem.Init();
CkRichText.Init(logFilter.HasFlag(CkLogFilter.RichText));
}
public static void CheckForObfuscation()
{
if (Assembly.GetCallingAssembly().GetTypes().FirstOrDefault(x => x.IsAssignableTo(typeof(IDalamudPlugin)))?.Name == Svc.PluginInterface.InternalName)
Svc.Log.Fatal($"{Svc.PluginInterface.InternalName} name match error!");
}
/// <summary>
/// Disposes all CkCommons services and cleans up resources. <para/>
/// You are required to call this to free up resources!
/// </summary>
public static void Dispose()
{
Disposed = true;
// Any classes that initialize, have an initializer, store data that should be replaced, or do not use IDisposable, should be manually disposed.
// Generic.Safe(AudioSystem.Dispose);
Generic.Safe(CkRichText.Dispose);
Generic.Safe(TextureManager.Dispose);
}
}