mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
refactor: remove need for AssetManager, pass asset dir via StartInfo
This commit is contained in:
parent
79bdf4464e
commit
e27ae3fd0c
6 changed files with 78 additions and 73 deletions
|
|
@ -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,22 +96,7 @@ namespace Dalamud {
|
|||
|
||||
this.ClientState = new ClientState(this, info, this.SigScanner);
|
||||
|
||||
Task.Run(async () => {
|
||||
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);
|
||||
this.LocalizationManager = new Localization(AssetDirectory.FullName);
|
||||
if (!string.IsNullOrEmpty(this.Configuration.LanguageOverride))
|
||||
this.LocalizationManager.SetupWithLangCode(this.Configuration.LanguageOverride);
|
||||
else
|
||||
|
|
@ -120,7 +107,8 @@ namespace Dalamud {
|
|||
DalamudUi = new DalamudInterface(this);
|
||||
|
||||
var isInterfaceLoaded = false;
|
||||
if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false")) {
|
||||
if (!bool.Parse(Environment.GetEnvironmentVariable("DALAMUD_NOT_HAVE_INTERFACE") ?? "false"))
|
||||
{
|
||||
try
|
||||
{
|
||||
InterfaceManager = new InterfaceManager(this, this.SigScanner);
|
||||
|
|
@ -136,9 +124,12 @@ namespace Dalamud {
|
|||
}
|
||||
|
||||
Data = new DataManager(this.StartInfo.Language);
|
||||
try {
|
||||
await Data.Initialize(this.baseDirectory);
|
||||
} catch (Exception e) {
|
||||
try
|
||||
{
|
||||
Data.Initialize(AssetDirectory.FullName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, "Could not initialize DataManager.");
|
||||
Unload();
|
||||
return;
|
||||
|
|
@ -157,7 +148,8 @@ namespace Dalamud {
|
|||
|
||||
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
|
||||
{
|
||||
PluginRepository.CleanupPlugins();
|
||||
|
|
@ -177,7 +169,6 @@ namespace Dalamud {
|
|||
IsReady = true;
|
||||
|
||||
Troubleshooting.LogTroubleshooting(this, isInterfaceLoaded);
|
||||
});
|
||||
}
|
||||
|
||||
public void Start() {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ namespace Dalamud {
|
|||
|
||||
public string PluginDirectory;
|
||||
public string DefaultPluginDirectory;
|
||||
|
||||
public string AssetDirectory;
|
||||
|
||||
public ClientLanguage Language;
|
||||
|
||||
public string GameVersion;
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ namespace Dalamud.Data
|
|||
this.language = language;
|
||||
}
|
||||
|
||||
public async Task Initialize(string baseDir)
|
||||
public void Initialize(string baseDir)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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[]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// </summary>
|
||||
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>
|
||||
/// The CommandManager object that allows you to add and remove custom chat commands.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue