Removal of ToArray()

This commit is contained in:
Brett Hewitson 2021-12-16 00:21:23 +10:00
parent 9eb22da9e7
commit 9f5cf132f0
41 changed files with 184 additions and 189 deletions

View file

@ -17,15 +17,13 @@ namespace ServerManagerTool.Lib
public override void FromIniValues(IEnumerable<string> iniValues) public override void FromIniValues(IEnumerable<string> iniValues)
{ {
var items = iniValues?.Select(AggregateIniValue.FromINIValue<EngramAutoUnlock>).ToArray(); var items = iniValues?.Select(AggregateIniValue.FromINIValue<EngramAutoUnlock>);
Clear(); Clear();
var itemsToAdd = items.Where(i => !this.Any(e => e.IsEquivalent(i))).ToArray(); AddRange(items.Where(i => !this.Any(e => e.IsEquivalent(i))));
AddRange(itemsToAdd);
var itemsToUpdate = items.Where(i => this.Any(e => e.IsEquivalent(i))).ToArray(); foreach (var item in items.Where(i => this.Any(e => e.IsEquivalent(i))))
foreach (var item in itemsToUpdate)
{ {
var e = this.FirstOrDefault(r => r.IsEquivalent(item)); var e = this.FirstOrDefault(r => r.IsEquivalent(item));
e.LevelToAutoUnlock = item.LevelToAutoUnlock; e.LevelToAutoUnlock = item.LevelToAutoUnlock;

View file

@ -18,15 +18,13 @@ namespace ServerManagerTool.Lib
public override void FromIniValues(IEnumerable<string> iniValues) public override void FromIniValues(IEnumerable<string> iniValues)
{ {
var items = iniValues?.Select(AggregateIniValue.FromINIValue<EngramEntry>).ToArray(); var items = iniValues?.Select(AggregateIniValue.FromINIValue<EngramEntry>);
Clear(); Clear();
var itemsToAdd = items.Where(i => !this.Any(e => e.IsEquivalent(i))).ToArray(); AddRange(items.Where(i => !this.Any(e => e.IsEquivalent(i))));
AddRange(itemsToAdd);
var itemsToUpdate = items.Where(i => this.Any(e => e.IsEquivalent(i))).ToArray(); foreach (var item in items.Where(i => this.Any(e => e.IsEquivalent(i))))
foreach (var item in itemsToUpdate)
{ {
var e = this.FirstOrDefault(r => r.IsEquivalent(item)); var e = this.FirstOrDefault(r => r.IsEquivalent(item));
e.EngramLevelRequirement = item.EngramLevelRequirement; e.EngramLevelRequirement = item.EngramLevelRequirement;

View file

@ -61,7 +61,7 @@ namespace ServerManagerTool.Lib
int index = 0; int index = 0;
int xpTotal = 0; int xpTotal = 0;
int engramTotal = 0; int engramTotal = 0;
foreach (var existingLevel in this.OrderBy(l => l.XPRequired).ToArray()) foreach (var existingLevel in this.OrderBy(l => l.XPRequired))
{ {
xpTotal += existingLevel.XPRequired; xpTotal += existingLevel.XPRequired;
engramTotal += existingLevel.EngramPoints; engramTotal += existingLevel.EngramPoints;

View file

@ -14,11 +14,9 @@ namespace ServerManagerTool.Lib
{ {
} }
public string[] RenderToView() public IEnumerable<string> RenderToView()
{ {
List<string> errors = new List<string>(); return new List<string>();
return errors.ToArray();
} }
public void RenderToModel() public void RenderToModel()

View file

@ -1,5 +1,4 @@
using ServerManagerTool.Common.Model; using ServerManagerTool.Common.Model;
using ServerManagerTool.Enums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -18,22 +17,20 @@ namespace ServerManagerTool.Lib
public override void FromIniValues(IEnumerable<string> iniValues) public override void FromIniValues(IEnumerable<string> iniValues)
{ {
var items = iniValues?.Select(AggregateIniValue.FromINIValue<ResourceClassMultiplier>).ToArray(); var items = iniValues?.Select(AggregateIniValue.FromINIValue<ResourceClassMultiplier>);
Clear(); Clear();
if (this._resetFunc != null) if (this._resetFunc != null)
this.AddRange(this._resetFunc()); this.AddRange(this._resetFunc());
var itemsToAdd = items.Where(i => !this.Any(r => r.IsEquivalent(i))).ToArray(); AddRange(items.Where(i => !this.Any(r => r.IsEquivalent(i))));
AddRange(itemsToAdd);
var itemsToUpdate = items.Where(i => this.Any(r => r.IsEquivalent(i))).ToArray(); foreach (var item in items.Where(i => this.Any(r => r.IsEquivalent(i))))
foreach (var item in itemsToUpdate)
{ {
this.FirstOrDefault(r => r.IsEquivalent(item)).Multiplier = item.Multiplier; this.FirstOrDefault(r => r.IsEquivalent(item)).Multiplier = item.Multiplier;
} }
IsEnabled = (items.Length > 0); IsEnabled = (Count > 0);
Sort(AggregateIniValue.SortKeySelector); Sort(AggregateIniValue.SortKeySelector);
} }

View file

@ -14,7 +14,7 @@ namespace ServerManagerTool.Lib
{ {
} }
public string[] RenderToView() public IEnumerable<string> RenderToView()
{ {
List<string> errors = new List<string>(); List<string> errors = new List<string>();
@ -27,7 +27,7 @@ namespace ServerManagerTool.Lib
} }
} }
return errors.ToArray(); return errors;
} }
public void RenderToModel() public void RenderToModel()

View file

@ -17,7 +17,7 @@ namespace ServerManagerTool.Lib
{ {
} }
public string[] RenderToView() public IEnumerable<string> RenderToView()
{ {
List<string> errors = new List<string>(); List<string> errors = new List<string>();
@ -48,7 +48,7 @@ namespace ServerManagerTool.Lib
Update(); Update();
return errors.ToArray(); return errors;
} }
public void RenderToModel() public void RenderToModel()

View file

@ -1875,7 +1875,7 @@ namespace ServerManagerTool.Lib
comment.AppendLine($"PGM Server: {_profile.PGM_Enabled}"); comment.AppendLine($"PGM Server: {_profile.PGM_Enabled}");
comment.AppendLine($"Process: {ServerProcess}"); comment.AppendLine($"Process: {ServerProcess}");
ZipUtils.ZipFiles(backupFile, files.ToArray(), comment.ToString(), false); ZipUtils.ZipFiles(backupFile, files, comment.ToString(), false);
LogProfileMessage($"Backup file created - {backupFile}"); LogProfileMessage($"Backup file created - {backupFile}");
} }
@ -2025,7 +2025,7 @@ namespace ServerManagerTool.Lib
comment.AppendLine($"PGM Server: {_profile.PGM_Enabled}"); comment.AppendLine($"PGM Server: {_profile.PGM_Enabled}");
comment.AppendLine($"Process: {ServerProcess}"); comment.AppendLine($"Process: {ServerProcess}");
ZipUtils.ZipFiles(backupFile, files.ToArray(), comment.ToString(), false); ZipUtils.ZipFiles(backupFile, files, comment.ToString(), false);
LogProfileMessage($"Backed up world files - {saveFolder}"); LogProfileMessage($"Backed up world files - {saveFolder}");
LogProfileMessage($"Backup file created - {backupFile}"); LogProfileMessage($"Backup file created - {backupFile}");
@ -2998,7 +2998,7 @@ namespace ServerManagerTool.Lib
if (ExitCode == EXITCODE_NORMALEXIT) if (ExitCode == EXITCODE_NORMALEXIT)
{ {
// get the profile associated with the branch // get the profile associated with the branch
var profiles = _profiles.Keys.Where(p => p.EnableAutoUpdate && p.BranchName.Equals(branch.BranchName, StringComparison.OrdinalIgnoreCase)).ToArray(); var profiles = _profiles.Keys.Where(p => p.EnableAutoUpdate && p.BranchName.Equals(branch.BranchName, StringComparison.OrdinalIgnoreCase));
var profileExitCodes = new ConcurrentDictionary<ServerProfileSnapshot, int>(); var profileExitCodes = new ConcurrentDictionary<ServerProfileSnapshot, int>();
if (Config.Default.AutoUpdate_ParallelUpdate) if (Config.Default.AutoUpdate_ParallelUpdate)
@ -3249,7 +3249,7 @@ namespace ServerManagerTool.Lib
if (exitCode == EXITCODE_NORMALEXIT) if (exitCode == EXITCODE_NORMALEXIT)
{ {
var branches = _profiles.Keys.Where(p => p.EnableAutoUpdate).Select(p => BranchSnapshot.Create(p)).Distinct(new BranchSnapshotComparer()).ToArray(); var branches = _profiles.Keys.Where(p => p.EnableAutoUpdate).Select(p => BranchSnapshot.Create(p)).Distinct(new BranchSnapshotComparer());
var exitCodes = new ConcurrentDictionary<BranchSnapshot, int>(); var exitCodes = new ConcurrentDictionary<BranchSnapshot, int>();
// update the server cache for each branch // update the server cache for each branch

View file

@ -223,7 +223,7 @@ namespace ServerManagerTool.Lib
token.ThrowIfCancellationRequested(); token.ThrowIfCancellationRequested();
// remove any players that do not have a player file. // remove any players that do not have a player file.
var droppedPlayers = _players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null).ToArray(); var droppedPlayers = _players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null);
foreach (var droppedPlayer in droppedPlayers) foreach (var droppedPlayer in droppedPlayers)
{ {
_players.TryRemove(droppedPlayer.PlayerId, out PlayerInfo player); _players.TryRemove(droppedPlayer.PlayerId, out PlayerInfo player);

View file

@ -3593,7 +3593,7 @@ namespace ServerManagerTool.Lib
} }
} }
private static Enum[] GetExclusions() private static IEnumerable<Enum> GetExclusions()
{ {
var exclusions = new List<Enum>(); var exclusions = new List<Enum>();
@ -3637,7 +3637,7 @@ namespace ServerManagerTool.Lib
exclusions.Add(ServerProfileCategory.SOTF); exclusions.Add(ServerProfileCategory.SOTF);
} }
return exclusions.ToArray(); return exclusions;
} }
private LevelList GetLevelList(LevelProgression levelProgression) private LevelList GetLevelList(LevelProgression levelProgression)
@ -4022,7 +4022,7 @@ namespace ServerManagerTool.Lib
return profile; return profile;
} }
public static ServerProfile LoadFromINIFiles(string file, ServerProfile profile, Enum[] exclusions = null) public static ServerProfile LoadFromINIFiles(string file, ServerProfile profile, IEnumerable<Enum> exclusions = null)
{ {
if (string.IsNullOrWhiteSpace(file) || !File.Exists(file)) if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
return null; return null;
@ -4394,7 +4394,7 @@ namespace ServerManagerTool.Lib
SaveINIFile(configDir); SaveINIFile(configDir);
} }
public void SaveINIFile(string profileIniDir, Enum[] exclusions = null) public void SaveINIFile(string profileIniDir, IEnumerable<Enum> exclusions = null)
{ {
if (exclusions == null) if (exclusions == null)
exclusions = GetExclusions(); exclusions = GetExclusions();
@ -4418,7 +4418,7 @@ namespace ServerManagerTool.Lib
filteredValues.AddRange(this.PlayerLevels.ToINIValuesForEngramPoints()); filteredValues.AddRange(this.PlayerLevels.ToINIValuesForEngramPoints());
} }
iniFile.WriteSection(IniFiles.Game, IniSections.Game_ShooterGameMode, filteredValues.ToArray()); iniFile.WriteSection(IniFiles.Game, IniSections.Game_ShooterGameMode, filteredValues);
} }
public bool UpdateDirectoryPermissions() public bool UpdateDirectoryPermissions()
@ -5860,7 +5860,7 @@ namespace ServerManagerTool.Lib
this.CustomEngineSettings.Clear(); this.CustomEngineSettings.Clear();
foreach (var section in sourceProfile.CustomEngineSettings) foreach (var section in sourceProfile.CustomEngineSettings)
{ {
this.CustomEngineSettings.Add(section.SectionName, section.ToIniValues().ToArray()); this.CustomEngineSettings.Add(section.SectionName, section.ToIniValues());
} }
} }
@ -5869,7 +5869,7 @@ namespace ServerManagerTool.Lib
this.CustomGameSettings.Clear(); this.CustomGameSettings.Clear();
foreach (var section in sourceProfile.CustomGameSettings) foreach (var section in sourceProfile.CustomGameSettings)
{ {
this.CustomGameSettings.Add(section.SectionName, section.ToIniValues().ToArray()); this.CustomGameSettings.Add(section.SectionName, section.ToIniValues());
} }
} }
@ -5878,7 +5878,7 @@ namespace ServerManagerTool.Lib
this.CustomGameUserSettings.Clear(); this.CustomGameUserSettings.Clear();
foreach (var section in sourceProfile.CustomGameUserSettings) foreach (var section in sourceProfile.CustomGameUserSettings)
{ {
this.CustomGameUserSettings.Add(section.SectionName, section.ToIniValues().ToArray()); this.CustomGameUserSettings.Add(section.SectionName, section.ToIniValues());
} }
} }
@ -6530,7 +6530,7 @@ namespace ServerManagerTool.Lib
Directory.CreateDirectory(folder); Directory.CreateDirectory(folder);
var file = Path.Combine(folder, Config.Default.ArkAdminFile); var file = Path.Combine(folder, Config.Default.ArkAdminFile);
File.WriteAllLines(file, this.ServerFilesAdmins.ToArray()); File.WriteAllLines(file, this.ServerFilesAdmins.ToEnumerable());
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -6547,7 +6547,7 @@ namespace ServerManagerTool.Lib
Directory.CreateDirectory(folder); Directory.CreateDirectory(folder);
var file = Path.Combine(folder, Config.Default.ArkExclusiveFile); var file = Path.Combine(folder, Config.Default.ArkExclusiveFile);
File.WriteAllLines(file, this.ServerFilesExclusive.ToArray()); File.WriteAllLines(file, this.ServerFilesExclusive.ToEnumerable());
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -6564,7 +6564,7 @@ namespace ServerManagerTool.Lib
Directory.CreateDirectory(folder); Directory.CreateDirectory(folder);
var file = Path.Combine(folder, Config.Default.ArkWhitelistFile); var file = Path.Combine(folder, Config.Default.ArkWhitelistFile);
File.WriteAllLines(file, this.ServerFilesWhitelisted.ToArray()); File.WriteAllLines(file, this.ServerFilesWhitelisted.ToEnumerable());
} }
catch (Exception ex) catch (Exception ex)
{ {

View file

@ -325,8 +325,8 @@ namespace ServerManagerTool.Lib
else if (command.command.Equals(RCON_COMMAND_GETCHAT, StringComparison.OrdinalIgnoreCase)) else if (command.command.Equals(RCON_COMMAND_GETCHAT, StringComparison.OrdinalIgnoreCase))
{ {
// TODO: Extract the player name from the chat // TODO: Extract the player name from the chat
var lines = command.lines.Where(l => !String.IsNullOrEmpty(l) && l != NoResponseOutput).ToArray(); var lines = command.lines.Where(l => !String.IsNullOrEmpty(l) && l != NoResponseOutput);
if (lines.Length == 0 && command.suppressCommand) if (!lines.Any() && command.suppressCommand)
{ {
command.suppressOutput = true; command.suppressOutput = true;
} }
@ -398,7 +398,7 @@ namespace ServerManagerTool.Lib
} }
} }
var droppedPlayers = this.players.Values.Where(p => onlinePlayers.FirstOrDefault(np => np.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null).ToArray(); var droppedPlayers = this.players.Values.Where(p => onlinePlayers.FirstOrDefault(np => np.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null);
foreach (var droppedPlayer in droppedPlayers) foreach (var droppedPlayer in droppedPlayers)
{ {
if (droppedPlayer.IsOnline) if (droppedPlayer.IsOnline)
@ -604,7 +604,7 @@ namespace ServerManagerTool.Lib
token.ThrowIfCancellationRequested(); token.ThrowIfCancellationRequested();
// remove any players that do not have a player file. // remove any players that do not have a player file.
var droppedPlayers = this.players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null).ToArray(); var droppedPlayers = this.players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null);
foreach (var droppedPlayer in droppedPlayers) foreach (var droppedPlayer in droppedPlayers)
{ {
players.TryRemove(droppedPlayer.PlayerId, out PlayerInfo player); players.TryRemove(droppedPlayer.PlayerId, out PlayerInfo player);

View file

@ -80,14 +80,13 @@ namespace ServerManagerTool.Lib.ViewModel
if (string.IsNullOrWhiteSpace(entry.EngramClassName)) if (string.IsNullOrWhiteSpace(entry.EngramClassName))
continue; continue;
var engramSettings = this.Where(vi => vi.EngramClassName == entry.EngramClassName).ToArray(); if (!this.Any(vi => vi.EngramClassName == entry.EngramClassName))
if (engramSettings == null || engramSettings.Length == 0)
{ {
var engram = GameData.GetEngramForClass(entry.EngramClassName); var engram = GameData.GetEngramForClass(entry.EngramClassName);
this.Add(CreateEngramSetting(entry.EngramClassName, engram?.Mod ?? GameData.MOD_UNKNOWN, engram?.KnownEngram ?? false, engram?.IsTekgram ?? false)); this.Add(CreateEngramSetting(entry.EngramClassName, engram?.Mod ?? GameData.MOD_UNKNOWN, engram?.KnownEngram ?? false, engram?.IsTekgram ?? false));
} }
engramSettings = this.Where(vi => vi.EngramClassName == entry.EngramClassName).ToArray(); var engramSettings = this.Where(vi => vi.EngramClassName == entry.EngramClassName);
foreach (var engramSetting in engramSettings) foreach (var engramSetting in engramSettings)
{ {
engramSetting.EngramLevelRequirement = entry.EngramLevelRequirement; engramSetting.EngramLevelRequirement = entry.EngramLevelRequirement;
@ -117,14 +116,13 @@ namespace ServerManagerTool.Lib.ViewModel
if (string.IsNullOrWhiteSpace(entry.EngramClassName)) if (string.IsNullOrWhiteSpace(entry.EngramClassName))
continue; continue;
var engramSettings = this.Where(vi => vi.EngramClassName == entry.EngramClassName).ToArray(); if (!this.Any(vi => vi.EngramClassName == entry.EngramClassName))
if (engramSettings == null || engramSettings.Length == 0)
{ {
var engram = GameData.GetEngramForClass(entry.EngramClassName); var engram = GameData.GetEngramForClass(entry.EngramClassName);
this.Add(CreateEngramSetting(entry.EngramClassName, engram?.Mod ?? GameData.MOD_UNKNOWN, engram?.KnownEngram ?? false, engram?.IsTekgram ?? false)); this.Add(CreateEngramSetting(entry.EngramClassName, engram?.Mod ?? GameData.MOD_UNKNOWN, engram?.KnownEngram ?? false, engram?.IsTekgram ?? false));
} }
engramSettings = this.Where(vi => vi.EngramClassName == entry.EngramClassName).ToArray(); var engramSettings = this.Where(vi => vi.EngramClassName == entry.EngramClassName);
foreach (var engramSetting in engramSettings) foreach (var engramSetting in engramSettings)
{ {
engramSetting.EngramAutoUnlock = true; engramSetting.EngramAutoUnlock = true;

View file

@ -990,7 +990,7 @@ namespace ServerManagerTool
var zipFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), this.Settings.ProfileID + ".zip"); var zipFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), this.Settings.ProfileID + ".zip");
if (File.Exists(zipFile)) File.Delete(zipFile); if (File.Exists(zipFile)) File.Delete(zipFile);
ZipUtils.ZipFiles(zipFile, files.ToArray(), comment.ToString()); ZipUtils.ZipFiles(zipFile, files, comment.ToString());
foreach (var kvp in obfuscateFiles) foreach (var kvp in obfuscateFiles)
{ {
ZipUtils.ZipAFile(zipFile, kvp.Key, kvp.Value); ZipUtils.ZipAFile(zipFile, kvp.Key, kvp.Value);
@ -1348,37 +1348,37 @@ namespace ServerManagerTool
foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
var dinoSpawnWeightMultipliers = new AggregateIniValueList<DinoSpawn>(nameof(Server.Profile.DinoSpawnWeightMultipliers), null); var dinoSpawnWeightMultipliers = new AggregateIniValueList<DinoSpawn>(nameof(Server.Profile.DinoSpawnWeightMultipliers), null);
dinoSpawnWeightMultipliers.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{dinoSpawnWeightMultipliers.IniCollectionKey}="))); dinoSpawnWeightMultipliers.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{dinoSpawnWeightMultipliers.IniCollectionKey}=")));
Server.Profile.DinoSpawnWeightMultipliers.AddRange(dinoSpawnWeightMultipliers); Server.Profile.DinoSpawnWeightMultipliers.AddRange(dinoSpawnWeightMultipliers);
Server.Profile.DinoSpawnWeightMultipliers.IsEnabled |= dinoSpawnWeightMultipliers.IsEnabled; Server.Profile.DinoSpawnWeightMultipliers.IsEnabled |= dinoSpawnWeightMultipliers.IsEnabled;
var preventDinoTameClassNames = new StringIniValueList(nameof(Server.Profile.PreventDinoTameClassNames), null); var preventDinoTameClassNames = new StringIniValueList(nameof(Server.Profile.PreventDinoTameClassNames), null);
preventDinoTameClassNames.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{preventDinoTameClassNames.IniCollectionKey}="))); preventDinoTameClassNames.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{preventDinoTameClassNames.IniCollectionKey}=")));
Server.Profile.PreventDinoTameClassNames.AddRange(preventDinoTameClassNames); Server.Profile.PreventDinoTameClassNames.AddRange(preventDinoTameClassNames);
Server.Profile.PreventDinoTameClassNames.IsEnabled |= preventDinoTameClassNames.IsEnabled; Server.Profile.PreventDinoTameClassNames.IsEnabled |= preventDinoTameClassNames.IsEnabled;
var npcReplacements = new AggregateIniValueList<NPCReplacement>(nameof(Server.Profile.NPCReplacements), null); var npcReplacements = new AggregateIniValueList<NPCReplacement>(nameof(Server.Profile.NPCReplacements), null);
npcReplacements.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{npcReplacements.IniCollectionKey}="))); npcReplacements.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{npcReplacements.IniCollectionKey}=")));
Server.Profile.NPCReplacements.AddRange(npcReplacements); Server.Profile.NPCReplacements.AddRange(npcReplacements);
Server.Profile.NPCReplacements.IsEnabled |= npcReplacements.IsEnabled; Server.Profile.NPCReplacements.IsEnabled |= npcReplacements.IsEnabled;
var tamedDinoClassDamageMultipliers = new AggregateIniValueList<ClassMultiplier>(nameof(Server.Profile.TamedDinoClassDamageMultipliers), null); var tamedDinoClassDamageMultipliers = new AggregateIniValueList<ClassMultiplier>(nameof(Server.Profile.TamedDinoClassDamageMultipliers), null);
tamedDinoClassDamageMultipliers.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{tamedDinoClassDamageMultipliers.IniCollectionKey}="))); tamedDinoClassDamageMultipliers.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{tamedDinoClassDamageMultipliers.IniCollectionKey}=")));
Server.Profile.TamedDinoClassDamageMultipliers.AddRange(tamedDinoClassDamageMultipliers); Server.Profile.TamedDinoClassDamageMultipliers.AddRange(tamedDinoClassDamageMultipliers);
Server.Profile.TamedDinoClassDamageMultipliers.IsEnabled |= tamedDinoClassDamageMultipliers.IsEnabled; Server.Profile.TamedDinoClassDamageMultipliers.IsEnabled |= tamedDinoClassDamageMultipliers.IsEnabled;
var tamedDinoClassResistanceMultipliers = new AggregateIniValueList<ClassMultiplier>(nameof(Server.Profile.TamedDinoClassResistanceMultipliers), null); var tamedDinoClassResistanceMultipliers = new AggregateIniValueList<ClassMultiplier>(nameof(Server.Profile.TamedDinoClassResistanceMultipliers), null);
tamedDinoClassResistanceMultipliers.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{tamedDinoClassResistanceMultipliers.IniCollectionKey}="))); tamedDinoClassResistanceMultipliers.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{tamedDinoClassResistanceMultipliers.IniCollectionKey}=")));
Server.Profile.TamedDinoClassResistanceMultipliers.AddRange(tamedDinoClassResistanceMultipliers); Server.Profile.TamedDinoClassResistanceMultipliers.AddRange(tamedDinoClassResistanceMultipliers);
Server.Profile.TamedDinoClassResistanceMultipliers.IsEnabled |= tamedDinoClassResistanceMultipliers.IsEnabled; Server.Profile.TamedDinoClassResistanceMultipliers.IsEnabled |= tamedDinoClassResistanceMultipliers.IsEnabled;
var dinoClassDamageMultipliers = new AggregateIniValueList<ClassMultiplier>(nameof(Server.Profile.DinoClassDamageMultipliers), null); var dinoClassDamageMultipliers = new AggregateIniValueList<ClassMultiplier>(nameof(Server.Profile.DinoClassDamageMultipliers), null);
dinoClassDamageMultipliers.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{dinoClassDamageMultipliers.IniCollectionKey}="))); dinoClassDamageMultipliers.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{dinoClassDamageMultipliers.IniCollectionKey}=")));
Server.Profile.DinoClassDamageMultipliers.AddRange(dinoClassDamageMultipliers); Server.Profile.DinoClassDamageMultipliers.AddRange(dinoClassDamageMultipliers);
Server.Profile.DinoClassDamageMultipliers.IsEnabled |= dinoClassDamageMultipliers.IsEnabled; Server.Profile.DinoClassDamageMultipliers.IsEnabled |= dinoClassDamageMultipliers.IsEnabled;
var dinoClassResistanceMultipliers = new AggregateIniValueList<ClassMultiplier>(nameof(Server.Profile.DinoClassResistanceMultipliers), null); var dinoClassResistanceMultipliers = new AggregateIniValueList<ClassMultiplier>(nameof(Server.Profile.DinoClassResistanceMultipliers), null);
dinoClassResistanceMultipliers.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{dinoClassResistanceMultipliers.IniCollectionKey}="))); dinoClassResistanceMultipliers.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{dinoClassResistanceMultipliers.IniCollectionKey}=")));
Server.Profile.DinoClassResistanceMultipliers.AddRange(dinoClassResistanceMultipliers); Server.Profile.DinoClassResistanceMultipliers.AddRange(dinoClassResistanceMultipliers);
Server.Profile.DinoClassResistanceMultipliers.IsEnabled |= dinoClassResistanceMultipliers.IsEnabled; Server.Profile.DinoClassResistanceMultipliers.IsEnabled |= dinoClassResistanceMultipliers.IsEnabled;
} }
@ -1458,7 +1458,7 @@ namespace ServerManagerTool
foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
var harvestResourceItemAmountClassMultipliers = new AggregateIniValueList<ResourceClassMultiplier>(nameof(Server.Profile.HarvestResourceItemAmountClassMultipliers), null); var harvestResourceItemAmountClassMultipliers = new AggregateIniValueList<ResourceClassMultiplier>(nameof(Server.Profile.HarvestResourceItemAmountClassMultipliers), null);
harvestResourceItemAmountClassMultipliers.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{harvestResourceItemAmountClassMultipliers.IniCollectionKey}="))); harvestResourceItemAmountClassMultipliers.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{harvestResourceItemAmountClassMultipliers.IniCollectionKey}=")));
Server.Profile.HarvestResourceItemAmountClassMultipliers.AddRange(harvestResourceItemAmountClassMultipliers); Server.Profile.HarvestResourceItemAmountClassMultipliers.AddRange(harvestResourceItemAmountClassMultipliers);
Server.Profile.HarvestResourceItemAmountClassMultipliers.IsEnabled |= harvestResourceItemAmountClassMultipliers.IsEnabled; Server.Profile.HarvestResourceItemAmountClassMultipliers.IsEnabled |= harvestResourceItemAmountClassMultipliers.IsEnabled;
} }
@ -1686,12 +1686,12 @@ namespace ServerManagerTool
foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
var overrideNamedEngramEntries = new EngramEntryList(nameof(Server.Profile.OverrideNamedEngramEntries)); var overrideNamedEngramEntries = new EngramEntryList(nameof(Server.Profile.OverrideNamedEngramEntries));
overrideNamedEngramEntries.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{overrideNamedEngramEntries.IniCollectionKey}="))); overrideNamedEngramEntries.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{overrideNamedEngramEntries.IniCollectionKey}=")));
Server.Profile.OverrideNamedEngramEntries.AddRange(overrideNamedEngramEntries); Server.Profile.OverrideNamedEngramEntries.AddRange(overrideNamedEngramEntries);
Server.Profile.OverrideNamedEngramEntries.IsEnabled |= overrideNamedEngramEntries.IsEnabled; Server.Profile.OverrideNamedEngramEntries.IsEnabled |= overrideNamedEngramEntries.IsEnabled;
var engramEntryAutoUnlocks = new EngramAutoUnlockList(nameof(Server.Profile.EngramEntryAutoUnlocks)); var engramEntryAutoUnlocks = new EngramAutoUnlockList(nameof(Server.Profile.EngramEntryAutoUnlocks));
engramEntryAutoUnlocks.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{engramEntryAutoUnlocks.IniCollectionKey}="))); engramEntryAutoUnlocks.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{engramEntryAutoUnlocks.IniCollectionKey}=")));
Server.Profile.EngramEntryAutoUnlocks.AddRange(engramEntryAutoUnlocks); Server.Profile.EngramEntryAutoUnlocks.AddRange(engramEntryAutoUnlocks);
Server.Profile.EngramEntryAutoUnlocks.IsEnabled |= engramEntryAutoUnlocks.IsEnabled; Server.Profile.EngramEntryAutoUnlocks.IsEnabled |= engramEntryAutoUnlocks.IsEnabled;
} }
@ -1790,7 +1790,7 @@ namespace ServerManagerTool
foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
var configOverrideItemCraftingCosts = new AggregateIniValueList<CraftingOverride>(nameof(Server.Profile.ConfigOverrideItemCraftingCosts), null); var configOverrideItemCraftingCosts = new AggregateIniValueList<CraftingOverride>(nameof(Server.Profile.ConfigOverrideItemCraftingCosts), null);
configOverrideItemCraftingCosts.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{configOverrideItemCraftingCosts.IniCollectionKey}="))); configOverrideItemCraftingCosts.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{configOverrideItemCraftingCosts.IniCollectionKey}=")));
Server.Profile.ConfigOverrideItemCraftingCosts.AddRange(configOverrideItemCraftingCosts); Server.Profile.ConfigOverrideItemCraftingCosts.AddRange(configOverrideItemCraftingCosts);
Server.Profile.ConfigOverrideItemCraftingCosts.IsEnabled |= configOverrideItemCraftingCosts.IsEnabled; Server.Profile.ConfigOverrideItemCraftingCosts.IsEnabled |= configOverrideItemCraftingCosts.IsEnabled;
} }
@ -1898,7 +1898,7 @@ namespace ServerManagerTool
// cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections. // cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections.
foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
Settings.CustomGameUserSettings.Add(section.SectionName, section.KeysToStringArray(), false); Settings.CustomGameUserSettings.Add(section.SectionName, section.KeysToStringEnumerable(), false);
} }
MessageBox.Show(_globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Label"), _globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Title"), MessageBoxButton.OK, MessageBoxImage.Information); MessageBox.Show(_globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Label"), _globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Title"), MessageBoxButton.OK, MessageBoxImage.Information);
@ -1957,7 +1957,7 @@ namespace ServerManagerTool
// cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections. // cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections.
foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
Settings.CustomGameUserSettings.Add(section.SectionName, section.KeysToStringArray(), false); Settings.CustomGameUserSettings.Add(section.SectionName, section.KeysToStringEnumerable(), false);
} }
} }
@ -1980,7 +1980,7 @@ namespace ServerManagerTool
var configIniFile = Path.Combine(ServerProfile.GetProfileServerConfigDir(Settings), Config.Default.ServerGameUserSettingsConfigFile); var configIniFile = Path.Combine(ServerProfile.GetProfileServerConfigDir(Settings), Config.Default.ServerGameUserSettingsConfigFile);
// load only this section, using the full exclusion list // load only this section, using the full exclusion list
var tempServerProfile = ServerProfile.LoadFromINIFiles(configIniFile, null, exclusions.ToArray()); var tempServerProfile = ServerProfile.LoadFromINIFiles(configIniFile, null, exclusions);
// perform a profile sync // perform a profile sync
Settings.SyncSettings(ServerProfileCategory.CustomGameUserSettings, tempServerProfile); Settings.SyncSettings(ServerProfileCategory.CustomGameUserSettings, tempServerProfile);
} }
@ -2059,7 +2059,7 @@ namespace ServerManagerTool
// cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections. // cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections.
foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
Settings.CustomGameSettings.Add(section.SectionName, section.KeysToStringArray(), false); Settings.CustomGameSettings.Add(section.SectionName, section.KeysToStringEnumerable(), false);
} }
MessageBox.Show(_globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Label"), _globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Title"), MessageBoxButton.OK, MessageBoxImage.Information); MessageBox.Show(_globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Label"), _globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Title"), MessageBoxButton.OK, MessageBoxImage.Information);
@ -2118,7 +2118,7 @@ namespace ServerManagerTool
// cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections. // cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections.
foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
Settings.CustomGameSettings.Add(section.SectionName, section.KeysToStringArray(), false); Settings.CustomGameSettings.Add(section.SectionName, section.KeysToStringEnumerable(), false);
} }
} }
@ -2141,7 +2141,7 @@ namespace ServerManagerTool
var configIniFile = Path.Combine(ServerProfile.GetProfileServerConfigDir(Settings), Config.Default.ServerGameUserSettingsConfigFile); var configIniFile = Path.Combine(ServerProfile.GetProfileServerConfigDir(Settings), Config.Default.ServerGameUserSettingsConfigFile);
// load only this section, using the full exclusion list // load only this section, using the full exclusion list
var tempServerProfile = ServerProfile.LoadFromINIFiles(configIniFile, null, exclusions.ToArray()); var tempServerProfile = ServerProfile.LoadFromINIFiles(configIniFile, null, exclusions);
// perform a profile sync // perform a profile sync
Settings.SyncSettings(ServerProfileCategory.CustomGameSettings, tempServerProfile); Settings.SyncSettings(ServerProfileCategory.CustomGameSettings, tempServerProfile);
} }
@ -2220,7 +2220,7 @@ namespace ServerManagerTool
// cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections. // cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections.
foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
Settings.CustomEngineSettings.Add(section.SectionName, section.KeysToStringArray(), false); Settings.CustomEngineSettings.Add(section.SectionName, section.KeysToStringEnumerable(), false);
} }
MessageBox.Show(_globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Label"), _globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Title"), MessageBoxButton.OK, MessageBoxImage.Information); MessageBox.Show(_globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Label"), _globalizer.GetResourceString("ServerSettings_LoadCustomConfig_Title"), MessageBoxButton.OK, MessageBoxImage.Information);
@ -2279,7 +2279,7 @@ namespace ServerManagerTool
// cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections. // cycle through the sections, adding them to the custom section list. Will bypass any sections that are named as per the ARK default sections.
foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => !string.IsNullOrWhiteSpace(s.SectionName) && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
Settings.CustomEngineSettings.Add(section.SectionName, section.KeysToStringArray(), false); Settings.CustomEngineSettings.Add(section.SectionName, section.KeysToStringEnumerable(), false);
} }
} }
@ -2302,7 +2302,7 @@ namespace ServerManagerTool
var configIniFile = Path.Combine(ServerProfile.GetProfileServerConfigDir(Settings), Config.Default.ServerGameUserSettingsConfigFile); var configIniFile = Path.Combine(ServerProfile.GetProfileServerConfigDir(Settings), Config.Default.ServerGameUserSettingsConfigFile);
// load only this section, using the full exclusion list // load only this section, using the full exclusion list
var tempServerProfile = ServerProfile.LoadFromINIFiles(configIniFile, null, exclusions.ToArray()); var tempServerProfile = ServerProfile.LoadFromINIFiles(configIniFile, null, exclusions);
// perform a profile sync // perform a profile sync
Settings.SyncSettings(ServerProfileCategory.CustomEngineSettings, tempServerProfile); Settings.SyncSettings(ServerProfileCategory.CustomEngineSettings, tempServerProfile);
} }
@ -2919,17 +2919,17 @@ namespace ServerManagerTool
foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
var configAddNPCSpawnEntriesContainer = new NPCSpawnContainerList<NPCSpawnContainer>(nameof(Server.Profile.ConfigAddNPCSpawnEntriesContainer), NPCSpawnContainerType.Add); var configAddNPCSpawnEntriesContainer = new NPCSpawnContainerList<NPCSpawnContainer>(nameof(Server.Profile.ConfigAddNPCSpawnEntriesContainer), NPCSpawnContainerType.Add);
configAddNPCSpawnEntriesContainer.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{configAddNPCSpawnEntriesContainer.IniCollectionKey}="))); configAddNPCSpawnEntriesContainer.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{configAddNPCSpawnEntriesContainer.IniCollectionKey}=")));
Server.Profile.ConfigAddNPCSpawnEntriesContainer.AddRange(configAddNPCSpawnEntriesContainer); Server.Profile.ConfigAddNPCSpawnEntriesContainer.AddRange(configAddNPCSpawnEntriesContainer);
Server.Profile.ConfigAddNPCSpawnEntriesContainer.IsEnabled |= configAddNPCSpawnEntriesContainer.IsEnabled; Server.Profile.ConfigAddNPCSpawnEntriesContainer.IsEnabled |= configAddNPCSpawnEntriesContainer.IsEnabled;
var configSubtractNPCSpawnEntriesContainer = new NPCSpawnContainerList<NPCSpawnContainer>(nameof(Server.Profile.ConfigSubtractNPCSpawnEntriesContainer), NPCSpawnContainerType.Subtract); var configSubtractNPCSpawnEntriesContainer = new NPCSpawnContainerList<NPCSpawnContainer>(nameof(Server.Profile.ConfigSubtractNPCSpawnEntriesContainer), NPCSpawnContainerType.Subtract);
configSubtractNPCSpawnEntriesContainer.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{configSubtractNPCSpawnEntriesContainer.IniCollectionKey}="))); configSubtractNPCSpawnEntriesContainer.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{configSubtractNPCSpawnEntriesContainer.IniCollectionKey}=")));
Server.Profile.ConfigSubtractNPCSpawnEntriesContainer.AddRange(configSubtractNPCSpawnEntriesContainer); Server.Profile.ConfigSubtractNPCSpawnEntriesContainer.AddRange(configSubtractNPCSpawnEntriesContainer);
Server.Profile.ConfigSubtractNPCSpawnEntriesContainer.IsEnabled |= configSubtractNPCSpawnEntriesContainer.IsEnabled; Server.Profile.ConfigSubtractNPCSpawnEntriesContainer.IsEnabled |= configSubtractNPCSpawnEntriesContainer.IsEnabled;
var configOverrideNPCSpawnEntriesContainer = new NPCSpawnContainerList<NPCSpawnContainer>(nameof(Server.Profile.ConfigOverrideNPCSpawnEntriesContainer), NPCSpawnContainerType.Override); var configOverrideNPCSpawnEntriesContainer = new NPCSpawnContainerList<NPCSpawnContainer>(nameof(Server.Profile.ConfigOverrideNPCSpawnEntriesContainer), NPCSpawnContainerType.Override);
configOverrideNPCSpawnEntriesContainer.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{configOverrideNPCSpawnEntriesContainer.IniCollectionKey}="))); configOverrideNPCSpawnEntriesContainer.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{configOverrideNPCSpawnEntriesContainer.IniCollectionKey}=")));
Server.Profile.ConfigOverrideNPCSpawnEntriesContainer.AddRange(configOverrideNPCSpawnEntriesContainer); Server.Profile.ConfigOverrideNPCSpawnEntriesContainer.AddRange(configOverrideNPCSpawnEntriesContainer);
Server.Profile.ConfigOverrideNPCSpawnEntriesContainer.IsEnabled |= configOverrideNPCSpawnEntriesContainer.IsEnabled; Server.Profile.ConfigOverrideNPCSpawnEntriesContainer.IsEnabled |= configOverrideNPCSpawnEntriesContainer.IsEnabled;
} }
@ -3123,7 +3123,7 @@ namespace ServerManagerTool
foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
var configOverrideSupplyCrateItems = new SupplyCrateOverrideList(nameof(Server.Profile.ConfigOverrideSupplyCrateItems)); var configOverrideSupplyCrateItems = new SupplyCrateOverrideList(nameof(Server.Profile.ConfigOverrideSupplyCrateItems));
configOverrideSupplyCrateItems.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{configOverrideSupplyCrateItems.IniCollectionKey}="))); configOverrideSupplyCrateItems.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{configOverrideSupplyCrateItems.IniCollectionKey}=")));
Server.Profile.ConfigOverrideSupplyCrateItems.AddRange(configOverrideSupplyCrateItems); Server.Profile.ConfigOverrideSupplyCrateItems.AddRange(configOverrideSupplyCrateItems);
Server.Profile.ConfigOverrideSupplyCrateItems.IsEnabled |= configOverrideSupplyCrateItems.IsEnabled; Server.Profile.ConfigOverrideSupplyCrateItems.IsEnabled |= configOverrideSupplyCrateItems.IsEnabled;
} }
@ -3133,7 +3133,7 @@ namespace ServerManagerTool
RefreshBaseSupplyCrateList(); RefreshBaseSupplyCrateList();
RefreshBasePrimalItemList(); RefreshBasePrimalItemList();
if (errors.Length > 0) if (errors.Any())
{ {
var error = $"The following errors have been found:\r\n\r\n{string.Join("\r\n", errors)}"; var error = $"The following errors have been found:\r\n\r\n{string.Join("\r\n", errors)}";
@ -3265,7 +3265,7 @@ namespace ServerManagerTool
foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
var configOverrideItemMaxQuantity = new AggregateIniValueList<StackSizeOverride>(nameof(Server.Profile.ConfigOverrideItemMaxQuantity), null); var configOverrideItemMaxQuantity = new AggregateIniValueList<StackSizeOverride>(nameof(Server.Profile.ConfigOverrideItemMaxQuantity), null);
configOverrideItemMaxQuantity.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{configOverrideItemMaxQuantity.IniCollectionKey}="))); configOverrideItemMaxQuantity.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{configOverrideItemMaxQuantity.IniCollectionKey}=")));
Server.Profile.ConfigOverrideItemMaxQuantity.AddRange(configOverrideItemMaxQuantity); Server.Profile.ConfigOverrideItemMaxQuantity.AddRange(configOverrideItemMaxQuantity);
Server.Profile.ConfigOverrideItemMaxQuantity.IsEnabled |= configOverrideItemMaxQuantity.IsEnabled; Server.Profile.ConfigOverrideItemMaxQuantity.IsEnabled |= configOverrideItemMaxQuantity.IsEnabled;
} }
@ -3274,7 +3274,7 @@ namespace ServerManagerTool
RefreshBasePrimalItemList(); RefreshBasePrimalItemList();
if (errors.Length > 0) if (errors.Any())
{ {
var error = $"The following errors have been found:\r\n\r\n{string.Join("\r\n", errors)}"; var error = $"The following errors have been found:\r\n\r\n{string.Join("\r\n", errors)}";
@ -3365,7 +3365,7 @@ namespace ServerManagerTool
foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName))) foreach (var section in iniFile.Sections.Where(s => s.SectionName != null && !SystemIniFile.IniSectionNames.ContainsValue(s.SectionName)))
{ {
var preventTransferForClassNames = new AggregateIniValueList<PreventTransferOverride>(nameof(Server.Profile.PreventTransferForClassNames), null); var preventTransferForClassNames = new AggregateIniValueList<PreventTransferOverride>(nameof(Server.Profile.PreventTransferForClassNames), null);
preventTransferForClassNames.FromIniValues(section.KeysToStringArray().Where(s => s.StartsWith($"{preventTransferForClassNames.IniCollectionKey}="))); preventTransferForClassNames.FromIniValues(section.KeysToStringEnumerable().Where(s => s.StartsWith($"{preventTransferForClassNames.IniCollectionKey}=")));
Server.Profile.PreventTransferForClassNames.AddRange(preventTransferForClassNames); Server.Profile.PreventTransferForClassNames.AddRange(preventTransferForClassNames);
Server.Profile.PreventTransferForClassNames.IsEnabled |= preventTransferForClassNames.IsEnabled; Server.Profile.PreventTransferForClassNames.IsEnabled |= preventTransferForClassNames.IsEnabled;
} }
@ -3374,7 +3374,7 @@ namespace ServerManagerTool
RefreshBaseDinoList(); RefreshBaseDinoList();
if (errors.Length > 0) if (errors.Any())
{ {
var error = $"The following errors have been found:\r\n\r\n{string.Join("\r\n", errors)}"; var error = $"The following errors have been found:\r\n\r\n{string.Join("\r\n", errors)}";

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
@ -18,29 +19,35 @@ namespace ArkData
/// <returns>The async task context containing the resulting container.</returns> /// <returns>The async task context containing the resulting container.</returns>
public static async Task<DataContainer> CreateAsync(string playerFileFolder, string tribeFileFolder) public static async Task<DataContainer> CreateAsync(string playerFileFolder, string tribeFileFolder)
{ {
var playerFiles = new string[0]; IEnumerable<string> playerFiles = null;
var tribeFiles = new string[0]; IEnumerable<string> tribeFiles = null;
if (Directory.Exists(playerFileFolder)) if (Directory.Exists(playerFileFolder))
{ {
playerFiles = Directory.GetFiles(playerFileFolder).Where(f => Path.GetFileNameWithoutExtension(f).StartsWith(DataFileDetails.PlayerFilePrefix) playerFiles = Directory.GetFiles(playerFileFolder).Where(f => Path.GetFileNameWithoutExtension(f).StartsWith(DataFileDetails.PlayerFilePrefix)
&& Path.GetFileNameWithoutExtension(f).EndsWith(DataFileDetails.PlayerFileSuffix) && Path.GetFileNameWithoutExtension(f).EndsWith(DataFileDetails.PlayerFileSuffix)
&& Path.GetExtension(f).Equals(DataFileDetails.PlayerFileExtension)).ToArray(); && Path.GetExtension(f).Equals(DataFileDetails.PlayerFileExtension));
} }
if (Directory.Exists(tribeFileFolder)) if (Directory.Exists(tribeFileFolder))
{ {
tribeFiles = Directory.GetFiles(tribeFileFolder).Where(f => Path.GetFileNameWithoutExtension(f).StartsWith(DataFileDetails.TribeFilePrefix) tribeFiles = Directory.GetFiles(tribeFileFolder).Where(f => Path.GetFileNameWithoutExtension(f).StartsWith(DataFileDetails.TribeFilePrefix)
&& Path.GetFileNameWithoutExtension(f).EndsWith(DataFileDetails.TribeFileSuffix) && Path.GetFileNameWithoutExtension(f).EndsWith(DataFileDetails.TribeFileSuffix)
&& Path.GetExtension(f).Equals(DataFileDetails.TribeFileExtension)).ToArray(); && Path.GetExtension(f).Equals(DataFileDetails.TribeFileExtension));
} }
var container = new DataContainer(); var container = new DataContainer();
if (playerFiles != null)
{
foreach (var file in playerFiles) foreach (var file in playerFiles)
container.Players.Add(await Parser.ParsePlayerAsync(file)); container.Players.Add(await Parser.ParsePlayerAsync(file));
}
if (tribeFiles != null)
{
foreach (var file in tribeFiles) foreach (var file in tribeFiles)
container.Tribes.Add(await Parser.ParseTribeAsync(file)); container.Tribes.Add(await Parser.ParseTribeAsync(file));
}
container.LinkPlayerTribe(); container.LinkPlayerTribe();
@ -58,14 +65,14 @@ namespace ArkData
// need to make multiple calls of 100 steam id's. // need to make multiple calls of 100 steam id's.
var lastSteamUpdateUtc = DateTime.UtcNow; var lastSteamUpdateUtc = DateTime.UtcNow;
var startIndex = 0; var startIndex = 0;
var playerSteamIds = Players.Where(p => p.LastPlatformUpdateUtc.AddMinutes(steamUpdateInterval) < DateTime.UtcNow).Select(p => p.PlayerId).ToArray(); var playerSteamIds = Players.Where(p => p.LastPlatformUpdateUtc.AddMinutes(steamUpdateInterval) < DateTime.UtcNow).Select(p => p.PlayerId);
while (true) while (true)
{ {
// check if the start index has exceeded the Players list count. // check if the start index has exceeded the Players list count.
if (startIndex >= playerSteamIds.Length) break; if (startIndex >= playerSteamIds.Count()) break;
// get the number of steam ids to read. // get the number of steam ids to read.
int steamIdsCount = System.Math.Min(MAX_STEAM_IDS, playerSteamIds.Length - startIndex); int steamIdsCount = Math.Min(MAX_STEAM_IDS, playerSteamIds.Count() - startIndex);
// get a comma delimited list of the steam ids to process // get a comma delimited list of the steam ids to process
var builder = string.Join(",", playerSteamIds, startIndex, steamIdsCount); var builder = string.Join(",", playerSteamIds, startIndex, steamIdsCount);

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
@ -16,29 +17,35 @@ namespace ArkData
/// </summary> /// </summary>
public static DataContainer Create(string playerFileFolder, string tribeFileFolder) public static DataContainer Create(string playerFileFolder, string tribeFileFolder)
{ {
var playerFiles = new string[0]; IEnumerable<string> playerFiles = null;
var tribeFiles = new string[0]; IEnumerable<string> tribeFiles = null;
if (Directory.Exists(playerFileFolder)) if (Directory.Exists(playerFileFolder))
{ {
playerFiles = Directory.GetFiles(playerFileFolder).Where(f => Path.GetFileNameWithoutExtension(f).StartsWith(DataFileDetails.PlayerFilePrefix) playerFiles = Directory.GetFiles(playerFileFolder).Where(f => Path.GetFileNameWithoutExtension(f).StartsWith(DataFileDetails.PlayerFilePrefix)
&& Path.GetFileNameWithoutExtension(f).EndsWith(DataFileDetails.PlayerFileSuffix) && Path.GetFileNameWithoutExtension(f).EndsWith(DataFileDetails.PlayerFileSuffix)
&& Path.GetExtension(f).Equals(DataFileDetails.PlayerFileExtension)).ToArray(); && Path.GetExtension(f).Equals(DataFileDetails.PlayerFileExtension));
} }
if (Directory.Exists(tribeFileFolder)) if (Directory.Exists(tribeFileFolder))
{ {
tribeFiles = Directory.GetFiles(tribeFileFolder).Where(f => Path.GetFileNameWithoutExtension(f).StartsWith(DataFileDetails.TribeFilePrefix) tribeFiles = Directory.GetFiles(tribeFileFolder).Where(f => Path.GetFileNameWithoutExtension(f).StartsWith(DataFileDetails.TribeFilePrefix)
&& Path.GetFileNameWithoutExtension(f).EndsWith(DataFileDetails.TribeFileSuffix) && Path.GetFileNameWithoutExtension(f).EndsWith(DataFileDetails.TribeFileSuffix)
&& Path.GetExtension(f).Equals(DataFileDetails.TribeFileExtension)).ToArray(); && Path.GetExtension(f).Equals(DataFileDetails.TribeFileExtension));
} }
var container = new DataContainer(); var container = new DataContainer();
if (playerFiles != null)
{
foreach (var file in playerFiles) foreach (var file in playerFiles)
container.Players.Add(Parser.ParsePlayer(file)); container.Players.Add(Parser.ParsePlayer(file));
}
if (tribeFiles != null)
{
foreach (var file in tribeFiles) foreach (var file in tribeFiles)
container.Tribes.Add(Parser.ParseTribe(file)); container.Tribes.Add(Parser.ParseTribe(file));
}
container.LinkPlayerTribe(); container.LinkPlayerTribe();
@ -56,14 +63,14 @@ namespace ArkData
// need to make multiple calls of 100 steam id's. // need to make multiple calls of 100 steam id's.
var lastSteamUpdateUtc = DateTime.UtcNow; var lastSteamUpdateUtc = DateTime.UtcNow;
var startIndex = 0; var startIndex = 0;
var playerSteamIds = Players.Where(p => p.LastPlatformUpdateUtc.AddMinutes(steamUpdateInterval) < DateTime.UtcNow).Select(p => p.PlayerId).ToArray(); var playerSteamIds = Players.Where(p => p.LastPlatformUpdateUtc.AddMinutes(steamUpdateInterval) < DateTime.UtcNow).Select(p => p.PlayerId);
while (true) while (true)
{ {
// check if the start index has exceeded the Players list count. // check if the start index has exceeded the Players list count.
if (startIndex >= playerSteamIds.Length) break; if (startIndex >= playerSteamIds.Count()) break;
// get the number of steam ids to read. // get the number of steam ids to read.
int steamIdsCount = System.Math.Min(MAX_STEAM_IDS, playerSteamIds.Length - startIndex); int steamIdsCount = Math.Min(MAX_STEAM_IDS, playerSteamIds.Count() - startIndex);
// get a comma delimited list of the steam ids to process // get a comma delimited list of the steam ids to process
var builder = string.Join(",", playerSteamIds, startIndex, steamIdsCount); var builder = string.Join(",", playerSteamIds, startIndex, steamIdsCount);

View file

@ -18,7 +18,7 @@ namespace ArkData
return -1; return -1;
} }
public static int[] Locate(this byte[] self, byte[] candidate) public static IEnumerable<int> Locate(this byte[] self, byte[] candidate)
{ {
if (IsEmptyLocate(self, candidate, 0)) if (IsEmptyLocate(self, candidate, 0))
return Empty; return Empty;
@ -29,7 +29,7 @@ namespace ArkData
list.Add(position); list.Add(position);
if (list.Count != 0) if (list.Count != 0)
return list.ToArray(); return list;
return Empty; return Empty;
} }

View file

@ -1790,7 +1790,7 @@ namespace ServerManagerTool.Lib
comment.AppendLine($"Profile Name: {_profile.ProfileName}"); comment.AppendLine($"Profile Name: {_profile.ProfileName}");
comment.AppendLine($"Process: {ServerProcess}"); comment.AppendLine($"Process: {ServerProcess}");
ZipUtils.ZipFiles(backupFile, files.ToArray(), comment.ToString(), false); ZipUtils.ZipFiles(backupFile, files, comment.ToString(), false);
LogProfileMessage($"Backup file created - {backupFile}"); LogProfileMessage($"Backup file created - {backupFile}");
} }
@ -1910,7 +1910,7 @@ namespace ServerManagerTool.Lib
ZipUtils.ZipAFile(backupFile, worldFileName, worldBackupFile, comment.ToString()); ZipUtils.ZipAFile(backupFile, worldFileName, worldBackupFile, comment.ToString());
if (files.Count > 0) if (files.Count > 0)
ZipUtils.UpdateFiles(backupFile, files.ToArray(), null, false, ""); ZipUtils.UpdateFiles(backupFile, files, null, false, "");
LogProfileMessage($"Backed up world files - {saveFolder}"); LogProfileMessage($"Backed up world files - {saveFolder}");
LogProfileMessage($"Backup file created - {backupFile}"); LogProfileMessage($"Backup file created - {backupFile}");
@ -2851,7 +2851,7 @@ namespace ServerManagerTool.Lib
if (ExitCode == EXITCODE_NORMALEXIT) if (ExitCode == EXITCODE_NORMALEXIT)
{ {
// get the profile associated with the branch // get the profile associated with the branch
var profiles = _profiles.Keys.Where(p => p.EnableAutoUpdate && p.BranchName.Equals(branch.BranchName, StringComparison.OrdinalIgnoreCase)).ToArray(); var profiles = _profiles.Keys.Where(p => p.EnableAutoUpdate && p.BranchName.Equals(branch.BranchName, StringComparison.OrdinalIgnoreCase));
var profileExitCodes = new ConcurrentDictionary<ServerProfileSnapshot, int>(); var profileExitCodes = new ConcurrentDictionary<ServerProfileSnapshot, int>();
if (Config.Default.AutoUpdate_ParallelUpdate) if (Config.Default.AutoUpdate_ParallelUpdate)
@ -3102,7 +3102,7 @@ namespace ServerManagerTool.Lib
if (exitCode == EXITCODE_NORMALEXIT) if (exitCode == EXITCODE_NORMALEXIT)
{ {
var branches = _profiles.Keys.Where(p => p.EnableAutoUpdate).Select(p => BranchSnapshot.Create(p)).Distinct(new BranchSnapshotComparer()).ToArray(); var branches = _profiles.Keys.Where(p => p.EnableAutoUpdate).Select(p => BranchSnapshot.Create(p)).Distinct(new BranchSnapshotComparer());
var exitCodes = new ConcurrentDictionary<BranchSnapshot, int>(); var exitCodes = new ConcurrentDictionary<BranchSnapshot, int>();
// update the server cache for each branch // update the server cache for each branch

View file

@ -212,7 +212,7 @@ namespace ServerManagerTool.Lib
return; return;
// remove any players that do not have a player record. // remove any players that do not have a player record.
var droppedPlayers = this._players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null).ToArray(); var droppedPlayers = this._players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null);
foreach (var droppedPlayer in droppedPlayers) foreach (var droppedPlayer in droppedPlayers)
{ {
_players.TryRemove(droppedPlayer.PlayerId, out PlayerInfo player); _players.TryRemove(droppedPlayer.PlayerId, out PlayerInfo player);

View file

@ -792,11 +792,9 @@ namespace ServerManagerTool.Lib
} }
} }
private static Enum[] GetExclusions() private static IEnumerable<Enum> GetExclusions()
{ {
var exclusions = new List<Enum>(); return new List<Enum>();
return exclusions.ToArray();
} }
public string GetLauncherFile() => Path.Combine(GetProfileServerConfigDir(), Config.Default.LauncherFile); public string GetLauncherFile() => Path.Combine(GetProfileServerConfigDir(), Config.Default.LauncherFile);
@ -885,7 +883,7 @@ namespace ServerManagerTool.Lib
return profile; return profile;
} }
public static ServerProfile LoadFromConfigFiles(string file, ServerProfile profile, Enum[] exclusions = null) public static ServerProfile LoadFromConfigFiles(string file, ServerProfile profile, IEnumerable<Enum> exclusions = null)
{ {
if (string.IsNullOrWhiteSpace(file) || !File.Exists(file)) if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
return null; return null;
@ -1108,7 +1106,7 @@ namespace ServerManagerTool.Lib
SaveConfigFile(serverConfigDir); SaveConfigFile(serverConfigDir);
} }
public void SaveConfigFile(string configDir, Enum[] exclusions = null) public void SaveConfigFile(string configDir, IEnumerable<Enum> exclusions = null)
{ {
if (exclusions == null) if (exclusions == null)
exclusions = GetExclusions(); exclusions = GetExclusions();
@ -1656,7 +1654,7 @@ namespace ServerManagerTool.Lib
Directory.CreateDirectory(folder); Directory.CreateDirectory(folder);
var file = Path.Combine(folder, Config.Default.ServerBlacklistFile); var file = Path.Combine(folder, Config.Default.ServerBlacklistFile);
File.WriteAllLines(file, this.ServerFilesBlacklisted.ToArray()); File.WriteAllLines(file, this.ServerFilesBlacklisted.ToEnumerable());
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -1673,7 +1671,7 @@ namespace ServerManagerTool.Lib
Directory.CreateDirectory(folder); Directory.CreateDirectory(folder);
var file = Path.Combine(folder, Config.Default.ServerWhitelistFile); var file = Path.Combine(folder, Config.Default.ServerWhitelistFile);
File.WriteAllLines(file, this.ServerFilesWhitelisted.ToArray()); File.WriteAllLines(file, this.ServerFilesWhitelisted.ToEnumerable());
} }
catch (Exception ex) catch (Exception ex)
{ {

View file

@ -450,7 +450,7 @@ namespace ServerManagerTool.Lib
return new List<string>(); return new List<string>();
// remove any players that do not have a player record. // remove any players that do not have a player record.
var droppedPlayers = this._players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null).ToArray(); var droppedPlayers = this._players.Values.Where(p => dataContainer.Players.FirstOrDefault(pd => pd.PlayerId.Equals(p.PlayerId, StringComparison.OrdinalIgnoreCase)) == null);
foreach (var droppedPlayer in droppedPlayers) foreach (var droppedPlayer in droppedPlayers)
{ {
_players.TryRemove(droppedPlayer.PlayerId, out PlayerInfo player); _players.TryRemove(droppedPlayer.PlayerId, out PlayerInfo player);

View file

@ -720,7 +720,7 @@ namespace ServerManagerTool
var zipFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), this.Settings.ProfileID + ".zip"); var zipFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), this.Settings.ProfileID + ".zip");
if (File.Exists(zipFile)) File.Delete(zipFile); if (File.Exists(zipFile)) File.Delete(zipFile);
ZipUtils.ZipFiles(zipFile, files.ToArray(), comment.ToString()); ZipUtils.ZipFiles(zipFile, files, comment.ToString());
foreach (var kvp in obfuscateFiles) foreach (var kvp in obfuscateFiles)
{ {
ZipUtils.ZipAFile(zipFile, kvp.Key, kvp.Value); ZipUtils.ZipAFile(zipFile, kvp.Key, kvp.Value);

View file

@ -86,7 +86,7 @@ namespace ServerManagerTool.Utils
Directory.CreateDirectory(modRootFolder); Directory.CreateDirectory(modRootFolder);
// get the a list of the mod file into include in the mod file // get the a list of the mod file into include in the mod file
var modFileItems = modIdList.Select(m => $"{m}.pak").ToArray(); var modFileItems = modIdList.Select(m => $"{m}.pak");
// create the mod file. // create the mod file.
File.WriteAllLines(modListFile, modFileItems); File.WriteAllLines(modListFile, modFileItems);
} }

View file

@ -50,14 +50,7 @@ namespace QueryMaster
//consecutive rcon command replies start with an empty packet //consecutive rcon command replies start with an empty packet
if (BitConverter.ToInt32(recvData[i], 4) == (int)PacketId.Empty) if (BitConverter.ToInt32(recvData[i], 4) == (int)PacketId.Empty)
continue; continue;
//if (recvData[i].Length - BitConverter.ToInt32(recvData[i], 0) == 4)
//{
str.Append(RconUtil.ProcessPacket(recvData[i]).Body); str.Append(RconUtil.ProcessPacket(recvData[i]).Body);
//}
//else
//{
// str.Append(RconUtil.ProcessPacket(recvData[i]).Body + Util.BytesToString(recvData[++i].Take(recvData[i].Length - 2).ToArray()));
//}
} }
} }
catch (Exception e) catch (Exception e)

