diff --git a/YAMDCC.Common/Strings.cs b/YAMDCC.Common/Strings.cs index 2420cd6..427d821 100644 --- a/YAMDCC.Common/Strings.cs +++ b/YAMDCC.Common/Strings.cs @@ -26,26 +26,6 @@ internal static class Strings { private static ResourceManager resMan; - /// - /// Gets a string from the underlying resource file. - /// - /// - /// This function internally calls - /// to retrieve the string. - /// - /// - /// The name of the string to find. - /// - /// - /// The value of the specified string name, if found. - /// null if the string couldn't be found. - /// - public static string GetString(string name) - { - resMan ??= new ResourceManager(typeof(Strings)); - return resMan.GetString(name, CultureInfo.InvariantCulture); - } - /// /// Gets a string from the underlying resource file, and /// replaces format objects with their string representation. @@ -53,8 +33,8 @@ public static string GetString(string name) /// /// The name of the string to find. /// - /// - /// The object to format the string with. + /// + /// The objects to format the string with. /// /// /// @@ -63,11 +43,13 @@ public static string GetString(string name) /// /// null if the string couldn't be found. /// - public static string GetString(string name, object arg0) + public static string GetString(string name, params object[] args) { - string temp = GetString(name); + resMan ??= new ResourceManager(typeof(Strings)); + string temp = resMan.GetString(name, CultureInfo.InvariantCulture); + return temp is null ? null - : string.Format(CultureInfo.InvariantCulture, temp, arg0); + : string.Format(CultureInfo.InvariantCulture, temp, args); } } diff --git a/YAMDCC.Config/YAMDCC_Config.cs b/YAMDCC.Config/YAMDCC_Config.cs index 310c3d1..5975597 100644 --- a/YAMDCC.Config/YAMDCC_Config.cs +++ b/YAMDCC.Config/YAMDCC_Config.cs @@ -22,10 +22,17 @@ namespace YAMDCC.Config; +// IDE0079: Remove unnecessary suppression (even though it *is* necessary) +#pragma warning disable IDE0079 +// CA1707: Identifiers should not contain underscores +#pragma warning disable CA1707 /// /// Represents a YAMDCC configuration. /// + public sealed class YAMDCC_Config +#pragma warning restore CA1707 +#pragma warning restore IDE0079 { /// /// The config version expected when loading a config. @@ -131,17 +138,17 @@ public sealed class YAMDCC_Config /// Parses a YAMDCC config XML and returns a /// object. /// - /// + /// /// The path to an XML config file. /// /// /// /// /// - public static YAMDCC_Config Load(string xmlFile) + public static YAMDCC_Config Load(string path) { XmlSerializer serialiser = new(typeof(YAMDCC_Config)); - using (XmlReader reader = XmlReader.Create(xmlFile)) + using (XmlReader reader = XmlReader.Create(path)) { YAMDCC_Config cfg = (YAMDCC_Config)serialiser.Deserialize(reader); return cfg.IsValid() ? cfg : throw new InvalidConfigException(); @@ -151,23 +158,23 @@ public static YAMDCC_Config Load(string xmlFile) /// /// Saves a YAMDCC config to the specified location. /// - /// + /// /// The XML file to write to. /// /// /// - public void Save(string xmlFile) + public void Save(string path) { - XmlSerializer serializer = new(typeof(YAMDCC_Config)); + XmlSerializer serialiser = new(typeof(YAMDCC_Config)); XmlWriterSettings settings = new() { Indent = true, IndentChars = "\t", }; - using (XmlWriter writer = XmlWriter.Create(xmlFile, settings)) + using (XmlWriter writer = XmlWriter.Create(path, settings)) { - serializer.Serialize(writer, this); + serialiser.Serialize(writer, this); } } diff --git a/YAMDCC.ConfigEditor/MainWindow.cs b/YAMDCC.ConfigEditor/MainWindow.cs index 21ddec8..a7aa9ca 100644 --- a/YAMDCC.ConfigEditor/MainWindow.cs +++ b/YAMDCC.ConfigEditor/MainWindow.cs @@ -1444,12 +1444,12 @@ private void UpdateStatus(StatusCode status, int data = 0) { if (AppStatus.Code == status) { - AppStatus.RepeatCount++; + AppStatus.Repeats++; } else { AppStatus.Code = status; - AppStatus.RepeatCount = 0; + AppStatus.Repeats = 0; } // set status text @@ -1464,6 +1464,7 @@ private void UpdateStatus(StatusCode status, int data = 0) lblStatus.Text = Strings.GetString("statResponseEmpty"); break; case StatusCode.ServiceTimeout: + persist = true; lblStatus.Text = Strings.GetString("statSvcTimeout"); break; case StatusCode.NoConfig: @@ -1481,14 +1482,14 @@ private void UpdateStatus(StatusCode status, int data = 0) break; default: persist = true; - AppStatus.RepeatCount = 0; + AppStatus.Repeats = 0; lblStatus.Text = "Ready"; break; } - if (AppStatus.RepeatCount > 0) + if (AppStatus.Repeats > 0) { - lblStatus.Text += $" (x{AppStatus.RepeatCount + 1})"; + lblStatus.Text += $" (x{AppStatus.Repeats + 1})"; } tmrStatusReset.Stop(); diff --git a/YAMDCC.ConfigEditor/Status.cs b/YAMDCC.ConfigEditor/Status.cs index 732431c..41a515e 100644 --- a/YAMDCC.ConfigEditor/Status.cs +++ b/YAMDCC.ConfigEditor/Status.cs @@ -19,12 +19,12 @@ namespace YAMDCC.ConfigEditor; internal sealed class Status { internal StatusCode Code; - internal int RepeatCount; + internal int Repeats; internal Status() { Code = StatusCode.None; - RepeatCount = 0; + Repeats = 0; } } diff --git a/YAMDCC.ConfigEditor/Strings.cs b/YAMDCC.ConfigEditor/Strings.cs index a8b7ea4..2b9ca21 100644 --- a/YAMDCC.ConfigEditor/Strings.cs +++ b/YAMDCC.ConfigEditor/Strings.cs @@ -26,26 +26,6 @@ internal static class Strings { private static ResourceManager resMan; - /// - /// Gets a string from the underlying resource file. - /// - /// - /// This function internally calls - /// to retrieve the string. - /// - /// - /// The name of the string to find. - /// - /// - /// The value of the specified string name, if found. - /// null if the string couldn't be found. - /// - public static string GetString(string name) - { - resMan ??= new ResourceManager(typeof(Strings)); - return resMan.GetString(name, CultureInfo.InvariantCulture); - } - /// /// Gets a string from the underlying resource file, and /// replaces format objects with their string representation. @@ -53,8 +33,8 @@ public static string GetString(string name) /// /// The name of the string to find. /// - /// - /// The object to format the string with. + /// + /// The objects to format the string with. /// /// /// @@ -63,11 +43,13 @@ public static string GetString(string name) /// /// null if the string couldn't be found. /// - public static string GetString(string name, object arg0) + public static string GetString(string name, params object[] args) { - string temp = GetString(name); + resMan ??= new ResourceManager(typeof(Strings)); + string temp = resMan.GetString(name, CultureInfo.InvariantCulture); + return temp is null ? null - : string.Format(CultureInfo.InvariantCulture, temp, arg0); + : string.Format(CultureInfo.InvariantCulture, temp, args); } } diff --git a/YAMDCC.ConfigEditor/packages.lock.json b/YAMDCC.ConfigEditor/packages.lock.json index 19b69eb..41f7a5f 100644 --- a/YAMDCC.ConfigEditor/packages.lock.json +++ b/YAMDCC.ConfigEditor/packages.lock.json @@ -2,13 +2,10 @@ "version": 1, "dependencies": { ".NETFramework,Version=v4.8": { - "Markdig": { + "MarkedNet": { "type": "Transitive", - "resolved": "0.40.0", - "contentHash": "4ve14zs+gt1irldTQE3y5FLAHuzmhW7T99lAAvVipe/q2LWT/nUCO0iICb9TXGvMX6n7Z1OZroFXkdSy91rO8w==", - "dependencies": { - "System.Memory": "4.5.5" - } + "resolved": "2.1.4", + "contentHash": "7JSHAIeNM1Zsmza046u6OIBx36GzzGDLjKCSxroAeYKYiAFQ+34dGfbx06nX1KR1RhxBucGyZxlDD1fv/33FIg==" }, "MessagePack": { "type": "Transitive", @@ -114,7 +111,7 @@ "Updater": { "type": "Project", "dependencies": { - "Markdig": "[0.40.0, )", + "MarkedNet": "[2.1.4, )", "Newtonsoft.Json": "[13.0.3, )", "TaskScheduler": "[2.11.0, )", "YAMDCC.Common": "[1.0.0-dev, )" diff --git a/YAMDCC.Logs/Logger.cs b/YAMDCC.Logs/Logger.cs index fb91695..4f44504 100644 --- a/YAMDCC.Logs/Logger.cs +++ b/YAMDCC.Logs/Logger.cs @@ -15,7 +15,6 @@ // YAMDCC. If not, see . using System; -using System.Globalization; using System.IO; using System.IO.Compression; using System.Reflection; @@ -42,11 +41,11 @@ public sealed class Logger : IDisposable /// /// The newline characters to split provided log message lines by. /// - private static readonly char[] NewLineChars = ['\r', '\n']; + private static readonly char[] NewLine = ['\r', '\n']; - private static string LogString(string text, LogLevel level, bool date) + private static string LogString(string str, LogLevel level, bool date) { - return (date ? $"[{DateTime.Now:dd/MM/yyyy HH:mm:ss.fff}] " : "") + $"[{level}]".PadRight(8).ToUpperInvariant() + text; + return $"{(date ? $"[{DateTime.Now:dd/MM/yyyy HH:mm:ss.fff}] " : "")}{$"[{level}]",-8} {str}"; } /// @@ -73,27 +72,27 @@ private static string LogString(string text, LogLevel level, bool date) /// /// The maximum number of logs to archive. /// - public int MaxArchivedLogs { get; set; } = 9; + public int MaxArchived { get; set; } = 9; /// /// How verbose should console logs be? /// - public LogLevel ConsoleLogLevel { get; set; } = LogLevel.Info; + public LogLevel ConsoleLevel { get; set; } = LogLevel.Info; /// /// How verbose should logs written to disk be? /// - public LogLevel FileLogLevel { get; set; } = LogLevel.Info; + public LogLevel FileLevel { get; set; } = LogLevel.Info; /// /// Should the log time be shown in console logs? /// - public bool LogTimeToConsole { get; set; } + public bool TimeToConsole { get; set; } /// /// Should the log time be shown in logs written to disk? /// - public bool LogTimeToFile { get; set; } = true; + public bool TimeToFile { get; set; } = true; /// /// Writes a Debug event to the . @@ -103,36 +102,17 @@ private static string LogString(string text, LogLevel level, bool date) /// public void Debug(string msg) { - if (FileLogLevel >= LogLevel.Debug) + if (FileLevel >= LogLevel.Debug) { LogFile(msg, LogLevel.Debug); } - if (ConsoleLogLevel >= LogLevel.Debug) + if (ConsoleLevel >= LogLevel.Debug) { LogConsole(msg, LogLevel.Debug); } } - /// - /// Writes a Debug event to the , - /// replacing format items with the objects in . - /// - /// - /// Equivalent to passing a - /// to the argument. - /// - /// - /// The message to write to the log. - /// - /// - /// The objects to format. - /// - public void Debug(string msg, params object[] args) - { - Debug(string.Format(CultureInfo.InvariantCulture, msg, args)); - } - /// /// Writes an Info event to the . /// @@ -141,36 +121,17 @@ public void Debug(string msg, params object[] args) /// public void Info(string msg) { - if (FileLogLevel >= LogLevel.Info) + if (FileLevel >= LogLevel.Info) { LogFile(msg, LogLevel.Info); } - if (ConsoleLogLevel >= LogLevel.Info) + if (ConsoleLevel >= LogLevel.Info) { LogConsole(msg, LogLevel.Info); } } - /// - /// Writes an Info event to the , - /// replacing format items with the objects in . - /// - /// - /// Equivalent to passing a - /// to the argument. - /// - /// - /// The message to write to the log. - /// - /// - /// The objects to format. - /// - public void Info(string msg, params object[] args) - { - Info(string.Format(CultureInfo.InvariantCulture, msg, args)); - } - /// /// Writes a Warning to the . /// @@ -179,36 +140,17 @@ public void Info(string msg, params object[] args) /// public void Warn(string msg) { - if (FileLogLevel >= LogLevel.Warn) + if (FileLevel >= LogLevel.Warn) { LogFile(msg, LogLevel.Warn); } - if (ConsoleLogLevel >= LogLevel.Warn) + if (ConsoleLevel >= LogLevel.Warn) { LogConsole(msg, LogLevel.Warn); } } - /// - /// Writes a Warning to the , - /// replacing format items with the objects in . - /// - /// - /// Equivalent to passing a - /// to the argument. - /// - /// - /// The message to write to the log. - /// - /// - /// The objects to format. - /// - public void Warn(string msg, params object[] args) - { - Warn(string.Format(CultureInfo.InvariantCulture, msg, args)); - } - /// /// Writes an Error to the . /// @@ -217,36 +159,17 @@ public void Warn(string msg, params object[] args) /// public void Error(string msg) { - if (FileLogLevel >= LogLevel.Error) + if (FileLevel >= LogLevel.Error) { LogFile(msg, LogLevel.Error); } - if (ConsoleLogLevel >= LogLevel.Error) + if (ConsoleLevel >= LogLevel.Error) { LogConsole(msg, LogLevel.Error); } } - /// - /// Writes an Error to the , - /// replacing format items with the objects in . - /// - /// - /// Equivalent to passing a - /// to the argument. - /// - /// - /// The message to write to the log. - /// - /// - /// The objects to format. - /// - public void Error(string msg, params object[] args) - { - Error(string.Format(CultureInfo.InvariantCulture, msg, args)); - } - /// /// Writes a Fatal error to the . Use when an /// application is about to terminate due to a fatal error. @@ -256,43 +179,23 @@ public void Error(string msg, params object[] args) /// public void Fatal(string msg) { - if (FileLogLevel >= LogLevel.Fatal) + if (FileLevel >= LogLevel.Fatal) { LogFile(msg, LogLevel.Fatal); } - if (ConsoleLogLevel >= LogLevel.Fatal) + if (ConsoleLevel >= LogLevel.Fatal) { LogConsole(msg, LogLevel.Fatal); } } - /// - /// Writes a Fatal error to the , - /// replacing format items with the objects in . - /// Use when an application is about to terminate due to a fatal error. - /// - /// - /// Equivalent to passing a - /// to the argument. - /// - /// - /// The message to write to the log. - /// - /// - /// The objects to format. - /// - public void Fatal(string msg, params object[] args) - { - Fatal(string.Format(CultureInfo.InvariantCulture, msg, args)); - } - /// /// Deletes all archived logs (files ending with .[number].log.gz). /// public void DeleteArchived() { - for (int i = 1; i <= MaxArchivedLogs; i++) + for (int i = 1; i <= MaxArchived; i++) { try { @@ -316,9 +219,9 @@ private void LogFile(string msg, LogLevel level) lock (LogWriter) { - foreach (string str in msg.Split(NewLineChars, StringSplitOptions.RemoveEmptyEntries)) + foreach (string str in msg.Split(NewLine, StringSplitOptions.RemoveEmptyEntries)) { - LogWriter.WriteLine(LogString(str, level, LogTimeToFile)); + LogWriter.WriteLine(LogString(str, level, TimeToFile)); } } } @@ -356,9 +259,9 @@ private void LogConsole(string msg, LogLevel level) break; } - foreach (string str in msg.Split(NewLineChars, StringSplitOptions.RemoveEmptyEntries)) + foreach (string str in msg.Split(NewLine, StringSplitOptions.RemoveEmptyEntries)) { - Console.WriteLine(LogString(str, level, LogTimeToConsole)); + Console.WriteLine(LogString(str, level, TimeToConsole)); } Console.BackgroundColor = bgColour; @@ -381,11 +284,11 @@ private void InitLogFile() // Rename old log files, and delete the oldest file if // there's too many log files - for (int i = MaxArchivedLogs; i >= 0; i--) + for (int i = MaxArchived; i >= 0; i--) { try { - if (i == MaxArchivedLogs) + if (i == MaxArchived) { File.Delete($"{LogPath}.{i}.log.gz"); } diff --git a/YAMDCC.Service/FanControlService.cs b/YAMDCC.Service/FanControlService.cs index 3428f8f..d929d83 100644 --- a/YAMDCC.Service/FanControlService.cs +++ b/YAMDCC.Service/FanControlService.cs @@ -371,7 +371,7 @@ private bool LogECReadByte(byte reg, out byte value) bool success = _EC.ReadByte(reg, out value); if (success) { - Log.Debug(Strings.GetString("svcECRead"), reg, value); + Log.Debug(Strings.GetString("svcECRead", reg, value)); } else { @@ -385,7 +385,7 @@ private bool LogECReadWord(byte reg, out ushort value, bool bigEndian) bool success = _EC.ReadWord(reg, out value, bigEndian); if (success) { - Log.Debug(Strings.GetString("svcECRead"), reg, value); + Log.Debug(Strings.GetString("svcECRead", reg, value)); } else { @@ -399,7 +399,7 @@ private bool LogECWriteByte(byte reg, byte value) bool success = _EC.WriteByte(reg, value); if (success) { - Log.Debug(Strings.GetString("svcECWrote"), reg); + Log.Debug(Strings.GetString("svcECWrote", reg)); } else { diff --git a/YAMDCC.Service/Program.cs b/YAMDCC.Service/Program.cs index 095153b..6bd232f 100644 --- a/YAMDCC.Service/Program.cs +++ b/YAMDCC.Service/Program.cs @@ -30,8 +30,8 @@ internal static class Program private static readonly Logger Log = new() { LogDir = Paths.Logs, - ConsoleLogLevel = LogLevel.None, - FileLogLevel = LogLevel.Debug, + ConsoleLevel = LogLevel.None, + FileLevel = LogLevel.Debug, }; /// @@ -40,7 +40,7 @@ internal static class Program private static void Main() { AppDomain.CurrentDomain.UnhandledException += static (sender, e) => - Log.Fatal(Strings.GetString("svcException"), e.ExceptionObject); + Log.Fatal(Strings.GetString("svcException", e.ExceptionObject)); if (Environment.UserInteractive) { @@ -53,7 +53,7 @@ private static void Main() $"OS version: {Environment.OSVersion}\n" + $"Service version: {Application.ProductVersion}"); - Log.FileLogLevel = cfg.LogLevel; + Log.FileLevel = cfg.LogLevel; Log.Debug("Log level is set to debug mode."); ServiceBase.Run(new FanControlService(Log)); } diff --git a/YAMDCC.Service/Strings.cs b/YAMDCC.Service/Strings.cs index d39e6b9..ab04f18 100644 --- a/YAMDCC.Service/Strings.cs +++ b/YAMDCC.Service/Strings.cs @@ -27,54 +27,27 @@ internal static class Strings private static ResourceManager resMan; /// - /// Gets a string from the underlying resource file. + /// Gets a string from the underlying resource file, and + /// replaces format objects with their string representation. /// - /// - /// This function internally calls - /// to retrieve the string. - /// /// /// The name of the string to find. /// - /// - /// The value of the specified string name, if found. - /// null if the string couldn't be found. - /// - public static string GetString(string name) - { - resMan ??= new ResourceManager(typeof(Strings)); - return resMan.GetString(name, CultureInfo.InvariantCulture); - } - - /// - /// Gets a string from the underlying resource file, and replaces format - /// items with the specified object's string representation. - /// - /// - /// The name of the string to find. - /// - /// - /// The object to format the string with. + /// + /// The objects to format the string with. /// /// - /// The formatted string corresponding to the specified string name, if found. + /// + /// The formatted string corresponding to + /// the specified string name, if found. + /// /// null if the string couldn't be found. /// - public static string GetString(string name, object arg0) - { - string temp = GetString(name); - return temp is null - ? null - : string.Format(CultureInfo.InvariantCulture, temp, arg0); - } - - /// - /// - /// The objects to format the string with. - /// public static string GetString(string name, params object[] args) { - string temp = GetString(name); + resMan ??= new ResourceManager(typeof(Strings)); + string temp = resMan.GetString(name, CultureInfo.InvariantCulture); + return temp is null ? null : string.Format(CultureInfo.InvariantCulture, temp, args); diff --git a/YAMDCC.Updater/GitHubApi/Release.cs b/YAMDCC.Updater/GitHubApi/Release.cs index d8f8e29..bf1d563 100644 --- a/YAMDCC.Updater/GitHubApi/Release.cs +++ b/YAMDCC.Updater/GitHubApi/Release.cs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License along with // YAMDCC. If not, see . -using System; using Newtonsoft.Json; +using System; namespace YAMDCC.Updater.GitHubApi; diff --git a/YAMDCC.Updater/GitHubApi/ReleaseAsset.cs b/YAMDCC.Updater/GitHubApi/ReleaseAsset.cs index df4792a..0e054dd 100644 --- a/YAMDCC.Updater/GitHubApi/ReleaseAsset.cs +++ b/YAMDCC.Updater/GitHubApi/ReleaseAsset.cs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License along with // YAMDCC. If not, see . -using System; using Newtonsoft.Json; +using System; namespace YAMDCC.Updater.GitHubApi; diff --git a/YAMDCC.Updater/Program.cs b/YAMDCC.Updater/Program.cs index 6ab297a..404b17d 100644 --- a/YAMDCC.Updater/Program.cs +++ b/YAMDCC.Updater/Program.cs @@ -17,9 +17,7 @@ using System; using System.Diagnostics; using System.IO; -using System.IO.Compression; using System.Net.Http; -using System.Reflection; using System.Windows.Forms; using YAMDCC.Common; using YAMDCC.Common.Dialogs; @@ -38,8 +36,6 @@ private static int Main(string[] args) Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve; - if (args.Length > 0) { switch (args[0].ToLowerInvariant()) @@ -171,21 +167,4 @@ private static string GetExceptionMsgs(Exception ex) } return str; } - - private static Assembly AssemblyResolve(object sender, ResolveEventArgs e) - { - // fix conflict between MessagePack's System.Runtime.CompilerServices.Unsafe - // assembly (v6.0.0.0) and the version that Markdig needs (v4.0.4.1) that - // can't be resolved with a binding redirect: - if (e.Name == Resources.GetString("SRCSU_Name")) - { - // unpack gzipped System.Runtime.CompilerServices.Unsafe dll - GZipStream input = new(new MemoryStream(Resources.GetObject("SRCSU_Dll")), CompressionMode.Decompress); - MemoryStream output = new(); - input.CopyTo(output); - - return Assembly.Load(output.ToArray()); - } - return null; - } } diff --git a/YAMDCC.Updater/Resources.cs b/YAMDCC.Updater/Resources.cs deleted file mode 100644 index eba8d87..0000000 --- a/YAMDCC.Updater/Resources.cs +++ /dev/null @@ -1,108 +0,0 @@ -// This file is part of YAMDCC (Yet Another MSI Dragon Center Clone). -// Copyright © Sparronator9999 and Contributors 2025. -// -// YAMDCC is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) -// any later version. -// -// YAMDCC is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -// more details. -// -// You should have received a copy of the GNU General Public License along with -// YAMDCC. If not, see . - -using System.Globalization; -using System.Resources; - -namespace YAMDCC.Updater; - -internal static class Resources -{ - private static ResourceManager _resMan; - - private static ResourceManager ResMan - { - get - { - _resMan ??= new ResourceManager(typeof(Resources)); - return _resMan; - } - } - - public static byte[] GetObject(string name) - { - return (byte[])ResMan.GetObject(name, CultureInfo.InvariantCulture); - } - - /// - /// Gets a string from the underlying resource file. - /// - /// - /// This function internally calls - /// to retrieve the string. - /// - /// - /// The name of the string to find. - /// - /// - /// The value of the specified string name, if found. - /// null if the string couldn't be found. - /// - public static string GetString(string name) - { - return ResMan.GetString(name, CultureInfo.InvariantCulture); - } - - /// - /// Gets a string from the underlying resource file, and - /// replaces format objects with their string representation. - /// - /// - /// The name of the string to find. - /// - /// - /// The object to format the string with. - /// - /// - /// - /// The formatted string corresponding to - /// the specified string name, if found. - /// - /// null if the string couldn't be found. - /// - public static string GetString(string name, object arg0) - { - string temp = GetString(name); - return temp is null - ? null - : string.Format(CultureInfo.InvariantCulture, temp, arg0); - } - - /// - /// Gets a string from the underlying resource file, and - /// replaces format objects with their string representation. - /// - /// - /// The name of the string to find. - /// - /// - /// The objects to format the string with. - /// - /// - /// - /// The formatted string corresponding to - /// the specified string name, if found. - /// - /// null if the string couldn't be found. - /// - public static string GetString(string name, params object[] args) - { - string temp = GetString(name); - return temp is null - ? null - : string.Format(CultureInfo.InvariantCulture, temp, args); - } -} diff --git a/YAMDCC.Updater/Strings.cs b/YAMDCC.Updater/Strings.cs new file mode 100644 index 0000000..30c89bd --- /dev/null +++ b/YAMDCC.Updater/Strings.cs @@ -0,0 +1,52 @@ +// This file is part of YAMDCC (Yet Another MSI Dragon Center Clone). +// Copyright © Sparronator9999 and Contributors 2025. +// +// YAMDCC is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// YAMDCC is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// YAMDCC. If not, see . + +using System.Globalization; +using System.Resources; + +namespace YAMDCC.Updater; + +internal static class Strings +{ + private static ResourceManager resMan; + + /// + /// Gets a string from the underlying resource file, and + /// replaces format objects with their string representation. + /// + /// + /// The name of the string to find. + /// + /// + /// The objects to format the string with. + /// + /// + /// + /// The formatted string corresponding to + /// the specified string name, if found. + /// + /// null if the string couldn't be found. + /// + public static string GetString(string name, params object[] args) + { + resMan ??= new ResourceManager(typeof(Strings)); + string temp = resMan.GetString(name, CultureInfo.InvariantCulture); + + return temp is null + ? null + : string.Format(CultureInfo.InvariantCulture, temp, args); + } +} diff --git a/YAMDCC.Updater/Resources.resx b/YAMDCC.Updater/Strings.resx similarity index 93% rename from YAMDCC.Updater/Resources.resx rename to YAMDCC.Updater/Strings.resx index 13df744..0c09c95 100644 --- a/YAMDCC.Updater/Resources.resx +++ b/YAMDCC.Updater/Strings.resx @@ -117,13 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - - System.Runtime.CompilerServices.Unsafe.dll.gz;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - You appear to be running a development version of YAMDCC. This updater cannot handle dev versions, and will likely diff --git a/YAMDCC.Updater/System.Runtime.CompilerServices.Unsafe.dll.gz b/YAMDCC.Updater/System.Runtime.CompilerServices.Unsafe.dll.gz deleted file mode 100644 index 3a94e38..0000000 Binary files a/YAMDCC.Updater/System.Runtime.CompilerServices.Unsafe.dll.gz and /dev/null differ diff --git a/YAMDCC.Updater/UpdateForm.cs b/YAMDCC.Updater/UpdateForm.cs index 4dab794..87e14de 100644 --- a/YAMDCC.Updater/UpdateForm.cs +++ b/YAMDCC.Updater/UpdateForm.cs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License along with // YAMDCC. If not, see . -using Markdig; +using MarkedNet; using System; using System.ComponentModel; using System.Diagnostics; @@ -32,6 +32,14 @@ namespace YAMDCC.Updater; internal sealed partial class UpdateForm : Form { + private static readonly Marked Markdown = new() + { + Options = new Options() + { + Gfm = true, + }, + }; + private readonly bool AutoUpdate; private Release Release; @@ -55,8 +63,8 @@ public UpdateForm(Release release = null, bool autoUpdate = false) if (release is null) { wbChangelog.DocumentText = GetHtml( - Resources.GetString("UpdatePrompt") + - (tsiPreRelease.Checked ? Resources.GetString("PreReleaseOn") : string.Empty)); + Strings.GetString("UpdatePrompt") + + (tsiPreRelease.Checked ? Strings.GetString("PreReleaseOn") : string.Empty)); } else { @@ -192,8 +200,8 @@ private void tsiPreRelease_Click(object sender, EventArgs e) if (btnUpdate.Tag is null) { wbChangelog.DocumentText = GetHtml( - Resources.GetString("UpdatePrompt") + - (tsiPreRelease.Checked ? Resources.GetString("PreReleaseOn") : string.Empty)); + Strings.GetString("UpdatePrompt") + + (tsiPreRelease.Checked ? Strings.GetString("PreReleaseOn") : string.Empty)); } } @@ -212,8 +220,8 @@ private async void CheckUpdate() catch (HttpRequestException ex) { SetProgress(0, $"ERROR: {(ex.InnerException is WebException ex2 ? ex2.Message : ex.Message)}"); - wbChangelog.DocumentText = GetHtml(Markdown.ToHtml(Resources.GetString( - "errCheckUpdate", ex))); + wbChangelog.DocumentText = GetHtml(Strings.GetString( + "errCheckUpdate", ex)); btnUpdate.Enabled = true; btnOptions.Enabled = true; return; @@ -221,8 +229,8 @@ private async void CheckUpdate() if (Release is null) { - SetProgress(0, Resources.GetString("errNoReleaseS")); - wbChangelog.DocumentText = GetHtml(Resources.GetString( + SetProgress(0, Strings.GetString("errNoReleaseS")); + wbChangelog.DocumentText = GetHtml(Strings.GetString( "errNoRelease")); } else @@ -264,11 +272,11 @@ private void UpdateAvailable() : $"{Release.Author.Login}"; // show the changelog of the latest release from GitHub - wbChangelog.DocumentText = GetHtml(Resources.GetString("Changelog", + wbChangelog.DocumentText = GetHtml(Strings.GetString("Changelog", Release.Name, - Release.PreRelease ? Resources.GetString("PreReleaseTag") : string.Empty, + Release.PreRelease ? Strings.GetString("PreReleaseTag") : string.Empty, $"{Release.PublishedAt.ToLocalTime():g}", - authorLink, Release.HtmlUrl, Markdown.ToHtml(Release.Body)), true); + authorLink, Release.HtmlUrl, Markdown.Parse(Release.Body)), true); btnUpdate.Text = $"&Update to {Release.TagName}"; btnUpdate.Tag = "update"; @@ -314,7 +322,7 @@ private void InstallUpdate() { if (ex.ErrorCode == -2147467259) // 0x80004005 - operation cancelled by user { - SetProgress(100, Resources.GetString("InstallPrompt")); + SetProgress(100, Strings.GetString("InstallPrompt")); Utils.ShowError("Admin is required to finish update install."); btnUpdate.Tag = "install"; btnUpdate.Text = "Install update"; @@ -335,7 +343,7 @@ private void SetTitleText(string title) private static string GetHtml(string text, bool html = false) { - return Resources.GetString("HtmlTemplate", html ? text : Markdown.ToHtml(text)); + return Strings.GetString("HtmlTemplate", html ? text : Markdown.Parse(text)); } private void SetProgress(int progress, string text) diff --git a/YAMDCC.Updater/YAMDCC.Updater.csproj b/YAMDCC.Updater/YAMDCC.Updater.csproj index 7d254fd..8d2f798 100644 --- a/YAMDCC.Updater/YAMDCC.Updater.csproj +++ b/YAMDCC.Updater/YAMDCC.Updater.csproj @@ -33,7 +33,7 @@ - + @@ -44,7 +44,7 @@ - + diff --git a/YAMDCC.Updater/packages.lock.json b/YAMDCC.Updater/packages.lock.json index 0a88c6e..69ce30d 100644 --- a/YAMDCC.Updater/packages.lock.json +++ b/YAMDCC.Updater/packages.lock.json @@ -2,14 +2,11 @@ "version": 1, "dependencies": { ".NETFramework,Version=v4.8": { - "Markdig": { + "MarkedNet": { "type": "Direct", - "requested": "[0.40.0, )", - "resolved": "0.40.0", - "contentHash": "4ve14zs+gt1irldTQE3y5FLAHuzmhW7T99lAAvVipe/q2LWT/nUCO0iICb9TXGvMX6n7Z1OZroFXkdSy91rO8w==", - "dependencies": { - "System.Memory": "4.5.5" - } + "requested": "[2.1.4, )", + "resolved": "2.1.4", + "contentHash": "7JSHAIeNM1Zsmza046u6OIBx36GzzGDLjKCSxroAeYKYiAFQ+34dGfbx06nX1KR1RhxBucGyZxlDD1fv/33FIg==" }, "Newtonsoft.Json": { "type": "Direct", @@ -23,31 +20,6 @@ "resolved": "2.11.0", "contentHash": "p9wH58XSNIyUtO7PIFAEldaKUzpYmlj+YWAfnUqBKnGxIZRY51I9BrsBGJijUVwlxrgmLLPUigRIv2ZTD4uPJA==" }, - "System.Buffers": { - "type": "Transitive", - "resolved": "4.5.1", - "contentHash": "Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg==" - }, - "System.Memory": { - "type": "Transitive", - "resolved": "4.5.5", - "contentHash": "XIWiDvKPXaTveaB7HVganDlOCRoj03l+jrwNvcge/t8vhGYKvqV+dMv6G4SAX2NoNmN0wZfVPTAlFwZcZvVOUw==", - "dependencies": { - "System.Buffers": "4.5.1", - "System.Numerics.Vectors": "4.5.0", - "System.Runtime.CompilerServices.Unsafe": "4.5.3" - } - }, - "System.Numerics.Vectors": { - "type": "Transitive", - "resolved": "4.5.0", - "contentHash": "QQTlPTl06J/iiDbJCiepZ4H//BVraReU4O4EoRw1U02H5TLUIT7xn3GnDp9AXPSlJUDyFs4uWjWafNX6WrAojQ==" - }, - "System.Runtime.CompilerServices.Unsafe": { - "type": "Transitive", - "resolved": "4.5.3", - "contentHash": "3TIsJhD1EiiT0w2CcDMN/iSSwnNnsrnbzeVHSKkaEgV85txMprmuO+Yq2AdSbeVGcg28pdNDTPK87tJhX7VFHw==" - }, "yamdcc.common": { "type": "Project", "dependencies": {