Skip to content

Commit

Permalink
More vscode suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Nov 17, 2023
1 parent 6802262 commit 4f701a6
Show file tree
Hide file tree
Showing 247 changed files with 1,646 additions and 1,380 deletions.
51 changes: 51 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[*.cs]
dotnet_analyzer_diagnostic.category-Style.severity = warning
dotnet_analyzer_diagnostic.category-CodeQuality.severity = warning

# Using `var` is good
dotnet_diagnostic.IDE0008.severity = none

# Don't need to enumerate every case for `switch` with `default`
dotnet_diagnostic.IDE0010.severity = none

# Don't "simplify" if statements that throw
dotnet_diagnostic.IDE0016.severity = none

# Expression bodies are good for methods
dotnet_diagnostic.IDE0022.severity = none

# Expression bodies are fine for operators
dotnet_diagnostic.IDE0024.severity = none

# Collection initialization simplification affects JObject, which is dumb
dotnet_diagnostic.IDE0028.severity = none

# "auto" properties seem pretty useless
dotnet_diagnostic.IDE0032.severity = none

# "local functions" are just weird, no thank you
dotnet_diagnostic.IDE0039.severity = none

# "if" statements should only be "simplified" if they're pure functional,
# and these checks don't know that
dotnet_diagnostic.IDE0045.severity = none
dotnet_diagnostic.IDE0046.severity = none
dotnet_diagnostic.IDE0270.severity = none

# We use "unnecessary" parentheses for clarity
dotnet_diagnostic.IDE0047.severity = none

# Let me keep my extra spaces for aligning things
dotnet_diagnostic.IDE0055.severity = none

# OK to call functions that return values and not use them
dotnet_diagnostic.IDE0058.severity = none

# A `using` inside a namespace is useful as a typedef
dotnet_diagnostic.IDE0065.severity = none

# Allow namespaces to be independent of folder names
dotnet_diagnostic.IDE0130.severity = none

# Who cares if it's a JSON formatted string, in a test?
dotnet_diagnostic.JSON002.severity = none
4 changes: 2 additions & 2 deletions AutoUpdate/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static void StartCKAN(string path)
// Start CKAN
if (IsOnMono())
{
Process.Start("mono", String.Format("\"{0}\"", path));
Process.Start("mono", string.Format("\"{0}\"", path));
}
else
{
Expand Down Expand Up @@ -171,7 +171,7 @@ private static bool IsOnWindows()
/// </summary>
/// <param name="sender">Source of unhandled exception</param>
/// <param name="e">Info about the exception</param>
private static void UnhandledExceptionEventHandler(Object sender, UnhandledExceptionEventArgs e)
private static void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e)
{
ReportError(Properties.Resources.UnhandledException, e.ExceptionObject);
}
Expand Down
7 changes: 3 additions & 4 deletions AutoUpdate/SingleAssemblyResourceManager.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System.IO;
using System.Globalization;
using System.Resources;
using System.Collections;
using System.Reflection;
using System.Collections.Generic;

