public static int CheckFile(RvFile file, string directory) { string filename = Path.Combine(directory, file.Name); string ext = Path.GetExtension(filename).ToLower(); if (ext != ".chd") { return(0); } if (file.Size < MaxHeader) { return(0); } Stream s; int retval = FileStream.OpenFileRead(filename, out s); if (retval != 0) { return(retval); } if (s == null) { return(1); } CheckFile(s, out file.AltSHA1, out file.AltMD5, out file.CHDVersion); file.FileStatusSet( (file.AltSHA1 != null ? FileStatus.AltSHA1FromHeader : 0) | (file.AltMD5 != null ? FileStatus.AltMD5FromHeader : 0) ); s.Close(); s.Dispose(); return(0); }
public static CHDManCheck ChdmanCheck(string filename, BackgroundWorker bgw, out string result) { _bgw = bgw; _result = ""; _resultType = CHDManCheck.Unset; string chdExe = "chdman.exe"; string chdPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, chdExe); if (!System.IO.File.Exists(chdPath)) { result = chdExe + " Not Found."; return(CHDManCheck.ChdmanNotFound); } if (!System.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); }