-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Create new Common library, with a shared global config and common methods - Reword a fan profile recommendation
- Loading branch information
1 parent
72401d6
commit 43f99f9
Showing
36 changed files
with
640 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://www.gnu.org/licenses/>. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Xml; | ||
using System.Xml.Serialization; | ||
using YAMDCC.Logs; | ||
|
||
namespace YAMDCC.Common | ||
{ | ||
public class CommonConfig | ||
{ | ||
/// <summary> | ||
/// The config version expected when loading a config. | ||
/// </summary> | ||
[XmlIgnore] | ||
public const int ExpectedVer = 1; | ||
|
||
/// <summary> | ||
/// The config version. Should be the same as <see cref="ExpectedVer"/> | ||
/// unless the config is newer or invalid. | ||
/// </summary> | ||
[XmlAttribute] | ||
public int Ver { get; set; } | ||
|
||
/// <summary> | ||
/// The product this <see cref="CommonConfig"/> was made for. | ||
/// </summary> | ||
[XmlAttribute] | ||
public string App { get; set; } | ||
|
||
[XmlElement] | ||
public LogLevel LogLevel { get; set; } = LogLevel.Debug; | ||
|
||
/// <summary> | ||
/// Loads the global app config XML and returns a | ||
/// <see cref="CommonConfig"/> object. | ||
/// </summary> | ||
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; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Saves the global app config XML. | ||
/// </summary> | ||
/// <exception cref="InvalidOperationException"/> | ||
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); | ||
} | ||
} | ||
|
||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...figEditor/Dialogs/CrashDialog.Designer.cs → ...CC.Common/Dialogs/CrashDialog.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...Editor/Dialogs/ProgressDialog.Designer.cs → ...Common/Dialogs/ProgressDialog.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ditor/Dialogs/TextInputDialog.Designer.cs → ...ommon/Dialogs/TextInputDialog.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...gEditor/Dialogs/VersionDialog.Designer.cs → ....Common/Dialogs/VersionDialog.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <https://www.gnu.org/licenses/>. | ||
|
||
using System.Globalization; | ||
using System.Resources; | ||
|
||
namespace YAMDCC.Common | ||
{ | ||
/// <summary> | ||
/// A resource class for retrieving strings. | ||
/// </summary> | ||
internal static class Strings | ||
{ | ||
private static ResourceManager resMan; | ||
|
||
/// <summary> | ||
/// Gets a string from the underlying resource file. | ||
/// </summary> | ||
/// <remarks> | ||
/// This function internally calls | ||
/// <see cref="ResourceManager.GetString(string)"/> to retrieve the string. | ||
/// </remarks> | ||
/// <param name="name"> | ||
/// The name of the string to find. | ||
/// </param> | ||
/// <returns> | ||
/// <para>The value of the specified string name, if found.</para> | ||
/// <para><c>null</c> if the string couldn't be found.</para> | ||
/// </returns> | ||
public static string GetString(string name) | ||
{ | ||
resMan ??= new ResourceManager(typeof(Strings)); | ||
return resMan.GetString(name, CultureInfo.InvariantCulture); | ||
} | ||
|
||
/// <summary> | ||
/// Gets a string from the underlying resource file, and | ||
/// replaces format objects with their string representation. | ||
/// </summary> | ||
/// <param name="name"> | ||
/// The name of the string to find. | ||
/// </param> | ||
/// <param name="arg0"> | ||
/// The object to format the string with. | ||
/// </param> | ||
/// <returns> | ||
/// <para> | ||
/// The formatted string corresponding to | ||
/// the specified string name, if found. | ||
/// </para> | ||
/// <para><c>null</c> if the string couldn't be found.</para> | ||
/// </returns> | ||
public static string GetString(string name, object arg0) | ||
{ | ||
string temp = GetString(name); | ||
return temp is null | ||
? null | ||
: string.Format(CultureInfo.InvariantCulture, temp, arg0); | ||
} | ||
} | ||
} |
Oops, something went wrong.