Encapsulate "hawking" routine in DiscoHawk and use it in CLI

resolves #2947
This commit is contained in:
YoshiRulz 2021-10-02 05:00:23 +10:00 committed by James Groom
parent 253d532a63
commit a514effba7
2 changed files with 25 additions and 21 deletions

View File

@ -42,19 +42,10 @@ namespace BizHawk.Client.DiscoHawk
Cursor = Cursors.WaitCursor;
foreach (var file in files)
{
var job = new DiscMountJob(fromPath: file);
job.Run();
var disc = job.OUT_Disc;
if (job.OUT_ErrorLevel)
{
MessageBox.Show(job.OUT_Log, "Error loading disc");
break;
}
string baseName = Path.GetFileNameWithoutExtension(file);
baseName += "_hawked";
string outfile = $"{Path.Combine(Path.GetDirectoryName(file), baseName)}.ccd";
CCD_Format.Dump(disc, outfile);
var success = DiscoHawkLogic.HawkAndWriteFile(
inputPath: file,
errorCallback: err => MessageBox.Show(err, "Error loading disc"));
if (!success) break;
}
Cursor = Cursors.Default;

View File

@ -243,6 +243,22 @@ namespace BizHawk.Emulation.DiscSystem
return ret;
}
public static bool HawkAndWriteFile(string inputPath, Action<string> errorCallback, DiscInterface discInterface = DiscInterface.BizHawk)
{
DiscMountJob job = new(inputPath, discInterface);
job.Run();
var disc = job.OUT_Disc;
if (job.OUT_ErrorLevel)
{
errorCallback(job.OUT_Log);
return false;
}
var baseName = Path.GetFileNameWithoutExtension(inputPath);
var outfile = Path.Combine(Path.GetDirectoryName(inputPath), $"{baseName}_hawked.ccd");
CCD_Format.Dump(disc, outfile);
return true;
}
public static void RunWithArgs(string[] args, Action<string> showComparisonResultsCallback)
{
bool scanCues = false;
@ -273,14 +289,11 @@ namespace BizHawk.Emulation.DiscSystem
if (hawk)
{
if (infile == null)
{
return;
}
// TODO - write it out
var dmj = new DiscMountJob(fromPath: infile, discInterface: loadDiscInterface);
dmj.Run();
if (infile == null) return;
HawkAndWriteFile(
inputPath: infile,
errorCallback: err => Console.WriteLine($"failed to convert {infile}:\n{err}"),
discInterface: loadDiscInterface);
}
bool verbose = true;