Add error handlings for UldWidget (#2011)

* Add error handlings for UldWidget

* fixes
This commit is contained in:
srkizer 2024-08-14 00:45:00 +09:00 committed by GitHub
parent 7e0c97f59e
commit cddad72066
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 444 additions and 213 deletions

View file

@ -1,5 +1,6 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Game;
using Dalamud.IoC;
@ -148,6 +149,16 @@ internal sealed class DataManager : IInternalDisposableService, IDataManager
return this.GameData.Repositories.TryGetValue(filePath.Repository, out var repository) ? repository.GetFile<T>(filePath.Category, filePath) : default;
}
/// <inheritdoc/>
public Task<T> GetFileAsync<T>(string path, CancellationToken cancellationToken) where T : FileResource =>
GameData.ParseFilePath(path) is { } filePath &&
this.GameData.Repositories.TryGetValue(filePath.Repository, out var repository)
? Task.Run(
() => repository.GetFile<T>(filePath.Category, filePath) ?? throw new FileNotFoundException(
"Failed to load file, most likely because the file could not be found."),
cancellationToken)
: Task.FromException<T>(new FileNotFoundException("The file could not be found."));
/// <inheritdoc/>
public bool FileExists(string path)
=> this.GameData.FileExists(path);