summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2016-12-30 12:04:27 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2016-12-30 12:04:27 -0500
commita432477ea31c32e62fb347aef75861ab7ef62510 (patch)
treedf2fe7258d7748ce829222633844a3f00e94302e /src/StardewModdingAPI
parenta7d3930d88b3f3b73c8f614372fcb839b3b5c5ad (diff)
downloadSMAPI-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)
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Framework/Monitor.cs5
-rw-r--r--src/StardewModdingAPI/Program.cs14
-rw-r--r--src/StardewModdingAPI/unix-launcher.sh8
3 files changed, 21 insertions, 6 deletions
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