Skip to content

Commit

Permalink
Adding progress to Status command.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpill90 committed Feb 13, 2024
1 parent 18b6de4 commit a8e2d6e
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 85 deletions.
4 changes: 0 additions & 4 deletions SteamPrefill/CliCommands/Benchmark/BenchmarkModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ public BenchmarkWorkload(ConcurrentBag<AppQueuedRequests> queuedAppsList, Concur

public void PrintSummary(IAnsiConsole ansiConsole)
{
// White spacing + a horizontal rule to delineate that the command has completed
ansiConsole.WriteLine();
ansiConsole.Write(new Rule());

// Setting up final formatting, to make sure padding and alignment is correct
var grid = new Grid()
.AddColumn(new GridColumn())
Expand Down
53 changes: 33 additions & 20 deletions SteamPrefill/CliCommands/Converters.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace SteamPrefill.CliCommands
{
//TODO these need to have better documentation overall. There are multiple "types" of these converters and validators, and they all cover different scenarios
//TODO go through all of these converters/validators and make sure their output messages are consistent between them all
#region Operating system

/// <summary>
/// Used to validate when an option flag has been specified, but no operating systems were specified.
/// Ex. --os , should throw the validation error.
Expand All @@ -26,6 +30,7 @@ public sealed class OperatingSystemConverter : BindingConverter<OperatingSystem>
{
public override OperatingSystem Convert(string rawValue)
{
//TODO case insensitive
if (!OperatingSystem.TryFromValue(rawValue, out var _))
{
AnsiConsole.MarkupLine(Red($"{White(rawValue)} is not a valid operating system!"));
Expand All @@ -36,6 +41,8 @@ public override OperatingSystem Convert(string rawValue)
}
}

#endregion

public sealed class ConcurrencyValidator : BindingValidator<uint>
{
public override BindingValidationError Validate(uint value)
Expand Down Expand Up @@ -71,6 +78,7 @@ public sealed class PresetWorkloadConverter : BindingConverter<PresetWorkload>
{
public override PresetWorkload Convert(string rawValue)
{
//TODO case insensitive
if (!PresetWorkload.TryFromName(rawValue, out var _))
{
AnsiConsole.MarkupLine(Red($"{White(rawValue)} is not a valid preset"));
Expand All @@ -81,24 +89,21 @@ public override PresetWorkload Convert(string rawValue)
}
}

public sealed class SortOrderValidator : BindingValidator<SortOrder>
#region Status command validators

public sealed class SortOrderConverter : BindingConverter<SortOrder>
{
public override BindingValidationError Validate(SortOrder value)
public override SortOrder Convert(string rawValue)
{
if (value == null)
// This will throw an error if a user specifies '--sort-order' but does not provide a value.
if (rawValue == null)
{
AnsiConsole.MarkupLine(Red($"A sort order must be specified when using {LightYellow("--sort-order")}"));
AnsiConsole.MarkupLine(Red($"A sort order must be provided when using {LightYellow("--sort-order")}"));
AnsiConsole.Markup(Red($"Valid sort orders include : {LightYellow("ascending/descending")}"));
throw new CommandException(".", 1, true);
}
return Ok();
}
}

public sealed class SortOrderConverter : BindingConverter<SortOrder>
{
public override SortOrder Convert(string rawValue)
{
rawValue = rawValue.ToLower();
if (!SortOrder.TryFromValue(rawValue, out var _))
{
AnsiConsole.MarkupLine(Red($"{White(rawValue)} is not a valid sort order!"));
Expand All @@ -109,20 +114,28 @@ public override SortOrder Convert(string rawValue)
}
}

public sealed class SortColumnValidator : BindingValidator<string>
public sealed class SortColumnConverter : BindingConverter<SortColumn>
{
public override BindingValidationError Validate(string value)
public override SortColumn Convert(string rawValue)
{
if (string.IsNullOrEmpty(value)
&& (!value.Equals("app", StringComparison.OrdinalIgnoreCase)
|| !value.Equals("size", StringComparison.OrdinalIgnoreCase)))
// This will throw an error if a user specifies '--sort-by' but does not provide a value.
if (rawValue == null)
{
AnsiConsole.MarkupLine($"Test: {value}");
AnsiConsole.MarkupLine(Red($"A sort column must be specified when using {LightYellow("--sort-column")}"));
AnsiConsole.Markup(Red($"Valid sort orders include : {LightYellow("app/size")}"));
AnsiConsole.MarkupLine(Red($"A value must be provided when using {LightYellow("--sort-by")}"));
AnsiConsole.Markup(Red($"Valid options include : {LightYellow("app/size")}"));
throw new CommandException(".", 1, true);
}
return Ok();

rawValue = rawValue.ToLower();
if (!SortColumn.TryFromValue(rawValue, out var _))
{
AnsiConsole.MarkupLine(Red($"{White(0)} is not a valid value for {LightYellow("--sort-by")}"));
AnsiConsole.Markup(Red($"Valid options include : {LightYellow("app/size")}"));
throw new CommandException(".", 1, true);
}
return SortColumn.FromValue(rawValue);
}
}

#endregion
}
30 changes: 15 additions & 15 deletions SteamPrefill/CliCommands/StatusCommand.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

namespace SteamPrefill.CliCommands
{
[UsedImplicitly]
[Command("status", Description = "List all currently selected apps and the used disk space.")]
[Command("status", Description = "Lists all currently selected apps and their download sizes.")]
public class StatusCommand : ICommand
{
[CommandOption("no-ansi",
Expand All @@ -16,12 +15,12 @@ public class StatusCommand : ICommand
public IReadOnlyList<OperatingSystem> OperatingSystems { get; init; } = new List<OperatingSystem> { OperatingSystem.Windows };

[CommandOption("sort-order", Description = "Specifies in which way the data should be sorted. Can be ascending/descending",
Converter = typeof(SortOrderConverter), Validators = new[] { typeof(SortOrderValidator) })]
Converter = typeof(SortOrderConverter))]
public SortOrder SortOrder { get; init; } = SortOrder.Ascending;

[CommandOption("sort-column", Description = "Specifies by which column the data should be sorted. Can be app/size",
Validators = new[] { typeof(SortColumnValidator) })]
public string SortColumn { get; init; } = "app";
[CommandOption("sort-by", Description = "Specifies by which column the data should be sorted. Can be app/size",
Converter = typeof(SortColumnConverter))]
public SortColumn SortBy { get; init; } = SortColumn.App;

private IAnsiConsole _ansiConsole;

Expand All @@ -43,7 +42,7 @@ public async ValueTask ExecuteAsync(IConsole console)
try
{
await steamManager.InitializeAsync();
await steamManager.CurrentlyDownloadedAsync(SortOrder, SortColumn);
await steamManager.PrintSelectedAppsStatsAsync(SortOrder, SortBy);
}
finally
{
Expand All @@ -54,16 +53,17 @@ public async ValueTask ExecuteAsync(IConsole console)
// Validates that the user has selected at least 1 app
private void ValidateUserHasSelectedApps(SteamManager steamManager)
{
var userSelectedApps = steamManager.LoadPreviouslySelectedApps();

if (!userSelectedApps.Any())
var userHasSelectedApps = steamManager.LoadPreviouslySelectedApps().Any();
if (userHasSelectedApps)
{
// User hasn't selected any apps yet
_ansiConsole.MarkupLine(Red("No apps have been selected for benchmark! At least 1 app is required!"));
_ansiConsole.Markup(Red($"See flags {LightYellow("--appid")}, {LightYellow("--all")} and {LightYellow("--use-selected")} to interactively choose which apps to prefill"));

throw new CommandException(".", 1, true);
return;
}

// User hasn't selected any apps yet
_ansiConsole.MarkupLine(Red("No apps have been selected! At least 1 app is required!"));
_ansiConsole.Markup(Red($"Use the {Cyan("select-apps")} command to interactively choose apps"));

throw new CommandException(".", 1, true);
}
}
}
2 changes: 2 additions & 0 deletions SteamPrefill/Handlers/AppInfoHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ public virtual async Task<AppInfo> GetAppInfoAsync(uint appId)
return userOwnedGames.Where(e => e.playtime_2weeks > 0).ToList();
}

//TODO is this necessary because --all includes things that shouldn't be downloaded?
/// <summary>
/// Gets a list of available games, filtering out any unavailable, non-Windows games.
/// </summary>
public async Task<List<AppInfo>> GetAvailableGamesByIdAsync(List<uint> appIds)
{
//TODO maybe a call to retreive app metadata async here so that you don't need to remember to do it manually
var appInfos = new List<AppInfo>();
foreach (var appId in appIds)
{
Expand Down
1 change: 1 addition & 0 deletions SteamPrefill/Handlers/DepotHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public async Task<List<DepotInfo>> FilterDepotsToDownloadAsync(DownloadArguments
}

//TODO comment
//TODO I don't like the fact that this has to be manually called in order to have things work correctly
public async Task BuildLinkedDepotInfoAsync(List<DepotInfo> depots)
{
foreach (var depotInfo in depots.Where(e => e.ManifestId == null))
Expand Down
7 changes: 7 additions & 0 deletions SteamPrefill/Models/Enums/SortOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ public sealed partial class SortOrder
public static readonly SortOrder Ascending = new("ascending");
public static readonly SortOrder Descending = new("descending");
}

[Intellenum(typeof(string))]
public sealed partial class SortColumn
{
public static readonly SortColumn App = new("app");
public static readonly SortColumn Size = new("size");
}
}
3 changes: 2 additions & 1 deletion SteamPrefill/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ private static List<string> ParseHiddenFlags()

// Skips using locally cached manifests. Saves disk space, at the expense of slower subsequent runs.
// Useful for debugging since the manifests will always be re-downloaded.
if (args.Any(e => e.Contains("--nocache")))
if (args.Any(e => e.Contains("--nocache")) || args.Any(e => e.Contains("--no-cache")))
{
AnsiConsole.Console.LogMarkupLine($"Using {LightYellow("--nocache")} flag. Will always re-download manifests...");
AppConfig.NoLocalCache = true;
args.Remove("--nocache");
args.Remove("--no-cache");
}

// Adding some formatting to logging to make it more readable + clear that these flags are enabled
Expand Down
6 changes: 5 additions & 1 deletion SteamPrefill/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"Clear cache": {
"commandName": "Project",
"commandLineArgs": "clear-cache"
}
},
"Stats": {
"commandName": "Project",
"commandLineArgs": "status --nocache"
}
}
}
Loading

0 comments on commit a8e2d6e

Please sign in to comment.