Skip to content

Commit

Permalink
fixed PasZip on Win64
Browse files Browse the repository at this point in the history
- as reported by #458
  • Loading branch information
Arnaud Bouchez committed Dec 2, 2024
1 parent b385c61 commit f7372b8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
57 changes: 29 additions & 28 deletions PasZip.pas
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ function CompressString(const data: RawByteZip; failIfGrow: boolean = false): Ra
/// uncompress memory using the ZLib INFLATE algorithm, checking crc32 checksum
function UncompressString(const data: RawByteZip): RawByteZip;

/// create a void .zip file
procedure CreateVoidZip(const aFileName: TFileName);

{$ifdef MSWINDOWS} { use Windows MapFile }

Expand Down Expand Up @@ -108,9 +110,6 @@ function IsCompressedFileEqual(const uncomprFile, comprFile: TFileName): boolean
function Zip(const zip: TFileName; const files, zipAs: array of TFileName;
NoSubDirectories: boolean = false): boolean;

/// create a void .zip file
procedure CreateVoidZip(const aFileName: TFileName);

{$endif MSWINDOWS}

/// create a compatible .gz file (returns file size)
Expand Down Expand Up @@ -3796,6 +3795,21 @@ function UncompressString(const data: RawByteZip): RawByteZip;
result := '';
end;

procedure CreateVoidZip(const aFileName: TFileName);
var
H: THandle;
lhr: TLastHeader;
begin
fillchar(lhr, sizeof(lhr), 0);
lhr.signature := $06054b50 + 1;
dec(lhr.signature); // +1 to avoid finding it in the exe
H := FileCreate(aFileName);
if H < 0 then
exit;
FileWrite(H, lhr, sizeof(lhr));
FileClose(H);
end;


{$ifdef MSWINDOWS}

Expand All @@ -3806,8 +3820,8 @@ function UncompressString(const data: RawByteZip): RawByteZip;

function CompressFile(const srcFile, dstFile: TFileName; failIfGrow: boolean): boolean;
var
sf, df: dword;
sm, dm: dword;
sf, df: THandle;
sm, dm: THandle;
sb, db: pointer;
sl, dl: int64;
err: dword;
Expand Down Expand Up @@ -3881,8 +3895,8 @@ function CompressFile(const srcFile, dstFile: TFileName; failIfGrow: boolean): b
function UncompressFile(const srcFile, dstFile: TFileName; lastWriteTime: int64;
attr: dword): boolean;
var
sf, df: dword;
sm, dm: dword;
sf, df: THandle;
sm, dm: THandle;
sb, db: pointer;
sl, dl: int64;
err: dword;
Expand Down Expand Up @@ -3962,14 +3976,15 @@ function IsCompressedFileEqual(const uncomprFile, comprFile: TFileName): boolean
crc1, crc2: dword;
begin
result := GetCompressedFileInfo(comprFile, size1, crc1) and
GetUncompressedFileInfo(uncomprFile, size2, crc2) and (size1 = size2) and
(crc1 = crc2);
GetUncompressedFileInfo(uncomprFile, size2, crc2) and
(size1 = size2) and
(crc1 = crc2);
end;

function GetCompressedFileInfo(const comprFile: TFileName; var size: int64;
var crc32: dword): boolean;
var
file_: dword;
file_: THandle;
c1: dword;
begin
result := false;
Expand All @@ -3986,7 +4001,7 @@ function GetCompressedFileInfo(const comprFile: TFileName; var size: int64;
function GetUncompressedFileInfo(const uncomprFile: TFileName; var size: int64;
var crc32: dword): boolean;
var
file_, map: dword;
file_, map: THandle;
buf: pointer;
begin
result := false;
Expand Down Expand Up @@ -4049,12 +4064,13 @@ function GzCompress(src: pointer; srcLen: integer; const fName: TFileName): card


{$ifdef MSWINDOWS}

function Zip(const zip: TFileName; const files, zipAs: array of TFileName;
NoSubDirectories: boolean = false): boolean;
var
i1, i2, i3: integer;
dstFh: dword;
srcFh: dword;
dstFh: THandle;
srcFh: THandle;
ft: TFileTime;
c1: dword;
lfhr: TLocalFileHeader;
Expand Down Expand Up @@ -4170,21 +4186,6 @@ function Zip(const zip: TFileName; const files, zipAs: array of TFileName;
end;
end;

procedure CreateVoidZip(const aFileName: TFileName);
var
H: THandle;
lhr: TLastHeader;
begin
fillchar(lhr, sizeof(lhr), 0);
lhr.signature := $06054b50 + 1;
dec(lhr.signature); // +1 to avoid finding it in the exe
H := FileCreate(aFileName);
if H < 0 then
exit;
FileWrite(H, lhr, sizeof(lhr));
FileClose(H);
end;

{$endif MSWINDOWS}

{$ifdef DYNAMIC_CRC_TABLE}
Expand Down
2 changes: 1 addition & 1 deletion SynopseCommit.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'1.18.7656'
'1.18.7657'

0 comments on commit f7372b8

Please sign in to comment.