Пример #1
0
        private static void CHDOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            // Collect the process command output.
            if (String.IsNullOrEmpty(outLine.Data))
            {
                return;
            }

            string sOut = outLine.Data;

            //ReportError.LogOut("CHDOutput: " + _outputLineCount + " : " + sOut);
            switch (_outputLineCount)
            {
            case 0:
                if (sOut.Length < 53 || sOut.Substring(0, 53) != "chdman - MAME Compressed Hunks of Data (CHD) manager ")
                {
                    _result     = "Incorrect startup of CHDMan :" + sOut;
                    _resultType = CHDManCheck.CHDReturnError;
                }
                break;

            case 1:
                if (sOut != "Raw SHA1 verification successful!")
                {
                    _result     = "Raw SHA1 check failed :" + sOut;
                    _resultType = CHDManCheck.CHDReturnError;
                }
                break;

            case 2:
                if (sOut != "Overall SHA1 verification successful!")
                {
                    _result     = "Overall SHA1 check failed :" + sOut;
                    _resultType = CHDManCheck.CHDReturnError;
                }
                break;

            default:
                _result = "Unexpected output from chdman :" + sOut;
                ReportError.SendErrorMessage("CHDOutputHandler returned =" + sOut);
                _resultType = CHDManCheck.CHDUnknownError;
                break;
            }

            _outputLineCount++;
        }
Пример #2
0
        private static void CHDOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            // Collect the process command output.
            if (String.IsNullOrEmpty(outLine.Data))
            {
                return;
            }

            string sOut = outLine.Data;

            //ReportError.LogOut("CHDOutput: " + _outputLineCount + " : " + sOut);
            switch (_outputLineCount)
            {
            case 0:
                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;
                }
                break;

            case 1:
                if (sOut != "Raw SHA1 verification successful!")
                {
                    _result     = "Raw SHA1 check failed :" + sOut;
                    _resultType = CHDManCheck.CHDReturnError;
                }
                break;

            case 2:
                if (sOut != "Overall SHA1 verification successful!")
                {
                    _result     = "Overall SHA1 check failed :" + sOut;
                    _resultType = CHDManCheck.CHDReturnError;
                }
                break;

            default:
                _result     = "Unexpected output from chdman :" + sOut;
                _resultType = CHDManCheck.CHDUnknownError;
                break;
            }

            _outputLineCount++;
        }
Пример #3
0
        private static void CHDErrorHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            // Collect the process command output.
            if (String.IsNullOrEmpty(outLine.Data))
            {
                return;
            }

            // We can get fed multiple lines worth of data because of \r line feeds
            string[] sLines = outLine.Data.Split(new string[] { "\r" }, StringSplitOptions.None);

            foreach (string sLine in sLines)
            {
                if (string.IsNullOrEmpty(sLine))
                {
                    continue;
                }

                ReportError.LogOut("CHDError: " + sLine);
                _bgw.ReportProgress(0, new bgwText3(sLine));

                if (_resultType != CHDManCheck.Unset)
                {
                    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
                {
                    _result     = "Unknown message : " + sLine;
                    _resultType = CHDManCheck.CHDUnknownError;
                }
            }
        }
Пример #4
0
        public static CHDManCheck ChdmanCheck(string filename, BackgroundWorker bgw, out string result)
        {
            _bgw        = bgw;
            _result     = "";
            _resultType = CHDManCheck.Unset;

            string chdExe = "chdman.exe";

            if (Settings.IsUnix)
            {
                chdExe = "chdman";
            }

            string chdPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, chdExe);

            if (!File.Exists(chdPath))
            {
                result = chdExe + " Not Found.";
                return(CHDManCheck.ChdmanNotFound);
            }

            if (!IO.File.Exists(filename))
            {
                result = filename + " Not Found.";
                return(CHDManCheck.CHDNotFound);
            }

            string shortName = NameFix.GetShortPath(filename);


            using (Process exeProcess = new Process())
            {
                exeProcess.StartInfo.FileName = chdPath;
                ReportError.LogOut("CHD: FileName :" + exeProcess.StartInfo.FileName);


                exeProcess.StartInfo.Arguments = "verify -i \"" + shortName + "\"";
                ReportError.LogOut("CHD: Arguments :" + exeProcess.StartInfo.Arguments);

                // Set UseShellExecute to false for redirection.
                exeProcess.StartInfo.UseShellExecute = false;
                // Stops the Command window from popping up.
                exeProcess.StartInfo.CreateNoWindow = true;

                // Redirect the standard output.
                // This stream is read asynchronously using an event handler.
                exeProcess.StartInfo.RedirectStandardOutput = true;
                exeProcess.StartInfo.RedirectStandardError  = true;

                // Set our event handler to asynchronously read the process output.
                exeProcess.OutputDataReceived += CHDOutputHandler;
                exeProcess.ErrorDataReceived  += CHDErrorHandler;

                _outputLineCount = 0;
                _errorLines      = 0;

                ReportError.LogOut("CHD: Scanning Starting");
                exeProcess.Start();

                // Start the asynchronous read of the process output stream.
                exeProcess.BeginOutputReadLine();
                exeProcess.BeginErrorReadLine();

                // Wait for the process finish.
                exeProcess.WaitForExit();
                ReportError.LogOut("CHD: Scanning Finished");
            }

            result = _result;

            if (_resultType == CHDManCheck.Unset)
            {
                _resultType = CHDManCheck.Good;
            }

            _bgw.ReportProgress(0, new bgwText3(""));

            ReportError.LogOut("CHD: returning result " + _resultType + " " + result);

            return(_resultType);
        }
