From 4675da0600edf6781cd740549ad0a175b606fc1e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 1 Apr 2017 16:08:31 -0400 Subject: add --log-path argument to specify SMAPI log path during testing --- src/StardewModdingAPI/Constants.cs | 2 +- src/StardewModdingAPI/Program.cs | 29 +++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs index e28b33d7..4a036cd0 100644 --- a/src/StardewModdingAPI/Constants.cs +++ b/src/StardewModdingAPI/Constants.cs @@ -69,7 +69,7 @@ namespace StardewModdingAPI internal static string ApiConfigPath => Path.Combine(Constants.ExecutionPath, $"{typeof(Program).Assembly.GetName().Name}.config.json"); /// The file path to the log where the latest output should be saved. - internal static string LogPath => Path.Combine(Constants.LogDir, "SMAPI-latest.txt"); + internal static string DefaultLogPath => Path.Combine(Constants.LogDir, "SMAPI-latest.txt"); /// The full path to the folder containing mods. internal static string ModPath { get; } = Path.Combine(Constants.ExecutionPath, "Mods"); diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index ac98f2e4..58850dc3 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -30,7 +30,7 @@ namespace StardewModdingAPI ** Properties *********/ /// The log file to which to write messages. - private readonly LogFileManager LogFile = new LogFileManager(Constants.LogPath); + private readonly LogFileManager LogFile; /// Manages console output interception. private readonly ConsoleInterceptionManager ConsoleManager = new ConsoleInterceptionManager(); @@ -67,17 +67,38 @@ namespace StardewModdingAPI /// The command-line arguments. private static void Main(string[] args) { - new Program(writeToConsole: !args.Contains("--no-terminal")) + // get flags from arguments + bool writeToConsole = !args.Contains("--no-terminal"); + + // get log path from arguments + string logPath = null; + { + int pathIndex = Array.LastIndexOf(args, "--log-path") + 1; + if (pathIndex >= 1 && args.Length >= pathIndex) + { + logPath = args[pathIndex]; + if (!Path.IsPathRooted(logPath)) + logPath = Path.Combine(Constants.LogDir, logPath); + } + } + if (string.IsNullOrWhiteSpace(logPath)) + logPath = Constants.DefaultLogPath; + + // load SMAPI + new Program(writeToConsole, logPath) .LaunchInteractively(); } /// Construct an instance. - internal Program(bool writeToConsole) + /// Whether to output log messages to the console. + /// The full file path to which to write log messages. + internal Program(bool writeToConsole, string logPath) { // load settings this.Settings = JsonConvert.DeserializeObject(File.ReadAllText(Constants.ApiConfigPath)); // initialise + this.LogFile = new LogFileManager(logPath); this.Monitor = new Monitor("SMAPI", this.ConsoleManager, this.LogFile, this.ExitGameImmediately) { WriteToConsole = writeToConsole }; this.ModRegistry = new ModRegistry(this.Settings.ModCompatibility); this.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry); @@ -460,7 +481,7 @@ namespace StardewModdingAPI try { int modEntries = modAssembly.DefinedTypes.Count(type => typeof(Mod).IsAssignableFrom(type) && !type.IsAbstract); - if(modEntries == 0) + if (modEntries == 0) { this.Monitor.Log($"{skippedPrefix} because its DLL has no '{nameof(Mod)}' subclass.", LogLevel.Error); continue; -- cgit