Configuration Changes

- Added a check for a valid configuration file when starting the server manager.
If config file is not valid, then it will delete the config file and shutdown the manager, with a message to restart the manager.
This commit is contained in:
Brett Hewitson 2022-07-16 13:50:46 +10:00
parent 9e52ccbaa1
commit 5fff2abc91
14 changed files with 244 additions and 76 deletions

View file

@ -365,6 +365,9 @@
<setting name="DiscordUrl" serializeAs="String">
<value>https://discord.gg/cJdHJSG</value>
</setting>
<setting name="ServicePointManager_SecurityProtocol" serializeAs="String">
<value>3072</value>
</setting>
</ServerManagerTool.Config>
<ServerManagerTool.Common.CommonConfig>
<setting name="DefaultSteamAPIKey" serializeAs="String">

View file

@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.IO;
@ -50,43 +51,12 @@ namespace ServerManagerTool
public App()
{
if (string.IsNullOrWhiteSpace(Config.Default.ServerManagerUniqueKey))
{
Config.Default.ServerManagerUniqueKey = Guid.NewGuid().ToString();
}
if (!string.IsNullOrWhiteSpace(Config.Default.DataDir))
{
Config.Default.DataDir = IOUtils.NormalizeFolder(Config.Default.DataDir);
}
if (!string.IsNullOrWhiteSpace(Config.Default.ConfigDirectory))
{
Config.Default.ConfigDirectory = IOUtils.NormalizeFolder(Config.Default.ConfigDirectory);
}
if (!string.IsNullOrWhiteSpace(Config.Default.BackupPath))
{
Config.Default.BackupPath = IOUtils.NormalizeFolder(Config.Default.BackupPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.AutoUpdate_CacheDir))
{
Config.Default.AutoUpdate_CacheDir = IOUtils.NormalizeFolder(Config.Default.AutoUpdate_CacheDir);
}
App.Instance = this;
Instance = this;
ApplicationStarted = false;
Args = string.Empty;
BetaVersion = false;
Title = string.Empty;
Version = AppUtils.GetDeployedVersion(Assembly.GetEntryAssembly());
ServicePointManager.SecurityProtocol = SecurityUtils.GetSecurityProtocol(0xC00); // TLS12
AppDomain.CurrentDomain.UnhandledException += ErrorHandling.CurrentDomain_UnhandledException;
MigrateSettings();
ReconfigureLogging();
}
public bool ApplicationStarted
@ -195,6 +165,37 @@ namespace ServerManagerTool
}
}
private void CheckForValidSettings()
{
try
{
// test one property from both setting files
var upgradeConfigTest = Config.Default.UpgradeConfig;
upgradeConfigTest = CommonConfig.Default.UpgradeConfig;
// no issues fetching the setting values, must have valid files.
return;
}
catch (ConfigurationErrorsException ex)
{
// one or more issues occurred when fetching the setting values.
// we need to delete the setting files.
ConfigurationErrorsException exception = ex;
while (exception != null)
{
if (!string.IsNullOrWhiteSpace(exception.Filename) && exception.Filename.EndsWith("user.config"))
{
File.Delete(exception.Filename);
}
exception = exception.InnerException as ConfigurationErrorsException;
}
throw;
}
}
public static void DiscoverMachinePublicIP(bool forceOverride)
{
if (forceOverride || string.IsNullOrWhiteSpace(Config.Default.MachinePublicIP))
@ -309,6 +310,50 @@ namespace ServerManagerTool
{
base.OnStartup(e);
try
{
CheckForValidSettings();
}
catch (Exception ex)
{
var message = $"{ex.Message}\r\n\r\nTry restarting the server manager, if this keeps happening please report this crash to the Server Manager discord.";
var result = MessageBox.Show(message, "Server Manager crashed", MessageBoxButton.OK, MessageBoxImage.Exclamation);
Environment.Exit(1);
}
MigrateSettings();
if (string.IsNullOrWhiteSpace(Config.Default.ServerManagerUniqueKey))
{
Config.Default.ServerManagerUniqueKey = Guid.NewGuid().ToString();
}
if (!string.IsNullOrWhiteSpace(Config.Default.DataDir))
{
Config.Default.DataDir = IOUtils.NormalizeFolder(Config.Default.DataDir);
}
if (!string.IsNullOrWhiteSpace(Config.Default.ConfigDirectory))
{
Config.Default.ConfigDirectory = IOUtils.NormalizeFolder(Config.Default.ConfigDirectory);
}
if (!string.IsNullOrWhiteSpace(Config.Default.BackupPath))
{
Config.Default.BackupPath = IOUtils.NormalizeFolder(Config.Default.BackupPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.AutoUpdate_CacheDir))
{
Config.Default.AutoUpdate_CacheDir = IOUtils.NormalizeFolder(Config.Default.AutoUpdate_CacheDir);
}
ServicePointManager.SecurityProtocol = SecurityUtils.GetSecurityProtocol(Config.Default.ServicePointManager_SecurityProtocol);
AppDomain.CurrentDomain.UnhandledException += ErrorHandling.CurrentDomain_UnhandledException;
ReconfigureLogging();
_globalizer = GlobalizedApplication.Instance;
try
{

View file

@ -3255,5 +3255,14 @@ namespace ServerManagerTool {
this["Alert_OnlinePlayerCountChange"] = value;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("3072")]
public int ServicePointManager_SecurityProtocol {
get {
return ((int)(this["ServicePointManager_SecurityProtocol"]));
}
}
}
}

View file

@ -893,5 +893,8 @@
<Setting Name="Alert_OnlinePlayerCountChange" Type="System.String" Scope="User">
<Value Profile="(Default)">Online Player Count:</Value>
</Setting>
<Setting Name="ServicePointManager_SecurityProtocol" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">3072</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -30,7 +30,7 @@ namespace ServerManagerTool
{
var details = new StringBuilder();
details.AppendLine("ARK Server Manager Crash Report");
details.AppendLine("Please report this crash to the Ark Server Manager forums - https://arkservermanager.freeforums.net");
details.AppendLine($"Please report this crash to the Server Manager discord - {Config.Default.DiscordUrl}");
details.AppendLine();
details.AppendLine($"Assembly: {Assembly.GetExecutingAssembly()}");
@ -64,7 +64,7 @@ namespace ServerManagerTool
message.AppendLine($"Crash Dump: {crashFile}");
details.AppendLine();
details.AppendLine();
message.AppendLine("Please report this crash to the Ark Server Manager forums - https://arkservermanager.freeforums.net");
message.AppendLine($"Please report this crash to the Server Manager discord - {Config.Default.DiscordUrl}");
message.AppendLine("The crash log will now be opened in notepad.");
var result = MessageBox.Show(message.ToString(), "ARK Server Manager crashed", MessageBoxButton.OK, MessageBoxImage.Exclamation);

View file

@ -9,10 +9,10 @@
<entry>
<id>urn:uuid:8CDA70CF-E8B8-4B9B-AD50-AD9A8B528E5B</id>
<title>1.1.436 (1.1.436.1)</title>
<summary>1.1.436.1</summary>
<title>1.1.436 (1.1.436.2)</title>
<summary>1.1.436.2</summary>
<link href="" />
<updated>2022-07-15T00:00:00Z</updated>
<updated>2022-07-16T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
@ -20,6 +20,7 @@
<br/>
<ul>
<li>Server Status - changed the server status code to stop the status cycling and to be more accurate.</li>
<li>Added a check for a valid configuration file when starting the server manager.\r\nIf config file is not valid, then it will delete the config file and shutdown the manager, with a message to restart the manager.</li>
</ul>
</p>
</div>

View file

@ -5,7 +5,30 @@
<title>Ark Server Manager Version Feed</title>
<subtitle>This is the Ark Server Manager beta version feed.</subtitle>
<link href="https://arkservermanager.freeforums.net/" />
<updated>2022-07-15T00:00:00Z</updated>
<updated>2022-07-16T00:00:00Z</updated>
<entry>
<id>urn:uuid:8CDA70CF-E8B8-4B9B-AD50-AD9A8B528E5B</id>
<title>1.1.436 (1.1.436.2)</title>
<summary>1.1.436.2</summary>
<link href="" />
<updated>2022-07-16T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">BUGFIX</u>
<br/>
<ul>
<li>Added a check for a valid configuration file when starting the server manager.\r\nIf config file is not valid, then it will delete the config file and shutdown the manager, with a message to restart the manager.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:8CDA70CF-E8B8-4B9B-AD50-AD9A8B528E5B</id>

View file

@ -284,6 +284,9 @@
<setting name="DiscordUrl" serializeAs="String">
<value>https://discord.gg/cJdHJSG</value>
</setting>
<setting name="ServicePointManager_SecurityProtocol" serializeAs="String">
<value>3072</value>
</setting>
</ServerManagerTool.Config>
<ServerManagerTool.Common.CommonConfig>
<setting name="DefaultSteamAPIKey" serializeAs="String">

View file

@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.IO;
@ -49,43 +50,12 @@ namespace ServerManagerTool
public App()
{
if (string.IsNullOrWhiteSpace(Config.Default.ServerManagerUniqueKey))
{
Config.Default.ServerManagerUniqueKey = Guid.NewGuid().ToString();
}
if (!string.IsNullOrWhiteSpace(Config.Default.DataPath))
{
Config.Default.DataPath = IOUtils.NormalizeFolder(Config.Default.DataPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.ConfigPath))
{
Config.Default.ConfigPath = IOUtils.NormalizeFolder(Config.Default.ConfigPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.BackupPath))
{
Config.Default.BackupPath = IOUtils.NormalizeFolder(Config.Default.BackupPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.AutoUpdate_CacheDir))
{
Config.Default.AutoUpdate_CacheDir = IOUtils.NormalizeFolder(Config.Default.AutoUpdate_CacheDir);
}
App.Instance = this;
Instance = this;
ApplicationStarted = false;
Args = string.Empty;
BetaVersion = false;
Title = string.Empty;
Version = AppUtils.GetDeployedVersion(Assembly.GetEntryAssembly());
ServicePointManager.SecurityProtocol = SecurityUtils.GetSecurityProtocol(0xC00); // TLS12
AppDomain.CurrentDomain.UnhandledException += ErrorHandling.CurrentDomain_UnhandledException;
MigrateSettings();
ReconfigureLogging();
}
public bool ApplicationStarted
@ -194,6 +164,37 @@ namespace ServerManagerTool
}
}
private void CheckForValidSettings()
{
try
{
// test one property from both setting files
var upgradeConfigTest = Config.Default.UpgradeConfig;
upgradeConfigTest = CommonConfig.Default.UpgradeConfig;
// no issues fetching the setting values, must have valid files.
return;
}
catch (ConfigurationErrorsException ex)
{
// one or more issues occurred when fetching the setting values.
// we need to delete the setting files.
ConfigurationErrorsException exception = ex;
while (exception != null)
{
if (!string.IsNullOrWhiteSpace(exception.Filename) && exception.Filename.EndsWith("user.config"))
{
File.Delete(exception.Filename);
}
exception = exception.InnerException as ConfigurationErrorsException;
}
throw;
}
}
public static void DiscoverMachinePublicIP(bool forceOverride)
{
if (forceOverride || string.IsNullOrWhiteSpace(Config.Default.MachinePublicIP))
@ -308,6 +309,50 @@ namespace ServerManagerTool
{
base.OnStartup(e);
try
{
CheckForValidSettings();
}
catch (Exception ex)
{
var message = $"{ex.Message}\r\n\r\nTry restarting the server manager, if this keeps happening please report this crash to the Server Manager discord.";
var result = MessageBox.Show(message, "Server Manager crashed", MessageBoxButton.OK, MessageBoxImage.Exclamation);
Environment.Exit(1);
}
MigrateSettings();
if (string.IsNullOrWhiteSpace(Config.Default.ServerManagerUniqueKey))
{
Config.Default.ServerManagerUniqueKey = Guid.NewGuid().ToString();
}
if (!string.IsNullOrWhiteSpace(Config.Default.DataPath))
{
Config.Default.DataPath = IOUtils.NormalizeFolder(Config.Default.DataPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.ConfigPath))
{
Config.Default.ConfigPath = IOUtils.NormalizeFolder(Config.Default.ConfigPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.BackupPath))
{
Config.Default.BackupPath = IOUtils.NormalizeFolder(Config.Default.BackupPath);
}
if (!string.IsNullOrWhiteSpace(Config.Default.AutoUpdate_CacheDir))
{
Config.Default.AutoUpdate_CacheDir = IOUtils.NormalizeFolder(Config.Default.AutoUpdate_CacheDir);
}
ServicePointManager.SecurityProtocol = SecurityUtils.GetSecurityProtocol(Config.Default.ServicePointManager_SecurityProtocol);
AppDomain.CurrentDomain.UnhandledException += ErrorHandling.CurrentDomain_UnhandledException;
ReconfigureLogging();
_globalizer = GlobalizedApplication.Instance;
try
{

View file

@ -2447,5 +2447,14 @@ namespace ServerManagerTool {
this["Alert_OnlinePlayerCountChange"] = value;
}
}
[global::System.Configuration.ApplicationScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("3072")]
public int ServicePointManager_SecurityProtocol {
get {
return ((int)(this["ServicePointManager_SecurityProtocol"]));
}
}
}
}

