66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
global using static QuestShare.Service;
|
|
global using QuestShare.Common;
|
|
using Dalamud.Plugin;
|
|
using Dalamud.Plugin.Services;
|
|
using Serilog.Events;
|
|
using QuestShare.Services;
|
|
using QuestShare.Addons;
|
|
|
|
namespace QuestShare;
|
|
|
|
public sealed class Plugin : IDalamudPlugin
|
|
{
|
|
public static string Name => "Quest Share";
|
|
public static string Version => "1.0.0";
|
|
public static string PluginDataPath { get; private set; } = null!;
|
|
internal static ConfigurationManager Configuration { get; private set; } = null!;
|
|
internal static SocketClientService SocketClient { get; private set; } = null!;
|
|
|
|
internal static StringWriter LogStream { get; private set; } = null!;
|
|
|
|
public Plugin(IDalamudPluginInterface pluginInterface)
|
|
{
|
|
pluginInterface.Create<Service>(pluginInterface);
|
|
// redirect console output to plugin log
|
|
Configuration = new ConfigurationManager();
|
|
WindowManager.Initialize();
|
|
GameEventManager.Initialize();
|
|
Commands.Initialize();
|
|
GameQuestManager.Initialize();
|
|
AddonPartyList.Initialize();
|
|
LogStream = new StringWriter();
|
|
Console.SetOut(LogStream);
|
|
Console.SetError(LogStream);
|
|
Service.Framework.Update += OnFramework;
|
|
Log.Debug($"Share Code: {Configuration.Instance.ShareCode} - Token: {Configuration.Instance.Token}");
|
|
SocketClient = new SocketClientService();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
WindowManager.Dispose();
|
|
GameEventManager.Dispose();
|
|
Commands.Dispose();
|
|
Configuration.Save();
|
|
LogStream.Dispose();
|
|
AddonPartyList.Dispose();
|
|
Service.Framework.Update -= OnFramework;
|
|
SocketClient.Dispose();
|
|
Configuration.Dispose();
|
|
ShareService.Dispose();
|
|
ClientState.Login -= Configuration.OnLogin;
|
|
ClientState.Logout -= Configuration.OnLogout;
|
|
}
|
|
|
|
private void OnFramework(IFramework framework)
|
|
{
|
|
// check if there's logs to write
|
|
if (LogStream != null && LogStream.ToString() != "")
|
|
{
|
|
var toWrite = LogStream.ToString();
|
|
LogStream.GetStringBuilder().Clear();
|
|
Log.Write(LogEventLevel.Debug, null, toWrite);
|
|
}
|
|
}
|
|
}
|