summaryrefslogtreecommitdiff
path: root/src/SMAPI/Constants.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-02-19 11:26:24 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-02-19 11:26:24 -0500
commit3c29ae6a1e77ba098b4d9421cacb0fc37510227c (patch)
treead6a586a812ef77d215f2d0e7599e0ffc21ce968 /src/SMAPI/Constants.cs
parent2d52681b1034d314d8d56c561a5aa72e54e34576 (diff)
downloadSMAPI-3c29ae6a1e77ba098b4d9421cacb0fc37510227c.tar.gz
SMAPI-3c29ae6a1e77ba098b4d9421cacb0fc37510227c.tar.bz2
SMAPI-3c29ae6a1e77ba098b4d9421cacb0fc37510227c.zip
add Constants.ContentPath
Diffstat (limited to 'src/SMAPI/Constants.cs')
-rw-r--r--src/SMAPI/Constants.cs44
1 files changed, 43 insertions, 1 deletions
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();