2
0
Эх сурвалжийг харах

SevenZipDLLDecoder: Minor fixes to error reporting.

Split up SevenZipWin32Error so that explicitly passing ErrorCode=0 really
does show 0 in the message.
Jordan Russell 1 сар өмнө
parent
commit
cf640a80fc

+ 10 - 5
Projects/Src/Compression.SevenZipDLLDecoder.pas

@@ -214,16 +214,19 @@ type
 
 
 { Helper functions }
 { Helper functions }
 
 
-procedure SevenZipWin32Error(const FunctionName: String; ErrorCode: DWORD = 0); overload;
+procedure SevenZipWin32Error(const FunctionName: String; const ErrorCode: DWORD); overload;
 begin
 begin
-  if ErrorCode = 0 then
-    ErrorCode := GetLastError;
   const ExceptMessage = FmtSetupMessage(msgErrorFunctionFailedWithMessage,
   const ExceptMessage = FmtSetupMessage(msgErrorFunctionFailedWithMessage,
     [FunctionName, IntToStr(ErrorCode), Win32ErrorString(ErrorCode)]);
     [FunctionName, IntToStr(ErrorCode), Win32ErrorString(ErrorCode)]);
   const LogMessage = Format('Function %s returned error code %d', [FunctionName, ErrorCode]);
   const LogMessage = Format('Function %s returned error code %d', [FunctionName, ErrorCode]);
   SevenZipError(ExceptMessage, LogMessage);
   SevenZipError(ExceptMessage, LogMessage);
 end;
 end;
 
 
+procedure SevenZipWin32Error(const FunctionName: String); overload;
+begin
+  SevenZipWin32Error(FunctionName, GetLastError);
+end;
+
 function GetHandler(const Filename, NotFoundErrorMsg: String): TGUID; forward;
 function GetHandler(const Filename, NotFoundErrorMsg: String): TGUID; forward;
 
 
 const
 const
@@ -600,8 +603,9 @@ begin
         case WaitForSingleObject(ThreadHandle, 50) of
         case WaitForSingleObject(ThreadHandle, 50) of
           WAIT_OBJECT_0: Break;
           WAIT_OBJECT_0: Break;
           WAIT_TIMEOUT: HandleProgress; { This calls the user's OnExtractionProgress handler! }
           WAIT_TIMEOUT: HandleProgress; { This calls the user's OnExtractionProgress handler! }
+          WAIT_FAILED: SevenZipWin32Error('WaitForSingleObject');
         else
         else
-          SevenZipWin32Error('WaitForSingleObject');
+          SevenZipError('WaitForSingleObject returned unknown value');
         end;
         end;
       end;
       end;
     except
     except
@@ -1008,7 +1012,8 @@ begin
   try
   try
     F := TFileRedir.Create(DisableFsRedir, ArchiveFilename, fdOpenExisting, faRead, fsRead);
     F := TFileRedir.Create(DisableFsRedir, ArchiveFilename, fdOpenExisting, faRead, fsRead);
   except
   except
-    SevenZipWin32Error('CreateFile');
+    on E: EFileError do
+      SevenZipWin32Error('CreateFile', E.ErrorCode);
   end;
   end;
   const InStream: IInStream = TInStream.Create(F);
   const InStream: IInStream = TInStream.Create(F);
   var ScanSize := DefaultScanSize;
   var ScanSize := DefaultScanSize;