Skip to content

Commit 17dbf9d

Browse files
committed
Add stats feature
1 parent 54c4f0f commit 17dbf9d

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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+
}

RedumpTool/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static void Main(string[] args)
3333
case PacksFeature pf: pf.ProcessArgs(args, 1); pf.Execute(); return;
3434
case UserFeature uf: uf.ProcessArgs(args, 1); uf.Execute(); return;
3535
case QueryFeature qf: qf.ProcessArgs(args, 1); qf.Execute(); return;
36+
case StatsFeature sf: sf.ProcessArgs(args, 1); sf.Execute(); return;
3637

3738
default:
3839
Console.WriteLine($"{featureName} is not a known feature");
@@ -54,6 +55,7 @@ private static CommandSet CreateCommands()
5455
commandSet.Add(new PacksFeature());
5556
commandSet.Add(new UserFeature());
5657
commandSet.Add(new QueryFeature());
58+
commandSet.Add(new StatsFeature());
5759

5860
return commandSet;
5961
}
@@ -103,6 +105,8 @@ private static void ShowHelp()
103105
Console.WriteLine(" -ns, --noslash - Don't replace forward slashes with '-'");
104106
Console.WriteLine(" --limit - Limit number of retrieved result pages");
105107
Console.WriteLine();
108+
Console.WriteLine("stats - Download the statistics page");
109+
Console.WriteLine();
106110
Console.WriteLine("If using an ID range, both minimum and maximum are required");
107111
Console.WriteLine();
108112
}

0 commit comments

Comments
 (0)