From 47a806533b9fbcfe3fc771316283a7734702baae Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 23 Apr 2021 02:05:14 -0400 Subject: [PATCH] add 64-bit support to the SMAPI installer (#767) --- build/common.targets | 15 +++--- docs/release-notes.md | 4 +- docs/technical/smapi.md | 17 +++--- .../Framework/InstallerPaths.cs | 11 +++- src/SMAPI.Installer/InteractiveInstaller.cs | 53 ++++++++++++++++--- .../Framework/GameScanning/GameScanner.cs | 11 ++-- 6 files changed, 84 insertions(+), 27 deletions(-) diff --git a/build/common.targets b/build/common.targets index 4068c491..6834c162 100644 --- a/build/common.targets +++ b/build/common.targets @@ -1,13 +1,16 @@ - + 3.9.5 SMAPI - latest $(AssemblySearchPaths);{GAC} - + + + + $(DefineConstants);SMAPI_FOR_WINDOWS $(DefineConstants);SMAPI_FOR_XNA @@ -53,9 +56,9 @@ - - - + + + diff --git a/docs/release-notes.md b/docs/release-notes.md index 748e62c5..9de285ae 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -9,13 +9,13 @@ ## Upcoming release * For players: + * Added support for unofficial 64-bit Stardew Valley, including automatic support in the SMAPI installer. + * Added update checks for Stardew64Installer if it patched the game. * When many mods fail to load, root dependencies are now listed in their own group so it's easier to see which ones you should try updating first. * On macOS, the `StardewModdingAPI.bin.osx` file is no longer overwritten if it's identical to avoid resetting file permissions (thanks to 007wayne!). - * Added update checks for Stardew64Installer if it patched the game. * Fixed error for non-English players after returning to title, reloading, and entering town with a completed movie theater. * Fixed `world_clear` console command not removing resource clumps outside the farm and secret woods. * Fixed inconsistent spelling/style for 'macOS'. - * Internal changes to prepare for unofficial 64-bit. * For modders: * Added asset propagation for `Data\Concessions`. diff --git a/docs/technical/smapi.md b/docs/technical/smapi.md index ca1631cd..b64239c1 100644 --- a/docs/technical/smapi.md +++ b/docs/technical/smapi.md @@ -82,7 +82,9 @@ To prepare a crossplatform SMAPI release, you'll need to compile it on two platf [crossplatforming info](https://stardewvalleywiki.com/Modding:Modder_Guide/Test_and_Troubleshoot#Testing_on_all_platforms) on the wiki for the first-time setup. -1. Update the version numbers in `build/common.targets`, `Constants`, and the `manifest.json` for +1. [Install a separate 64-bit version of Stardew Valley](https://github.com/Steviegt6/Stardew64Installer#readme) + on Windows. +2. Update the version numbers in `build/common.targets`, `Constants`, and the `manifest.json` for bundled mods. Make sure you use a [semantic version](https://semver.org). Recommended format: build type | format | example @@ -90,12 +92,15 @@ on the wiki for the first-time setup. dev build | `-alpha.` | `3.0.0-alpha.20171230` prerelease | `-beta.` | `3.0.0-beta.20171230` release | `` | `3.0.0` - -2. In Windows: +3. In Windows: 1. Rebuild the solution with the _release_ solution configuration. - 2. Copy `bin/SMAPI installer` and `bin/SMAPI installer for developers` to Linux/macOS. - -3. In Linux/macOS: + 2. Back up the `bin/SMAPI installer` and `bin/SMAPI installer for developers` folders. + 3. Edit `common.targets` and uncomment the Stardew Valley 64-bit section at the top. + 4. Rebuild the solution again. + 5. Rename the compiled `StardewModdingAPI.exe` file to `StardewModdingAPI-x64.exe`, and copy it + into the `windows-install.dat` files from step ii. + 6. Copy the folders from step ii to Linux/MacOS. +4. In Linux/macOS: 1. Rebuild the solution with the _release_ solution configuration. 2. Add the `windows-install.*` files from Windows to the `bin/SMAPI installer` and `bin/SMAPI installer for developers` folders compiled on Linux. diff --git a/src/SMAPI.Installer/Framework/InstallerPaths.cs b/src/SMAPI.Installer/Framework/InstallerPaths.cs index 2cabf88b..6ba5fa5f 100644 --- a/src/SMAPI.Installer/Framework/InstallerPaths.cs +++ b/src/SMAPI.Installer/Framework/InstallerPaths.cs @@ -44,8 +44,8 @@ namespace StardewModdingAPI.Installer.Framework /// The full path to the user's config overrides file. public string ApiUserConfigPath { get; } - /// The full path to the installed SMAPI executable file. - public string ExecutablePath { get; } + /// The full path to the installed game executable file. + public string ExecutablePath { get; private set; } /// The full path to the vanilla game launcher on Linux/macOS. public string UnixLauncherPath { get; } @@ -79,5 +79,12 @@ namespace StardewModdingAPI.Installer.Framework this.ApiConfigPath = Path.Combine(gameDir.FullName, "smapi-internal", "config.json"); this.ApiUserConfigPath = Path.Combine(gameDir.FullName, "smapi-internal", "config.user.json"); } + + /// Override the filename for the . + /// the file name. + public void SetExecutableFileName(string filename) + { + this.ExecutablePath = Path.Combine(this.GamePath, filename); + } } } diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index 376949da..6bfc6874 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; @@ -10,7 +11,6 @@ using StardewModdingAPI.Internal.ConsoleWriting; using StardewModdingAPI.Toolkit; using StardewModdingAPI.Toolkit.Framework.ModScanning; using StardewModdingAPI.Toolkit.Utilities; -using System.Diagnostics; namespace StardewModdingApi.Installer { @@ -275,7 +275,20 @@ namespace StardewModdingApi.Installer /********* - ** Step 4: validate assumptions + ** Step 4: detect 64-bit Stardew Valley + *********/ + // detect 64-bit mode + bool isWindows64Bit = false; + if (context.Platform == Platform.Windows) + { + FileInfo linuxExecutable = new FileInfo(Path.Combine(paths.GamePath, "StardewValley.exe")); + isWindows64Bit = linuxExecutable.Exists && this.Is64Bit(linuxExecutable.FullName); + if (isWindows64Bit) + paths.SetExecutableFileName(linuxExecutable.Name); + } + + /********* + ** Step 5: validate assumptions *********/ // executable exists if (!File.Exists(paths.ExecutablePath)) @@ -298,7 +311,7 @@ namespace StardewModdingApi.Installer /********* - ** Step 5: ask what to do + ** Step 6: ask what to do *********/ ScriptAction action; { @@ -306,7 +319,7 @@ namespace StardewModdingApi.Installer ** print header ****/ this.PrintInfo("Hi there! I'll help you install or remove SMAPI. Just one question first."); - this.PrintDebug($"Game path: {paths.GamePath}"); + this.PrintDebug($"Game path: {paths.GamePath}{(context.IsWindows ? $" [{(isWindows64Bit ? "64-bit" : "32-bit")}]" : "")}"); this.PrintDebug($"Color scheme: {this.GetDisplayText(scheme)}"); this.PrintDebug("----------------------------------------------------------------------------"); Console.WriteLine(); @@ -344,14 +357,14 @@ namespace StardewModdingApi.Installer /********* - ** Step 6: apply + ** Step 7: apply *********/ { /**** ** print header ****/ this.PrintInfo($"That's all I need! I'll {action.ToString().ToLower()} SMAPI now."); - this.PrintDebug($"Game path: {paths.GamePath}"); + this.PrintDebug($"Game path: {paths.GamePath}{(context.IsWindows ? $" [{(isWindows64Bit ? "64-bit" : "32-bit")}]" : "")}"); this.PrintDebug($"Color scheme: {this.GetDisplayText(scheme)}"); this.PrintDebug("----------------------------------------------------------------------------"); Console.WriteLine(); @@ -412,6 +425,27 @@ namespace StardewModdingApi.Installer this.RecursiveCopy(sourceEntry, paths.GameDir); } + if (isWindows64Bit) + { + this.PrintDebug("Making SMAPI 64-bit..."); + FileInfo x64Executable = new FileInfo(Path.Combine(paths.BundleDir.FullName, "StardewModdingAPI-x64.exe")); + if (x64Executable.Exists) + { + string targetName = "StardewModdingAPI.exe"; + this.InteractivelyDelete(Path.Combine(paths.GameDir.FullName, targetName)); + this.InteractivelyDelete(Path.Combine(paths.GameDir.FullName, x64Executable.Name)); + + this.RecursiveCopy(x64Executable, paths.GameDir); + File.Move(Path.Combine(paths.GamePath, x64Executable.Name), Path.Combine(paths.GamePath, targetName)); + } + else + { + this.PrintError($"Oops! Could not find the required '{x64Executable.Name}' installer file. SMAPI was unable to install correctly."); + Console.ReadLine(); + return; + } + } + // replace mod launcher (if possible) if (context.IsUnix) { @@ -535,6 +569,13 @@ namespace StardewModdingApi.Installer /********* ** Private methods *********/ + /// Get whether an executable is 64-bit. + /// The absolute path to the executable file. + private bool Is64Bit(string executablePath) + { + return AssemblyName.GetAssemblyName(executablePath).ProcessorArchitecture != ProcessorArchitecture.X86; + } + /// Get the display text for a color scheme. /// The color scheme. private string GetDisplayText(MonitorColorScheme scheme) diff --git a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs index d18a2204..c90fc1d3 100644 --- a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs +++ b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs @@ -20,9 +20,6 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning /// The current OS. private readonly Platform Platform; - /// The name of the Stardew Valley executable. - private readonly string ExecutableName; - /********* ** Public methods @@ -31,7 +28,6 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning public GameScanner() { this.Platform = EnvironmentUtility.DetectPlatform(); - this.ExecutableName = EnvironmentUtility.GetExecutableName(this.Platform); } /// Find all valid Stardew Valley install folders. @@ -58,7 +54,12 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning /// The folder to check. public bool LooksLikeGameFolder(DirectoryInfo dir) { - return dir.Exists && dir.EnumerateFiles(this.ExecutableName).Any(); + return + dir.Exists + && ( + dir.EnumerateFiles("StardewValley.exe").Any() + || dir.EnumerateFiles("Stardew Valley.exe").Any() + ); }