From 47a806533b9fbcfe3fc771316283a7734702baae Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 23 Apr 2021 02:05:14 -0400 Subject: add 64-bit support to the SMAPI installer (#767) --- src/SMAPI.Installer/Framework/InstallerPaths.cs | 11 ++++- src/SMAPI.Installer/InteractiveInstaller.cs | 53 +++++++++++++++++++--- .../Framework/GameScanning/GameScanner.cs | 11 +++-- 3 files changed, 62 insertions(+), 13 deletions(-) (limited to 'src') 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() + ); } -- cgit