| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- 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, DestDir: String;
- const FullPaths: Boolean);
- implementation
- uses
- Windows, SysUtils, Setup.LoggingFunc;
- { Compiled by Visual Studio 2022 using compile.bat
- To enable source debugging recompile using compile-bcc32c.bat and turn off the VISUALSTUDIO define below
- Note that in a speed test the code produced by bcc32c was about 33% slower }
- {$L Src\Compression.SevenZipDecoder\7zDecode\IS7zDec.obj}
- {$DEFINE VISUALSTUDIO}
- function IS_7zDec(const fileName: PChar; const fullPaths: Bool): Integer; cdecl; external name '_IS_7zDec';
- {$IFDEF VISUALSTUDIO}
- function __CreateDirectoryW(lpPathName: LPCWSTR;
- lpSecurityAttributes: PSecurityAttributes): BOOL; cdecl;
- begin
- Result := CreateDirectoryW(lpPathName, lpSecurityAttributes);
- end;
- { Never actually called but still required by the linker }
- function __CreateFileA(lpFileName: LPCSTR; dwDesiredAccess, dwShareMode: DWORD;
- lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
- hTemplateFile: THandle): THandle; cdecl;
- begin
- Result := CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
- end;
- function __CreateFileW(lpFileName: LPCWSTR; dwDesiredAccess, dwShareMode: DWORD;
- lpSecurityAttributes: PSecurityAttributes; dwCreationDisposition, dwFlagsAndAttributes: DWORD;
- hTemplateFile: THandle): THandle; cdecl;
- begin
- Result := CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
- end;
- function __FileTimeToLocalFileTime(lpFileTime: PFileTime; var lpLocalFileTime: TFileTime): BOOL; cdecl;
- begin
- Result := FileTimeToLocalFileTime(lpFileTime, lpLocalFileTime);
- end;
- { Never actually called but still required by the linker }
- function __GetFileSize(hFile: THandle; lpFileSizeHigh: Pointer): DWORD; cdecl;
- begin
- Result := GetFileSize(hFile, lpFileSizeHigh);
- end;
- function __ReadFile(hFile: THandle; var Buffer; nNumberOfBytesToRead: DWORD;
- var lpNumberOfBytesRead: DWORD; lpOverlapped: POverlapped): BOOL; cdecl;
- begin
- Result := ReadFile(hFile, Buffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped);
- end;
- function __SetFileAttributesW(lpFileName: LPCWSTR; dwFileAttributes: DWORD): BOOL; cdecl;
- begin
- Result := SetFileAttributesW(lpFileName, dwFileAttributes);
- end;
- function __SetFilePointer(hFile: THandle; lDistanceToMove: Longint;
- lpDistanceToMoveHigh: Pointer; dwMoveMethod: DWORD): DWORD; cdecl;
- begin
- Result := SetFilePointer(hFile, lDistanceToMove, lpDistanceToMoveHigh, dwMoveMethod);
- end;
- function __SetFileTime(hFile: THandle;
- lpCreationTime, lpLastAccessTime, lpLastWriteTime: PFileTime): BOOL; cdecl;
- begin
- Result := SetFileTime(hFile, lpCreationTime, lpLastAccessTime, lpLastWriteTime);
- end;
- function __WriteFile(hFile: THandle; const Buffer; nNumberOfBytesToWrite: DWORD;
- var lpNumberOfBytesWritten: DWORD; lpOverlapped: POverlapped): BOOL; cdecl;
- begin
- Result := WriteFile(hFile, Buffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped);
- end;
- function __CloseHandle(hObject: THandle): BOOL; cdecl;
- begin
- Result := CloseHandle(hObject);
- end;
- function __GetLastError: DWORD; cdecl;
- begin
- Result := GetLastError;
- end;
- function __LocalFree(hMem: HLOCAL): HLOCAL; cdecl;
- begin
- Result := LocalFree(hMem);
- end;
- function __FormatMessageA(dwFlags: DWORD; lpSource: Pointer; dwMessageId: DWORD; dwLanguageId: DWORD;
- lpBuffer: LPSTR; nSize: DWORD; Arguments: Pointer): DWORD; cdecl;
- begin
- Result := FormatMessageA(dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments);
- end;
- function __WideCharToMultiByte(CodePage: UINT; dwFlags: DWORD;
- lpWideCharStr: LPWSTR; cchWideChar: Integer; lpMultiByteStr: LPSTR;
- cchMultiByte: Integer; lpDefaultChar: LPCSTR; lpUsedDefaultChar: PBOOL): Integer; cdecl;
- begin
- Result := WideCharToMultiByte(CodePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cchMultiByte, lpDefaultChar, lpUsedDefaultChar);
- end;
- //https://github.com/rust-lang/compiler-builtins/issues/403
- procedure __allshl; register; external 'ntdll.dll' name '_allshl';
- procedure __aullshr; register; external 'ntdll.dll' name '_aullshr';
- {$ELSE}
- procedure __aullrem; stdcall; external 'ntdll.dll' name '_aullrem';
- procedure __aulldiv; stdcall; external 'ntdll.dll' name '_aulldiv';
- {$ENDIF}
- 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 _wcscmp(string1, string2: PChar): Integer; cdecl;
- begin
- Result := StrComp(string1, string2);
- end;
- function __fputs(str: PAnsiChar; unused: Pointer): Integer; cdecl;
- begin
- Log(UTF8ToString(str));
- Result := 1;
- end;
- procedure SevenZipDecode(const FileName, DestDir: String;
- const FullPaths: Boolean);
- begin
- var SaveCurDir := GetCurrentDir;
- SetCurrentDir(DestDir);
- IS_7zDec(PChar(FileName), FullPaths);
- SetCurrentDir(SaveCurDir);
- end;
- end.
|