mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-14 16:27:21 +00:00
Cache resource name => manifest resouce name mapping
This commit is contained in:
parent
133a19a468
commit
7ac1a4c6df
1 changed files with 8 additions and 4 deletions
|
@ -13,6 +13,7 @@ namespace PKHeX.Core
|
|||
private const string TranslationSplitter = " = ";
|
||||
private static Assembly thisAssembly = typeof(Util).GetTypeInfo().Assembly;
|
||||
private static string[] manifestResourceNames = thisAssembly.GetManifestResourceNames();
|
||||
private static Dictionary<string, string> resourceNameMap = new Dictionary<string, string>();
|
||||
private static Dictionary<string, string[]> stringListCache = new Dictionary<string, string[]>();
|
||||
|
||||
|
||||
|
@ -119,15 +120,18 @@ namespace PKHeX.Core
|
|||
|
||||
public static string GetStringResource(string name)
|
||||
{
|
||||
var resourceName = manifestResourceNames
|
||||
if (!resourceNameMap.ContainsKey(name))
|
||||
{
|
||||
resourceNameMap.Add(name, manifestResourceNames
|
||||
.Where(x => x.StartsWith("PKHeX.Core.Resources.text.") && x.EndsWith(name + ".txt", StringComparison.OrdinalIgnoreCase))
|
||||
.FirstOrDefault();
|
||||
.FirstOrDefault());
|
||||
}
|
||||
|
||||
if (resourceName == null) {
|
||||
if (resourceNameMap[name] == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
using (var resource = thisAssembly.GetManifestResourceStream(resourceName))
|
||||
using (var resource = thisAssembly.GetManifestResourceStream(resourceNameMap[name]))
|
||||
using (var reader = new StreamReader(resource))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
|
|
Loading…
Reference in a new issue