Skip to content

Commit

Permalink
Use Count instead of Any
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Oct 11, 2024
1 parent 8c02754 commit 0809104
Show file tree
Hide file tree
Showing 22 changed files with 35 additions and 35 deletions.
6 changes: 3 additions & 3 deletions Cmdline/Action/Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
}

// Present the results.
if (!matching_compatible.Any()
&& (!options.all || !matching_incompatible.Any()))
if (matching_compatible.Count == 0
&& (!options.all || matching_incompatible.Count == 0))
{
return Exit.OK;
}
Expand All @@ -89,7 +89,7 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
mod.@abstract);
}

if (matching_incompatible.Any())
if (matching_incompatible.Count != 0)
{
user.RaiseMessage(Properties.Resources.SearchIncompatibleModsHeader);
foreach (CkanModule mod in matching_incompatible)
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Show.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
var matches = search.PerformSearch(instance, modName);

// Display the results of the search.
if (!matches.Any())
if (matches.Count == 0)
{
// No matches found.
user.RaiseMessage(Properties.Resources.ShowNoClose);
Expand Down
4 changes: 2 additions & 2 deletions Core/GameInstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public GameInstanceManager(IUser user, IConfiguration? configuration = null)
// If we know of no instances, try to find one.
// Otherwise, we know of too many instances!
// We don't know which one to pick, so we return null.
return !instances.Any() ? FindAndRegisterDefaultInstances() : null;
return instances.Count == 0 ? FindAndRegisterDefaultInstances() : null;
}

/// <summary>
Expand All @@ -145,7 +145,7 @@ public GameInstanceManager(IUser user, IConfiguration? configuration = null)
/// </summary>
public GameInstance? FindAndRegisterDefaultInstances()
{
if (instances.Any())
if (instances.Count != 0)
{
throw new KSPManagerKraken("Attempted to scan for defaults with instances");
}
Expand Down
2 changes: 1 addition & 1 deletion Core/ModuleInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ public void UninstallList(IEnumerable<string> mods,
.ToList();

// If there is nothing to uninstall, skip out.
if (!goners.Any())
if (goners.Count == 0)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ public static IEnumerable<string> FindReverseDependencies(

// The empty list has no reverse dependencies
// (Don't remove broken modules if we're only installing)
if (modulesToRemove.Any())
if (modulesToRemove.Count != 0)
{
// All modules in the input are included in the output
foreach (string starter in modulesToRemove)
Expand Down
6 changes: 3 additions & 3 deletions Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private void ResolveStanza(List<RelationshipDescriptor>? stanza,
&& reason is SelectionReason.RelationshipReason rel
&& MightBeInstallable(mod, rel.Parent, installed_modules))
.ToList();
if (!candidates.Any())
if (candidates.Count == 0)
{
// Nothing found, try again while simulating an empty mod list
// Necessary for e.g. proceed_with_inconsistencies, conflicts will still be caught below
Expand All @@ -319,7 +319,7 @@ private void ResolveStanza(List<RelationshipDescriptor>? stanza,
.ToList();
}

if (!candidates.Any())
if (candidates.Count == 0)
{
if (!soft_resolve && reason is SelectionReason.RelationshipReason rel)
{
Expand Down Expand Up @@ -645,7 +645,7 @@ public IEnumerable<string> ConflictDescriptions
conflictingModDescription(kvp.Key, null),
conflictingModDescription(kvp.Value, null)));

public bool IsConsistent => !conflicts.Any();
public bool IsConsistent => conflicts.Count == 0;

public List<SelectionReason> ReasonsFor(CkanModule mod)
=> reasons.TryGetValue(mod, out List<SelectionReason>? r)
Expand Down
2 changes: 1 addition & 1 deletion Core/Relationships/SanityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static bool CheckConsistency(IEnumerable<CkanModule> modules
var dllSet = dlls?.ToHashSet();
UnmetDepends = FindUnsatisfiedDepends(modList, dllSet, dlc).ToList();
Conflicts = FindConflicting(modList, dllSet, dlc);
return !UnmetDepends.Any() && !Conflicts.Any();
return UnmetDepends.Count == 0 && Conflicts.Count == 0;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion GUI/Controls/Changeset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void LoadChangeset(List<ModChange> changes,
Dictionary<CkanModule, string>? conflicts)
{
changeset = changes;
ConfirmChangesButton.Enabled = conflicts == null || !conflicts.Any();
ConfirmChangesButton.Enabled = conflicts == null || conflicts.Count == 0;
CloseTheGameLabel.Visible = changes?.Any(ch => DeletingChanges.Contains(ch.ChangeType))
?? false;
ChangesGrid.DataSource = new BindingList<ChangesetRow>(
Expand Down
2 changes: 1 addition & 1 deletion GUI/Controls/ChooseRecommendedMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void MarkConflicts()
? Color.LightCoral
: Color.Empty;
}
RecommendedModsContinueButton.Enabled = !conflicts.Any();
RecommendedModsContinueButton.Enabled = conflicts.Count == 0;
OnConflictFound?.Invoke(string.Join("; ", resolver.ConflictDescriptions));
}
catch (DependencyNotSatisfiedKraken k)
Expand Down
4 changes: 2 additions & 2 deletions GUI/Controls/ManageMods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void ChangeSetUpdated()
{
Util.Invoke(this, () =>
{
if (ChangeSet != null && ChangeSet.Any())
if (ChangeSet != null && ChangeSet.Count != 0)
{
ApplyToolButton.Enabled = true;
}
Expand Down Expand Up @@ -1923,7 +1923,7 @@ protected override bool ProcessCmdKey(ref Message msg, Keys keyData)

public bool AllowClose()
{
if (Conflicts != null && Conflicts.Any())
if (Conflicts != null && Conflicts.Count != 0)
{
// Ask if they want to resolve conflicts
string confDescrip = Conflicts
Expand Down
2 changes: 1 addition & 1 deletion GUI/Dialogs/ManageGameInstancesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public ManageGameInstancesDialog(GameInstanceManager mgr,
StartPosition = FormStartPosition.CenterScreen;
}

if (!manager.Instances.Any())
if (manager.Instances.Count == 0)
{
manager.FindAndRegisterDefaultInstances();
}
Expand Down
8 changes: 4 additions & 4 deletions GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ private void InstallFromCkanFiles(string[] files)
.Select(gv => new GameVersion(gv.Major, gv.Minor))
.Distinct()
.ToList();
if (missing.Any()
if (missing.Count != 0
&& YesNoDialog(string.Format(Properties.Resources.MetapackageAddCompatibilityPrompt,
filesRange.ToSummaryString(CurrentInstance.game),
crit.ToSummaryString(CurrentInstance.game)),
Expand All @@ -841,7 +841,7 @@ private void InstallFromCkanFiles(string[] files)
.ToHashSet();
// Get incompatible mods we're installing
var myIncompat = toInstall.Where(mod => allIncompat.Contains(mod.identifier)).ToList();
if (!myIncompat.Any()
if (myIncompat.Count == 0
// Confirm installation of incompatible like the Versions tab does
|| YesNoDialog(string.Format(Properties.Resources.ModpackInstallIncompatiblePrompt,
string.Join(Environment.NewLine, myIncompat),
Expand Down Expand Up @@ -943,7 +943,7 @@ private void ShowSelectionModInfo(ListView.SelectedListViewItemCollection select

private void ManageMods_OnChangeSetChanged(List<ModChange> changeset, Dictionary<GUIMod, string> conflicts)
{
if (changeset != null && changeset.Any())
if (changeset != null && changeset.Count != 0)
{
tabController.ShowTab("ChangesetTabPage", 1, false);
UpdateChangesDialog(
Expand Down Expand Up @@ -1069,7 +1069,7 @@ private void LaunchGame(string? command = null)
var incomp = registry.IncompatibleInstalled(CurrentInstance.VersionCriteria())
.Where(m => !m.Module.IsDLC && !suppressedIdentifiers.Contains(m.identifier))
.ToList();
if (incomp.Any() && CurrentInstance.Version() is GameVersion gv)
if (incomp.Count != 0 && CurrentInstance.Version() is GameVersion gv)
{
// Warn that it might not be safe to run game with incompatible modules installed
string incompatDescrip = incomp
Expand Down
2 changes: 1 addition & 1 deletion GUI/Main/MainRecommendations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void AuditRecommendations(Registry registry, GameVersionCriteria version
recommendations, suggestions, supporters);
var result = ChooseRecommendedMods.Wait();
tabController.HideTab("ChooseRecommendedModsTabPage");
if (result != null && result.Any())
if (result != null && result.Count != 0)
{
Wait.StartWaiting(InstallMods, PostInstallMods, true,
new InstallArgument(
Expand Down
4 changes: 2 additions & 2 deletions Netkan/Processors/QueueHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void handleMessages(string url, int howMany, int timeoutMinutes)
VisibilityTimeout = (int)TimeSpan.FromMinutes(timeoutMinutes).TotalSeconds,
MessageAttributeNames = new List<string>() { "All" },
}).Result;
if (!resp.Messages.Any())
if (resp.Messages.Count == 0)
{
log.Debug("No metadata in queue");
}
Expand Down Expand Up @@ -261,7 +261,7 @@ private SendMessageBatchRequestEntry inflationMessage(Metadata? ckan,
}
);
}
if (warningAppender.Warnings.Any())
if (warningAppender.Warnings.Count != 0)
{
attribs.Add(
"WarningMessages",
Expand Down
2 changes: 1 addition & 1 deletion Netkan/Sources/Github/GithubApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public IEnumerable<GithubRelease> GetAllReleases(GithubRef reference)
ghRel.PreRelease == reference.UsePrerelease
// Skip releases without assets
&& ghRel.Assets != null
&& ghRel.Assets.Any())
&& ghRel.Assets.Count != 0)
// Insurance against GitHub returning them in the wrong order
.OrderByDescending(ghRel => ghRel.PublishedAt)
.ToList();
Expand Down
2 changes: 1 addition & 1 deletion Netkan/Transformers/NetkanTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static List<ITransformer> InjectVersionedOverrideTransformers(List<ITran
result.Add(transformers[i]);
}

if (result.Any())
if (result.Count != 0)
{
if (result.First() is VersionedOverrideTransformer firstVersionedOverride)
{
Expand Down
2 changes: 1 addition & 1 deletion Netkan/Validators/CraftsInShipsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Validate(Metadata metadata)
.Where(f => !AllowedCraftPath(inst.ToRelativeGameDir(f.destination)))
.ToList();

if (badCrafts.Any())
if (badCrafts.Count != 0)
{
Log.WarnFormat(
"Craft files installed outside Ships folder: {0}",
Expand Down
2 changes: 1 addition & 1 deletion Netkan/Validators/HarmonyValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Validate(Metadata metadata)
StringComparison.InvariantCultureIgnoreCase) != -1)
.OrderBy(f => f)
.ToList();
bool bundlesHarmony = harmonyDLLs.Any();
bool bundlesHarmony = harmonyDLLs.Count != 0;
bool providesHarmony1 = mod.ProvidesList.Contains("Harmony1");
if (bundlesHarmony && !providesHarmony1)
{
Expand Down
6 changes: 3 additions & 3 deletions Netkan/Validators/InstallsFilesValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void Validate(Metadata metadata)
&& p.LastIndexOf($"/{dir}/", StringComparison.InvariantCultureIgnoreCase) > 0)
.OrderBy(f => f)
.ToList();
if (gamedatas.Any())
if (gamedatas.Count != 0)
{
var badPaths = string.Join("\r\n", gamedatas);
throw new Kraken($"{dir} directory found within {dir}:\r\n{badPaths}");
Expand All @@ -60,7 +60,7 @@ public void Validate(Metadata metadata)
.GroupBy(f => f)
.SelectMany(grp => grp.Skip(1).OrderBy(f => f))
.ToList();
if (duplicates.Any())
if (duplicates.Count != 0)
{
var badPaths = string.Join("\r\n", duplicates);
throw new Kraken($"Multiple files attempted to install to:\r\n{badPaths}");
Expand All @@ -75,7 +75,7 @@ public void Validate(Metadata metadata)
.Distinct()
.Where(incl => !allFiles.Any(f => f.Contains(incl)))
.ToList();
if (unmatchedIncludeOnlys.Any())
if (unmatchedIncludeOnlys.Count != 0)
{
log.WarnFormat("No matches for includes_only: {0}",
string.Join(", ", unmatchedIncludeOnlys));
Expand Down
4 changes: 2 additions & 2 deletions Netkan/Validators/PluginsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void Validate(Metadata metadata)
GameInstance inst = new GameInstance(_game, "/", "dummy", new NullUser());

var plugins = _moduleService.GetPlugins(mod, zip, inst).ToList();
bool hasPlugin = plugins.Any();
bool hasPlugin = plugins.Count != 0;
if (hasPlugin)
{
var dllPaths = plugins
Expand All @@ -45,7 +45,7 @@ public void Validate(Metadata metadata)
.Where(ident => !string.IsNullOrEmpty(ident)
&& !identifiersToIgnore.Contains(ident))
.ToHashSet();
if (dllIdentifiers.Any() && !dllIdentifiers.Contains(metadata.Identifier))
if (dllIdentifiers.Count != 0 && !dllIdentifiers.Contains(metadata.Identifier))
{
Log.WarnFormat(
"No plugin matching the identifier, manual installations won't be detected: {0}",
Expand Down
2 changes: 1 addition & 1 deletion Netkan/Validators/SpaceWarpInfoValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void Validate(Metadata metadata)
StringComparer.InvariantCultureIgnoreCase))
?? Enumerable.Empty<string>())
.ToList();
if (missingDeps.Any())
if (missingDeps.Count != 0)
{
log.WarnFormat("Dependencies from swinfo.json missing from module: {0}",
string.Join(", ", missingDeps));
Expand Down
2 changes: 1 addition & 1 deletion Tests/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static void AssertNoAsyncVoidMethods(Assembly assembly)
method.DeclaringType?.Name ?? "",
method.Name))
.ToList();
Assert.False(messages.Any(),
Assert.False(messages.Count != 0,
"Async void methods found!" + Environment.NewLine + string.Join(Environment.NewLine, messages));
}

Expand Down

0 comments on commit 0809104

Please sign in to comment.