#1 Re: Low level and performance » How to unzip or zip files content » 2017-03-30 19:10:33

I use SynZip.pas on Lazarus. When I create zip archive with unicode filenames, it work fine, but when unzip, have error. After some changes in SynZip.pas I have support for unicode names in zip archive.
1) In uses add LazFileUtils
2) In constructor TZipRead.Create(const aFileName: TFileName; ZipStartOffset, Size: cardinal);
replace string

file_ := CreateFile(pointer(aFileName), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);

with

file_ := CreateFileW(PWideChar(WideString(aFileName)), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);

result

constructor TZipRead.Create(const aFileName: TFileName; ZipStartOffset, Size: cardinal);
begin
   file_ := CreateFileW(PWideChar(WideString(aFileName)), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);
   Create(file_,ZipStartOffset, Size);
end;

3) In function EnsurePath(var Path: TFileName): boolean
replace strings

   if DirectoryExists(Path) then
...
   if CreateDirectory(pointer(path),nil) then

with

   if DirectoryExistsUTF8(Path) then
...
   if CreateDirectoryW(PWideChar(WideString(path)),nil) then

result

function EnsurePath(var Path: TFileName): boolean;
var Parent: TFileName;
begin
  result := false;
  if Path='' then exit;
  if Path[length(Path)]<>'\' then
    Path := Path+'\';
  if DirectoryExistsUTF8(Path) then
    result := true else begin
    Parent := ExtractFilePath(system.copy(Path,1,length(Path)-1));
    if (Parent<>'') and not DirectoryExists(Parent) then
      if not EnsurePath(Parent) then exit;
    if CreateDirectoryW(PWideChar(WideString(path)),nil) then
      result := true;
  end;
end;

After this changes I can unzip files with unicode filenames

Board footer

Powered by FluxBB