Skip to content

Commit 7f2c0d2

Browse files
committed
new checks and fixes for disc mastering issues
fixes #89
1 parent 608ed22 commit 7f2c0d2

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

IrdLibraryClient/IrdFormat/IsoHeaderParser.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@ public static class IsoHeaderParser
5151
foreach (var filename in filenames)
5252
{
5353
var targetFilename = filename.FixDiscFsPath();
54-
if (targetFilename.EndsWith('.'))
55-
{
56-
Log.Warn($"Fixing potential mastering error in {filename}");
57-
targetFilename = targetFilename.TrimEnd('.');
58-
}
5954
var clusterRange = reader.PathToClusters(filename).ToList();
55+
#if DEBUG
6056
if (clusterRange.Count != 1)
61-
Log.Warn($"{targetFilename} is split in {clusterRange.Count} ranges");
57+
Log.Debug($"{targetFilename} is split in {clusterRange.Count} ranges");
58+
#endif
6259
var startSector = clusterRange.Min(r => r.Offset);
6360
var lengthInSectors = clusterRange.Sum(r => r.Count);
6461
var length = reader.GetFileLength(filename);

Ps3DiscDumper/Dumper.cs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -659,18 +659,43 @@ public async Task DumpAsync(string output)
659659

660660
Log.Info($"Reading {file.TargetFileName} ({file.SizeInBytes.AsStorageUnit()})");
661661
CurrentFileNumber++;
662-
var convertedFilename = Path.DirectorySeparatorChar == '\\' ? file.TargetFileName : file.TargetFileName.Replace('\\', Path.DirectorySeparatorChar);
663-
var inputFilename = Path.Combine(InputDevicePath, convertedFilename);
662+
var targetFilename = file.TargetFileName;
664663

665-
if (!File.Exists(inputFilename))
664+
var trailingPeriod = targetFilename.EndsWith('.');
665+
var inputFilePath = Path.Combine(InputDevicePath, targetFilename);
666+
// BLES00932 Demon's Souls: trailing . is trimmed on both Windows and Linux
667+
if (trailingPeriod && !File.Exists(inputFilePath))
668+
{
669+
Log.Warn($"Potential mastering error in {targetFilename}");
670+
targetFilename = targetFilename.TrimEnd('.');
671+
inputFilePath = Path.Combine(InputDevicePath, targetFilename);
672+
}
673+
// BLJS92001 Tsugime Ranko: trailing . is replaced with #ABCD in Windows, but is kept as . on Linux
674+
if (trailingPeriod && OperatingSystem.IsWindows() && !File.Exists(inputFilePath))
675+
{
676+
var inputDir = Path.GetDirectoryName(inputFilePath);
677+
var testNameBase = Path.GetFileName(inputFilePath);
678+
var options = new EnumerationOptions {IgnoreInaccessible = true, RecurseSubdirectories = false};
679+
var lst = Directory.GetFiles(inputDir, testNameBase + "#*", options);
680+
if (lst is [var match])
681+
{
682+
Log.Warn($"Using {match} as a match for {file.TargetFileName}");
683+
inputFilePath = match;
684+
}
685+
else
686+
{
687+
Log.Error($"Found {lst.Length} potential matches for {file.TargetFileName}");
688+
}
689+
}
690+
if (!File.Exists(inputFilePath))
666691
{
667692
Log.Error($"Missing {file.TargetFileName}");
668693
BrokenFiles.Add((file.TargetFileName, "missing"));
669694
continue;
670695
}
671696

672-
var outputFilename = Path.Combine(outputPathBase, convertedFilename);
673-
var fileDir = Path.GetDirectoryName(outputFilename);
697+
var outputFilePath = Path.Combine(outputPathBase, targetFilename);
698+
var fileDir = Path.GetDirectoryName(outputFilePath);
674699
if (!Directory.Exists(fileDir))
675700
{
676701
Log.Debug("Creating directory " + fileDir);
@@ -690,8 +715,8 @@ select v.Files[file.TargetFileName].Hashes
690715
try
691716
{
692717
tries--;
693-
await using var outputStream = File.Open(outputFilename, FileMode.Create, FileAccess.Write, FileShare.Read);
694-
await using var inputStream = File.Open(inputFilename, FileMode.Open, FileAccess.Read, FileShare.Read);
718+
await using var outputStream = File.Open(outputFilePath, FileMode.Create, FileAccess.Write, FileShare.Read);
719+
await using var inputStream = File.Open(inputFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
695720
await using var decrypter = new Decrypter(inputStream, driveStream, decryptionKey, file.StartSector, sectorSize, unprotectedRegions);
696721
Decrypter = decrypter;
697722
await decrypter.CopyToAsync(outputStream, 8 * 1024 * 1024, Cts.Token).ConfigureAwait(false);
@@ -737,7 +762,7 @@ select v.Files[file.TargetFileName].Hashes
737762
await Task.Yield();
738763
} while (error && tries > 0 && !Cts.IsCancellationRequested);
739764

740-
_ = new FileInfo(outputFilename)
765+
_ = new FileInfo(outputFilePath)
741766
{
742767
CreationTimeUtc = file.FileInfo.CreationTimeUtc,
743768
LastWriteTimeUtc = file.FileInfo.LastWriteTimeUtc
@@ -774,7 +799,10 @@ select v.Files[file.TargetFileName].Hashes
774799
Log.Warn(e, $"Failed to fix timestamp for directory {dir.TargetDirName}");
775800
}
776801
}
777-
Log.Info("Completed");
802+
if (BrokenFiles.Count is 0)
803+
Log.Info("Completed");
804+
else
805+
Log.Warn($"Completed with {BrokenFiles.Count} broken file{(BrokenFiles.Count == 1 ? "" : "s")}");
778806
}
779807

780808
public static async Task<(Version, GitHubReleaseInfo)> CheckUpdatesAsync()

UI.Avalonia/ViewModels/MainViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ private async Task DumpDiscAsync()
320320
|| LastOperationWarning is true)
321321
return;
322322

323-
Success = dumper.ValidationStatus is not false;
323+
Success = dumper.ValidationStatus is not false && dumper.BrokenFiles.Count is 0;
324324
if (Success == false)
325325
{
326326
StepTitle = "Dump is not valid";

0 commit comments

Comments
 (0)