Remove duplicate GetFullFile method

This commit is contained in:
Matt Nadareski
2024-05-21 20:46:48 -04:00
parent 6e798aa565
commit bb95112559
9 changed files with 58 additions and 79 deletions

View File

@@ -31,6 +31,7 @@
- Handle version like category
- Move PlayStation drive use mostly to helper
- Separate out copy protection run
- Remove duplicate GetFullFile method
### 3.1.9a (2024-05-21)

View File

@@ -87,17 +87,17 @@ namespace MPF.Core.Processors
info.Artifacts ??= [];
if (File.Exists(basePath + ".cicm.xml"))
info.Artifacts["cicm"] = GetBase64(GetFullFile(basePath + ".cicm.xml")) ?? string.Empty;
info.Artifacts["cicm"] = GetBase64(InfoTool.GetFullFile(basePath + ".cicm.xml")) ?? string.Empty;
if (File.Exists(basePath + ".ibg"))
info.Artifacts["ibg"] = Convert.ToBase64String(File.ReadAllBytes(basePath + ".ibg"));
if (File.Exists(basePath + ".log"))
info.Artifacts["log"] = GetBase64(GetFullFile(basePath + ".log")) ?? string.Empty;
info.Artifacts["log"] = GetBase64(InfoTool.GetFullFile(basePath + ".log")) ?? string.Empty;
if (File.Exists(basePath + ".mhddlog.bin"))
info.Artifacts["mhddlog_bin"] = Convert.ToBase64String(File.ReadAllBytes(basePath + ".mhddlog.bin"));
if (File.Exists(basePath + ".resume.xml"))
info.Artifacts["resume"] = GetBase64(GetFullFile(basePath + ".resume.xml")) ?? string.Empty;
info.Artifacts["resume"] = GetBase64(InfoTool.GetFullFile(basePath + ".resume.xml")) ?? string.Empty;
if (File.Exists(basePath + ".sub.log"))
info.Artifacts["sub_log"] = GetBase64(GetFullFile(basePath + ".sub.log")) ?? string.Empty;
info.Artifacts["sub_log"] = GetBase64(InfoTool.GetFullFile(basePath + ".sub.log")) ?? string.Empty;
}
/// <inheritdoc/>

View File

