Переглянути джерело

Redo the message change. Todo: commit updated Default.isl.

Martijn Laan 3 місяців тому
батько
коміт
36177fd98a

+ 2 - 0
Components/Lzma2/Util/7z/7zMain.c

@@ -967,6 +967,8 @@ int Z7_CDECL mainW(int numargs, WCHAR *args[])
     PrintError("decoder doesn't support this archive");
   else if (res == SZ_ERROR_MEM)
     PrintError("cannot allocate memory");
+  else if (res == SZ_ERROR_DATA)
+    PrintError("Data error");
   else if (res == SZ_ERROR_CRC)
     PrintError("CRC error");
   else if (res == SZ_ERROR_ARCHIVE)

+ 46 - 35
Projects/Src/Compression.SevenZipDLLDecoder.pas

@@ -15,7 +15,7 @@ unit Compression.SevenZipDLLDecoder;
 interface
 
 uses
-  Windows, SysUtils, Shared.FileClass, Shared.VerInfoFunc, Compression.SevenZipDecoder;
+  Windows, Shared.FileClass, Shared.VerInfoFunc, Compression.SevenZipDecoder;
 
 function SevenZipDLLInit(const SevenZipLibrary: HMODULE;
   [ref] const VersionNumbers: TFileVersionNumbers): Boolean;
@@ -49,12 +49,10 @@ type
     function HasTime: Boolean;
   end;
 
-  ESevenZipError = class(Exception);
-
 implementation
 
 uses
-  Classes, Forms, Variants, ActiveX, ComObj, Generics.Collections,
+  Classes, SysUtils, Forms, Variants, ActiveX, ComObj, Generics.Collections,
   Compression.SevenZipDLLDecoder.Interfaces, PathFunc,
   Shared.Int64Em, Shared.SetupMessageIDs, Shared.CommonFunc,
   SetupLdrAndSetup.Messages, SetupLdrAndSetup.RedirFunc,
@@ -193,20 +191,14 @@ type
 
 { Helper functions }
 
-procedure SevenZipError(const LogMessage, ExceptMessage: String);
-{ Do not call from secondary thread. LogMessage may contain non-localized text
-  ExceptMessage should not. }
-begin
-  LogFmt('ERROR: %s', [LogMessage]); { Just like 7zMain.c }
-  raise Exception.Create(ExceptMessage);
-end;
-
-procedure SevenZipWin32Error(const FunctionName: String; LastError: DWORD = 0); overload;
+procedure SevenZipWin32Error(const FunctionName: String; ErrorCode: DWORD = 0); overload;
 begin
-  if LastError = 0 then
-    LastError := GetLastError;
-  const Msg = Format('%s (%u)', [Win32ErrorString(LastError), LastError]);
-  SevenZipError(Format('%s failed: %s', [FunctionName, Msg]), Msg);
+  if ErrorCode = 0 then
+    ErrorCode := GetLastError;
+  const ExceptMessage = FmtSetupMessage(msgErrorFunctionFailedWithMessage,
+    [FunctionName, IntToStr(ErrorCode), Win32ErrorString(ErrorCode)]);
+  const LogMessage = Format('Function %s returned error code %d', [FunctionName, ErrorCode]);
+  SevenZipError(ExceptMessage, LogMessage);
 end;
 
 const
@@ -560,24 +552,43 @@ end;
 
 procedure TArchiveExtractBaseCallback.HandleResult;
 
-  function OperationResultToString(const opRes: TNOperationResult): String;
+  procedure BadOperationResultError(const opRes: TNOperationResult);
   begin
+    var LogMessage: String;
+    case opRes of
+      kUnsupportedMethod: LogMessage := 'Unsupported method';
+      kDataError: LogMessage := 'Data error';
+      kCRCError: LogMessage := 'CRC error';
+      kUnavailable: LogMessage := 'Unavailable data';
+      kUnexpectedEnd: LogMessage := 'Unexpected end';
+      kDataAfterEnd: LogMessage := 'Data after end';
+      kIsNotArc: LogMessage := 'Is not an archive';
+      kHeadersError: LogMessage := 'Headers error';
+      kWrongPassword: LogMessage := 'Wrong password';
+    else
+      LogMessage := Format('Unknown operation result: %d', [Ord(opRes)]);
+    end;
+
     case opRes of
