mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58: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,25 +49,20 @@ 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 reader in Readers.Where(r => r.CanRead(typeof(T)))) {
|
||||||
foreach (var ext in reader.GetFileExtensions()) {
|
foreach (var ext in reader.GetFileExtensions()) {
|
||||||
var file = new FileInfo(Path.Combine(this.RootDirectory, $"{assetName}.{ext}"));
|
var file = Path.Combine(this.RootDirectory, $"{assetName}.{ext}");
|
||||||
if (!file.Exists)
|
triedFiles.Add(file);
|
||||||
|
if (!File.Exists(file))
|
||||||
continue;
|
continue;
|
||||||
using (var stream = file.OpenRead()) {
|
using (var stream = File.OpenRead(file)) {
|
||||||
var read = reader.Read(this, assetName, stream, typeof(T), existing);
|
var read = reader.Read(this, assetName, stream, typeof(T), existing);
|
||||||
if (!(read is T t))
|
if (!(read is T t))
|
||||||
throw new ContentLoadException($"{reader} returned non-{typeof(T)} for asset {assetName}");
|
throw new ContentLoadException($"{reader} returned non-{typeof(T)} for asset {assetName}");
|
||||||
|
@ -77,7 +72,8 @@ namespace MLEM.Data.Content {
|
||||||
return t;
|
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