From df7e814286641c27a64cf354c15d69ddcfae062d Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 3 Nov 2019 18:24:34 -0500 Subject: add support for using environment variables instead of command-line arguments (#665) --- src/SMAPI/Program.cs | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/SMAPI') diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 2d143439..05d7ff66 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -116,21 +116,27 @@ namespace StardewModdingAPI /// This method is separate from because that can't contain any references to assemblies loaded by (e.g. via ), or Mono will incorrectly show an assembly resolution error before assembly resolution is set up. private static void Start(string[] args) { - // get flags from arguments - bool writeToConsole = !args.Contains("--no-terminal"); + // get flags + bool writeToConsole = !args.Contains("--no-terminal") && Environment.GetEnvironmentVariable("SMAPI_NO_TERMINAL") == null; - // get mods path from arguments - string modsPath = null; + // get mods path + string modsPath; { + string rawModsPath = null; + + // get from command line args int pathIndex = Array.LastIndexOf(args, "--mods-path") + 1; if (pathIndex >= 1 && args.Length >= pathIndex) - { - modsPath = args[pathIndex]; - if (!string.IsNullOrWhiteSpace(modsPath) && !Path.IsPathRooted(modsPath)) - modsPath = Path.Combine(Constants.ExecutionPath, modsPath); - } - if (string.IsNullOrWhiteSpace(modsPath)) - modsPath = Constants.DefaultModsPath; + rawModsPath = args[pathIndex]; + + // get from environment variables + if (string.IsNullOrWhiteSpace(rawModsPath)) + rawModsPath = Environment.GetEnvironmentVariable("SMAPI_MODS_PATH"); + + // normalise + modsPath = !string.IsNullOrWhiteSpace(rawModsPath) + ? Path.Combine(Constants.ExecutionPath, rawModsPath) + : Constants.DefaultModsPath; } // load SMAPI -- cgit