-      kOK: Result := 'OK';
-      kUnsupportedMethod: Result := 'Unsupported method';
-      kDataError: Result := 'Data error';
-      kCRCError: Result := 'CRC error';
-      kUnavailable: Result := 'Unavailable';
-      kUnexpectedEnd: Result := 'Unexpected end';
-      kDataAfterEnd: Result := 'Data after end';
-      kIsNotArc: Result := 'Is not an archive';
-      kHeadersError: Result := 'Headers error';
-      kWrongPassword: Result := 'Wrong password';
+      kUnsupportedMethod:
+        SevenZipError(SetupMessages[msgExtractArchiveUnsupportedFormat], LogMessage);
+      kDataError, kCRCError, kUnavailable, kUnexpectedEnd, kDataAfterEnd, kIsNotArc, kHeadersError:
+        SevenZipError(SetupMessages[msgExtractArchiveIsCorrupted], LogMessage);
+      kWrongPassword:
+        SevenZipError(SetupMessages[msgExtractArchiveIncorrectPassword], LogMessage);
     else
-      Result := Format('Unknown operation result: %d', [Ord(opRes)]);
+      SevenZipError(Ord(opRes).ToString, LogMessage);
     end;
   end;
 
+  procedure BadResultError(const Res: HRESULT);
+  begin
+    if Res = E_OUTOFMEMORY then
+      SevenZipError(SetupMessages[msgExtractArchiveOutOfMemory], 'Out of memory')
+    else
+      SevenZipWin32Error('Extract', FResult.Res);
+  end;
+
 begin
   if Assigned(FResult.SavedFatalException) then begin
     var Msg: String;
@@ -585,15 +596,15 @@ begin
       Msg := (FResult.SavedFatalException as Exception).Message
     else
       Msg := FResult.SavedFatalException.ClassName;
-    SevenZipError(Format('Worker thread terminated unexpectedly with exception: %s', [Msg]), Msg);
+    InternalErrorFmt('Worker thread terminated unexpectedly with exception: %s', [Msg]);
   end else if FResult.Res = E_ABORT then
     Abort
   else begin
     var OpRes := FResult.OpRes;
     if OpRes <> kOK then
-      SevenZipError(OperationResultToString(FResult.OpRes), Ord(OpRes).ToString)
+      BadOperationResultError(OpRes)
     else if FResult.Res <> S_OK then
-      SevenZipWin32Error('Extract', FResult.Res);
+      BadResultError(FResult.Res);
   end;
 end;
 
