summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md12
-rw-r--r--release-notes.md3
-rw-r--r--src/StardewModdingAPI.Installer/InteractiveInstaller.cs69
3 files changed, 74 insertions, 10 deletions
diff --git a/README.md b/README.md
index 332a3754..cbf0ec36 100644
--- a/README.md
+++ b/README.md
@@ -160,8 +160,16 @@ field | purpose
`ModCompatibility` | A list of mod versions SMAPI should consider compatible or broken regardless of whether it detects incompatible code. This can be used to force SMAPI to load an incompatible mod, though that isn't recommended.
### Command-line arguments
-SMAPI recognises the following command-line arguments. These are intended for internal use or
-testing and may change without warning.
+The SMAPI installer recognises three command-line arguments:
+
+argument | purpose
+-------- | -------
+`--install` | Preselects the install action, skipping the prompt asking what the user wants to do.
+`--uninstall` | Preselects the uninstall action, skipping the prompt asking what the user wants to do.
+`--game-path "path"` | Specifies the full path to the folder containing the Stardew Valley executable, skipping automatic detection and any prompt to choose a path. If the path is not valid, the installer displays an error.
+
+SMAPI itself recognises two arguments, but these are intended for internal use or testing and may
+change without warning.
argument | purpose
-------- | -------
diff --git a/release-notes.md b/release-notes.md
index 0bc69f30..3df1517e 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -26,6 +26,9 @@ For mod developers:
* Fixed `TimeEvents.AfterDayStarted` being raised during the new-game intro.
* Fixed `Context.IsPlayerFree` being incorrectly false in some cases (e.g. when using a tool).
+For power users:
+* Added command-line arguments to the SMAPI installer so it can be scripted.
+
## 1.15.2
For players:
* Improved error when using very old versions of Stardew Valley.
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
@@ -136,15 +136,44 @@ 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
****/
// get platform
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
/// <summary>Interactively locate the game install path to update.</summary>
/// <param name="platform">The current platform.</param>
- private DirectoryInfo InteractivelyGetInstallPath(Platform platform)
+ /// <param name="specifiedPath">The path specified as a command-line argument (if any), which should override automatic path detection.</param>
+ 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 =
(