Recent

Author Topic: TUnZipper and / \ delimiter  (Read 10105 times)

Mando

  • Full Member
  • ***
  • Posts: 181
TUnZipper and / \ delimiter
« on: November 03, 2010, 05:39:43 pm »
Hello all:

I'm developing a zip, odt files explorer. There are some files (zip) that I can explore and unzip them but others, I can explore them but I can not unzip them. The program causes a 'EFCreateError' exception with the message:
Unable to create file "z:\unzip/folder/file01.txt"

because the path of files inside the zip/odt archive is formed with / instead of \.

Anyone knows the way to solve this?
i'm using windows 7,
lazarus 0.9.29 - FPC 2.4.0 - SVN:27358 - Date: 2010-09-14
TUnZipper
regards.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4474
  • I like bugs.
Re: TUnZipper and / \ delimiter
« Reply #1 on: November 03, 2010, 09:22:06 pm »
I'm developing a zip, odt files explorer. There are some files (zip) that I can explore and unzip them but others, I can explore them but I can not unzip them. The program causes a 'EFCreateError' exception with the message:
Unable to create file "z:\unzip/folder/file01.txt"

because the path of files inside the zip/odt archive is formed with / instead of \.

Anyone knows the way to solve this?
i'm using windows 7,
lazarus 0.9.29 - FPC 2.4.0 - SVN:27358 - Date: 2010-09-14
TUnZipper

According to the zip file specification "/" is the path separator.
If your zip file uses "\" character instead, then it is technically an invalid file.
However, many zip programs and libraries accept "\", too.

Are you sure the problem is related to unzipping at all? Do you have drive z:? Do you have write access there?
IIRC Windows itself accepts both "/" and "\" as path separators in many situations.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

bonmario

  • Sr. Member
  • ****
  • Posts: 346
Re: TUnZipper and / \ delimiter
« Reply #2 on: November 04, 2010, 05:33:10 am »
It's related with this? http://mantis.freepascal.org/view.php?id=7604

Hi, Mario

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: TUnZipper and / \ delimiter
« Reply #3 on: November 04, 2010, 06:42:20 am »
Quote
...because the path of files inside the zip/odt archive is formed with / instead of \.
perfectly normal.

Quote
Anyone knows the way to solve this?
StringReplace()

Mando

  • Full Member
  • ***
  • Posts: 181
Re: TUnZipper and / \ delimiter (SOLVED)
« Reply #4 on: November 04, 2010, 08:18:28 am »
Thanks all for your responses:

JuhaManninen:
Quote
According to the zip file specification "/" is the path separator.
Ok. Then, Why TUnZipper cannot unzips the archive?

My program only do this:

Code: [Select]
procedure TForm1.Button5Click(Sender: TObject);
var FunZipper:TUnZipper;
     Ruta: string;
begin

  if OpenDialog1.execute then
  begin
    Ruta:=extractfilepath(openDialog1.FileName)+'unzip\';
 
    FUnZipper:=TUnZipper.create;
    FUNzipper.OutputPath:=Ruta;
    FUnZipper.FileName:=openDialog1.FileName;
    FUnzipper.UnZipAllFiles;
    FUnZipper.Free;

  end;
end;         


Ivan17:
I'd tried StringReplace, but with an auxiliar StringList instead of FUnZipper.Entries directly.

This is the code I use now:
Code: [Select]
procedure TForm1.Button6Click(Sender: TObject);
var FunZipper:TUnZipper;
    Ruta: string;
    i: Integer;
begin

  if OpenDialog1.execute then
  begin
    Ruta:=extractfilepath(openDialog1.FileName)+'unzip\';

    FUnZipper:=TUnZipper.create;
    FUNzipper.OutputPath:=Ruta;
    FUnZipper.FileName:=openDialog1.FileName;
    Funzipper.Examine;

    showmessagefmt('%d archivos',[FUnZipper.Entries.Count]);

    memo1.Clear;

    for i:=0 to FUnZipper.Entries.Count-1 do
    begin
       FUnZipper.Entries[i].ArchiveFileName:=StringReplace(FUnZipper.Entries[i].ArchiveFileName,'/','\',[rfReplaceAll]);
       memo1.Lines.add(FUnZipper.Entries[i].ArchiveFileName);
    end;
    FUnzipper.UnZipAllFiles;
    FUnZipper.Free;

  end;

end;

It works properly... but I still do not understand why no TUnZipper extract the files, automatically replacing path delimiters.


Thanks all, regards.


JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4474
  • I like bugs.
Re: TUnZipper and / \ delimiter (SOLVED)
« Reply #5 on: November 04, 2010, 09:13:49 am »
Ok. Then, Why TUnZipper cannot unzips the archive?

Because it has a bug apparently. Who maintains it?

Zip is a cross-platform format and the lib should take care of path delimiters.
I didn't find the ZIP standard definition in net but I know this related KDE bug report:
  https://bugs.kde.org/show_bug.cgi?id=176646

Some archive programs generate invalid files (wrong delimiter) but in your case that was not the problem. The zip file itself was correct.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Mando

  • Full Member
  • ***
  • Posts: 181
Re: TUnZipper and / \ delimiter
« Reply #6 on: November 04, 2010, 09:51:13 am »
SORRY GUYS:

Doesn't work!!!!!!!!.

I check my program with a "bad-built" archive, with "\" as path delimiter.

...but

I find the solution:

I commented the line #1517 on zipper.pp

Code: [Select]
//***AllowDirectorySeparators:=[DirectorySeparator];
Now It works, at least on windows.

Regards.






« Last Edit: November 04, 2010, 10:39:23 am by Mando »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4474
  • I like bugs.
Re: TUnZipper and / \ delimiter
« Reply #7 on: November 04, 2010, 12:00:28 pm »
I check my program with a "bad-built" archive, with "\" as path delimiter.

What program generated such archive? Send a bug report to there.

Juha
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Mando

  • Full Member
  • ***
  • Posts: 181
Re: TUnZipper and / \ delimiter
« Reply #8 on: November 05, 2010, 02:09:02 am »
Hello, JuhaManninen:

That file is one I downloaded from internet, I don´t remind
 where... sorry.


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11459
  • FPC developer.
Re: TUnZipper and / \ delimiter
« Reply #9 on: November 05, 2010, 08:47:48 pm »

Code: [Select]
//***AllowDirectorySeparators:=[DirectorySeparator];
Now It works, at least on windows.




What happens if you put

Code: [Select]
AllowDirectorySeparators:=['/','\'];
as first line in your source?

 

TinyPortal © 2005-2018