summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-09-18 11:48:20 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-09-18 11:48:20 -0400
commit8a117744608dfff970855defbffb1f40466ab755 (patch)
tree961b8b7d4632073c8fac554ff8d1b0a771e7c65f
parent54a7c1f9bde0f98d9f81aa9dcd7bd4c18e409877 (diff)
downloadSMAPI-8a117744608dfff970855defbffb1f40466ab755.tar.gz
SMAPI-8a117744608dfff970855defbffb1f40466ab755.tar.bz2
SMAPI-8a117744608dfff970855defbffb1f40466ab755.zip
add simpler error when an asset isn't found
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Framework/ContentManagers/GameContentManager.cs44
2 files changed, 27 insertions, 18 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index ab120994..f330c677 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -4,6 +4,7 @@
## Upcoming release
* For players:
* Added more progress updates in the log during startup.
+ * Simplified common asset load error message.
* Fixed crash loading mods with corrupted translation files.
* For mod authors:
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>