Skip to content

Commit 4439c00

Browse files
committed
Error Message Handling + Fix Badly Rewritten Size
1 parent 8f1a85d commit 4439c00

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

Zero2Undub/MainWindow.xaml.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ private void UndubGame(object sender, DoWorkEventArgs e)
5050
}
5151

5252
(sender as BackgroundWorker)?.ReportProgress(100 * importer.UndubbedFiles / (Ps2Constants.NumberFiles));
53+
54+
if (!importer.IsSuccess)
55+
{
56+
MessageBox.Show($"The program failed with the following message: {importer.ErrorMessage}", "PS2 Fatal Frame 2 Undubber");
57+
return;
58+
}
59+
5360
MessageBox.Show("All Done! Enjoy the game :D", "PS2 Fatal Frame 2 Undubber");
5461
}
5562

Zero2UndubProcess/Zero2FileImporter.cs

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public class Zero2FileImporter
99
public int UndubbedFiles { get; private set; }
1010
public bool IsCompleted { get; private set; } = false;
1111

12+
public bool IsSuccess { get; private set; } = false;
13+
14+
public string ErrorMessage { get; private set; }
15+
1216
private const int TocLocationInUsIso = 0x2F90B8;
1317
private const int ImgBinStartAddressInIso = 0x30D40000;
1418
private FileInfo JpIsoFile { get; set; }
@@ -38,32 +42,44 @@ public static void LaunchUndub(string usIsoFile, string jpIsoFile)
3842

3943
public void UndubGame()
4044
{
41-
for (var i = 0; i < Ps2Constants.NumberFiles; i++)
45+
try
4246
{
43-
var currentFileJp = _jpFileDb.Zero2Files[i];
44-
var currentFileUs = _usFileDb.Zero2Files[i];
45-
UndubbedFiles = i;
46-
47-
if (currentFileJp.FileExtension != FileExtension.Video &&
48-
currentFileJp.FileExtension != FileExtension.Audio)
47+
for (var i = 0; i < Ps2Constants.NumberFiles; i++)
4948
{
50-
continue;
51-
}
49+
var currentFileJp = _jpFileDb.Zero2Files[i];
50+
var currentFileUs = _usFileDb.Zero2Files[i];
51+
UndubbedFiles = i;
52+
53+
if (currentFileJp.FileExtension != FileExtension.Video &&
54+
currentFileJp.FileExtension != FileExtension.Audio)
55+
{
56+
continue;
57+
}
5258

53-
if (currentFileJp.Size <= currentFileUs.Size)
54-
{
55-
Console.WriteLine($"Undubbing file {currentFileJp.FileId} of type {currentFileJp.FileExtension}");
56-
WriteNewFile(currentFileUs, currentFileJp);
57-
}
58-
else
59-
{
60-
Console.WriteLine($"File {currentFileJp.FileId} of type {currentFileJp.FileExtension} is too big");
59+
if (currentFileJp.Size <= currentFileUs.Size)
60+
{
61+
Console.WriteLine($"Undubbing file {currentFileJp.FileId} of type {currentFileJp.FileExtension}");
62+
WriteNewFile(currentFileUs, currentFileJp);
63+
}
64+
else
65+
{
66+
Console.WriteLine($"File {currentFileJp.FileId} of type {currentFileJp.FileExtension} is too big");
67+
}
6168
}
62-
}
6369

64-
Console.WriteLine("Done!");
70+
Console.WriteLine("Done!");
6571

66-
IsCompleted = true;
72+
IsCompleted = true;
73+
}
74+
catch (Exception e)
75+
{
76+
Console.WriteLine(e);
77+
IsSuccess = false;
78+
IsCompleted = true;
79+
return;
80+
}
81+
82+
IsSuccess = true;
6783
}
6884

6985
private void WriteNewFile(Zero2File usFile, Zero2File jpFile)
@@ -97,7 +113,9 @@ private void WriteFileNewSize(int fileIndex, int newSize)
97113
var fileLocation = fileIndex * 0xc + 4;
98114
usIsoData.Seek(TocLocationInUsIso, SeekOrigin.Begin);
99115
usIsoData.Seek(fileLocation, SeekOrigin.Current);
100-
usIsoData.Write(BitConverter.GetBytes(newSize).Reverse().ToArray());
116+
117+
var buffer = BitConverter.GetBytes(newSize);
118+
usIsoData.Write(buffer);
101119
}
102120
}
103121
}

0 commit comments

Comments
 (0)