diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000000..f7a664c935
--- /dev/null
+++ b/.editorconfig
@@ -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
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 5a5d29c54b..ec8310ef1c 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -5,7 +5,10 @@ on:
branches:
- master
pull_request:
- types: [opened, synchronize, reopened]
+ types:
+ - opened
+ - synchronize
+ - reopened
jobs:
build:
@@ -14,8 +17,14 @@ jobs:
strategy:
fail-fast: false
matrix:
- mono: ['6.8', '6.10', '6.12', 'latest']
- configuration: [Debug, Release]
+ mono:
+ - latest
+ - '6.12'
+ - '6.10'
+ - '6.8'
+ configuration:
+ - Debug
+ - Release
container:
image: mono:${{ matrix.mono }}
@@ -27,6 +36,10 @@ jobs:
run: |
apt-get update || true
apt-get install -y apt-transport-https
+ - name: Setup .NET Core
+ uses: actions/setup-dotnet@v3
+ with:
+ dotnet-version: '7'
- name: Installing build dependencies
run: apt-get update && apt-get install -y git
- name: Install runtime dependencies
@@ -66,7 +79,7 @@ jobs:
curl -O https://raw.githubusercontent.com/KSP-CKAN/NetKAN/master/NetKAN/ZeroMiniAVC.netkan && \
mono netkan.exe ZeroMiniAVC.netkan
"
- if: matrix.configuration == 'release' && ( matrix.mono == '6.8' || matrix.mono == 'latest' )
+ if: matrix.configuration == 'release'
- name: Upload ckan.exe artifact
uses: actions/upload-artifact@v3
@@ -95,14 +108,16 @@ jobs:
strategy:
fail-fast: false
matrix:
- configuration: [Debug_NetCore, Release_NetCore]
+ configuration:
+ - Debug_NetCore
+ - Release_NetCore
steps:
- uses: actions/checkout@v3
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
- dotnet-version: '5.0.x'
+ dotnet-version: '7'
- name: Restore cache for _build/tools
uses: actions/cache@v3
with:
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 85603e7f00..9b6e93b8c4 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -31,6 +31,10 @@ jobs:
echo 'odd_build=true' >> $GITHUB_OUTPUT
fi
+ - name: Setup .NET Core
+ uses: actions/setup-dotnet@v3
+ with:
+ dotnet-version: '7'
- name: Installing build dependencies
run: apt-get update && apt-get install -y git make sed gzip fakeroot lintian dpkg-dev gpg createrepo
- name: Installing runtime dependencies
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index a917fcbc18..719ae366bf 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -15,6 +15,10 @@ jobs:
steps:
- uses: actions/checkout@v3
+ - name: Setup .NET Core
+ uses: actions/setup-dotnet@v3
+ with:
+ dotnet-version: '7'
- name: Installing build dependencies
run: apt-get update && apt-get install -y git make sed libplist-utils xorriso gzip fakeroot lintian rpm wget jq dpkg-dev gpg createrepo
- name: Installing runtime dependencies
diff --git a/.gitignore b/.gitignore
index 8fa9db1fb8..d66419ff80 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,5 @@
/_build/
/.vs/
-/.vscode/
/tools
test-results
*.userprefs
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000000..f7c9752af9
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,17 @@
+{
+ "dotnet.preferCSharpExtension": false,
+ "dotnet.server.useOmnisharp": true,
+ "dotnet.defaultSolution": "CKAN.sln",
+ "dotnet.automaticallyCreateSolutionInWorkspace": false,
+ "dotnet.backgroundAnalysis.analyzerDiagnosticsScope": "fullSolution",
+ "dotnet.backgroundAnalysis.compilerDiagnosticsScope": "fullSolution",
+ "omnisharp.useModernNet": false,
+ "omnisharp.projectLoadTimeout": 600,
+ "python.defaultInterpreterPath": "py",
+ "files.watcherExclude": {
+ "**/_build/**": true
+ },
+ "nunitTestRunner.projectsPatterns": [
+ "_build/out/**/*.Tests.dll"
+ ]
+}
diff --git a/AutoUpdate/CKAN-autoupdate.csproj b/AutoUpdate/CKAN-autoupdate.csproj
index 7b8c631bae..9d65829fc2 100644
--- a/AutoUpdate/CKAN-autoupdate.csproj
+++ b/AutoUpdate/CKAN-autoupdate.csproj
@@ -1,7 +1,8 @@
CKAN-AutoUpdateHelper
- ..\_build\out\$(AssemblyName)\$(Configuration)\bin\
+ ..\_build\out\$(AssemblyName)\$(Configuration)\bin\
+ ..\_build\out\$(AssemblyName)\VSCodeIDE\bin\
..\_build\out\$(AssemblyName)\$(Configuration)\obj\
@@ -16,8 +17,8 @@
false
7
..\assets\ckan.ico
- net45
- v4.5
+ net48
+ v4.8
512
prompt
4
@@ -28,10 +29,6 @@
-
-
-
-
Properties\GlobalAssemblyVersionInfo.cs
@@ -48,25 +45,4 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/AutoUpdate/Main.cs b/AutoUpdate/Main.cs
index 56e5b4667e..2d32697b02 100644
--- a/AutoUpdate/Main.cs
+++ b/AutoUpdate/Main.cs
@@ -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
{
@@ -171,7 +171,7 @@ private static bool IsOnWindows()
///
/// Source of unhandled exception
/// Info about the exception
- private static void UnhandledExceptionEventHandler(Object sender, UnhandledExceptionEventArgs e)
+ private static void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e)
{
ReportError(Properties.Resources.UnhandledException, e.ExceptionObject);
}
diff --git a/AutoUpdate/SingleAssemblyResourceManager.cs b/AutoUpdate/SingleAssemblyResourceManager.cs
index 48f266d341..3ee0990a59 100644
--- a/AutoUpdate/SingleAssemblyResourceManager.cs
+++ b/AutoUpdate/SingleAssemblyResourceManager.cs
@@ -1,7 +1,6 @@
using System.IO;
using System.Globalization;
using System.Resources;
-using System.Collections;
using System.Reflection;
using System.Collections.Generic;
@@ -9,7 +8,7 @@ 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)
{
@@ -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
@@ -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)
diff --git a/Cmdline/Action/Available.cs b/Cmdline/Action/Available.cs
index 969fccb449..5fdab4d305 100644
--- a/Cmdline/Action/Available.cs
+++ b/Cmdline/Action/Available.cs
@@ -1,5 +1,4 @@
using System.Linq;
-using System.Collections.Generic;
namespace CKAN.CmdLine
{
diff --git a/Cmdline/Action/Cache.cs b/Cmdline/Action/Cache.cs
index a928222985..50332e5bf1 100644
--- a/Cmdline/Action/Cache.cs
+++ b/Cmdline/Action/Cache.cs
@@ -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)
{
@@ -214,14 +216,9 @@ private int ShowCacheSizeLimit()
private int SetCacheSizeLimit(SetLimitOptions options)
{
IConfiguration cfg = ServiceLocator.Container.Resolve();
- 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();
}
diff --git a/Cmdline/Action/Compat.cs b/Cmdline/Action/Compat.cs
index 7be08bc06e..734c3310f9 100644
--- a/Cmdline/Action/Compat.cs
+++ b/Cmdline/Action/Compat.cs
@@ -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)
{
diff --git a/Cmdline/Action/Filter.cs b/Cmdline/Action/Filter.cs
index 9cab436414..3c8ed92688 100644
--- a/Cmdline/Action/Filter.cs
+++ b/Cmdline/Action/Filter.cs
@@ -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)
{
diff --git a/Cmdline/Action/GameInstance.cs b/Cmdline/Action/GameInstance.cs
index 328abfb408..849d954703 100644
--- a/Cmdline/Action/GameInstance.cs
+++ b/Cmdline/Action/GameInstance.cs
@@ -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)
{
@@ -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;
}
@@ -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);
}
diff --git a/Cmdline/Action/Install.cs b/Cmdline/Action/Install.cs
index 6338bb9440..81b76ef5ef 100644
--- a/Cmdline/Action/Install.cs
+++ b/Cmdline/Action/Install.cs
@@ -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)
diff --git a/Cmdline/Action/Mark.cs b/Cmdline/Action/Mark.cs
index aff716bce4..ead13ffc37 100644
--- a/Cmdline/Action/Mark.cs
+++ b/Cmdline/Action/Mark.cs
@@ -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)
{
diff --git a/Cmdline/Action/Remove.cs b/Cmdline/Action/Remove.cs
index f28a430fe1..e0634f3136 100644
--- a/Cmdline/Action/Remove.cs
+++ b/Cmdline/Action/Remove.cs
@@ -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
diff --git a/Cmdline/Action/Repair.cs b/Cmdline/Action/Repair.cs
index 5eaaf32267..198f4dec6e 100644
--- a/Cmdline/Action/Repair.cs
+++ b/Cmdline/Action/Repair.cs
@@ -60,7 +60,9 @@ public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCom
}
exitCode = options.Handle(manager, User);
if (exitCode != Exit.OK)
+ {
return;
+ }
switch (option)
{
diff --git a/Cmdline/Action/Replace.cs b/Cmdline/Action/Replace.cs
index 5f89e7ffee..7032baa756 100644
--- a/Cmdline/Action/Replace.cs
+++ b/Cmdline/Action/Replace.cs
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
-using System.Text.RegularExpressions;
using log4net;
using CKAN.Versioning;
@@ -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;
diff --git a/Cmdline/Action/Repo.cs b/Cmdline/Action/Repo.cs
index 074a93d0f7..48dc18d075 100644
--- a/Cmdline/Action/Repo.cs
+++ b/Cmdline/Action/Repo.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Net;
using Newtonsoft.Json;
using CommandLine;
@@ -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)
{
@@ -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();
diff --git a/Cmdline/Action/Search.cs b/Cmdline/Action/Search.cs
index c71b96821e..59edd9912c 100644
--- a/Cmdline/Action/Search.cs
+++ b/Cmdline/Action/Search.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
-using CKAN.Games;
namespace CKAN.CmdLine
{
@@ -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;
@@ -33,7 +32,7 @@ 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(),
@@ -41,21 +40,21 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
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(),
@@ -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);
}
@@ -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);
}
}
@@ -125,27 +124,23 @@ public int RunCommand(CKAN.GameInstance ksp, object raw_options)
public List 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
@@ -153,7 +148,6 @@ public List PerformSearch(CKAN.GameInstance ksp, string term, string
|| module.SearchableDescription.IndexOf(term, StringComparison.OrdinalIgnoreCase) > -1)
&& module.SearchableAuthors.Any((auth) => auth.IndexOf(author, StringComparison.OrdinalIgnoreCase) > -1))
.ToList();
- }
}
///
diff --git a/Cmdline/CKAN-cmdline.csproj b/Cmdline/CKAN-cmdline.csproj
index b5f8011a3f..10f9de0ec8 100644
--- a/Cmdline/CKAN-cmdline.csproj
+++ b/Cmdline/CKAN-cmdline.csproj
@@ -1,7 +1,8 @@
CKAN-CmdLine
- ..\_build\out\$(AssemblyName)\$(Configuration)\bin\
+ ..\_build\out\$(AssemblyName)\$(Configuration)\bin\
+ ..\_build\out\$(AssemblyName)\VSCodeIDE\bin\
..\_build\out\$(AssemblyName)\$(Configuration)\obj\
@@ -14,11 +15,11 @@
true
Debug;Release
false
- 7
- net45
+ 7.3
+ net48
CKAN.CmdLine.MainClass
..\assets\ckan.ico
- v4.5
+ v4.8
512
prompt
4
diff --git a/Cmdline/ConsoleUser.cs b/Cmdline/ConsoleUser.cs
index 8f2725b837..99373bdd06 100644
--- a/Cmdline/ConsoleUser.cs
+++ b/Cmdline/ConsoleUser.cs
@@ -93,7 +93,7 @@ public int RaiseSelectionDialog(string message, params object[] args)
}
// Validate input.
- if (String.IsNullOrWhiteSpace(message))
+ if (string.IsNullOrWhiteSpace(message))
{
throw new Kraken("Passed message string must be non-empty.");
}
@@ -130,7 +130,7 @@ public int RaiseSelectionDialog(string message, params object[] args)
// Further data validation.
foreach (object argument in args)
{
- if (String.IsNullOrWhiteSpace(argument.ToString()))
+ if (string.IsNullOrWhiteSpace(argument.ToString()))
{
throw new Kraken("Candidate may not be empty.");
}
@@ -142,14 +142,14 @@ public int RaiseSelectionDialog(string message, params object[] args)
// List options.
for (int i = 0; i < args.Length; i++)
{
- string CurrentRow = String.Format("{0}", i + 1);
+ string CurrentRow = string.Format("{0}", i + 1);
if (i == defaultSelection)
{
CurrentRow += "*";
}
- CurrentRow += String.Format(") {0}", args[i]);
+ CurrentRow += string.Format(") {0}", args[i]);
RaiseMessage(CurrentRow);
}
@@ -176,7 +176,7 @@ public int RaiseSelectionDialog(string message, params object[] args)
input = input.Trim().ToLower();
// Check for default selection.
- if (String.IsNullOrEmpty(input) && defaultSelection >= 0)
+ if (string.IsNullOrEmpty(input) && defaultSelection >= 0)
{
return defaultSelection;
}
diff --git a/Cmdline/Main.cs b/Cmdline/Main.cs
index 22593eff5b..4767f8a7d0 100644
--- a/Cmdline/Main.cs
+++ b/Cmdline/Main.cs
@@ -6,11 +6,8 @@
using System;
using System.Net;
using System.Diagnostics;
-using System.IO;
using System.Linq;
-using System.Reflection;
using System.Runtime.InteropServices;
-using System.Text.RegularExpressions;
using Autofac;
using log4net;
@@ -154,7 +151,9 @@ public static int Execute(GameInstanceManager manager, CommonOptions opts, strin
{
int exitCode = options.Handle(manager, user);
if (exitCode != Exit.OK)
+ {
return exitCode;
+ }
// Don't bother with instances or registries yet because some commands don't need them.
return RunSimpleAction(cmdline, options, args, user, manager);
}
@@ -293,7 +292,7 @@ private static int ConsoleUi(GameInstanceManager manager, ConsoleUIOptions opts)
{
// Debug/verbose output just messes up the screen
LogManager.GetRepository().Threshold = Level.Warn;
- return CKAN.ConsoleUI.ConsoleUI.Main_(manager,
+ return ConsoleUI.ConsoleUI.Main_(manager,
opts.Theme ?? Environment.GetEnvironmentVariable("CKAN_CONSOLEUI_THEME") ?? "default",
opts.Debug);
}
@@ -352,14 +351,7 @@ public NoGameInstanceKraken() { }
public class CmdLineUtil
{
public static uint GetUID()
- {
- if (Platform.IsUnix || Platform.IsMac)
- {
- return getuid();
- }
-
- return 1;
- }
+ => Platform.IsUnix || Platform.IsMac ? getuid() : 1;
[DllImport("libc")]
private static extern uint getuid();
diff --git a/Cmdline/Options.cs b/Cmdline/Options.cs
index 11e89f0a52..6f676ee0ed 100644
--- a/Cmdline/Options.cs
+++ b/Cmdline/Options.cs
@@ -289,7 +289,10 @@ private static void CheckMonoVersion(IUser user, int rec_major, int rec_minor, i
try
{
Type type = Type.GetType("Mono.Runtime");
- if (type == null) return;
+ if (type == null)
+ {
+ return;
+ }
MethodInfo display_name = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
if (display_name != null)
@@ -299,15 +302,15 @@ private static void CheckMonoVersion(IUser user, int rec_major, int rec_minor, i
if (match.Success)
{
- int major = Int32.Parse(match.Groups["major"].Value);
- int minor = Int32.Parse(match.Groups["minor"].Value);
- int patch = Int32.Parse(match.Groups["revision"].Value);
+ int major = int.Parse(match.Groups["major"].Value);
+ int minor = int.Parse(match.Groups["minor"].Value);
+ int patch = int.Parse(match.Groups["revision"].Value);
if (major < rec_major || (major == rec_major && minor < rec_minor))
{
user.RaiseMessage(Properties.Resources.OptionsMonoWarning,
- String.Join(".", major, minor, patch),
- String.Join(".", rec_major, rec_minor, rec_patch));
+ string.Join(".", major, minor, patch),
+ string.Join(".", rec_major, rec_minor, rec_patch));
}
}
}
diff --git a/Cmdline/ProgressReporter.cs b/Cmdline/ProgressReporter.cs
index 02989d0cfe..333ba656c2 100644
--- a/Cmdline/ProgressReporter.cs
+++ b/Cmdline/ProgressReporter.cs
@@ -1,4 +1,3 @@
-using System;
using System.Text.RegularExpressions;
namespace CKAN.CmdLine
diff --git a/Cmdline/SingleAssemblyResourceManager.cs b/Cmdline/SingleAssemblyResourceManager.cs
index 25f1e19f90..e13699cd00 100644
--- a/Cmdline/SingleAssemblyResourceManager.cs
+++ b/Cmdline/SingleAssemblyResourceManager.cs
@@ -1,7 +1,6 @@
using System.IO;
using System.Globalization;
using System.Resources;
-using System.Collections;
using System.Reflection;
using System.Collections.Generic;
@@ -9,7 +8,7 @@ namespace CKAN.CmdLine
{
// 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)
{
@@ -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
@@ -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)
diff --git a/ConsoleUI/CKAN-ConsoleUI.csproj b/ConsoleUI/CKAN-ConsoleUI.csproj
index 1d774b9e5e..634c192ed8 100644
--- a/ConsoleUI/CKAN-ConsoleUI.csproj
+++ b/ConsoleUI/CKAN-ConsoleUI.csproj
@@ -1,7 +1,8 @@
CKAN-ConsoleUI
- ..\_build\out\$(AssemblyName)\$(Configuration)\bin\
+ ..\_build\out\$(AssemblyName)\$(Configuration)\bin\
+ ..\_build\out\$(AssemblyName)\VSCodeIDE\bin\
..\_build\out\$(AssemblyName)\$(Configuration)\obj\
@@ -14,10 +15,10 @@
true
Debug;Release
false
- 7
- net45
+ 7.3
+ net48
..\assets\ckan.ico
- v4.5
+ v4.8
512
prompt
4
diff --git a/ConsoleUI/CompatibleVersionDialog.cs b/ConsoleUI/CompatibleVersionDialog.cs
index a3d016812b..50afd03808 100644
--- a/ConsoleUI/CompatibleVersionDialog.cs
+++ b/ConsoleUI/CompatibleVersionDialog.cs
@@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.ComponentModel;
-using Autofac;
-
using CKAN.Versioning;
using CKAN.Games;
using CKAN.ConsoleUI.Toolkit;
diff --git a/ConsoleUI/DownloadImportDialog.cs b/ConsoleUI/DownloadImportDialog.cs
index 3bc4e7c5f2..116a96b420 100644
--- a/ConsoleUI/DownloadImportDialog.cs
+++ b/ConsoleUI/DownloadImportDialog.cs
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Collections.Generic;
-using System.ComponentModel;
using CKAN.ConsoleUI.Toolkit;
namespace CKAN.ConsoleUI {
diff --git a/ConsoleUI/ExitScreen.cs b/ConsoleUI/ExitScreen.cs
index 86562f89d1..ad74be0125 100644
--- a/ConsoleUI/ExitScreen.cs
+++ b/ConsoleUI/ExitScreen.cs
@@ -59,7 +59,7 @@ private void Draw(ConsoleTheme theme)
.Replace("{0}", ckanPiece).ToArray(),
new FancyLinePiece[] {
new FancyLinePiece(
- new string(Symbols.horizLine, Console.WindowWidth - 2 -2 * horizMargin),
+ new string(Symbols.horizLine, Console.WindowWidth - 2 -(2 * horizMargin)),
theme.ExitInnerBg, theme.ExitNormalFg)
},
}.Concat(
@@ -90,7 +90,7 @@ private void drawLine(ConsoleTheme theme, int y, FancyLinePiece[] pieces)
foreach (FancyLinePiece p in pieces) {
textLen += p.Text.Length;
}
- int boxW = Console.WindowWidth - 2 * horizMargin;
+ int boxW = Console.WindowWidth - (2 * horizMargin);
int leftPad = (boxW - textLen) / 2;
if (leftPad < 0) {
leftPad = 0;
@@ -157,7 +157,7 @@ IEnumerable InjectReplacement(string p, int i)
var pieces = Text.Split(tokens, StringSplitOptions.None);
return pieces.Length <= 1
// Stop making new objects if no tokens found
- ? Enumerable.Repeat(this, 1)
+ ? Enumerable.Repeat(this, 1)
: pieces.SelectMany(InjectReplacement);
}
diff --git a/ConsoleUI/GameInstanceAddScreen.cs b/ConsoleUI/GameInstanceAddScreen.cs
index b882e40cec..59e7f51ba6 100644
--- a/ConsoleUI/GameInstanceAddScreen.cs
+++ b/ConsoleUI/GameInstanceAddScreen.cs
@@ -27,20 +27,13 @@ public GameInstanceAddScreen(GameInstanceManager mgr) : base(mgr)
/// The basic non-empty and unique checks are good enough for adding.
///
protected override bool Valid()
- {
- if (!nameValid() || !pathValid()) {
- return false;
- }
- return true;
- }
+ => nameValid() && pathValid();
///
/// Put description in top center
///
protected override string CenterHeader()
- {
- return Properties.Resources.InstanceAddTitle;
- }
+ => Properties.Resources.InstanceAddTitle;
///
/// Add the instance
diff --git a/ConsoleUI/GameInstanceEditScreen.cs b/ConsoleUI/GameInstanceEditScreen.cs
index 53b4adfc69..ecf923f9e6 100644
--- a/ConsoleUI/GameInstanceEditScreen.cs
+++ b/ConsoleUI/GameInstanceEditScreen.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.ComponentModel;
using CKAN.Versioning;
-using CKAN.Games;
using CKAN.ConsoleUI.Toolkit;
namespace CKAN.ConsoleUI {
@@ -174,33 +173,22 @@ private static V SortedDictFind(SortedDictionary dict, Func
return kvp.Value;
}
}
- return default(V);
+ return default;
}
///
/// Put description in top center
///
protected override string CenterHeader()
- {
- return Properties.Resources.InstanceEditTitle;
- }
+ => Properties.Resources.InstanceEditTitle;
///
/// Return whether the fields are valid.
/// Similar to adding, except leaving the fields unchanged is allowed.
///
protected override bool Valid()
- {
- if (name.Value != ksp.Name
- && !nameValid()) {
- return false;
- }
- if (path.Value != ksp.GameDir()
- && !pathValid()) {
- return false;
- }
- return true;
- }
+ => (name.Value == ksp.Name || nameValid())
+ && (path.Value == ksp.GameDir() || pathValid());
///
/// Save the changes.
diff --git a/ConsoleUI/InstallFilterAddDialog.cs b/ConsoleUI/InstallFilterAddDialog.cs
index dbb953c2eb..de2ea97265 100644
--- a/ConsoleUI/InstallFilterAddDialog.cs
+++ b/ConsoleUI/InstallFilterAddDialog.cs
@@ -1,11 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-
-using Autofac;
-
-using CKAN.Versioning;
-using CKAN.Games;
using CKAN.ConsoleUI.Toolkit;
namespace CKAN.ConsoleUI {
diff --git a/ConsoleUI/ModInfoScreen.cs b/ConsoleUI/ModInfoScreen.cs
index a3ecea46d8..3e55db34df 100644
--- a/ConsoleUI/ModInfoScreen.cs
+++ b/ConsoleUI/ModInfoScreen.cs
@@ -1,7 +1,5 @@
using System;
-using System.Diagnostics;
using System.Collections.Generic;
-using System.Text.RegularExpressions;
using System.Linq;
using System.Threading;
@@ -31,7 +29,7 @@ public ModInfoScreen(GameInstanceManager mgr, Registry registry, ChangePlan cp,
plan = cp;
this.registry = registry;
- int midL = Console.WindowWidth / 2 - 1;
+ int midL = (Console.WindowWidth / 2) - 1;
AddObject(new ConsoleLabel(
1, 1, -1,
@@ -58,8 +56,8 @@ public ModInfoScreen(GameInstanceManager mgr, Registry registry, ChangePlan cp,
));
AddObject(new ConsoleLabel(
13, 4, midL - 2,
- () => string.Join(", ", Array.ConvertAll(
- mod.license.ToArray(), (l => l.ToString())))
+ () => string.Join(", ", Array.ConvertAll(
+ mod.license.ToArray(), l => l.ToString()))
));
AddObject(new ConsoleLabel(
3, 5, 12,
@@ -74,13 +72,13 @@ public ModInfoScreen(GameInstanceManager mgr, Registry registry, ChangePlan cp,
if (mod.install_size > 0)
{
AddObject(new ConsoleLabel(
- midL / 2, 5, midL / 2 + 9,
+ midL / 2, 5, (midL / 2) + 9,
() => "Install:",
null,
th => th.DimLabelFg
));
AddObject(new ConsoleLabel(
- midL / 2 + 9, 5, midL - 2,
+ (midL / 2) + 9, 5, midL - 2,
() => CkanModule.FmtSize(mod.install_size)
));
}
@@ -263,7 +261,7 @@ private int addDependencies(int top = 8)
int numConfs = mod.conflicts?.Count ?? 0;
if (numDeps + numConfs > 0) {
- int midL = Console.WindowWidth / 2 - 1;
+ int midL = (Console.WindowWidth / 2) - 1;
int h = Math.Min(11, numDeps + numConfs + 2);
const int lblW = 16;
int nameW = midL - 2 - lblW - 2 - 1;
@@ -336,7 +334,7 @@ private int addDependencies(int top = 8)
private int addVersionDisplay()
{
- int boxLeft = Console.WindowWidth / 2 + 1,
+ int boxLeft = (Console.WindowWidth / 2) + 1,
boxTop = 3;
const int boxRight = -1,
boxH = 5;
diff --git a/ConsoleUI/ModListHelpDialog.cs b/ConsoleUI/ModListHelpDialog.cs
index 5f110337ff..747c0562af 100644
--- a/ConsoleUI/ModListHelpDialog.cs
+++ b/ConsoleUI/ModListHelpDialog.cs
@@ -22,7 +22,7 @@ public ModListHelpDialog() : base()
int btnL = (Console.WindowWidth - btnW) / 2;
ConsoleTextBox symbolTb = new ConsoleTextBox(
- GetLeft() + 2, GetTop() + 2, Console.WindowWidth / 2 - 1, GetBottom() - 4,
+ GetLeft() + 2, GetTop() + 2, (Console.WindowWidth / 2) - 1, GetBottom() - 4,
false,
TextAlign.Center,
th => th.PopupBg,
@@ -51,7 +51,7 @@ public ModListHelpDialog() : base()
));
ConsoleTextBox searchTb = new ConsoleTextBox(
- Console.WindowWidth / 2 + 1, GetTop() + 3, GetRight() - 2, GetBottom() - 4,
+ (Console.WindowWidth / 2) + 1, GetTop() + 3, GetRight() - 2, GetBottom() - 4,
false,
TextAlign.Center,
th => th.PopupBg,
diff --git a/ConsoleUI/ModListScreen.cs b/ConsoleUI/ModListScreen.cs
index 6c98c0baa6..60bcac5bd9 100644
--- a/ConsoleUI/ModListScreen.cs
+++ b/ConsoleUI/ModListScreen.cs
@@ -31,7 +31,7 @@ public ModListScreen(GameInstanceManager mgr, RepositoryDataManager repoData, Re
debug = dbg;
manager = mgr;
this.regMgr = regMgr;
- this.registry = regMgr.registry;
+ registry = regMgr.registry;
this.repoData = repoData;
moduleList = new ConsoleListBox(
@@ -75,7 +75,9 @@ public ModListScreen(GameInstanceManager mgr, RepositoryDataManager repoData, Re
if (filter.Length <= 1) {
// Don't blank the list for just "~" by itself
return true;
- } else switch (filter.Substring(1, 1)) {
+ } else
+ {
+ switch (filter.Substring(1, 1)) {
case "i":
return registry.IsInstalled(m.identifier, false);
case "u":
@@ -106,6 +108,8 @@ public ModListScreen(GameInstanceManager mgr, RepositoryDataManager repoData, Re
}
return false;
}
+ }
+
return false;
} else {
filter = CkanModule.nonAlphaNums.Replace(filter, "");
@@ -347,7 +351,7 @@ private bool ImportDownloads(ConsoleTheme theme)
private bool CaptureKey(ConsoleTheme theme)
{
- ConsoleKeyInfo k = default(ConsoleKeyInfo);
+ ConsoleKeyInfo k = default;
ConsoleMessageDialog keyprompt = new ConsoleMessageDialog(Properties.Resources.ModListPressAKey, new List());
keyprompt.Run(theme, (ConsoleTheme th) => {
k = Console.ReadKey(true);
@@ -435,11 +439,11 @@ private bool UpdateRegistry(ConsoleTheme theme, bool showNewModsPrompt = true)
);
LaunchSubScreen(theme, ps, (ConsoleTheme th) => {
HashSet availBefore = new HashSet(
- Array.ConvertAll(
+ Array.ConvertAll(
registry.CompatibleModules(
manager.CurrentInstance.VersionCriteria()
).ToArray(),
- (l => l.identifier)
+ l => l.identifier
)
);
recent.Clear();
diff --git a/ConsoleUI/Program.cs b/ConsoleUI/Program.cs
index 2f6e6f299b..da14b854ed 100644
--- a/ConsoleUI/Program.cs
+++ b/ConsoleUI/Program.cs
@@ -14,7 +14,9 @@ public static class ConsoleUI
///
/// Command line arguments
[STAThread]
+ #pragma warning disable IDE0060
public static void Main(string[] args)
+ #pragma warning restore IDE0060
{
Main_(null, null);
}
diff --git a/ConsoleUI/RepoAddScreen.cs b/ConsoleUI/RepoAddScreen.cs
index 0e3629f406..99e972a45c 100644
--- a/ConsoleUI/RepoAddScreen.cs
+++ b/ConsoleUI/RepoAddScreen.cs
@@ -23,12 +23,7 @@ public RepoAddScreen(IGame game, SortedDictionary reps)
/// True if name and URL are valid, false otherwise.
///
protected override bool Valid()
- {
- if (!nameValid() || !urlValid()) {
- return false;
- }
- return true;
- }
+ => nameValid() && urlValid();
///
/// Save the new Repository
diff --git a/ConsoleUI/RepoEditScreen.cs b/ConsoleUI/RepoEditScreen.cs
index 1807aab1ea..32349fab2d 100644
--- a/ConsoleUI/RepoEditScreen.cs
+++ b/ConsoleUI/RepoEditScreen.cs
@@ -28,17 +28,8 @@ public RepoEditScreen(IGame game, SortedDictionary reps, Rep
/// True if valid, false otherwise
///
protected override bool Valid()
- {
- if (name.Value != repository.name
- && !nameValid()) {
- return false;
- }
- if (url.Value != repository.uri.ToString()
- && !urlValid()) {
- return false;
- }
- return true;
- }
+ => (name.Value == repository.name || nameValid())
+ && (url.Value == repository.uri.ToString() || urlValid());
///
/// Save changes
diff --git a/ConsoleUI/SingleAssemblyResourceManager.cs b/ConsoleUI/SingleAssemblyResourceManager.cs
index 994305ec28..ecdf62c50d 100644
--- a/ConsoleUI/SingleAssemblyResourceManager.cs
+++ b/ConsoleUI/SingleAssemblyResourceManager.cs
@@ -1,7 +1,6 @@
using System.IO;
using System.Globalization;
using System.Resources;
-using System.Collections;
using System.Reflection;
using System.Collections.Generic;
@@ -9,12 +8,29 @@ namespace CKAN.ConsoleUI
{
// Thanks and credit to this guy: https://stackoverflow.com/q/1952638/2422988
- class SingleAssemblyResourceManager : ResourceManager
+ ///
+ /// Wrapper around ResourceManager that retrieves strings from the assembly
+ /// rather than external files
+ ///
+ public class SingleAssemblyResourceManager : ResourceManager
{
- public SingleAssemblyResourceManager(string basename, Assembly assembly) : base(basename, assembly)
+ ///
+ /// Initialize the resource manager
+ ///
+ /// To be passed to ResourceManager
+ /// To be passed to ResourceManager
+ public SingleAssemblyResourceManager(string basename, Assembly assembly)
+ : base(basename, assembly)
{
}
+ ///
+ /// Provides resources from the assembly to ResourceManager
+ ///
+ /// The language to get
+ /// Set to false to avoid loading if not already cached
+ /// Just gets passed to base class implementation
+ ///
protected override ResourceSet InternalGetResourceSet(CultureInfo culture,
bool createIfNotExists, bool tryParents)
{
@@ -23,7 +39,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
@@ -34,7 +50,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)
diff --git a/ConsoleUI/Toolkit/ConsoleButton.cs b/ConsoleUI/Toolkit/ConsoleButton.cs
index 98aea54123..010d95a369 100644
--- a/ConsoleUI/Toolkit/ConsoleButton.cs
+++ b/ConsoleUI/Toolkit/ConsoleButton.cs
@@ -35,12 +35,8 @@ public override void Draw(ConsoleTheme theme, bool focused)
// Main button text
Console.SetCursorPosition(GetLeft(), GetTop());
Console.BackgroundColor = theme.PopupButtonBg;
- if (focused) {
- Console.ForegroundColor = theme.PopupButtonSelectedFg;
- } else {
- Console.ForegroundColor = theme.PopupButtonFg;
- }
- Console.Write(ScreenObject.PadCenter(caption, w));
+ Console.ForegroundColor = focused ? theme.PopupButtonSelectedFg : theme.PopupButtonFg;
+ Console.Write(PadCenter(caption, w));
// Right shadow
if (theme.PopupButtonShadow.HasValue)
@@ -93,8 +89,8 @@ public override void OnKeyPress(ConsoleKeyInfo k)
}
}
- private string caption;
- private Action choiceEvent;
+ private readonly string caption;
+ private readonly Action choiceEvent;
private readonly string shadowStrip;
}
}
diff --git a/ConsoleUI/Toolkit/ConsoleChoiceDialog.cs b/ConsoleUI/Toolkit/ConsoleChoiceDialog.cs
index a9f493629b..50d4d19ab6 100644
--- a/ConsoleUI/Toolkit/ConsoleChoiceDialog.cs
+++ b/ConsoleUI/Toolkit/ConsoleChoiceDialog.cs
@@ -84,11 +84,11 @@ public ConsoleChoiceDialog(string m, string hdr, List c, Func process = null)
{
base.Run(theme, process);
- return cancelled ? default(ChoiceT) : choices.Selection;
+ return cancelled ? default : choices.Selection;
}
- private ConsoleListBox choices;
- private bool cancelled;
+ private readonly ConsoleListBox choices;
+ private bool cancelled;
}
}
diff --git a/ConsoleUI/Toolkit/ConsoleDialog.cs b/ConsoleUI/Toolkit/ConsoleDialog.cs
index 3a73809040..6bbd02b539 100644
--- a/ConsoleUI/Toolkit/ConsoleDialog.cs
+++ b/ConsoleUI/Toolkit/ConsoleDialog.cs
@@ -1,5 +1,4 @@
using System;
-using System.Collections.Generic;
namespace CKAN.ConsoleUI.Toolkit {
diff --git a/ConsoleUI/Toolkit/ConsoleDoubleFrame.cs b/ConsoleUI/Toolkit/ConsoleDoubleFrame.cs
index d27a35db54..f77d3e8e94 100644
--- a/ConsoleUI/Toolkit/ConsoleDoubleFrame.cs
+++ b/ConsoleUI/Toolkit/ConsoleDoubleFrame.cs
@@ -91,11 +91,11 @@ private void writeTitleRow(string title, int w)
///
public override bool Focusable() { return false; }
- private Func getTopTitle;
- private Func getMidTitle;
- private Func getColor;
- private bool doubleBorder;
- private int middleRow;
+ private readonly Func getTopTitle;
+ private readonly Func getMidTitle;
+ private readonly Func getColor;
+ private readonly bool doubleBorder;
+ private readonly int middleRow;
}
}
diff --git a/ConsoleUI/Toolkit/ConsoleField.cs b/ConsoleUI/Toolkit/ConsoleField.cs
index 9e13ab1cf3..5aaf25fe3b 100644
--- a/ConsoleUI/Toolkit/ConsoleField.cs
+++ b/ConsoleUI/Toolkit/ConsoleField.cs
@@ -1,5 +1,4 @@
using System;
-using CKAN.ConsoleUI.Toolkit;
namespace CKAN.ConsoleUI.Toolkit {
@@ -49,9 +48,7 @@ public ConsoleField(int l, int t, int r, string val = "")
public event ChangeListener OnChange;
private void Changed()
{
- if (OnChange != null) {
- OnChange(this, Value);
- }
+ OnChange?.Invoke(this, Value);
}
///
@@ -89,11 +86,9 @@ public override void Draw(ConsoleTheme theme, bool focused)
Console.ForegroundColor = theme.FieldGhostFg;
Console.Write(GhostText().PadRight(w));
} else {
- if (focused) {
- Console.ForegroundColor = theme.FieldFocusedFg;
- } else {
- Console.ForegroundColor = theme.FieldBlurredFg;
- }
+ Console.ForegroundColor = focused
+ ? theme.FieldFocusedFg
+ : theme.FieldBlurredFg;
Console.Write(FormatExactWidth(Value.Substring(leftPos), w));
}
}
@@ -126,11 +121,9 @@ public override void OnKeyPress(ConsoleKeyInfo k)
break;
case ConsoleKey.Delete:
if (Position < Value.Length) {
- if ((k.Modifiers & ConsoleModifiers.Control) == 0) {
- Value = Value.Substring(0, Position) + Value.Substring(Position + 1);
- } else {
- Value = Value.Substring(0, Position);
- }
+ Value = (k.Modifiers & ConsoleModifiers.Control) == 0
+ ? Value.Substring(0, Position) + Value.Substring(Position + 1)
+ : Value.Substring(0, Position);
Changed();
}
break;
@@ -160,7 +153,7 @@ public override void OnKeyPress(ConsoleKeyInfo k)
Blur((k.Modifiers & ConsoleModifiers.Shift) == 0);
break;
default:
- if (!Char.IsControl(k.KeyChar)) {
+ if (!char.IsControl(k.KeyChar)) {
if (Position < Value.Length) {
Value = Value.Substring(0, Position) + k.KeyChar + Value.Substring(Position);
} else {
diff --git a/ConsoleUI/Toolkit/ConsoleFileMultiSelectDialog.cs b/ConsoleUI/Toolkit/ConsoleFileMultiSelectDialog.cs
index 1597e2eec9..36919347d0 100644
--- a/ConsoleUI/Toolkit/ConsoleFileMultiSelectDialog.cs
+++ b/ConsoleUI/Toolkit/ConsoleFileMultiSelectDialog.cs
@@ -24,9 +24,9 @@ public ConsoleFileMultiSelectDialog(string title, string startPath, string filPa
curDir = new DirectoryInfo(startPath);
filePattern = filPat;
- int w = (Console.WindowWidth > idealW + 2 * hPad)
+ int w = (Console.WindowWidth > idealW + (2 * hPad))
? idealW
- : Console.WindowWidth - 2 * hPad;
+ : Console.WindowWidth - (2 * hPad);
int left = (Console.WindowWidth - w) / 2;
int right = -left;
@@ -73,8 +73,8 @@ public ConsoleFileMultiSelectDialog(string title, string startPath, string filPa
Width = 9,
Renderer = (FileSystemInfo fi) => getLength(fi),
Comparer = (a, b) => {
- FileInfo fa = a as FileInfo, fb = b as FileInfo;
- return fa == null
+ FileInfo fb = b as FileInfo;
+ return !(a is FileInfo fa)
? (fb == null ? 0 : -1)
: (fb == null ? 1 : fa.Length.CompareTo(fb.Length));
}
@@ -111,8 +111,8 @@ public ConsoleFileMultiSelectDialog(string title, string startPath, string filPa
AddBinding(Keys.CtrlA, (object sender, ConsoleTheme theme) => {
foreach (FileSystemInfo fi in contents) {
if (!isDir(fi)) {
- FileInfo file = fi as FileInfo;
- if (file != null) {
+ if (fi is FileInfo file)
+ {
chosenFiles.Add(file);
}
}
@@ -137,18 +137,21 @@ public ConsoleFileMultiSelectDialog(string title, string startPath, string filPa
private bool selectRow()
{
if (isDir(fileList.Selection)) {
- DirectoryInfo di = fileList.Selection as DirectoryInfo;
- if (di != null) {
+ if (fileList.Selection is DirectoryInfo di)
+ {
curDir = di;
pathField.Value = curDir.FullName;
fileList.SetData(getFileList());
}
} else {
- FileInfo fi = fileList.Selection as FileInfo;
- if (fi != null) {
- if (chosenFiles.Contains(fi)) {
+ if (fileList.Selection is FileInfo fi)
+ {
+ if (chosenFiles.Contains(fi))
+ {
chosenFiles.Remove(fi);
- } else {
+ }
+ else
+ {
chosenFiles.Add(fi);
}
}
@@ -226,18 +229,11 @@ private static bool pathEquals(FileSystemInfo a, FileSystemInfo b)
}
private string getLength(FileSystemInfo fi)
- {
- if (isDir(fi)) {
- return Properties.Resources.FileSelectDirSize;
- } else {
- FileInfo file = fi as FileInfo;
- if (file != null) {
- return CkanModule.FmtSize(file.Length);
- } else {
- return Properties.Resources.FileSelectDirSize;
- }
- }
- }
+ => isDir(fi)
+ ? Properties.Resources.FileSelectDirSize
+ : fi is FileInfo file
+ ? CkanModule.FmtSize(file.Length)
+ : Properties.Resources.FileSelectDirSize;
private long totalChosenSize()
{
@@ -250,12 +246,9 @@ private long totalChosenSize()
}
private string getRowSymbol(FileSystemInfo fi)
- {
- if (!isDir(fi) && chosenFiles.Contains(fi as FileInfo)) {
- return chosen;
- }
- return "";
- }
+ => !isDir(fi) && chosenFiles.Contains(fi as FileInfo)
+ ? chosen
+ : "";
private string getRowName(FileSystemInfo fi)
{
@@ -298,19 +291,19 @@ private int compareNames(FileSystemInfo a, FileSystemInfo b)
}
}
- private List contents;
- private ConsoleField pathField;
- private ConsoleListBox fileList;
- private DirectoryInfo curDir;
+ private List contents;
+ private readonly ConsoleField pathField;
+ private readonly ConsoleListBox fileList;
+ private DirectoryInfo curDir;
- private HashSet chosenFiles = new HashSet();
+ private readonly HashSet chosenFiles = new HashSet();
- private string filePattern;
+ private readonly string filePattern;
private static readonly string chosen = Symbols.checkmark;
private const int idealW = 76;
- private int labelW => Properties.Resources.FileSelectDirectory.Length;
+ private int labelW => Properties.Resources.FileSelectDirectory.Length;
private const int hPad = 2;
private const int top = 2;
private const int bottom = -2;
diff --git a/ConsoleUI/Toolkit/ConsoleFrame.cs b/ConsoleUI/Toolkit/ConsoleFrame.cs
index 1d9bc859b1..15a9c15c02 100644
--- a/ConsoleUI/Toolkit/ConsoleFrame.cs
+++ b/ConsoleUI/Toolkit/ConsoleFrame.cs
@@ -75,9 +75,9 @@ public override void Draw(ConsoleTheme theme, bool focused)
///
public override bool Focusable() { return false; }
- private Func getTitle;
- private Func getColor;
- private bool doubleBorder;
+ private readonly Func getTitle;
+ private readonly Func getColor;
+ private readonly bool doubleBorder;
}
}
diff --git a/ConsoleUI/Toolkit/ConsoleLabel.cs b/ConsoleUI/Toolkit/ConsoleLabel.cs
index a59f8678a0..ebbb9e95ac 100644
--- a/ConsoleUI/Toolkit/ConsoleLabel.cs
+++ b/ConsoleUI/Toolkit/ConsoleLabel.cs
@@ -33,16 +33,8 @@ public override void Draw(ConsoleTheme theme, bool focused)
{
int w = GetRight() - GetLeft() + 1;
Console.SetCursorPosition(GetLeft(), GetTop());
- if (getBgColor == null) {
- Console.BackgroundColor = theme.LabelBg;
- } else {
- Console.BackgroundColor = getBgColor(theme);
- }
- if (getFgColor == null) {
- Console.ForegroundColor = theme.LabelFg;
- } else {
- Console.ForegroundColor = getFgColor(theme);
- }
+ Console.BackgroundColor = getBgColor == null ? theme.LabelBg : getBgColor(theme);
+ Console.ForegroundColor = getFgColor == null ? theme.LabelFg : getFgColor(theme);
try {
Console.Write(FormatExactWidth(labelFunc(), w));
} catch (Exception ex) {
@@ -55,9 +47,9 @@ public override void Draw(ConsoleTheme theme, bool focused)
///
public override bool Focusable() { return false; }
- private Func labelFunc;
- private Func getBgColor;
- private Func getFgColor;
+ private readonly Func labelFunc;
+ private readonly Func getBgColor;
+ private readonly Func getFgColor;
}
}
diff --git a/ConsoleUI/Toolkit/ConsoleListBox.cs b/ConsoleUI/Toolkit/ConsoleListBox.cs
index 38c4b6d44c..ba6581afed 100644
--- a/ConsoleUI/Toolkit/ConsoleListBox.cs
+++ b/ConsoleUI/Toolkit/ConsoleListBox.cs
@@ -82,15 +82,10 @@ public string FilterString {
///
/// Currently selected row's object
///
- public RowT Selection {
- get {
- if (selectedRow >= 0 && selectedRow < (sortedFilteredData?.Count ?? 0)) {
- return sortedFilteredData[selectedRow];
- } else {
- return default (RowT);
- }
- }
- }
+ public RowT Selection
+ => selectedRow >= 0 && selectedRow < (sortedFilteredData?.Count ?? 0)
+ ? sortedFilteredData[selectedRow]
+ : default;
///
/// Return the number of rows shown in the box
@@ -201,7 +196,7 @@ public override void Draw(ConsoleTheme theme, bool focused)
theme,
r, t + scrollTop, b,
sortedFilteredData.Count > 0
- ? t + 1 + scrollTop + (h - 2 - scrollTop) * selectedRow / sortedFilteredData.Count
+ ? t + 1 + scrollTop + ((h - 2 - scrollTop) * selectedRow / sortedFilteredData.Count)
: -1
);
}
@@ -251,7 +246,7 @@ public override void OnKeyPress(ConsoleKeyInfo k)
break;
default:
// Go backwards if (k.Modifiers & ConsoleModifiers.Shift)
- if (!Char.IsControl(k.KeyChar)
+ if (!char.IsControl(k.KeyChar)
&& (k.Modifiers | ConsoleModifiers.Shift) == ConsoleModifiers.Shift) {
bool forward = (k.Modifiers & ConsoleModifiers.Shift) == 0;
@@ -350,30 +345,21 @@ public void SetData(IList newData)
}
private string FmtHdr(int colIndex, int w)
- {
- ConsoleListBoxColumn col = columns[colIndex];
- if (colIndex == sortColIndex) {
- return FormatExactWidth(
- col.Header + " " + (sortDir == ListSortDirection.Ascending ? sortUp : sortDown),
- w
- );
- } else {
- return FormatExactWidth(col.Header, w);
- }
- }
+ => colIndex == sortColIndex
+ ? FormatExactWidth(
+ columns[colIndex].Header + " "
+ + (sortDir == ListSortDirection.Ascending ? sortUp : sortDown),
+ w)
+ : FormatExactWidth(columns[colIndex].Header, w);
private void filterAndSort()
{
// Keep the same row highlighted when the number of rows changes
RowT oldSelect = Selection;
- if (string.IsNullOrEmpty(filterStr) || filterCheck == null) {
- sortedFilteredData = new List(data);
- } else {
- sortedFilteredData = new List(data).FindAll(
- r => filterCheck(r, filterStr)
- );
- }
+ sortedFilteredData = string.IsNullOrEmpty(filterStr) || filterCheck == null
+ ? new List(data)
+ : new List(data).FindAll(r => filterCheck(r, filterStr));
// Semantic sort for versions rather than lexicographical
if (sortColIndex >= 0 && sortColIndex < columns.Count) {
@@ -395,40 +381,31 @@ private void filterAndSort()
}
private Comparison getComparer(ConsoleListBoxColumn col, bool ascending)
- {
- if (ascending) {
- return col.Comparer
- ?? ((a, b) => col.Renderer(a).Trim().CompareTo(col.Renderer(b).Trim()));
-
- } else if (col.Comparer != null) {
- return (a, b) => col.Comparer(b, a);
- } else {
- return (a, b) => col.Renderer(b).Trim().CompareTo(col.Renderer(a).Trim());
- }
- }
+ => ascending
+ ? col.Comparer
+ ?? ((a, b) => col.Renderer(a).Trim().CompareTo(col.Renderer(b).Trim()))
+ : col.Comparer != null
+ ? (Comparison)((RowT a, RowT b) => col.Comparer(b, a))
+ : ((RowT a, RowT b) => col.Renderer(b).Trim().CompareTo(col.Renderer(a).Trim()));
// Sometimes type safety can be a minor hindrance;
// this would just be "first || second" in C
private int IntOr(Func first, Func second)
{
int a = first();
- if (a != 0) {
- return a;
- } else {
- return second();
- }
+ return a != 0 ? a : second();
}
- private List sortedFilteredData;
- private IList data;
- private IList> columns;
- private Func filterCheck;
- private ConsolePopupMenu sortMenu;
+ private List sortedFilteredData;
+ private IList data;
+ private readonly IList> columns;
+ private readonly Func filterCheck;
+ private ConsolePopupMenu sortMenu;
- private int defaultSortColumn = 0;
- private int sortColIndex;
- private ListSortDirection sortDir;
- private string filterStr = "";
+ private readonly int defaultSortColumn = 0;
+ private int sortColIndex;
+ private ListSortDirection sortDir;
+ private string filterStr = "";
private int topRow = 0;
private int selectedRow = 0;
diff --git a/ConsoleUI/Toolkit/ConsoleMessageDialog.cs b/ConsoleUI/Toolkit/ConsoleMessageDialog.cs
index ef8126ce06..7f34d14a8e 100644
--- a/ConsoleUI/Toolkit/ConsoleMessageDialog.cs
+++ b/ConsoleUI/Toolkit/ConsoleMessageDialog.cs
@@ -27,7 +27,7 @@ public ConsoleMessageDialog(string m, List btns, Func hdr = null
CenterHeader = hdr;
}
- int btnW = btns.Count * buttonWidth + (btns.Count - 1) * buttonPadding;
+ int btnW = (btns.Count * buttonWidth) + ((btns.Count - 1) * buttonPadding);
if (w < btnW + 4) {
// Widen the window to fit the buttons
// Buttons will NOT wrap - use ConsoleChoiceDialog
@@ -46,13 +46,13 @@ public ConsoleMessageDialog(string m, List btns, Func hdr = null
// Calculate vertical position including offset
int t, b;
if (vertOffset <= 0) {
- t = (Console.WindowHeight - h) / 2 + vertOffset;
+ t = ((Console.WindowHeight - h) / 2) + vertOffset;
if (t < 1) {
t = 2;
}
b = t + h - 1;
} else {
- b = (Console.WindowHeight - h) / 2 + h - 1;
+ b = ((Console.WindowHeight - h) / 2) + h - 1;
if (b >= Console.WindowHeight - 1) {
b = Console.WindowHeight - 1;
}
diff --git a/ConsoleUI/Toolkit/ConsolePopupMenu.cs b/ConsoleUI/Toolkit/ConsolePopupMenu.cs
index c1558d9fe5..3d8026d91e 100644
--- a/ConsoleUI/Toolkit/ConsolePopupMenu.cs
+++ b/ConsoleUI/Toolkit/ConsolePopupMenu.cs
@@ -66,13 +66,10 @@ public bool Run(ConsoleTheme theme, int right, int top)
if (options[selectedOption].OnExec != null) {
val = options[selectedOption].OnExec(theme);
}
- if (options[selectedOption].SubMenu != null) {
- options[selectedOption].SubMenu.Run(
+ options[selectedOption].SubMenu?.Run(
theme,
right - 2,
- top + selectedOption + 2
- );
- }
+ top + selectedOption + 2);
break;
case ConsoleKey.F10:
case ConsoleKey.Escape:
@@ -156,23 +153,17 @@ private void DrawFooter(ConsoleTheme theme)
}
private string AnnotatedCaption(ConsoleMenuOption opt)
- {
- if (opt.SubMenu != null) {
- return opt.Caption.PadRight(longestLength - 1) + submenuIndicator;
- } else if (opt.RadioActive != null) {
- if (opt.RadioActive()) {
- return $"({Symbols.dot}) {opt.Caption}".PadRight(longestLength);
- } else {
- return $"( ) {opt.Caption}".PadRight(longestLength);
- }
- } else {
- return opt.Caption.PadRight(longestLength - opt.Key.Length) + opt.Key;
- }
- }
+ => opt.SubMenu != null
+ ? opt.Caption.PadRight(longestLength - 1) + submenuIndicator
+ : opt.RadioActive != null
+ ? opt.RadioActive()
+ ? $"({Symbols.dot}) {opt.Caption}".PadRight(longestLength)
+ : $"( ) {opt.Caption}".PadRight(longestLength)
+ : opt.Caption.PadRight(longestLength - opt.Key.Length) + opt.Key;
- private List options;
- private int longestLength;
- private int selectedOption = 0;
+ private readonly List options;
+ private readonly int longestLength;
+ private int selectedOption = 0;
private static readonly string submenuIndicator = ">";
}
diff --git a/ConsoleUI/Toolkit/ConsoleProgressBar.cs b/ConsoleUI/Toolkit/ConsoleProgressBar.cs
index 77f93b35a5..ac07f3579b 100644
--- a/ConsoleUI/Toolkit/ConsoleProgressBar.cs
+++ b/ConsoleUI/Toolkit/ConsoleProgressBar.cs
@@ -63,8 +63,8 @@ public override void Draw(ConsoleTheme theme, bool focused)
///
public override bool Focusable() { return false; }
- private Func captionFunc;
- private Func percentFunc;
+ private readonly Func captionFunc;
+ private readonly Func percentFunc;
}
}
diff --git a/ConsoleUI/Toolkit/ConsoleScreen.cs b/ConsoleUI/Toolkit/ConsoleScreen.cs
index 7eeb1cf8e5..d51e48f4a1 100644
--- a/ConsoleUI/Toolkit/ConsoleScreen.cs
+++ b/ConsoleUI/Toolkit/ConsoleScreen.cs
@@ -78,7 +78,7 @@ protected virtual string MenuTip()
///
/// Tell IUser clients that we have the ability to interact with the user
///
- public bool Headless { get { return false; } }
+ public bool Headless => false;
// These functions can be implemented the same on all screens,
// so they are not virtual.
@@ -128,7 +128,7 @@ public int RaiseSelectionDialog(string message, params object[] args)
{
ConsoleMessageDialog d = new ConsoleMessageDialog(
string.Join("", messagePieces) + message,
- new List(Array.ConvertAll