mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 15:07:03 +01:00
Porting the old instance complete. Added DD necessities
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using TGServiceInterface;
|
||||
using System.Configuration;
|
||||
|
||||
namespace TGServerService
|
||||
{
|
||||
@@ -8,6 +8,11 @@ namespace TGServerService
|
||||
/// </summary>
|
||||
class DeprecatedInstanceConfig : InstanceConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// The default <see cref="ServerInstance"/> directory
|
||||
/// </summary>
|
||||
const string DefaultInstallationPath = "C:\\tgstation-server-3";
|
||||
|
||||
/// <summary>
|
||||
/// Convert the settings version 6 .NET settings file to a config json
|
||||
/// </summary>
|
||||
@@ -15,33 +20,78 @@ namespace TGServerService
|
||||
public static InstanceConfig CreateFromNETSettings()
|
||||
{
|
||||
var Config = Properties.Settings.Default;
|
||||
var result = new DeprecatedInstanceConfig((string)Config.GetPreviousVersion("ServerDirectory"))
|
||||
{
|
||||
ProjectName = (string)Config.GetPreviousVersion("ProjectName"),
|
||||
Port = (ushort)Config.GetPreviousVersion("ServerPort"),
|
||||
CommitterName = (string)Config.GetPreviousVersion("CommitterName"),
|
||||
CommitterEmail = (string)Config.GetPreviousVersion("CommitterEmail"),
|
||||
Security = (DreamDaemonSecurity)Config.GetPreviousVersion("ServerSecurity"),
|
||||
Autostart = (bool)Config.GetPreviousVersion("DDAutoStart"),
|
||||
ChatProviderData = (string)Config.GetPreviousVersion("ChatProviderData"),
|
||||
ChatProviderEntropy = (string)Config.GetPreviousVersion("ChatProviderEntropy"),
|
||||
ReattachRequired = (bool)Config.GetPreviousVersion("ReattachToDD"),
|
||||
ReattachProcessID = (int)Config.GetPreviousVersion("ReattachPID"),
|
||||
ReattachPort = (ushort)Config.GetPreviousVersion("ReattachPort"),
|
||||
ReattachCommsKey = (string)Config.GetPreviousVersion("ReattachCommsKey"),
|
||||
ReattachAPIVersion = (string)Config.GetPreviousVersion("ReattachAPIVersion"),
|
||||
AutoUpdateInterval = (ulong)Config.GetPreviousVersion("AutoUpdateInterval"),
|
||||
AuthorizedUserGroupSID = (string)Config.GetPreviousVersion("AuthorizedGroupSID")
|
||||
};
|
||||
var result = new DeprecatedInstanceConfig(LoadPreviousNetPropertyOrDefault("ServerDirectory", "C:\\tgstation-server-3"));
|
||||
// using nameof for sanity where possible
|
||||
result.ProjectName = LoadPreviousNetPropertyOrDefault(nameof(ProjectName), result.ProjectName);
|
||||
result.Port = LoadPreviousNetPropertyOrDefault("ServerPort", result.Port);
|
||||
result.CommitterName = LoadPreviousNetPropertyOrDefault(nameof(CommitterName), result.CommitterName);
|
||||
result.CommitterEmail = LoadPreviousNetPropertyOrDefault(nameof(CommitterEmail), result.CommitterEmail);
|
||||
result.Security = LoadPreviousNetPropertyOrDefault("ServerSecurity", result.Security);
|
||||
result.Autostart = LoadPreviousNetPropertyOrDefault("DDAutoStart", result.Autostart);
|
||||
result.ChatProviderData = LoadPreviousNetPropertyOrDefault(nameof(ChatProviderData), result.ChatProviderData);
|
||||
result.ChatProviderEntropy = LoadPreviousNetPropertyOrDefault(nameof(ChatProviderEntropy), result.ChatProviderEntropy);
|
||||
result.ReattachRequired = LoadPreviousNetPropertyOrDefault("ReattachToDD", result.ReattachRequired);
|
||||
result.ReattachProcessID = LoadPreviousNetPropertyOrDefault("ReattachPID", result.ReattachProcessID);
|
||||
result.ReattachPort = LoadPreviousNetPropertyOrDefault(nameof(ReattachPort), result.ReattachPort);
|
||||
result.ReattachCommsKey = LoadPreviousNetPropertyOrDefault(nameof(ReattachCommsKey), result.ReattachCommsKey);
|
||||
result.ReattachAPIVersion = LoadPreviousNetPropertyOrDefault(nameof(ReattachAPIVersion), result.ReattachAPIVersion);
|
||||
result.AutoUpdateInterval = LoadPreviousNetPropertyOrDefault(nameof(AutoUpdateInterval), result.AutoUpdateInterval);
|
||||
result.AuthorizedUserGroupSID = LoadPreviousNetPropertyOrDefault("AuthorizedGroupSID", result.AuthorizedUserGroupSID);
|
||||
result.MigrateToCurrentVersion();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a previous .NET config <paramref name="property"/> and returns it or some <paramref name="defaultValue"/> if it wasn't set
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the <paramref name="property"/></typeparam>
|
||||
/// <param name="property">The config key of the property</param>
|
||||
/// <param name="defaultValue">The default value of the <paramref name="property"/></param>
|
||||
/// <returns>The <paramref name="property"/> if it exists, otherwise the <paramref name="defaultValue"/></returns>
|
||||
static T LoadPreviousNetPropertyOrDefault<T>(string property, T defaultValue)
|
||||
{
|
||||
//try it the simple way first
|
||||
try
|
||||
{
|
||||
var result = (T)Properties.Settings.Default.GetPreviousVersion(property);
|
||||
return result == null ? defaultValue : result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
//.NET is fucking stupid
|
||||
//If we don't have the correct property in our *CURRENT* .settings file it will automatically throw an exception when it tries to load it
|
||||
//Which means we can never fucking delete config settings
|
||||
//Which is fucking retarded
|
||||
//This hooks into the settings provider and forces it to load it anyway
|
||||
var Config = Properties.Settings.Default;
|
||||
var Provider = Config.Properties[nameof(Config.SettingsVersion)].Provider; //nameof for sanity
|
||||
|
||||
var sp = new SettingsProperty(property)
|
||||
{
|
||||
PropertyType = typeof(T),
|
||||
DefaultValue = defaultValue,
|
||||
Provider = Provider
|
||||
};
|
||||
|
||||
var ProviderInterface = Provider as IApplicationSettingsProvider;
|
||||
|
||||
var result = ProviderInterface.GetPreviousVersion(Config.Context, sp);
|
||||
if (result != null && result.PropertyValue != null)
|
||||
return (T)result.PropertyValue;
|
||||
}
|
||||
catch { }
|
||||
//f u c k i t
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct a <see cref="DeprecatedInstanceConfig"/>. Used by the deserializer
|
||||
/// </summary>
|
||||
[Obsolete("This method is for use by the deserializer only.", true)]
|
||||
public DeprecatedInstanceConfig() : base(null) { }
|
||||
public DeprecatedInstanceConfig() : base(DefaultInstallationPath) { }
|
||||
|
||||
/// <summary>
|
||||
/// Construct a <see cref="DeprecatedInstanceConfig"/> for a <see cref="ServerInstance"/> at <paramref name="path"/>
|
||||
|
||||
Reference in New Issue
Block a user