View file

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QueryMaster namespace QueryMaster
{ {

View file

@ -1,10 +1,12 @@
namespace ServerManagerTool.Common.Interfaces using System.Collections.Generic;
namespace ServerManagerTool.Common.Interfaces
{ {
public interface IIniSectionCollection public interface IIniSectionCollection
{ {
IIniValuesCollection[] Sections { get; } IIniValuesCollection[] Sections { get; }
void Add(string sectionName, string[] values); void Add(string sectionName, IEnumerable<string> values);
void Update(); void Update();
} }

View file

@ -13,7 +13,7 @@ namespace ServerManagerTool.Common.Lib
{ {
JsonProperty property = base.CreateProperty(member, memberSerialization); JsonProperty property = base.CreateProperty(member, memberSerialization);
var customAttributes = member.CustomAttributes?.ToArray() ?? new CustomAttributeData[0]; var customAttributes = member.CustomAttributes ?? new CustomAttributeData[0];
if (customAttributes.Any(a => a.AttributeType == typeof(System.Configuration.UserScopedSettingAttribute))) if (customAttributes.Any(a => a.AttributeType == typeof(System.Configuration.UserScopedSettingAttribute)))
{ {
property.ShouldSerialize = instance => { return property.PropertyType.IsValueType || property.PropertyType == typeof(string); }; property.ShouldSerialize = instance => { return property.PropertyType.IsValueType || property.PropertyType == typeof(string); };

View file

@ -173,13 +173,13 @@ namespace ServerManagerTool.Common.Model
if (property.GetValue(this) is IIniValuesCollection collection) if (property.GetValue(this) is IIniValuesCollection collection)
{ {
var values = SplitCollectionValues(kvPropertyValue, DELIMITER); var values = SplitCollectionValues(kvPropertyValue, DELIMITER)
values = values.Where(v => !string.IsNullOrWhiteSpace(v)).ToArray(); .Where(v => !string.IsNullOrWhiteSpace(v));
if (attr?.ListValueWithinBrackets ?? false) if (attr?.ListValueWithinBrackets ?? false)
{ {
values = values.Select(v => v.Substring(1)).ToArray(); values = values.Select(v => v.Substring(1));
values = values.Select(v => v.Substring(0, v.Length - 1)).ToArray(); values = values.Select(v => v.Substring(0, v.Length - 1));
} }
collection.FromIniValues(values); collection.FromIniValues(values);
} }
@ -266,7 +266,7 @@ namespace ServerManagerTool.Common.Model
return result.ToString(); return result.ToString();
} }
protected string[] SplitCollectionValues(string valueString, char delimiter) protected IEnumerable<string> SplitCollectionValues(string valueString, char delimiter)
{ {
if (string.IsNullOrWhiteSpace(valueString)) if (string.IsNullOrWhiteSpace(valueString))
return new string[0]; return new string[0];
@ -306,7 +306,7 @@ namespace ServerManagerTool.Common.Model
result.Add(tempString.Substring(startIndex)); result.Add(tempString.Substring(startIndex));
return result.ToArray(); return result;
} }
public void Update(AggregateIniValue other) public void Update(AggregateIniValue other)

View file

@ -59,17 +59,16 @@ namespace ServerManagerTool.Common.Model
public virtual void FromIniValues(IEnumerable<string> iniValues) public virtual void FromIniValues(IEnumerable<string> iniValues)
{ {
var items = iniValues?.Select(AggregateIniValue.FromINIValue<T>).ToArray(); var items = iniValues?.Select(AggregateIniValue.FromINIValue<T>);
Clear(); Clear();
AddRange(items); AddRange(items);
IsEnabled = (Count != 0); IsEnabled = (Count > 0);
// Add any default values which were missing // Add any default values which were missing
if (_resetFunc != null) if (_resetFunc != null)
{ {
var defaultItemsToAdd = _resetFunc().Where(r => !this.Any(v => v.IsEquivalent(r))).ToArray(); AddRange(_resetFunc().Where(r => !this.Any(v => v.IsEquivalent(r))));
AddRange(defaultItemsToAdd);
} }
Sort(AggregateIniValue.SortKeySelector); Sort(AggregateIniValue.SortKeySelector);

View file

@ -1,5 +1,6 @@
using ServerManagerTool.Common.Interfaces; using ServerManagerTool.Common.Interfaces;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace ServerManagerTool.Common.Model namespace ServerManagerTool.Common.Model
@ -14,12 +15,12 @@ namespace ServerManagerTool.Common.Model
} }
} }
public void Add(string sectionName, string[] values) public void Add(string sectionName, IEnumerable<string> values)
{ {
Add(sectionName, values, true); Add(sectionName, values, true);
} }
public void Add(string sectionName, string[] values, bool clearExisting) public void Add(string sectionName, IEnumerable<string> values, bool clearExisting)
{ {
var section = this.Items.FirstOrDefault(s => s.SectionName.Equals(sectionName, StringComparison.OrdinalIgnoreCase) && !s.IsDeleted); var section = this.Items.FirstOrDefault(s => s.SectionName.Equals(sectionName, StringComparison.OrdinalIgnoreCase) && !s.IsDeleted);
if (section == null) if (section == null)

View file

@ -98,8 +98,7 @@ namespace ServerManagerTool.Common.Model
// Add any default values which were missing // Add any default values which were missing
if (this.ResetFunc != null) if (this.ResetFunc != null)
{ {
var defaultItemsToAdd = this.ResetFunc().Where(r => !this.Any(v => this.EquivalencyFunc(v, r))).ToArray(); this.AddRange(this.ResetFunc().Where(r => !this.Any(v => this.EquivalencyFunc(v, r))));
this.AddRange(defaultItemsToAdd);
this.Sort(this.SortKeySelectorFunc); this.Sort(this.SortKeySelectorFunc);
} }
} }

View file

@ -1,4 +1,5 @@
using System.Collections.ObjectModel; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
@ -68,16 +69,15 @@ namespace ServerManagerTool.Common.Model
public void Remove(string steamId) public void Remove(string steamId)
{ {
var items = this.Where(i => i.PlayerId.Equals(steamId, System.StringComparison.OrdinalIgnoreCase)).ToArray(); foreach (var item in this.Where(i => i.PlayerId.Equals(steamId, System.StringComparison.OrdinalIgnoreCase)))
foreach (var item in items)
{ {
this.Remove(item); this.Remove(item);
} }
} }
public string[] ToArray() public IEnumerable<string> ToEnumerable()
{ {
return this.Select(i => i.PlayerId).ToArray(); return this.Select(i => i.PlayerId);
} }
public string ToDelimitedString(string delimiter) public string ToDelimitedString(string delimiter)

View file

@ -18,7 +18,7 @@ namespace ServerManagerTool.Common.Model
var tableValue = value as VdfTable; var tableValue = value as VdfTable;
if (tableValue != null && tableValue.Count > 0) if (tableValue != null && tableValue.Count > 0)
{ {
var betaKeyItems = tableValue.Where(v => v.Name.Equals("betakey", StringComparison.OrdinalIgnoreCase)).ToArray(); var betaKeyItems = tableValue.Where(v => v.Name.Equals("betakey", StringComparison.OrdinalIgnoreCase));
foreach (var item in betaKeyItems) foreach (var item in betaKeyItems)
{ {
tableValue.Remove(item); tableValue.Remove(item);

View file

@ -32,7 +32,7 @@ namespace ServerManagerTool.Common.Serialization
get; get;
} }
public void Deserialize(object obj, Enum[] exclusions) public void Deserialize(object obj, IEnumerable<Enum> exclusions)
{ {
var iniFiles = new Dictionary<string, IniFile>(); var iniFiles = new Dictionary<string, IniFile>();
var fields = obj.GetType() var fields = obj.GetType()
@ -168,7 +168,7 @@ namespace ServerManagerTool.Common.Serialization
} }
} }
public void Serialize(object obj, Enum[] exclusions) public void Serialize(object obj, IEnumerable<Enum> exclusions)
{ {
var iniFiles = new Dictionary<string, IniFile>(); var iniFiles = new Dictionary<string, IniFile>();
var fields = obj.GetType() var fields = obj.GetType()
@ -205,7 +205,7 @@ namespace ServerManagerTool.Common.Serialization
if (section.IsEnabled) if (section.IsEnabled)
{ {
WriteSection(iniFiles, attr.File, section.IniCollectionKey, section.ToIniValues().ToArray()); WriteSection(iniFiles, attr.File, section.IniCollectionKey, section.ToIniValues());
} }
} }
} }
@ -228,8 +228,7 @@ namespace ServerManagerTool.Common.Serialization
{ {
var section = ReadSection(iniFiles, attr.File, attr.Section); var section = ReadSection(iniFiles, attr.File, attr.Section);
var filteredSection = section var filteredSection = section
.Where(s => !s.StartsWith(collection.IniCollectionKey + (collection.IsArray ? "[" : "="))) .Where(s => !s.StartsWith(collection.IniCollectionKey + (collection.IsArray ? "[" : "=")));
.ToArray();
WriteSection(iniFiles, attr.File, attr.Section, filteredSection); WriteSection(iniFiles, attr.File, attr.Section, filteredSection);
} }
@ -314,7 +313,7 @@ namespace ServerManagerTool.Common.Serialization
result = result.Concat(collection.ToIniValues()); result = result.Concat(collection.ToIniValues());
} }
WriteSection(iniFiles, attr.File, attr.Section, result?.ToArray()); WriteSection(iniFiles, attr.File, attr.Section, result);
} }
} }
else else
@ -381,29 +380,29 @@ namespace ServerManagerTool.Common.Serialization
SaveFiles(iniFiles); SaveFiles(iniFiles);
} }
public string[] ReadSection(Enum iniFile, Enum section) public IEnumerable<string> ReadSection(Enum iniFile, Enum section)
{ {
return ReadSection(iniFile, SectionNames[section]); return ReadSection(iniFile, SectionNames[section]);
} }
public string[] ReadSection(Enum iniFile, string sectionName) public IEnumerable<string> ReadSection(Enum iniFile, string sectionName)
{ {
var file = Path.Combine(this.BasePath, FileNames[iniFile]); var file = Path.Combine(this.BasePath, FileNames[iniFile]);
return IniFileUtils.ReadSection(file, sectionName); return IniFileUtils.ReadSection(file, sectionName);
} }
public void WriteSection(Enum iniFile, Enum section, string[] values) public void WriteSection(Enum iniFile, Enum section, IEnumerable<string> values)
{ {
WriteSection(iniFile, SectionNames[section], values); WriteSection(iniFile, SectionNames[section], values);
} }
public void WriteSection(Enum iniFile, string sectionName, string[] values) public void WriteSection(Enum iniFile, string sectionName, IEnumerable<string> values)
{ {
var file = Path.Combine(this.BasePath, FileNames[iniFile]); var file = Path.Combine(this.BasePath, FileNames[iniFile]);
IniFileUtils.WriteSection(file, sectionName, values); IniFileUtils.WriteSection(file, sectionName, values);
} }
private string[] ReadCustomSectionNames(Dictionary<string, IniFile> iniFiles, Enum iniFile) private IEnumerable<string> ReadCustomSectionNames(Dictionary<string, IniFile> iniFiles, Enum iniFile)
{ {
if (!iniFiles.ContainsKey(FileNames[iniFile])) if (!iniFiles.ContainsKey(FileNames[iniFile]))
{ {
@ -415,15 +414,15 @@ namespace ServerManagerTool.Common.Serialization
} }
} }
return iniFiles[FileNames[iniFile]].Sections.Select(s => s.SectionName).Where(s => !SectionNames.ContainsValue(s)).ToArray(); return iniFiles[FileNames[iniFile]].Sections.Select(s => s.SectionName).Where(s => !SectionNames.ContainsValue(s));
} }
private string[] ReadSection(Dictionary<string, IniFile> iniFiles, Enum iniFile, Enum section) private IEnumerable<string> ReadSection(Dictionary<string, IniFile> iniFiles, Enum iniFile, Enum section)
{ {
return ReadSection(iniFiles, iniFile, SectionNames[section]); return ReadSection(iniFiles, iniFile, SectionNames[section]);
} }
private string[] ReadSection(Dictionary<string, IniFile> iniFiles, Enum iniFile, string sectionName) private IEnumerable<string> ReadSection(Dictionary<string, IniFile> iniFiles, Enum iniFile, string sectionName)
{ {
if (!iniFiles.ContainsKey(FileNames[iniFile])) if (!iniFiles.ContainsKey(FileNames[iniFile]))
{ {
@ -435,7 +434,7 @@ namespace ServerManagerTool.Common.Serialization
} }
} }
return iniFiles[FileNames[iniFile]].GetSection(sectionName)?.KeysToStringArray() ?? new string[0]; return iniFiles[FileNames[iniFile]].GetSection(sectionName)?.KeysToStringEnumerable() ?? new string[0];
} }
private string ReadValue(Dictionary<string, IniFile> iniFiles, Enum iniFile, Enum section, string keyName) private string ReadValue(Dictionary<string, IniFile> iniFiles, Enum iniFile, Enum section, string keyName)
@ -453,12 +452,12 @@ namespace ServerManagerTool.Common.Serialization
return iniFiles[FileNames[iniFile]].GetKey(SectionNames[section], keyName)?.KeyValue ?? string.Empty; return iniFiles[FileNames[iniFile]].GetKey(SectionNames[section], keyName)?.KeyValue ?? string.Empty;
} }
private void WriteSection(Dictionary<string, IniFile> iniFiles, Enum iniFile, Enum section, string[] values) private void WriteSection(Dictionary<string, IniFile> iniFiles, Enum iniFile, Enum section, IEnumerable<string> values)
{ {
WriteSection(iniFiles, iniFile, SectionNames[section], values); WriteSection(iniFiles, iniFile, SectionNames[section], values);
} }
private void WriteSection(Dictionary<string, IniFile> iniFiles, Enum iniFile, string sectionName, string[] values) private void WriteSection(Dictionary<string, IniFile> iniFiles, Enum iniFile, string sectionName, IEnumerable<string> values)
{ {
if (!iniFiles.ContainsKey(FileNames[iniFile])) if (!iniFiles.ContainsKey(FileNames[iniFile]))
{ {

View file

@ -68,7 +68,7 @@ namespace ServerManagerTool.Common.Serialization
Sections.Remove(section); Sections.Remove(section);
} }
public bool WriteSection(string sectionName, string[] keysValuePairs) public bool WriteSection(string sectionName, IEnumerable<string> keysValuePairs)
{ {
if (sectionName == null) if (sectionName == null)
return false; return false;
@ -186,7 +186,7 @@ namespace ServerManagerTool.Common.Serialization
{ {
result.AppendLine($"[{section.SectionName}]"); result.AppendLine($"[{section.SectionName}]");
foreach (var keyString in section.KeysToStringArray()) foreach (var keyString in section.KeysToStringEnumerable())
{ {
result.AppendLine(keyString); result.AppendLine(keyString);
} }

View file

@ -41,9 +41,9 @@ namespace ServerManagerTool.Common.Serialization
return Keys?.FirstOrDefault(s => s.KeyName.Equals(keyName, StringComparison.OrdinalIgnoreCase)); return Keys?.FirstOrDefault(s => s.KeyName.Equals(keyName, StringComparison.OrdinalIgnoreCase));
} }
public string[] KeysToStringArray() public IEnumerable<string> KeysToStringEnumerable()
{ {
return Keys.Select(k => k.ToString()).ToArray(); return Keys.Select(k => k.ToString());
} }
public void RemoveKey(string keyName) public void RemoveKey(string keyName)

View file

@ -1,5 +1,6 @@
using ServerManagerTool.Common.Serialization; using ServerManagerTool.Common.Serialization;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@ -13,13 +14,13 @@ namespace ServerManagerTool.Common.Utils
/// <param name="file">The name of the initialization file.</param> /// <param name="file">The name of the initialization file.</param>
/// <param name="sectionName">The name of the section in the initialization file.</param> /// <param name="sectionName">The name of the section in the initialization file.</param>
/// <returns>A string array containing the key name and value pairs associated with the named section.</returns> /// <returns>A string array containing the key name and value pairs associated with the named section.</returns>
public static string[] ReadSection(string file, string sectionName) public static IEnumerable<string> ReadSection(string file, string sectionName)
{ {
if (sectionName == null) if (sectionName == null)
return new string[0]; return new string[0];
var iniFile = ReadFromFile(file); var iniFile = ReadFromFile(file);
return iniFile?.GetSection(sectionName)?.KeysToStringArray() ?? new string[0]; return iniFile?.GetSection(sectionName)?.KeysToStringEnumerable() ?? new string[0];
} }
/// <summary> /// <summary>
@ -46,7 +47,7 @@ namespace ServerManagerTool.Common.Utils
/// <param name="sectionName">The name of the section in which data is written.</param> /// <param name="sectionName">The name of the section in which data is written.</param>
/// <param name="keysValuePairs">An array of key names and associated values that are to be written to the named section.</param> /// <param name="keysValuePairs">An array of key names and associated values that are to be written to the named section.</param>
/// <returns>True if the function succeeds; otherwise False.</returns> /// <returns>True if the function succeeds; otherwise False.</returns>
public static bool WriteSection(string file, string sectionName, string[] keysValuePairs) public static bool WriteSection(string file, string sectionName, IEnumerable<string> keysValuePairs)
{ {
if (sectionName == null) if (sectionName == null)
return false; return false;
@ -165,7 +166,7 @@ namespace ServerManagerTool.Common.Utils
{ {
writer.WriteLine($"[{section.SectionName}]"); writer.WriteLine($"[{section.SectionName}]");
foreach (var keyString in section.KeysToStringArray()) foreach (var keyString in section.KeysToStringEnumerable())
{ {
writer.WriteLine(keyString); writer.WriteLine(keyString);
} }

View file

@ -285,7 +285,7 @@ namespace ServerManagerTool.Common.Utils
} }
} }
public static BigInteger[] GetProcessorAffinityList() public static IEnumerable<BigInteger> GetProcessorAffinityList()
{ {
var processorCount = ProcessorCount; var processorCount = ProcessorCount;
var results = new List<BigInteger>(processorCount + 1); var results = new List<BigInteger>(processorCount + 1);
@ -295,7 +295,7 @@ namespace ServerManagerTool.Common.Utils
{ {
results.Add((BigInteger)Math.Pow(2, index)); results.Add((BigInteger)Math.Pow(2, index));
} }
return results.ToArray(); return results;
} }
public static string[] GetProcessPriorityList() public static string[] GetProcessPriorityList()

View file

@ -49,7 +49,7 @@ namespace ServerManagerTool.Common.Utils
try try
{ {
var filesToDelete = new DirectoryInfo(backupPath).GetFiles($"{settingsFileName}_*{settingsFileExt}").Where(f => f.LastWriteTimeUtc.AddDays(7) < DateTime.UtcNow).ToArray(); var filesToDelete = new DirectoryInfo(backupPath).GetFiles($"{settingsFileName}_*{settingsFileExt}").Where(f => f.LastWriteTimeUtc.AddDays(7) < DateTime.UtcNow);
foreach (var fileToDelete in filesToDelete) foreach (var fileToDelete in filesToDelete)
{ {
try try

View file

@ -1,5 +1,6 @@
using Ionic.Zip; using Ionic.Zip;
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -68,11 +69,11 @@ namespace ServerManagerTool.Common.Utils
} }
} }
public static void UpdateFiles(string zipFile, string[] filesToZip, string comment = "", bool preserveDirHierarchy = true, string directoryPathInArchive = "") public static void UpdateFiles(string zipFile, IEnumerable<string> filesToZip, string comment = "", bool preserveDirHierarchy = true, string directoryPathInArchive = "")
{ {
if (string.IsNullOrWhiteSpace(zipFile)) if (string.IsNullOrWhiteSpace(zipFile))
throw new ArgumentNullException(nameof(zipFile)); throw new ArgumentNullException(nameof(zipFile));
if (filesToZip == null || filesToZip.Length == 0) if (!filesToZip.Any())
return; return;
if (!File.Exists(zipFile)) if (!File.Exists(zipFile))
@ -160,11 +161,11 @@ namespace ServerManagerTool.Common.Utils
} }
} }
public static void ZipFiles(string zipFile, string[] filesToZip, string comment = "", bool preserveDirHierarchy = true, string directoryPathInArchive = "") public static void ZipFiles(string zipFile, IEnumerable<string> filesToZip, string comment = "", bool preserveDirHierarchy = true, string directoryPathInArchive = "")
{ {
if (string.IsNullOrWhiteSpace(zipFile)) if (string.IsNullOrWhiteSpace(zipFile))
throw new ArgumentNullException(nameof(zipFile)); throw new ArgumentNullException(nameof(zipFile));
if (filesToZip == null || filesToZip.Length == 0) if (!filesToZip.Any())
throw new ArgumentNullException(nameof(filesToZip)); throw new ArgumentNullException(nameof(filesToZip));
using (var zip = new ZipFile(zipFile)) using (var zip = new ZipFile(zipFile))

View file

@ -277,7 +277,7 @@ namespace ServerManagerTool.Updater
var processes = ProcessUtils.GetProcesses(process.ProcessName, executablePath); var processes = ProcessUtils.GetProcesses(process.ProcessName, executablePath);
// check if there is more than one instance of the application running // check if there is more than one instance of the application running
if (processes.Length != 1) if (processes.Count() != 1)
throw new Exception("The application to be updated has more than one instance running."); throw new Exception("The application to be updated has more than one instance running.");
// get the command line of the process // get the command line of the process

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@ -83,7 +84,7 @@ namespace ServerManagerTool.Updater
return Process.GetProcessById(processId); return Process.GetProcessById(processId);
} }
public static Process[] GetProcesses(string processName, string executablePath) public static IEnumerable<Process> GetProcesses(string processName, string executablePath)
{ {
var runningProcesses = Process.GetProcessesByName(processName).ToList(); var runningProcesses = Process.GetProcessesByName(processName).ToList();
@ -95,7 +96,7 @@ namespace ServerManagerTool.Updater
runningProcesses.RemoveAt(i); runningProcesses.RemoveAt(i);
} }
return runningProcesses.ToArray(); return runningProcesses;
} }
public static bool IsAlreadyRunning() public static bool IsAlreadyRunning()