diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-08-23 18:45:04 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2020-08-23 18:51:01 -0400 |
commit | 76c926c396092f02441a62937bfc5d437e582e57 (patch) | |
tree | d3a673ac8681378f9d4a1dd5737540a611570378 /src/SMAPI.Toolkit/Utilities | |
parent | 625c41c0ea39bb2af37ece7865098cf2f6d38471 (diff) | |
download | SMAPI-76c926c396092f02441a62937bfc5d437e582e57.tar.gz SMAPI-76c926c396092f02441a62937bfc5d437e582e57.tar.bz2 SMAPI-76c926c396092f02441a62937bfc5d437e582e57.zip |
add EarlyConstants for constants needed before external DLLs are loaded
Diffstat (limited to 'src/SMAPI.Toolkit/Utilities')
-rw-r--r-- | src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs b/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs new file mode 100644 index 00000000..4ef578f7 --- /dev/null +++ b/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs @@ -0,0 +1,57 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using StardewModdingAPI.Toolkit.Framework; + +namespace StardewModdingAPI.Toolkit.Utilities +{ + /// <summary>Provides methods for fetching environment information.</summary> + public static class EnvironmentUtility + { + /********* + ** Fields + *********/ + /// <summary>The cached platform.</summary> + private static Platform? CachedPlatform; + + + /********* + ** Public methods + *********/ + /// <summary>Detect the current OS.</summary> + public static Platform DetectPlatform() + { + Platform? platform = EnvironmentUtility.CachedPlatform; + + if (platform == null) + { + string rawPlatform = LowLevelEnvironmentUtility.DetectPlatform(); + EnvironmentUtility.CachedPlatform = platform = (Platform)Enum.Parse(typeof(Platform), rawPlatform, ignoreCase: true); + } + + return platform.Value; + } + + + /// <summary>Get the human-readable OS name and version.</summary> + /// <param name="platform">The current platform.</param> + [SuppressMessage("ReSharper", "EmptyGeneralCatchClause", Justification = "Error suppressed deliberately to fallback to default behaviour.")] + public static string GetFriendlyPlatformName(Platform platform) + { + return LowLevelEnvironmentUtility.GetFriendlyPlatformName(platform.ToString()); + } + + /// <summary>Get the name of the Stardew Valley executable.</summary> + /// <param name="platform">The current platform.</param> + public static string GetExecutableName(Platform platform) + { + return LowLevelEnvironmentUtility.GetExecutableName(platform.ToString()); + } + + /// <summary>Get whether the platform uses Mono.</summary> + /// <param name="platform">The current platform.</param> + public static bool IsMono(this Platform platform) + { + return LowLevelEnvironmentUtility.IsMono(platform.ToString()); + } + } +} |