Skip to content

Commit

Permalink
Merge pull request #195 from liamcannon/feature/linqOptimization
Browse files Browse the repository at this point in the history
Various LINQ optimizations
  • Loading branch information
jupster authored Sep 30, 2024
2 parents ee973f8 + 8daef5e commit b888dd7
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion FASTER Maintenance/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private static void MigrateTo17()
}
Console.WriteLine($"\tRead config from '{selected}\\user.config'");

var servers = conf16.UserSettings.Settings.Setting.FirstOrDefault(s => s.Name == "Servers");
var servers = conf16.UserSettings.Settings.Setting.Find(s => s.Name == "Servers");
conf16.UserSettings.Settings.Setting.Remove(servers);
conf17.UserSettings = new Models._17Models.UserSettings { Settings = new Models._17Models.Settings { Setting = conf16.UserSettings.Settings.Setting } };
Console.WriteLine("\tConverted standard values to 1.7");
Expand Down
2 changes: 1 addition & 1 deletion FASTER/FASTER.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<PublishReadyToRunComposite>false</PublishReadyToRunComposite>
<UseWPF>true</UseWPF>
<Version>1.9.5.2</Version>
<Version>1.9.5.3</Version>
<Authors>Keelah Fox</Authors>
<Company>FoxliCorp.</Company>
<Description>Fox's Arma Server Tool Extended Rewrite</Description>
Expand Down
2 changes: 1 addition & 1 deletion FASTER/Models/ArmaMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ internal async Task UpdateModAsync()
break;
case UpdateState.Success:
Status = ArmaModStatus.UpToDate;
var nx = new DateTime(1970, 1, 1);
var nx = DateTime.UnixEpoch;
var ts = DateTime.UtcNow - nx;

LocalLastUpdated = (ulong) ts.TotalSeconds;
Expand Down
8 changes: 4 additions & 4 deletions FASTER/Models/ServerCfg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public bool HeadlessClientEnabled
{
headlessClientEnabled = value;
RaisePropertyChanged("HeadlessClientEnabled");
if (value && !headlessClients.Any(e => e.Length > 0))
if (value && !headlessClients.Exists(e => e.Length > 0))
{ HeadlessClients = "127.0.0.1"; }
}
}
Expand Down Expand Up @@ -733,7 +733,7 @@ public List<ProfileMission> Missions

bool isEqual = _missions.Count == value.Count
&& !( from mission in value
let local = _missions.FirstOrDefault(m => m.Path == mission.Path)
let local = _missions.Find(m => m.Path == mission.Path)
where local == null || local.MissionChecked != mission.MissionChecked
select mission ).Any();

Expand Down Expand Up @@ -932,8 +932,8 @@ public string ProcessFile()
+ "\r\n"
+ "\r\n"
+ "// HEADLESS CLIENT\r\n"
+ $"{(headlessClientEnabled && !headlessClients.Any(string.IsNullOrWhiteSpace) ? $"headlessClients[] = { "{\n\t\"" + string.Join("\",\n\t \"", headlessClients) + "\"\n}" };\r\n" : "")}"
+ $"{(headlessClientEnabled && !localClient.Any(string.IsNullOrWhiteSpace)? $"localClient[] = { "{\n\t\"" + string.Join("\",\n\t \"", localClient) + "\"\n}" };" : "")}";
+ $"{(headlessClientEnabled && !headlessClients.Exists(string.IsNullOrWhiteSpace) ? $"headlessClients[] = { "{\n\t\"" + string.Join("\",\n\t \"", headlessClients) + "\"\n}" };\r\n" : "")}"
+ $"{(headlessClientEnabled && !localClient.Exists(string.IsNullOrWhiteSpace)? $"localClient[] = { "{\n\t\"" + string.Join("\",\n\t \"", localClient) + "\"\n}" };" : "")}";
return output;
}