@@ -103,28 +103,6 @@ namespace MPF.Core.Processors
return Convert.ToBase64String(temp);
}
/// <summary>
/// Get the full lines from the input file, if possible
/// </summary>
/// <param name="filename">file location</param>
/// <param name="binary">True if should read as binary, false otherwise (default)</param>
/// <returns>Full text of the file, null on error</returns>
protected static string? GetFullFile(string filename, bool binary = false)
{
// If the file doesn't exist, we can't get info from it
if (!File.Exists(filename))
return null;
// If we're reading as binary
if (binary)
{
byte[] bytes = File.ReadAllBytes(filename);
return BitConverter.ToString(bytes).Replace("-", string.Empty);
}
return File.ReadAllText(filename);
}
#endregion
#region Methods to Move
@@ -144,7 +122,7 @@ namespace MPF.Core.Processors
try
{
var hex = GetFullFile(picPath, true);
var hex = InfoTool.GetFullFile(picPath, true);
if (hex == null)
return null;

View File

@@ -54,9 +54,9 @@ namespace MPF.Core.Processors
info.Artifacts ??= [];
if (File.Exists(basePath + ".bca"))
info.Artifacts["bca"] = GetBase64(GetFullFile(basePath + ".bca", binary: true)) ?? string.Empty;
info.Artifacts["bca"] = GetBase64(InfoTool.GetFullFile(basePath + ".bca", binary: true)) ?? string.Empty;
if (File.Exists(basePath + "-dumpinfo.txt"))
info.Artifacts["dumpinfo"] = GetBase64(GetFullFile(basePath + "-dumpinfo.txt")) ?? string.Empty;
info.Artifacts["dumpinfo"] = GetBase64(InfoTool.GetFullFile(basePath + "-dumpinfo.txt")) ?? string.Empty;
}
/// <inheritdoc/>
@@ -206,7 +206,7 @@ namespace MPF.Core.Processors
try
{
var hex = GetFullFile(bcaPath, true);
var hex = InfoTool.GetFullFile(bcaPath, true);
if (hex == null)
return null;

View File

@@ -236,33 +236,33 @@ namespace MPF.Core.Processors
//if (File.Exists($"{basePath}.c2"))
// info.Artifacts["c2"] = Convert.ToBase64String(File.ReadAllBytes($"{basePath}.c2")) ?? string.Empty;
if (File.Exists($"{basePath}_c2Error.txt"))
info.Artifacts["c2Error"] = GetBase64(GetFullFile($"{basePath}_c2Error.txt")) ?? string.Empty;
info.Artifacts["c2Error"] = GetBase64(InfoTool.GetFullFile($"{basePath}_c2Error.txt")) ?? string.Empty;
if (File.Exists($"{basePath}.ccd"))
info.Artifacts["ccd"] = GetBase64(GetFullFile($"{basePath}.ccd")) ?? string.Empty;
info.Artifacts["ccd"] = GetBase64(InfoTool.GetFullFile($"{basePath}.ccd")) ?? string.Empty;
if (File.Exists($"{basePath}_cmd.txt")) // TODO: Figure out how to read in the timestamp-named file
info.Artifacts["cmd"] = GetBase64(GetFullFile($"{basePath}_cmd.txt")) ?? string.Empty;
info.Artifacts["cmd"] = GetBase64(InfoTool.GetFullFile($"{basePath}_cmd.txt")) ?? string.Empty;
if (File.Exists($"{basePath}_CSSKey.txt"))
info.Artifacts["csskey"] = GetBase64(GetFullFile($"{basePath}_CSSKey.txt")) ?? string.Empty;
info.Artifacts["csskey"] = GetBase64(InfoTool.GetFullFile($"{basePath}_CSSKey.txt")) ?? string.Empty;
if (File.Exists($"{basePath}.cue"))
info.Artifacts["cue"] = GetBase64(GetFullFile($"{basePath}.cue")) ?? string.Empty;
info.Artifacts["cue"] = GetBase64(InfoTool.GetFullFile($"{basePath}.cue")) ?? string.Empty;
if (File.Exists($"{basePath}.dat"))
info.Artifacts["dat"] = GetBase64(GetFullFile($"{basePath}.dat")) ?? string.Empty;
info.Artifacts["dat"] = GetBase64(InfoTool.GetFullFile($"{basePath}.dat")) ?? string.Empty;
if (File.Exists($"{basePath}_disc.txt"))
info.Artifacts["disc"] = GetBase64(GetFullFile($"{basePath}_disc.txt")) ?? string.Empty;
info.Artifacts["disc"] = GetBase64(InfoTool.GetFullFile($"{basePath}_disc.txt")) ?? string.Empty;
//if (File.Exists(Path.Combine(outputDirectory, $"{basePath}_DMI.bin")))
// info.Artifacts["dmi"] = Convert.ToBase64String(File.ReadAllBytes(Path.Combine(outputDirectory, $"{basePath}_DMI.bin"))) ?? string.Empty;
if (File.Exists($"{basePath}_drive.txt"))
info.Artifacts["drive"] = GetBase64(GetFullFile($"{basePath}_drive.txt")) ?? string.Empty;
info.Artifacts["drive"] = GetBase64(InfoTool.GetFullFile($"{basePath}_drive.txt")) ?? string.Empty;
if (File.Exists($"{basePath}_img.cue"))
info.Artifacts["img_cue"] = GetBase64(GetFullFile($"{basePath}_img.cue")) ?? string.Empty;
info.Artifacts["img_cue"] = GetBase64(InfoTool.GetFullFile($"{basePath}_img.cue")) ?? string.Empty;
if (File.Exists($"{basePath}.img_EdcEcc.txt"))
info.Artifacts["img_EdcEcc"] = GetBase64(GetFullFile($"{basePath}.img_EdcEcc.txt")) ?? string.Empty;
info.Artifacts["img_EdcEcc"] = GetBase64(InfoTool.GetFullFile($"{basePath}.img_EdcEcc.txt")) ?? string.Empty;
if (File.Exists($"{basePath}.img_EccEdc.txt"))
info.Artifacts["img_EdcEcc"] = GetBase64(GetFullFile($"{basePath}.img_EccEdc.txt")) ?? string.Empty;
info.Artifacts["img_EdcEcc"] = GetBase64(InfoTool.GetFullFile($"{basePath}.img_EccEdc.txt")) ?? string.Empty;
if (File.Exists($"{basePath}_mainError.txt"))
info.Artifacts["mainError"] = GetBase64(GetFullFile($"{basePath}_mainError.txt")) ?? string.Empty;
info.Artifacts["mainError"] = GetBase64(InfoTool.GetFullFile($"{basePath}_mainError.txt")) ?? string.Empty;
if (File.Exists($"{basePath}_mainInfo.txt"))
info.Artifacts["mainInfo"] = GetBase64(GetFullFile($"{basePath}_mainInfo.txt")) ?? string.Empty;
info.Artifacts["mainInfo"] = GetBase64(InfoTool.GetFullFile($"{basePath}_mainInfo.txt")) ?? string.Empty;
//if (File.Exists($"{basePath}_PFI.bin"))
// info.Artifacts["pfi"] = Convert.ToBase64String(File.ReadAllBytes($"{basePath}_PFI.bin")) ?? string.Empty;
//if (File.Exists($"{basePath}_PIC.bin"))
@@ -272,17 +272,17 @@ namespace MPF.Core.Processors
if (File.Exists($"{basePath}.sub"))
info.Artifacts["sub"] = Convert.ToBase64String(File.ReadAllBytes($"{basePath}.sub")) ?? string.Empty;
if (File.Exists($"{basePath}_subError.txt"))
info.Artifacts["subError"] = GetBase64(GetFullFile($"{basePath}_subError.txt")) ?? string.Empty;
info.Artifacts["subError"] = GetBase64(InfoTool.GetFullFile($"{basePath}_subError.txt")) ?? string.Empty;
if (File.Exists($"{basePath}_subInfo.txt"))
info.Artifacts["subInfo"] = GetBase64(GetFullFile($"{basePath}_subInfo.txt")) ?? string.Empty;
info.Artifacts["subInfo"] = GetBase64(InfoTool.GetFullFile($"{basePath}_subInfo.txt")) ?? string.Empty;
if (File.Exists($"{basePath}_subIntention.txt"))
info.Artifacts["subIntention"] = GetBase64(GetFullFile($"{basePath}_subIntention.txt")) ?? string.Empty;
info.Artifacts["subIntention"] = GetBase64(InfoTool.GetFullFile($"{basePath}_subIntention.txt")) ?? string.Empty;
//if (File.Exists($"{basePath}_sub.txt"))
// info.Artifacts["subReadable"] = GetBase64(GetFullFile($"{basePath}_sub.txt")) ?? string.Empty;
// info.Artifacts["subReadable"] = GetBase64(InfoTool.GetFullFile($"{basePath}_sub.txt")) ?? string.Empty;
//if (File.Exists($"{basePath}_subReadable.txt"))
// info.Artifacts["subReadable"] = GetBase64(GetFullFile($"{basePath}_subReadable.txt")) ?? string.Empty;
// info.Artifacts["subReadable"] = GetBase64(InfoTool.GetFullFile($"{basePath}_subReadable.txt")) ?? string.Empty;
if (File.Exists($"{basePath}_volDesc.txt"))
info.Artifacts["volDesc"] = GetBase64(GetFullFile($"{basePath}_volDesc.txt")) ?? string.Empty;
info.Artifacts["volDesc"] = GetBase64(InfoTool.GetFullFile($"{basePath}_volDesc.txt")) ?? string.Empty;
}
/// <inheritdoc/>
@@ -344,7 +344,7 @@ namespace MPF.Core.Processors
info.CommonDiscInfo!.ErrorsCount = (errorCount == -1 ? "Error retrieving error count" : errorCount.ToString());
}
info.TracksAndWriteOffsets.Cuesheet = GetFullFile($"{basePath}.cue") ?? string.Empty;
info.TracksAndWriteOffsets.Cuesheet = InfoTool.GetFullFile($"{basePath}.cue") ?? string.Empty;
//var cueSheet = new CueSheet($"{basePath}.cue"); // TODO: Do something with this
// Attempt to get the write offset
@@ -437,7 +437,7 @@ namespace MPF.Core.Processors
{
var fi = new FileInfo($"{basePath}_subIntention.txt");
if (fi.Length > 0)
info.CopyProtection!.SecuROMData = GetFullFile($"{basePath}_subIntention.txt") ?? string.Empty;
info.CopyProtection!.SecuROMData = InfoTool.GetFullFile($"{basePath}_subIntention.txt") ?? string.Empty;
}
// Needed for some odd copy protections

