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; Cursor = Cursors.WaitCursor;
foreach (var file in files) foreach (var file in files)
{ {
var job = new DiscMountJob(fromPath: file); var success = DiscoHawkLogic.HawkAndWriteFile(
job.Run(); inputPath: file,
var disc = job.OUT_Disc; errorCallback: err => MessageBox.Show(err, "Error loading disc"));
if (job.OUT_ErrorLevel) if (!success) break;
{
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);
} }
Cursor = Cursors.Default; Cursor = Cursors.Default;

View File

@ -243,6 +243,22 @@ namespace BizHawk.Emulation.DiscSystem
return ret; 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) public static void RunWithArgs(string[] args, Action<string> showComparisonResultsCallback)
{ {
bool scanCues = false; bool scanCues = false;
@ -273,14 +289,11 @@ namespace BizHawk.Emulation.DiscSystem
if (hawk) if (hawk)
{ {
if (infile == null) if (infile == null) return;
{ HawkAndWriteFile(
return; inputPath: infile,
} errorCallback: err => Console.WriteLine($"failed to convert {infile}:\n{err}"),
discInterface: loadDiscInterface);
// TODO - write it out
var dmj = new DiscMountJob(fromPath: infile, discInterface: loadDiscInterface);
dmj.Run();
} }
bool verbose = true; bool verbose = true;