diff --git a/Utilities.cs b/Utilities.cs index bf07ad90..ad4b4ce3 100644 --- a/Utilities.cs +++ b/Utilities.cs @@ -771,11 +771,11 @@ namespace DICUI mappings["Mould SID Code"] = ""; mappings["Additional Mould"] = ""; mappings["Toolstamp or Mastering Code"] = ""; - mappings["Write Offset"] = ""; mappings["Error Count"] = GetErrorCount(combinedBase + ".img_EdcEcc.txt", combinedBase + "_c2Error.txt", combinedBase + "_mainError.txt").ToString(); mappings["Cuesheet"] = GetCuesheet(combinedBase + ".cue"); + mappings["Write Offset"] = GetWriteOffset(combinedBase + "_disc.txt"); break; case DiscType.DVD5: case DiscType.HDDVD: @@ -979,5 +979,45 @@ namespace DICUI } } } + + /// + /// Get the write offset from the input file, if possible + /// + /// _disc.txt file location + /// Sample write offset if possible, null on error + private static string GetWriteOffset(string disc) + { + // If the file doesn't exist, we can't get info from it + if (!File.Exists(disc)) + { + return null; + } + + using (StreamReader sr = File.OpenText(disc)) + { + try + { + // Make sure this file is a _disc.txt + if (sr.ReadLine() != "========== TOC ==========") + { + return null; + } + + // Fast forward to the offsets + while (!sr.ReadLine().Trim().StartsWith("========== Offset")); + sr.ReadLine(); // Combined Offset + sr.ReadLine(); // Drive Offset + sr.ReadLine(); // Separator line + + // Now that we're at the offsets, attempt to get the sample offset + return sr.ReadLine().Split(' ').LastOrDefault(); + } + catch + { + // We don't care what the exception is right now + return null; + } + } + } } }