From a37e6aaf18ebccb59f93bce1631d41b1135971e9 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 11 Jun 2018 21:51:35 -0700 Subject: [PATCH] Add first two info extraction helpers --- MainWindow.xaml.cs | 3 ++ Utilities.cs | 113 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index ed3e654c..01461a24 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -179,6 +179,9 @@ namespace DICUI return; } + // TODO: UNUSED + Dictionary templateValues = Utilities.ExtractOutputInformation(outputDirectory, outputFilename, selected.Item2, selected.Item3); + // Special cases switch (selected.Item2) { diff --git a/Utilities.cs b/Utilities.cs index 636962ef..39b2affc 100644 --- a/Utilities.cs +++ b/Utilities.cs @@ -768,18 +768,24 @@ namespace DICUI { case DiscType.CD: case DiscType.GDROM: // TODO: Verify - mappings["Errors Count"] = "(REQUIRED)"; mappings["Cuesheet"] = ""; mappings["Write Offset"] = ""; + + mappings["Primary Volume Descriptor (PVD)"] = GetPVD(combinedBase + "_mainInfo.txt"); + mappings["Error Count"] = GetErrorCount(combinedBase + ".img_EdcEcc.txt", + combinedBase + "_c2Error.txt", + combinedBase + "_mainError.txt").ToString(); break; case DiscType.DVD5: case DiscType.HDDVD: case DiscType.BD25: case DiscType.GameCubeGameDisc: case DiscType.UMD: + mappings["Primary Volume Descriptor (PVD)"] = GetPVD(combinedBase + "_mainInfo.txt"); break; case DiscType.DVD9: case DiscType.BD50: + mappings["Primary Volume Descriptor (PVD)"] = GetPVD(combinedBase + "_mainInfo.txt"); mappings["Layerbreak"] = "(REQUIRED)"; break; case DiscType.Floppy: @@ -790,5 +796,110 @@ namespace DICUI return mappings; } + + /// + /// Get the detected error count from the input files, if possible + /// + /// .img_EdcEcc.txt file location + /// _c2Error.txt file location + /// _mainError.txt file location + /// Error count if possible, -1 on error + /// TODO: Ensure all possible error states are taken care of + private static long GetErrorCount(string edcecc, string c2Error, string mainError) + { + // If one of the files doesn't exist, we can't get info from them + if (!File.Exists(edcecc) || !File.Exists(c2Error) || !File.Exists(mainError)) + { + return -1; + } + + // First off, if the mainError file has any contents, we have an uncorrectable error + if (new FileInfo(mainError).Length > 0) + { + return -1; + } + + // First line of defense is the EdcEcc error file + using (StreamReader sr = File.OpenText(edcecc)) + { + try + { + // Fast forward to the PVD + string line = sr.ReadLine(); + while (!line.StartsWith("[NO ERROR]") + && !line.StartsWith("[WARNING]") + && !line.StartsWith("[ERROR]")) + { + line = sr.ReadLine(); + } + + // Now that we're at the error line, determine what the value should be + if (line.StartsWith("[NO ERROR]")) + { + return 0; + } + else if (line.StartsWith("[WARNING]")) + { + // Not sure how to handle these properly + return -1; + } + else if (line.StartsWith("[ERROR] Number of sector(s) where user data doesn't match the expected ECC/EDC:")) + { + return Int64.Parse(line.Remove(0, 80)); + } + + return -1; + } + catch + { + // We don't care what the exception is right now + return -1; + } + } + } + + /// + /// Get the PVD from the input file, if possible + /// + /// _mainInfo.txt file location + /// Newline-deliminated PVD if possible, null on error + private static string GetPVD(string mainInfo) + { + // If the file doesn't exist, we can't get info from it + if (!File.Exists(mainInfo)) + { + return null; + } + + using (StreamReader sr = File.OpenText(mainInfo)) + { + try + { + // Make sure this file is a _mainInfo.txt + if (sr.ReadLine() != "========== LBA[000016, 0x00010]: Main Channel ==========") + { + return null; + } + + // Fast forward to the PVD + while (!sr.ReadLine().StartsWith("0310")); + + // Now that we're at the PVD, read each line in and concatenate + string pvd = sr.ReadLine() + "\n"; // 0320 + pvd += sr.ReadLine() + "\n"; // 0330 + pvd += sr.ReadLine() + "\n"; // 0340 + pvd += sr.ReadLine() + "\n"; // 0350 + pvd += sr.ReadLine() + "\n"; // 0360 + pvd += sr.ReadLine() + "\n"; // 0370 + + return pvd; + } + catch + { + // We don't care what the exception is right now + return null; + } + } + } } }