mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-11 02:24:36 +01:00
Less footguns in service dependency handling (#1560)
This commit is contained in:
parent
5777745ab3
commit
a0f4baf8fa
23 changed files with 659 additions and 302 deletions
|
|
@ -44,7 +44,10 @@ internal sealed class DalamudAssetManager : IServiceType, IDisposable, IDalamudA
|
|||
private bool isDisposed;
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
private DalamudAssetManager(Dalamud dalamud, HappyHttpClient httpClient)
|
||||
private DalamudAssetManager(
|
||||
Dalamud dalamud,
|
||||
HappyHttpClient httpClient,
|
||||
ServiceManager.RegisterStartupBlockerDelegate registerStartupBlocker)
|
||||
{
|
||||
this.dalamud = dalamud;
|
||||
this.httpClient = httpClient;
|
||||
|
|
@ -55,8 +58,17 @@ internal sealed class DalamudAssetManager : IServiceType, IDisposable, IDalamudA
|
|||
this.fileStreams = Enum.GetValues<DalamudAsset>().ToDictionary(x => x, _ => (Task<FileStream>?)null);
|
||||
this.textureWraps = Enum.GetValues<DalamudAsset>().ToDictionary(x => x, _ => (Task<IDalamudTextureWrap>?)null);
|
||||
|
||||
// Block until all the required assets to be ready.
|
||||
var loadTimings = Timings.Start("DAM LoadAll");
|
||||
this.WaitForAllRequiredAssets().ContinueWith(_ => loadTimings.Dispose());
|
||||
registerStartupBlocker(
|
||||
Task.WhenAll(
|
||||
Enum.GetValues<DalamudAsset>()
|
||||
.Where(x => x is not DalamudAsset.Empty4X4)
|
||||
.Where(x => x.GetAttribute<DalamudAssetAttribute>()?.Required is true)
|
||||
.Select(this.CreateStreamAsync)
|
||||
.Select(x => x.ToContentDisposedTask()))
|
||||
.ContinueWith(_ => loadTimings.Dispose()),
|
||||
"Prevent Dalamud from loading more stuff, until we've ensured that all required assets are available.");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -83,25 +95,6 @@ internal sealed class DalamudAssetManager : IServiceType, IDisposable, IDalamudA
|
|||
this.scopedFinalizer.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Waits for all the required assets to be ready. Will result in a faulted task, if any of the required assets
|
||||
/// has failed to load.
|
||||
/// </summary>
|
||||
/// <returns>The task.</returns>
|
||||
[Pure]
|
||||
public Task WaitForAllRequiredAssets()
|
||||
{
|
||||
lock (this.syncRoot)
|
||||
{
|
||||
return Task.WhenAll(
|
||||
Enum.GetValues<DalamudAsset>()
|
||||
.Where(x => x is not DalamudAsset.Empty4X4)
|
||||
.Where(x => x.GetAttribute<DalamudAssetAttribute>()?.Required is true)
|
||||
.Select(this.CreateStreamAsync)
|
||||
.Select(x => x.ToContentDisposedTask()));
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
[Pure]
|
||||
public bool IsStreamImmediatelyAvailable(DalamudAsset asset) =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue