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 36131b7..df116da 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; } @@ -330,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; @@ -367,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 (sOut.Substring(0, 11) == "Verifying, " && sOut.Substring(sOut.Length - 13, 13) == " complete... ") - { - //_resultType = CHDManCheck.Good; - return; - } - - - ReportError.SendErrorMessage("CHDErrorHandler returned =" + sOut); - _result = "Unknown message : " + sOut; - _resultType = CHDManCheck.CHDUnknownError; }