Expand Down
2 changes: 1 addition & 1 deletion FASTER/Models/ServerProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public ServerProfile Clone()
{
p.GenerateNewId();

if (p.Name.EndsWith(")") && p.Name.Contains('(') && int.TryParse(p.Name.Substring(p.Name.Length - 2, 1), out _))
if (p.Name.EndsWith(')') && p.Name.Contains('(') && int.TryParse(p.Name.Substring(p.Name.Length - 2, 1), out _))
{
var i = p.Name.IndexOf('(');
var j = p.Name.Length;
Expand Down
4 changes: 2 additions & 2 deletions FASTER/ViewModel/ModsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ public async Task AddLocalModAsync()
return;

var oldPaths = new List<string>();
if (!Path.GetFileName(localPath).StartsWith("@") && Directory.GetDirectories(localPath).Where((file) => Path.GetFileName(file).StartsWith("@")).ToList().Count > 0)
if (!Path.GetFileName(localPath).StartsWith('@') && Directory.GetDirectories(localPath).Where((file) => Path.GetFileName(file).StartsWith('@')).ToList().Count > 0)
{
oldPaths = Directory.GetDirectories(localPath).Where((file) => Path.GetFileName(file).StartsWith("@")).ToList();
oldPaths = Directory.GetDirectories(localPath).Where((file) => Path.GetFileName(file).StartsWith('@')).ToList();
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions FASTER/ViewModel/ProfileViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ internal void DeleteProfile()
{ Directory.Delete(Path.Combine(Profile.ArmaPath, "Servers", Profile.Id), true); }
Properties.Settings.Default.Profiles.Remove(Profile);
Properties.Settings.Default.Save();
MainWindow.Instance.ContentProfileViews.Remove(MainWindow.Instance.ContentProfileViews.FirstOrDefault(p => p.Profile.Id == Profile.Id));
MainWindow.Instance.ContentProfileViews.Remove(MainWindow.Instance.ContentProfileViews.Find(p => p.Profile.Id == Profile.Id));
var menuItem = MainWindow.Instance.IServerProfilesMenu.Items.Cast<ToggleButton>().FirstOrDefault(p => p.Name == Profile.Id);
if(menuItem != null)
MainWindow.Instance.IServerProfilesMenu.Items.Remove(menuItem);
Expand Down Expand Up @@ -302,7 +302,7 @@ internal void LoadModsFromFile()
List<string> notFound = new();
foreach (var extractedMod in extractedModList)
{
var mod = Profile.ProfileMods.FirstOrDefault(m => m.Id == extractedMod.Id || ModUtilities.GetCompareString(extractedMod.Name) == ModUtilities.GetCompareString(m.Name));
var mod = Profile.ProfileMods.Find(m => m.Id == extractedMod.Id || ModUtilities.GetCompareString(extractedMod.Name) == ModUtilities.GetCompareString(m.Name));
if (mod != null)
{
mod.ClientSideChecked = true;
Expand Down Expand Up @@ -396,7 +396,7 @@ internal async Task ClearModKeys()
{
foreach (var keyFile in Directory.GetFiles(Path.Combine(Profile.ArmaPath, "keys")))
{
if (ignoredKeys.Any(keyFile.Contains))
if (Array.Exists(ignoredKeys, x => keyFile.Contains(x)))
continue;
try
{
Expand All @@ -423,7 +423,7 @@ public void LoadData()
var modlist = new List<ProfileMod>();
foreach(var mod in Properties.Settings.Default.armaMods.ArmaMods)
{
ProfileMod existingMod = Profile.ProfileMods.FirstOrDefault(m => m.Id == mod.WorkshopId);
ProfileMod existingMod = Profile.ProfileMods.Find(m => m.Id == mod.WorkshopId);
if (existingMod == null)
{
var newProfile = new ProfileMod { Name = mod.Name, Id = mod.WorkshopId, IsLocal = mod.IsLocal};
Expand Down Expand Up @@ -465,7 +465,7 @@ internal void LoadMissions()

foreach (var mission in newMissions)
{
ProfileMission existingMission = Profile.ServerCfg.Missions.FirstOrDefault(m => m.Path == mission);
ProfileMission existingMission = Profile.ServerCfg.Missions.Find(m => m.Path == mission);
if (existingMission == null)
{
var newMission = new ProfileMission { Name = mission.Replace(".pbo", ""), Path = mission };
Expand Down
2 changes: 1 addition & 1 deletion FASTER/ViewModel/SteamUpdaterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public async Task<int> RunModsUpdater(ObservableCollection<ArmaMod> mods)

sw.Stop();
mod.Status = ArmaModStatus.UpToDate;
var nx = new DateTime(1970, 1, 1);
var nx = DateTime.UnixEpoch;
var ts = DateTime.UtcNow - nx;
mod.LocalLastUpdated = (ulong) ts.TotalSeconds;

Expand Down
2 changes: 1 addition & 1 deletion FASTER_Version.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.9.5.2</version>
<version>1.9.5.3</version>
<url>https://github.com/Foxlider/FASTER/releases/latest/download/Release_x64.zip</url>
<changelog>https://github.com/Foxlider/FASTER/releases</changelog>
<mandatory>true</mandatory>
Expand Down

0 comments on commit b888dd7

Please sign in to comment.