From e27dfd039dc098f3bd55ae7a4aacc6754212edd8 Mon Sep 17 00:00:00 2001 From: Jim Westfall Date: Tue, 28 Oct 2014 18:37:16 -0700 Subject: [PATCH 1/3] chdman fixes for mono/unix - call chdman as chdman and not chdman.exe - fix parsing issue with chdman stderr output --- ROMVault2/SupportedFiles/CHD/CHD.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ROMVault2/SupportedFiles/CHD/CHD.cs b/ROMVault2/SupportedFiles/CHD/CHD.cs index 36131b7..5740ce8 100644 --- a/ROMVault2/SupportedFiles/CHD/CHD.cs +++ b/ROMVault2/SupportedFiles/CHD/CHD.cs @@ -245,10 +245,14 @@ namespace ROMVault2.SupportedFiles.CHD _result = ""; _resultType = CHDManCheck.Unset; - string chdPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "chdman.exe"); + string chdExe = "chdman.exe"; + if (Settings.MonoFileIO) + chdExe = "chdman"; + + string chdPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, chdExe); if (!File.Exists(chdPath)) { - result = "chdman not found"; + result = chdExe + " Not Found."; return CHDManCheck.ChdmanNotFound; } @@ -421,7 +425,7 @@ namespace ROMVault2.SupportedFiles.CHD // check for Verifying message if (sOut.Length >= 24) - if (sOut.Substring(0, 11) == "Verifying, " && sOut.Substring(sOut.Length - 13, 13) == " complete... ") + if (System.Text.RegularExpressions.Regex.IsMatch(sOut, "Verifying, \\d+\\.\\d+\\% complete\\.\\.\\.")) { //_resultType = CHDManCheck.Good; return; From 7f6b01516d9ba5dbde55da33bc70f8f7b4330c5a Mon Sep 17 00:00:00 2001 From: Jim Westfall Date: Tue, 28 Oct 2014 21:10:43 -0700 Subject: [PATCH 2/3] Fix parsing of chdman stderr output. Makes it works under mono/linux and also corrects the displayed error message in windows. --- ROMVault2/SupportedFiles/CHD/CHD.cs | 109 +++++++++++++--------------- 1 file changed, 50 insertions(+), 59 deletions(-) diff --git a/ROMVault2/SupportedFiles/CHD/CHD.cs b/ROMVault2/SupportedFiles/CHD/CHD.cs index 5740ce8..29b4da5 100644 --- a/ROMVault2/SupportedFiles/CHD/CHD.cs +++ b/ROMVault2/SupportedFiles/CHD/CHD.cs @@ -371,70 +371,61 @@ namespace ROMVault2.SupportedFiles.CHD // Collect the process command output. if (String.IsNullOrEmpty(outLine.Data)) return; - string sOut = outLine.Data; - ReportError.LogOut("CHDError: " + sOut); + // We can get fed multiple lines worth of data because of \r line feeds + string[] sLines = outLine.Data.Split(new string[] { "\r" }, StringSplitOptions.None); - _bgw.ReportProgress(0, new bgwText3(sOut)); + foreach (string sLine in sLines) { - if (_resultType != CHDManCheck.Unset) - { - if(_errorLines>0) + if (string.IsNullOrEmpty(sLine)) continue; + + ReportError.LogOut("CHDError: " + sLine); + _bgw.ReportProgress(0, new bgwText3(sLine)); + + if (_resultType != CHDManCheck.Unset) { - _errorLines -= 1; - _result += "\r\n" + sOut; + if (_errorLines>0) + { + _errorLines -= 1; + _result += "\r\n" + sLine; + } + } + else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"^No verification to be done; CHD has (uncompressed|no checksum)")) + { + _result = sLine; + _resultType = CHDManCheck.Corrupt; + } + else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"^Error (opening|reading) CHD file.*")) + { + _result = sLine; + _resultType = CHDManCheck.Corrupt; + } + else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"^Error opening parent CHD file .*:")) + { + _result = sLine; + _resultType = CHDManCheck.Corrupt; + } + else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"^Error: (Raw|Overall) SHA1 in header")) + { + _result = sLine; + _resultType = CHDManCheck.Corrupt; + } + else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"^Out of memory")) + { + _result = sLine; + _resultType = CHDManCheck.Corrupt; + } + // Verifying messages are a non-error + else if (System.Text.RegularExpressions.Regex.IsMatch(sLine, @"Verifying, \d+\.\d+\% complete\.\.\.")) + { + + } + else + { + ReportError.SendErrorMessage("CHDErrorHandler returned =" + sLine); + _result = "Unknown message : " + sLine; + _resultType = CHDManCheck.CHDUnknownError; } - return; } - - if (sOut.Length > 44) - if (sOut.Substring(0, 23) == "Error reading CHD file " && sOut.Substring(sOut.Length - 21, 21) == ": decompression error") - { - _result = sOut; - _resultType = CHDManCheck.Corrupt; - return; - } - if (sOut.Length > 35) - if (sOut.Substring(0, 23) == "Error opening CHD file " && sOut.Substring(sOut.Length - 21, 21) == ": decompression error") - { - _result = sOut; - _resultType = CHDManCheck.Corrupt; - return; - } - if (sOut.Length > 35) - if (sOut.Substring(0, 23) == "Error opening CHD file " && sOut.Substring(sOut.Length - 12, 12) == ": read error") - { - _result = sOut; - _resultType = CHDManCheck.Corrupt; - return; - } - if (sOut.Length > 25) - if (sOut.Substring(0, 25) == "Error: Raw SHA1 in header") - { - _result = sOut; - _errorLines = 1; - _resultType = CHDManCheck.Corrupt; - return; - } - if (sOut.Length == 13) - if (sOut == "Out of memory") - { - _result = sOut; - _resultType = CHDManCheck.Corrupt; - return; - } - - // check for Verifying message - if (sOut.Length >= 24) - if (System.Text.RegularExpressions.Regex.IsMatch(sOut, "Verifying, \\d+\\.\\d+\\% complete\\.\\.\\.")) - { - //_resultType = CHDManCheck.Good; - return; - } - - - ReportError.SendErrorMessage("CHDErrorHandler returned =" + sOut); - _result = "Unknown message : " + sOut; - _resultType = CHDManCheck.CHDUnknownError; } From 634de3b3d7625e93da87f870c336a4d1aa2563ae Mon Sep 17 00:00:00 2001 From: Jim Westfall Date: Wed, 29 Oct 2014 20:20:37 -0700 Subject: [PATCH 3/3] More CHD related fixes - CHDReturnError was not handled and would cause an exception/crash - CHD error/filename were swapped in ErrorGrid when scanning - Use regex when parsing chdman stdout output --- ROMVault2/FileScanning.cs | 5 +++-- ROMVault2/SupportedFiles/CHD/CHD.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ROMVault2/FileScanning.cs b/ROMVault2/FileScanning.cs index e8b3726..698c1c4 100644 --- a/ROMVault2/FileScanning.cs +++ b/ROMVault2/FileScanning.cs @@ -820,11 +820,12 @@ namespace ROMVault2 tFile.FileStatusSet(FileStatus.SHA1CHDVerified); return; case CHD.CHDManCheck.Corrupt: - _bgw.ReportProgress(0, new bgwShowError(error, filename)); + _bgw.ReportProgress(0, new bgwShowError(filename, error)); tFile.GotStatus = GotStatus.Corrupt; return; + case CHD.CHDManCheck.CHDReturnError: case CHD.CHDManCheck.CHDUnknownError: - _bgw.ReportProgress(0, new bgwShowError(error, filename)); + _bgw.ReportProgress(0, new bgwShowError(filename, error)); return; case CHD.CHDManCheck.ChdmanNotFound: return; diff --git a/ROMVault2/SupportedFiles/CHD/CHD.cs b/ROMVault2/SupportedFiles/CHD/CHD.cs index 29b4da5..df116da 100644 --- a/ROMVault2/SupportedFiles/CHD/CHD.cs +++ b/ROMVault2/SupportedFiles/CHD/CHD.cs @@ -334,7 +334,7 @@ namespace ROMVault2.SupportedFiles.CHD switch (_outputLineCount) { case 0: - if (sOut.Length < 53 || sOut.Substring(0, 53) != "chdman - MAME Compressed Hunks of Data (CHD) manager ") + if (!System.Text.RegularExpressions.Regex.IsMatch(sOut, @"^chdman - MAME Compressed Hunks of Data \(CHD\) manager ([0-9\.]+) \(.*\)")) { _result = "Incorrect startup of CHDMan :" + sOut; _resultType = CHDManCheck.CHDReturnError;