mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-25 22:17:51 +01:00
Merge pull request #365 from Cyberboss/MigrationManager
Removes remnants of .NET config from server
This commit is contained in:
@@ -11,82 +11,8 @@ namespace TGS.Server
|
||||
/// <summary>
|
||||
/// The default <see cref="Instance"/> directory
|
||||
/// </summary>
|
||||
const string DefaultInstallationPath = "C:\\tgstation-server-3";
|
||||
|
||||
/// <summary>
|
||||
/// Convert the settings version 6 .NET settings file to a config json
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="IInstanceConfig"/> based off the old .NET setting file</returns>
|
||||
public static IInstanceConfig CreateFromNETSettings()
|
||||
{
|
||||
var Config = Properties.Settings.Default;
|
||||
var result = new DeprecatedInstanceConfig(Helpers.NormalizePath(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["SettingsVersion"].Provider;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
const string DefaultInstallationPath = "C:\\TGSTATION-SERVER-3";
|
||||
|
||||
/// <summary>
|
||||
/// Construct a <see cref="DeprecatedInstanceConfig"/>. Used by the deserializer
|
||||
/// </summary>
|
||||
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace TGS.Server.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.3.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles />
|
||||
<Settings />
|
||||
</SettingsFile>
|
||||
@@ -110,11 +110,6 @@
|
||||
<Compile Include="Instance\Interop.cs" />
|
||||
<Compile Include="Instance\PreactionHandler.cs" />
|
||||
<Compile Include="ProcessExtension.cs" />
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Instance\Repository.cs" />
|
||||
<Compile Include="Server.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
@@ -128,10 +123,6 @@
|
||||
<None Include="packages.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TGS.Interface\TGS.Interface.csproj">
|
||||
|
||||
Reference in New Issue
Block a user