mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 14:38:34 +01:00
Fixed some content readers not being tried for RawContentManager
This commit is contained in:
parent
df5a654500
commit
2342eb093a
2 changed files with 18 additions and 22 deletions
|
@ -4,7 +4,7 @@ using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace MLEM.Data.Content {
|
namespace MLEM.Data.Content {
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public class RawJsonReader : RawContentReader {
|
public class JsonReader : RawContentReader {
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool CanRead(Type t) {
|
public override bool CanRead(Type t) {
|
|
@ -49,35 +49,31 @@ namespace MLEM.Data.Content {
|
||||||
return this.Read<T>(assetName, default);
|
return this.Read<T>(assetName, default);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RawContentReader GetReader<T>() {
|
|
||||||
var reader = Readers.FirstOrDefault(r => r.CanRead(typeof(T)));
|
|
||||||
if (reader == null)
|
|
||||||
throw new ContentLoadException($"{typeof(T)} has no RawContentReader");
|
|
||||||
return reader;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override void ReloadAsset<T>(string originalAssetName, T currentAsset) {
|
protected override void ReloadAsset<T>(string originalAssetName, T currentAsset) {
|
||||||
this.Read(originalAssetName, currentAsset);
|
this.Read(originalAssetName, currentAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private T Read<T>(string assetName, T existing) {
|
private T Read<T>(string assetName, T existing) {
|
||||||
var reader = GetReader<T>();
|
var triedFiles = new List<string>();
|
||||||
foreach (var ext in reader.GetFileExtensions()) {
|
foreach (var reader in Readers.Where(r => r.CanRead(typeof(T)))) {
|
||||||
var file = new FileInfo(Path.Combine(this.RootDirectory, $"{assetName}.{ext}"));
|
foreach (var ext in reader.GetFileExtensions()) {
|
||||||
if (!file.Exists)
|
var file = Path.Combine(this.RootDirectory, $"{assetName}.{ext}");
|
||||||
continue;
|
triedFiles.Add(file);
|
||||||
using (var stream = file.OpenRead()) {
|
if (!File.Exists(file))
|
||||||
var read = reader.Read(this, assetName, stream, typeof(T), existing);
|
continue;
|
||||||
if (!(read is T t))
|
using (var stream = File.OpenRead(file)) {
|
||||||
throw new ContentLoadException($"{reader} returned non-{typeof(T)} for asset {assetName}");
|
var read = reader.Read(this, assetName, stream, typeof(T), existing);
|
||||||
this.LoadedAssets[assetName] = t;
|
if (!(read is T t))
|
||||||
if (t is IDisposable d && !this.disposableAssets.Contains(d))
|
throw new ContentLoadException($"{reader} returned non-{typeof(T)} for asset {assetName}");
|
||||||
this.disposableAssets.Add(d);
|
this.LoadedAssets[assetName] = t;
|
||||||
return t;
|
if (t is IDisposable d && !this.disposableAssets.Contains(d))
|
||||||
|
this.disposableAssets.Add(d);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new ContentLoadException($"Asset {assetName} not found");
|
throw new ContentLoadException($"Asset {assetName} not found. Tried files {string.Join(", ", triedFiles)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
Loading…
Reference in a new issue