|
| 1 | +using System; |
| 2 | +using System.Threading.Tasks; |
| 3 | + |
| 4 | +namespace RedumpTool.Features |
| 5 | +{ |
| 6 | + internal sealed class StatsFeature : BaseFeature |
| 7 | + { |
| 8 | + #region Feature Definition |
| 9 | + |
| 10 | + public const string DisplayName = "stats"; |
| 11 | + |
| 12 | + private static readonly string[] _flags = ["stats"]; |
| 13 | + |
| 14 | + private const string _description = "Download the statistics page"; |
| 15 | + |
| 16 | + #endregion |
| 17 | + |
| 18 | + public StatsFeature() |
| 19 | + : base(DisplayName, _flags, _description) |
| 20 | + { |
| 21 | + RequiresInputs = false; |
| 22 | + |
| 23 | + // Common |
| 24 | + Add(DebugInput); |
| 25 | + Add(OutputInput); |
| 26 | + Add(UsernameInput); |
| 27 | + Add(PasswordInput); |
| 28 | + Add(AttemptCountInput); |
| 29 | + Add(TimeoutInput); |
| 30 | + Add(ForceDownloadInput); |
| 31 | + Add(ForceContinueInput); |
| 32 | + } |
| 33 | + |
| 34 | + /// <inheritdoc/> |
| 35 | + public override bool Execute() |
| 36 | + { |
| 37 | + // Get common values |
| 38 | + string? outDir = OutputInput.Value; |
| 39 | + string? username = UsernameInput.Value; |
| 40 | + string? password = PasswordInput.Value; |
| 41 | + int? attemptCount = AttemptCountInput.Value; |
| 42 | + int? timeout = TimeoutInput.Value; |
| 43 | + bool forceDownload = ForceDownloadInput.Value; |
| 44 | + bool forceContinue = ForceContinueInput.Value; |
| 45 | + |
| 46 | + // Output directory validation |
| 47 | + if (!ValidateAndCreateOutputDirectory(outDir)) |
| 48 | + return false; |
| 49 | + |
| 50 | + // Update client properties |
| 51 | + _client.Debug = DebugInput.Value; |
| 52 | + if (attemptCount != null && attemptCount > 0) |
| 53 | + _client.AttemptCount = attemptCount.Value; |
| 54 | + if (timeout != null && timeout > 0) |
| 55 | + _client.Timeout = TimeSpan.FromSeconds(timeout.Value); |
| 56 | + _client.Overwrite = forceDownload; |
| 57 | + _client.IgnoreErrors = forceContinue; |
| 58 | + |
| 59 | + // Login to Redump, if necessary |
| 60 | + _client.Login(username, password).Wait(); |
| 61 | + |
| 62 | + // Start the processing |
| 63 | + Task<bool> processingTask = _client.DownloadStatisticsPage(outDir); |
| 64 | + |
| 65 | + // Retrieve the result |
| 66 | + processingTask.Wait(); |
| 67 | + return processingTask.Result; |
| 68 | + } |
| 69 | + |
| 70 | + /// <inheritdoc/> |
| 71 | + public override bool VerifyInputs() => true; |
| 72 | + } |
| 73 | +} |
0 commit comments