summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Constants.cs44
2 files changed, 44 insertions, 1 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 4cbd1ad9..2448995e 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -7,6 +7,7 @@
* Fixed `player_add` console command's handling of Journal Scraps and Secret Notes.
* For mod authors:
+ * Added `Constants.ContentPath`.
* Added `IAssetName Name` field to the info received by `IAssetEditor` and `IAssetLoader` methods.
_This adds methods for working with asset names, parsed locales, etc._
* Fixed the `SDate` constructor being case-sensitive.
diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs
index 810dfe48..b736ca59 100644
--- a/src/SMAPI/Constants.cs
+++ b/src/SMAPI/Constants.cs
@@ -83,6 +83,9 @@ namespace StardewModdingAPI
/// <summary>The path to the game folder.</summary>
public static string GamePath { get; } = EarlyConstants.GamePath;
+ /// <summary>The path to the game's <c>Content</c> folder.</summary>
+ public static string ContentPath { get; } = Constants.GetContentFolderPath();
+
/// <summary>The directory path containing Stardew Valley's app data.</summary>
public static string DataPath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley");
@@ -297,13 +300,52 @@ namespace StardewModdingAPI
/*********
** Private methods
*********/
+ /// <summary>Get the absolute path to the game's <c>Content</c> folder.</summary>
+ private static string GetContentFolderPath()
+ {
+ //
+ // We can't use Path.Combine(Constants.GamePath, Game1.content.RootDirectory) here,
+ // since Game1.content isn't initialized until later in the game startup.
+ //
+
+ string gamePath = EarlyConstants.GamePath;
+
+ // most platforms
+ if (EarlyConstants.Platform != GamePlatform.Mac)
+ return Path.Combine(gamePath, "Content");
+
+ // macOS
+ string[] paths = new[]
+ {
+ // GOG
+ // - game: Stardew Valley.app/Contents/MacOS
+ // - content: Stardew Valley.app/Resources/Content
+ "../../Resources/Content",
+
+ // Steam
+ // - game: StardewValley/Contents/MacOS
+ // - content: StardewValley/Contents/Resources/Content
+ "../Resources/Content"
+ }
+ .Select(path => Path.GetFullPath(Path.Combine(gamePath, path)))
+ .ToArray();
+
+ foreach (string path in paths)
+ {
+ if (Directory.Exists(path))
+ return path;
+ }
+
+ return paths.Last();
+ }
+
/// <summary>Get the name of the save folder, if any.</summary>
private static string GetSaveFolderName()
{
return Constants.GetSaveFolder()?.Name;
}
- /// <summary>Get the path to the current save folder, if any.</summary>
+ /// <summary>Get the absolute path to the current save folder, if any.</summary>
private static string GetSaveFolderPathIfExists()
{
DirectoryInfo saveFolder = Constants.GetSaveFolder();