Пример #5
0
        private static void CHDErrorHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            // Collect the process command output.
            if (String.IsNullOrEmpty(outLine.Data))
            {
                return;
            }

            string sOut = outLine.Data;

            ReportError.LogOut("CHDError: " + sOut);

            _bgw.ReportProgress(0, new bgwText3(sOut));

            if (_resultType != CHDManCheck.Unset)
            {
                if (_errorLines > 0)
                {
                    _errorLines -= 1;
                    _result     += "\r\n" + sOut;
                }
                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;
        }
Пример #6
0
        public static CHDManCheck ChdmanCheck(string filename, BackgroundWorker bgw, out string result)
        {
            _bgw = bgw;
            _result = "";
            _resultType = CHDManCheck.Unset;

            string chdExe = "chdman.exe";
            if (Settings.IsUnix)
                chdExe = "chdman";

            string chdPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, chdExe);
            if (!File.Exists(chdPath))
            {
                result = chdExe + " Not Found.";
                return CHDManCheck.ChdmanNotFound;
            }

            if (!IO.File.Exists(filename))
            {
                result = filename + " Not Found.";
                return CHDManCheck.CHDNotFound;
            }

            string shortName = NameFix.GetShortPath(filename);

            using (Process exeProcess = new Process())
            {
                exeProcess.StartInfo.FileName = chdPath;
                ReportError.LogOut("CHD: FileName :" + exeProcess.StartInfo.FileName);

                exeProcess.StartInfo.Arguments = "verify -i \"" + shortName + "\"";
                ReportError.LogOut("CHD: Arguments :" + exeProcess.StartInfo.Arguments);

                // Set UseShellExecute to false for redirection.
                exeProcess.StartInfo.UseShellExecute = false;
                // Stops the Command window from popping up.
                exeProcess.StartInfo.CreateNoWindow = true;

                // Redirect the standard output.
                // This stream is read asynchronously using an event handler.
                exeProcess.StartInfo.RedirectStandardOutput = true;
                exeProcess.StartInfo.RedirectStandardError = true;

                // Set our event handler to asynchronously read the process output.
                exeProcess.OutputDataReceived += CHDOutputHandler;
                exeProcess.ErrorDataReceived += CHDErrorHandler;

                _outputLineCount = 0;
                _errorLines=0;

                ReportError.LogOut("CHD: Scanning Starting");
                exeProcess.Start();

                // Start the asynchronous read of the process output stream.
                exeProcess.BeginOutputReadLine();
                exeProcess.BeginErrorReadLine();

                // Wait for the process finish.
                exeProcess.WaitForExit();
                ReportError.LogOut("CHD: Scanning Finished");

            }

            result = _result;

            if (_resultType == CHDManCheck.Unset)
                _resultType = CHDManCheck.Good;

            _bgw.ReportProgress(0, new bgwText3(""));

            ReportError.LogOut("CHD: returning result " + _resultType + " " + result);

            return _resultType;
        }
Пример #7
0
        private static void CHDOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            // Collect the process command output.
            if (String.IsNullOrEmpty(outLine.Data)) return;

            string sOut = outLine.Data;
            //ReportError.LogOut("CHDOutput: " + _outputLineCount + " : " + sOut);
            switch (_outputLineCount)
            {
                case 0:
                    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;
                    }
                    break;
                case 1:
                    if (sOut != "Raw SHA1 verification successful!")
                    {
                        _result = "Raw SHA1 check failed :" + sOut;
                        _resultType = CHDManCheck.CHDReturnError;
                    }
                    break;
                case 2:
                    if (sOut != "Overall SHA1 verification successful!")
                    {
                        _result = "Overall SHA1 check failed :" + sOut;
                        _resultType = CHDManCheck.CHDReturnError;
                    }
                    break;
                default:
                    _result = "Unexpected output from chdman :" + sOut;
                    _resultType = CHDManCheck.CHDUnknownError;
                    break;
            }

            _outputLineCount++;
        }
Пример #8
0
        private static void CHDErrorHandler(object sendingProcess, DataReceivedEventArgs outLine)
        {
            // Collect the process command output.
            if (String.IsNullOrEmpty(outLine.Data)) return;

            // We can get fed multiple lines worth of data because of \r line feeds
            string[] sLines = outLine.Data.Split(new string[] { "\r" }, StringSplitOptions.None);

            foreach (string sLine in sLines) {

                if (string.IsNullOrEmpty(sLine)) continue;

                ReportError.LogOut("CHDError: " + sLine);
                _bgw.ReportProgress(0, new bgwText3(sLine));

                if (_resultType != CHDManCheck.Unset)
                {
                    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
                {
                    _result = "Unknown message : " + sLine;
                    _resultType = CHDManCheck.CHDUnknownError;
                }
            }
        }