Handle missing files without hard failure

Also adds support for lookups with file extensions
This commit is contained in:
Dean Herbert 2018-03-14 18:42:13 +09:00
parent 62e908e22c
commit 8e52d91180
1 changed files with 13 additions and 3 deletions

View File

@ -60,10 +60,12 @@ private class LegacySkinResourceStore : IResourceStore<byte[]>
private string getPathForFile(string filename)
{
bool hasExtension = filename.Contains('.');
string lastPiece = filename.Split('/').Last();
var file = skin.Files.FirstOrDefault(f =>
string.Equals(Path.GetFileNameWithoutExtension(f.Filename), lastPiece, StringComparison.InvariantCultureIgnoreCase));
string.Equals(hasExtension ? f.Filename : Path.GetFileNameWithoutExtension(f.Filename), lastPiece, StringComparison.InvariantCultureIgnoreCase));
return file?.FileInfo.StoragePath;
}
@ -73,9 +75,17 @@ public LegacySkinResourceStore(SkinInfo skin, IResourceStore<byte[]> underlyingS
this.underlyingStore = underlyingStore;
}
public Stream GetStream(string name) => underlyingStore.GetStream(getPathForFile(name));
public Stream GetStream(string name)
{
string path = getPathForFile(name);
return path == null ? null : underlyingStore.GetStream(path);
}
byte[] IResourceStore<byte[]>.Get(string name) => underlyingStore.Get(getPathForFile(name));
byte[] IResourceStore<byte[]>.Get(string name)
{
string path = getPathForFile(name);
return path == null ? null : underlyingStore.Get(path);
}
}
}
}