Skip to content

Commit d5ccc0c

Browse files
committed
Simplify downloader creation
1 parent 0ef9c6f commit d5ccc0c

File tree

1 file changed

+25
-48
lines changed

1 file changed

+25
-48
lines changed

RedumpTool/Program.cs

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,8 @@ private static Feature DeriveFeature(string feature)
8080
/// <returns>Initialized Downloader on success, null otherwise</returns>
8181
private static Downloader? CreateDownloader(Feature feature, string[] args)
8282
{
83-
// Set temporary internal variables
84-
string? outDir = null;
85-
string? username = null;
86-
string? password = null;
87-
int minimumId = -1;
88-
int maximumId = -1;
89-
string? queryString = null;
90-
bool useSubfolders = false;
91-
bool onlyNew = false;
92-
bool onlyList = false;
93-
bool noSlash = false;
94-
bool force = false;
95-
96-
// Now loop through all of the arguments
83+
// Loop through all of the arguments
84+
var downloader = new Downloader();
9785
try
9886
{
9987
for (int i = 1; i < args.Length; i++)
@@ -103,69 +91,73 @@ private static Feature DeriveFeature(string feature)
10391
// Output directory
10492
case "-o":
10593
case "--output":
106-
outDir = args[++i].Trim('"');
94+
downloader.OutDir = args[++i].Trim('"');
10795
break;
10896

10997
// Username
11098
case "-u":
11199
case "--username":
112-
username = args[++i];
100+
downloader.Username = args[++i];
113101
break;
114102

115103
// Password
116104
case "-p":
117105
case "--password":
118-
password = args[++i];
106+
downloader.Password = args[++i];
119107
break;
120108

121109
// Minimum Redump ID
122110
case "-min":
123111
case "--minimum":
124-
if (!int.TryParse(args[++i], out minimumId))
112+
if (!int.TryParse(args[++i], out int minimumId))
125113
minimumId = -1;
114+
115+
downloader.MinimumId = minimumId;
126116
break;
127117

128118
// Maximum Redump ID
129119
case "-max":
130120
case "--maximum":
131-
if (!int.TryParse(args[++i], out maximumId))
121+
if (!int.TryParse(args[++i], out int maximumId))
132122
maximumId = -1;
123+
124+
downloader.MaximumId = maximumId;
133125
break;
134126

135127
// Quicksearch text
136128
case "-q":
137129
case "--query":
138-
queryString = args[++i];
130+
downloader.QueryString = args[++i];
139131
break;
140132

141133
// Packs subfolders
142134
case "-s":
143135
case "--subfolders":
144-
useSubfolders = true;
136+
downloader.UseSubfolders = true;
145137
break;
146138

147139
// Use last modified
148140
case "-n":
149141
case "--onlynew":
150-
onlyNew = true;
142+
downloader.OnlyNew = true;
151143
break;
152144

153145
// List instead of download
154146
case "-l":
155147
case "--list":
156-
onlyList = true;
148+
downloader.OnlyList = true;
157149
break;
158150

159151
// Don't filter forward slashes from queries
160152
case "-ns":
161153
case "--noslash":
162-
noSlash = true;
154+
downloader.NoSlash = true;
163155
break;
164156

165157
// Force continuation
166158
case "-f":
167159
case "--force":
168-
force = true;
160+
downloader.Force = true;
169161
break;
170162

171163
// Everything else
@@ -182,18 +174,18 @@ private static Feature DeriveFeature(string feature)
182174
}
183175

184176
// Output directory validation
185-
if (!onlyList && string.IsNullOrEmpty(outDir))
177+
if (!downloader.OnlyList && string.IsNullOrEmpty(downloader.OutDir))
186178
{
187179
Console.WriteLine("No output directory set!");
188180
return null;
189181
}
190-
else if (!onlyList && !string.IsNullOrEmpty(outDir))
182+
else if (!downloader.OnlyList && !string.IsNullOrEmpty(downloader.OutDir))
191183
{
192184
// Create the output directory, if it doesn't exist
193185
try
194186
{
195-
if (!Directory.Exists(outDir))
196-
Directory.CreateDirectory(outDir);
187+
if (!Directory.Exists(downloader.OutDir))
188+
Directory.CreateDirectory(downloader.OutDir!);
197189
}
198190
catch (Exception ex)
199191
{
@@ -203,40 +195,25 @@ private static Feature DeriveFeature(string feature)
203195
}
204196

205197
// Range verification
206-
if (feature == Feature.Site && !onlyNew && (minimumId < 0 || maximumId < 0))
198+
if (feature == Feature.Site && !downloader.OnlyNew && (downloader.MinimumId < 0 || downloader.MaximumId < 0))
207199
{
208200
Console.WriteLine("Please enter a valid range of Redump IDs");
209201
return null;
210202
}
211-
else if (feature == Feature.WIP && !onlyNew && (minimumId < 0 || maximumId < 0))
203+
else if (feature == Feature.WIP && !downloader.OnlyNew && (downloader.MinimumId < 0 || downloader.MaximumId < 0))
212204
{
213205
Console.WriteLine("Please enter a valid range of WIP IDs");
214206
return null;
215207
}
216208

217209
// Query verification (and cleanup)
218-
if (feature == Feature.Quicksearch && string.IsNullOrEmpty(queryString))
210+
if (feature == Feature.Quicksearch && string.IsNullOrEmpty(downloader.QueryString))
219211
{
220212
Console.WriteLine("Please enter a query for searching");
221213
return null;
222214
}
223215

224-
// Create and return the downloader
225-
var downloader = new Downloader()
226-
{
227-
Feature = feature,
228-
MinimumId = minimumId,
229-
MaximumId = maximumId,
230-
QueryString = queryString,
231-
OutDir = outDir,
232-
UseSubfolders = useSubfolders,
233-
OnlyNew = onlyNew,
234-
OnlyList = onlyList,
235-
Force = force,
236-
NoSlash = noSlash,
237-
Username = username,
238-
Password = password,
239-
};
216+
// Return the downloader
240217
return downloader;
241218
}
242219

0 commit comments

Comments
 (0)