From 956e477edb515953e71d1cce1a728284f6ce3cc0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 6 Nov 2016 11:15:46 -0500 Subject: add developer mode which shows all deprecation warnings, update release process (#165) --- README.md | 67 ++++++++++++---------- .../StardewModdingAPI.Installer.csproj | 5 +- .../Framework/DeprecationManager.cs | 12 +++- src/StardewModdingAPI/Framework/UserSettings.cs | 9 +++ src/StardewModdingAPI/Program.cs | 15 ++++- .../StardewModdingAPI-settings.json | 4 ++ src/StardewModdingAPI/StardewModdingAPI.csproj | 8 ++- 7 files changed, 85 insertions(+), 35 deletions(-) create mode 100644 src/StardewModdingAPI/Framework/UserSettings.cs create mode 100644 src/StardewModdingAPI/StardewModdingAPI-settings.json diff --git a/README.md b/README.md index 87b2669b..a0071c61 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,8 @@ placed in a `bin` directory at the root of the git repository. ### Preparing a release To prepare a crossplatform SMAPI release, you'll need to compile it on two platforms. See _[crossplatforming a SMAPI mod](http://canimod.com/guides/crossplatforming-a-smapi-mod#preparing-a-mod-release)_ -for the first-time setup. - -For simplicity, all paths are relative to the root of the repository (the directory containing `src`). +for the first-time setup. For simplicity, all paths are relative to the root of the repository (the +directory containing `src`). 1. Update the version number in `AssemblyInfo.cs` and `Constants::Version`. Make sure you use a [semantic version](http://semver.org). Recommended format: @@ -52,35 +51,43 @@ For simplicity, all paths are relative to the root of the repository (the direct 2. In Windows: 1. Rebuild the solution in _Release_ mode. - 2. Transfer the `bin/Release/~Package` directory to Linux or Mac. + 2. Rename `bin/Packaged` to `SMAPI-` (e.g. `SMAPI-1.0`). + 2. Transfer the `SMAPI-` directory to Linux or Mac. _This adds the installer executable and Windows files. We'll do the rest in Linux or Mac, since we need to set Unix file permissions that Windows won't save._ 2. In Linux or Mac: 1. Rebuild the solution in _Release_ mode. - 2. Copy `bin/Release/~Package/Mono` into the package directory you transferred from Windows. - 3. Open a terminal in your package directory and run `chmod 755 Mono/StardewModdingAPI`. - 4. Rename your package directory to `SMAPI--installer`. - 5. Compress it into a `SMAPI-.zip` file. - -If you did everything right, you should have a release file like this: - -``` -SMAPI-1.0.zip - SMAPI-1.0-installer/ - Mono/ - Mods/* - Newtonsoft.Json.dll - StardewModdingAPI - StardewModdingAPI.exe - StardewModdingAPI.exe.mdb - System.Numerics.dll - steam_appid.txt - Windows/ - Mods/* - StardewModdingAPI.exe - StardewModdingAPI.pdb - steam_appid.txt - install.exe - readme.txt -``` + 2. Copy `bin/Packaged/Mono` into the `SMAPI-` directory. + 3. If you did everything right so far, you should have a directory like this: + + ``` + SMAPI-1.0/ + Mono/ + Mods/* + Newtonsoft.Json.dll + StardewModdingAPI + StardewModdingAPI.exe + StardewModdingAPI.exe.mdb + StardewModdingAPI.xml + StardewModdingAPI-settings.json + System.Numerics.dll + steam_appid.txt + Windows/ + Mods/* + StardewModdingAPI.exe + StardewModdingAPI.pdb + StardewModdingAPI.xml + StardewModdingAPI-settings.json + steam_appid.txt + install.exe + readme.txt + ``` + 4. Open a terminal in the `SMAPI-` directory and run `chmod 755 Mono/StardewModdingAPI`. + 5. Copy & paste the `SMAPI-` directory as `SMAPI--for-developers`. + 6. In the `SMAPI-` directory, delete the following files: + * `Mono/StardewModdingAPI.xml` + * `Mono/StardewModdingAPI-settings.json` + * `Windows/StardewModdingAPI.xml` + * `Windows/StardewModdingAPI-settings.json` + 7. Compress the two folders into `SMAPI-.zip` and `SMAPI--for-developers.zip`. \ No newline at end of file diff --git a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj index e5271e96..4242cb94 100644 --- a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj +++ b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj @@ -51,7 +51,7 @@ - $(SolutionDir)\..\bin\$(Configuration)\~Package + $(SolutionDir)\..\bin\Packaged $(SolutionDir)\..\bin\$(Configuration)\SMAPI @@ -66,6 +66,8 @@ + + @@ -74,6 +76,7 @@ + diff --git a/src/StardewModdingAPI/Framework/DeprecationManager.cs b/src/StardewModdingAPI/Framework/DeprecationManager.cs index a3d1ea41..0c5a49f9 100644 --- a/src/StardewModdingAPI/Framework/DeprecationManager.cs +++ b/src/StardewModdingAPI/Framework/DeprecationManager.cs @@ -18,6 +18,13 @@ namespace StardewModdingAPI.Framework private readonly HashSet LoggedDeprecations = new HashSet(StringComparer.InvariantCultureIgnoreCase); + /********* + ** Accessors + *********/ + /// Whether -level deprecation messages should be shown in the console. + public bool SendNoticesToConsole { get; set; } + + /********* ** Public methods *********/ @@ -63,7 +70,10 @@ namespace StardewModdingAPI.Framework switch (severity) { case DeprecationLevel.Notice: - Log.LogToFile(message); + if (this.SendNoticesToConsole) + Log.Debug($"[DEV] {message}"); + else + Log.LogToFile(message); break; case DeprecationLevel.Info: diff --git a/src/StardewModdingAPI/Framework/UserSettings.cs b/src/StardewModdingAPI/Framework/UserSettings.cs new file mode 100644 index 00000000..199d19b3 --- /dev/null +++ b/src/StardewModdingAPI/Framework/UserSettings.cs @@ -0,0 +1,9 @@ +namespace StardewModdingAPI.Framework +{ + /// Contains user settings from SMAPI's JSON configuration file. + internal class UserSettings + { + /// Whether to enable development features. + public bool DeveloperMode { get; set; } + } +} diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index e9e357d5..047d74c7 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Windows.Forms; #endif using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json; using StardewModdingAPI.Events; using StardewModdingAPI.Framework; using StardewModdingAPI.Inheritance; @@ -67,6 +68,18 @@ namespace StardewModdingAPI // set thread culture for consistent log formatting Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); + // load user settings + { + string settingsPath = $@"{Constants.ExecutionPath}\{typeof(Program).Assembly.GetName().Name}-settings.json"; + if (File.Exists(settingsPath)) + { + string json = File.ReadAllText(settingsPath); + UserSettings settings = JsonConvert.DeserializeObject(json); + Program.DeprecationManager.SendNoticesToConsole = settings?.DeveloperMode == true; + } + + } + // hook into & launch the game try { @@ -271,7 +284,7 @@ namespace StardewModdingAPI } // log deprecated fields - if(manifest.UsedAuthourField) + if (manifest.UsedAuthourField) Program.DeprecationManager.Warn(manifest.Name, $"{nameof(Manifest)}.{nameof(Manifest.Authour)}", "1.0", DeprecationLevel.Notice); } catch (Exception ex) diff --git a/src/StardewModdingAPI/StardewModdingAPI-settings.json b/src/StardewModdingAPI/StardewModdingAPI-settings.json new file mode 100644 index 00000000..d27d0141 --- /dev/null +++ b/src/StardewModdingAPI/StardewModdingAPI-settings.json @@ -0,0 +1,4 @@ +{ + /* show all deprecation notices in the console? */ + "DeveloperMode": true +} diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 5540267a..bbb41ee3 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -59,7 +59,7 @@ true false $(SolutionDir)\..\bin\Debug\SMAPI - bin\Debug\StardewModdingAPI.xml + $(SolutionDir)\..\bin\Debug\SMAPI\StardewModdingAPI.xml true 6 @@ -68,7 +68,7 @@ bin\Release\ false $(SolutionDir)\..\bin\Release\SMAPI - bin\Release\StardewModdingAPI.xml + $(SolutionDir)\..\bin\Debug\SMAPI\StardewModdingAPI.xml TRACE true true @@ -200,6 +200,7 @@ + @@ -220,6 +221,9 @@ Designer + + Always + Always -- cgit