-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathoptions.ixx
351 lines (330 loc) · 14.7 KB
/
options.ixx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
module;
#include <format>
#include <list>
#include <memory>
#include <string>
#include "throw_line.hh"
export module options;
import utils.logger;
import utils.misc;
import utils.strings;
namespace gpsxre
{
export struct Options
{
std::string arguments;
std::list<std::string> commands;
bool help;
bool version;
bool verbose;
bool auto_eject;
bool debug;
std::string image_path;
std::string image_name;
bool overwrite;
bool force_split;
bool leave_unchanged;
std::string drive;
std::unique_ptr<std::string> drive_type;
std::unique_ptr<int> drive_read_offset;
std::unique_ptr<int> drive_c2_shift;
std::unique_ptr<int> drive_pregap_start;
std::unique_ptr<std::string> drive_read_method;
std::unique_ptr<std::string> drive_sector_order;
std::unique_ptr<double> speed;
int retries;
bool refine_subchannel;
std::unique_ptr<int> lba_start;
std::unique_ptr<int> lba_end;
bool force_qtoc;
bool legacy_subs;
std::string skip;
int skip_fill;
bool iso9660_trim;
bool plextor_skip_leadin;
int plextor_leadin_retries;
bool asus_skip_leadout;
bool disable_cdtext;
bool force_cdtext_reading;
bool correct_offset_shift;
bool offset_shift_relocate;
std::unique_ptr<int> force_offset;
int audio_silence_threshold;
std::unique_ptr<int> dump_write_offset;
int dump_read_size;
bool overread_leadout;
bool force_unscrambled;
bool force_refine;
Options(int argc, const char *argv[])
: help(false)
, version(false)
, verbose(false)
, auto_eject(false)
, debug(false)
, overwrite(false)
, force_split(false)
, leave_unchanged(false)
, retries(0)
, refine_subchannel(false)
, force_qtoc(false)
, legacy_subs(false)
, skip_fill(0x55)
, iso9660_trim(false)
, plextor_skip_leadin(false)
, plextor_leadin_retries(4)
, asus_skip_leadout(false)
, disable_cdtext(false)
, force_cdtext_reading(false)
, correct_offset_shift(false)
, offset_shift_relocate(false)
, audio_silence_threshold(32)
, dump_read_size(32)
, overread_leadout(false)
, force_unscrambled(false)
, force_refine(false)
{
for(int i = 1; i < argc; ++i)
arguments += str_quoted_if_space(argv[i]) + " ";
if(!arguments.empty())
arguments.pop_back();
std::string *s_value = nullptr;
int *i_value = nullptr;
double *d_value = nullptr;
for(int i = 1; i < argc; ++i)
{
std::string o(argv[i]);
// option
if(o[0] == '-')
{
std::string key;
auto value_pos = o.find("=");
if(value_pos == std::string::npos)
{
key = o;
o.clear();
}
else
{
key = std::string(o, 0, value_pos);
o = std::string(o, value_pos + 1);
}
if(s_value == nullptr && i_value == nullptr)
{
if(key == "--help" || key == "-h")
help = true;
else if(key == "--version")
version = true;
else if(key == "--verbose")
verbose = true;
else if(key == "--auto-eject")
auto_eject = true;
else if(key == "--debug")
debug = true;
else if(key == "--image-path")
s_value = &image_path;
else if(key == "--image-name")
s_value = &image_name;
else if(key == "--overwrite")
overwrite = true;
else if(key == "--force-split")
force_split = true;
else if(key == "--leave-unchanged")
leave_unchanged = true;
else if(key == "--drive")
s_value = &drive;
else if(key == "--drive-type")
{
drive_type = std::make_unique<std::string>();
s_value = drive_type.get();
}
else if(key == "--drive-read-offset")
{
drive_read_offset = std::make_unique<int>();
i_value = drive_read_offset.get();
}
else if(key == "--drive-c2-shift")
{
drive_c2_shift = std::make_unique<int>();
i_value = drive_c2_shift.get();
}
else if(key == "--drive-pregap-start")
{
drive_pregap_start = std::make_unique<int>();
i_value = drive_pregap_start.get();
}
else if(key == "--drive-read-method")
{
drive_read_method = std::make_unique<std::string>();
s_value = drive_read_method.get();
}
else if(key == "--drive-sector-order")
{
drive_sector_order = std::make_unique<std::string>();
s_value = drive_sector_order.get();
}
else if(key == "--speed")
{
speed = std::make_unique<double>();
d_value = speed.get();
}
else if(key == "--retries")
i_value = &retries;
else if(key == "--refine-subchannel")
refine_subchannel = true;
else if(key == "--lba-start")
{
lba_start = std::make_unique<int>();
i_value = lba_start.get();
}
else if(key == "--lba-end")
{
lba_end = std::make_unique<int>();
i_value = lba_end.get();
}
else if(key == "--force-qtoc")
force_qtoc = true;
else if(key == "--legacy-subs")
legacy_subs = true;
else if(key == "--skip")
s_value = &skip;
else if(key == "--skip-fill")
i_value = &skip_fill;
else if(key == "--iso9660-trim")
iso9660_trim = true;
else if(key == "--plextor-skip-leadin")
plextor_skip_leadin = true;
else if(key == "--plextor-leadin-retries")
i_value = &plextor_leadin_retries;
else if(key == "--asus-skip-leadout")
asus_skip_leadout = true;
else if(key == "--disable-cdtext")
disable_cdtext = true;
else if(key == "--force-cdtext-reading")
force_cdtext_reading = true;
else if(key == "--correct-offset-shift")
correct_offset_shift = true;
else if(key == "--offset-shift-relocate")
offset_shift_relocate = true;
else if(key == "--force-offset")
{
force_offset = std::make_unique<int>();
i_value = force_offset.get();
}
else if(key == "--audio-silence-threshold")
i_value = &audio_silence_threshold;
else if(key == "--dump-write-offset")
{
dump_write_offset = std::make_unique<int>();
i_value = dump_write_offset.get();
}
else if(key == "--dump-read-size")
i_value = &dump_read_size;
else if(key == "--overread-leadout")
overread_leadout = true;
else if(key == "--force-unscrambled")
force_unscrambled = true;
else if(key == "--force-refine")
force_refine = true;
// unknown option
else
{
throw_line("unknown option ({})", key);
}
}
else
throw_line("option value expected ({})", argv[i - 1]);
}
if(!o.empty())
{
if(s_value != nullptr)
{
*s_value = o;
s_value = nullptr;
}
else if(i_value != nullptr)
{
*i_value = str_to_int(o);
i_value = nullptr;
}
else if(d_value != nullptr)
{
*d_value = str_to_double(o);
d_value = nullptr;
}
else
commands.emplace_back(o);
}
}
}
void printUsage()
{
LOG("usage: redumper [command] [options]");
LOG("");
LOG("COMMANDS:");
LOG("\t<empty> \tor cd/sacd/dvd/bd, aggregate mode that does everything (default)");
LOG("\tdump \tdumps disc to primary dump files");
LOG("\trefine \trefines dump files by re-reading the disc");
LOG("\tverify \tverifies dump files from the disc and marks any mismatch in state for the subsequent refine");
LOG("\tdvdkey \textracts DVD CSS keys from the disc or cracks title keys on region mismatch");
LOG("\tdvdisokey \tcracks DVD CSS keys directly from iso dump, no drive required");
LOG("\tprotection\tscans dump files for protections");
LOG("\tsplit \tgenerates BIN/CUE track split from dump files");
LOG("\thash \toutputs XML DAT hash entries (CUE/BIN or ISO)");
LOG("\tinfo \toutputs basic image information (CUE/BIN or ISO)");
LOG("\tskeleton \tgenerates image file with zeroed content");
LOG("");
LOG("OPTIONS:");
LOG("\t(general)");
LOG("\t--help,-h \tprint usage");
LOG("\t--version \tprint version");
LOG("\t--verbose \tverbose output");
LOG("\t--auto-eject \tauto eject after dump");
LOG("\t--drive=VALUE \tdrive to use, first available drive with disc, if not provided");
LOG("\t--speed=VALUE \tdrive read speed, optimal drive speed will be used if not provided");
LOG("\t--retries=VALUE \tnumber of sector retries in case of SCSI/C2 error (default: {})", retries);
LOG("\t--image-path=VALUE \tdump files base directory");
LOG("\t--image-name=VALUE \tdump files prefix, autogenerated in dump mode if not provided");
LOG("\t--overwrite \toverwrites previously generated dump files");
LOG("");
LOG("\t(drive configuration)");
LOG("\t--drive-type=VALUE \toverride drive type, possible values: GENERIC, PLEXTOR, LG_ASU2, LG_ASU3, LG_ASU8A, LG_ASU8B, LG_ASU8C");
LOG("\t--drive-read-offset=VALUE \toverride drive read offset");
LOG("\t--drive-c2-shift=VALUE \toverride drive C2 shift");
LOG("\t--drive-pregap-start=VALUE \toverride drive pre-gap start LBA");
LOG("\t--drive-read-method=VALUE \toverride drive read method, possible values: BE, D8, BE_CDDA");
LOG("\t--drive-sector-order=VALUE \toverride drive sector order, possible values: DATA_C2_SUB, DATA_SUB_C2, DATA_SUB, DATA_C2");
LOG("");
LOG("\t(drive specific)");
LOG("\t--plextor-skip-leadin \tskip dumping lead-in using negative range");
LOG("\t--plextor-leadin-retries=VALUE \tmaximum number of lead-in retries per session (default: {})", plextor_leadin_retries);
LOG("\t--asus-skip-leadout \tskip extracting lead-out from drive cache");
LOG("\t--disable-cdtext \tdisable CD-TEXT reading");
LOG("\t--force-cdtext-reading \tforce multisession CD-TEXT reading for all drives");
LOG("");
LOG("\t(offset)");
LOG("\t--force-offset=VALUE \toverride offset autodetection and use supplied value");
LOG("\t--audio-silence-threshold=VALUE\tmaximum absolute sample value to treat it as silence (default: {})", audio_silence_threshold);
LOG("\t--correct-offset-shift \tcorrect disc write offset shift");
LOG("\t--offset-shift-relocate \tdon't merge offset groups with non-matching LBA");
LOG("");
LOG("\t(split)");
LOG("\t--force-split \tforce track split with errors");
LOG("\t--leave-unchanged \tdon't replace erroneous sectors with generated ones");
LOG("\t--force-qtoc \tforce QTOC based track split");
LOG("\t--legacy-subs \treplicate DIC style subchannel based track split");
LOG("\t--skip-fill=VALUE \tfill byte value for skipped sectors (default: 0x{:02X})", skip_fill);
LOG("\t--iso9660-trim \ttrim each ISO9660 data track to PVD volume size, useful for discs with fake TOC");
LOG("");
LOG("\t(miscellaneous)");
LOG("\t--lba-start=VALUE \tLBA to start dumping from");
LOG("\t--lba-end=VALUE \tLBA to stop dumping at (everything before the value), useful for discs with fake TOC");
LOG("\t--refine-subchannel \tin addition to SCSI/C2, refine subchannel");
LOG("\t--skip=VALUE \tLBA ranges of sectors to skip");
LOG("\t--dump-write-offset=VALUE \toffset hint for data sectors read using BE method");
LOG("\t--dump-read-size=VALUE \tnumber of sectors to read at once on initial dump, DVD only (default: {})", dump_read_size);
LOG("\t--overread-leadout \tdo not limit lead-out to the first hundred sectors, read until drive returns SCSI error");
LOG("\t--force-unscrambled \tdo not attempt to read data sectors as audio (BE read method only)");
LOG("\t--force-refine \tdo not check TOC when refining a disc");
}
};
}