From 8aec4614995a03f38e7611d12a0891eda23fa40c Mon Sep 17 00:00:00 2001 From: Brett Hewitson Date: Thu, 6 Jan 2022 12:06:20 +1000 Subject: [PATCH] Minor tweaks to Auto-Update process --- src/ConanServerManager/Lib/ServerApp.cs | 18 ++++++++------ src/ConanServerManager/Lib/ServerProfile.cs | 27 ++++++++++++++++----- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/ConanServerManager/Lib/ServerApp.cs b/src/ConanServerManager/Lib/ServerApp.cs index 30992f08..d91c22cf 100644 --- a/src/ConanServerManager/Lib/ServerApp.cs +++ b/src/ConanServerManager/Lib/ServerApp.cs @@ -2387,9 +2387,7 @@ namespace ServerManagerTool.Lib { try { - var profile = ServerProfile.LoadFrom(profileFile); - profile.DestroyServerFilesWatcher(); - profile.SaveLauncher(); + var profile = ServerProfile.LoadFromProfileFileBasic(profileFile, null); profiles.Add(ServerProfileSnapshot.Create(profile), profile); } catch (Exception ex) @@ -2957,7 +2955,8 @@ namespace ServerManagerTool.Lib ServerProcess = ServerProcess, SteamCMDProcessWindowStyle = ProcessWindowStyle.Hidden }; - profileExitCodes.TryAdd(profile, app.PerformProfileUpdate(branch, profile)); + app.PerformProfileUpdate(branch, profile); + profileExitCodes.TryAdd(profile, app.ExitCode); }); } else @@ -2977,7 +2976,8 @@ namespace ServerManagerTool.Lib ServerProcess = ServerProcess, SteamCMDProcessWindowStyle = ProcessWindowStyle.Hidden }; - profileExitCodes.TryAdd(profile, app.PerformProfileUpdate(branch, profile)); + app.PerformProfileUpdate(branch, profile); + profileExitCodes.TryAdd(profile, app.ExitCode); } } @@ -3041,10 +3041,11 @@ namespace ServerManagerTool.Lib // load all the profiles, do this at the very start in case the user changes one or more while the process is running. LoadProfiles(); - + + var profiles = _profiles.Keys.Where(p => p.EnableAutoBackup); var exitCodes = new ConcurrentDictionary(); - Parallel.ForEach(_profiles.Keys.Where(p => p.EnableAutoBackup), profile => { + Parallel.ForEach(profiles, profile => { var app = new ServerApp { DeleteOldBackupFiles = Config.Default.AutoBackup_DeleteOldFiles, @@ -3053,7 +3054,8 @@ namespace ServerManagerTool.Lib SendEmails = true, ServerProcess = ServerProcessType.AutoBackup }; - exitCodes.TryAdd(profile, app.PerformProfileBackup(profile, CancellationToken.None)); + app.PerformProfileBackup(profile, CancellationToken.None); + exitCodes.TryAdd(profile, app.ExitCode); }); foreach (var profile in _profiles.Keys) diff --git a/src/ConanServerManager/Lib/ServerProfile.cs b/src/ConanServerManager/Lib/ServerProfile.cs index d4b32244..a5c73077 100644 --- a/src/ConanServerManager/Lib/ServerProfile.cs +++ b/src/ConanServerManager/Lib/ServerProfile.cs @@ -908,6 +908,22 @@ namespace ServerManagerTool.Lib } public static ServerProfile LoadFromProfileFile(string file, ServerProfile profile) + { + profile = LoadFromProfileFileBasic(file, profile); + + if (profile is null) + return null; + + profile.CheckLauncherArgs(); + + profile.LoadServerFiles(true, true); + profile.SetupServerFilesWatcher(); + + profile._lastSaveLocation = file; + return profile; + } + + public static ServerProfile LoadFromProfileFileBasic(string file, ServerProfile profile) { if (string.IsNullOrWhiteSpace(file) || !File.Exists(file)) return null; @@ -945,17 +961,12 @@ namespace ServerManagerTool.Lib } } - profile.CheckLauncherArgs(); - var serverConfigFile = Path.Combine(GetProfileServerConfigDir(profile), Config.Default.ServerGameConfigFile); if (File.Exists(serverConfigFile)) { profile = LoadFromConfigFiles(serverConfigFile, profile); } - profile.LoadServerFiles(true, true); - profile.SetupServerFilesWatcher(); - profile._lastSaveLocation = file; return profile; } @@ -1047,10 +1058,14 @@ namespace ServerManagerTool.Lib public void SaveProfile() { + var settings = new JsonSerializerSettings(); + settings.Converters.Add(new NullableValueConverter()); + settings.Converters.Add(new NullableValueConverter()); + // // Save the profile // - JsonUtils.SerializeToFile(this, GetProfileFile()); + JsonUtils.SerializeToFile(this, GetProfileFile(), settings); } public void SaveLauncher()