diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-09-18 13:08:38 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-09-18 13:08:38 -0400 |
commit | ebe41180c41f544919c03fb3bf6029437a7d65a4 (patch) | |
tree | 0c5c0602bbee1fc96a024f3be1cd225d72d37fa0 /src/SMAPI/Framework/ContentManagers | |
parent | c5b8cd626489dad6210fe629658314dfc85f4d08 (diff) | |
parent | 6643da4574bec2d71ac9c25a2c9ab15b8c855e2b (diff) | |
download | SMAPI-ebe41180c41f544919c03fb3bf6029437a7d65a4.tar.gz SMAPI-ebe41180c41f544919c03fb3bf6029437a7d65a4.tar.bz2 SMAPI-ebe41180c41f544919c03fb3bf6029437a7d65a4.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/ContentManagers')
-rw-r--r-- | src/SMAPI/Framework/ContentManagers/GameContentManager.cs | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs index 63cd1759..38bcf153 100644 --- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.IO; using System.Linq; using System.Reflection; using Microsoft.Xna.Framework.Content; @@ -205,28 +206,35 @@ namespace StardewModdingAPI.Framework.ContentManagers /// <remarks>Derived from <see cref="LocalizedContentManager.Load{T}(string, LocalizedContentManager.LanguageCode)"/>.</remarks> private T RawLoad<T>(string assetName, LanguageCode language, bool useCache) { - // use cached key - if (language == this.Language && this.LocalizedAssetNames.TryGetValue(assetName, out string cachedKey)) - return base.RawLoad<T>(cachedKey, useCache); - - // try translated key - if (language != LocalizedContentManager.LanguageCode.en) + try { - string translatedKey = $"{assetName}.{this.GetLocale(language)}"; - try - { - T obj = base.RawLoad<T>(translatedKey, useCache); - this.LocalizedAssetNames[assetName] = translatedKey; - return obj; - } - catch (ContentLoadException) + // use cached key + if (language == this.Language && this.LocalizedAssetNames.TryGetValue(assetName, out string cachedKey)) + return base.RawLoad<T>(cachedKey, useCache); + + // try translated key + if (language != LocalizedContentManager.LanguageCode.en) { - this.LocalizedAssetNames[assetName] = assetName; + string translatedKey = $"{assetName}.{this.GetLocale(language)}"; + try + { + T obj = base.RawLoad<T>(translatedKey, useCache); + this.LocalizedAssetNames[assetName] = translatedKey; + return obj; + } + catch (ContentLoadException) + { + this.LocalizedAssetNames[assetName] = assetName; + } } - } - // try base asset - return base.RawLoad<T>(assetName, useCache); + // try base asset + return base.RawLoad<T>(assetName, useCache); + } + catch (ContentLoadException ex) when (ex.InnerException is FileNotFoundException innerEx && innerEx.InnerException == null) + { + throw new SContentLoadException($"Error loading \"{assetName}\": it isn't in the Content folder and no mod provided it."); + } } /// <summary>Parse an asset key that contains an explicit language into its asset name and language, if applicable.</summary> |