-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slapping together some test code to see if prefill can detect corrupt…
… chunks
- Loading branch information
Showing
12 changed files
with
254 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// ReSharper disable MemberCanBePrivate.Global - Properties used as parameters can't be private with CliFx, otherwise they won't work. | ||
namespace SteamPrefill.CliCommands | ||
{ | ||
//TODO description | ||
//TODO write documentation | ||
//TODO split up internal logic so that the prefill and validation logic don't overlap too much | ||
[UsedImplicitly] | ||
[Command("validate", Description = "TODO")] | ||
public class ValidateCommand : ICommand | ||
{ | ||
[CommandOption("all", Description = "Validates all currently owned games", Converter = typeof(NullableBoolConverter))] | ||
public bool? DownloadAllOwnedGames { get; init; } | ||
|
||
|
||
[CommandOption("force", 'f', | ||
Description = "Forces the validation to always run, overrides the default behavior of only validating if a newer version is available.", | ||
Converter = typeof(NullableBoolConverter))] | ||
public bool? Force { get; init; } | ||
|
||
[CommandOption("os", Description = "Specifies which operating system(s) games should be downloaded for. Can be windows/linux/macos", | ||
Converter = typeof(OperatingSystemConverter), Validators = new[] { typeof(OperatingSystemValidator) })] | ||
public IReadOnlyList<OperatingSystem> OperatingSystems { get; init; } = new List<OperatingSystem> { OperatingSystem.Windows }; | ||
|
||
[CommandOption("verbose", Description = "Produces more detailed log output. Will output logs for games are already up to date.", Converter = typeof(NullableBoolConverter))] | ||
public bool? Verbose | ||
{ | ||
get => AppConfig.VerboseLogs; | ||
init => AppConfig.VerboseLogs = value ?? default(bool); | ||
} | ||
|
||
[CommandOption("unit", | ||
Description = "Specifies which unit to use to display download speed. Can be either bits/bytes.", | ||
Converter = typeof(TransferSpeedUnitConverter))] | ||
public TransferSpeedUnit TransferSpeedUnit { get; init; } = TransferSpeedUnit.Bits; | ||
|
||
[CommandOption("no-ansi", | ||
Description = "Application output will be in plain text. " + | ||
"Should only be used if terminal does not support Ansi Escape sequences, or when redirecting output to a file.", | ||
Converter = typeof(NullableBoolConverter))] | ||
public bool? NoAnsiEscapeSequences { get; init; } | ||
|
||
private IAnsiConsole _ansiConsole; | ||
|
||
public async ValueTask ExecuteAsync(IConsole console) | ||
{ | ||
_ansiConsole = console.CreateAnsiConsole(); | ||
// Property must be set to false in order to disable ansi escape sequences | ||
_ansiConsole.Profile.Capabilities.Ansi = !NoAnsiEscapeSequences ?? true; | ||
|
||
await UpdateChecker.CheckForUpdatesAsync(typeof(Program), "tpill90/steam-lancache-prefill", AppConfig.CacheDir); | ||
|
||
var downloadArgs = new DownloadArguments | ||
{ | ||
Force = Force ?? default(bool), | ||
NoCache = default(bool), | ||
TransferSpeedUnit = TransferSpeedUnit, | ||
OperatingSystems = OperatingSystems.ToList() | ||
}; | ||
|
||
using var steamManager = new SteamManager(_ansiConsole, downloadArgs); | ||
ValidateUserHasSelectedApps(steamManager); | ||
|
||
try | ||
{ | ||
await steamManager.InitializeAsync(); | ||
await steamManager.DownloadMultipleAppsAsync(DownloadAllOwnedGames ?? default(bool), default(bool), 0); | ||
} | ||
finally | ||
{ | ||
steamManager.Shutdown(); | ||
} | ||
} | ||
|
||
// Validates that the user has selected at least 1 app | ||
private void ValidateUserHasSelectedApps(SteamManager steamManager) | ||
{ | ||
var userSelectedApps = steamManager.LoadPreviouslySelectedApps(); | ||
|
||
if ((DownloadAllOwnedGames ?? default(bool)) || userSelectedApps.Any()) | ||
{ | ||
return; | ||
} | ||
|
||
_ansiConsole.MarkupLine(Red("No apps have been selected for prefill! At least 1 app is required!")); | ||
_ansiConsole.MarkupLine(Red($"Use the {Cyan("select-apps")} command to interactively choose which apps to prefill. ")); | ||
_ansiConsole.MarkupLine(""); | ||
_ansiConsole.Markup(Red($"Alternatively, the flag {LightYellow("--all")} can be specified to prefill all owned apps")); | ||
throw new CommandException(".", 1, true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
SteamPrefill/Models/Exceptions/ChunkChecksumFailedException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace SteamPrefill.Models.Exceptions | ||
{ | ||
public class ChunkChecksumFailedException : Exception | ||
{ | ||
public ChunkChecksumFailedException(string message) : base(message) | ||
{ | ||
} | ||
|
||
public ChunkChecksumFailedException(string message, Exception innerException) : base(message, innerException) | ||
{ | ||
} | ||
|
||
public ChunkChecksumFailedException() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.