From ab10e35fd5aaea8a19e6ca7359f20c6303bbad15 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 11 Jul 2010 12:43:38 +0000 Subject: [PATCH] * added basic reading for ms help 2 the successor to chm git-svn-id: trunk@15548 - --- .gitattributes | 3 + packages/chm/Makefile | 124 +++---- packages/chm/Makefile.fpc | 4 +- packages/chm/fpmake.pp | 16 + packages/chm/src/itolitlsreader.pas | 508 ++++++++++++++++++++++++++++ packages/chm/src/itolitlstypes.pas | 137 ++++++++ packages/chm/src/itsftransform.pas | 442 ++++++++++++++++++++++++ 7 files changed, 1170 insertions(+), 64 deletions(-) create mode 100644 packages/chm/src/itolitlsreader.pas create mode 100644 packages/chm/src/itolitlstypes.pas create mode 100644 packages/chm/src/itsftransform.pas diff --git a/.gitattributes b/.gitattributes index 0ae77c9396..136f07dac5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -998,6 +998,9 @@ packages/chm/src/chmwriter.pas svneol=native#text/plain packages/chm/src/fasthtmlparser.pas svneol=native#text/plain packages/chm/src/htmlindexer.pas svneol=native#text/plain packages/chm/src/htmlutil.pas svneol=native#text/plain +packages/chm/src/itolitlsreader.pas svneol=native#text/plain +packages/chm/src/itolitlstypes.pas svneol=native#text/plain +packages/chm/src/itsftransform.pas svneol=native#text/plain packages/chm/src/lzxcompressthread.pas svneol=native#text/plain packages/chm/src/paslznonslide.pas svneol=native#text/plain packages/chm/src/paslzx.pas svneol=native#text/plain diff --git a/packages/chm/Makefile b/packages/chm/Makefile index 7ddbed148a..abcbc8c4a1 100644 --- a/packages/chm/Makefile +++ b/packages/chm/Makefile @@ -1,5 +1,5 @@ # -# Don't edit, this file is generated by FPCMake Version 2.0.0 [2010/05/27] +# Don't edit, this file is generated by FPCMake Version 2.0.0 [2010/07/11] # default: all MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded avr-embedded armeb-linux armeb-embedded mipsel-linux @@ -450,187 +450,187 @@ ifeq ($(FULL_TARGET),mipsel-linux) override TARGET_PROGRAMS+=chmcmd chmls endif ifeq ($(FULL_TARGET),i386-linux) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-go32v2) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-win32) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-os2) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-freebsd) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-beos) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-haiku) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-netbsd) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-solaris) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-qnx) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-netware) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-openbsd) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-wdosx) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-darwin) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-emx) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-watcom) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-netwlibc) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-wince) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-embedded) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-symbian) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),i386-nativent) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),m68k-linux) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),m68k-freebsd) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),m68k-netbsd) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),m68k-amiga) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),m68k-atari) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),m68k-openbsd) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),m68k-palmos) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),m68k-embedded) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),powerpc-linux) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),powerpc-netbsd) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),powerpc-amiga) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),powerpc-macos) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),powerpc-darwin) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),powerpc-morphos) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),powerpc-embedded) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),sparc-linux) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),sparc-netbsd) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),sparc-solaris) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),sparc-embedded) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),x86_64-linux) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),x86_64-freebsd) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),x86_64-solaris) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),x86_64-darwin) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),x86_64-win64) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),x86_64-embedded) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),arm-linux) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),arm-palmos) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),arm-darwin) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),arm-wince) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),arm-gba) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),arm-nds) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),arm-embedded) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),arm-symbian) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),powerpc64-linux) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),powerpc64-darwin) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),powerpc64-embedded) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),avr-embedded) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),armeb-linux) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),armeb-embedded) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif ifeq ($(FULL_TARGET),mipsel-linux) -override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread +override TARGET_UNITS+=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader endif override INSTALL_FPCPACKAGE=y ifeq ($(FULL_TARGET),i386-linux) diff --git a/packages/chm/Makefile.fpc b/packages/chm/Makefile.fpc index e33ec7393d..1333cdbec7 100644 --- a/packages/chm/Makefile.fpc +++ b/packages/chm/Makefile.fpc @@ -9,7 +9,7 @@ version=2.5.1 [target] units=fasthtmlparser htmlutil paslzx paslzxcomp paslznonslide chmbase chmtypes \ chmspecialfiles chmsitemap chmwriter chmfilewriter chmreader htmlindexer \ - chmfiftimain lzxcompressthread + chmfiftimain lzxcompressthread itolitlstypes itsftransform itolitlsreader programs=chmcmd chmls programs_win32=unblockchm programs_win64=unblockchm @@ -35,4 +35,4 @@ cdmcmd$(EXEEXT): chmcmd.lpr chmls$(EXEEXT): chmls.lpr -unblockchm$(EXEEXT): unblockchm.pp \ No newline at end of file +unblockchm$(EXEEXT): unblockchm.pp diff --git a/packages/chm/fpmake.pp b/packages/chm/fpmake.pp index 4bfc659e70..a4de6c5736 100644 --- a/packages/chm/fpmake.pp +++ b/packages/chm/fpmake.pp @@ -93,6 +93,22 @@ begin begin AddUnit('htmlindexer'); end; + T:=P.Targets.AddUnit('itolitlstypes.pas'); + T:=P.Targets.AddUnit('itsftransform.pas'); + with T.Dependencies do + begin + AddUnit('itolitlstypes'); + AddUnit('paslzx'); + end; + T:=P.Targets.AddUnit('itolitlsreader.pas'); + with T.Dependencies do + begin //chmreader, itolitlstypes, Sysutils, chmbase, itsftransform; + AddUnit('chmbase'); + AddUnit('chmreader'); + AddUnit('itolitlstypes'); + AddUnit('itsftransform'); + + end; // P.ProgramPath.Add('src'); T:=P.Targets.AddProgram('chmls.lpr'); diff --git a/packages/chm/src/itolitlsreader.pas b/packages/chm/src/itolitlsreader.pas new file mode 100644 index 0000000000..ff74b0b81d --- /dev/null +++ b/packages/chm/src/itolitlsreader.pas @@ -0,0 +1,508 @@ +{ Copyright (C) <2009> itloitlsreader.pas + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License + for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +} +{ + See the file COPYING.modifiedLGPL, included in this distribution, + for details about the copyright. +} +unit ITOLITLSReader; + +{$mode objfpc}{$H+} + +{ $DEFINE DEBUG_HELP2} + +interface + +uses + Classes, chmreader, itolitlstypes, Sysutils, chmbase, itsftransform; + +type + + { TITOLITLSReader } + + TITOLITLSReader = class(TITSFReader) + private + FStartStreamPos: QWord; // used when the data we are reading is part of a larger file + SectionNames: TStringList; + function GetStreamPos: Qword; + procedure SetStreamPos(const AValue: Qword); + + private + Header: TITOLITLSHeader; + HeaderSectionTable: array of TITOLITLSHeaderSectionEntry; + PostHeader: TITOLITLSPostHeader; + CAOLHeader: TCAOLRec; + function FileSize: QWord; + function GetChunkType(AStream: TStream): TDirChunkType; + function GetTransform(const AGuid: TGuid): TITSFTransform; + procedure ReadHeader; override; + procedure ReadHeaderEntries; override; + function GetTransforms(ASectionPrefix: String): TITSFTransformList; + + property StreamPos: Qword read GetStreamPos write SetStreamPos; + public + constructor Create(AStream: TStream; FreeStreamOnDestroy: Boolean); override; + destructor Destroy; override; + procedure GetCompleteFileList(ForEach: TFileEntryForEach; AIncludeInternalFiles: Boolean = True); override; + function ObjectExists(Name: String): QWord; override; + function GetObject(Name: String): TMemoryStream; override; + + end; + +implementation + +type + + { TStreamChunk } + + TStreamChunk = class(TStream) + private + FStream: TStream; + FSize: QWord; + FBasePos: QWord; + FPos: QWord; + public + Function GetSize : Int64; Override; + function Read(var Buffer; Count: Longint): Longint; override; + function Seek(Offset: Longint; Origin: Word): Longint; override; + constructor Create(AHostStream: TStream; ABasePos, ASize: QWord); + end; + +{ TStreamChunk } + +function TStreamChunk.GetSize: Int64; +begin + Result:=FSize; +end; + +function TStreamChunk.Read(var Buffer; Count: Longint): Longint; +begin + FStream.Seek(FBasePos+FPos, soFromBeginning); + {$IFDEF DEBUG_HELP2} + //WriteLn('Want Read Count: ', Count,' Pos = ', FPos); + //if FSize - FPos < Count then + // Count := FSize - FPos; + {$ENDIF} + Result := FStream.Read(Buffer, Count); + Inc(FPos, Result); +end; + +function TStreamChunk.Seek(Offset: Longint; Origin: Word): Longint; +var + NewPosition: LongInt; +begin + Case Origin of + soFromBeginning : NewPosition:=Offset; + soFromEnd : NewPosition:=FSize+Offset; + soFromCurrent : NewPosition:=NewPosition+Offset; + end; + {$IFDEF DEBUG_HELP2} + //WriteLn('WantSeek = ', Offset,' Size = ', FSize); + {$ENDIF} + FPos:=NewPosition; + Exit(NewPosition); + if NewPosition < 0 then NewPosition := 0; + if NewPosition >= FSize then NewPosition := FSize-1; + FStream.Position := FBasePos+NewPosition; + Result := FStream.Position - FBasePos; + FPos := Result; + {$IFDEF DEBUG_HELP2} + //WriteLn('Pos = ', fpos); + {$ENDIF} +end; + +constructor TStreamChunk.Create(AHostStream: TStream; ABasePos, ASize: QWord); +begin + FStream := AHostStream; + FBasePos := ABasePos; + FSize := ASize; + {$IFDEF DEBUG_HELP2} + //WriteLn('Created Size = ', FSize, ' Offset = ', ABasePos); + {$ENDIF} +end; + + + +{ TITOLITLSReader } + +function TITOLITLSReader.GetStreamPos: Qword; +begin + Result := fStream.Position-FStartStreamPos; +end; + +procedure TITOLITLSReader.SetStreamPos(const AValue: Qword); +begin + fStream.Position:=FStartStreamPos+AValue; +end; + +function TITOLITLSReader.FileSize: QWord; +begin + fStream.Position:=LEtoN(HeaderSectionTable[0].OffSet)+8; + fStream.Read(Result, 8); + Result := LEtoN(Result); +end; + +function TITOLITLSReader.GetChunkType(AStream: TStream): TDirChunkType; +var + Sig: TSig; +begin + AStream.Read(Sig, 4); + if Sig = 'PMGL' then Result := ctPMGL + else if Sig = 'PMGI' then Result := ctPMGI + else if Sig = 'AOLL' then Result := ctAOLL + else if Sig = 'AOLI' then Result := ctAOLI; + AStream.Seek(-4,soFromCurrent); +end; + +function TITOLITLSReader.GetTransform(const AGuid: TGuid): TITSFTransform; +begin + Result := nil; +end; + +procedure TITOLITLSReader.ReadHeader; +var + CachedPos: QWord; + SectionName: string; + i: Integer; +begin + {$IFDEF DEBUG_HELP2} + WriteLn(ClassName); + {$ENDIF} + fStream.Read(Header, SizeOf(TITOLITLSHeader)); + if not((Header.Sig[0] = 'ITOL') and (Header.Sig[1] = 'ITLS')) then + Exit; + ReadHeaderEntries; + CachedPos := StreamPos; + fStream.Read(PostHeader, Sizeof(TITOLITLSPostHeader)); + StreamPos := CachedPos + PostHeader.CAOLOffset; + fStream.Read(CAOLHeader, SizeOf(TCAOLRec)); + {$IFDEF DEBUG_HELP2} + WriteLn(CAOLHeader.ITSFHeader.ITSFsig); + {$ENDIF} + GetSections(SectionNames); + for i := 1 to SectionNames.Count-1 do + begin + FmtStr(SectionName, '::DataSpace/Storage/%s/',[SectionNames[i]]); + SectionNames.Objects[i] := GetTransforms(SectionName); + end; +end; + +procedure TITOLITLSReader.ReadHeaderEntries; +var + i: Integer; +begin + StreamPos := Header.HeaderSectionTableOffset; + SetLength(HeaderSectionTable, Header.HeaderSectionEntryCount); + for i := 0 to Header.HeaderSectionEntryCount -1 do + begin + fStream.Read(HeaderSectionTable[i], SizeOf(TITOLITLSHeaderSectionEntry)); + HeaderSectionTable[i].OffSet:= LEtoN(HeaderSectionTable[i].OffSet); + HeaderSectionTable[i].Length:= LEtoN(HeaderSectionTable[i].Length); + {$IFDEF DEBUG_HELP2} + //WriteLn('Entry #',i,' Offset = ',Entry.OffSet,' Length = ',Entry.Length); + {$ENDIF} + + end; +end; + +function TITOLITLSReader.GetTransforms(ASectionPrefix: String): TITSFTransformList; +var + Stream: TMemoryStream; + Guid: TGuid; + GCount: Integer; + Transform: TITSFTransform; + TransformClass: TITSFTransformClass = nil; + Idx: Integer; +begin + Result := nil; + Stream := GetObject(ASectionPrefix+'Transform/List'); + if Stream = nil then + begin + {$IFDEF DEBUG_HELP2} + //WriteLn(ASectionPrefix+'Transform/List doesnt exist!'); + {$ENDIF} + Exit; + end; + + Result := TITSFTransformList.Create; + + FillChar(Guid, SizeOf(Guid), 0); + TransformClass := RegisteredTransforms.Transform[Guid]; + Idx := Result.AddTransform(TransformClass); + Transform := TransformClass.Create(@Self.GetObject, nil); + Result.TransformInstance[Idx] := Transform; + {$IFDEF DEBUG_HELP2} + WriteLn('Sec: ', ASectionPrefix, ' Transform Add ', Transform.ClassName); + {$ENDIF} + + GCount := Stream.Size div SizeOf(TGuid); + while GCount > 0 do + begin + Dec(GCount); + Stream.Read(Guid, 16); + TransformClass := RegisteredTransforms.Transform[Guid]; + Idx := Result.AddTransform(TransformClass); + Transform := TransformClass.Create(@Self.GetObject, Transform); + Result.TransformInstance[Idx] := Transform; + {$IFDEF DEBUG_HELP2} + WriteLn('Sec: ', ASectionPrefix, ' Transform Add ', Transform.ClassName); + {$ENDIF} + end; + Stream.Free; +end; + +constructor TITOLITLSReader.Create(AStream: TStream; + FreeStreamOnDestroy: Boolean); +begin + inherited Create(AStream, FreeStreamOnDestroy); +end; + +destructor TITOLITLSReader.Destroy; +begin + if SectionNames<> nil then + begin + while SectionNames.Count > 0 do + begin + if SectionNames.Objects[SectionNames.Count-1] <> nil then + SectionNames.Objects[SectionNames.Count-1].Free; + SectionNames.Delete(SectionNames.Count-1); + end; + SectionNames.Free; + end; + inherited Destroy; +end; + +function ReadEntry(AStream: TStream): TPMGListChunkEntry; +var + NameLength: LongInt; +begin + NameLength:=GetCompressedInteger(AStream); + SetLength(Result.Name, NameLength); + AStream.Read(Result.Name[1], NameLength); + Result.ContentSection:= GetCompressedInteger(AStream); + Result.ContentOffset:= GetCompressedInteger(AStream); + Result.DecompressedLength:= GetCompressedInteger(AStream); +end; + +procedure TITOLITLSReader.GetCompleteFileList(ForEach: TFileEntryForEach; AIncludeInternalFiles: Boolean = True); +var + SecOffset: QWord; + IFCM: TIFCMRec; + ChunkType: TDirChunkType; + Chunk: TMemoryStream; + i, j: Integer; + AOLL: TAOLLChunkHeader; + AOLI: TAOLIChunkHeader; + Entry: TPMGListChunkEntry;// not really a PMGL entry but the members are the same + NameLength: LongInt; + EntryCount: Word; +begin + StreamPos:=HeaderSectionTable[1].OffSet; + fStream.Read(IFCM, SizeOf(IFCM)); + + for i := 0 to IFCM.ChunkCount-1 do + begin + Chunk:= TMemoryStream.Create; + Chunk.CopyFrom(fStream, IFCM.ChunkSize); + Chunk.Position:=0; + + ChunkType:= GetChunkType(Chunk); + case ChunkType of + ctAOLL : + begin + Chunk.Read(AOLL, SizeOf(AOLL)); + Chunk.Seek(-2, soFromEnd); + EntryCount:= LEtoN(Chunk.ReadWord); + {$IFDEF DEBUG_HELP2} + WriteLn(EntryCount); + {$ENDIF} + Chunk.Seek(SizeOf(AOLL), soFromBeginning); + for j := 0 to EntryCount-1 do + begin + Entry := ReadEntry(Chunk); + ForEach(Entry.Name, Entry.ContentOffset, Entry.DecompressedLength, Entry.ContentSection); + end; + end; + ctAOLI : + begin + //Chunk.Read(AOLI, SizeOf(AOLI)); + end; + end; + Chunk.Free; + end; + +end; + +function TITOLITLSReader.ObjectExists(Name: String): QWord; +var + IFCM: TIFCMRec; + ChunkIndex: QWord; + Chunk: TMemoryStream; + StartOfChunks: QWord; + EntryCount: Word; + AOLL: TAOLLChunkHeader; + AOLI: TAOLIChunkHeader; + Entry: TPMGListChunkEntry; + CRes: LongInt; + i: integer; +begin + Result := 0; + + if Name = fCachedEntry.Name then + Exit(fCachedEntry.DecompressedLength); // we've already looked it up + + fCachedEntry.Name:=''; + fCachedEntry.ContentSection:=-1; + fCachedEntry.DecompressedLength:=0; + fCachedEntry.ContentOffset:=-1; + + StreamPos:=HeaderSectionTable[1].OffSet; + fStream.Read(IFCM, SizeOf(IFCM)); + StartOfChunks := fstream.Position; + {$R-} + ChunkIndex:=PostHeader.ListChunkInfo.TopAOLIChunkIndex; + if ChunkIndex = -1 then + ChunkIndex := PostHeader.ListChunkInfo.FirstAOLLChunkIndex; + + Chunk := TMemoryStream.Create; + while ChunkIndex <> -1 do + begin + Chunk.Position:=0; + fStream.Position:= StartOfChunks + (IFCM.ChunkSize*ChunkIndex); + Chunk.CopyFrom(fStream, IFCM.ChunkSize); + Chunk.Position:=0; + + case GetChunkType(Chunk) of + ctAOLL : + begin + Chunk.Read(AOLL, SizeOf(AOLL)); + Chunk.Seek(-2, soFromEnd); + EntryCount:= LEtoN(Chunk.ReadWord); + {$IFDEF DEBUG_HELP2} + WriteLn(EntryCount); + {$ENDIF} + Chunk.Seek(SizeOf(AOLL), soFromBeginning); + for i := 0 to EntryCount-1 do + begin + Entry := ReadEntry(Chunk); + CRes := ChmCompareText(Name, Entry.Name); + if CRes = 0 then + begin + ChunkIndex:=-1; + fCachedEntry := Entry; + Break; + + end + else if CRes > 0 then + Continue + else + begin + ChunkIndex := -1; + Break; + end; + end; + end; + ctAOLI : + begin + //Chunk.Read(AOLI, SizeOf(AOLI)); + end; + end; + + + end; + {$R+} + Chunk.Free; + Result := fCachedEntry.DecompressedLength; + +end; + +function TITOLITLSReader.GetObject(Name: String): TMemoryStream; +var + Entry, + ContentEntry: TPMGListChunkEntry; + SectionName: String; + Transforms: TITSFTransformList; + Transform: TITSFTransform; + ContentStream: TStream; + ChunkPos: QWord; + i: Integer; +begin + Result := nil; + {$IFDEF DEBUG_HELP2} + WriteLn('Want: ', Name); + {$ENDIF} + if ObjectExists(Name) = 0 then begin + //WriteLn('Object ', name,' Doesn''t exist or is zero sized.'); + Exit; + end; + if Name = '/' then + Exit; // wierd bug where written size and offset contain random data + Entry := fCachedEntry; + + + + if Entry.ContentSection = 0 then begin + Result := TMemoryStream.Create; + {$IFDEF DEBUG_HELP2} + WriteLn('Offset = ', Entry.ContentOffset); + {$ENDIF} + //StreamPos := CAOLHeader.ITSFHeader.Section0Offset + Entry.ContentOffset; + ChunkPos := CAOLHeader.ITSFHeader.Section0Offset;// + fCachedEntry.ContentOffset; + ContentStream := TStreamChunk.Create(fStream, ChunkPos, FileSize-ChunkPos); + ContentStream.Seek(Entry.ContentOffset, soFromBeginning); + Result.CopyFrom(ContentStream, Entry.DecompressedLength); + ContentStream.Free; + + end + else + begin + FmtStr(SectionName, '::DataSpace/Storage/%s/',[SectionNames[Entry.ContentSection]]); + {$IFDEF DEBUG_HELP2} + WriteLn('Want: ', SectionName); + {$ENDIF} + if ObjectExists(SectionName+'Content') = 0 then + Exit; + ContentEntry := fCachedEntry; + + Transforms := TITSFTransformList(SectionNames.Objects[Entry.ContentSection]); + if Transforms = nil then + Exit; + ChunkPos := CAOLHeader.ITSFHeader.Section0Offset + ContentEntry.ContentOffset; + ContentStream := TStreamChunk.Create(fStream, ChunkPos, ContentEntry.DecompressedLength); + //ContentStream := GetObject(SectionName+'Content'); + Result := TMemoryStream.Create; + {$IFDEF DEBUG_HELP2} + {for i := Transforms.Count-1 downto 0 do + begin + //WriteLn('Found Transform: ', GUIDToString(Transforms.TransformIndex[i].GUID)); + + //WriteLn(Transform.ClassName); + Transform := Transforms.TransformInstance[i]; + if Transform = nil then + WriteLn('Trqansform = nil!'); + + end;} + + WriteLn('Transform Count = ', Transforms.Count); + WriteLn('Asking ', Transforms.TransformInstance[Transforms.Count-1].ClassName,' for data'); + {$ENDIF} + Transforms.TransformInstance[Transforms.Count-1].WantData(SectionName, ContentStream, Entry.ContentOffset, Entry.DecompressedLength, Result); + ContentStream.Free; + end; + Result.Position := 0; +end; + +end. diff --git a/packages/chm/src/itolitlstypes.pas b/packages/chm/src/itolitlstypes.pas new file mode 100644 index 0000000000..bd6b932af3 --- /dev/null +++ b/packages/chm/src/itolitlstypes.pas @@ -0,0 +1,137 @@ +unit ITOLITLSTypes; + +{$mode objfpc}{$H+} +{$PACKRECORDS C} + +interface + +uses ChmBase; + +type + + TSig = array[0..3] of char; + TITOLITLSHeader = record + Sig: Array [0..1] of TSig; // ITLO/ITLS + Version: DWord; // = 1 + HeaderSectionTableOffset: DWord; + HeaderSectionEntryCount: DWord; + PostHeaderTableSize: DWord; + GUID: TGuid; // {0A9007C1-4076-11D3-8789-0000F8105754} + end; + + TITOLITLSHeaderSectionEntry = record + OffSet: QWord; // From Start of ITLO/ITLS + Length: QWord; + end; + + TChunkDirInfo = record + TopAOLIChunkIndex: QWord; // -1 if none + FirstAOLLChunkIndex, + LastAOLLChunkIndex: QWord; + Unknown0: QWord; // 0 + ChunkSize: DWord; // = $2000 if list $200 if Index + QuickRefDensity: DWord; // = 2 + Unknown1: DWord; // = 0 + DirDepth: DWord; // 1 there is no index, 2 if there is one level of AOLI 3 if two index levels etc + Unknown2: QWord; // 0 + DirEntryCount: QWord; // Number Of Directory Entries + end; + + TITSFHeaderV4= record + ITSFsig: array [0..3] of char; + Version: LongWord; + HeaderLength: LongWord; + Unknown_1: LongWord; + Section0Offset: QWord; + TimeStamp: LongWord; //bigendian + LanguageID: LongWord; + end; + + TCAOLRec = record + Sig: TSig; // CAOL + Version: DWord; // 2 + CAOLSize: DWord; // includes ITSF section = $50 + CompilerID: array [0..1] of char; // = "HH" + Unknown: Word; // 0 + Unknown1: DWord; // $43ED or 0 + DirChunkSize: DWord; // $2000 + DirIndexChunkSize: DWord; // $200 + Unknown2, // $100000 + Unknown3: DWord;// $20000 + Unknown4, + Unknown5, + Unknown6: DWord; // = 0 + ITSFHeader: TITSFHeaderV4; + end; + + TITOLITLSPostHeader = record + Version: DWord; // 2 + CAOLOffset: DWord; // usually $98 (is from start of PostHeader) + ListChunkInfo, + IndexChunkInfo: TChunkDirInfo; + Unknown3: DWord; // = $100000 + Unknown4: Dword; // = $20000 + Unknown5: QWord; // 0 + + end; + + THeaderSection0 = TITSPHeaderPrefix; + + TIFCMRec = record + SIG: TSig; // = IFCM + Version: DWord; // = 1 + ChunkSize: DWord; // = $2000 + UnKnown: DWord; // = $100000 + Unknown1: DWord; // = -1 + Unknown2: DWord; // = -1 + ChunkCount: Dword;// + Unknown3: DWord; // = 0 + end; + + TAOLLChunkHeader = record + Sig: TSig; // = AOLL + QuickRefSize: DWord; + ChunkIndex: QWord; // must be correct in the order written + PrevChunkIndex: QWord; + NextChunkIndex: QWord; + FirstEntryIndex: QWord; + Unknown0, // = 1 + Unknown1: DWord;// = 0 + // entries + end; + + TAOLIChunkHeader = record + Sig: TSig; // = AOLI + QuickRefSize: DWord;// Length of quickref area at end of directory chunk + ChunkIndex: QWord;// Directory chunk number + // entries + end; + + const + ITOLITLSGuid: TGuid = '{0A9007C1-4076-11D3-8789-0000F8105754}'; + + type + TLZXv3ControlData = record + Sig: TSig; + Version: DWord; + ResetInterval: Dword; + WindowSize: DWord; + CacheSize: Dword; + Unknown1, + Unknown2: DWord; // 0 + end; + + TLZXv3ResetTable = record + Version: Dword; + EntryCount: DWord; + EntrySize: DWord; + EntryStart: DWord; + UnCompressedSize, + CompressedSize: QWord; + BlockSize: QWord; // $8000 + end; + + +implementation + +end. diff --git a/packages/chm/src/itsftransform.pas b/packages/chm/src/itsftransform.pas new file mode 100644 index 0000000000..bc6a64f776 --- /dev/null +++ b/packages/chm/src/itsftransform.pas @@ -0,0 +1,442 @@ +{ Copyright (C) <2009> itfstransform.pas + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License + for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +} +{ + See the file COPYING.modifiedLGPL, included in this distribution, + for details about the copyright. +} +unit ITSFTransform; + +{ $DEFINE DEBUG_HELP2} + +{$mode objfpc}{$H+} + +interface + +uses + Classes, paslzx, ITOLITLSTypes; + +type + TGetObject = function(AName: String): TMemoryStream of object; + + TITSFTransformList = class; + TITSFTransform = class; + + { TITSFTransform } + TITSFTransform = class + private + FDataStream: TStream; + FPrefix: String; + FParentTransform: TITSFTransform; + public + GetObject: TGetObject; // GetObject(Name: String): TMemoryStream; + OutStream: TMemoryStream; + constructor Create(AGetObject: TGetObject; AParentTransform: TITSFTransform); virtual; + + function WantData(APrefix: String; ADataStream: TStream; const DataStart, DataLength: Integer; AOutStream: TMemoryStream): Boolean; virtual; + + property ParentTransform : TITSFTransform read FParentTransform; + property Prefix: String read FPrefix write FPrefix; + property DataStream: TStream read FDataStream write FDataStream; + class function GUID: TGuid; virtual; + class function GUIDString: String; virtual; + end; + + TITSFTransformClass = class of TITSFTransform; + + { TPlainTransform } + + TPlainTransform = class(TITSFTransform) + function WantData(APrefix: String; ADataStream: TStream; const DataStart, DataLength: Integer; AOutStream: TMemoryStream): Boolean; override; + end; + + { TLZXv3Transform } + + TLZXv3Transform = class(TITSFTransform) + private + Entries: array of QWord; + Data: TLZXv3ControlData; + Table: TLZXv3ResetTable; + function GetControlData: Boolean; + function GetResetTable: Boolean; + + function FindChunkCompressedSize(AEntryIndex: Integer): DWord; + function FindFirstChunkFromOffset(AOffset, ASize: QWord; out ChunkCount: DWord): Integer; + + function ExtractChunks(AFirstChunkIndex, AChunkCount: DWord; out ExtractedOffsetStart: QWord): TMemoryStream; + public + function WantData(APrefix: String; ADataStream: TStream; const DataStart, DataLength: Integer; AOutStream: TMemoryStream): Boolean; override; + + class function GUID: TGuid; override; + end; + + { TITSFTransformList } + + TITSFTransformList = class(TFPList) + private + function GetTransform(AGuid: TGuid): TITSFTransformClass; + function GetTransformIndex(AIndex: DWord): TITSFTransformClass; + function GetTransformInstance(AIndex: DWord): TITSFTransform; + procedure SetTransformInstance(AIndex: DWord; const AValue: TITSFTransform); + public + function AddTransform(ATransform: TITSFTransformClass): Integer; + procedure Delete(AIndex: Integer); + property Transform[AGuid: TGuid]: TITSFTransformClass read GetTransform; + property TransformIndex[AIndex: DWord]: TITSFTransformClass read GetTransformIndex; + property TransformInstance[AIndex: DWord]: TITSFTransform read GetTransformInstance write SetTransformInstance; + end; + +function RegisteredTransforms: TITSFTransformList; + + +implementation +uses + SysUtils; + +var + LocTransforms: TITSFTransformList = nil; + +type + PITSFTranformItem = ^TITSFTranformItem; + TITSFTranformItem = record + //Guid: TGuid; + Transform: TITSFTransformClass; + Instance: TITSFTransform; + end; + +function RegisteredTransforms: TITSFTransformList; +begin + if LocTransforms = nil then + LocTransforms := TITSFTransformList.Create; + Result := LocTransforms; +end; + +{ TITSFTransform } + +constructor TITSFTransform.Create(AGetObject: TGetObject; AParentTransform: TITSFTransform); +begin + GetObject:=AGetObject; + FParentTransform := AParentTransform; +end; + +function TITSFTransform.WantData(APrefix: String; ADataStream: TStream; + const DataStart, DataLength: Integer; AOutStream: TMemoryStream): Boolean; +begin + Prefix := APrefix; + DataStream := ADataStream; + OutStream := AOutStream; + {$IFDEF DEBUG_HELP2} + WriteLn('WantData Class = ', ClassName); + {$ENDIF} +end; + +class function TITSFTransform.GUID: TGuid; +const + AGuid: TGuid = '{00000000-0000-0000-0000-000000000000}'; +begin + Result := AGuid; +end; + +class function TITSFTransform.GUIDString: String; +begin + Result := GUIDToString(GUID); +end; + +{ TITSFTransformList } + +function TITSFTransformList.GetTransform(AGuid: TGuid): TITSFTransformClass; +var + Item: PITSFTranformItem; + i: Integer; + GUID: TGuid; +begin + Result := nil; + for i := 0 to Count-1 do + begin + Item := PITSFTranformItem(Items[i]); + GUID := Item^.Transform.GUID; + if CompareByte(GUID,AGuid, 16) = 0 then + Exit(Item^.Transform); + end; +end; + +function TITSFTransformList.GetTransformIndex(AIndex: DWord): TITSFTransformClass; +begin + Result := PITSFTranformItem(Items[AIndex])^.Transform; +end; + +function TITSFTransformList.GetTransformInstance(AIndex: DWord): TITSFTransform; +begin + Result := PITSFTranformItem(Items[AIndex])^.Instance; +end; + +procedure TITSFTransformList.SetTransformInstance(AIndex: DWord; + const AValue: TITSFTransform); +begin + PITSFTranformItem(Items[AIndex])^.Instance := AValue; +end; + +function TITSFTransformList.AddTransform(ATransform: TITSFTransformClass): Integer; +var + Item: PITSFTranformItem; +begin + if not Assigned(ATransform) then + Exit; + New(Item); + Item^.Transform:= ATransform; + Item^.Instance := nil; + Add(Item); +end; + +procedure TITSFTransformList.Delete(AIndex: Integer); +var + Item: PITSFTranformItem; +begin + Item := PITSFTranformItem(Items[AIndex]); + Dispose(Item); + Inherited Delete(AIndex); +end; + +{ TLZXv3Transform } + +function TLZXv3Transform.FindFirstChunkFromOffset(AOffset, ASize: QWord; out ChunkCount: DWord): Integer; +var + EndChunk: DWord; +begin + Result := AOffset div Table.BlockSize; + EndChunk := (AOffset + ASize) div Table.BlockSize; + ChunkCount:=EndChunk-Result; + //if ChunkCount = 0 then + Inc(ChunkCount); +end; + +function TLZXv3Transform.GetControlData: Boolean; +var + ControlDataStream: TStream; + ESize: LongWord; +begin + Result := False; + try + ControlDataStream := GetObject(Prefix+'ControlData'); + + if ControlDataStream = nil then + Exit; + + + ESize := NtoLE(ControlDataStream.ReadDWord); + while ESize <> 7 do + begin + ControlDataStream.Seek(ESize*4, soFromCurrent); + ESize := LEtoN(ControlDataStream.ReadDWord); + end; + if ESize = 7 then + ControlDataStream.Read(Data, SizeOf(TLZXv3ControlData)); + + finally + if Assigned(ControlDataStream) then + ControlDataStream.Free; + end; + Result := ESize = 7; + //WriteLn('GetControlData = ', REsult); + +end; + +function TLZXv3Transform.GetResetTable: Boolean; +var + WholePrefix: String; + ResetStream: TStream; + {$IFDEF ENDIAN_BIG} + i: Integer; + {$ENDIF} +begin + Result := False; + WholePrefix:=Prefix+'Transform/'+GUIDString+'/'; + ResetStream := GetObject(WholePrefix+'InstanceData/ResetTable'); + if ResetStream = nil then + Exit; + ResetStream.Read(Table, SizeOf(TLZXv3ResetTable)); + SetLength(Entries, Table.EntryCount); + ResetStream.Read(Entries[0], Table.EntryCount*8); + {$IFDEF ENDIAN_BIG} + for i := Low(Entries) to High(Entries) do + Entries[i] := LEtoN(Entries[i]); + {$ENDIF} + {$IFDEF DEBUG_HELP2} + //for i := Low(Entries) to High(Entries) do + // WriteLn('Entry[',i,'] = ',Entries[i] ,' UnCompressStart = ', i*$8000); + {$ENDIF} + ResetStream.Free; + + Result := True; +end; + +function TLZXv3Transform.FindChunkCompressedSize(AEntryIndex: Integer): DWord; +begin + if AEntryIndex < High(Entries) then + Result := Entries[AEntryIndex+1] - Entries[AEntryIndex] + else + Result := DataStream.Size-Entries[AEntryIndex]; +end; + +function TLZXv3Transform.ExtractChunks(AFirstChunkIndex, AChunkCount: DWord; + out ExtractedOffsetStart: QWord): TMemoryStream; +var + LZX: PLZXState; + CStart, + CSize: DWord; + //CBuf: Pointer; + Buf: TMemoryStream; + CBuf: Pointer; + UBuf: Pointer; + USize: Dword; + URes: DWord; + WinCode: DWord; + WinSize: QWord; + BlockMask: Byte; +begin + BlockMask := (Data.ResetInterval shl 1) - 1; + + // must start on a even numbered block + while (AFirstChunkIndex mod Data.ResetInterval <> 0) and (AFirstChunkIndex > 0) do + begin + Dec(AFirstChunkIndex); + Inc(AChunkCount); + end; + + ExtractedOffsetStart := Table.BlockSize*AFirstChunkIndex; + + {$IFDEF DEBUG_HELP2} + WriteLn('Getting Data, StartChunk=', AFirstChunkIndex,' Count = ', AChunkCount); + WriteLn('Version = ', Data.Version); + WriteLn('Window Size = ',Data.WindowSize); + WriteLn('Block Size = ',Hexstr(Table.BlockSize,16)); + WriteLn('Block Size = ',Table.BlockSize); + {$ENDIF} + + WinSize := (Data.WindowSize * Table.BlockSize); + WinCode := 0; + while WinSize > 1 do + begin + Inc(WinCode); + //WriteLn(HexStr(WinSize, 16)); + WinSize := WinSize shr 1; + end; + + LZX := LZXinit(WinCode);//ata.WindowSize); + + CBuf := GetMem(Table.BlockSize); + UBuf := GetMem(Table.BlockSize); + + Result := TMemoryStream.Create; + Buf := TMemoryStream.Create; + + CStart := Entries[AFirstChunkIndex]; + CSize := Entries[AFirstChunkIndex+AChunkCount]+FindChunkCompressedSize(AFirstChunkIndex+AChunkCount); + ParentTransform.WantData(Prefix, DataStream, CStart, CSize, Buf); + Buf.Position:=0; + + while AChunkCount > 0 do + begin + Dec(AChunkCount); + + CSize := FindChunkCompressedSize(AFirstChunkIndex); + + CSize := Buf.Read(CBuf^, CSize); + if AFirstChunkIndex mod Data.ResetInterval = 0 then + begin + LZXreset(LZX); + {$IFDEF DEBUG_HELP2} + WriteLn('Reset LZX Window'); + {$ENDIF} + end; + URes := LZXdecompress(LZX, CBuf, UBuf, CSize, Table.BlockSize); + //CBuf.Size := 0; + {$IFDEF DEBUG_HELP2} + WriteLn('Decompress = ', URes); + {$ENDIF} + + Result.Write(UBuf^, Table.BlockSize); + Inc(AFirstChunkIndex); + end; + Buf.Free; + Freemem(UBuf); + Freemem(CBuf); + Result.Position:=0; + LZXteardown(LZX); +end; + + +function TLZXv3Transform.WantData(APrefix: String; ADataStream: TStream; const DataStart, + DataLength: Integer; AOutStream: TMemoryStream): Boolean; +var + LZXData: TLZXv3ControlData; + ResetTable: TLZXv3ResetTable; + ChunkStart, + ChunkCount: DWord; + RawChunks: TStream; + ChunkDataStart: QWord; +begin + inherited WantData(APrefix, ADataStream, DataStart, DataLength, AOutStream); + {$IFDEF DEBUG_HELP2} + WriteLn('WantData Pre=',APrefix,' DS=', DataStart,' DL=',DataLength); + {$ENDIF} + + Result := False; + if not (GetControlData and GetResetTable) then + Exit; + {$IFDEF DEBUG_HELP2} + WriteLn('Got Needed Info'); + {$ENDIF} + ChunkStart := FindFirstChunkFromOffset(DataStart,DataLength, ChunkCount); + + RawChunks := ExtractChunks(ChunkStart, ChunkCount, ChunkDataStart); + + RawChunks.Position := DataStart-ChunkDataStart; + AOutStream.CopyFrom(RawChunks, DataLength); + RawChunks.Free; + + Result := True; +end; + +class function TLZXv3Transform.GUID: TGuid; +const + AGuid: TGuid = '{0A9007C6-4076-11D3-8789-0000F8105754}'; +begin + Result := AGuid; +end; + +{ TPlainTransform } + +function TPlainTransform.WantData(APrefix: String; ADataStream: TStream; const DataStart, DataLength: Integer; + AOutStream: TMemoryStream): Boolean; +begin + inherited WantData(APrefix, ADataStream, DataStart, DataLength, AOutStream); + ADataStream.Position:=DataStart; + AOutStream.CopyFrom(ADataStream, DataLength); + Result := True; +end; + +initialization + RegisteredTransforms.AddTransform(TPlainTransform); + RegisteredTransforms.AddTransform(TLZXv3Transform); + +finalization + if Assigned(LocTransforms) then + LocTransforms.Free; + +end. + +