diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-12-30 12:04:27 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-12-30 12:04:27 -0500 |
commit | a432477ea31c32e62fb347aef75861ab7ef62510 (patch) | |
tree | df2fe7258d7748ce829222633844a3f00e94302e | |
parent | a7d3930d88b3f3b73c8f614372fcb839b3b5c5ad (diff) | |
download | SMAPI-a432477ea31c32e62fb347aef75861ab7ef62510.tar.gz SMAPI-a432477ea31c32e62fb347aef75861ab7ef62510.tar.bz2 SMAPI-a432477ea31c32e62fb347aef75861ab7ef62510.zip |
fallback to launching SMAPI without a terminal on Linux if the terminal is unavailable (#198)
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/Monitor.cs | 5 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 14 | ||||
-rw-r--r-- | src/StardewModdingAPI/unix-launcher.sh | 8 |
4 files changed, 31 insertions, 7 deletions
@@ -14,6 +14,7 @@ your game files. * [Preparing a release](#preparing-a-release) * [Advanced usage](#advanced-usage) * [Configuration file](#configuration-file) + * [Command-line arguments](#command-line-arguments) ## For players * [How to install SMAPI & use mods](http://canimod.com/guides/using-mods#installing-smapi) @@ -120,4 +121,12 @@ these fields: field | purpose ----- | ------- `DeveloperMode` | Default `false` (except in _SMAPI for developers_ releases). Whether to enable features intended for mod developers. Currently this only makes `TRACE`-level messages appear in the console. -`CheckForUpdates` | Default `true`. Whether SMAPI should check for a newer version when you load the game. If a new version is available, a small message will appear in the console. This doesn't affect the load time even if your connection is offline or slow, because it happens in the background.
\ No newline at end of file +`CheckForUpdates` | Default `true`. Whether SMAPI should check for a newer version when you load the game. If a new version is available, a small message will appear in the console. This doesn't affect the load time even if your connection is offline or slow, because it happens in the background. + +### Command-line arguments +SMAPI recognises the following command-line arguments. These are intended for internal use and may +change without warning. + +argument | purpose +-------- | ------- +`--no-terminal` | SMAPI won't write anything to the console window. (Messages will still be written to the log file.)
\ No newline at end of file diff --git a/src/StardewModdingAPI/Framework/Monitor.cs b/src/StardewModdingAPI/Framework/Monitor.cs index cf46a474..0989bb7e 100644 --- a/src/StardewModdingAPI/Framework/Monitor.cs +++ b/src/StardewModdingAPI/Framework/Monitor.cs @@ -37,6 +37,9 @@ namespace StardewModdingAPI.Framework /// <summary>Whether to show trace messages in the console.</summary> internal bool ShowTraceInConsole { get; set; } + /// <summary>Whether to write anything to the console. This should be disabled if no console is available.</summary> + internal bool WriteToConsole { get; set; } = true; + /********* ** Public methods @@ -108,7 +111,7 @@ namespace StardewModdingAPI.Framework message = $"[{DateTime.Now:HH:mm:ss} {levelStr} {source}] {message}"; // log - if (this.ShowTraceInConsole || level != LogLevel.Trace) + if (this.WriteToConsole && (this.ShowTraceInConsole || level != LogLevel.Trace)) { Console.ForegroundColor = color; Console.WriteLine(message); diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 9cb84cf5..58dbd87d 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -93,12 +93,14 @@ namespace StardewModdingAPI ** Public methods *********/ /// <summary>The main entry point which hooks into and launches the game.</summary> - private static void Main() + /// <param name="args">The command-line arguments.</param> + private static void Main(string[] args) { - // set thread culture for consistent log formatting - Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); + // set log options + Program.Monitor.WriteToConsole = !args.Contains("--no-terminal"); + Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); // for consistent log formatting - // add info header + // add info headers Program.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Game1.version} on {Environment.OSVersion}", LogLevel.Info); // initialise user settings @@ -123,6 +125,8 @@ namespace StardewModdingAPI } if (!Program.Settings.CheckForUpdates) Program.Monitor.Log($"You configured SMAPI to not check for updates. Running an old version of SMAPI is not recommended. You can enable update checks by editing or deleting {Constants.ApiConfigPath}.", LogLevel.Warn); + if (!Program.Monitor.WriteToConsole) + Program.Monitor.Log($"Writing to the terminal is disabled because the --no-terminal argument was received. This usually means launching the terminal failed.", LogLevel.Warn); // initialise legacy log Log.Monitor = Program.GetSecondaryMonitor("legacy mod"); @@ -595,7 +599,7 @@ namespace StardewModdingAPI /// <param name="name">The name of the module which will log messages with this instance.</param> private static Monitor GetSecondaryMonitor(string name) { - return new Monitor(name, Program.LogFile) { ShowTraceInConsole = Program.Settings.DeveloperMode }; + return new Monitor(name, Program.LogFile) { WriteToConsole = Program.Monitor.WriteToConsole, ShowTraceInConsole = Program.Settings.DeveloperMode }; } } } diff --git a/src/StardewModdingAPI/unix-launcher.sh b/src/StardewModdingAPI/unix-launcher.sh index 93e33c78..bf0e9d5e 100644 --- a/src/StardewModdingAPI/unix-launcher.sh +++ b/src/StardewModdingAPI/unix-launcher.sh @@ -64,4 +64,12 @@ else else $LAUNCHER fi + + # some Linux users get error 127 (command not found) from the above block, even though + # `command -v` indicates the command is valid. As a fallback, launch SMAPI without a terminal when + # that happens and pass in an argument indicating SMAPI shouldn't try writing to the terminal + # (which can be slow if there is none). + if [ $? -eq 127 ]; then + $LAUNCHER --no-terminal + fi fi |