Browse Source

Improve various 7-zip.

Martijn Laan 11 months ago
parent
commit
0a71d3bbe1

+ 2 - 1
ISHelp/isxfunc.xml

@@ -1837,7 +1837,8 @@ end;</pre>
       <function>
       <function>
         <name>Extract7ZipFile</name>
         <name>Extract7ZipFile</name>
         <prototype>function Extract7ZipFile(const FileName, DestDir: String; const FullPaths: Boolean): Integer;</prototype>
         <prototype>function Extract7ZipFile(const FileName, DestDir: String; const FullPaths: Boolean): Integer;</prototype>
-        <description><p>Extracts the specified 7-Zip archive to the specified directory, with or without using path names. Returns zero if successful, nonzero otherwise.</p></description>
+        <description><p>Extracts the specified 7-Zip archive to the specified directory, with or without using path names. Returns zero if successful, nonzero otherwise</p>
+<p>The archive must not be encrypted.</p></description>
         <remarks><p>Uses an embedded version of the &quot;7z ANSI-C Decoder&quot; from the LZMA SDK by Igor Pavlov, as-is, except that Unicode support was improved.</p>
         <remarks><p>Uses an embedded version of the &quot;7z ANSI-C Decoder&quot; from the LZMA SDK by Igor Pavlov, as-is, except that Unicode support was improved.</p>
 <p>All output of the decoder is logged if logging is enabled, including error messages but excluding empty lines.</p>
 <p>All output of the decoder is logged if logging is enabled, including error messages but excluding empty lines.</p>
 <p>The decoder has the following limitations, as written by Igor Pavlov in the LZMA SDK:<br /><br />
 <p>The decoder has the following limitations, as written by Igor Pavlov in the LZMA SDK:<br /><br />

+ 7 - 10
Projects/Src/Compression.LZMADecompressor.pas

@@ -58,20 +58,17 @@ type
     procedure ProcessHeader; override;
     procedure ProcessHeader; override;
   end;
   end;
 
 
+implementation
+
+type
+  TLZMASRes = type Integer;
+
   PLZMAISzAlloc = ^TLZMAISzAlloc;
   PLZMAISzAlloc = ^TLZMAISzAlloc;
   TLZMAISzAlloc = record
   TLZMAISzAlloc = record
     Alloc: function(p: PLZMAISzAlloc; size: Cardinal): Pointer; cdecl;
     Alloc: function(p: PLZMAISzAlloc; size: Cardinal): Pointer; cdecl;
     Free: procedure(p: PLZMAISzAlloc; address: Pointer); cdecl;
     Free: procedure(p: PLZMAISzAlloc; address: Pointer); cdecl;
   end;
   end;
 
 
-function LZMAAllocFunc(unused: PLZMAISzAlloc; size: Cardinal): Pointer; cdecl;
-procedure LZMAFreeFunc(unused: PLZMAISzAlloc; address: Pointer); cdecl;
-
-implementation
-
-type
-  TLZMASRes = type Integer;
-
 const
 const
   { SRes (TLZMASRes) }
   { SRes (TLZMASRes) }
   SZ_OK = 0;
   SZ_OK = 0;
@@ -137,7 +134,7 @@ begin
   raise ECompressDataError.CreateFmt(SLZMADecompDataError, [Id]);
   raise ECompressDataError.CreateFmt(SLZMADecompDataError, [Id]);
 end;
 end;
 
 
-function LZMAAllocFunc(unused: PLZMAISzAlloc; size: Cardinal): Pointer; cdecl;
+function LZMAAllocFunc(p: PLZMAISzAlloc; size: Cardinal): Pointer; cdecl;
 begin
 begin
   if (size <> 0) and (size <= Cardinal(MaxDictionarySize)) then
   if (size <> 0) and (size <= Cardinal(MaxDictionarySize)) then
     Result := VirtualAlloc(nil, size, MEM_COMMIT, PAGE_READWRITE)
     Result := VirtualAlloc(nil, size, MEM_COMMIT, PAGE_READWRITE)
@@ -145,7 +142,7 @@ begin
     Result := nil;
     Result := nil;
 end;
 end;
 
 
-procedure LZMAFreeFunc(unused: PLZMAISzAlloc; address: Pointer); cdecl;
+procedure LZMAFreeFunc(p: PLZMAISzAlloc; address: Pointer); cdecl;
 begin
 begin
   if Assigned(address) then
   if Assigned(address) then
     VirtualFree(address, 0, MEM_RELEASE);
     VirtualFree(address, 0, MEM_RELEASE);

+ 13 - 4
Projects/Src/Compression.SevenZipDecoder.pas

@@ -18,7 +18,7 @@ function SevenZipDecode(const FileName, DestDir: String;
 implementation
 implementation
 
 
 uses
 uses
-  Windows, SysUtils, Compression.LZMADecompressor, Setup.LoggingFunc;
+  Windows, SysUtils, Setup.LoggingFunc;
 
 
 { Compiled by Visual Studio 2022 using compile.bat
 { Compiled by Visual Studio 2022 using compile.bat
   To enable source debugging recompile using compile-bcc32c.bat and turn off the VISUALSTUDIO define below
   To enable source debugging recompile using compile-bcc32c.bat and turn off the VISUALSTUDIO define below
@@ -138,14 +138,23 @@ begin
   Result := dest;
   Result := dest;
 end;
 end;
 
 
-function _malloc(size: Cardinal): Pointer; cdecl;
+function _malloc(size: NativeUInt): Pointer; cdecl;
 begin
 begin
-  Result := LZMAAllocFunc(nil, size);
+  if size > High(NativeInt) then
+    Result := nil
+  else begin
+    try
+      GetMem(Result, NativeInt(size));
+    except
+      on EOutOfMemory do
+        Result := nil;
+    end;
+  end;
 end;
 end;
 
 
 procedure _free(address: Pointer); cdecl;
 procedure _free(address: Pointer); cdecl;
 begin
 begin
-  LZMAFreeFunc(nil, address);
+  FreeMem(address);
 end;
 end;
 
 
 function _wcscmp(string1, string2: PChar): Integer; cdecl;
 function _wcscmp(string1, string2: PChar): Integer; cdecl;