-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathRedumper.cs
More file actions
2171 lines (1923 loc) · 89.9 KB
/
Redumper.cs
File metadata and controls
2171 lines (1923 loc) · 89.9 KB
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using SabreTools.Hashing;
using SabreTools.RedumpLib;
using SabreTools.RedumpLib.Data;
namespace MPF.Processors
{
/// <summary>
/// Represents processing Redumper outputs
/// </summary>
public sealed class Redumper : BaseProcessor
{
/// <inheritdoc/>
public Redumper(RedumpSystem? system, MediaType? type) : base(system, type) { }
#region BaseProcessor Implementations
/// <inheritdoc/>
public override void GenerateSubmissionInfo(SubmissionInfo info, string basePath, bool redumpCompat)
{
// Ensure that required sections exist
info = Builder.EnsureAllSections(info);
// Get the dumping program and version
info.DumpingInfo!.DumpingProgram ??= string.Empty;
info.DumpingInfo.DumpingProgram += $" {GetVersion($"{basePath}.log") ?? "Unknown Version"}";
info.DumpingInfo.DumpingParameters = GetParameters($"{basePath}.log") ?? "Unknown Parameters";
info.DumpingInfo.DumpingDate = ProcessingTool.GetFileModifiedDate($"{basePath}.log")?.ToString("yyyy-MM-dd HH:mm:ss");
// Fill in the hardware data
if (GetHardwareInfo($"{basePath}.log", out var manufacturer, out var model, out var firmware))
{
info.DumpingInfo.Manufacturer = manufacturer;
info.DumpingInfo.Model = model;
info.DumpingInfo.Firmware = firmware;
}
// Fill in the disc type data
if (GetDiscType($"{basePath}.log", out var discTypeOrBookType))
info.DumpingInfo.ReportedDiscType = discTypeOrBookType;
// Fill in the volume labels
if (GetVolumeLabels($"{basePath}.log", out var volLabels))
VolumeLabels = volLabels;
switch (Type)
{
case MediaType.CDROM:
info.Extras!.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD";
info.TracksAndWriteOffsets!.ClrMameProData = GetDatfile($"{basePath}.log");
info.TracksAndWriteOffsets.Cuesheet = ProcessingTool.GetFullFile($"{basePath}.cue") ?? string.Empty;
// Attempt to get the write offset
string cdWriteOffset = GetWriteOffset($"{basePath}.log") ?? string.Empty;
info.CommonDiscInfo!.RingWriteOffset = cdWriteOffset;
info.TracksAndWriteOffsets.OtherWriteOffsets = cdWriteOffset;
// Attempt to get the error count
if (GetErrorCount($"{basePath}.log", out long redumpErrors, out long c2Errors))
{
info.CommonDiscInfo.ErrorsCount = (redumpErrors == -1 ? "Error retrieving error count" : redumpErrors.ToString());
info.DumpingInfo.C2ErrorsCount = (c2Errors == -1 ? "Error retrieving error count" : c2Errors.ToString());
}
// Attempt to get multisession data
string cdMultiSessionInfo = GetMultisessionInformation($"{basePath}.log") ?? string.Empty;
if (!string.IsNullOrEmpty(cdMultiSessionInfo))
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.Multisession] = cdMultiSessionInfo;
// Attempt to get the universal hash, if it's an audio disc
if (System.IsAudio())
{
string universalHash = GetUniversalHash($"{basePath}.log") ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.UniversalHash] = universalHash;
}
// Attempt to get the non-zero data start, if it's an audio disc
if (System.IsAudio())
{
string ringNonZeroDataStart = GetRingNonZeroDataStart($"{basePath}.log") ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.RingNonZeroDataStart] = ringNonZeroDataStart;
string ringPerfectAudioOffset = GetRingPerfectAudioOffset($"{basePath}.log") ?? string.Empty;
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.RingPerfectAudioOffset] = ringPerfectAudioOffset;
}
break;
case MediaType.DVD:
case MediaType.HDDVD:
case MediaType.BluRay:
case MediaType.NintendoGameCubeGameDisc:
case MediaType.NintendoWiiOpticalDisc:
case MediaType.NintendoWiiUOpticalDisc:
info.Extras!.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD";
info.TracksAndWriteOffsets!.ClrMameProData = GetDatfile($"{basePath}.log");
// Get the individual hash data, as per internal
if (ProcessingTool.GetISOHashValues(info.TracksAndWriteOffsets.ClrMameProData, out long size, out var crc32, out var md5, out var sha1))
{
info.SizeAndChecksums!.Size = size;
info.SizeAndChecksums.CRC32 = crc32;
info.SizeAndChecksums.MD5 = md5;
info.SizeAndChecksums.SHA1 = sha1;
}
// Deal with the layerbreaks
if (GetLayerbreaks($"{basePath}.log", out var layerbreak1, out var layerbreak2, out var layerbreak3))
{
info.SizeAndChecksums!.Layerbreak = !string.IsNullOrEmpty(layerbreak1) ? long.Parse(layerbreak1) : default;
info.SizeAndChecksums!.Layerbreak2 = !string.IsNullOrEmpty(layerbreak2) ? long.Parse(layerbreak2) : default;
info.SizeAndChecksums!.Layerbreak3 = !string.IsNullOrEmpty(layerbreak3) ? long.Parse(layerbreak3) : default;
}
// Attempt to get the error count
long scsiErrors = GetSCSIErrorCount($"{basePath}.log");
info.CommonDiscInfo!.ErrorsCount = (scsiErrors == -1 ? "Error retrieving error count" : scsiErrors.ToString());;
// Bluray-specific options
if (Type == MediaType.BluRay || Type == MediaType.NintendoWiiUOpticalDisc)
{
int trimLength = -1;
switch (System)
{
case RedumpSystem.MicrosoftXboxOne:
case RedumpSystem.MicrosoftXboxSeriesXS:
case RedumpSystem.SonyPlayStation3:
case RedumpSystem.SonyPlayStation4:
case RedumpSystem.SonyPlayStation5:
if (info.SizeAndChecksums!.Layerbreak3 != default)
trimLength = 520;
else if (info.SizeAndChecksums!.Layerbreak2 != default)
trimLength = 392;
else
trimLength = 264;
break;
}
info.Extras!.PIC = GetPIC($"{basePath}.physical", trimLength)
?? GetPIC($"{basePath}.0.physical", trimLength)
?? GetPIC($"{basePath}.1.physical", trimLength)
?? string.Empty;
var di = ProcessingTool.GetDiscInformation($"{basePath}.physical")
?? ProcessingTool.GetDiscInformation($"{basePath}.0.physical")
?? ProcessingTool.GetDiscInformation($"{basePath}.1.physical");
info.SizeAndChecksums!.PICIdentifier = ProcessingTool.GetPICIdentifier(di);
}
break;
}
// Extract info based specifically on RedumpSystem
switch (System)
{
case RedumpSystem.AppleMacintosh:
case RedumpSystem.EnhancedCD:
case RedumpSystem.IBMPCcompatible:
case RedumpSystem.RainbowDisc:
case RedumpSystem.SonyElectronicBook:
info.CopyProtection!.SecuROMData = GetSecuROMData($"{basePath}.log", out SecuROMScheme secuROMScheme) ?? string.Empty;
if (secuROMScheme == SecuROMScheme.Unknown)
info.CommonDiscInfo!.Comments = "Warning: Incorrect SecuROM sector count" + Environment.NewLine;
// Needed for some odd copy protections
info.CopyProtection!.Protection += GetDVDProtection($"{basePath}.log", false) ?? string.Empty;
break;
case RedumpSystem.DVDAudio:
case RedumpSystem.DVDVideo:
info.CopyProtection!.Protection = GetDVDProtection($"{basePath}.log", true) ?? string.Empty;
break;
case RedumpSystem.KonamiPython2:
if (GetPlayStationInfo($"{basePath}.log", out string? kp2EXEDate, out string? kp2Serial, out string? kp2Version))
{
info.CommonDiscInfo!.EXEDateBuildDate = kp2EXEDate;
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.InternalSerialName] = kp2Serial ?? string.Empty;
info.VersionAndEditions!.Version = kp2Version ?? string.Empty;
}
break;
case RedumpSystem.MicrosoftXbox:
// If .dmi / .pfi / .ss don't already exist, create them
if (!File.Exists($"{basePath}.dmi"))
RemoveHeader($"{basePath}.manufacturer", $"{basePath}.dmi");
if (!File.Exists($"{basePath}.pfi"))
RemoveHeader($"{basePath}.physical", $"{basePath}.pfi");
if (!File.Exists($"{basePath}.ss"))
ProcessingTool.CleanSS($"{basePath}.security", $"{basePath}.ss");
string xmidString = ProcessingTool.GetXMID($"{basePath}.dmi");
var xmid = SabreTools.Serialization.Wrappers.XMID.Create(xmidString);
if (xmid != null)
{
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.XMID] = xmidString?.TrimEnd('\0') ?? string.Empty;
info.CommonDiscInfo.Serial = xmid.Serial ?? string.Empty;
if (!redumpCompat)
{
info.VersionAndEditions!.Version = xmid.Version ?? string.Empty;
info.CommonDiscInfo.Region = ProcessingTool.GetXGDRegion(xmid.Model.RegionIdentifier);
}
}
string? dmi1Crc = HashTool.GetFileHash($"{basePath}.dmi", HashType.CRC32);
if (dmi1Crc != null)
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.DMIHash] = dmi1Crc.ToUpperInvariant();
string? pfi1Crc = HashTool.GetFileHash($"{basePath}.pfi", HashType.CRC32);
if (pfi1Crc != null)
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.PFIHash] = pfi1Crc.ToUpperInvariant();
string? ss1Crc = HashTool.GetFileHash($"{basePath}.ss", HashType.CRC32);
if (ss1Crc != null)
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.SSHash] = ss1Crc.ToUpperInvariant();
string? ranges1 = ProcessingTool.GetSSRanges($"{basePath}.ss");
if (!string.IsNullOrEmpty(ranges1))
info.Extras!.SecuritySectorRanges = ranges1;
break;
case RedumpSystem.MicrosoftXbox360:
// If .dmi / .pfi / .ss don't already exist, create them
if (!File.Exists($"{basePath}.dmi"))
RemoveHeader($"{basePath}.manufacturer", $"{basePath}.dmi");
if (!File.Exists($"{basePath}.pfi"))
RemoveHeader($"{basePath}.physical", $"{basePath}.pfi");
if (!File.Exists($"{basePath}.ss"))
ProcessingTool.CleanSS($"{basePath}.security", $"{basePath}.ss");
string xemidString = ProcessingTool.GetXeMID($"{basePath}.dmi");
var xemid = SabreTools.Serialization.Wrappers.XeMID.Create(xemidString);
if (xemid != null)
{
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.XeMID] = xemidString?.TrimEnd('\0') ?? string.Empty;
info.CommonDiscInfo.Serial = xemid.Serial ?? string.Empty;
if (!redumpCompat)
info.VersionAndEditions!.Version = xemid.Version ?? string.Empty;
info.CommonDiscInfo.Region = ProcessingTool.GetXGDRegion(xemid.Model.RegionIdentifier);
}
string? dmi23Crc = HashTool.GetFileHash($"{basePath}.dmi", HashType.CRC32);
if (dmi23Crc != null)
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.DMIHash] = dmi23Crc.ToUpperInvariant();
string? pfi23Crc = HashTool.GetFileHash($"{basePath}.pfi", HashType.CRC32);
if (pfi23Crc != null)
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.PFIHash] = pfi23Crc.ToUpperInvariant();
string? ss23Crc = HashTool.GetFileHash($"{basePath}.ss", HashType.CRC32);
if (ss23Crc != null)
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.SSHash] = ss23Crc.ToUpperInvariant();
string? ranges23 = ProcessingTool.GetSSRanges($"{basePath}.ss");
if (!string.IsNullOrEmpty(ranges23))
info.Extras!.SecuritySectorRanges = ranges23;
break;
case RedumpSystem.NamcoSegaNintendoTriforce:
if (Type == MediaType.CDROM)
{
info.Extras!.Header = GetGDROMHeader($"{basePath}.log",
out string? buildDate,
out string? serial,
out _,
out string? version) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = serial ?? string.Empty;
info.CommonDiscInfo.EXEDateBuildDate = buildDate ?? string.Empty;
// TODO: Support region setting from parsed value
info.VersionAndEditions!.Version = version ?? string.Empty;
}
break;
case RedumpSystem.SegaMegaCDSegaCD:
info.Extras!.Header = GetSegaCDHeader($"{basePath}.log", out var scdBuildDate, out var scdSerial, out _) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = scdSerial ?? string.Empty;
info.CommonDiscInfo.EXEDateBuildDate = scdBuildDate ?? string.Empty;
// TODO: Support region setting from parsed value
break;
case RedumpSystem.SegaChihiro:
if (Type == MediaType.CDROM)
{
info.Extras!.Header = GetGDROMHeader($"{basePath}.log",
out string? buildDate,
out string? serial,
out _,
out string? version) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = serial ?? string.Empty;
info.CommonDiscInfo.EXEDateBuildDate = buildDate ?? string.Empty;
// TODO: Support region setting from parsed value
info.VersionAndEditions!.Version = version ?? string.Empty;
}
break;
case RedumpSystem.SegaDreamcast:
if (Type == MediaType.CDROM)
{
info.Extras!.Header = GetGDROMHeader($"{basePath}.log",
out string? buildDate,
out string? serial,
out _,
out string? version) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = serial ?? string.Empty;
info.CommonDiscInfo.EXEDateBuildDate = buildDate ?? string.Empty;
// TODO: Support region setting from parsed value
info.VersionAndEditions!.Version = version ?? string.Empty;
}
break;
case RedumpSystem.SegaNaomi:
if (Type == MediaType.CDROM)
{
info.Extras!.Header = GetGDROMHeader($"{basePath}.log",
out string? buildDate,
out string? serial,
out _,
out string? version) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = serial ?? string.Empty;
info.CommonDiscInfo.EXEDateBuildDate = buildDate ?? string.Empty;
// TODO: Support region setting from parsed value
info.VersionAndEditions!.Version = version ?? string.Empty;
}
break;
case RedumpSystem.SegaNaomi2:
if (Type == MediaType.CDROM)
{
info.Extras!.Header = GetGDROMHeader($"{basePath}.log",
out string? buildDate,
out string? serial,
out _,
out string? version) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = serial ?? string.Empty;
info.CommonDiscInfo.EXEDateBuildDate = buildDate ?? string.Empty;
// TODO: Support region setting from parsed value
info.VersionAndEditions!.Version = version ?? string.Empty;
}
break;
case RedumpSystem.SegaSaturn:
info.Extras!.Header = GetSaturnHeader($"{basePath}.log",
out string? saturnBuildDate,
out string? saturnSerial,
out _,
out string? saturnVersion) ?? string.Empty;
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = saturnSerial ?? string.Empty;
info.CommonDiscInfo.EXEDateBuildDate = saturnBuildDate ?? string.Empty;
// TODO: Support region setting from parsed value
info.VersionAndEditions!.Version = saturnVersion ?? string.Empty;
break;
case RedumpSystem.SonyPlayStation:
if (GetPlayStationInfo($"{basePath}.log", out string? psxEXEDate, out string? psxSerial, out var _))
{
info.CommonDiscInfo!.EXEDateBuildDate = psxEXEDate;
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.InternalSerialName] = psxSerial ?? string.Empty;
}
info.CopyProtection!.AntiModchip = GetPlayStationAntiModchipDetected($"{basePath}.log").ToYesNo();
info.EDC!.EDC = GetPlayStationEDCStatus($"{basePath}.log").ToYesNo();
info.CopyProtection.LibCrypt = GetPlayStationLibCryptStatus($"{basePath}.log").ToYesNo();
info.CopyProtection.LibCryptData = GetPlayStationLibCryptData($"{basePath}.log");
break;
case RedumpSystem.SonyPlayStation2:
if (GetPlayStationInfo($"{basePath}.log", out string? ps2EXEDate, out string? ps2Serial, out var ps2Version))
{
info.CommonDiscInfo!.EXEDateBuildDate = ps2EXEDate;
info.CommonDiscInfo.CommentsSpecialFields![SiteCode.InternalSerialName] = ps2Serial ?? string.Empty;
info.VersionAndEditions!.Version = ps2Version ?? string.Empty;
}
string? ps2Protection = GetPlayStation2Protection($"{basePath}.log");
if (ps2Protection != null)
info.CommonDiscInfo!.Comments = $"<b>Protection</b>: {ps2Protection}" + Environment.NewLine;
break;
case RedumpSystem.SonyPlayStation3:
if (GetPlayStationInfo($"{basePath}.log", out var _, out string? ps3Serial, out var ps3Version))
{
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = ps3Serial ?? string.Empty;
info.VersionAndEditions!.Version = ps3Version ?? string.Empty;
}
break;
case RedumpSystem.SonyPlayStation4:
if (GetPlayStationInfo($"{basePath}.log", out var _, out string? ps4Serial, out var ps4Version))
{
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = ps4Serial ?? string.Empty;
info.VersionAndEditions!.Version = ps4Version ?? string.Empty;
}
break;
case RedumpSystem.SonyPlayStation5:
if (GetPlayStationInfo($"{basePath}.log", out var _, out string? ps5Serial, out var ps5Version))
{
info.CommonDiscInfo!.CommentsSpecialFields![SiteCode.InternalSerialName] = ps5Serial ?? string.Empty;
info.VersionAndEditions!.Version = ps5Version ?? string.Empty;
}
break;
}
}
/// <inheritdoc/>
internal override List<OutputFile> GetOutputFiles(string? outputDirectory, string outputFilename)
{
// Remove the extension by default
outputFilename = Path.GetFileNameWithoutExtension(outputFilename);
// Get the base path
string basePath;
if (string.IsNullOrEmpty(outputDirectory))
basePath = outputFilename;
else
basePath = Path.Combine(outputDirectory, outputFilename);
switch (Type)
{
case MediaType.CDROM:
case MediaType.GDROM:
List<OutputFile> cdrom = [
new($"{outputFilename}.asus", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"asus"),
new($"{outputFilename}.atip", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"atip"),
new($"{outputFilename}.cdtext", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"cdtext"),
new($"{outputFilename}.cue", OutputFileFlags.Required),
new($"{outputFilename}.fulltoc", OutputFileFlags.Required
| OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"fulltoc"),
new($"{outputFilename}.log", OutputFileFlags.Required
| OutputFileFlags.Artifact
| OutputFileFlags.Zippable,
"log"),
new CustomOutputFile([$"{outputFilename}.dat", $"{outputFilename}.log"], OutputFileFlags.Required,
DatfileExists),
new($"{outputFilename}.pma", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"pma"),
new([$"{outputFilename}.flip"], OutputFileFlags.None),
new([$"{outputFilename}.scram", $"{outputFilename}.scrap"], OutputFileFlags.Required
| OutputFileFlags.Deleteable),
new($"{outputFilename}.state", OutputFileFlags.Required
| OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"state"),
new($"{outputFilename}.subcode", OutputFileFlags.Required
| OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"subcode"),
new($"{outputFilename}.toc", OutputFileFlags.Required
| OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"toc"),
];
// Include .hash and .skeleton for all files in cuesheet
try
{
// Read the entire cuesheet
string[] cueLines = File.ReadAllLines($"{basePath}.cue");
// Track number, assuming 1-based
uint trackNumber = 1;
foreach (string cueLine in cueLines)
{
// Skip all non-FILE lines
if (!cueLine.StartsWith("FILE"))
continue;
// Extract the information
var match = Regex.Match(cueLine, @"FILE ""(.*?)"" BINARY");
if (!match.Success || match.Groups.Count == 0)
continue;
// Get the track name from the matches
string trackName = match.Groups[1].Value;
trackName = Path.GetFileNameWithoutExtension(trackName);
// Add the artifacts
cdrom.Add(new($"{trackName}.hash", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
$"hash_{trackNumber}"));
cdrom.Add(new($"{trackName}.skeleton", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
$"skeleton_{trackNumber}"));
trackNumber++;
}
}
catch
{
cdrom.Add(new($"{outputFilename}.hash", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"hash"));
cdrom.Add(new($"{outputFilename}.skeleton", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"skeleton"));
}
return cdrom;
case MediaType.DVD:
case MediaType.NintendoGameCubeGameDisc:
case MediaType.NintendoWiiOpticalDisc:
return [
// .asus is obsolete: newer redumper produces .cache instead
new($"{outputFilename}.asus", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"asus"),
new($"{outputFilename}.cache", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"cache"),
new($"{outputFilename}.dmi", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"dmi"),
new($"{outputFilename}.hash", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"hash"),
new($"{outputFilename}.log", OutputFileFlags.Required
| OutputFileFlags.Artifact
| OutputFileFlags.Zippable,
"log"),
new CustomOutputFile([$"{outputFilename}.dat", $"{outputFilename}.log"], OutputFileFlags.Required,
DatfileExists),
new([$"{outputFilename}.manufacturer", $"{outputFilename}.0.manufacturer"], OutputFileFlags.Required
| OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"manufacturer_0"),
new($"{outputFilename}.1.manufacturer", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"manufacturer_1"),
new($"{outputFilename}.pfi", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"pfi"),
new([$"{outputFilename}.physical", $"{outputFilename}.0.physical"], OutputFileFlags.Required
| OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"physical_0"),
new($"{outputFilename}.1.physical", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"physical_1"),
new($"{outputFilename}.security", System.IsXGD() && !IsManufacturerEmpty($"{basePath}.manufacturer")
? OutputFileFlags.Required | OutputFileFlags.Binary | OutputFileFlags.Zippable
: OutputFileFlags.Binary | OutputFileFlags.Zippable,
"security"),
new($"{outputFilename}.skeleton", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"skeleton"),
new($"{outputFilename}.ss", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"ss"),
new($"{outputFilename}.ssv1", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"ssv1"),
new($"{outputFilename}.ssv2", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"ssv2"),
new($"{outputFilename}.state", OutputFileFlags.Required
| OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"state"),
];
case MediaType.HDDVD: // TODO: Confirm that this information outputs
case MediaType.BluRay:
case MediaType.NintendoWiiUOpticalDisc:
return [
new($"{outputFilename}.asus", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"asus"),
new($"{outputFilename}.hash", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"hash"),
new($"{outputFilename}.log", OutputFileFlags.Required
| OutputFileFlags.Artifact
| OutputFileFlags.Zippable,
"log"),
new CustomOutputFile([$"{outputFilename}.dat", $"{outputFilename}.log"], OutputFileFlags.Required,
DatfileExists),
new([$"{outputFilename}.physical", $"{outputFilename}.0.physical"], OutputFileFlags.Required
| OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"physical_0"),
new($"{outputFilename}.1.physical", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"physical_1"),
new($"{outputFilename}.2.physical", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"physical_2"),
new($"{outputFilename}.3.physical", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"physical_3"),
new($"{outputFilename}.skeleton", OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"skeleton"),
new($"{outputFilename}.state", OutputFileFlags.Required
| OutputFileFlags.Binary
| OutputFileFlags.Zippable,
"state"),
];
}
return [];
}
#endregion
#region Private Extra Methods
/// <summary>
/// Get if the datfile exists in the log
/// </summary>
/// <param name="log">Log file location</param>
private static bool DatfileExists(string log)
=> GetDatfile(log) != null;
/// <summary>
/// Copies a file with the header removed
/// </summary>
/// <param name="inputFilename">Filename of file to copy from</param>
/// <param name="outputFilename">Filename of file to copy to</param>
/// <param name="headerLength">Length of header to remove</param>
private static bool RemoveHeader(string inputFilename, string outputFilename, int headerLength = 4)
{
// If the file doesn't exist, we can't copy
if (!File.Exists(inputFilename))
return false;
// If the output file already exists, don't overwrite
if (File.Exists(outputFilename))
return false;
try
{
using var inputStream = new FileStream(inputFilename, FileMode.Open, FileAccess.Read);
// If the header length is not valid, don't copy
if (headerLength < 1 || headerLength >= inputStream.Length)
return false;
using var outputStream = new FileStream(outputFilename, FileMode.Create, FileAccess.Write);
// Skip the header
inputStream.Seek(headerLength, SeekOrigin.Begin);
// inputStream.CopyTo(outputStream);
byte[] buffer = new byte[4096];
int count;
while ((count = inputStream.Read(buffer, 0, buffer.Length)) != 0)
{
outputStream.Write(buffer, 0, count);
}
return true;
}
catch
{
// We don't care what the exception is right now
return false;
}
}
/// <summary>
/// Checks whether a .manufacturer file is empty or not
/// True if standard DVD (empty DMI), False if error or XGD with security sectors
/// </summary>
/// <param name="inputFilename">Filename of .manufacturer file to check</param>
private static bool IsManufacturerEmpty(string inputFilename)
{
// If the file doesn't exist, we can't copy
if (!File.Exists(inputFilename))
return false;
try
{
using var inputStream = new FileStream(inputFilename, FileMode.Open, FileAccess.Read);
// If the manufacturer file is not the correct size, return false
if (inputStream.Length != 2052)
return false;
byte[] buffer = new byte[2052];
int bytesRead = inputStream.Read(buffer, 0, buffer.Length);
// Return false if any value is non-zero, skip SCSI header (4 bytes)
for (int i = 4; i < bytesRead; i++)
{
if (buffer[i] != 0x00)
return false;
}
return true;
}
catch
{
// We don't care what the exception is right now
return false;
}
}
#endregion
#region Information Extraction Methods
/// <summary>
/// Get the cuesheet from the input file, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Newline-delimited cuesheet if possible, null on error</returns>
internal static string? GetCuesheet(string log)
{
// If the file doesn't exist, we can't get info from it
if (string.IsNullOrEmpty(log))
return null;
if (!File.Exists(log))
return null;
try
{
// Fast forward to the cuesheet line
using var sr = File.OpenText(log);
while (!sr.EndOfStream && sr.ReadLine()?.TrimStart()?.StartsWith("CUE [") == false) ;
if (sr.EndOfStream)
return null;
// Now that we're at the relevant entries, read each line in and concatenate
string? cueString = string.Empty, line = sr.ReadLine()?.Trim();
while (!string.IsNullOrEmpty(line))
{
cueString += line + "\n";
line = sr.ReadLine()?.Trim();
}
return cueString.TrimEnd('\n');
}
catch
{
// We don't care what the exception is right now
return null;
}
}
/// <summary>
/// Get the datfile from the input file, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>Newline-delimited datfile if possible, null on error</returns>
internal static string? GetDatfile(string log)
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(log))
return null;
try
{
using var sr = File.OpenText(log);
string? datString = null;
// Find all occurrences of the hash information
while (!sr.EndOfStream)
{
// Fast forward to the dat line
while (!sr.EndOfStream && sr.ReadLine()?.TrimStart()?.StartsWith("dat:") == false) ;
if (sr.EndOfStream)
break;
// Now that we're at the relevant entries, read each line in and concatenate
datString = string.Empty;
var line = sr.ReadLine()?.Trim();
while (line?.StartsWith("<rom") == true)
{
datString += line + "\n";
if (sr.EndOfStream)
break;
line = sr.ReadLine()?.Trim();
}
}
return datString?.TrimEnd('\n');
}
catch
{
// We don't care what the exception is right now
return null;
}
}
/// <summary>
/// Get reported disc type information, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>True if disc type info was set, false otherwise</returns>
internal static bool GetDiscType(string log, out string? discTypeOrBookType)
{
// Set the default values
discTypeOrBookType = null;
// If the file doesn't exist, we can't get the info
if (string.IsNullOrEmpty(log))
return false;
if (!File.Exists(log))
return false;
try
{
using var sr = File.OpenText(log);
var line = sr.ReadLine();
while (line != null)
{
// Trim the line for later use
line = line.Trim();
// The profile is listed in a single line
if (line.StartsWith("current profile:"))
{
// current profile: <discType>
discTypeOrBookType = line.Substring("current profile: ".Length);
}
line = sr.ReadLine();
}
return true;
}
catch
{
// We don't care what the exception is right now
discTypeOrBookType = null;
return false;
}
}
/// <summary>
/// Get the DVD protection information, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <param name="includeAlways">Indicates whether region and protection type are always included</param>
/// <returns>Formatted string representing the DVD protection, null on error</returns>
internal static string? GetDVDProtection(string log, bool includeAlways)
{
// If one of the files doesn't exist, we can't get info from them
if (string.IsNullOrEmpty(log))
return null;
if (!File.Exists(log))
return null;
// Setup all of the individual pieces
string? region = null, rceProtection = null, copyrightProtectionSystemType = null, vobKeys = null, decryptedDiscKey = null;
using (var sr = File.OpenText(log))
{
try
{
// Fast forward to the copyright information
while (sr.ReadLine()?.Trim().StartsWith("copyright:") == false) ;
// Now read until we hit the manufacturing information
var line = sr.ReadLine()?.Trim();
while (line != null && !sr.EndOfStream)
{
if (line.StartsWith("protection system type"))
{
copyrightProtectionSystemType = line.Substring("protection system type: ".Length);
if (copyrightProtectionSystemType == "none" || copyrightProtectionSystemType == "<none>")
copyrightProtectionSystemType = "No";
}
else if (line.StartsWith("region management information:"))
{
region = line.Substring("region management information: ".Length);
}
else if (line.StartsWith("disc key"))
{
decryptedDiscKey = line.Substring("disc key: ".Length).Replace(':', ' ');
}
else if (line.StartsWith("title keys"))
{
vobKeys = string.Empty;
line = sr.ReadLine()?.Trim();
while (!string.IsNullOrEmpty(line))
{
var match = Regex.Match(line, @"^(.*?): (.*?)$", RegexOptions.Compiled);
if (match.Success)
{
string normalizedKey = match.Groups[2].Value.Replace(':', ' ');
if (normalizedKey == "none" || normalizedKey == "<none>")
normalizedKey = "No Title Key";
else if (normalizedKey == "<error>")
normalizedKey = "Error Retrieving Title Key";
vobKeys += $"{match.Groups[1].Value} Title Key: {normalizedKey}\n";
}
else
{
break;
}
line = sr.ReadLine()?.Trim();
}
}
else
{
break;
}
line = sr.ReadLine()?.Trim();
}
}
catch { }
}
// Filter out if we're not always including information
if (!includeAlways)
{
if (region == "1 2 3 4 5 6 7 8")
region = null;
if (copyrightProtectionSystemType == "No")
copyrightProtectionSystemType = null;
}
// Now we format everything we can
string protection = string.Empty;
if (!string.IsNullOrEmpty(region))
protection += $"Region: {region}\n";
if (!string.IsNullOrEmpty(rceProtection))
protection += $"RCE Protection: {rceProtection}\n";
if (!string.IsNullOrEmpty(copyrightProtectionSystemType))
protection += $"Copyright Protection System Type: {copyrightProtectionSystemType}\n";
if (!string.IsNullOrEmpty(vobKeys))
protection += vobKeys;
if (!string.IsNullOrEmpty(decryptedDiscKey))
protection += $"Decrypted Disc Key: {decryptedDiscKey}\n";
return protection;
}
/// <summary>
/// Get the detected error counts from the input files, if possible
/// </summary>
/// <param name="log">Log file location</param>
/// <returns>True if error counts could be retrieved, false otherwise</returns>
internal static bool GetErrorCount(string log, out long redumpErrors, out long c2Errors)
{
redumpErrors = -1; c2Errors = -1;
// If the file doesn't exist, we can't get info from it
if (string.IsNullOrEmpty(log))
return false;
if (!File.Exists(log))
return false;
try
{
redumpErrors = 0; c2Errors = 0;
using var sr = File.OpenText(log);
// Find the error counts
while (!sr.EndOfStream)
{
var line = sr.ReadLine()?.Trim();
if (line == null)
break;
// C2: <error count>
if (line.StartsWith("C2:"))
{
string[] parts = line.Split(' ');
if (long.TryParse(parts[1], out long c2TrackErrors))
c2Errors += c2TrackErrors;
else
c2Errors = -1;
}
// REDUMP.ORG errors: <error count>
else if (line.StartsWith("REDUMP.ORG errors:"))
{
string[] parts = line!.Split(' ');
if (long.TryParse(parts[2], out long redumpTrackErrors))
redumpErrors += redumpTrackErrors;
else
redumpErrors = -1;
}
// If either value is -1, exit the loop
if (c2Errors == -1 || redumpErrors == -1)
break;
}