namespace CKAN.AutoUpdateHelper
{
// Thanks and credit to this guy: https://stackoverflow.com/q/1952638/2422988

class SingleAssemblyResourceManager : ResourceManager
public class SingleAssemblyResourceManager : ResourceManager
{
public SingleAssemblyResourceManager(string basename, Assembly assembly) : base(basename, assembly)
{
Expand All @@ -23,7 +22,7 @@ protected override ResourceSet InternalGetResourceSet(CultureInfo culture,
// Lazy-load default language (without caring about duplicate assignment in race conditions, no harm done)
if (neutralResourcesCulture == null)
{
neutralResourcesCulture = GetNeutralResourcesLanguage(this.MainAssembly);
neutralResourcesCulture = GetNeutralResourcesLanguage(MainAssembly);
}

// If we're asking for the default language, then ask for the
Expand All @@ -34,7 +33,7 @@ protected override ResourceSet InternalGetResourceSet(CultureInfo culture,
}
string resourceFileName = GetResourceFileName(culture);

Stream store = this.MainAssembly.GetManifestResourceStream(resourceFileName);
Stream store = MainAssembly.GetManifestResourceStream(resourceFileName);

// If we found the appropriate resources in the local assembly
if (store != null)
Expand Down
1 change: 0 additions & 1 deletion Cmdline/Action/Available.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using System.Collections.Generic;

namespace CKAN.CmdLine
{
Expand Down
13 changes: 5 additions & 8 deletions Cmdline/Action/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ public int RunSubCommand(GameInstanceManager mgr, CommonOptions opts, SubCommand
manager = mgr ?? new GameInstanceManager(user);
exitCode = options.Handle(manager, user);
if (exitCode != Exit.OK)
{
return;
}

switch (option)
{
Expand Down Expand Up @@ -214,14 +216,9 @@ private int ShowCacheSizeLimit()
private int SetCacheSizeLimit(SetLimitOptions options)
{
IConfiguration cfg = ServiceLocator.Container.Resolve<IConfiguration>();
if (options.Megabytes < 0)
{
cfg.CacheSizeLimit = null;
}
else
{
cfg.CacheSizeLimit = options.Megabytes * (long)1024 * (long)1024;
}
cfg.CacheSizeLimit = options.Megabytes < 0
? null :
(long?)(options.Megabytes * 1024 * 1024);
return ShowCacheSizeLimit();
}

Expand Down
2 changes: 2 additions & 0 deletions Cmdline/Action/Compat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCom
_kspManager = manager ?? new GameInstanceManager(_user);
exitCode = comOpts.Handle(_kspManager, _user);
if (exitCode != Exit.OK)
{
return;
}

switch (option)
{
Expand Down
2 changes: 2 additions & 0 deletions Cmdline/Action/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public int RunSubCommand(GameInstanceManager mgr, CommonOptions opts, SubCommand
manager = mgr ?? new GameInstanceManager(user);
exitCode = options.Handle(manager, user);
if (exitCode != Exit.OK)
{
return;
}

switch (option)
{
Expand Down
6 changes: 4 additions & 2 deletions Cmdline/Action/GameInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCom
Manager = manager ?? new GameInstanceManager(User);
exitCode = options.Handle(Manager, User);
if (exitCode != Exit.OK)
{
return;
}

switch (option)
{
Expand Down Expand Up @@ -461,7 +463,7 @@ private int SetDefaultInstall(DefaultOptions options)
string defaultInstance = Manager.Configuration.AutoStartInstance;
int defaultInstancePresent = 0;

if (!String.IsNullOrWhiteSpace(defaultInstance))
if (!string.IsNullOrWhiteSpace(defaultInstance))
{
defaultInstancePresent = 1;
}
Expand All @@ -477,7 +479,7 @@ private int SetDefaultInstall(DefaultOptions options)
}

// Mark the default instance for the user.
if (!String.IsNullOrWhiteSpace(defaultInstance))
if (!string.IsNullOrWhiteSpace(defaultInstance))
{
keys[0] = Manager.Instances.IndexOfKey(defaultInstance);
}
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Install.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
ckan_uri = new Uri(ckan_file);
}

string filename = String.Empty;
string filename = string.Empty;

// If it is a local file, we already know the filename. If it is remote, create a temporary file and download the remote resource.
if (ckan_uri.IsFile)
Expand Down
2 changes: 2 additions & 0 deletions Cmdline/Action/Mark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public int RunSubCommand(GameInstanceManager mgr, CommonOptions opts, SubCommand
manager = mgr ?? new GameInstanceManager(user);
exitCode = options.Handle(manager, user);
if (exitCode != Exit.OK)
{
return;
}

switch (option)
{
Expand Down
2 changes: 2 additions & 0 deletions Cmdline/Action/Remove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
foreach (string mod in regMgr.registry.InstalledModules.Select(mod => mod.identifier))
{
if (justins.Any(re => re.IsMatch(mod)))
{
selectedModules.Add(mod);
}
}

// Replace the regular expressions with the selected modules
Expand Down
2 changes: 2 additions & 0 deletions Cmdline/Action/Repair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCom
}
exitCode = options.Handle(manager, User);
if (exitCode != Exit.OK)
{
return;
}

switch (option)
{
Expand Down
3 changes: 1 addition & 2 deletions Cmdline/Action/Replace.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

using log4net;
using CKAN.Versioning;
Expand All @@ -9,7 +8,7 @@ namespace CKAN.CmdLine
{
public class Replace : ICommand
{
public Replace(CKAN.GameInstanceManager mgr, RepositoryDataManager repoData, IUser user)
public Replace(GameInstanceManager mgr, RepositoryDataManager repoData, IUser user)
{
manager = mgr;
this.repoData = repoData;
Expand Down
6 changes: 3 additions & 3 deletions Cmdline/Action/Repo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;

using Newtonsoft.Json;
using CommandLine;
Expand Down Expand Up @@ -139,7 +137,9 @@ public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCom
Manager = manager ?? new GameInstanceManager(User);
exitCode = options.Handle(Manager, User);
if (exitCode != Exit.OK)
{
return;
}

switch (option)
{
Expand Down Expand Up @@ -282,7 +282,7 @@ private int AddRepository(RepoAddOptions options)

foreach (Repository candidate in repositoryList.repositories)
{
if (String.Equals(candidate.name, options.name, StringComparison.OrdinalIgnoreCase))
if (string.Equals(candidate.name, options.name, StringComparison.OrdinalIgnoreCase))
{
options.name = candidate.name;
options.uri = candidate.uri.ToString();
Expand Down
36 changes: 15 additions & 21 deletions Cmdline/Action/Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using CKAN.Games;

namespace CKAN.CmdLine
{
Expand All @@ -19,7 +18,7 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
SearchOptions options = (SearchOptions)raw_options;

// Check the input.
if (String.IsNullOrWhiteSpace(options.search_term) && String.IsNullOrWhiteSpace(options.author_term))
if (string.IsNullOrWhiteSpace(options.search_term) && string.IsNullOrWhiteSpace(options.author_term))
{
user.RaiseError(Properties.Resources.SearchNoTerm);
return Exit.BADOPT;
Expand All @@ -33,29 +32,29 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
}

// Show how many matches we have.
if (options.all && !String.IsNullOrWhiteSpace(options.author_term))
if (options.all && !string.IsNullOrWhiteSpace(options.author_term))
{
user.RaiseMessage(Properties.Resources.SearchFoundByAuthorWithIncompat,
matching_compatible.Count().ToString(),
matching_incompatible.Count().ToString(),
options.search_term,
options.author_term);
}
else if (options.all && String.IsNullOrWhiteSpace(options.author_term))
else if (options.all && string.IsNullOrWhiteSpace(options.author_term))
{
user.RaiseMessage(Properties.Resources.SearchFoundWithIncompat,
matching_compatible.Count().ToString(),
matching_incompatible.Count().ToString(),
options.search_term);
}
else if (!options.all && !String.IsNullOrWhiteSpace(options.author_term))
else if (!options.all && !string.IsNullOrWhiteSpace(options.author_term))
{
user.RaiseMessage(Properties.Resources.SearchFoundByAuthor,
matching_compatible.Count().ToString(),
options.search_term,
options.author_term);
}
else if (!options.all && String.IsNullOrWhiteSpace(options.author_term))
else if (!options.all && string.IsNullOrWhiteSpace(options.author_term))
{
user.RaiseMessage(Properties.Resources.SearchFound,
matching_compatible.Count().ToString(),
Expand All @@ -77,7 +76,7 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
mod.identifier,
mod.version,
mod.name,
mod.author == null ? "N/A" : String.Join(", ", mod.author),
mod.author == null ? "N/A" : string.Join(", ", mod.author),
mod.@abstract);
}

Expand All @@ -94,7 +93,7 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
mod.version,
GameVersion,
mod.name,
mod.author == null ? "N/A" : String.Join(", ", mod.author),
mod.author == null ? "N/A" : string.Join(", ", mod.author),
mod.@abstract);
}
}
Expand Down Expand Up @@ -125,35 +124,30 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
public List<CkanModule> PerformSearch(CKAN.GameInstance ksp, string term, string author = null, bool searchIncompatible = false)
{
// Remove spaces and special characters from the search term.
term = String.IsNullOrWhiteSpace(term) ? string.Empty : CkanModule.nonAlphaNums.Replace(term, "");
author = String.IsNullOrWhiteSpace(author) ? string.Empty : CkanModule.nonAlphaNums.Replace(author, "");
term = string.IsNullOrWhiteSpace(term) ? string.Empty : CkanModule.nonAlphaNums.Replace(term, "");
author = string.IsNullOrWhiteSpace(author) ? string.Empty : CkanModule.nonAlphaNums.Replace(author, "");

var registry = RegistryManager.Instance(ksp, repoData).registry;

if (!searchIncompatible)
{
return registry
.CompatibleModules(ksp.VersionCriteria())
return searchIncompatible
? registry
.IncompatibleModules(ksp.VersionCriteria())
// Look for a match in each string.
.Where(module => (module.SearchableName.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1
|| module.SearchableIdentifier.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1
|| module.SearchableAbstract.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1
|| module.SearchableDescription.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1)
&& module.SearchableAuthors.Any((auth) => auth.IndexOf(author, StringComparison.OrdinalIgnoreCase) > -1))
.ToList();
}
else
{
return registry
.IncompatibleModules(ksp.VersionCriteria())
.ToList()
: registry
.CompatibleModules(ksp.VersionCriteria())
// Look for a match in each string.
.Where(module => (module.SearchableName.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1
|| module.SearchableIdentifier.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1
|| module.SearchableAbstract.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1
|| module.SearchableDescription.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1)
&& module.SearchableAuthors.Any((auth) => auth.IndexOf(author, StringComparison.OrdinalIgnoreCase) > -1))
.ToList();
}
}

/// <summary>
Expand Down
Loading

0 comments on commit 4f701a6

Please sign in to comment.