Skip to content

Commit

Permalink
Merge #3920 VSCode clean-up and other minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Oct 18, 2023
2 parents 46c4dec + 95dd738 commit b50dda0
Show file tree
Hide file tree
Showing 201 changed files with 619 additions and 2,504 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/_build/
/.vs/
/.vscode/
/tools
test-results
*.userprefs
Expand Down
7 changes: 4 additions & 3 deletions AutoUpdate/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ private static void MakeExecutable(string path)

string command = string.Format("+x \"{0}\"", path);

ProcessStartInfo permsinfo = new ProcessStartInfo("chmod", command);
permsinfo.UseShellExecute = false;
Process permsprocess = Process.Start(permsinfo);
var permsprocess = Process.Start(new ProcessStartInfo("chmod", command)
{
UseShellExecute = false
});
permsprocess.WaitForExit();
}
}
Expand Down
5 changes: 2 additions & 3 deletions AutoUpdate/SingleAssemblyResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public SingleAssemblyResourceManager(string basename, Assembly assembly) : base(
protected override ResourceSet InternalGetResourceSet(CultureInfo culture,
bool createIfNotExists, bool tryParents)
{
ResourceSet rs;
if (!myResourceSets.TryGetValue(culture, out rs) && createIfNotExists)
if (!myResourceSets.TryGetValue(culture, out ResourceSet rs) && createIfNotExists)
{
// Lazy-load default language (without caring about duplicate assignment in race conditions, no harm done)
if (neutralResourcesCulture == null)
Expand Down Expand Up @@ -53,6 +52,6 @@ protected override ResourceSet InternalGetResourceSet(CultureInfo culture,
}

private CultureInfo neutralResourcesCulture;
private Dictionary<CultureInfo, ResourceSet> myResourceSets = new Dictionary<CultureInfo, ResourceSet>();
private readonly Dictionary<CultureInfo, ResourceSet> myResourceSets = new Dictionary<CultureInfo, ResourceSet>();
}
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ All notable changes to this project will be documented in this file.
- [CLI] Parse quoted strings for `ckan prompt` (#3889 by: HebaruSan; reviewed: techman83)
- [Build] Remove log4net, newtonsoft deps from deb package (#3900 by: HebaruSan; reviewed: techman83)
- [GUI] Add test to check GUI thread safety (#3914 by: HebaruSan; reviewed: techman83)
- [Multiple] VSCode clean-up and other minor fixes (#3920 by: HebaruSan)

## v1.33.2 (Laplace)

Expand Down
14 changes: 5 additions & 9 deletions Cmdline/Action/AuthToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using CKAN.Configuration;
using CommandLine;
using CommandLine.Text;
using log4net;

namespace CKAN.CmdLine
{
Expand Down Expand Up @@ -49,7 +48,7 @@ public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCom
switch (option)
{
case "list":
exitCode = listAuthTokens(options);
exitCode = listAuthTokens();
break;
case "add":
exitCode = addAuthToken((AddAuthTokenOptions)options);
Expand All @@ -64,7 +63,7 @@ public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCom
return exitCode;
}

private int listAuthTokens(CommonOptions opts)
private int listAuthTokens()
{
string hostHeader = Properties.Resources.AuthTokenHostHeader;
string tokenHeader = Properties.Resources.AuthTokenTokenHeader;
Expand All @@ -76,8 +75,7 @@ private int listAuthTokens(CommonOptions opts)
foreach (string host in hosts)
{
longestHostLen = Math.Max(longestHostLen, host.Length);
string token;
if (ServiceLocator.Container.Resolve<IConfiguration>().TryGetAuthToken(host, out token))
if (ServiceLocator.Container.Resolve<IConfiguration>().TryGetAuthToken(host, out string token))
{
longestTokenLen = Math.Max(longestTokenLen, token.Length);
}
Expand All @@ -92,8 +90,7 @@ private int listAuthTokens(CommonOptions opts)
);
foreach (string host in hosts)
{
string token;
if (ServiceLocator.Container.Resolve<IConfiguration>().TryGetAuthToken(host, out token))
if (ServiceLocator.Container.Resolve<IConfiguration>().TryGetAuthToken(host, out string token))
{
user.RaiseMessage(fmt, host, token);
}
Expand Down Expand Up @@ -121,8 +118,7 @@ private int removeAuthToken(RemoveAuthTokenOptions opts)
return Exit.OK;
}

private IUser user;
private static readonly ILog log = LogManager.GetLogger(typeof(AuthToken));
private IUser user;
}

internal class AuthTokenSubOptions : VerbCommandOptions
Expand Down
4 changes: 2 additions & 2 deletions Cmdline/Action/Available.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
return Exit.OK;
}

private IUser user;
private RepositoryDataManager repoData;
private readonly IUser user;
private readonly RepositoryDataManager repoData;
}
}
27 changes: 11 additions & 16 deletions Cmdline/Action/Cache.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CommandLine;
using CommandLine.Text;
using log4net;
using Autofac;

using CKAN.Configuration;
Expand Down Expand Up @@ -112,23 +111,23 @@ public int RunSubCommand(GameInstanceManager mgr, CommonOptions opts, SubCommand
switch (option)
{
case "list":
exitCode = ListCacheDirectory((CommonOptions)suboptions);
exitCode = ListCacheDirectory();
break;

case "set":
exitCode = SetCacheDirectory((SetOptions)suboptions);
break;

case "clear":
exitCode = ClearCacheDirectory((CommonOptions)suboptions);
exitCode = ClearCacheDirectory();
break;

case "reset":
exitCode = ResetCacheDirectory((CommonOptions)suboptions);
exitCode = ResetCacheDirectory();
break;

case "showlimit":
exitCode = ShowCacheSizeLimit((CommonOptions)suboptions);
exitCode = ShowCacheSizeLimit();
break;

case "setlimit":
Expand All @@ -145,7 +144,7 @@ public int RunSubCommand(GameInstanceManager mgr, CommonOptions opts, SubCommand
return exitCode;
}

private int ListCacheDirectory(CommonOptions options)
private int ListCacheDirectory()
{
IConfiguration cfg = ServiceLocator.Container.Resolve<IConfiguration>();
user.RaiseMessage(cfg.DownloadCacheDir);
Expand All @@ -161,8 +160,7 @@ private int SetCacheDirectory(SetOptions options)
return Exit.BADOPT;
}

string failReason;
if (manager.TrySetupCache(options.Path, out failReason))
if (manager.TrySetupCache(options.Path, out string failReason))
{
IConfiguration cfg = ServiceLocator.Container.Resolve<IConfiguration>();
user.RaiseMessage(Properties.Resources.CacheSet, cfg.DownloadCacheDir);
Expand All @@ -176,18 +174,17 @@ private int SetCacheDirectory(SetOptions options)
}
}

private int ClearCacheDirectory(CommonOptions options)
private int ClearCacheDirectory()
{
manager.Cache.RemoveAll();
user.RaiseMessage(Properties.Resources.CacheCleared);
printCacheInfo();
return Exit.OK;
}

private int ResetCacheDirectory(CommonOptions options)
private int ResetCacheDirectory()
{
string failReason;
if (manager.TrySetupCache("", out failReason))
if (manager.TrySetupCache("", out string failReason))
{
IConfiguration cfg = ServiceLocator.Container.Resolve<IConfiguration>();
user.RaiseMessage(Properties.Resources.CacheReset, cfg.DownloadCacheDir);
Expand All @@ -200,7 +197,7 @@ private int ResetCacheDirectory(CommonOptions options)
return Exit.OK;
}

private int ShowCacheSizeLimit(CommonOptions options)
private int ShowCacheSizeLimit()
{
IConfiguration cfg = ServiceLocator.Container.Resolve<IConfiguration>();
if (cfg.CacheSizeLimit.HasValue)
Expand All @@ -225,7 +222,7 @@ private int SetCacheSizeLimit(SetLimitOptions options)
{
cfg.CacheSizeLimit = options.Megabytes * (long)1024 * (long)1024;
}
return ShowCacheSizeLimit(null);
return ShowCacheSizeLimit();
}

private void printCacheInfo()
Expand All @@ -239,8 +236,6 @@ private void printCacheInfo()

private IUser user;
private GameInstanceManager manager;

private static readonly ILog log = LogManager.GetLogger(typeof(Cache));
}

}
2 changes: 1 addition & 1 deletion Cmdline/Action/Compare.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CKAN.CmdLine
// Does not need an instance, so this is not an ICommand
public class Compare
{
private IUser user;
private readonly IUser user;

public Compare(IUser user)
{
Expand Down
12 changes: 5 additions & 7 deletions Cmdline/Action/Compat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,10 @@ public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCom
var instance = MainClass.GetGameInstance(_kspManager);
var addOptions = (CompatAddOptions)suboptions;

GameVersion GameVersion;
if (GameVersion.TryParse(addOptions.Version, out GameVersion))
if (GameVersion.TryParse(addOptions.Version, out GameVersion gv))
{
var newCompatibleVersion = instance.GetCompatibleVersions();
newCompatibleVersion.Add(GameVersion);
newCompatibleVersion.Add(gv);
instance.SetCompatibleVersions(newCompatibleVersion);
}
else
Expand All @@ -170,13 +169,12 @@ public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCom
var instance = MainClass.GetGameInstance(_kspManager);
var addOptions = (CompatForgetOptions)suboptions;

GameVersion GameVersion;
if (GameVersion.TryParse(addOptions.Version, out GameVersion))
if (GameVersion.TryParse(addOptions.Version, out GameVersion gv))
{
if (GameVersion != instance.Version())
if (gv != instance.Version())
{
var newCompatibleVersion = instance.GetCompatibleVersions();
newCompatibleVersion.RemoveAll(i => i == GameVersion);
newCompatibleVersion.RemoveAll(i => i == gv);
instance.SetCompatibleVersions(newCompatibleVersion);
}
else
Expand Down
7 changes: 2 additions & 5 deletions Cmdline/Action/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Autofac;
using CommandLine;
using CommandLine.Text;
using log4net;

namespace CKAN.CmdLine
{
Expand Down Expand Up @@ -48,7 +47,7 @@ public int RunSubCommand(GameInstanceManager mgr, CommonOptions opts, SubCommand
switch (option)
{
case "list":
exitCode = ListFilters((FilterListOptions)suboptions, option);
exitCode = ListFilters((FilterListOptions)suboptions);
break;

case "add":
Expand All @@ -69,7 +68,7 @@ public int RunSubCommand(GameInstanceManager mgr, CommonOptions opts, SubCommand
return exitCode;
}

private int ListFilters(FilterListOptions opts, string verb)
private int ListFilters(FilterListOptions opts)
{
int exitCode = opts.Handle(manager, user);
if (exitCode != Exit.OK)
Expand Down Expand Up @@ -216,8 +215,6 @@ private int RemoveFilters(FilterRemoveOptions opts, string verb)

private GameInstanceManager manager;
private IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(Filter));
}

internal class FilterSubOptions : VerbCommandOptions
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/GameInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ private int CloneInstall(CloneOptions options)
}
// Try to use instanceNameOrPath as a path and create a new game instance.
// If it's valid, go on.
else if (Manager.InstanceAt(instanceNameOrPath, newName) is CKAN.GameInstance instance && instance.Valid)
else if (Manager.InstanceAt(instanceNameOrPath) is CKAN.GameInstance instance && instance.Valid)
{
Manager.CloneInstance(instance, newName, newPath);
}
Expand Down
8 changes: 4 additions & 4 deletions Cmdline/Action/Install.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
// Parse the JSON file.
try
{
CkanModule m = MainClass.LoadCkanFromFile(instance, filename);
CkanModule m = MainClass.LoadCkanFromFile(filename);
options.modules.Add($"{m.identifier}={m.version}");
}
catch (Kraken kraken)
Expand Down Expand Up @@ -275,9 +275,9 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
return Exit.OK;
}

private GameInstanceManager manager;
private RepositoryDataManager repoData;
private IUser user;
private readonly GameInstanceManager manager;
private readonly RepositoryDataManager repoData;
private readonly IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(Install));
}
Expand Down
4 changes: 2 additions & 2 deletions Cmdline/Action/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
}
}

private RepositoryDataManager repoData;
private IUser user;
private readonly RepositoryDataManager repoData;
private readonly IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(List));
}
Expand Down
5 changes: 1 addition & 4 deletions Cmdline/Action/Mark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using CommandLine;
using CommandLine.Text;
using log4net;

namespace CKAN.CmdLine
{
Expand Down Expand Up @@ -120,10 +119,8 @@ private int MarkAuto(MarkAutoOptions opts, bool value, string verb, string descr
}

private GameInstanceManager manager;
private RepositoryDataManager repoData;
private readonly RepositoryDataManager repoData;
private IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(Mark));
}

internal class MarkSubOptions : VerbCommandOptions
Expand Down
2 changes: 0 additions & 2 deletions Cmdline/Action/Prompt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Text.RegularExpressions;

using CommandLine;
using CommandLine.Text;
using log4net;

namespace CKAN.CmdLine
{
Expand Down
6 changes: 3 additions & 3 deletions Cmdline/Action/Remove.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public int RunCommand(CKAN.GameInstance instance, object raw_options)
return Exit.OK;
}

private GameInstanceManager manager;
private RepositoryDataManager repoData;
private IUser user;
private readonly GameInstanceManager manager;
private readonly RepositoryDataManager repoData;
private readonly IUser user;

private static readonly ILog log = LogManager.GetLogger(typeof(Remove));
}
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Repair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public int RunSubCommand(GameInstanceManager manager, CommonOptions opts, SubCom
}

private IUser User { get; set; }
private RepositoryDataManager repoData;
private readonly RepositoryDataManager repoData;

/// <summary>
/// Try to repair our registry.
Expand Down
Loading

0 comments on commit b50dda0

Please sign in to comment.