diff --git a/src/ARKServerManager/Lib/ServerApp.cs b/src/ARKServerManager/Lib/ServerApp.cs index b8b6cbb3..2facb227 100644 --- a/src/ARKServerManager/Lib/ServerApp.cs +++ b/src/ARKServerManager/Lib/ServerApp.cs @@ -2494,9 +2494,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) @@ -3064,7 +3062,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 @@ -3084,7 +3083,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); } } @@ -3149,9 +3149,10 @@ 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, @@ -3160,7 +3161,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/ARKServerManager/Lib/ServerProfile.cs b/src/ARKServerManager/Lib/ServerProfile.cs index 4b79149f..0174aee7 100644 --- a/src/ARKServerManager/Lib/ServerProfile.cs +++ b/src/ARKServerManager/Lib/ServerProfile.cs @@ -4007,9 +4007,13 @@ namespace ServerManagerTool.Lib if (profile.PlayerLevels.Count == 0) { profile.ResetLevelProgressionToOfficial(LevelProgression.Player); - profile.ResetLevelProgressionToOfficial(LevelProgression.Dino); profile.EnableLevelProgressions = false; } + if (profile.DinoLevels.Count == 0) + { + profile.ResetLevelProgressionToOfficial(LevelProgression.Dino); + profile.EnableDinoLevelProgressions = false; + } // // Since these are not inserted the normal way, we force a recomputation here. @@ -4065,42 +4069,11 @@ namespace ServerManagerTool.Lib public static ServerProfile LoadFromProfileFile(string file, ServerProfile profile) { - if (string.IsNullOrWhiteSpace(file) || !File.Exists(file)) + profile = LoadFromProfileFileBasic(file, profile); + + if (profile is null) return null; - if (Path.GetExtension(file) != Config.Default.ProfileExtension) - return null; - - profile = profile ?? new ServerProfile(); - - try - { - var settings = new JsonSerializerSettings(); - settings.Converters.Add(new NullableValueConverter()); - settings.Converters.Add(new NullableValueConverter()); - - profile = JsonUtils.DeserializeFromFile(file, settings); - if (profile == null) - return null; - } - catch - { - // could not load the profile file, just exit - return null; - } - - // check if profile id and filename match - var fileName = Path.GetFileNameWithoutExtension(file); - if (Guid.TryParse(fileName, out Guid fileId) && Guid.TryParse(profile.ProfileID, out Guid profileId)) - { - // filename is a guid - check it against the profile id - if (!Guid.Equals(fileId, profileId)) - { - // id values are not in sync, change the profile id to be the same as the filename - profile.ProfileID = fileId.ToString(); - } - } - profile.CheckLauncherArgs(); if (profile.PGM_Enabled) @@ -4109,20 +4082,12 @@ namespace ServerManagerTool.Lib if (profile.SOTF_Enabled) Config.Default.SectionSOTFEnabled = true; - var configIniPath = Path.Combine(GetProfileServerConfigDir(profile), Config.Default.ServerGameUserSettingsConfigFile); - if (File.Exists(configIniPath)) - { - profile = LoadFromINIFiles(configIniPath, profile); - } - if (profile.PlayerLevels.Count == 0) { profile.ResetLevelProgressionToOfficial(LevelProgression.Player); - profile.ResetLevelProgressionToOfficial(LevelProgression.Dino); profile.EnableLevelProgressions = false; - profile.EnableDinoLevelProgressions = false; } - else if (profile.DinoLevels.Count == 0) + if (profile.DinoLevels.Count == 0) { profile.ResetLevelProgressionToOfficial(LevelProgression.Dino); profile.EnableDinoLevelProgressions = false; @@ -4151,6 +4116,43 @@ namespace ServerManagerTool.Lib return profile; } + public static ServerProfile LoadFromProfileFileBasic(string file, ServerProfile profile) + { + if (string.IsNullOrWhiteSpace(file) || !File.Exists(file)) + return null; + + if (Path.GetExtension(file) != Config.Default.ProfileExtension) + return null; + + if (profile is null) + profile = new ServerProfile(); + + try + { + var settings = new JsonSerializerSettings(); + settings.Converters.Add(new NullableValueConverter()); + settings.Converters.Add(new NullableValueConverter()); + + profile = JsonUtils.DeserializeFromFile(file, settings); + if (profile == null) + return null; + } + catch + { + // could not load the profile file, just exit + return null; + } + + var configIniPath = Path.Combine(GetProfileServerConfigDir(profile), Config.Default.ServerGameUserSettingsConfigFile); + if (File.Exists(configIniPath)) + { + profile = LoadFromINIFiles(configIniPath, profile); + } + + profile._lastSaveLocation = file; + return profile; + } + public void Save(bool updateFolderPermissions, bool updateSchedules, ProgressDelegate progressCallback) { if (string.IsNullOrWhiteSpace(Config.Default.DataDir)) diff --git a/src/ARKServerManager/Lib/ServerProfileSnapshot.cs b/src/ARKServerManager/Lib/ServerProfileSnapshot.cs index 2a02fbe2..ee75d889 100644 --- a/src/ARKServerManager/Lib/ServerProfileSnapshot.cs +++ b/src/ARKServerManager/Lib/ServerProfileSnapshot.cs @@ -19,7 +19,6 @@ namespace ServerManagerTool.Lib public string PGM_Name; public string AdminPassword; public string ServerName; - public string ServerArgs; public IPAddress ServerIPAddress; public int ServerPort; public int ServerPeerPort; @@ -70,7 +69,6 @@ namespace ServerManagerTool.Lib PGM_Name = profile.PGM_Name, AdminPassword = profile.AdminPassword, ServerName = profile.ServerName, - ServerArgs = profile.GetServerArgs(), ServerIPAddress = string.IsNullOrWhiteSpace(profile.ServerIP) ? IPAddress.Loopback : IPAddress.TryParse(profile.ServerIP.Trim(), out IPAddress ipAddress) ? ipAddress : IPAddress.Loopback, ServerPort = profile.ServerPort, ServerPeerPort = profile.ServerPeerPort,