/// <summary> /// Initializes a new instance of the <see cref="PlayerTrackPlugin"/> class. /// </summary> public PlayerTrackPlugin() { Task.Run(() => { try { // setup common libs this.localization = new Localization(PluginInterface, CommandManager); this.BackupManager = new BackupManager(PluginInterface.GetPluginConfigDirectory()); this.XivCommon = new XivCommonBase(Hooks.NamePlates); // load config try { this.Configuration = PluginInterface.GetPluginConfig() as PlayerTrackConfig ?? new PlayerTrackConfig(); } catch (Exception ex) { Logger.LogError("Failed to load config so creating new one.", ex); this.Configuration = new PlayerTrackConfig(); this.SaveConfig(); } // setup services this.BaseRepository = new BaseRepository(GetPluginFolder()); this.LodestoneService = new LodestoneService(this); this.ActorManager = new ActorManager(this); this.CategoryService = new CategoryService(this); this.EncounterService = new EncounterService(this); this.PlayerService = new PlayerService(this); this.VisibilityService = new VisibilityService(this); this.FCNameColorService = new FCNameColorService(this); this.PlayerTrackProvider = new PlayerTrackProvider(PluginInterface, new PlayerTrackAPI(this)); this.WindowManager = new WindowManager(this); this.PluginCommandManager = new PluginCommandManager(this); this.NamePlateManager = new NamePlateManager(this); // run backup this.backupTimer = new Timer { Interval = this.Configuration.BackupFrequency, Enabled = false }; this.backupTimer.Elapsed += this.BackupTimerOnElapsed; var pluginVersion = Assembly.GetExecutingAssembly().VersionNumber(); if (this.Configuration.PluginVersion < pluginVersion) { Logger.LogInfo("Running backup since new version detected."); this.RunUpgradeBackup(); this.Configuration.PluginVersion = pluginVersion; this.SaveConfig(); } else { this.BackupTimerOnElapsed(this, null); } // migrate if needed var success = Migrator.Migrate(this); if (success) { // special handling for fresh install this.HandleFreshInstall(); // reset categories if failed to load if (this.CategoryService.GetCategories().Length == 0) { this.CategoryService.ResetCategories(); } // start plugin this.IsDoneLoading = true; this.backupTimer.Enabled = true; this.VisibilityService.Start(); this.FCNameColorService.Start(); this.ActorManager.Start(); this.WindowManager.AddWindows(); } } catch (Exception ex) { Logger.LogError(ex, "Failed to initialize plugin."); } }); }