Re: Reading Zip file contents without DLL's... How?
From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 01/03/04
- Next message: Martin Pagnan: "Re: Paradox table picture statement - DBGRID delimma"
- Previous message: Maarten Wiltink: "Re: Delphi 8: Confusion"
- In reply to: Link: "Re: Reading Zip file contents without DLL's... How?"
- Next in thread: AlanGLLoyd: "Re: Reading Zip file contents without DLL's... How?"
- Reply: AlanGLLoyd: "Re: Reading Zip file contents without DLL's... How?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 3 Jan 2004 22:15:03 +0100
"Link" <mickeym@NOSPAM.go.to> wrote in message
news:3ff60c51$0$69960$edfadb0f@dread12.news.tele.dk...
>>> FileSeek(ZipFile,26,0);
>>
>> Zero. How illuminating.
>
> If we can trust the documentation, this searches to byte 26 from the
> beginning of the file. The syntax is FileSeek(Handle, Offset, Origin),
> where a value of 0 for Origin means from the beginning of the file.
Yes, that's what it says. That doesn't make me any happier about it.
There should be some constants defined somewhere, and documented with
FileSeek.
[...]
>>> FileRead(ZipFile,ExtSizePointer^,2);
>>> FileSeek(ZipFile,30,0);
>>> NameSize:=integer(ExtSizePointer);
>>
>> No, ExtNamePointer^.
>
> Why? The data comes from the above FileRead, which SHOULD assign a
> value of 50 to ExtSizePointer. And ExtNamePointer isn't allocated
> memory until this next line:
Curses. My mistake. I meant "No, ExtSizePointer^". Dereference the
pointer, do not cast it to an integer.
[...]
> The difference between this and the sample code this was based from,
> is that I use a PString, rather than a PChar. Does that really make
> any difference? Isn't a PChar just a PString that can only contain
> 1 character?
Pointers do not contain things; they point to them. (Actually, of course,
they contain memory addresses.)
A PChar points to a single character, but through pointer arithmetic you
can change what character it points to. Adding one to a PChar value will
give you a new pointer that points to the _next_ character. Please think
about this; it's quite fundamental and important. Adding one to a PChar
variable will make the variable point to the next character (- change the
value in the variable to one that points to the next character).
A PString value points to a (long) string value, which in Delphi is a
pointer itself and is not yours to manage. String variables may be used
_as strings_ in your code and the Delphi run-time system will manage the
memory containing the strings, and the pointer in the variable that points
to it, for you. At this point, you should remember two things: that strings
are _strings_ at the language level, and that pointers to strings are not
useful for your current purpose.
[...]
>> Assuming that there's a 4-byte length at offset 26, and a string buffer
>> of the indicated length at offset 30, this code might work (untested):
>>
>> function FirstFilenameInZipfile(const ArchiveFilename: String): String;
>> var
>> Archive: File;
>> Length: Integer;
>> begin
>> Assign(Archive, ArchiveFilename); Reset(Archive);
>> try
>> Seek(Archive, 26);
>> BlockRead(Archive, Length, SizeOf(Length));
>> SetLength(Result, Length);
>> BlockRead(Archive, Result[1], Length);
>> finally
>> Close(Archive);
>> end;
>> end;
> After a few modifications to adapt it to my need (changing Length to
> a Word, adding a seek to skip the 2 bytes between the things to read,
> reading the filename to a separate string, and processing that string),
> it still doesn't work, setting Length to a value of 63975 (should be 50).
More curses. Error checking would have been nice at this point; the
problem is in the default record size assumed by Reset and proper testing
would have revealed that no data were in fact read.
Amend code to "Reset(Archive, 1);".
> Also, I can't seem to find any help entry for your usage of Seek.
Type "seek", press F1, read help.
Groetjes,
Maarten Wiltink
- Next message: Martin Pagnan: "Re: Paradox table picture statement - DBGRID delimma"
- Previous message: Maarten Wiltink: "Re: Delphi 8: Confusion"
- In reply to: Link: "Re: Reading Zip file contents without DLL's... How?"
- Next in thread: AlanGLLoyd: "Re: Reading Zip file contents without DLL's... How?"
- Reply: AlanGLLoyd: "Re: Reading Zip file contents without DLL's... How?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|