From a7d3930d88b3f3b73c8f614372fcb839b3b5c5ad Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 30 Dec 2016 11:47:23 -0500 Subject: encapsulate repeated monitor construction --- src/StardewModdingAPI/Program.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/StardewModdingAPI/Program.cs') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 090098ca..9cb84cf5 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -125,7 +125,7 @@ namespace StardewModdingAPI 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); // initialise legacy log - Log.Monitor = new Monitor("legacy mod", Program.LogFile) { ShowTraceInConsole = Program.Settings.DeveloperMode }; + Log.Monitor = Program.GetSecondaryMonitor("legacy mod"); Log.ModRegistry = Program.ModRegistry; // hook into & launch the game @@ -183,7 +183,7 @@ namespace StardewModdingAPI internal static IMonitor GetLegacyMonitorForMod() { string modName = Program.ModRegistry.GetModFromStack() ?? "unknown"; - return new Monitor(modName, Program.LogFile); + return Program.GetSecondaryMonitor(modName); } @@ -518,7 +518,7 @@ namespace StardewModdingAPI // inject data mod.ModManifest = manifest; mod.Helper = helper; - mod.Monitor = new Monitor(manifest.Name, Program.LogFile) { ShowTraceInConsole = Program.Settings.DeveloperMode }; + mod.Monitor = Program.GetSecondaryMonitor(manifest.Name); mod.PathOnDisk = directory; // track mod @@ -590,5 +590,12 @@ namespace StardewModdingAPI Console.ReadKey(); Environment.Exit(0); } + + /// Get a monitor instance derived from SMAPI's current settings. + /// The name of the module which will log messages with this instance. + private static Monitor GetSecondaryMonitor(string name) + { + return new Monitor(name, Program.LogFile) { ShowTraceInConsole = Program.Settings.DeveloperMode }; + } } } -- cgit From a432477ea31c32e62fb347aef75861ab7ef62510 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 30 Dec 2016 12:04:27 -0500 Subject: fallback to launching SMAPI without a terminal on Linux if the terminal is unavailable (#198) --- README.md | 11 ++++++++++- src/StardewModdingAPI/Framework/Monitor.cs | 5 ++++- src/StardewModdingAPI/Program.cs | 14 +++++++++----- src/StardewModdingAPI/unix-launcher.sh | 8 ++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) (limited to 'src/StardewModdingAPI/Program.cs') diff --git a/README.md b/README.md index 8294452c..311c6d0e 100644 --- a/README.md +++ b/README.md @@ -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 /// Whether to show trace messages in the console. internal bool ShowTraceInConsole { get; set; } + /// Whether to write anything to the console. This should be disabled if no console is available. + 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 *********/ /// The main entry point which hooks into and launches the game. - private static void Main() + /// The command-line arguments. + 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 /// The name of the module which will log messages with this instance. 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 -- cgit From 40bc8f57c71d12d49bad24074cfe3279efe12850 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 14 Jan 2017 00:59:19 -0500 Subject: add support for incompatible mod version ranges --- release-notes.md | 3 +++ .../Framework/Models/IncompatibleMod.cs | 18 ++++++++++++------ src/StardewModdingAPI/Program.cs | 2 +- src/StardewModdingAPI/StardewModdingAPI.data.json | 10 +++++----- 4 files changed, 21 insertions(+), 12 deletions(-) (limited to 'src/StardewModdingAPI/Program.cs') diff --git a/release-notes.md b/release-notes.md index 6cedbc4f..6c667c31 100644 --- a/release-notes.md +++ b/release-notes.md @@ -8,6 +8,9 @@ For players: * Fixed issue where SMAPI couldn't be launched from Steam for some Linux players. * Updated list of incompatible mods. +For SMAPI developers: + * Added support for specifying a lower bound in mod incompatibility data. + ## 1.5 See [log](https://github.com/Pathoschild/SMAPI/compare/1.4...1.5). diff --git a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs index 9bf06552..bcc62bb4 100644 --- a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs +++ b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs @@ -14,8 +14,11 @@ namespace StardewModdingAPI.Framework.Models /// The mod name. public string Name { get; set; } + /// The oldest incompatible mod version, or null for all past versions. + public string LowerVersion { get; set; } + /// The most recent incompatible mod version. - public string Version { get; set; } + public string UpperVersion { get; set; } /// The URL the user can check for an official updated version. public string UpdateUrl { get; set; } @@ -23,7 +26,7 @@ namespace StardewModdingAPI.Framework.Models /// The URL the user can check for an unofficial updated version. public string UnofficialUpdateUrl { get; set; } - /// A regular expression matching version strings to consider compatible, even if they technically precede . + /// A regular expression matching version strings to consider compatible, even if they technically precede . public string ForceCompatibleVersion { get; set; } @@ -34,14 +37,17 @@ namespace StardewModdingAPI.Framework.Models /// The current version of the matching mod. public bool IsCompatible(ISemanticVersion version) { - ISemanticVersion incompatibleVersion = new SemanticVersion(this.Version); + ISemanticVersion lowerVersion = this.LowerVersion != null ? new SemanticVersion(this.LowerVersion) : null; + ISemanticVersion upperVersion = new SemanticVersion(this.UpperVersion); - // allow newer versions - if (version.IsNewerThan(incompatibleVersion)) + // ignore versions not in range + if (lowerVersion != null && version.IsOlderThan(lowerVersion)) + return true; + if (version.IsNewerThan(upperVersion)) return true; // allow versions matching override return !string.IsNullOrWhiteSpace(this.ForceCompatibleVersion) && Regex.IsMatch(version.ToString(), this.ForceCompatibleVersion, RegexOptions.IgnoreCase); } } -} \ No newline at end of file +} diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 58dbd87d..9d08c823 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -402,7 +402,7 @@ namespace StardewModdingAPI { if (!compatibility.IsCompatible(manifest.Version)) { - string warning = $"Skipped {compatibility.Name} ≤v{compatibility.Version} because this version is not compatible with the latest version of the game. Please check for a newer version of the mod here:"; + string warning = $"Skipped {compatibility.Name} {manifest.Version} because this version is not compatible with the latest version of the game. Please check for a newer version of the mod here:"; if (!string.IsNullOrWhiteSpace(compatibility.UpdateUrl)) warning += $"{Environment.NewLine}- official mod: {compatibility.UpdateUrl}"; if (!string.IsNullOrWhiteSpace(compatibility.UnofficialUpdateUrl)) diff --git a/src/StardewModdingAPI/StardewModdingAPI.data.json b/src/StardewModdingAPI/StardewModdingAPI.data.json index f350e8c5..464286af 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.data.json +++ b/src/StardewModdingAPI/StardewModdingAPI.data.json @@ -9,15 +9,15 @@ This file contains advanced metadata for SMAPI. You shouldn't change this file. { "ID": "SPDSprinklersMod", "Name": "Better Sprinklers", - "Version": "2.1", + "UpperVersion": "2.1", "UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/41", "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031", - "ForceCompatibleVersion": "^2.1-EntoPatch" + "ForceCompatibleVersion": "^2.1-EntoPatch" }, { "ID": "SPDChestLabel", "Name": "Chest Label System", - "Version": "1.5", + "UpperVersion": "1.5", "UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/242", "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031", "ForceCompatibleVersion": "^1.5-EntoPatch" @@ -25,14 +25,14 @@ This file contains advanced metadata for SMAPI. You shouldn't change this file. { "ID": "CJBCheatsMenu", "Name": "CJB Cheats Menu", - "Version": "1.12", + "UpperVersion": "1.12", "UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/4", "ForceCompatibleVersion": "^1.12-EntoPatch" }, { "ID": "CJBItemSpawner", "Name": "CJB Item Spawner", - "Version": "1.5", + "UpperVersion": "1.5", "UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/93", "ForceCompatibleVersion": "^1.5-EntoPatch" } -- cgit From 0ac9e47ea2af8d09baa2df9568aa30dce790c950 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 14 Jan 2017 01:11:42 -0500 Subject: add support for custom incompatible-mod-version error text --- release-notes.md | 1 + src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs | 4 ++++ src/StardewModdingAPI/Program.cs | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/StardewModdingAPI/Program.cs') diff --git a/release-notes.md b/release-notes.md index 6c667c31..bede8849 100644 --- a/release-notes.md +++ b/release-notes.md @@ -10,6 +10,7 @@ For players: For SMAPI developers: * Added support for specifying a lower bound in mod incompatibility data. + * Added support for custom incompatible-mod-version error text. ## 1.5 See [log](https://github.com/Pathoschild/SMAPI/compare/1.4...1.5). diff --git a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs index bcc62bb4..bcf5639c 100644 --- a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs +++ b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs @@ -29,6 +29,10 @@ namespace StardewModdingAPI.Framework.Models /// A regular expression matching version strings to consider compatible, even if they technically precede . public string ForceCompatibleVersion { get; set; } + /// The reason phrase to show in the warning, or null to use the default value. + /// "this version is incompatible with the latest version of the game" + public string ReasonPhrase { get; set; } + /********* ** Public methods diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 9d08c823..e5c27e71 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -402,7 +402,8 @@ namespace StardewModdingAPI { if (!compatibility.IsCompatible(manifest.Version)) { - string warning = $"Skipped {compatibility.Name} {manifest.Version} because this version is not compatible with the latest version of the game. Please check for a newer version of the mod here:"; + string reasonPhrase = compatibility.ReasonPhrase ?? "this version is not compatible with the latest version of the game"; + string warning = $"Skipped {compatibility.Name} {manifest.Version} because {reasonPhrase}. Please check for a newer version of the mod here:"; if (!string.IsNullOrWhiteSpace(compatibility.UpdateUrl)) warning += $"{Environment.NewLine}- official mod: {compatibility.UpdateUrl}"; if (!string.IsNullOrWhiteSpace(compatibility.UnofficialUpdateUrl)) -- cgit