Prechádzať zdrojové kódy

Embed the test application code. So now we can extract 7zip archives with basically zero extra code by us.

The overhead is basically zero: before inclusion a compiled Example1.iss is 1.75 MB and after inclusion it's 1.77 MB. I'm sure it's fully included since it extracts an external archive.

The code's output is redirected to the log and its limits are as documented by 7zC.txt:

"- It reads only "FileName", "Size", "LastWriteTime" and "CRC" information for each file in archive.
 - It supports only LZMA and Copy (no compression) methods with BCJ or BCJ2 filters.
 - It converts original UTF-16 Unicode file names to UTF-8 Unicode file names.

These limitations will be fixed in future versions."

Also: it's not fully Unicode? Not sure if this is my fault or not.

Todo:
-It needs to collect output strings and watch for newlines before directly calling Log, much/just like output logging.
-If the OBJ is compiled with Visual Studio then the Delphi compile doesn't work: it complains about missing the various Windows functions used. For the OBJ compiled with bcc32c this was solved by just doing 'uses Windows'.
-Am unsure if it now contains two copies of the LZMA/LZMA decompression code, one from IS7ZipDec.obj and the other from ISLzmaDec/ISLzma2Dec.obj.
-Test the FullPaths parameter.
Martijn Laan 11 mesiacov pred
rodič
commit
f0290f699a

+ 83 - 0
Projects/Src/Compression.SevenZipDecoder.pas

@@ -0,0 +1,83 @@
+unit Compression.SevenZipDecoder;
+
+{
+  Inno Setup
+  Copyright (C) 1997-2024 Jordan Russell
+  Portions by Martijn Laan
+  For conditions of distribution and use, see LICENSE.TXT.
+
+  Interface to the 7-Zip Decoder OBJ in Compression.SevenZipDecoder\7ZipDecode,
+  used by Setup.
+}
+
+interface
+
+procedure SevenZipDecode(const FileName: AnsiString; const DestDir: String;
+  const FullPaths: Boolean);
+
+implementation
+
+uses
+  Windows, SysUtils, Setup.LoggingFunc;
+
+{$L Src\Compression.SevenZipDecoder\7ZipDecode\IS7ZipDec.obj}
+
+function IS_7ZipDec(const fileName: PAnsiChar; const fullPaths: Bool): Integer; cdecl; external name '_IS_7ZipDec';
+
+{.$DEFINE VISUALSTUDIO}
+
+//https://github.com/rust-lang/compiler-builtins/issues/403
+{$IFDEF VISUALSTUDIO}
+procedure __allshl; register; external 'ntdll.dll' name '_allshl';
+procedure __aullshr; register; external 'ntdll.dll' name '_aullshr';
+{$ENDIF}
+procedure __aullrem; stdcall; external 'ntdll.dll' name '_aullrem';
+procedure __aulldiv; stdcall; external 'ntdll.dll' name '_aulldiv';
+
+function _memcpy(dest, src: Pointer; n: Cardinal): Pointer; cdecl;
+begin
+  Move(src^, dest^, n);
+  Result := dest;
+end;
+
+function _memset(dest: Pointer; c: Integer; n: Cardinal): Pointer; cdecl;
+begin
+  FillChar(dest^, n, c);
+  Result := dest;
+end;
+
+function _malloc(size: Cardinal): Pointer; cdecl;
+begin
+  if size <> 0 then
+    Result := VirtualAlloc(nil, size, MEM_COMMIT, PAGE_READWRITE)
+  else
+    Result := nil;
+end;
+
+procedure _free(address: Pointer); cdecl;
+begin
+  if Assigned(address) then
+    VirtualFree(address, 0, MEM_RELEASE);
+end;
+
+function _strcmp(string1, string2: PAnsiChar): Integer; cdecl;
+begin
+  Result := StrComp(string1, string2);
+end;
+
+function _fputs(str: PAnsiChar; unused: Pointer): Integer; cdecl;
+begin
+  Log(String(str));
+  Result := 1;
+end;
+
+procedure SevenZipDecode(const FileName: AnsiString; const DestDir: String;
+  const FullPaths: Boolean);
+begin
+  var SaveCurDir := GetCurrentDir;
+  SetCurrentDir(DestDir);
+  IS_7ZipDec(PAnsiChar(FileName), FullPaths);
+  SetCurrentDir(SaveCurDir);
+end;
+
+end.

+ 30 - 0
Projects/Src/Compression.SevenZipDecoder/7ZipDecode/IS7ZipDec.c

