Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle paths without DriveInfo #4300

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cmdline/Action/AuthToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public int RunSubCommand(GameInstanceManager? manager,
string[] args = unparsed.options.ToArray();
int exitCode = Exit.OK;

Parser.Default.ParseArgumentsStrict(args, new AuthTokenSubOptions(), (string option, object suboptions) =>
Parser.Default.ParseArgumentsStrict(args, new AuthTokenSubOptions(), (option, suboptions) =>
{
if (!string.IsNullOrEmpty(option) && suboptions != null)
{
Expand Down
21 changes: 15 additions & 6 deletions Cmdline/Action/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public int RunSubCommand(GameInstanceManager? mgr,

int exitCode = Exit.OK;
// Parse and process our sub-verbs
Parser.Default.ParseArgumentsStrict(args, new CacheSubOptions(), (string option, object suboptions) =>
Parser.Default.ParseArgumentsStrict(args, new CacheSubOptions(), (option, suboptions) =>
{
// ParseArgumentsStrict calls us unconditionally, even with bad arguments
if (!string.IsNullOrEmpty(option) && suboptions != null)
Expand Down Expand Up @@ -251,11 +251,20 @@ private void printCacheInfo()
{
if (manager?.Cache != null)
{
manager.Cache.GetSizeInfo(out int fileCount, out long bytes, out long bytesFree);
user?.RaiseMessage(Properties.Resources.CacheInfo,
fileCount,
CkanModule.FmtSize(bytes),
CkanModule.FmtSize(bytesFree));
manager.Cache.GetSizeInfo(out int fileCount, out long bytes, out long? bytesFree);
if (bytesFree.HasValue)
{
user?.RaiseMessage(Properties.Resources.CacheInfo,
fileCount,
CkanModule.FmtSize(bytes),
CkanModule.FmtSize(bytesFree.Value));
}
else
{
user?.RaiseMessage(Properties.Resources.CacheInfoFreeSpaceUnknown,
fileCount,
CkanModule.FmtSize(bytes));
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Compat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public int RunSubCommand(GameInstanceManager? mgr,
{
var exitCode = Exit.OK;

Parser.Default.ParseArgumentsStrict(options.options.ToArray(), new CompatSubOptions(), (string option, object suboptions) =>
Parser.Default.ParseArgumentsStrict(options.options.ToArray(), new CompatSubOptions(), (option, suboptions) =>
{
// ParseArgumentsStrict calls us unconditionally, even with bad arguments
if (!string.IsNullOrEmpty(option) && suboptions != null)
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int RunSubCommand(GameInstanceManager? mgr,
string[] args = unparsed.options.ToArray();
int exitCode = Exit.OK;
// Parse and process our sub-verbs
Parser.Default.ParseArgumentsStrict(args, new FilterSubOptions(), (string option, object suboptions) =>
Parser.Default.ParseArgumentsStrict(args, new FilterSubOptions(), (option, suboptions) =>
{
// ParseArgumentsStrict calls us unconditionally, even with bad arguments
if (!string.IsNullOrEmpty(option) && suboptions != null)
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/GameInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public int RunSubCommand(GameInstanceManager? manager,

int exitCode = Exit.OK;
// Parse and process our sub-verbs
Parser.Default.ParseArgumentsStrict(args, new InstanceSubOptions(), (string option, object suboptions) =>
Parser.Default.ParseArgumentsStrict(args, new InstanceSubOptions(), (option, suboptions) =>
{
// ParseArgumentsStrict calls us unconditionally, even with bad arguments
if (!string.IsNullOrEmpty(option) && suboptions != null)
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Mark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public int RunSubCommand(GameInstanceManager? mgr,
string[] args = unparsed.options.ToArray();
int exitCode = Exit.OK;
// Parse and process our sub-verbs
Parser.Default.ParseArgumentsStrict(args, new MarkSubOptions(), (string option, object suboptions) =>
Parser.Default.ParseArgumentsStrict(args, new MarkSubOptions(), (option, suboptions) =>
{
// ParseArgumentsStrict calls us unconditionally, even with bad arguments
if (!string.IsNullOrEmpty(option) && suboptions != null)
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Repair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public int RunSubCommand(GameInstanceManager? manager,
{
int exitCode = Exit.OK;
// Parse and process our sub-verbs
Parser.Default.ParseArgumentsStrict(unparsed.options.ToArray(), new RepairSubOptions(), (string option, object suboptions) =>
Parser.Default.ParseArgumentsStrict(unparsed.options.ToArray(), new RepairSubOptions(), (option, suboptions) =>
{
// ParseArgumentsStrict calls us unconditionally, even with bad arguments
if (!string.IsNullOrEmpty(option) && suboptions != null)
Expand Down
5 changes: 2 additions & 3 deletions Cmdline/Action/Repo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public int RunSubCommand(GameInstanceManager? manager,
int exitCode = Exit.OK;

// Parse and process our sub-verbs
Parser.Default.ParseArgumentsStrict(args, new RepoSubOptions(), (string option, object suboptions) =>
Parser.Default.ParseArgumentsStrict(args, new RepoSubOptions(), (option, suboptions) =>
{
// ParseArgumentsStrict calls us unconditionally, even with bad arguments
if (!string.IsNullOrEmpty(option) && suboptions != null)
Expand Down Expand Up @@ -200,8 +200,7 @@ private int AvailableRepositories(string? userAgent)
is RepositoryList repoList)
{
var maxNameLen = repoList.repositories
.Select(r => r.name.Length)
.Max();
.Max(r => r.name.Length);
foreach (var repository in repoList.repositories)
{
user?.RaiseMessage(" {0}: {1}",
Expand Down
2 changes: 1 addition & 1 deletion Cmdline/Action/Stability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public int RunSubCommand(GameInstanceManager? manager,
int exitCode = Exit.OK;
Parser.Default.ParseArgumentsStrict(options.options.ToArray(),
new StabilitySubOptions(),
(string option, object suboptions) =>
(option, suboptions) =>
{
// ParseArgumentsStrict calls us unconditionally, even with bad arguments
if (!string.IsNullOrEmpty(option) && suboptions != null)
Expand Down
1 change: 1 addition & 0 deletions Cmdline/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ If you must run as an administrator, the `--asroot` parameter will bypass this c
<data name="CacheResetFailed" xml:space="preserve"><value>Can't reset cache path: {0}</value></data>
<data name="CacheUnlimited" xml:space="preserve"><value>Unlimited</value></data>
<data name="CacheInfo" xml:space="preserve"><value>{0} files, {1}, {2} free</value></data>
<data name="CacheInfoFreeSpaceUnknown" xml:space="preserve"><value>{0} files, {1}, free space unknown</value></data>
<data name="CompareSame" xml:space="preserve"><value>"{0}" and "{1}" are the same versions.</value></data>
<data name="CompareLower" xml:space="preserve"><value>"{0}" is lower than "{1}".</value></data>
<data name="CompareHigher" xml:space="preserve"><value>"{0}" is higher than "{1}".</value></data>
Expand Down
5 changes: 3 additions & 2 deletions ConsoleUI/AuthTokenAddDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public AuthTokenAddDialog(ConsoleTheme theme) : base(theme)
AddObject(tokenEntry);

AddTip(Properties.Resources.Esc, Properties.Resources.Cancel);
AddBinding(Keys.Escape, (object sender) => false);
AddBinding(Keys.Escape, sender => false);

AddTip(Properties.Resources.Enter, Properties.Resources.Accept, validKey);
AddBinding(Keys.Enter, (object sender) => {
AddBinding(Keys.Enter, sender =>
{
if (validKey()) {
ServiceLocator.Container.Resolve<IConfiguration>().SetAuthToken(hostEntry.Value, tokenEntry.Value);
return false;
Expand Down
12 changes: 7 additions & 5 deletions ConsoleUI/AuthTokenListScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public AuthTokenScreen(ConsoleTheme theme) : base(theme)
new List<ConsoleListBoxColumn<string>>() {
new ConsoleListBoxColumn<string>(
Properties.Resources.AuthTokenListHostHeader,
(string s) => s, null, 20),
s => s, null, 20),
new ConsoleListBoxColumn<string>(
Properties.Resources.AuthTokenListTokenHeader,
(string s) => {
s => {
return ServiceLocator.Container.Resolve<IConfiguration>().TryGetAuthToken(s, out string? token)
? token
: Properties.Resources.AuthTokenListMissingToken;
Expand All @@ -57,10 +57,11 @@ public AuthTokenScreen(ConsoleTheme theme) : base(theme)
));

AddTip(Properties.Resources.Esc, Properties.Resources.Back);
AddBinding(Keys.Escape, (object sender) => false);
AddBinding(Keys.Escape, sender => false);

tokenList.AddTip("A", Properties.Resources.Add);
tokenList.AddBinding(Keys.A, (object sender) => {
tokenList.AddBinding(Keys.A, sender =>
{
var ad = new AuthTokenAddDialog(theme);
ad.Run();
DrawBackground();
Expand All @@ -69,7 +70,8 @@ public AuthTokenScreen(ConsoleTheme theme) : base(theme)
});

tokenList.AddTip("R", Properties.Resources.Remove, () => tokenList.Selection != null);
tokenList.AddBinding(Keys.R, (object sender) => {
tokenList.AddBinding(Keys.R, sender =>
{
if (tokenList.Selection != null) {
ServiceLocator.Container.Resolve<IConfiguration>().SetAuthToken(tokenList.Selection, null);
tokenList.SetData(new List<string>(ServiceLocator.Container.Resolve<IConfiguration>().GetAuthTokenHosts()));
Expand Down
9 changes: 6 additions & 3 deletions ConsoleUI/CompatibleVersionDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public CompatibleVersionDialog(ConsoleTheme theme, IGame game) : base(theme)
);
AddObject(choices);
choices.AddTip(Properties.Resources.Enter, Properties.Resources.CompatibleVersionsListAcceptTip);
choices.AddBinding(Keys.Enter, (object sender) => {
choices.AddBinding(Keys.Enter, sender =>
{
choice = choices.Selection;
return false;
});
Expand All @@ -51,7 +52,8 @@ public CompatibleVersionDialog(ConsoleTheme theme, IGame game) : base(theme)
};
AddObject(manualEntry);
manualEntry.AddTip(Properties.Resources.Enter, Properties.Resources.CompatibleVersionsEntryAcceptTip, () => GameVersion.TryParse(manualEntry.Value, out choice));
manualEntry.AddBinding(Keys.Enter, (object sender) => {
manualEntry.AddBinding(Keys.Enter, sender =>
{
if (GameVersion.TryParse(manualEntry.Value, out choice)) {
// Good value, done running
return false;
Expand All @@ -62,7 +64,8 @@ public CompatibleVersionDialog(ConsoleTheme theme, IGame game) : base(theme)
});

AddTip(Properties.Resources.Esc, Properties.Resources.Cancel);
AddBinding(Keys.Escape, (object StronglyTypedResourceBuilder) => {
AddBinding(Keys.Escape, StronglyTypedResourceBuilder =>
{
choice = null;
return false;
});
Expand Down
11 changes: 7 additions & 4 deletions ConsoleUI/DeleteDirectoriesScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public DeleteDirectoriesScreen(ConsoleTheme theme,
directories.AddTip("D", Properties.Resources.DeleteDirectoriesDeleteDirTip,
() => directories.Selection is not null
&& !toDelete.Contains(directories.Selection));
directories.AddBinding(Keys.D, (object sender) => {
directories.AddBinding(Keys.D, sender =>
{
if (directories.Selection is not null)
{
toDelete.Add(directories.Selection);
Expand All @@ -61,7 +62,8 @@ public DeleteDirectoriesScreen(ConsoleTheme theme,
directories.AddTip("K", Properties.Resources.DeleteDirectoriesKeepDirTip,
() => directories.Selection is not null
&& toDelete.Contains(directories.Selection));
directories.AddBinding(Keys.K, (object sender) => {
directories.AddBinding(Keys.K, sender =>
{
if (directories.Selection is not null)
{
toDelete.Remove(directories.Selection);
Expand Down Expand Up @@ -90,10 +92,11 @@ public DeleteDirectoriesScreen(ConsoleTheme theme,
Properties.Resources.DeleteDirectoriesCancelTip);
AddBinding(Keys.Escape,
// Discard changes
(object sender) => false);
sender => false);

AddTip("F9", Properties.Resources.DeleteDirectoriesApplyTip);
AddBinding(Keys.F9, (object sender) => {
AddBinding(Keys.F9, sender =>
{
foreach (var d in toDelete) {
try {
Directory.Delete(d, true);
Expand Down
24 changes: 15 additions & 9 deletions ConsoleUI/DependencyScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,25 @@ public DependencyScreen(ConsoleTheme theme,
new List<ConsoleListBoxColumn<Dependency>>() {
new ConsoleListBoxColumn<Dependency>(
Properties.Resources.RecommendationsInstallHeader,
(Dependency d) => StatusSymbol(d.module),
d => StatusSymbol(d.module),
null,
7),
new ConsoleListBoxColumn<Dependency>(
Properties.Resources.RecommendationsNameHeader,
(Dependency d) => d.module.ToString(),
d => d.module.ToString(),
null,
null),
new ConsoleListBoxColumn<Dependency>(
Properties.Resources.RecommendationsSourcesHeader,
(Dependency d) => string.Join(", ", d.dependents),
d => string.Join(", ", d.dependents),
null,
42)
},
1, 0, ListSortDirection.Descending
);
dependencyList.AddTip("+", Properties.Resources.Toggle);
dependencyList.AddBinding(Keys.Plus, (object sender) => {
dependencyList.AddBinding(Keys.Plus, sender =>
{
if (dependencyList.Selection?.module is CkanModule mod
&& (accepted.Contains(mod) || TryWithoutConflicts(accepted.Append(mod)))) {
ChangePlan.toggleContains(accepted, mod);
Expand All @@ -88,7 +89,8 @@ public DependencyScreen(ConsoleTheme theme,
});

dependencyList.AddTip($"{Properties.Resources.Ctrl}+A", Properties.Resources.SelectAll);
dependencyList.AddBinding(Keys.CtrlA, (object sender) => {
dependencyList.AddBinding(Keys.CtrlA, sender =>
{
if (TryWithoutConflicts(dependencies.Keys)) {
foreach (var kvp in dependencies) {
if (!accepted.Contains(kvp.Key)) {
Expand All @@ -100,13 +102,15 @@ public DependencyScreen(ConsoleTheme theme,
});

dependencyList.AddTip($"{Properties.Resources.Ctrl}+D", Properties.Resources.DeselectAll, () => accepted.Count > 0);
dependencyList.AddBinding(Keys.CtrlD, (object sender) => {
dependencyList.AddBinding(Keys.CtrlD, sender =>
{
accepted.Clear();
return true;
});

dependencyList.AddTip(Properties.Resources.Enter, Properties.Resources.Details);
dependencyList.AddBinding(Keys.Enter, (object sender) => {
dependencyList.AddBinding(Keys.Enter, sender =>
{
if (dependencyList.Selection != null) {
LaunchSubScreen(new ModInfoScreen(theme, manager, instance, reg, userAgent, plan,
dependencyList.Selection.module,
Expand All @@ -119,14 +123,16 @@ public DependencyScreen(ConsoleTheme theme,
AddObject(dependencyList);

AddTip(Properties.Resources.Esc, Properties.Resources.Cancel);
AddBinding(Keys.Escape, (object sender) => {
AddBinding(Keys.Escape, sender =>
{
// Add everything to rejected
rejected.UnionWith(dependencies.Keys.Select(m => m.identifier));
return false;
});

AddTip("F9", Properties.Resources.Accept);
AddBinding(Keys.F9, (object sender) => {
AddBinding(Keys.F9, sender =>
{
if (TryWithoutConflicts(accepted)) {
plan.Install.UnionWith(accepted);
// Add the rest to rejected
Expand Down
2 changes: 1 addition & 1 deletion ConsoleUI/DownloadImportDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void ImportDownloads(ConsoleTheme theme,
Properties.Resources.ImportProgressTitle,
Properties.Resources.ImportProgressMessage);
ps.Run(() => ModuleInstaller.ImportFiles(files, ps,
(CkanModule mod) => cp.Install.Add(mod),
mod => cp.Install.Add(mod),
RegistryManager.Instance(gameInst, repoData).registry,
gameInst, cache));
}
Expand Down
Loading