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,22 +96,7 @@ 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 {
var res = await AssetManager.EnsureAssets(this.baseDirectory);
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;
}
this.LocalizationManager = new Localization(this.StartInfo.WorkingDirectory);
if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride)) if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride))
this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride); this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride);
else else
@ -120,7 +107,8 @@ namespace Dalamud {
DalamudUi = new DalamudInterface(this); DalamudUi = new DalamudInterface(this);
var isInterfaceLoaded = false; var isInterfaceLoaded = false;
if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false")) { if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false"))
{
try try
{ {
InterfaceManager = new InterfaceManager(this, this.SigScanner); InterfaceManager = new InterfaceManager(this, this.SigScanner);
@ -136,9 +124,12 @@ namespace Dalamud {
} }
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);
}
catch (Exception e)
{
Log.Error(e, "Could not initialize DataManager."); Log.Error(e, "Could not initialize DataManager.");
Unload(); Unload();
return; return;
@ -157,7 +148,8 @@ namespace Dalamud {
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();
@ -177,7 +169,6 @@ namespace Dalamud {
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>