From 937750f10085840a0b0c84da516c7544594c812b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 2 Aug 2017 01:36:56 -0400 Subject: add installer command-line arguments for scripting (#337) --- .../InteractiveInstaller.cs | 69 +++++++++++++++++++--- 1 file changed, 61 insertions(+), 8 deletions(-) (limited to 'src/StardewModdingAPI.Installer') diff --git a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs index 78d3d10e..6aee9961 100644 --- a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs +++ b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs @@ -135,6 +135,27 @@ namespace StardewModdingApi.Installer /// public void Run(string[] args) { + /**** + ** read command-line arguments + ****/ + // get action from CLI + bool installArg = args.Contains("--install"); + bool uninstallArg = args.Contains("--uninstall"); + if (installArg && uninstallArg) + { + this.PrintError("You can't specify both --install and --uninstall command-line flags."); + Console.ReadLine(); + return; + } + + // get game path from CLI + string gamePathArg = null; + { + int pathIndex = Array.LastIndexOf(args, "--game-path") + 1; + if (pathIndex >= 1 && args.Length >= pathIndex) + gamePathArg = args[pathIndex]; + } + /**** ** collect details ****/ @@ -142,9 +163,17 @@ namespace StardewModdingApi.Installer Platform platform = this.DetectPlatform(); this.PrintDebug($"Platform: {(platform == Platform.Windows ? "Windows" : "Linux or Mac")}."); + // get game path + DirectoryInfo installDir = this.InteractivelyGetInstallPath(platform, gamePathArg); + if (installDir == null) + { + this.PrintError("Failed finding your game path."); + Console.ReadLine(); + return; + } + // get folders DirectoryInfo packageDir = new DirectoryInfo(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "internal", platform.ToString())); - DirectoryInfo installDir = this.InteractivelyGetInstallPath(platform); DirectoryInfo modsDir = new DirectoryInfo(Path.Combine(installDir.FullName, "Mods")); var paths = new { @@ -203,13 +232,19 @@ namespace StardewModdingApi.Installer /**** ** ask user what to do ****/ - Console.WriteLine("You can...."); - Console.WriteLine("[1] Install SMAPI."); - Console.WriteLine("[2] Uninstall SMAPI."); - Console.WriteLine(); - ScriptAction action; + + if (installArg) + action = ScriptAction.Install; + else if (uninstallArg) + action = ScriptAction.Uninstall; + else { + Console.WriteLine("You can...."); + Console.WriteLine("[1] Install SMAPI."); + Console.WriteLine("[2] Uninstall SMAPI."); + Console.WriteLine(); + string choice = this.InteractivelyChoose("What do you want to do? Type 1 or 2, then press enter.", "1", "2"); switch (choice) { @@ -222,8 +257,8 @@ namespace StardewModdingApi.Installer default: throw new InvalidOperationException($"Unexpected action key '{choice}'."); } + Console.WriteLine(); } - Console.WriteLine(); /**** ** Always uninstall old files @@ -513,13 +548,31 @@ namespace StardewModdingApi.Installer /// Interactively locate the game install path to update. /// The current platform. - private DirectoryInfo InteractivelyGetInstallPath(Platform platform) + /// The path specified as a command-line argument (if any), which should override automatic path detection. + private DirectoryInfo InteractivelyGetInstallPath(Platform platform, string specifiedPath) { // get executable name string executableFilename = platform == Platform.Windows ? "Stardew Valley.exe" : "StardewValley.exe"; + // validate specified path + if (specifiedPath != null) + { + var dir = new DirectoryInfo(specifiedPath); + if (!dir.Exists) + { + this.PrintError($"You specified --game-path \"{specifiedPath}\", but that folder doesn't exist."); + return null; + } + if (!dir.EnumerateFiles(executableFilename).Any()) + { + this.PrintError($"You specified --game-path \"{specifiedPath}\", but that folder doesn't contain the Stardew Valley executable."); + return null; + } + return dir; + } + // get installed paths DirectoryInfo[] defaultPaths = ( -- cgit From 527b00ee13407d13d227ad2d4e2d14991eab77d9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 14 Aug 2017 01:53:15 -0400 Subject: ignore installer arguments until SMAPI 2.0 --- src/StardewModdingAPI.Installer/InteractiveInstaller.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/StardewModdingAPI.Installer') diff --git a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs index 6aee9961..01288f33 100644 --- a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs +++ b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs @@ -135,6 +135,11 @@ namespace StardewModdingApi.Installer /// public void Run(string[] args) { +#if SMAPI_1_x + bool installArg = false; + bool uninstallArg = false; + string gamePathArg = null; +#else /**** ** read command-line arguments ****/ @@ -155,6 +160,7 @@ namespace StardewModdingApi.Installer if (pathIndex >= 1 && args.Length >= pathIndex) gamePathArg = args[pathIndex]; } +#endif /**** ** collect details -- cgit From c47e43a1e92cc8389ef06bd800251fbe0458fb76 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 14 Aug 2017 08:11:11 -0400 Subject: rename crossplatform.targets to common.targets for reuse --- src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/StardewModdingAPI.Installer') diff --git a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj index 765364dc..58ce519c 100644 --- a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj +++ b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj @@ -51,6 +51,6 @@ - + \ No newline at end of file -- cgit From 49ff572932f72374ebee73a3ebae6cc2c24bbeed Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 16 Aug 2017 23:03:14 -0400 Subject: fix build config --- src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/StardewModdingAPI.Installer') diff --git a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj index 58ce519c..4ddd6ebe 100644 --- a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj +++ b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj @@ -1,4 +1,4 @@ - + -- cgit From e42f06c916f753aefaf385e8463df048cbb8b604 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 21 Aug 2017 14:49:09 -0400 Subject: update for 1.15.2 release --- src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/StardewModdingAPI.Installer') diff --git a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj index 4ddd6ebe..58ce519c 100644 --- a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj +++ b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj @@ -1,4 +1,4 @@ - + -- cgit