From e27ae3fd0ccb2a3699d321b5f5628d6350903f4a Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sat, 16 Jan 2021 18:57:16 +0100 Subject: [PATCH] refactor: remove need for AssetManager, pass asset dir via StartInfo --- Dalamud/Dalamud.cs | 127 +++++++++++------------ Dalamud/DalamudStartInfo.cs | 3 + Dalamud/Data/DataManager.cs | 2 +- Dalamud/Interface/DalamudInterface.cs | 2 +- Dalamud/Interface/InterfaceManager.cs | 6 +- Dalamud/Plugin/DalamudPluginInterface.cs | 11 ++ 6 files changed, 78 insertions(+), 73 deletions(-) diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index d55169185..0d6eb0f77 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -71,6 +71,8 @@ namespace Dalamud { public bool IsReady { get; private set; } + public DirectoryInfo AssetDirectory => new DirectoryInfo(this.StartInfo.AssetDirectory); + public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch) { this.StartInfo = info; this.LogLevelSwitch = loggingLevelSwitch; @@ -94,90 +96,79 @@ namespace Dalamud { this.ClientState = new ClientState(this, info, this.SigScanner); - Task.Run(async () => { - try { - var res = await AssetManager.EnsureAssets(this.baseDirectory); + this.LocalizationManager = new Localization(AssetDirectory.FullName); + if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride)) + this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride); + else + this.LocalizationManager.SetupWithUiCulture(); - if (!res) { - Log.Error("One or more assets failed to download."); - Unload(); - return; - } - } catch (Exception e) { - Log.Error(e, "Error in asset task."); - Unload(); - return; + PluginRepository = new PluginRepository(this, this.StartInfo.PluginDirectory, this.StartInfo.GameVersion); + + DalamudUi = new DalamudInterface(this); + + var isInterfaceLoaded = false; + if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false")) + { + try + { + InterfaceManager = new InterfaceManager(this, this.SigScanner); + InterfaceManager.OnDraw += DalamudUi.Draw; + + InterfaceManager.Enable(); + isInterfaceLoaded = true; } - - this.LocalizationManager = new Localization(this.StartInfo.WorkingDirectory); - if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride)) - this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride); - else - this.LocalizationManager.SetupWithUiCulture(); - - PluginRepository = new PluginRepository(this, this.StartInfo.PluginDirectory, this.StartInfo.GameVersion); - - DalamudUi = new DalamudInterface(this); - - var isInterfaceLoaded = false; - if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false")) { - try - { - InterfaceManager = new InterfaceManager(this, this.SigScanner); - InterfaceManager.OnDraw += DalamudUi.Draw; - - InterfaceManager.Enable(); - isInterfaceLoaded = true; - } - catch (Exception e) - { - Log.Information(e, "Could not init interface."); - } + catch (Exception e) + { + Log.Information(e, "Could not init interface."); } + } - Data = new DataManager(this.StartInfo.Language); - try { - await Data.Initialize(this.baseDirectory); - } catch (Exception e) { - Log.Error(e, "Could not initialize DataManager."); - Unload(); - return; - } + Data = new DataManager(this.StartInfo.Language); + try + { + Data.Initialize(AssetDirectory.FullName); + } + catch (Exception e) + { + Log.Error(e, "Could not initialize DataManager."); + Unload(); + return; + } - SeStringManager = new SeStringManager(Data); + SeStringManager = new SeStringManager(Data); #if DEBUG - AntiDebug = new AntiDebug(this.SigScanner); + AntiDebug = new AntiDebug(this.SigScanner); #endif - // Initialize managers. Basically handlers for the logic - CommandManager = new CommandManager(this, info.Language); - DalamudCommands = new DalamudCommands(this); - DalamudCommands.SetupCommands(); + // Initialize managers. Basically handlers for the logic + CommandManager = new CommandManager(this, info.Language); + DalamudCommands = new DalamudCommands(this); + DalamudCommands.SetupCommands(); - ChatHandlers = new ChatHandlers(this); + ChatHandlers = new ChatHandlers(this); - if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false")) { - try - { - PluginRepository.CleanupPlugins(); + if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false")) + { + try + { + PluginRepository.CleanupPlugins(); - PluginManager = new PluginManager(this, this.StartInfo.PluginDirectory, this.StartInfo.DefaultPluginDirectory); - PluginManager.LoadPlugins(); - } - catch (Exception ex) - { - Log.Error(ex, "Plugin load failed."); - } + PluginManager = new PluginManager(this, this.StartInfo.PluginDirectory, this.StartInfo.DefaultPluginDirectory); + PluginManager.LoadPlugins(); } + catch (Exception ex) + { + Log.Error(ex, "Plugin load failed."); + } + } - this.Framework.Enable(); - this.ClientState.Enable(); + this.Framework.Enable(); + this.ClientState.Enable(); - IsReady = true; + IsReady = true; - Troubleshooting.LogTroubleshooting(this, isInterfaceLoaded); - }); + Troubleshooting.LogTroubleshooting(this, isInterfaceLoaded); } public void Start() { diff --git a/Dalamud/DalamudStartInfo.cs b/Dalamud/DalamudStartInfo.cs index 4e40beef0..80b77d71c 100644 --- a/Dalamud/DalamudStartInfo.cs +++ b/Dalamud/DalamudStartInfo.cs @@ -10,6 +10,9 @@ namespace Dalamud { public string PluginDirectory; public string DefaultPluginDirectory; + + public string AssetDirectory; + public ClientLanguage Language; public string GameVersion; diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs index 2e5da30b1..db15a8ba7 100644 --- a/Dalamud/Data/DataManager.cs +++ b/Dalamud/Data/DataManager.cs @@ -61,7 +61,7 @@ namespace Dalamud.Data this.language = language; } - public async Task Initialize(string baseDir) + public void Initialize(string baseDir) { try { diff --git a/Dalamud/Interface/DalamudInterface.cs b/Dalamud/Interface/DalamudInterface.cs index 668e56083..eb51b9b25 100644 --- a/Dalamud/Interface/DalamudInterface.cs +++ b/Dalamud/Interface/DalamudInterface.cs @@ -334,7 +334,7 @@ namespace Dalamud.Interface public void OpenCredits() { var logoGraphic = this.dalamud.InterfaceManager.LoadImage( - Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "UIRes", "logo.png")); + Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "logo.png")); this.creditsWindow = new DalamudCreditsWindow(this.dalamud, logoGraphic, this.dalamud.Framework); this.isImguiDrawCreditsWindow = true; } diff --git a/Dalamud/Interface/InterfaceManager.cs b/Dalamud/Interface/InterfaceManager.cs index 51c0da80b..a36328f27 100644 --- a/Dalamud/Interface/InterfaceManager.cs +++ b/Dalamud/Interface/InterfaceManager.cs @@ -274,13 +274,13 @@ namespace Dalamud.Interface fontConfig.MergeMode = true; fontConfig.PixelSnapH = true; - var fontPathJp = Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "UIRes", "NotoSansCJKjp-Medium.otf"); + var fontPathJp = Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "NotoSansCJKjp-Medium.otf"); var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned); DefaultFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathJp, 17.0f, null, japaneseRangeHandle.AddrOfPinnedObject()); - var fontPathGame = Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "UIRes", "gamesym.ttf"); + var fontPathGame = Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "gamesym.ttf"); var gameRangeHandle = GCHandle.Alloc(new ushort[] { @@ -291,7 +291,7 @@ namespace Dalamud.Interface ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathGame, 17.0f, fontConfig, gameRangeHandle.AddrOfPinnedObject()); - var fontPathIcon = Path.Combine(this.dalamud.StartInfo.WorkingDirectory, "UIRes", "FontAwesome5FreeSolid.otf"); + var fontPathIcon = Path.Combine(this.dalamud.AssetDirectory.FullName, "UIRes", "FontAwesome5FreeSolid.otf"); var iconRangeHandle = GCHandle.Alloc(new ushort[] { diff --git a/Dalamud/Plugin/DalamudPluginInterface.cs b/Dalamud/Plugin/DalamudPluginInterface.cs index f0d2d33b8..9028e462c 100644 --- a/Dalamud/Plugin/DalamudPluginInterface.cs +++ b/Dalamud/Plugin/DalamudPluginInterface.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Dynamic; +using System.IO; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; @@ -28,6 +29,16 @@ namespace Dalamud.Plugin /// public PluginLoadReason Reason { get; } + /// + /// Get the directory Dalamud assets are stored in. + /// + public DirectoryInfo DalamudAssetDirectory => this.dalamud.AssetDirectory; + + /// + /// Get the directory your plugin configurations are stored in. + /// + public DirectoryInfo ConfigDirectory => new DirectoryInfo(GetPluginConfigDirectory()); + /// /// The CommandManager object that allows you to add and remove custom chat commands. ///