diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-04-14 00:18:19 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-04-14 00:18:19 -0400 |
commit | 6d269621b28240a0da6de5fd5faa4c35553c15bb (patch) | |
tree | 9600d94e2a4b3c5f73888db008213342d1f55586 | |
parent | 0d5278a270a0d51baefe99cf908f532a66489602 (diff) | |
download | SMAPI-6d269621b28240a0da6de5fd5faa4c35553c15bb.tar.gz SMAPI-6d269621b28240a0da6de5fd5faa4c35553c15bb.tar.bz2 SMAPI-6d269621b28240a0da6de5fd5faa4c35553c15bb.zip |
make crossplatform handling more consistent
-rw-r--r-- | docs/release-notes.md | 3 | ||||
-rw-r--r-- | src/SMAPI.Common/EnvironmentUtility.cs | 15 | ||||
-rw-r--r-- | src/SMAPI.Installer/InteractiveInstaller.cs | 21 |
3 files changed, 25 insertions, 14 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index 9ae1d2c4..f3e9af6f 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -14,7 +14,8 @@ * Fixed issue where assets didn't reload correctly when the player switches language. * For SMAPI developers: - * Added MacOS detection to `Constants.Platform`. + * Added more consistent crossplatform handling using a new `EnvironmentUtility`. + * Added MacOS detection. * Added prerelease versions to the mod update-check API response where available (GitHub only). * Added support for beta releases on the home page. * Split mod DB out of `StardewModdingAPI.config.json`, so we can load config earlier and reduce unnecessary memory usage later. diff --git a/src/SMAPI.Common/EnvironmentUtility.cs b/src/SMAPI.Common/EnvironmentUtility.cs index b8a6d775..9d9e91e6 100644 --- a/src/SMAPI.Common/EnvironmentUtility.cs +++ b/src/SMAPI.Common/EnvironmentUtility.cs @@ -61,6 +61,21 @@ namespace StardewModdingAPI.Common return (platform == Platform.Mac ? "MacOS " : "") + Environment.OSVersion; } + /// <summary>Get the name of the Stardew Valley executable.</summary> + /// <param name="platform">The current platform.</param> + public static string GetExecutableName(Platform platform) + { + return platform == Platform.Windows + ? "Stardew Valley.exe" + : "StardewValley.exe"; + } + + /// <summary>Get whether the platform uses Mono.</summary> + /// <param name="platform">The current platform.</param> + public static bool IsMono(this Platform platform) + { + return platform == Platform.Linux || platform == Platform.Mac; + } /********* ** Private methods diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index 01076573..0d602b57 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -142,7 +142,7 @@ namespace StardewModdingApi.Installer ** Get platform & set window title ****/ Platform platform = EnvironmentUtility.DetectPlatform(); - Console.Title = $"SMAPI {new SemanticVersionImpl(this.GetType().Assembly.GetName().Version)} installer on {platform}"; + Console.Title = $"SMAPI {new SemanticVersionImpl(this.GetType().Assembly.GetName().Version)} installer on {platform} {EnvironmentUtility.GetFriendlyPlatformName(platform)}"; Console.WriteLine(); /**** @@ -179,11 +179,11 @@ namespace StardewModdingApi.Installer } // get folders - DirectoryInfo packageDir = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "internal", platform.ToString())); + DirectoryInfo packageDir = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "internal", platform.IsMono() ? "Mono" : "Windows")); DirectoryInfo modsDir = new DirectoryInfo(Path.Combine(installDir.FullName, "Mods")); var paths = new { - executable = Path.Combine(installDir.FullName, platform == Platform.Windows ? "Stardew Valley.exe" : "StardewValley.exe"), + executable = Path.Combine(installDir.FullName, EnvironmentUtility.GetExecutableName(platform)), unixSmapiLauncher = Path.Combine(installDir.FullName, "StardewModdingAPI"), unixLauncher = Path.Combine(installDir.FullName, "StardewValley"), unixLauncherBackup = Path.Combine(installDir.FullName, "StardewValley-original") @@ -199,7 +199,7 @@ namespace StardewModdingApi.Installer { this.PrintError(platform == Platform.Windows && packageDir.FullName.Contains(Path.GetTempPath()) && packageDir.FullName.Contains(".zip") ? "The installer is missing some files. It looks like you're running the installer from inside the downloaded zip; make sure you unzip the downloaded file first, then run the installer from the unzipped folder." - : $"The 'internal/{platform}' package folder is missing (should be at {packageDir})." + : $"The 'internal/{packageDir.Name}' package folder is missing (should be at {packageDir})." ); Console.ReadLine(); return; @@ -272,7 +272,7 @@ namespace StardewModdingApi.Installer ** Always uninstall old files ****/ // restore game launcher - if ((platform == Platform.Linux || platform == Platform.Mac) && File.Exists(paths.unixLauncherBackup)) + if (platform.IsMono() && File.Exists(paths.unixLauncherBackup)) { this.PrintDebug("Removing SMAPI launcher..."); this.InteractivelyDelete(paths.unixLauncher); @@ -305,7 +305,7 @@ namespace StardewModdingApi.Installer } // replace mod launcher (if possible) - if (platform == Platform.Linux || platform == Platform.Mac) + if (platform.IsMono()) { this.PrintDebug("Safely replacing game launcher..."); if (!File.Exists(paths.unixLauncherBackup)) @@ -554,9 +554,7 @@ namespace StardewModdingApi.Installer private DirectoryInfo InteractivelyGetInstallPath(Platform platform, string specifiedPath) { // get executable name - string executableFilename = platform == Platform.Windows - ? "Stardew Valley.exe" - : "StardewValley.exe"; + string executableFilename = EnvironmentUtility.GetExecutableName(platform); // validate specified path if (specifiedPath != null) @@ -662,10 +660,7 @@ namespace StardewModdingApi.Installer string[] packagedModNames = packagedModsDir.GetDirectories().Select(p => p.Name).ToArray(); // get path - string homePath = platform == Platform.Windows - ? Environment.GetEnvironmentVariable("APPDATA") - : Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".config"); - string appDataPath = Path.Combine(homePath, "StardewValley"); + string appDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley"); DirectoryInfo modDir = new DirectoryInfo(Path.Combine(appDataPath, "Mods")); // check if migration needed |