@@ -915,7 +926,7 @@ function OpenArchiveRedir(const DisableFsRedir: Boolean;
 begin
   { CreateObject }
   if CreateSevenZipObject(clsid, IInArchive, Result) <> S_OK then
-    SevenZipError('Cannot get class object' { Just like Client7z.cpp }, '-1');
+    SevenZipError(SetupMessages[msgExtractArchiveUnsupportedFormat], 'Cannot get class object' { Just like Client7z.cpp });
 
   { Open }
   var F: TFile := nil; { Set to nil to silence compiler }
@@ -928,9 +939,9 @@ begin
   var ScanSize: Int64 := 1 shl 23; { From Client7z.cpp }
   const OpenCallback: IArchiveOpenCallback = TArchiveOpenCallback.Create(Password);
   if Result.Open(InStream, @ScanSize, OpenCallback) <> S_OK then
-    SevenZipError('Cannot open file as archive' { Just like Client7z.cpp }, '-2');
+    SevenZipError(SetupMessages[msgExtractArchiveIsCorrupted], 'Cannot open as archive' { Just like Client7z.cpp });
   if Result.GetNumberOfItems(numItems) <> S_OK then
-    SevenZipError('Cannot get number of items', '-3');
+    SevenZipError(SetupMessages[msgExtractArchiveIsCorrupted], 'Cannot get number of items');
 end;
 
 { ExtractArchiveRedir }

+ 74 - 29
Projects/Src/Compression.SevenZipDecoder.pas

@@ -12,9 +12,16 @@ unit Compression.SevenZipDecoder;
 
 interface
 
+uses
+  SysUtils;
+
 type
   TOnExtractionProgress = function(const ArchiveName, FileName: string; const Progress, ProgressMax: Int64): Boolean of object;
 
+  ESevenZipError = class(Exception);
+
+procedure SevenZipError(const ExceptMessage: String; const LogMessage: String = '');
+
 procedure Extract7ZipArchiveRedir(const DisableFsRedir: Boolean;
   const ArchiveFileName, DestDir, Password: String; const FullPaths: Boolean;
   const OnExtractionProgress: TOnExtractionProgress);
@@ -22,10 +29,10 @@ procedure Extract7ZipArchiveRedir(const DisableFsRedir: Boolean;
 implementation
 
 uses
-  Windows, SysUtils, Forms,
+  Windows, Forms,
   PathFunc,
-  Shared.SetupMessageIDs, SetupLdrAndSetup.Messages, SetupLdrAndSetup.RedirFunc,
-  Setup.LoggingFunc, Setup.MainFunc, Setup.InstFunc;
+  Shared.SetupMessageIDs, Shared.CommonFunc, SetupLdrAndSetup.Messages,
+  SetupLdrAndSetup.RedirFunc, Setup.LoggingFunc, Setup.MainFunc, Setup.InstFunc;
 
 type
   TSevenZipDecodeState = record
@@ -294,9 +301,43 @@ begin
     State.Aborted := True;
 end;
 
+procedure SevenZipError(const ExceptMessage, LogMessage: String);
+{ LogMessage may be non-localized or empty but ExceptMessage may be neither.
+  ExceptMessage should not already contain msgErrorExtractionFailed.
+  Should not be called from a secondary thread if LogMessage is not empty. }
+begin
+  if LogMessage <> '' then
+    LogFmt('ERROR: %s', [LogMessage]); { Just like 7zMain.c }
+  raise ESevenZipError.Create(ExceptMessage);
+end;
+
 procedure Extract7ZipArchiveRedir(const DisableFsRedir: Boolean;
   const ArchiveFileName, DestDir, Password: String; const FullPaths: Boolean;
   const OnExtractionProgress: TOnExtractionProgress);
+
+  procedure BadResultError(const Res: Integer);
+  const
+    SZ_ERROR_DATA = 1;
+    SZ_ERROR_MEM = 2;
+    SZ_ERROR_CRC = 3;
+    SZ_ERROR_UNSUPPORTED = 4;
+    SZ_ERROR_ARCHIVE = 16;
+    SZ_ERROR_NO_ARCHIVE = 17;
+  begin
+    { Logging already done by 7zMain.c }
+
+    case Res of
+      SZ_ERROR_UNSUPPORTED, SZ_ERROR_NO_ARCHIVE:
+        SevenZipError(SetupMessages[msgExtractArchiveUnsupportedFormat]);
+      SZ_ERROR_DATA, SZ_ERROR_CRC, SZ_ERROR_ARCHIVE:
+        SevenZipError(SetupMessages[msgExtractArchiveIsCorrupted]);
+      SZ_ERROR_MEM:
+        SevenZipError(SetupMessages[msgExtractArchiveOutOfMemory]);
+    else
+      SevenZipError(Res.ToString);
+    end;
+  end;
+
 begin
   LogArchiveExtractionModeOnce;
 
@@ -304,36 +345,40 @@ begin
     InternalError('Extract7ZipArchive: Invalid ArchiveFileName value');
   if DestDir = '' then
     InternalError('Extract7ZipArchive: Invalid DestDir value');
+  if Password <> '' then
+    InternalError('Extract7ZipArchive: Invalid Password value');
 
   LogFmt('Extracting 7-Zip archive %s to %s. Full paths? %s', [ArchiveFileName, DestDir, SYesNo[FullPaths]]);
 
-  if Password <> '' then begin
-    Log('ERROR: Password not supported by basic archive extraction'); { Just like 7zMain.c }
-    raise Exception.Create(FmtSetupMessage(msgErrorExtractionFailed, ['-2']))
-  end else if not ForceDirectories(DisableFsRedir, DestDir) then begin
-    Log('ERROR: Failed to create destination directory'); { Just like 7zMain.c }
-    raise Exception.Create(FmtSetupMessage(msgErrorExtractionFailed, ['-1']));
+  try
+    if not ForceDirectories(DisableFsRedir, DestDir) then
+      SevenZipError(FmtSetupMessage1(msgErrorCreatingDir, DestDir), 'Failed to create destination directory');
+
+    State.DisableFsRedir := DisableFsRedir;
+    State.ExpandedArchiveFileName := PathExpand(ArchiveFileName);
+    State.ExpandedDestDir := AddBackslash(PathExpand(DestDir));
+    State.LogBuffer := '';
+    State.ExtractedArchiveName := PathExtractName(ArchiveFileName);
+    State.OnExtractionProgress := OnExtractionProgress;
+    State.LastReportedProgress := 0;
+    State.LastReportedProgressMax := 0;
+    State.Aborted := False;
+
+    var Res := IS_7zDec(PChar(ArchiveFileName), FullPaths);
+
+    if State.LogBuffer <> '' then
+      Log(State.LogBuffer);
+
+    if State.Aborted then
+      Abort
+    else if Res <> 0 then
+      BadResultError(Res);
+  except
+    on E: EAbort do
+      raise ESevenZipError.Create(SetupMessages[msgErrorExtractionAborted])
+    else
+      raise ESevenZipError.Create(FmtSetupMessage1(msgErrorExtractionFailed, GetExceptMessage));
   end;
-
-  State.DisableFsRedir := DisableFsRedir;
-  State.ExpandedArchiveFileName := PathExpand(ArchiveFileName);
-  State.ExpandedDestDir := AddBackslash(PathExpand(DestDir));
-  State.LogBuffer := '';
-  State.ExtractedArchiveName := PathExtractName(ArchiveFileName);
-  State.OnExtractionProgress := OnExtractionProgress;
-  State.LastReportedProgress := 0;
-  State.LastReportedProgressMax := 0;
-  State.Aborted := False;
-
-  var Res := IS_7zDec(PChar(ArchiveFileName), FullPaths);
-
-  if State.LogBuffer <> '' then
-    Log(State.LogBuffer);
-
-  if State.Aborted then
-    raise Exception.Create(SetupMessages[msgErrorExtractionAborted])
-  else if Res <> 0 then
-    raise Exception.Create(FmtSetupMessage(msgErrorExtractionFailed, [Res.ToString])); { Already logged by 7zMain.c }
 end;
 
 end.

BIN
Projects/Src/Compression.SevenZipDecoder/7zDecode/IS7zDec.obj


+ 4 - 4
Projects/Src/Compression.SevenZipDecoder/7zDecode/IS7zDec.obj.issig

@@ -1,6 +1,6 @@
 format issig-v1
-file-size 93692
-file-hash 3984b8b947779519be78c34858a3bd0f5eb75cd166fd5d43102af518bf35d4f7
+file-size 93886
+file-hash 43ef412680232ecf42556737b7ea1c341f8134e64bf0b36932458e97d569d7c5
 key-id def0147c3bbc17ab99bf7b7a9c2de1390283f38972152418d7c2a4a7d7131a38
-sig-r ba2f9ec8f07c76da83c9fb175f82f939e712865069783c151775ba53d0dd00c7
-sig-s 1e56679de72a7ec1493aed723ee77ec0df4ddc469d0505a503d7641850395257
+sig-r 6311ecc5160524349d2ae725ca31f605cfed4452f9b501bc082e6f8a75211106
+sig-s f2162f7b1aae75c9328b79b334d1d66474de3ef417440ceb500a0d83c249f371

+ 2 - 1
Projects/Src/Setup.MainFunc.pas

@@ -246,7 +246,8 @@ uses
   Setup.WizardForm, Setup.DebugClient, Shared.VerInfoFunc, Setup.FileExtractor,
   Shared.FileClass, Setup.LoggingFunc,
   SimpleExpression, Setup.Helper, Setup.SpawnClient, Setup.SpawnServer,
-  Setup.DotNetFunc, Shared.TaskDialogFunc, Setup.MainForm, Compression.SevenZipDLLDecoder;
+  Setup.DotNetFunc, Shared.TaskDialogFunc, Setup.MainForm, Compression.SevenZipDecoder,
+  Compression.SevenZipDLLDecoder;
 
 var
   ShellFolders: array[Boolean, TShellFolderID] of String;

+ 5 - 1
Projects/Src/Shared.SetupMessageIDs.pas

@@ -2,7 +2,7 @@ unit Shared.SetupMessageIDs;
 
 {
   Inno Setup
-  Copyright (C) 1997-2020 Jordan Russell
+  Copyright (C) 1997-2025 Jordan Russell
   Portions by Martijn Laan
   For conditions of distribution and use, see LICENSE.TXT.
 
@@ -122,6 +122,10 @@ type
     msgExistingFileReadOnlyKeepExisting,
     msgExitSetupMessage,
     msgExitSetupTitle,
+    msgExtractArchiveIncorrectPassword,
+    msgExtractArchiveIsCorrupted,
+    msgExtractArchiveOutOfMemory,
+    msgExtractArchiveUnsupportedFormat,
     msgExtractionLabel,
     msgFileAbortRetryIgnoreSkipNotRecommended,
     msgFileAbortRetryIgnoreIgnoreNotRecommended,

+ 1 - 1
Projects/Src/Shared.Struct.pas

@@ -36,7 +36,7 @@ const
   SetupID: TSetupID = 'Inno Setup Setup Data (6.5.0)';
   UninstallLogID: array[Boolean] of TUninstallLogID =
     ('Inno Setup Uninstall Log (b)', 'Inno Setup Uninstall Log (b) 64-bit');
-  MessagesHdrID: TMessagesHdrID = 'Inno Setup Messages (6.4.0) (u)';
+  MessagesHdrID: TMessagesHdrID = 'Inno Setup Messages (6.5.0) (u)';
   MessagesLangOptionsID: TMessagesLangOptionsID = '!mlo!001';
   ZLIBID: TCompID = 'zlb'#26;
   DiskSliceID: TDiskSliceID = 'idska32'#26;