View File

@@ -49,9 +49,9 @@ namespace MPF.Core.Processors
string? getKeyBasePath = GetCFWBasePath(basePath);
if (File.Exists(getKeyBasePath + ".disc.pic"))
info.Artifacts["discpic"] = GetBase64(GetFullFile(getKeyBasePath + ".disc.pic", binary: true)) ?? string.Empty;
info.Artifacts["discpic"] = GetBase64(InfoTool.GetFullFile(getKeyBasePath + ".disc.pic", binary: true)) ?? string.Empty;
if (File.Exists(getKeyBasePath + ".getkey.log"))
info.Artifacts["getkeylog"] = GetBase64(GetFullFile(getKeyBasePath + ".getkey.log")) ?? string.Empty;
info.Artifacts["getkeylog"] = GetBase64(InfoTool.GetFullFile(getKeyBasePath + ".getkey.log")) ?? string.Empty;
}
/// <inheritdoc/>

View File

@@ -132,43 +132,43 @@ namespace MPF.Core.Processors
info.Artifacts ??= [];
if (File.Exists($"{basePath}.cdtext"))
info.Artifacts["cdtext"] = GetBase64(GetFullFile($"{basePath}.cdtext")) ?? string.Empty;
info.Artifacts["cdtext"] = GetBase64(InfoTool.GetFullFile($"{basePath}.cdtext")) ?? string.Empty;
if (File.Exists($"{basePath}.cue"))
info.Artifacts["cue"] = GetBase64(GetFullFile($"{basePath}.cue")) ?? string.Empty;
info.Artifacts["cue"] = GetBase64(InfoTool.GetFullFile($"{basePath}.cue")) ?? string.Empty;
if (File.Exists($"{basePath}.fulltoc"))
info.Artifacts["fulltoc"] = GetBase64(GetFullFile($"{basePath}.fulltoc")) ?? string.Empty;
info.Artifacts["fulltoc"] = GetBase64(InfoTool.GetFullFile($"{basePath}.fulltoc")) ?? string.Empty;
if (File.Exists($"{basePath}.hash"))
info.Artifacts["hash"] = GetBase64(GetFullFile($"{basePath}.hash")) ?? string.Empty;
info.Artifacts["hash"] = GetBase64(InfoTool.GetFullFile($"{basePath}.hash")) ?? string.Empty;
// TODO: "{basePath} (Track X).hash" (get from cuesheet)
if (File.Exists($"{basePath}.log"))
info.Artifacts["log"] = GetBase64(GetFullFile($"{basePath}.log")) ?? string.Empty;
info.Artifacts["log"] = GetBase64(InfoTool.GetFullFile($"{basePath}.log")) ?? string.Empty;
if (File.Exists($"{basePath}.manufacturer"))
info.Artifacts["manufacturer"] = GetBase64(GetFullFile($"{basePath}.manufacturer")) ?? string.Empty;
info.Artifacts["manufacturer"] = GetBase64(InfoTool.GetFullFile($"{basePath}.manufacturer")) ?? string.Empty;
if (File.Exists($"{basePath}.1.manufacturer"))
info.Artifacts["manufacturer1"] = GetBase64(GetFullFile($"{basePath}.1.manufacturer")) ?? string.Empty;
info.Artifacts["manufacturer1"] = GetBase64(InfoTool.GetFullFile($"{basePath}.1.manufacturer")) ?? string.Empty;
if (File.Exists($"{basePath}.2.manufacturer"))
info.Artifacts["manufacturer2"] = GetBase64(GetFullFile($"{basePath}.2.manufacturer")) ?? string.Empty;
info.Artifacts["manufacturer2"] = GetBase64(InfoTool.GetFullFile($"{basePath}.2.manufacturer")) ?? string.Empty;
if (File.Exists($"{basePath}.physical"))
info.Artifacts["physical"] = GetBase64(GetFullFile($"{basePath}.physical")) ?? string.Empty;
info.Artifacts["physical"] = GetBase64(InfoTool.GetFullFile($"{basePath}.physical")) ?? string.Empty;
if (File.Exists($"{basePath}.0.physical"))
info.Artifacts["physical0"] = GetBase64(GetFullFile($"{basePath}.0.physical")) ?? string.Empty;
info.Artifacts["physical0"] = GetBase64(InfoTool.GetFullFile($"{basePath}.0.physical")) ?? string.Empty;
if (File.Exists($"{basePath}.1.physical"))
info.Artifacts["physical1"] = GetBase64(GetFullFile($"{basePath}.1.physical")) ?? string.Empty;
info.Artifacts["physical1"] = GetBase64(InfoTool.GetFullFile($"{basePath}.1.physical")) ?? string.Empty;
if (File.Exists($"{basePath}.2.physical"))
info.Artifacts["physical2"] = GetBase64(GetFullFile($"{basePath}.2.physical")) ?? string.Empty;
info.Artifacts["physical2"] = GetBase64(InfoTool.GetFullFile($"{basePath}.2.physical")) ?? string.Empty;
// if (File.Exists($"{basePath}.skeleton"))
// info.Artifacts["skeleton"] = GetBase64(GetFullFile($"{basePath}.skeleton")) ?? string.Empty;
// info.Artifacts["skeleton"] = GetBase64(InfoTool.GetFullFile($"{basePath}.skeleton")) ?? string.Empty;
// // Also: "{basePath} (Track X).skeleton" (get from cuesheet)
// if (File.Exists($"{basePath}.scram"))
// info.Artifacts["scram"] = GetBase64(GetFullFile($"{basePath}.scram")) ?? string.Empty;
// info.Artifacts["scram"] = GetBase64(InfoTool.GetFullFile($"{basePath}.scram")) ?? string.Empty;
// if (File.Exists($"{basePath}.scrap"))
// info.Artifacts["scrap"] = GetBase64(GetFullFile($"{basePath}.scrap")) ?? string.Empty;
// info.Artifacts["scrap"] = GetBase64(InfoTool.GetFullFile($"{basePath}.scrap")) ?? string.Empty;
if (File.Exists($"{basePath}.state"))
info.Artifacts["state"] = GetBase64(GetFullFile($"{basePath}.state")) ?? string.Empty;
info.Artifacts["state"] = GetBase64(InfoTool.GetFullFile($"{basePath}.state")) ?? string.Empty;
if (File.Exists($"{basePath}.subcode"))
info.Artifacts["subcode"] = GetBase64(GetFullFile($"{basePath}.subcode")) ?? string.Empty;
info.Artifacts["subcode"] = GetBase64(InfoTool.GetFullFile($"{basePath}.subcode")) ?? string.Empty;
if (File.Exists($"{basePath}.toc"))
info.Artifacts["toc"] = GetBase64(GetFullFile($"{basePath}.toc")) ?? string.Empty;
info.Artifacts["toc"] = GetBase64(InfoTool.GetFullFile($"{basePath}.toc")) ?? string.Empty;
}
/// <inheritdoc/>
@@ -202,7 +202,7 @@ namespace MPF.Core.Processors
case MediaType.CDROM:
info.Extras!.PVD = GetPVD($"{basePath}.log") ?? "Disc has no PVD";
info.TracksAndWriteOffsets!.ClrMameProData = GetDatfile($"{basePath}.log");
info.TracksAndWriteOffsets.Cuesheet = GetFullFile($"{basePath}.cue") ?? string.Empty;
info.TracksAndWriteOffsets.Cuesheet = InfoTool.GetFullFile($"{basePath}.cue") ?? string.Empty;
// Attempt to get the write offset
string cdWriteOffset = GetWriteOffset($"{basePath}.log") ?? string.Empty;

