refactor: remove need for AssetManager, pass asset dir via StartInfo

This commit is contained in:
goat 2021-01-16 18:57:16 +01:00
parent 79bdf4464e
commit e27ae3fd0c
6 changed files with 78 additions and 73 deletions

View file

@ -71,6 +71,8 @@ namespace Dalamud {
public bool IsReady { get; private set; } public bool IsReady { get; private set; }
public DirectoryInfo AssetDirectory => new DirectoryInfo(this.StartInfo.AssetDirectory);
public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch) { public Dalamud(DalamudStartInfo info, LoggingLevelSwitch loggingLevelSwitch) {
this.StartInfo = info; this.StartInfo = info;
this.LogLevelSwitch = loggingLevelSwitch; this.LogLevelSwitch = loggingLevelSwitch;
@ -94,90 +96,79 @@ namespace Dalamud {
this.ClientState = new ClientState(this, info, this.SigScanner); this.ClientState = new ClientState(this, info, this.SigScanner);
Task.Run(async () => { this.LocalizationManager = new Localization(AssetDirectory.FullName);
try { if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride))
var res = await AssetManager.EnsureAssets(this.baseDirectory); this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride);
else
this.LocalizationManager.SetupWithUiCulture();
if (!res) { PluginRepository = new PluginRepository(this, this.StartInfo.PluginDirectory, this.StartInfo.GameVersion);
Log.Error("One or more assets failed to download.");
Unload(); DalamudUi = new DalamudInterface(this);
return;
} var isInterfaceLoaded = false;
} catch (Exception e) { if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false"))
Log.Error(e, "Error in asset task."); {
Unload(); try
return; {
InterfaceManager = new InterfaceManager(this, this.SigScanner);
InterfaceManager.OnDraw += DalamudUi.Draw;
InterfaceManager.Enable();
isInterfaceLoaded = true;
} }
catch (Exception e)
this.LocalizationManager = new Localization(this.StartInfo.WorkingDirectory); {
if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride)) Log.Information(e, "Could not init interface.");
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.");
}
} }
}
Data = new DataManager(this.StartInfo.Language); Data = new DataManager(this.StartInfo.Language);
try { try
await Data.Initialize(this.baseDirectory); {
} catch (Exception e) { Data.Initialize(AssetDirectory.FullName);
Log.Error(e, "Could not initialize DataManager."); }
Unload(); catch (Exception e)
return; {
} Log.Error(e, "Could not initialize DataManager.");
Unload();
return;
}
SeStringManager = new SeStringManager(Data); SeStringManager = new SeStringManager(Data);
#if DEBUG #if DEBUG
AntiDebug = new AntiDebug(this.SigScanner); AntiDebug = new AntiDebug(this.SigScanner);
#endif #endif
// Initialize managers. Basically handlers for the logic // Initialize managers. Basically handlers for the logic
CommandManager = new CommandManager(this, info.Language); CommandManager = new CommandManager(this, info.Language);
DalamudCommands = new DalamudCommands(this); DalamudCommands = new DalamudCommands(this);
DalamudCommands.SetupCommands(); DalamudCommands.SetupCommands();
ChatHandlers = new ChatHandlers(this); ChatHandlers = new ChatHandlers(this);
if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false")) { if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_PLUGINS") ?? "false"))
try {
{ try
PluginRepository.CleanupPlugins(); {
PluginRepository.CleanupPlugins();
PluginManager = new PluginManager(this, this.StartInfo.PluginDirectory, this.StartInfo.DefaultPluginDirectory); PluginManager = new PluginManager(this, this.StartInfo.PluginDirectory, this.StartInfo.DefaultPluginDirectory);
PluginManager.LoadPlugins(); PluginManager.LoadPlugins();
}
catch (Exception ex)
{
Log.Error(ex, "Plugin load failed.");
}
} }
catch (Exception ex)
{
Log.Error(ex, "Plugin load failed.");
}
}
this.Framework.Enable(); this.Framework.Enable();
this.ClientState.Enable(); this.ClientState.Enable();
IsReady = true; IsReady = true;
Troubleshooting.LogTroubleshooting(this, isInterfaceLoaded); Troubleshooting.LogTroubleshooting(this, isInterfaceLoaded);
});
} }
public void Start() { public void Start() {

View file

@ -10,6 +10,9 @@ namespace Dalamud {
public string PluginDirectory; public string PluginDirectory;
public string DefaultPluginDirectory; public string DefaultPluginDirectory;
public string AssetDirectory;
public ClientLanguage Language; public ClientLanguage Language;
public string GameVersion; public string GameVersion;

View file

@ -61,7 +61,7 @@ namespace Dalamud.Data
this.language = language; this.language = language;
} }
public async Task Initialize(string baseDir) public void Initialize(string baseDir)
{ {
try try
{ {

View file

@ -334,7 +334,7 @@ namespace Dalamud.Interface
public void OpenCredits() { public void OpenCredits() {
var logoGraphic = var logoGraphic =
this.dalamud.InterfaceManager.LoadImage( 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.creditsWindow = new DalamudCreditsWindow(this.dalamud, logoGraphic, this.dalamud.Framework);
this.isImguiDrawCreditsWindow = true; this.isImguiDrawCreditsWindow = true;
} }

View file

@ -274,13 +274,13 @@ namespace Dalamud.Interface
fontConfig.MergeMode = true; fontConfig.MergeMode = true;
fontConfig.PixelSnapH = 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); var japaneseRangeHandle = GCHandle.Alloc(GlyphRangesJapanese.GlyphRanges, GCHandleType.Pinned);
DefaultFont = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathJp, 17.0f, null, japaneseRangeHandle.AddrOfPinnedObject()); 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[] var gameRangeHandle = GCHandle.Alloc(new ushort[]
{ {
@ -291,7 +291,7 @@ namespace Dalamud.Interface
ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPathGame, 17.0f, fontConfig, gameRangeHandle.AddrOfPinnedObject()); 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[] var iconRangeHandle = GCHandle.Alloc(new ushort[]
{ {

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Dynamic; using System.Dynamic;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -28,6 +29,16 @@ namespace Dalamud.Plugin
/// </summary> /// </summary>
public PluginLoadReason Reason { get; } public PluginLoadReason Reason { get; }
/// <summary>
/// Get the directory Dalamud assets are stored in.
/// </summary>
public DirectoryInfo DalamudAssetDirectory => this.dalamud.AssetDirectory;
/// <summary>
/// Get the directory your plugin configurations are stored in.
/// </summary>
public DirectoryInfo ConfigDirectory => new DirectoryInfo(GetPluginConfigDirectory());
/// <summary> /// <summary>
/// The CommandManager object that allows you to add and remove custom chat commands. /// The CommandManager object that allows you to add and remove custom chat commands.
/// </summary> /// </summary>