@@ -0,0 +1,30 @@
+/*
+  IS7ZipDec.c, by Martijn Laan for Inno Setup
+  This file is public domain (like the LZMA SDK)
+*/
+
+#include "../../../../Components/Lzma2/Util/7z/7zMain.c"
+
+#include "../../../../Components/Lzma2/7zAlloc.c"
+#include "../../../../Components/Lzma2/7zArcIn.c"
+#include "../../../../Components/Lzma2/7zBuf.c"
+#include "../../../../Components/Lzma2/7zCrc.c"
+#include "../../../../Components/Lzma2/7zCrcOpt.c"
+#include "../../../../Components/Lzma2/7zDec.c"
+#include "../../../../Components/Lzma2/7zFile.c"
+#include "../../../../Components/Lzma2/7zStream.c"
+#include "../../../../Components/Lzma2/Bcj2.c"
+#include "../../../../Components/Lzma2/Bra.c"
+#include "../../../../Components/Lzma2/Bra86.c"
+#include "../../../../Components/Lzma2/Delta.c"
+#include "../../../../Components/Lzma2/LzmaDec.c"
+#include "../../../../Components/Lzma2/Lzma2Dec.c"
+
+int IS_7ZipDec(char *fileName, BOOL fullPaths)
+{
+  char* args[3];
+  args[0] = "";
+  args[1] = fullPaths?"x":"e";
+  args[2] = fileName;
+  return main(3, args);
+}

BIN
Projects/Src/Compression.SevenZipDecoder/7ZipDecode/IS7ZipDec.obj


+ 43 - 0
Projects/Src/Compression.SevenZipDecoder/7ZipDecode/compile-bcc32c.bat

@@ -0,0 +1,43 @@
+@echo off
+
+rem  Inno Setup
+rem  Copyright (C) 1997-2024 Jordan Russell
+rem  Portions by Martijn Laan
+rem  For conditions of distribution and use, see LICENSE.TXT.
+rem
+rem  Batch file to compile IS7ZipDec.c using Embarcadero's free
+rem  C++ compiler from https://www.embarcadero.com/free-tools/ccompiler
+rem  with source debugging turned on
+
+setlocal
+
+cd /d %~dp0
+
+if exist compilesettings.bat goto compilesettingsfound
+:compilesettingserror
+echo compilesettings.bat is missing or incomplete. It needs to be created
+echo with the following line, adjusted for your system:
+echo.
+echo   set BCCROOT=C:\BCC102
+goto failed2
+
+:compilesettingsfound
+set BCCROOT=
+call .\compilesettings.bat
+if "%BCCROOT%"=="" goto compilesettingserror
+
+rem -------------------------------------------------------------------------
+
+echo - Compiling IS7ZipDec.c
+"%BCCROOT%\bin\bcc32c.exe" -c -O2 -v IS7ZipDec.c
+if errorlevel 1 goto failed
+
+echo Success!
+goto exit
+
+:failed
+echo *** FAILED ***
+:failed2
+exit /b 1
+
+:exit

+ 49 - 0
Projects/Src/Compression.SevenZipDecoder/7ZipDecode/compile.bat

@@ -0,0 +1,49 @@
+@echo off
+
+rem  Inno Setup
+rem  Copyright (C) 1997-2024 Jordan Russell
+rem  Portions by Martijn Laan
+rem  For conditions of distribution and use, see LICENSE.TXT.
+rem
+rem  Batch file to compile IS7ZipDec.c
+
+setlocal
+
+cd /d %~dp0
+
+if exist compilesettings.bat goto compilesettingsfound
+:compilesettingserror
+echo compilesettings.bat is missing or incomplete. It needs to be created
+echo with the following line, adjusted for your system:
+echo.
+echo   set VSTOOLSROOT=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools
+goto failed2
+
+:compilesettingsfound
+set VSTOOLSROOT=
+call .\compilesettings.bat
+if "%VSTOOLSROOT%"=="" goto compilesettingserror
+
+rem -------------------------------------------------------------------------
+
+set __VSCMD_ARG_NO_LOGO=1
+set VSCMD_SKIP_SENDTELEMETRY=1
+
+echo - Calling VsDevCmd.bat
+call "%VSTOOLSROOT%\VsDevCmd.bat"
+if errorlevel 1 goto exit
+echo.
+
+echo - Compiling IS7ZipDec.c
+cl.exe /c /O2 /GS- IS7ZipDec.c
+if errorlevel 1 goto failed
+
+echo Success!
+goto exit
+
+:failed
+echo *** FAILED ***
+:failed2
+exit /b 1
+
+:exit