View File

@@ -56,17 +56,17 @@ namespace MPF.Core.Processors
info.Artifacts ??= [];
if (File.Exists($"{basePath}_disc.txt"))
info.Artifacts["disc"] = GetBase64(GetFullFile($"{basePath}_disc.txt")) ?? string.Empty;
info.Artifacts["disc"] = GetBase64(InfoTool.GetFullFile($"{basePath}_disc.txt")) ?? string.Empty;
if (File.Exists($"{basePath}_drive.txt"))
info.Artifacts["drive"] = GetBase64(GetFullFile($"{basePath}_drive.txt")) ?? string.Empty;
info.Artifacts["drive"] = GetBase64(InfoTool.GetFullFile($"{basePath}_drive.txt")) ?? string.Empty;
if (File.Exists($"{basePath}_mainError.txt"))
info.Artifacts["mainError"] = GetBase64(GetFullFile($"{basePath}_mainError.txt")) ?? string.Empty;
info.Artifacts["mainError"] = GetBase64(InfoTool.GetFullFile($"{basePath}_mainError.txt")) ?? string.Empty;
if (File.Exists($"{basePath}_mainInfo.txt"))
info.Artifacts["mainInfo"] = GetBase64(GetFullFile($"{basePath}_mainInfo.txt")) ?? string.Empty;
info.Artifacts["mainInfo"] = GetBase64(InfoTool.GetFullFile($"{basePath}_mainInfo.txt")) ?? string.Empty;
//if (File.Exists($"{basePath}_PFI.bin"))
// info.Artifacts["pfi"] = Convert.ToBase64String(File.ReadAllBytes($"{basePath}_PFI.bin")) ?? string.Empty;
if (File.Exists($"{basePath}_volDesc.txt"))
info.Artifacts["volDesc"] = GetBase64(GetFullFile($"{basePath}_volDesc.txt")) ?? string.Empty;
info.Artifacts["volDesc"] = GetBase64(InfoTool.GetFullFile($"{basePath}_volDesc.txt")) ?? string.Empty;
}
/// <inheritdoc/>

View File

@@ -65,9 +65,9 @@ namespace MPF.Core.Processors
string? logPath = GetLogName(baseDir);
if (File.Exists(logPath))
info.Artifacts["log"] = GetBase64(GetFullFile(logPath!)) ?? string.Empty;
info.Artifacts["log"] = GetBase64(InfoTool.GetFullFile(logPath!)) ?? string.Empty;
if (File.Exists($"{basePath}.dvd"))
info.Artifacts["dvd"] = GetBase64(GetFullFile($"{basePath}.dvd")) ?? string.Empty;
info.Artifacts["dvd"] = GetBase64(InfoTool.GetFullFile($"{basePath}.dvd")) ?? string.Empty;
//if (File.Exists($"{baseDir}DMI.bin"))
// info.Artifacts["dmi"] = Convert.ToBase64String(File.ReadAllBytes($"{baseDir}DMI.bin")) ?? string.Empty;
// TODO: Include PFI artifact only if the hash doesn't match known PFI hashes