diff --git a/YAMDCC.Common/CommonConfig.cs b/YAMDCC.Common/CommonConfig.cs new file mode 100644 index 0000000..59fc3a0 --- /dev/null +++ b/YAMDCC.Common/CommonConfig.cs @@ -0,0 +1,101 @@ +// This file is part of YAMDCC (Yet Another MSI Dragon Center Clone). +// Copyright © Sparronator9999 and Contributors 2023-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; +using System.IO; +using System.Xml; +using System.Xml.Serialization; +using YAMDCC.Logs; + +namespace YAMDCC.Common +{ + public class CommonConfig + { + /// + /// The config version expected when loading a config. + /// + [XmlIgnore] + public const int ExpectedVer = 1; + + /// + /// The config version. Should be the same as + /// unless the config is newer or invalid. + /// + [XmlAttribute] + public int Ver { get; set; } + + /// + /// The product this was made for. + /// + [XmlAttribute] + public string App { get; set; } + + [XmlElement] + public LogLevel LogLevel { get; set; } = LogLevel.Debug; + + /// + /// Loads the global app config XML and returns a + /// object. + /// + public static CommonConfig Load() + { + XmlSerializer serialiser = new(typeof(CommonConfig)); + try + { + using (XmlReader reader = XmlReader.Create(Paths.GlobalConf)) + { + CommonConfig cfg = (CommonConfig)serialiser.Deserialize(reader); + return cfg.Ver == ExpectedVer + ? cfg + : throw new InvalidConfigException(); + } + } + catch (Exception ex) + { + if (ex is FileNotFoundException + or InvalidOperationException + or InvalidConfigException) + { + return new CommonConfig(); + } + else + { + throw; + } + } + } + + /// + /// Saves the global app config XML. + /// + /// + public void Save() + { + XmlSerializer serializer = new(typeof(CommonConfig)); + XmlWriterSettings settings = new() + { + Indent = true, + IndentChars = "\t", + }; + + using (XmlWriter writer = XmlWriter.Create(Paths.GlobalConf, settings)) + { + serializer.Serialize(writer, this); + } + } + + } +} diff --git a/YAMDCC.ConfigEditor/Dialogs/CrashDialog.Designer.cs b/YAMDCC.Common/Dialogs/CrashDialog.Designer.cs similarity index 99% rename from YAMDCC.ConfigEditor/Dialogs/CrashDialog.Designer.cs rename to YAMDCC.Common/Dialogs/CrashDialog.Designer.cs index e0cc6ec..7c68f75 100644 --- a/YAMDCC.ConfigEditor/Dialogs/CrashDialog.Designer.cs +++ b/YAMDCC.Common/Dialogs/CrashDialog.Designer.cs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License along with // YAMDCC. If not, see . -namespace YAMDCC.ConfigEditor.Dialogs +namespace YAMDCC.Common.Dialogs { partial class CrashDialog { diff --git a/YAMDCC.ConfigEditor/Dialogs/CrashDialog.cs b/YAMDCC.Common/Dialogs/CrashDialog.cs similarity index 95% rename from YAMDCC.ConfigEditor/Dialogs/CrashDialog.cs rename to YAMDCC.Common/Dialogs/CrashDialog.cs index c71ef75..70a933d 100644 --- a/YAMDCC.ConfigEditor/Dialogs/CrashDialog.cs +++ b/YAMDCC.Common/Dialogs/CrashDialog.cs @@ -18,9 +18,9 @@ using System.Diagnostics; using System.Windows.Forms; -namespace YAMDCC.ConfigEditor.Dialogs +namespace YAMDCC.Common.Dialogs { - internal sealed partial class CrashDialog : Form + public sealed partial class CrashDialog : Form { public CrashDialog(Exception ex) { diff --git a/YAMDCC.ConfigEditor/Dialogs/CrashDialog.resx b/YAMDCC.Common/Dialogs/CrashDialog.resx similarity index 100% rename from YAMDCC.ConfigEditor/Dialogs/CrashDialog.resx rename to YAMDCC.Common/Dialogs/CrashDialog.resx diff --git a/YAMDCC.ConfigEditor/Dialogs/ProgressDialog.Designer.cs b/YAMDCC.Common/Dialogs/ProgressDialog.Designer.cs similarity index 99% rename from YAMDCC.ConfigEditor/Dialogs/ProgressDialog.Designer.cs rename to YAMDCC.Common/Dialogs/ProgressDialog.Designer.cs index aa8c032..24a6c9b 100644 --- a/YAMDCC.ConfigEditor/Dialogs/ProgressDialog.Designer.cs +++ b/YAMDCC.Common/Dialogs/ProgressDialog.Designer.cs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License along with // YAMDCC. If not, see . -namespace YAMDCC.ConfigEditor.Dialogs +namespace YAMDCC.Common.Dialogs { partial class ProgressDialog { diff --git a/YAMDCC.ConfigEditor/Dialogs/ProgressDialog.cs b/YAMDCC.Common/Dialogs/ProgressDialog.cs similarity index 97% rename from YAMDCC.ConfigEditor/Dialogs/ProgressDialog.cs rename to YAMDCC.Common/Dialogs/ProgressDialog.cs index 97ba1e9..b43d2ea 100644 --- a/YAMDCC.ConfigEditor/Dialogs/ProgressDialog.cs +++ b/YAMDCC.Common/Dialogs/ProgressDialog.cs @@ -19,9 +19,9 @@ using System.Globalization; using System.Windows.Forms; -namespace YAMDCC.ConfigEditor.Dialogs +namespace YAMDCC.Common.Dialogs { - internal sealed partial class ProgressDialog : Form + public sealed partial class ProgressDialog : Form { #region Disable close button private const int CP_NOCLOSE_BUTTON = 0x200; @@ -37,8 +37,8 @@ protected override CreateParams CreateParams } #endregion - public bool Cancelled; - public object Result; + public bool Cancelled { get; set; } + public object Result { get; set; } private readonly object Argument; private readonly string Caption; diff --git a/YAMDCC.ConfigEditor/Dialogs/ProgressDialog.resx b/YAMDCC.Common/Dialogs/ProgressDialog.resx similarity index 100% rename from YAMDCC.ConfigEditor/Dialogs/ProgressDialog.resx rename to YAMDCC.Common/Dialogs/ProgressDialog.resx diff --git a/YAMDCC.ConfigEditor/Dialogs/TextInputDialog.Designer.cs b/YAMDCC.Common/Dialogs/TextInputDialog.Designer.cs similarity index 99% rename from YAMDCC.ConfigEditor/Dialogs/TextInputDialog.Designer.cs rename to YAMDCC.Common/Dialogs/TextInputDialog.Designer.cs index 66fb45c..13f013a 100644 --- a/YAMDCC.ConfigEditor/Dialogs/TextInputDialog.Designer.cs +++ b/YAMDCC.Common/Dialogs/TextInputDialog.Designer.cs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License along with // YAMDCC. If not, see . -namespace YAMDCC.ConfigEditor.Dialogs +namespace YAMDCC.Common.Dialogs { partial class TextInputDialog { diff --git a/YAMDCC.ConfigEditor/Dialogs/TextInputDialog.cs b/YAMDCC.Common/Dialogs/TextInputDialog.cs similarity index 92% rename from YAMDCC.ConfigEditor/Dialogs/TextInputDialog.cs rename to YAMDCC.Common/Dialogs/TextInputDialog.cs index fdb1072..668414c 100644 --- a/YAMDCC.ConfigEditor/Dialogs/TextInputDialog.cs +++ b/YAMDCC.Common/Dialogs/TextInputDialog.cs @@ -17,14 +17,14 @@ using System; using System.Windows.Forms; -namespace YAMDCC.ConfigEditor.Dialogs +namespace YAMDCC.Common.Dialogs { - internal sealed partial class TextInputDialog : Form + public sealed partial class TextInputDialog : Form { /// /// The text that the user entered in this dialog. /// - public string Result; + public string Result { get; set; } public TextInputDialog(string caption, string title, string text, bool multiline = false) { diff --git a/YAMDCC.ConfigEditor/Dialogs/TextInputDialog.resx b/YAMDCC.Common/Dialogs/TextInputDialog.resx similarity index 100% rename from YAMDCC.ConfigEditor/Dialogs/TextInputDialog.resx rename to YAMDCC.Common/Dialogs/TextInputDialog.resx diff --git a/YAMDCC.ConfigEditor/Dialogs/VersionDialog.Designer.cs b/YAMDCC.Common/Dialogs/VersionDialog.Designer.cs similarity index 99% rename from YAMDCC.ConfigEditor/Dialogs/VersionDialog.Designer.cs rename to YAMDCC.Common/Dialogs/VersionDialog.Designer.cs index 8f05762..cdb6946 100644 --- a/YAMDCC.ConfigEditor/Dialogs/VersionDialog.Designer.cs +++ b/YAMDCC.Common/Dialogs/VersionDialog.Designer.cs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License along with // YAMDCC. If not, see . -namespace YAMDCC.ConfigEditor.Dialogs +namespace YAMDCC.Common.Dialogs { partial class VersionDialog { diff --git a/YAMDCC.ConfigEditor/Dialogs/VersionDialog.cs b/YAMDCC.Common/Dialogs/VersionDialog.cs similarity index 95% rename from YAMDCC.ConfigEditor/Dialogs/VersionDialog.cs rename to YAMDCC.Common/Dialogs/VersionDialog.cs index 4897211..2664433 100644 --- a/YAMDCC.ConfigEditor/Dialogs/VersionDialog.cs +++ b/YAMDCC.Common/Dialogs/VersionDialog.cs @@ -18,9 +18,9 @@ using System.Diagnostics; using System.Windows.Forms; -namespace YAMDCC.ConfigEditor.Dialogs +namespace YAMDCC.Common.Dialogs { - internal sealed partial class VersionDialog : Form + public sealed partial class VersionDialog : Form { public VersionDialog() { diff --git a/YAMDCC.ConfigEditor/Dialogs/VersionDialog.resx b/YAMDCC.Common/Dialogs/VersionDialog.resx similarity index 100% rename from YAMDCC.ConfigEditor/Dialogs/VersionDialog.resx rename to YAMDCC.Common/Dialogs/VersionDialog.resx diff --git a/YAMDCC.Config/InvalidConfigException.cs b/YAMDCC.Common/InvalidConfigException.cs similarity index 91% rename from YAMDCC.Config/InvalidConfigException.cs rename to YAMDCC.Common/InvalidConfigException.cs index 9a4e1b7..a26b1b8 100644 --- a/YAMDCC.Config/InvalidConfigException.cs +++ b/YAMDCC.Common/InvalidConfigException.cs @@ -16,7 +16,7 @@ using System; -namespace YAMDCC.Config +namespace YAMDCC.Common { /// /// The exception thrown when an invalid is loaded. @@ -27,6 +27,6 @@ public sealed class InvalidConfigException : Exception /// Initializes a new instance of the class. /// public InvalidConfigException() - : base("The YAMDCC config was not in the expected format.") { } + : base("The config was not in the expected format.") { } } } diff --git a/YAMDCC.ConfigEditor/Paths.cs b/YAMDCC.Common/Paths.cs similarity index 94% rename from YAMDCC.ConfigEditor/Paths.cs rename to YAMDCC.Common/Paths.cs index 7c78235..e7659dd 100644 --- a/YAMDCC.ConfigEditor/Paths.cs +++ b/YAMDCC.Common/Paths.cs @@ -17,9 +17,9 @@ using System; using System.IO; -namespace YAMDCC.ConfigEditor +namespace YAMDCC.Common { - internal static class Paths + public static class Paths { /// /// The URL to this project's GitHub page. @@ -44,6 +44,9 @@ internal static class Paths /// public static readonly string Logs = Path.Combine(Data, "Logs"); + public static readonly string GlobalConf = Path.Combine(Data, "GlobalConfig.xml"); + + /// /// The path where the currently applied YAMDCC config is saved. /// diff --git a/YAMDCC.Common/Strings.cs b/YAMDCC.Common/Strings.cs new file mode 100644 index 0000000..d3f422f --- /dev/null +++ b/YAMDCC.Common/Strings.cs @@ -0,0 +1,74 @@ +// This file is part of YAMDCC (Yet Another MSI Dragon Center Clone). +// Copyright © Sparronator9999 and Contributors 2023-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.Common +{ + /// + /// A resource class for retrieving strings. + /// + 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. + /// + /// + /// 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); + } + } +} diff --git a/YAMDCC.Common/Strings.resx b/YAMDCC.Common/Strings.resx new file mode 100644 index 0000000..368eed2 --- /dev/null +++ b/YAMDCC.Common/Strings.resx @@ -0,0 +1,134 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + A fast, lightweight alternative to MSI Center for MSI laptops, written in C#. + + + Copyright © Sparronator9999 (and contributors), 2023-2025. +YAMDCC and its authors are not affiliated with Micro-Star International Co., Ltd. in any way. +Made in Australia from at least 99% Australian contributions. + + + YAMDCC has crashed! + +Before reporting a bug, try again on the latest release of YAMDCC (if available). +If the crash still occurs, please create an issue with the following crash report: + + \ No newline at end of file diff --git a/YAMDCC.ConfigEditor/Utils.cs b/YAMDCC.Common/Utils.cs similarity index 99% rename from YAMDCC.ConfigEditor/Utils.cs rename to YAMDCC.Common/Utils.cs index 6f4ac05..2ff9978 100644 --- a/YAMDCC.ConfigEditor/Utils.cs +++ b/YAMDCC.Common/Utils.cs @@ -21,12 +21,12 @@ using System.ServiceProcess; using System.Windows.Forms; -namespace YAMDCC.ConfigEditor +namespace YAMDCC.Common { /// /// A collection of miscellaneous useful utilities /// - internal static class Utils + public static class Utils { /// /// Shows an error dialog. diff --git a/YAMDCC.Common/YAMDCC.Common.csproj b/YAMDCC.Common/YAMDCC.Common.csproj new file mode 100644 index 0000000..8966d31 --- /dev/null +++ b/YAMDCC.Common/YAMDCC.Common.csproj @@ -0,0 +1,57 @@ + + + latest-recommended + YAMDCC common code library + Sparronator9999 + Copyright © 2023-2025 Sparronator9999 (and Contributors) + True + 13.0 + Library + GPL-3.0-or-later + true + win7-x64;win7-x86;win-x64;win-x86 + net48 + YAMDCC common code library + 1.0.0 + dev + + + none + + + + + + + + + + + + + + + + + + + + + Form + + + Form + + + Form + + + Form + + + + + Designer + + + diff --git a/YAMDCC.Common/packages.lock.json b/YAMDCC.Common/packages.lock.json new file mode 100644 index 0000000..c9a75b3 --- /dev/null +++ b/YAMDCC.Common/packages.lock.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "dependencies": { + ".NETFramework,Version=v4.8": { + "yamdcc.logs": { + "type": "Project" + } + }, + ".NETFramework,Version=v4.8/win-x64": {}, + ".NETFramework,Version=v4.8/win-x86": {}, + ".NETFramework,Version=v4.8/win7-x64": {}, + ".NETFramework,Version=v4.8/win7-x86": {} + } +} \ No newline at end of file diff --git a/YAMDCC.Config/YAMDCC.Config.csproj b/YAMDCC.Config/YAMDCC.Config.csproj index 4e3bd41..85c003b 100644 --- a/YAMDCC.Config/YAMDCC.Config.csproj +++ b/YAMDCC.Config/YAMDCC.Config.csproj @@ -18,4 +18,7 @@ none + + + diff --git a/YAMDCC.Config/YAMDCC_Config.cs b/YAMDCC.Config/YAMDCC_Config.cs index 6d435ab..1f941fc 100644 --- a/YAMDCC.Config/YAMDCC_Config.cs +++ b/YAMDCC.Config/YAMDCC_Config.cs @@ -18,6 +18,7 @@ using System.IO; using System.Xml; using System.Xml.Serialization; +using YAMDCC.Common; namespace YAMDCC.Config { diff --git a/YAMDCC.Config/packages.lock.json b/YAMDCC.Config/packages.lock.json index 9cb623c..5da4846 100644 --- a/YAMDCC.Config/packages.lock.json +++ b/YAMDCC.Config/packages.lock.json @@ -1,7 +1,17 @@ { "version": 1, "dependencies": { - ".NETFramework,Version=v4.8": {}, + ".NETFramework,Version=v4.8": { + "yamdcc.common": { + "type": "Project", + "dependencies": { + "YAMDCC.Logs": "[1.0.0-dev, )" + } + }, + "yamdcc.logs": { + "type": "Project" + } + }, ".NETFramework,Version=v4.8/win-x64": {}, ".NETFramework,Version=v4.8/win-x86": {}, ".NETFramework,Version=v4.8/win7-x64": {}, diff --git a/YAMDCC.ConfigEditor/MainWindow.Designer.cs b/YAMDCC.ConfigEditor/MainWindow.Designer.cs index 5ab88d8..a2dabb8 100644 --- a/YAMDCC.ConfigEditor/MainWindow.Designer.cs +++ b/YAMDCC.ConfigEditor/MainWindow.Designer.cs @@ -50,6 +50,7 @@ private void InitializeComponent() System.Windows.Forms.ToolStripSeparator sep3; System.Windows.Forms.ToolStripSeparator sep4; System.Windows.Forms.ToolStripSeparator sep5; + System.Windows.Forms.ToolStripMenuItem tsiLogLevel; System.Windows.Forms.TabControl tcMain; System.Windows.Forms.TabPage tabFanControl; System.Windows.Forms.FlowLayoutPanel flwFanSelect; @@ -77,6 +78,12 @@ private void InitializeComponent() this.tsiProfDel = new System.Windows.Forms.ToolStripMenuItem(); this.tsiECtoConf = new System.Windows.Forms.ToolStripMenuItem(); this.tsiECMon = new System.Windows.Forms.ToolStripMenuItem(); + this.tsiLogNone = new System.Windows.Forms.ToolStripMenuItem(); + this.tsiLogDebug = new System.Windows.Forms.ToolStripMenuItem(); + this.tsiLogInfo = new System.Windows.Forms.ToolStripMenuItem(); + this.tsiLogWarn = new System.Windows.Forms.ToolStripMenuItem(); + this.tsiLogError = new System.Windows.Forms.ToolStripMenuItem(); + this.tsiLogFatal = new System.Windows.Forms.ToolStripMenuItem(); this.tsiStopSvc = new System.Windows.Forms.ToolStripMenuItem(); this.tsiUninstall = new System.Windows.Forms.ToolStripMenuItem(); this.tsiHelp = new System.Windows.Forms.ToolStripMenuItem(); @@ -111,6 +118,7 @@ private void InitializeComponent() sep3 = new System.Windows.Forms.ToolStripSeparator(); sep4 = new System.Windows.Forms.ToolStripSeparator(); sep5 = new System.Windows.Forms.ToolStripSeparator(); + tsiLogLevel = new System.Windows.Forms.ToolStripMenuItem(); tcMain = new System.Windows.Forms.TabControl(); tabFanControl = new System.Windows.Forms.TabPage(); flwFanSelect = new System.Windows.Forms.FlowLayoutPanel(); @@ -228,6 +236,7 @@ private void InitializeComponent() sep4, this.tsiECMon, sep5, + tsiLogLevel, this.tsiStopSvc, this.tsiUninstall}); this.tsiOptions.Name = "tsiOptions"; @@ -306,6 +315,61 @@ private void InitializeComponent() sep5.Name = "sep5"; sep5.Size = new System.Drawing.Size(254, 6); // + // tsiLogLevel + // + tsiLogLevel.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.tsiLogDebug, + this.tsiLogInfo, + this.tsiLogWarn, + this.tsiLogError, + this.tsiLogFatal, + this.tsiLogNone}); + tsiLogLevel.Name = "tsiLogLevel"; + tsiLogLevel.Size = new System.Drawing.Size(257, 22); + tsiLogLevel.Text = "Service log level"; + // + // tsiLogNone + // + this.tsiLogNone.Name = "tsiLogNone"; + this.tsiLogNone.Size = new System.Drawing.Size(180, 22); + this.tsiLogNone.Text = "Disabled"; + this.tsiLogNone.Click += new System.EventHandler(this.tsiLogNone_Click); + // + // tsiLogDebug + // + this.tsiLogDebug.Name = "tsiLogDebug"; + this.tsiLogDebug.Size = new System.Drawing.Size(180, 22); + this.tsiLogDebug.Text = "Debug"; + this.tsiLogDebug.Click += new System.EventHandler(this.tsiLogDebug_Click); + // + // tsiLogInfo + // + this.tsiLogInfo.Name = "tsiLogInfo"; + this.tsiLogInfo.Size = new System.Drawing.Size(180, 22); + this.tsiLogInfo.Text = "Info"; + this.tsiLogInfo.Click += new System.EventHandler(this.tsiLogInfo_Click); + // + // tsiLogWarn + // + this.tsiLogWarn.Name = "tsiLogWarn"; + this.tsiLogWarn.Size = new System.Drawing.Size(180, 22); + this.tsiLogWarn.Text = "Warning"; + this.tsiLogWarn.Click += new System.EventHandler(this.tsiLogWarn_Click); + // + // tsiLogError + // + this.tsiLogError.Name = "tsiLogError"; + this.tsiLogError.Size = new System.Drawing.Size(180, 22); + this.tsiLogError.Text = "Error"; + this.tsiLogError.Click += new System.EventHandler(this.tsiLogError_Click); + // + // tsiLogFatal + // + this.tsiLogFatal.Name = "tsiLogFatal"; + this.tsiLogFatal.Size = new System.Drawing.Size(180, 22); + this.tsiLogFatal.Text = "Fatal"; + this.tsiLogFatal.Click += new System.EventHandler(this.tsiLogFatal_Click); + // // tsiStopSvc // this.tsiStopSvc.Name = "tsiStopSvc"; @@ -536,7 +600,7 @@ private void InitializeComponent() // lblPerfMode.Anchor = System.Windows.Forms.AnchorStyles.Right; lblPerfMode.AutoSize = true; - lblPerfMode.Location = new System.Drawing.Point(18, 35); + lblPerfMode.Location = new System.Drawing.Point(18, 36); lblPerfMode.Margin = new System.Windows.Forms.Padding(4, 3, 0, 3); lblPerfMode.Name = "lblPerfMode"; lblPerfMode.Size = new System.Drawing.Size(112, 15); @@ -558,7 +622,7 @@ private void InitializeComponent() // lblWinFnSwap.Anchor = System.Windows.Forms.AnchorStyles.Right; lblWinFnSwap.AutoSize = true; - lblWinFnSwap.Location = new System.Drawing.Point(3, 60); + lblWinFnSwap.Location = new System.Drawing.Point(3, 62); lblWinFnSwap.Margin = new System.Windows.Forms.Padding(3, 3, 0, 3); lblWinFnSwap.Name = "lblWinFnSwap"; lblWinFnSwap.Padding = new System.Windows.Forms.Padding(0, 0, 0, 2); @@ -570,7 +634,7 @@ private void InitializeComponent() // this.chkWinFnSwap.Anchor = System.Windows.Forms.AnchorStyles.Left; this.chkWinFnSwap.AutoSize = true; - this.chkWinFnSwap.Location = new System.Drawing.Point(133, 59); + this.chkWinFnSwap.Location = new System.Drawing.Point(133, 61); this.chkWinFnSwap.Name = "chkWinFnSwap"; this.chkWinFnSwap.Size = new System.Drawing.Size(68, 19); this.chkWinFnSwap.TabIndex = 5; @@ -582,7 +646,7 @@ private void InitializeComponent() // lblKeyLight.Anchor = System.Windows.Forms.AnchorStyles.Right; lblKeyLight.AutoSize = true; - lblKeyLight.Location = new System.Drawing.Point(18, 99); + lblKeyLight.Location = new System.Drawing.Point(18, 101); lblKeyLight.Margin = new System.Windows.Forms.Padding(3, 3, 0, 3); lblKeyLight.Name = "lblKeyLight"; lblKeyLight.Size = new System.Drawing.Size(112, 15); @@ -595,7 +659,7 @@ private void InitializeComponent() flwKeyLight.Controls.Add(this.lblKeyLightLow); flwKeyLight.Controls.Add(this.tbKeyLight); flwKeyLight.Controls.Add(this.lblKeyLightHigh); - flwKeyLight.Location = new System.Drawing.Point(130, 81); + flwKeyLight.Location = new System.Drawing.Point(130, 83); flwKeyLight.Margin = new System.Windows.Forms.Padding(0); flwKeyLight.Name = "flwKeyLight"; flwKeyLight.Size = new System.Drawing.Size(225, 51); @@ -880,5 +944,11 @@ private void InitializeComponent() private System.Windows.Forms.Label lblKeyLightLow; private System.Windows.Forms.Label lblKeyLightHigh; private System.Windows.Forms.CheckBox chkChgLim; + private System.Windows.Forms.ToolStripMenuItem tsiLogNone; + private System.Windows.Forms.ToolStripMenuItem tsiLogDebug; + private System.Windows.Forms.ToolStripMenuItem tsiLogInfo; + private System.Windows.Forms.ToolStripMenuItem tsiLogWarn; + private System.Windows.Forms.ToolStripMenuItem tsiLogError; + private System.Windows.Forms.ToolStripMenuItem tsiLogFatal; } } diff --git a/YAMDCC.ConfigEditor/MainWindow.cs b/YAMDCC.ConfigEditor/MainWindow.cs index 8b2e390..53cc6bc 100644 --- a/YAMDCC.ConfigEditor/MainWindow.cs +++ b/YAMDCC.ConfigEditor/MainWindow.cs @@ -22,9 +22,11 @@ using System.Reflection; using System.Text; using System.Windows.Forms; +using YAMDCC.Common; +using YAMDCC.Common.Dialogs; using YAMDCC.Config; -using YAMDCC.ConfigEditor.Dialogs; using YAMDCC.IPC; +using YAMDCC.Logs; namespace YAMDCC.ConfigEditor { @@ -33,6 +35,8 @@ internal sealed partial class MainWindow : Form #region Fields private readonly Status AppStatus = new(); + private readonly CommonConfig GlobalConfig; + /// /// The YAMDCC config that is currently open for editing. /// @@ -104,6 +108,36 @@ public MainWindow() }; tmrSvcTimeout.Tick += tmrSvcTimeout_Tick; + GlobalConfig = CommonConfig.Load(); + if (GlobalConfig.App == "YAMDCC") + { + switch (GlobalConfig.LogLevel) + { + case LogLevel.None: + tsiLogNone.Checked = true; + break; + case LogLevel.Fatal: + tsiLogFatal.Checked = true; + break; + case LogLevel.Error: + tsiLogError.Checked = true; + break; + case LogLevel.Warn: + tsiLogWarn.Checked = true; + break; + case LogLevel.Info: + tsiLogInfo.Checked = true; + break; + case LogLevel.Debug: + tsiLogDebug.Checked = true; + break; + } + } + else + { + tsiLogDebug.Checked = true; + } + DisableAll(); } @@ -157,6 +191,8 @@ private void MainWindow_Closing(object sender, FormClosingEventArgs e) { SendServiceMessage(new ServiceCommand(Command.FullBlast, "0")); } + GlobalConfig.App = "YAMDCC"; + GlobalConfig.Save(); } private void OnProcessExit(object sender, EventArgs e) @@ -1091,6 +1127,66 @@ private static Label FanCurveLabel(string text, float scale, ContentAlignment te }; } + private void tsiLogNone_Click(object sender, EventArgs e) + { + tsiLogNone.Checked = true; + tsiLogDebug.Checked = false; + tsiLogInfo.Checked = false; + tsiLogWarn.Checked = false; + tsiLogError.Checked = false; + tsiLogFatal.Checked = false; + } + + private void tsiLogDebug_Click(object sender, EventArgs e) + { + tsiLogNone.Checked = false; + tsiLogDebug.Checked = true; + tsiLogInfo.Checked = false; + tsiLogWarn.Checked = false; + tsiLogError.Checked = false; + tsiLogFatal.Checked = false; + } + + private void tsiLogInfo_Click(object sender, EventArgs e) + { + tsiLogNone.Checked = false; + tsiLogDebug.Checked = false; + tsiLogInfo.Checked = true; + tsiLogWarn.Checked = false; + tsiLogError.Checked = false; + tsiLogFatal.Checked = false; + } + + private void tsiLogWarn_Click(object sender, EventArgs e) + { + tsiLogNone.Checked = false; + tsiLogDebug.Checked = false; + tsiLogInfo.Checked = false; + tsiLogWarn.Checked = true; + tsiLogError.Checked = false; + tsiLogFatal.Checked = false; + } + + private void tsiLogError_Click(object sender, EventArgs e) + { + tsiLogNone.Checked = false; + tsiLogDebug.Checked = false; + tsiLogInfo.Checked = false; + tsiLogWarn.Checked = false; + tsiLogError.Checked = true; + tsiLogFatal.Checked = false; + } + + private void tsiLogFatal_Click(object sender, EventArgs e) + { + tsiLogNone.Checked = false; + tsiLogDebug.Checked = false; + tsiLogInfo.Checked = false; + tsiLogWarn.Checked = false; + tsiLogError.Checked = false; + tsiLogFatal.Checked = true; + } + private static NumericUpDown FanCurveNUD(int tag, float scale) { return new NumericUpDown() diff --git a/YAMDCC.ConfigEditor/MainWindow.resx b/YAMDCC.ConfigEditor/MainWindow.resx index 282df58..ff92125 100644 --- a/YAMDCC.ConfigEditor/MainWindow.resx +++ b/YAMDCC.ConfigEditor/MainWindow.resx @@ -138,6 +138,9 @@ False + + False + False diff --git a/YAMDCC.ConfigEditor/Program.cs b/YAMDCC.ConfigEditor/Program.cs index 6cfa76a..c6b4967 100644 --- a/YAMDCC.ConfigEditor/Program.cs +++ b/YAMDCC.ConfigEditor/Program.cs @@ -20,7 +20,8 @@ using System.Security.Principal; using System.ServiceProcess; using System.Windows.Forms; -using YAMDCC.ConfigEditor.Dialogs; +using YAMDCC.Common; +using YAMDCC.Common.Dialogs; namespace YAMDCC.ConfigEditor { diff --git a/YAMDCC.ConfigEditor/Strings.resx b/YAMDCC.ConfigEditor/Strings.resx index 7f9cd5c..1880ac6 100644 --- a/YAMDCC.ConfigEditor/Strings.resx +++ b/YAMDCC.ConfigEditor/Strings.resx @@ -117,9 +117,6 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - A fast, lightweight alternative to MSI Center for MSI laptops, written in C#. - Please enter a name for your new fan profile: @@ -317,11 +314,6 @@ Make sure to save your config (using the "Save config" button)! Your laptop hasn't rebooted yet following a request to copy the default fan profiles of your laptop to the loaded config. Cancel copying the default fan profiles and continue loading YAMDCC? - - - Copyright © Sparronator9999 (and contributors), 2023-2025. -YAMDCC and its authors are not affiliated with Micro-Star International Co., Ltd. in any way. -Made in Australia from at least 99% Australian contributions. This is the temperature that the component being cooled by @@ -339,8 +331,7 @@ this fan must cool down to before the fan slows down. Recommended values: Set every down threshold to ~3°C below the next up threshold (i.e. the one diagonally up and to the right of this down threshold). -Increase the gap (e.g. to 5°C) if your fan often cycles on and off -or between two speeds while idling. +Increase the gap (e.g. to 5°C) if your fan often quickly cycles between this speed and the next one up. This is the fan speed that the fan will run at when the component's @@ -361,12 +352,6 @@ Note that this is different from Windows' power plans. Performance mode description: {0} - - - YAMDCC has crashed! - -Before reporting a bug, try again on the latest release of YAMDCC (if available). -If the crash still occurs, please create an issue with the following crash report: Installing YAMDCC service. This may take some time... diff --git a/YAMDCC.ConfigEditor/YAMDCC.ConfigEditor.csproj b/YAMDCC.ConfigEditor/YAMDCC.ConfigEditor.csproj index b857e3f..e886889 100644 --- a/YAMDCC.ConfigEditor/YAMDCC.ConfigEditor.csproj +++ b/YAMDCC.ConfigEditor/YAMDCC.ConfigEditor.csproj @@ -27,9 +27,6 @@ none - - - @@ -40,6 +37,7 @@ + @@ -60,11 +58,6 @@ - - - - - diff --git a/YAMDCC.ConfigEditor/packages.lock.json b/YAMDCC.ConfigEditor/packages.lock.json index ebe8fee..8128602 100644 --- a/YAMDCC.ConfigEditor/packages.lock.json +++ b/YAMDCC.ConfigEditor/packages.lock.json @@ -86,8 +86,17 @@ "System.Runtime.CompilerServices.Unsafe": "4.5.3" } }, + "yamdcc.common": { + "type": "Project", + "dependencies": { + "YAMDCC.Logs": "[1.0.0-dev, )" + } + }, "yamdcc.config": { - "type": "Project" + "type": "Project", + "dependencies": { + "YAMDCC.Common": "[1.0.0-dev, )" + } }, "yamdcc.ecaccess": { "type": "Project" @@ -104,9 +113,10 @@ "yamdccsvc": { "type": "Project", "dependencies": { + "YAMDCC.Common": "[1.0.0-dev, )", "YAMDCC.Config": "[1.0.0-dev, )", "YAMDCC.ECAccess": "[1.0.0-dev, )", - "YAMDCC.IPC": "[2.1.1-release, )", + "YAMDCC.IPC": "[2.1.2-release, )", "YAMDCC.Logs": "[1.0.0-dev, )" } } diff --git a/YAMDCC.Service/FanControlService.cs b/YAMDCC.Service/FanControlService.cs index 807b155..2fb7824 100644 --- a/YAMDCC.Service/FanControlService.cs +++ b/YAMDCC.Service/FanControlService.cs @@ -22,6 +22,7 @@ using System.IO.Pipes; using System.ServiceProcess; using System.Timers; +using YAMDCC.Common; using YAMDCC.Config; using YAMDCC.ECAccess; using YAMDCC.IPC; @@ -121,7 +122,7 @@ protected override void OnStart(string[] args) int rebootFlag = -1; try { - StreamReader sr = new(Paths.ECtoConfPending); + StreamReader sr = new(Paths.ECToConfPending); if (int.TryParse(sr.ReadToEnd(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int value)) { rebootFlag = value; @@ -131,7 +132,7 @@ protected override void OnStart(string[] args) if (rebootFlag == 0) { ECToConf(); - File.Delete(Paths.ECtoConfPending); + File.Delete(Paths.ECToConfPending); } } catch (FileNotFoundException) { } @@ -160,7 +161,7 @@ protected override void OnShutdown() int rebootFlag = -1; try { - StreamReader sr = new(Paths.ECtoConfPending); + StreamReader sr = new(Paths.ECToConfPending); try { if (int.TryParse(sr.ReadToEnd(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int value)) @@ -175,7 +176,7 @@ protected override void OnShutdown() if (rebootFlag == 1) { - StreamWriter sw = new(Paths.ECtoConfPending); + StreamWriter sw = new(Paths.ECToConfPending); try { sw.Write(0); diff --git a/YAMDCC.Service/Paths.cs b/YAMDCC.Service/Paths.cs deleted file mode 100644 index 6edc8ea..0000000 --- a/YAMDCC.Service/Paths.cs +++ /dev/null @@ -1,54 +0,0 @@ -// This file is part of YAMDCC (Yet Another MSI Dragon Center Clone). -// Copyright © Sparronator9999 and Contributors 2023-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; -using System.IO; - -namespace YAMDCC.Service -{ - internal static class Paths - { - /// - /// The path where program data is stored. - /// - /// - /// (C:\ProgramData\Sparronator9999\YAMDCC on Windows) - /// - public static readonly string Data = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), - "Sparronator9999", "YAMDCC"); - - /// - /// The path where YAMDCC service logs are saved. - /// - /// - /// (C:\ProgramData\Sparronator9999\YAMDCC\Logs on Windows) - /// - public static readonly string Logs = Path.Combine(Data, "Logs"); - - /// - /// The path where the currently applied YAMDCC config is saved. - /// - /// - /// (C:\ProgramData\Sparronator9999\YAMDCC\CurrentConfig.xml on Windows) - /// - public static readonly string CurrentConfig = Path.Combine(Data, "CurrentConfig.xml"); - - public static readonly string ECToConfSuccess = Path.Combine(Data, "ECToConfSuccess"); - public static readonly string ECToConfFail = Path.Combine(Data, "ECToConfFail"); - public static readonly string ECtoConfPending = Path.Combine(Data, "ECToConfPending"); - } -} diff --git a/YAMDCC.Service/Program.cs b/YAMDCC.Service/Program.cs index 9058875..c4f39ed 100644 --- a/YAMDCC.Service/Program.cs +++ b/YAMDCC.Service/Program.cs @@ -17,6 +17,7 @@ using System; using System.ServiceProcess; using System.Windows.Forms; +using YAMDCC.Common; using YAMDCC.Logs; namespace YAMDCC.Service @@ -30,11 +31,7 @@ internal static class Program { LogDir = Paths.Logs, ConsoleLogLevel = LogLevel.None, -#if DEBUG FileLogLevel = LogLevel.Debug, -#else - FileLogLevel = LogLevel.Info, -#endif }; /// @@ -52,9 +49,16 @@ private static void Main() } else { + CommonConfig cfg = CommonConfig.Load(); Log.Info( $"OS version: {Environment.OSVersion}\n" + $"Service version: {Application.ProductVersion}"); + + if (cfg.App == "YAMDCC") + { + Log.FileLogLevel = cfg.LogLevel; + } + Log.Debug("Log level is set to debug mode."); ServiceBase.Run(new FanControlService(Log)); } diff --git a/YAMDCC.Service/YAMDCC.Service.csproj b/YAMDCC.Service/YAMDCC.Service.csproj index 15961c4..b7c4797 100644 --- a/YAMDCC.Service/YAMDCC.Service.csproj +++ b/YAMDCC.Service/YAMDCC.Service.csproj @@ -40,6 +40,7 @@ + diff --git a/YAMDCC.Service/packages.lock.json b/YAMDCC.Service/packages.lock.json index 76a75d8..d499d6a 100644 --- a/YAMDCC.Service/packages.lock.json +++ b/YAMDCC.Service/packages.lock.json @@ -86,8 +86,17 @@ "System.Runtime.CompilerServices.Unsafe": "4.5.3" } }, + "yamdcc.common": { + "type": "Project", + "dependencies": { + "YAMDCC.Logs": "[1.0.0-dev, )" + } + }, "yamdcc.config": { - "type": "Project" + "type": "Project", + "dependencies": { + "YAMDCC.Common": "[1.0.0-dev, )" + } }, "yamdcc.ecaccess": { "type": "Project" diff --git a/YAMDCC.sln b/YAMDCC.sln index 9ee314a..62e7044 100644 --- a/YAMDCC.sln +++ b/YAMDCC.sln @@ -20,6 +20,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YAMDCC.Service", "YAMDCC.Se EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "YAMDCC.Logs", "YAMDCC.Logs\YAMDCC.Logs.csproj", "{46F94C80-4C0D-43E4-9970-D1925024C99E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YAMDCC.Common", "YAMDCC.Common\YAMDCC.Common.csproj", "{EE3AF4BE-7CA3-4E37-A85F-5A157FD35960}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -50,6 +52,10 @@ Global {46F94C80-4C0D-43E4-9970-D1925024C99E}.Debug|Any CPU.Build.0 = Debug|Any CPU {46F94C80-4C0D-43E4-9970-D1925024C99E}.Release|Any CPU.ActiveCfg = Release|Any CPU {46F94C80-4C0D-43E4-9970-D1925024C99E}.Release|Any CPU.Build.0 = Release|Any CPU + {EE3AF4BE-7CA3-4E37-A85F-5A157FD35960}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE3AF4BE-7CA3-4E37-A85F-5A157FD35960}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE3AF4BE-7CA3-4E37-A85F-5A157FD35960}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE3AF4BE-7CA3-4E37-A85F-5A157FD35960}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE