From 6a18dd6fadaea7d72ce9ef4e2752c669c4f6420b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 23 Feb 2017 22:58:23 -0500 Subject: merge config files --- src/StardewModdingAPI/Program.cs | 65 ++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 43 deletions(-) (limited to 'src/StardewModdingAPI/Program.cs') diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index b8a16e79..eadbaaeb 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -47,8 +47,8 @@ namespace StardewModdingAPI /// The core logger for SMAPI. private readonly Monitor Monitor; - /// The user settings for SMAPI. - private UserSettings Settings; + /// The SMAPI configuration settings. + private readonly SConfig Settings; /// Tracks whether the game should exit immediately and any pending initialisation should be cancelled. private readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource(); @@ -87,6 +87,10 @@ namespace StardewModdingAPI /// Construct an instance. internal Program(bool writeToConsole) { + // load settings + this.Settings = JsonConvert.DeserializeObject(File.ReadAllText(Constants.ApiConfigPath)); + + // initialise this.Monitor = new Monitor("SMAPI", this.ConsoleManager, this.LogFile, this.ExitGameImmediately) { WriteToConsole = writeToConsole }; this.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry); } @@ -99,20 +103,6 @@ namespace StardewModdingAPI this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Game1.version} on {Environment.OSVersion}", LogLevel.Info); Console.Title = $"SMAPI {Constants.ApiVersion} - running Stardew Valley {Game1.version}"; - // read settings - { - string settingsPath = Constants.ApiConfigPath; - if (File.Exists(settingsPath)) - { - string json = File.ReadAllText(settingsPath); - this.Settings = JsonConvert.DeserializeObject(json); - } - else - this.Settings = new UserSettings(); - - File.WriteAllText(settingsPath, JsonConvert.SerializeObject(this.Settings, Formatting.Indented)); - } - // inject compatibility shims #pragma warning disable 618 Command.Shim(this.CommandManager, this.DeprecationManager, this.ModRegistry); @@ -341,20 +331,6 @@ namespace StardewModdingAPI AssemblyLoader modAssemblyLoader = new AssemblyLoader(this.TargetPlatform, this.Monitor); AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => modAssemblyLoader.ResolveAssembly(e.Name); - // get known incompatible mods - IDictionary incompatibleMods; - try - { - incompatibleMods = File.Exists(Constants.ApiModMetadataPath) - ? JsonConvert.DeserializeObject(File.ReadAllText(Constants.ApiModMetadataPath)).ToDictionary(p => p.ID, p => p) - : new Dictionary(0); - } - catch (Exception ex) - { - incompatibleMods = new Dictionary(); - this.Monitor.Log($"Couldn't read metadata file at {Constants.ApiModMetadataPath}. SMAPI will still run, but some features may be disabled.\n{ex}", LogLevel.Warn); - } - // load mod assemblies int modsLoaded = 0; List deprecationWarnings = new List(); // queue up deprecation warnings to show after mod list @@ -413,23 +389,26 @@ namespace StardewModdingAPI } // validate known incompatible mods - IncompatibleMod compatibility; - if (incompatibleMods.TryGetValue(!string.IsNullOrWhiteSpace(manifest.UniqueID) ? manifest.UniqueID : manifest.EntryDll, out compatibility)) { - if (!compatibility.IsCompatible(manifest.Version)) + string modKey = !string.IsNullOrWhiteSpace(manifest.UniqueID) ? manifest.UniqueID : manifest.EntryDll; + IncompatibleMod compatibility = this.Settings.IncompatibleMods.FirstOrDefault(p => p.ID == modKey); + if(compatibility != null) { - bool hasOfficialUrl = !string.IsNullOrWhiteSpace(compatibility.UpdateUrl); - bool hasUnofficialUrl = !string.IsNullOrWhiteSpace(compatibility.UnofficialUpdateUrl); + if (!compatibility.IsCompatible(manifest.Version)) + { + bool hasOfficialUrl = !string.IsNullOrWhiteSpace(compatibility.UpdateUrl); + bool hasUnofficialUrl = !string.IsNullOrWhiteSpace(compatibility.UnofficialUpdateUrl); - string reasonPhrase = compatibility.ReasonPhrase ?? "it isn't compatible with the latest version of the game"; - string warning = $"Skipped {compatibility.Name} because {reasonPhrase}. Please check for a version newer than {compatibility.UpperVersion} here:"; - if (hasOfficialUrl) - warning += !hasUnofficialUrl ? $" {compatibility.UpdateUrl}" : $"{Environment.NewLine}- official mod: {compatibility.UpdateUrl}"; - if (hasUnofficialUrl) - warning += $"{Environment.NewLine}- unofficial update: {compatibility.UnofficialUpdateUrl}"; + string reasonPhrase = compatibility.ReasonPhrase ?? "it isn't compatible with the latest version of the game"; + string warning = $"Skipped {compatibility.Name} because {reasonPhrase}. Please check for a version newer than {compatibility.UpperVersion} here:"; + if (hasOfficialUrl) + warning += !hasUnofficialUrl ? $" {compatibility.UpdateUrl}" : $"{Environment.NewLine}- official mod: {compatibility.UpdateUrl}"; + if (hasUnofficialUrl) + warning += $"{Environment.NewLine}- unofficial update: {compatibility.UnofficialUpdateUrl}"; - this.Monitor.Log(warning, LogLevel.Error); - continue; + this.Monitor.Log(warning, LogLevel.Error); + continue; + } } } -- cgit