View file

@ -671,5 +671,8 @@
<Setting Name="Alert_OnlinePlayerCountChange" Type="System.String" Scope="User">
<Value Profile="(Default)">Online Player Count:</Value>
</Setting>
<Setting Name="ServicePointManager_SecurityProtocol" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">3072</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -29,7 +29,7 @@ namespace ServerManagerTool
{
var details = new StringBuilder();
details.AppendLine("Server Manager Crash Report");
details.AppendLine($"Please report this crash to the Server Manager forums - {Config.Default.ServerManagerForumUrl}");
details.AppendLine($"Please report this crash to the Server Manager discord - {Config.Default.DiscordUrl}");
details.AppendLine();
details.AppendLine($"Assembly: {Assembly.GetEntryAssembly()}");
@ -64,7 +64,7 @@ namespace ServerManagerTool
message.AppendLine($"Crash Dump: {crashFile}");
details.AppendLine();
details.AppendLine();
message.AppendLine($"Please report this crash to the Server Manager forums - {Config.Default.ServerManagerForumUrl}");
message.AppendLine($"Please report this crash to the Server Manager discord - {Config.Default.DiscordUrl}");
message.AppendLine("The crash log will now be opened in notepad.");
var result = MessageBox.Show(message.ToString(), "Server Manager crashed", MessageBoxButton.OK, MessageBoxImage.Exclamation);

View file

@ -9,10 +9,10 @@
<entry>
<id>urn:uuid:8CDA70CF-E8B8-4B9B-AD50-AD9A8B528E5B</id>
<title>1.1.79 (1.1.79.1)</title>
<summary>1.1.79.1</summary>
<title>1.1.79 (1.1.79.2)</title>
<summary>1.1.79.2</summary>
<link href="" />
<updated>2022-07-15T00:00:00Z</updated>
<updated>2022-07-16T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
@ -20,6 +20,7 @@
<br/>
<ul>
<li>Server Status - changed the server status code to stop the status cycling and to be more accurate.</li>
<li>Added a check for a valid configuration file when starting the server manager.\r\nIf config file is not valid, then it will delete the config file and shutdown the manager, with a message to restart the manager.</li>
</ul>
</p>
</div>

View file

@ -5,7 +5,30 @@
<title>Conan Server Manager Version Feed</title>
<subtitle>This is the Conan Server Manager beta version feed.</subtitle>
<link href="https://servermanagers.freeforums.net/" />
<updated>2022-07-15T00:00:00Z</updated>
<updated>2022-07-16T00:00:00Z</updated>
<entry>
<id>urn:uuid:8CDA70CF-E8B8-4B9B-AD50-AD9A8B528E5B</id>
<title>1.1.79 (1.1.79.2)</title>
<summary>1.1.79.2</summary>
<link href="" />
<updated>2022-07-16T00:00:00Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml" style="font-family: Arial, Verdana, Helvetica, Sans-Serif;font-size: .8em;">
<p>
<u style="font-size: .9em;">BUGFIX</u>
<br/>
<ul>
<li>Added a check for a valid configuration file when starting the server manager.\r\nIf config file is not valid, then it will delete the config file and shutdown the manager, with a message to restart the manager.</li>
</ul>
</p>
</div>
</content>
<author>
<name>bletch</name>
<email>bletch1971@hotmail.com</email>
</author>
</entry>
<entry>
<id>urn:uuid:8CDA70CF-E8B8-4B9B-AD50-AD9A8B528E5B</id>