*** empty log message ***

This commit is contained in:
Enrico Maria Giordano
2007-06-02 13:16:44 +00:00
parent cdf41837bc
commit 7006075d95
59 changed files with 0 additions and 17352 deletions

View File

@@ -1,73 +0,0 @@
/** \page pageLic Licensing information
ZipArchive library - creation, modification and decompression of "zip" format archives <BR>
Copyright &copy; 2000 - 2002 Tadeusz Dracz. <BR>
E-Mail: \htmlonly<a href="mailto:tdracz@artpol-software.com"> tdracz@artpol-software.com</a><BR>
Web: <A HREF="http://www.artpol-software.com" target="_blank">http://www.artpol-software.com</A> \endhtmlonly
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This library 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 General Public License for more details.
You should have received a copy of the GNU 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
<HR>
*************************************************************************
An English version of the \ref pageGPL "GNU GPL" is in the gpl.txt file distributed with
this project. Translations to other languages are available at:
\htmlonly
<A HREF="http://www.gnu.org/copyleft/gpl.html" target="_blank">http://www.gnu.org/copyleft/gpl.html</A>
\endhtmlonly
<B><EM>
Distributing ZipArchive under GNU GPL implies ZipArchive can only be used
with software that is licensed under conditions compliant with the GPL.
Embedding in proprietary software requires an alternative license.
</B></EM>
\subsection s1 Alternative license for use with proprietary software
If you want to distribute software in a commercial context that incorporates
ZipArchive and you do not want to meet the conditions of GNU GPL
<B>(e.g. an obligation to provide a customer with the source code of your
software that uses the ZipArchive library)</B>, you need to have a commercial license.
- The commercial license provides you with the same rights as the GNU GPL, but in
addition allows you to embed ZipArchive library in proprietary software without
affecting the copyright of this software (it removes the GNU GPL obligation
to publish the source code)
- The license gives you royalty free distribution rights
- The license does not allow you to transfer these rights
- The license is granted per developer
- You won't need to purchase an additional license for the future versions of the library
The commercial license is available free of charge for using ZipArchive library in:
- freeware software <EM>(freeware is software that is available free of charge, but which is copyrighted by the developer, who retains the right to control its redistribution and to sell it in the future)</EM>
- excluded is software which is associated with an equipment that the same company manufactures and which has no practical usage value without it (e.g. software used for maintenace of machines) - unless the equipment is free as well (?)
- if you decide to sell the software in the future - you will need to purchase the commercial license for using the ZipArchive library, unless it is distributed in the shareware way - see below
- software distributed in the Shareware way <em>(Shareware distribution gives users a chance to try software before buying it. If you try a Shareware program and continue using it, you are expected to register. Individual programs differ on details -- some request registration while others require it, some specify a maximum trial period.
Copyright laws apply to both Shareware and commercial software and the copyright holder retains all rights, with the exception that copying and distributing the program for evaluation purposes is encouraged, subject to certain conditions. For example, some authors require written permission before a commercial disk vendor may copy their Shareware. )</em>
- excluded is software which price for a single copy is higher than the price of the ZipArchive library for a single developer
Extended Licence for HBZLIB (library for zip compression in \htmlonly <A HREF="http://www.harbour-project.org" target="_blank">Harbour</A>\endhtmlonly)<BR>
You can create proprietary software using hbzlib respecting the follow:
- ZipArchive library must be linked together with hbzlib
- you cannot use ZipArchive as a dynamic library (DLL), it must be linked staticaly with the software
- the commercial license for ZipArchive is free of charge, but these grants are valid only if the whole application is written with Harbour
There is a fee for the commercial license for using the library in the software not falling into the mentioned categories.
<BR>
It is recommended that you should print two copies of the commercial license
document after you receive it, sign them and send by post. One copy, signed by the author will be sent back to you.
Please \htmlonly <a href="mailto:tdracz@artpol-software.com">contact the author</a> or visit <A HREF="http://www.artpol-software.com" target="_blank">the Artpol Software web site</A>\endhtmlonly to find out more.
*/

View File

@@ -1,91 +0,0 @@
# Makefile for ZipArchive library
# Copyright (C) 2000-2002 Tadeusz Dracz
# For conditions of distribution and use, see copyright notice in License.txt
# To install to /usr/lib and /usr/include, type:
# make install
# to install to a different directory change prefix
CC=g++
CCC=cc
#FLAGSD = -g
FLAGSD =
ZIPARCHLIB = libziparch.a
ZIPPIELOCATION = stl/zippie/
prefix = /usr
libdir = ${prefix}/lib
includedir = ${prefix}/include
zipardir = $(includedir)/ziparchive
AR=ar rc
RANLIB=ranlib
.SUFFIXES: .c .cpp
.c.o:
$(CCC) -c -I. -I$(HB_INC_INSTALL) -o $*.o $<
.cpp.o:
$(CC) $(FLAGSD) -I$(HB_INC_INSTALL) -c -I. $<
OBJS = ZipArchive.o ZipAutoBuffer.o ZipCentralDir.o \
ZipCompatibility.o ZipException.o ZipFile.o ZipFileHeader.o \
ZipMemFile.o ZipPathComponent.o ZipPlatform.o ZipPlatformComm.o \
ZipStorage.o ZipString.o zipnew.o zipcomp.o zip.o
#OBJSZLIB = zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/uncompr.o zlib/deflate.o zlib/trees.o \
zlib/zutil.o zlib/inflate.o zlib/infblock.o zlib/inftrees.o zlib/infcodes.o zlib/infutil.o zlib/inffast.o
OBJSZLIB =
$(ZIPARCHLIB): $(OBJS) $(OBJSZLIB)
$(AR) $@ $(OBJS) $(OBJSZLIB)
-@ ($(RANLIB) $@ || true) >/dev/null 2>&1
ZipArchive.o: ZipArchive.h
ZipAutoBuffer.o: ZipAutoBuffer.h
ZipCentralDir.o: ZipCentralDir.h
ZipCompatibility.o: ZipCompatibility.h
ZipException.o: ZipException.h
ZipFile.o: ZipFile.h
ZipFileHeader.o: ZipFileHeader.h
ZipMemFile.o: ZipMemFile.h
ZipPathComponent.o: ZipPathComponent.h
ZipPlatform.o: ZipPlatform.h
ZipStorage.o: ZipStorage.h
ZipString.o: ZipString.h
zipnew.o: hbzip2.h
zipcomp.o: hbzip2.h
zip.o: hbzip2.h
clean:
-rm -f *.o *~ $(ZIPARCHLIB)
zippie:
$(CC) -I$(zipardir) -I$(HB_INC_INSTALL) $(FLAGSD) -o zippie $(ZIPPIELOCATION)zippie.cpp $(ZIPPIELOCATION)CmdLine.cpp -lz -lstdc++ -lziparch
# $(CC) -I$(zipardir) $(FLAGSD) -o zippie ZIPPIELOCATION)zippie.cpp $(ZIPPIELOCATION)CmdLine.cpp -lstdc++ -lziparch
cleanzippie:
-rm -f zippie
install:
-@if [ ! -d $(includedir) ]; then mkdir $(includedir); fi
-@if [ ! -d $(libdir) ]; then mkdir $(libdir); fi
-@if [ ! -d $(zipardir) ]; then mkdir $(zipardir); fi
cp libziparch.a $(libdir)
cp libziparch.a /usr/lib/xharbour
chmod 755 $(libdir)/$(ZIPARCHLIB)
chmod 755 /usr/lib/xharbour/libziparch.a
cp *.h $(zipardir)
chmod 644 $(zipardir)/*h
uninstall:
rm -f $(zipardir)/*h
rm -f $(libdir)/$(ZIPARCHLIB)
rmdir $(zipardir)

View File

@@ -1,70 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipFileMapping.h $
// $Archive: /ZipArchive_Linux/ZipFileMapping.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2002 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_AUTOHANDLE_H__D68326EA_D7FA_4792_AB1F_68D09533E399__INCLUDED_)
#define AFX_AUTOHANDLE_H__D68326EA_D7FA_4792_AB1F_68D09533E399__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <sys/mman.h>
namespace ziparchv
{
struct CZipFileMapping
{
CZipFileMapping()
{
m_iSize = 0;
m_pFileMap = NULL;
}
bool CreateMapping(CZipFile* pFile)
{
if (!pFile)
return false;
m_iSize = pFile->GetLength();
m_pFileMap = mmap(0, m_iSize, PROT_READ|PROT_WRITE, MAP_SHARED, pFile->m_hFile, 0);
return (m_pFileMap != NULL);
}
void RemoveMapping()
{
if (m_pFileMap)
{
munmap(m_pFileMap, m_iSize);
m_pFileMap = NULL;
}
}
~CZipFileMapping()
{
RemoveMapping();
}
char* GetMappedMemory()
{
return reinterpret_cast<char*> (m_pFileMap);
}
protected:
void* m_pFileMap;
size_t m_iSize;
};
}
#endif // !defined(AFX_AUTOHANDLE_H__D68326EA_D7FA_4792_AB1F_68D09533E399__INCLUDED_)

View File

@@ -1,194 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipPathComponent.cpp $
// $Archive: /ZipArchive_Linux/ZipPathComponent.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zippathcomponent.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CZipPathComponent::~CZipPathComponent()
{
}
void CZipPathComponent::SetFullPath(LPCTSTR lpszFullPath)
{
CZipString szTempPath(lpszFullPath);
const CZipString szPrefix = _T("\\\\?\\unc\\");
int i = -1, iLen = szPrefix.GetLength();
if (iLen > szTempPath.GetLength())
iLen = szTempPath.GetLength();
CZipString szPossiblePrefix = szTempPath.Left(iLen);
szPossiblePrefix.MakeLower(); // must perform case insensitive comparison
while (++i < iLen && szPossiblePrefix[i] == szPrefix[i]);
if (i == 2 || i == 4 || i == 8) // unc path, unicode path or unc path meeting windows file name conventions
{
m_szPrefix = szTempPath.Left(i);
szTempPath = szTempPath.Mid(i);
}
else
m_szPrefix.Empty();
m_szDrive.Empty();
m_szFileTitle.Empty();
m_szDirectory.Empty();
m_szFileExt.Empty();
int p;
for (p = szTempPath.GetLength() - 1; p >= 0; p--)
if (szTempPath[p] == m_cSeparator)
break;
if (p != -1)
{
m_szDirectory = szTempPath.Left(p);
if (p == szTempPath.GetLength() - 1 )
return; // no filename present
else
p++;
}
else
p = 0;
// p points at the beginning of the filename
m_szFileTitle = szTempPath.Mid(p);
for (p = m_szFileTitle.GetLength() - 1; p >= 0; p--)
if (m_szFileTitle[p] == _T('.'))
break;
if (p != -1)
{
m_szFileExt = m_szFileTitle.Mid(p+1);
m_szFileTitle = m_szFileTitle.Left(p);
}
}
CZipString CZipPathComponent::GetNoDrive() const
{
CZipString szPath = m_szDirectory;
CZipString szFileName = GetFileName();
if (!szFileName.IsEmpty() && !szPath.IsEmpty())
szPath += m_cSeparator;
szPath += szFileName;
return szPath;
}

View File

@@ -1,546 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipPlatform.cpp $
// $Archive: /ZipArchive_Linux/ZipPlatform.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipplatform.h"
#include "zipfileheader.h"
#include "zipexception.h"
#include "zipautobuffer.h"
#include <utime.h>
#include "zippathcomponent.h"
#include "zipcompatibility.h"
#include <sys/vfs.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
const TCHAR CZipPathComponent::m_cSeparator = _T('/');
#ifndef _UTIMBUF_DEFINED
#define _utimbuf utimbuf
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DWORD ZipPlatform::GetDeviceFreeSpace(LPCTSTR lpszPath)
{
struct statfs sStats;
if (statfs(lpszPath, &sStats) == -1)
return 0;
return sStats.f_bsize * sStats.f_bavail;
}
bool ZipPlatform::GetFileSize(LPCTSTR lpszFileName, DWORD& dSize)
{
int f = open(lpszFileName, O_RDONLY);
if (f == -1)
return false;
int iSize = lseek(f, 0, SEEK_END);
close(f);
if (iSize == -1)
return false;
dSize = (DWORD)iSize;
return true;
}
CZipString ZipPlatform::GetTmpFileName(LPCTSTR lpszPath, DWORD iSizeNeeded)
{
TCHAR empty[] = _T(""), prefix [] = _T("zar");
TCHAR* buf = NULL;
CZipString tempPath;
if (lpszPath)
{
// first try the user provided directory
tempPath = lpszPath;
if (ZipPlatform::GetDeviceFreeSpace(tempPath) < iSizeNeeded)
tempPath.Empty();
else
{
CZipPathComponent::AppendSeparator(tempPath);
tempPath += prefix;
tempPath += _T("XXXXXX");
TCHAR* c = mktemp(tempPath.GetBuffer(tempPath.GetLength()));
tempPath.ReleaseBuffer();
if (c)
return tempPath;
else
tempPath.Empty();
}
}
TCHAR* v = tempnam(tempPath, prefix);
tempPath = v;
free(v);
if (!tempPath.IsEmpty())
{
CZipPathComponent zpc(tempPath);
if (ZipPlatform::GetDeviceFreeSpace(zpc.GetFilePath()) < iSizeNeeded)
return empty;
return tempPath;
}
else
return empty;
}
bool ZipPlatform::GetCurrentDirectory(CZipString& sz)
{
char* pBuf = getcwd(NULL, 0);
if (!pBuf)
return false;
sz = pBuf;
free(pBuf);
return true;
}
bool ZipPlatform::SetFileAttr(LPCTSTR lpFileName, DWORD uAttr)
{
return chmod(lpFileName, uAttr >> 16) == 0;
}
bool ZipPlatform::GetFileAttr(LPCTSTR lpFileName, DWORD& uAttr)
{
struct stat sStats;
if (stat(lpFileName, &sStats) == -1)
return false;
uAttr = (sStats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_IFMT)) << 16;
return true;
}
bool ZipPlatform::GetFileModTime(LPCTSTR lpFileName, time_t & ttime)
{
struct stat st;
if (stat(lpFileName, &st) != 0)
return false;
ttime = st.st_mtime;
return ttime != -1;
}
bool ZipPlatform::SetFileModTime(LPCTSTR lpFileName, time_t ttime)
{
struct utimbuf ub;
ub.actime = time(NULL);
ub.modtime = ttime == -1 ? time(NULL) : ttime; // if wrong file time, set it to the current
return utime(lpFileName, &ub) == 0;
}
bool ZipPlatform::ChangeDirectory(LPCTSTR lpDirectory)
{
return chdir(lpDirectory) == 0;
}
int ZipPlatform::FileExists(LPCTSTR lpszName)
{
struct stat st;
if (stat(lpszName, &st) != 0)
return 0;
else
{
if (S_ISDIR(st.st_mode))
return -1;
else
return 1;
}
}
ZIPINLINE bool ZipPlatform::IsDriveRemovable(LPCTSTR lpszFilePath)
{
// not implemmented
return true;
}
ZIPINLINE bool ZipPlatform::SetVolLabel(LPCTSTR lpszPath, LPCTSTR lpszLabel)
{
// not implemmented
return true;
}
ZIPINLINE void ZipPlatform::AnsiOem(CZipAutoBuffer& buffer, bool bAnsiToOem)
{
// not implemmented
}
ZIPINLINE bool ZipPlatform::RemoveFile(LPCTSTR lpszFileName, bool bThrow)
{
if (unlink(lpszFileName) != 0)
if (bThrow)
CZipException::Throw(CZipException::notRemoved, lpszFileName);
else
return false;
return true;
}
ZIPINLINE bool ZipPlatform::RenameFile( LPCTSTR lpszOldName, LPCTSTR lpszNewName , bool bThrow)
{
if (rename(lpszOldName, lpszNewName) != 0)
if (bThrow)
CZipException::Throw(CZipException::notRenamed, lpszOldName);
else
return false;
return true;
}
ZIPINLINE bool ZipPlatform::IsDirectory(DWORD uAttr)
{
return S_ISDIR(uAttr >> 16) != 0;
}
ZIPINLINE bool ZipPlatform::CreateDirectory(LPCTSTR lpDirectory)
{
return mkdir(lpDirectory, S_IRUSR | S_IWUSR | S_IRGRP |S_IROTH) == 0;
}
ZIPINLINE DWORD ZipPlatform::GetDefaultAttributes()
{
return 0x81a40000;
}
ZIPINLINE DWORD ZipPlatform::GetDefaultDirAttributes()
{
return 0x41ff0010;
}
ZIPINLINE int ZipPlatform::GetSystemID()
{
return ZipCompatibility::zcUnix;
}
ZIPINLINE bool ZipPlatform::GetSystemCaseSensitivity()
{
return true;
}
bool ZipPlatform::TruncateFile(int iDes, DWORD iSize)
{
return ftruncate(iDes, iSize) == 0;
}
int ZipPlatform::OpenFile(LPCTSTR lpszFileName, UINT iMode, int iShareMode)
{
return open(lpszFileName, iMode, S_IRUSR | S_IWUSR | S_IRGRP |S_IROTH );
}
bool ZipPlatform::FlushFile(int iDes)
{
return fsync(iDes) == 0;
}
int ZipPlatform::GetFileSystemHandle(int iDes)
{
return iDes;
}

View File

@@ -1,25 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipString.cpp $
// $Archive: /ZipArchive/ZipString.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "zipstring.h"
ZIPSTRINGCOMPARE GetCZipStrCompFunc(bool bCaseSensitive, bool bCollate)
{
if (bCollate)
return bCaseSensitive ? & CZipString::Collate : & CZipString::CollateNoCase;
else
return bCaseSensitive ? & CZipString::Compare : & CZipString::CompareNoCase;
}

View File

@@ -1,178 +0,0 @@
/*
* $DOC$
* $FUNCNAME$
* HB_ZIPFILE()
* $CATEGORY$
* ZIP FUNCTION
* $ONELINER$
* Create a zip file
* $SYNTAX$
* HB_ZIPFILE( <cFile> , <cFileToCompress> | <aFiles>, <nLevel> ,
* <bBlock>,<lOverWrite> ) ---> lCompress
* $ARGUMENTS$
* <cFile> Name of the zip file
*
* <cFileToCompress> Name of a file to Compress, Drive and/or path
* can be used
*
* <aFiles> An array containing files to compress, Drive and/or path
* can be used
*
* <nLevel> Compression level ranging from 0 to 9
*
* <bBlock> Code block to execute while compressing
*
* <lOverWrite> Toggle to overwite the file if exists
* $RETURNS$
* <lCompress> .t. if file was create, otherwise .f.
* $DESCRIPTION$
* This function creates a zip file named <cFile>. If the extension
* is ommited, .ZIP will be assumed. If the second parameter is a
* character string, this file will be added to the zip file. If the
* second parameter is an array, all file names contained in <aFiles>
* will be compressed.
*
* If <nLevel> is used, it detemines the compression type where 0 means
* no compression and 9 means best compression.
*
* If <bBlock> is used, every time the file is opened to compress it
* will evaluate bBlock. Parameters of bBlock are cFile and nPos.
*
* If <lOverWrite> is used , it toggles to overwrite or not the existing
* file. Default is to overwrite the file.
* $EXAMPLES$
* FUNCTION MAIN()
*
* IF HB_ZIPFILE( "TEST.ZIP","TEST.PRG")
* qout("File was successly create")
* ENDIF
*
* IF HB_ZIPFILE( "TEST1.ZIP",{"TEST.PRG","c:\windows\win.ini"})
* qout("File was successly create")
* ENDIF
*
* IF HB_ZIPFILE( "TEST2.ZIP",{"TEST.PRG","c:\windows\win.ini"},8,{|nPos,cFile|,qout(cFile)})
* qout("File was successly create")
* ENDIF
*
* aFiles := {"TEST.PRG","c:\windows\win.ini"}
* nLen := Len(afiles)
* aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²')
* GaugeDisplay( aGauge )
* Hb_ZIPFILE('test33.zip',aFiles,8,{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen)})
* Return Nil
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/*
* $DOC$
* $FUNCNAME$
* HB_UNZIPFILE()
* $CATEGORY$
* ZIP FUNCTION
* $ONELINER$
* Unzip a compressed file
* $SYNTAX$
* HB_UNZIPFILE( <cFile> , <bBlock> , <lWithPath>) ---> lCompress
* $ARGUMENTS$
* <cFile> Name of the zip file
*
* <bBlock> Code block to execute while compressing
*
* <lWithPath> Toggle to create directory if needed
*
* $RETURNS$
* <lCompress> .t. if all file was successfuly restored, otherwise .f.
* $DESCRIPTION$
* This function restores all files contained inside the <cFile>.
* If the extension is ommited, .ZIP will be assumed. If a file already
* exists, it wlll be overwriten.
*
* If <bBlock> is used, every time the file is opened to compress it
* will evaluate bBlock. Parameters of bBlock are cFile and nPos.
* $EXAMPLES$
* FUNCTION MAIN()
*
* IF HB_UNZIPFILE( "TEST.ZIP")
* qout("File was successly create")
* ENDIF
*
* IF HB_ZIPFILE( "TEST2.ZIP",{|cFile|,qout(cFile)})
* qout("File was successly create")
* ENDIF
*
* Return Nil
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/*
* $DOC$
* $FUNCNAME$
* HB_GETUNZIPFILE()
* $CATEGORY$
* ZIP FUNCTION
* $ONELINER$
* Gets the number of files that are in the zipfile
* $SYNTAX$
* HB_GETUNZIPFILE( <cFile>) ---> nNumber
* $ARGUMENTS$
* <cFile> Name of the zip file
* $RETURNS$
* <nNumber> The number of files contained inside the zipfile
* $DESCRIPTION$
* This function returns the number of files that is stored in the zipfile.
* The purpose for this function is to use in conjuntion with the
* HB_UNZIPFILE() function, so you can use returned result in the code
* block. See example below.
* $EXAMPLES$
* FUNCTION MAIN()
* Local nFiles :=HB_GETUNZIPFILE('test.zip')
*
* if nFiles >0
* ? "This files Contains ",nfiles
* endif
*
* Return Nil
*
* Here is an example of How to use HB_GETUNZIPFILE() in conjunction
* with HB_UNZIPFILE()
*
* Function Main()
* Local aGauge,nLen
*
* aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²')
* GaugeDisplay( aGauge )
* nLen := HB_GETUNZIPFILE('test22')
* hb_UNZIPFILE('test22',{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen),qout(cFile)},.t.)
*
* Return Nil
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/

View File

@@ -1,708 +0,0 @@
/*
* $DOC$
* $FUNCNAME$
* HB_ZIPFILE()
* $CATEGORY$
* ZIP FUNCTION
* $ONELINER$
* Create a zip file
* $SYNTAX$
* HB_ZIPFILE( <cFile> , <cFileToCompress> | <aFiles>, <nLevel> ,
* <bBlock>,<lOverWrite> ,<cPassword>,<lWithPath>,<lWithDrive>) ---> lCompress
* $ARGUMENTS$
* <cFile> Name of the zip file
*
* <cFileToCompress> Name of a file to Compress, Drive and/or path
* can be used
*
* <aFiles> An array containing files to compress, Drive and/or path
* can be used
*
* <nLevel> Compression level ranging from 0 to 9
*
* <bBlock> Code block to execute while compressing
*
* <lOverWrite> Toggle to overwite the file if exists
*
* <cPassword> Password to encrypt the files
*
* <lWithPath> Toggle to store the path or not
*
* <lWithDrive> Toggle to store the Drive letter and path or not
* $RETURNS$
* <lCompress> .t. if file was create, otherwise .f.
* $DESCRIPTION$
* This function creates a zip file named <cFile>. If the extension
* is ommited, .ZIP will be assumed. If the second parameter is a
* character string, this file will be added to the zip file. If the
* second parameter is an array, all file names contained in <aFiles>
* will be compressed.
*
* If <nLevel> is used, it detemines the compression type where 0 means
* no compression and 9 means best compression.
*
* If <bBlock> is used, every time the file is opened to compress it
* will evaluate bBlock. Parameters of bBlock are cFile and nPos.
*
* If <lOverWrite> is used , it toggles to overwrite or not the existing
* file. Default is to overwrite the file,otherwise if <lOverWrite> is false
* the new files are added to the <cFile>.
*
* If <cPassword> is used, all files that are added to the archive are encrypted
* with the password.
*
* If <lWithPath> is used, it tells thats the path should also be stored with
* the file name. Default is false.
*
* If <lWithDrive> is used, it tells thats the Drive and path should also be stored
* with the file name. Default is false.
*
* $EXAMPLES$
* FUNCTION MAIN()
*
* IF HB_ZIPFILE( "TEST.ZIP","TEST.PRG")
* qout("File was successly create")
* ENDIF
*
* IF HB_ZIPFILE( "TEST1.ZIP",{"TEST.PRG","c:\windows\win.ini"})
* qout("File was successly create")
* ENDIF
*
* IF HB_ZIPFILE( "TEST2.ZIP",{"TEST.PRG","c:\windows\win.ini"},8,{|nPos,cFile|,qout(cFile)})
* qout("File was successly create")
* ENDIF
*
* aFiles := {"TEST.PRG","c:\windows\win.ini"}
* nLen := Len(afiles)
* aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²')
* GaugeDisplay( aGauge )
* Hb_ZIPFILE('test33.zip',aFiles,8,{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen)},,'hello')
* Return Nil
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/*
* $DOC$
* $FUNCNAME$
* HB_UNZIPFILE()
* $CATEGORY$
* ZIP FUNCTION
* $ONELINER$
* Unzip a compressed file
* $SYNTAX$
* HB_UNZIPFILE( <cFile> , <bBlock> , <lWithPath>) ,<cPassWord>,<cPath>,
* [<cFile>|<aFile>] <---> lCompress
* $ARGUMENTS$
* <cFile> Name of the zip file
*
* <bBlock> Code block to execute while compressing
*
* <lWithPath> Toggle to create directory if needed
*
* <cPassWord> Password to use to extract files
*
* <cPath> Path to extract the files.
*
* <cFile>|<aFiles> An file or an Array of files to extract
* $RETURNS$
* <lCompress> .t. if all file was successfuly restored, otherwise .f.
* $DESCRIPTION$
* This function restores all files contained inside the <cFile>.
* If the extension is ommited, .ZIP will be assumed. If a file already
* exists, it wlll be overwriten.
*
* If <bBlock> is used, every time the file is opened to compress it
* will evaluate bBlock. Parameters of bBlock are cFile and nPos.
*
* The <cPath> is an obrogatory parameter. Set to ".\" to extract to the
* current dir
* $EXAMPLES$
* FUNCTION MAIN()
*
* IF HB_UNZIPFILE( "TEST.ZIP")
* qout("File was successly create")
* ENDIF
*
* IF HB_ZIPFILE( "TEST2.ZIP",{|cFile|,qout(cFile)})
* qout("File was successly create")
* ENDIF
*
* Return Nil
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/*
* $DOC$
* $FUNCNAME$
* HB_GETUNZIPFILE()
* $CATEGORY$
* ZIP FUNCTION
* $ONELINER$
* Gets the number of files that are in the zipfile
* $SYNTAX$
* HB_GETUNZIPFILE( <cFile>) ---> nNumber
* $ARGUMENTS$
* <cFile> Name of the zip file
* $RETURNS$
* <nNumber> The number of files contained inside the zipfile
* $DESCRIPTION$
* This function returns the number of files that is stored in the zipfile.
* The purpose for this function is to use in conjuntion with the
* HB_UNZIPFILE() function, so you can use returned result in the code
* block. See example below.
* $EXAMPLES$
* FUNCTION MAIN()
* Local nFiles :=HB_GETUNZIPFILE('test.zip')
*
* if nFiles >0
* ? "This files Contains ",nfiles
* endif
*
* Return Nil
*
* Here is an example of How to use HB_GETUNZIPFILE() in conjunction
* with HB_UNZIPFILE()
*
* Function Main()
* Local aGauge,nLen
*
* aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²')
* GaugeDisplay( aGauge )
* nLen := HB_GETUNZIPFILE('test22')
* hb_UNZIPFILE('test22',{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen),qout(cFile)},.t.)
*
* Return Nil
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/*
* $DOC$
* $FUNCNAME$
* HB_ZIPFILEBYTDSPAN()
* $CATEGORY$
* ZIP FUNCTION
* $ONELINER$
* Create a zip file
* $SYNTAX$
* HB_ZIPFILEBYTDSPAN()( <cFile> , <cFileToCompress> | <aFiles>, <nLevel> ,
* <bBlock>,<lOverWrite> ,<cPassword>,<iSize>,<lWithPath>,<lWithDrive>) ---> lCompress
* $ARGUMENTS$
* <cFile> Name of the zip file
*
* <cFileToCompress> Name of a file to Compress, Drive and/or path
* can be used
*
* <aFiles> An array containing files to compress, Drive and/or path
* can be used
*
* <nLevel> Compression level ranging from 0 to 9
*
* <bBlock> Code block to execute while compressing
*
* <lOverWrite> Toggle to overwite the file if exists
*
* <cPassword> Password to encrypt the files
*
* <iSize> Size of the archive, in bytes,default is 1457664 bytes
*
* <lWithPath> Toggle to store the path or not
*
* <lWithDrive> Toggle to store the Drive letter and path or not
* $RETURNS$
* <lCompress> .t. if file was create, otherwise .f.
* $DESCRIPTION$
* This function creates a zip file named <cFile>. If the extension
* is ommited, .ZIP will be assumed. If the second parameter is a
* character string, this file will be added to the zip file. If the
* second parameter is an array, all file names contained in <aFiles>
* will be compressed.
*
* If <nLevel> is used, it detemines the compression type where 0 means
* no compression and 9 means best compression.
*
* If <bBlock> is used, every time the file is opened to compress it
* will evaluate bBlock. Parameters of bBlock are cFile and nPos.
*
* If <lOverWrite> is used , it toggles to overwrite or not the existing
* file. Default is to overwrite the file,otherwise if <lOverWrite> is false
* the new files are added to the <cFile>.
*
* If <lWithPath> is used, it tells thats the path should also be stored with
* the file name. Default is false.
*
* If <lWithDrive> is used, it tells thats the Drive and path should also be stored
* with the file name. Default is false.
*
* $EXAMPLES$
* FUNCTION MAIN()
*
* IF HB_ZIPFILEBYTDSPAN( "TEST.ZIP","TEST.PRG")
* qout("File was successly create")
* ENDIF
*
* IF ZIPFILEBYTDSPAN( "TEST1.ZIP",{"TEST.PRG","c:\windows\win.ini"})
* qout("File was successly create")
* ENDIF
*
* IF HB_ZIPFILEBYTDSPAN( "TEST2.ZIP",{"TEST.PRG","c:\windows\win.ini"},8,{|nPos,cFile|,qout(cFile)},'hello',,521421)
* qout("File was successly create")
* ENDIF
*
* aFiles := {"TEST.PRG","c:\windows\win.ini"}
* nLen := Len(afiles)
* aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²')
* GaugeDisplay( aGauge )
* HB_ZIPFILEBYTDSPAN('test33.zip',aFiles,8,{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen)},,'hello',,6585452)
* Return Nil
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/*
* $DOC$
* $FUNCNAME$
* HB_ZIPFILEBYPKSPAN()
* $CATEGORY$
* ZIP FUNCTION
* $ONELINER$
* Create a zip file on removable media
* $SYNTAX$
* HB_ZIPFILEBYPKSPAN( <cFile> , <cFileToCompress> | <aFiles>, <nLevel> ,
* <bBlock>,<lOverWrite> ,<cPassword>,<lWithPath>,<lWithDrive>) ---> lCompress
* $ARGUMENTS$
* <cFile> Name of the zip file
*
* <cFileToCompress> Name of a file to Compress, Drive and/or path
* can be used
*
* <aFiles> An array containing files to compress, Drive and/or path
* can be used
*
* <nLevel> Compression level ranging from 0 to 9
*
* <bBlock> Code block to execute while compressing
*
* <lOverWrite> Toggle to overwite the file if exists
*
* <cPassword> Password to encrypt the files
*
* <lWithPath> Toggle to store the path or not
*
* <lWithDrive> Toggle to store the Drive letter and path or not
* $RETURNS$
* <lCompress> .t. if file was create, otherwise .f.
* $DESCRIPTION$
* This function creates a zip file named <cFile>. If the extension
* is ommited, .ZIP will be assumed. If the second parameter is a
* character string, this file will be added to the zip file. If the
* second parameter is an array, all file names contained in <aFiles>
* will be compressed.Also , the use of this function is for creating
* backup in removable media like an floppy drive/zip drive.
*
* If <nLevel> is used, it detemines the compression type where 0 means
* no compression and 9 means best compression.
*
* If <bBlock> is used, every time the file is opened to compress it
* will evaluate bBlock. Parameters of bBlock are cFile and nPos.
*
* If <lOverWrite> is used , it toggles to overwrite or not the existing
* file. Default is to overwrite the file,otherwise if <lOverWrite> is false
* the new files are added to the <cFile>.
*
* If <cPassword> is used, all files that are added to the archive are encrypted
* with the password.
*
* If <lWithPath> is used, it tells thats the path should also be stored with
* the file name. Default is false.
*
* If <lWithDrive> is used, it tells thats the Drive and path should also be stored
* with the file name. Default is false.
*
* Before calling this function, Set an Changedisk codeblock by calling
* the HB_SETDISKZIP().
* $EXAMPLES$
* FUNCTION MAIN()
*
* IF HB_ZIPFILE( "a:\TEST.ZIP","TEST.PRG")
* qout("File was successly create")
* ENDIF
*
* IF HB_ZIPFILEBYPKSPAN( "a:\TEST1.ZIP",{"TEST.PRG","c:\windows\win.ini"})
* qout("File was successly create")
* ENDIF
*
* IF HB_ZIPFILEBYPKSPAN( "TEST2.ZIP",{"TEST.PRG","c:\windows\win.ini"},8,{|nPos,cFile|,qout(cFile)})
* qout("File was successly create")
* ENDIF
*
* aFiles := {"TEST.PRG","c:\windows\win.ini"}
* nLen := Len(afiles)
* aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²')
* GaugeDisplay( aGauge )
* Hb_ZIPFILEBYPKSPAN('f:\test33.zip',aFiles,8,{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen)},,'hello')
* // assuming f:\ as an Zip Drive
* Return Nil
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/* $DOC$
* $FUNCNAME$
* HB_SETDISKZIP()
* $CATEGORY$
* Zip Function
* $ONELINER$
* Set an codeblock for disk changes
* $SYNTAX$
* HB_SETDISKZIP(<bBlock>)
* $ARGUMENTS$
* <bBlock> an Code block that contains an function that will be performed
* when the need of changing disk are need.
* $RETURNS$
* It returns allways True
* $DESCRIPTION$
* This function will set an codeblock that will be evaluated every time
* that an changedisk event is neccessary.
*
* Set this function before opening archives that are in removable media.
* This block will be released, when the caller finish it job.
* $EXAMPLES$
* HB_SETDISKZIP({|x| alert('Please insert disk no "+str(x,3))})
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/* $DOC$
* $FUNCNAME$
* HB_ZIPDELETEFILES()
* $CATEGORY$
* Zip Functions
* $ONELINER$
* Delete files from an zip archive
* $SYNTAX$
* HB_ZIPDELETEFILES(<cFile>,<cFiletoDelete>|<aFiles>) --> <lDeleted>
* $ARGUMENTS$
* <cFile> The name of the zip files from where the files will be deleted
*
* <cFiletoDelete> An File to be removed
*
* <aFiles> An Array of Files to Be Removed
* $RETURNS$
* <lDeleted> If the files are deleted , it will return .T., otherwise
* it will return .f. for the Follow cases: Spanned Archives, the file
* could not be found in the zip file.
* $DESCRIPTION$
* This function removes files from an Zip archive.
* $EXAMPLES$
* ? "has the file zipnew.i been deleted ",if(HB_ZIPDELETEFILES('\test23.zip','zipnew.i'),"Yes","No")
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/* $DOC$
* $FUNCNAME$
* HB_ZIPTESTPK()
* $CATEGORY$
* Zip Functions
* $ONELINER$
* Test pkSpaned zip files
* $SYNTAX$
* HB_ZIPTESTPK(<cFile>) --> <nReturnCode>
* $ARGUMENTS$
* <cFile> File to be tested.
* $RETURNS$
* <nReturn> An code that tell if the current disk is the Last of an pkspanded
* disk set.
* $DESCRIPTION$
* This function tests if the disk inserted is the last disk of an backup
* set or not.
* It will return the follow return code when an error is found
*
* <table>
* Error code Meaning
* 114 Incorrect Disk
* 103 No Call back was set with HB_SETDISKZIP()
* </table>
*
* Call this function to determine if the disk inserted is the correct
* one before any other function.
* $EXAMPLES$
* if (HB_ZIPTESTPK('a:\test22.zip')==114)
* ? "invalid Disk"
* endif
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/* $DOC$
* $FUNCNAME$
* HB_GETZIPCOMMENT()
* $CATEGORY$
* Zip Functions
* $ONELINER$
* Return the comment of an zip file
* $SYNTAX$
* HB_GETZIPCOMMENT(<szFile>) --> <szComment>
* $ARGUMENTS$
* <szFile> File to get the comment from
* $RETURNS$
* <szComment> The comment that was stored in <szFile>
* $DESCRIPTION$
* This function recieve an valid zip file name as parameter,
* and return the global comment stored within.
* $EXAMPLES$
* ? "The comment of tes.zip",HB_GETZIPCOMMENT('tes.zip')
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/* $DOC$
* $FUNCNAME$
* HB_SETZIPCOMMENT()
* $CATEGORY$
* Zip Functions
* $ONELINER$
* Set an Zip archive Comment
* $SYNTAX$
* HB_SETZIPCOMMENT(<cComment>) -->Nil
* $ARGUMENTS$
* <cComment> Comment to add to the zip archive
* $RETURNS$
* <NIL> this function always return NIL
* $DESCRIPTION$
* This function stored an global comment to an zip archive.
* It should be called before any of the Compression Function.
* $EXAMPLES$
* HB_SETZIPCOMMENT("This is an Test")
* hb_zipfile('test.zip',{"\windows\ios.ini","\windows\win.ini"})
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/* $DOC$
* $FUNCNAME$
* HB_SETBUFFER()
* $CATEGORY$
*
* $ONELINER$
*
* $SYNTAX$
* HB_SETBUFFER([<nWriteBuffer>],[<nExtractBuffer>],[<nReadBuffer>]) -->Nil
* $ARGUMENTS$
* <nWriteBuffer> The size of the write buffer.
*
* <nExtractBuffer> The size of the extract buffer.
*
* <nReadBuffer> The size of the read buffer.
* $RETURNS$
* <NIL> This function always return NIL.
* $DESCRIPTION$
* This function set the size of the internal buffers for read/write/extract
* operation
*
* If the size of the buffer is smaller then the default , the function
* will automaticaly use the default values,which is 65535/16384/32768.
*
* This function be called before any of the Compression/decompression
* Function.
* $EXAMPLES$
* HB_SETBUFFER(100000,115214,65242)
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/*
* $DOC$
* $FUNCNAME$
* HB_GETUNRARFILE()
* $CATEGORY$
* RAR FUNCTION
* $ONELINER$
* Gets the number of files that are in the rar file
* $SYNTAX$
* HB_GETUNRARFILE( <cFile>) ---> nNumber
* $ARGUMENTS$
* <cFile> Name of the rar file
* $RETURNS$
* <nNumber> The number of files contained inside the rarfile
* $DESCRIPTION$
* This function returns the number of files that is stored in the rar file.
* $EXAMPLES$
* FUNCTION MAIN()
* Local nFiles :=HB_GETUNZIPFILE('test.zip')
*
* if nFiles >0
* ? "This files Contains ",nfiles
* endif
*
* Return Nil
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $FILES$
* Library is zlib.lib and zlib_bor.lib For Borland Compilers
* Library is zlib.lib zlib_ms.lib for MSVC compilers
* $END$
*/
/* $DOC$
* $FUNCNAME$
* COMPRESSSTRING()
* $CATEGORY$
* Compression()
* $ONELINER$
* Compress an string
* $SYNTAX$
* CompressString(@<cString>,@<nSize>)
* $ARGUMENTS$
* <cString> Buffer to compress, must be passed by reference.
*
* <nSize> The Lenght of the compression String
* $RETURNS$
* NIL
* $DESCRIPTION$
* This function compress an string buffer and return the compression function
* and the size of this compression function.
* This size is required for uncompression the string
* $EXAMPLES$
* Local cTest:= memoread('tzipfile.prg')
* ? 'String before compressing',cTest
*
* COMPRESSSTRING(@cTest,@nSize)
* ? "Size",nSize
* ? " "
* ? " "
* ? 'String after compressing',cTest
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $SEEALSO$
* UNCOMPRESSSTRING()
* $END$
*/
/* $DOC$
* $FUNCNAME$
* UNCOMPRESSSTRING()
* $CATEGORY$
* Compression
* $ONELINER$
* Uncompress an String
* $SYNTAX$
* UNCOMPRESSSTRING(<cBuffer>,<nSize>) ---> <cUncompressBuffer>
* $ARGUMENTS$
* <cBuffer> The compressing string to uncompress
*
* <nSize> The saved size returned by compressionstring
* $RETURNS$
* <cUncompressBuffer> The String uncompressed
* $DESCRIPTION$
*
* $EXAMPLES$
* cOrig:=UNCOMPRESSSTRING(cTest,nSize)
* ?'uncompressed String',cOrig
* $STATUS$
* R
* $COMPLIANCE$
* This function is a Harbour extension
* $PLATFORMS$
* All
* $SEEALSO$
* COMPRESSSTRING()
* $END$
*/

View File

@@ -1,90 +0,0 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Header file for the Zlib API,
*
* Copyright 2000 Luiz Rafael Culik <culik@sl.conex.net>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#ifndef HB_APIZLIB_H_
#define HB_APIZLIB_H_
#include <hbsetup.h>
#include <hbapi.h>
#include <hbapiitm.h>
#include <hbapifs.h>
#include <hbapigt.h>
#include <hbvmpub.h>
#include <hbvm.h>
#include "zip.h"
#include "unzip.h"
HB_EXTERN_BEGIN
#define filePos 1
#define Lenght 2
#define Method 3
#define Size 4
#define Ratio 5
#define Date 6
#define Time 7
#define Crc32 8
extern uLong hb___filetime(char *f, tm_zip *tmzip, uLong *dt);
extern char *hb___CheckFile( char * szFile);
extern int hb___CompressOneFile(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite);
extern int hb___CompressMultipleFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite);
extern BOOL hb___unZipFiles(char *szFile,PHB_ITEM pBlock,BOOL bExtractPath);
extern int hb___ExtractCurrentFile(unzFile uf,BOOL popt_extract_without_path,BOOL popt_overwrite,PHB_ITEM pBlock);
extern void hb____ChangeFileDate(char *filename,uLong dosdate,tm_unz tmu_date);
extern int hb___MakeDir(char *szNewDirectory);
extern int hb___GetNumbersofFilestoUnzip(char *szFile);
extern PHB_ITEM hb___GetFilesNamesFromZip(char *szFile,BOOL iMode);
HB_EXTERN_END
#endif /* HB_APIEXT_H_ */

View File

@@ -1,128 +0,0 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Header file for the Zlib API,
*
* Copyright 2000-2001 Luiz Rafael Culik <culik@sl.conex.net>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#ifndef HB_APIZLIB_H_
#define HB_APIZLIB_H_
#define HB_OS_WIN_32_USED
#include <hbsetup.h>
#include <hbapi.h>
#include <hbapiitm.h>
#include <hbapifs.h>
#include <hbapigt.h>
#include <hbvmpub.h>
#include <hbvm.h>
#include <time.h>
#ifdef __cplusplus
#include <ZipArchive.h>
extern "C" {
#endif
#define filePos 1
#define Lenght 2
#define Method 3
#define Size 4
#define Ratio 5
#define Date 6
#define Time 7
#define Crc32 8
#define Attr 9
#define WRITEBUFFERSIZE (16384)
#define MAXFILENAME (256)
typedef struct _HB_ZIP_INTERNAL{
int iWrite;
int iExtract;
int iRead;
char * szComment;
PHB_ITEM pItem;
} HB_ZIP_INTERNAL,* PHB_ZIP_INTERNAL,* HB_ZIP_INTERNAL_PTR;
#ifndef LPCTSTR
typedef const char *LPCSTR;
typedef LPCSTR LPCTSTR;
#endif
extern char *hb___CheckFile( char * szFile);
extern PHB_ITEM hb___GetFilesNamesFromZip(char *szFile,BOOL iMode);
extern void hb_____GetTime(struct tm *tz);
extern int hb_CmpPkSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress);
extern int hb_CmpPkSpanStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress);
extern char *hb_getPassWord(char *szName);
extern int hb___GetNumbersofFilestoUnzip(char *szFile);
extern int hb___SetCallbackFunc(PHB_ITEM pFunc);
extern int hb_CmpTdSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize ,BOOL bPath ,BOOL bDrive,PHB_ITEM pProgress);
extern int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress);
extern int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress);
extern int hb_CmpTdSpanStd(char *szFile,char * szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress);
extern int hb_UnzipAll(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pDiskBlock,PHB_ITEM pProgress);
extern int hb_UnzipOne(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,char *szFiletoExtract,PHB_ITEM pProgress);
extern int hb_UnzipSel(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pArray,PHB_ITEM pProgress);
extern int hb_UnzipOneIndex(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,int uiCount,PHB_ITEM pProgress);
extern int hb_UnzipSelIndex(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pSelArray,PHB_ITEM pProgress);
extern int hb_DeleteOne(char *szFile,char *szFiletoDelete);
extern int hb_DeleteSel(char *szFile,PHB_ITEM pArray,BOOL bCase);
extern int hb_DeleteOneIndex(char *szFile,int uiCount);
extern int hb_TestForPKS(char *szFile);
extern void hb_SetZipBuff(int a,int b,int c);
extern void hb_SetZipComment(char *szComment);
extern const char *hb_GetZipComment(char *szFile);
extern BOOL hb_IsPassWord(char *szName);
extern unsigned long GetCurrentFileSize( LPCTSTR szFile);
extern BOOL hb_SaveZipFileFromMemory(char *szFile);
extern BOOL hb_CreateZipInMemory(char *szFileToCompress,char *szFile);
#ifdef __cplusplus
}
#endif
#endif /* HB_APIEXT_H_ */

View File

@@ -1,18 +0,0 @@
#if !defined (ZIP_EXPORT_H)
#define ZIP_EXPORT_H
#if defined (ZIP_HAS_DLL)
# if (ZIP_HAS_DLL == 1)
# if defined (ZIP_BUILD_DLL)
# define ZIP_API __declspec (dllexport)
# else
# define ZIP_API __declspec (dllimport)
# endif /* ZIP_BUILD_DLL */
# else
# define ZIP_API
# endif /* ! ZIP_HAS_DLL == 1 */
#else
# define ZIP_API
#endif /* ZIP_HAS_DLL */
#endif /* ZIP_EXPORT_H */

View File

@@ -1,84 +0,0 @@
#ifndef HB_APIZLIB_H_
#define HB_APIZLIB_H_
#define HB_OS_WIN_32_USED
#include <hbsetup.h>
#include <hbapiitm.h>
#include <hbapifs.h>
#include <hbapigt.h>
#include <hbvmpub.h>
#include <hbvm.h>
#include <time.h>
#ifdef __cplusplus
#include <ZipArchive.h>
extern "C" {
#endif
#define filePos 1
#define Lenght 2
#define Method 3
#define Size 4
#define Ratio 5
#define Date 6
#define Time 7
#define Crc32 8
#define Attr 9
#define WRITEBUFFERSIZE (16384)
#define MAXFILENAME (256)
typedef struct _HB_ZIP_INTERNAL{
int iWrite;
int iExtract;
int iRead;
char * szComment;
PHB_ITEM pItem;
} HB_ZIP_INTERNAL,* PHB_ZIP_INTERNAL,* HB_ZIP_INTERNAL_PTR;
#ifndef LPCTSTR
typedef const char *LPCSTR;
typedef LPCSTR LPCTSTR;
#endif
class SpanCallback : public CZipSpanCallback
{
bool Callback(int iProgress)
{
PHB_ITEM pDisk=hb_itemPutNL(NULL,m_uDiskNeeded);
bool iReturn=true;
hb_vmEvalBlockV( pChangeDiskBlock, 1,pDisk );
hb_itemRelease(pDisk);
return iReturn;
}
};
class SpanActionCallback : public CZipActionCallback
{
bool Callback(int iProgress)
{
int iReturn=1;
PHB_ITEM pDisk;
PHB_ITEM pTotal =hb_itemPutNL(NULL,m_uTotalToDo);
pDisk= hb_itemPutNL(NULL,m_uTotalSoFar);
hb_vmEvalBlockV( pProgressInfo, 2,pDisk,pTotal);
hb_itemRelease(pDisk);
hb_itemRelease(pTotal);
return iReturn;
}
};
class hbZip {
public:
BOOL bAdded;
hbZip(){
bAdded=false
};
virtual ~hbZip();
CZipArchive szZip;
SpanCallback span;
SpanActionCallback spanac;
};
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -1,90 +0,0 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Header file for the Zlib API,
*
* Copyright 2000 Luiz Rafael Culik <culik@sl.conex.net>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#ifndef HB_APIZLIB_H_
#define HB_APIZLIB_H_
#include <hbsetup.h>
#include <hbapi.h>
#include <hbapiitm.h>
#include <hbapifs.h>
#include <hbapigt.h>
#include <hbvmpub.h>
#include <hbvm.h>
#include "zip.h"
#include "unzip.h"
HB_EXTERN_BEGIN
#define filePos 1
#define Lenght 2
#define Method 3
#define Size 4
#define Ratio 5
#define Date 6
#define Time 7
#define Crc32 8
extern uLong hb___filetime(char *f, tm_zip *tmzip, uLong *dt);
extern char *hb___CheckFile( char * szFile);
extern int hb___CompressOneFile(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite);
extern int hb___CompressMultipleFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite);
extern BOOL hb___unZipFiles(char *szFile,PHB_ITEM pBlock,BOOL bExtractPath);
extern int hb___ExtractCurrentFile(unzFile uf,BOOL popt_extract_without_path,BOOL popt_overwrite,PHB_ITEM pBlock);
extern void hb____ChangeFileDate(char *filename,uLong dosdate,tm_unz tmu_date);
extern int hb___MakeDir(char *szNewDirectory);
extern int hb___GetNumbersofFilestoUnzip(char *szFile);
extern PHB_ITEM hb___GetFilesNamesFromZip(char *szFile,BOOL iMode);
HB_EXTERN_END
#endif /* HB_APIEXT_H_ */

View File

@@ -1,128 +0,0 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Header file for the Zlib API,
*
* Copyright 2000-2001 Luiz Rafael Culik <culik@sl.conex.net>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#ifndef HB_APIZLIB_H_
#define HB_APIZLIB_H_
#define HB_OS_WIN_32_USED
#include <hbsetup.h>
#include <hbapi.h>
#include <hbapiitm.h>
#include <hbapifs.h>
#include <hbapigt.h>
#include <hbvmpub.h>
#include <hbvm.h>
#include <time.h>
#ifdef __cplusplus
#include <ZipArchive.h>
extern "C" {
#endif
#define filePos 1
#define Lenght 2
#define Method 3
#define Size 4
#define Ratio 5
#define Date 6
#define Time 7
#define Crc32 8
#define Attr 9
#define WRITEBUFFERSIZE (16384)
#define MAXFILENAME (256)
typedef struct _HB_ZIP_INTERNAL{
int iWrite;
int iExtract;
int iRead;
char * szComment;
PHB_ITEM pItem;
} HB_ZIP_INTERNAL,* PHB_ZIP_INTERNAL,* HB_ZIP_INTERNAL_PTR;
#ifndef LPCTSTR
typedef const char *LPCSTR;
typedef LPCSTR LPCTSTR;
#endif
extern char *hb___CheckFile( char * szFile);
extern PHB_ITEM hb___GetFilesNamesFromZip(char *szFile,BOOL iMode);
extern void hb_____GetTime(struct tm *tz);
extern int hb_CmpPkSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress);
extern int hb_CmpPkSpanStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress);
extern char *hb_getPassWord(char *szName);
extern int hb___GetNumbersofFilestoUnzip(char *szFile);
extern int hb___SetCallbackFunc(PHB_ITEM pFunc);
extern int hb_CmpTdSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize ,BOOL bPath ,BOOL bDrive,PHB_ITEM pProgress);
extern int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress);
extern int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress);
extern int hb_CmpTdSpanStd(char *szFile,char * szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress);
extern int hb_UnzipAll(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pDiskBlock,PHB_ITEM pProgress);
extern int hb_UnzipOne(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,char *szFiletoExtract,PHB_ITEM pProgress);
extern int hb_UnzipSel(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pArray,PHB_ITEM pProgress);
extern int hb_UnzipOneIndex(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,int uiCount,PHB_ITEM pProgress);
extern int hb_UnzipSelIndex(char *szFile,PHB_ITEM pBlock,BOOL bWithPath,char *szPassWord,char *szPath,PHB_ITEM pSelArray,PHB_ITEM pProgress);
extern int hb_DeleteOne(char *szFile,char *szFiletoDelete);
extern int hb_DeleteSel(char *szFile,PHB_ITEM pArray,BOOL bCase);
extern int hb_DeleteOneIndex(char *szFile,int uiCount);
extern int hb_TestForPKS(char *szFile);
extern void hb_SetZipBuff(int a,int b,int c);
extern void hb_SetZipComment(char *szComment);
extern const char *hb_GetZipComment(char *szFile);
extern BOOL hb_IsPassWord(char *szName);
extern unsigned long GetCurrentFileSize( LPCTSTR szFile);
extern BOOL hb_SaveZipFileFromMemory(char *szFile);
extern BOOL hb_CreateZipInMemory(char *szFileToCompress,char *szFile);
#ifdef __cplusplus
}
#endif
#endif /* HB_APIEXT_H_ */

View File

@@ -1,15 +0,0 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by version.rc
//
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@@ -1,126 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: stdafx.h $
// $Archive: /ZipArchive_STL/stdafx.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_STDAFX_H__926F70F4_1B34_49AA_9532_498E8D2F3495__INCLUDED_)
#define AFX_STDAFX_H__926F70F4_1B34_49AA_9532_498E8D2F3495__INCLUDED_
#if (_MSC_VER < 1300) && !defined (__BORLANDC__) && !defined (__GNUC__)
#define ZIPINLINE inline
#else
#define ZIPINLINE
#endif
#define ZIP_ARCHIVE_STL
#if _MSC_VER > 1000
#pragma once
//because of STL
#pragma warning (disable : 4710) // 'function' : function not inlined
#pragma warning (disable : 4514) // unreferenced inline/local function has been removed
#pragma warning (disable:4786) // 'identifier' : identifier was truncated to 'number' characters in the debug information
#endif // _MSC_VER > 1000
// some Windows typical definitions
#if defined (_UNICODE) && !defined (UNICODE)
#define UNICODE
#endif
#if defined (UNICODE) && !defined (_UNICODE)
#define _UNICODE
#endif
#ifndef _WIN32
#ifndef NULL
#define NULL 0
#endif
#include <ctype.h>
typedef int HFILE;
typedef void* HANDLE;
typedef unsigned long DWORD;
typedef long LONG;
typedef int BOOL;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int UINT;
#ifndef FALSE
#define FALSE (int)0
#endif
#ifndef TRUE
#define TRUE (int)1
#endif
typedef unsigned short WCHAR; // wc, 16-bit UNICODE character
typedef const WCHAR *LPCWSTR;
typedef const char *LPCSTR;
typedef WCHAR *LPWSTR;
typedef char *LPSTR;
#ifdef _UNICODE
typedef wchar_t TCHAR;
typedef LPCWSTR LPCTSTR;
typedef LPWSTR LPTSTR;
#define _T(x) L ## x
#else /* _UNICODE */ // r_winnt
typedef char TCHAR;
typedef LPCSTR LPCTSTR;
typedef LPSTR LPTSTR;
#define _T(x) x
#endif /* _UNICODE */ // r_winnt
#else
#include <TCHAR.H>
#include <windows.H>
#ifndef STRICT
#define STRICT
#endif
#endif // #ifndef _WIN32
#ifndef ASSERT
#include <assert.h>
#define ASSERT(f) assert((f))
#endif
#ifndef VERIFY
#ifdef _DEBUG
#define VERIFY(x) ASSERT((x))
#else
#define VERIFY(x) x
#endif
#endif
#ifndef TRACE
#define TRACE
#endif
#if _MSC_VER >= 1300
#define ZIP_ULONGLONG ULONGLONG
#define ZIP_LONGLONG LONGLONG
#else
#define ZIP_ULONGLONG DWORD
#define ZIP_LONGLONG LONG
#endif
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__926F70F4_1B34_49AA_9532_498E8D2F3495__INCLUDED_)

View File

@@ -1,274 +0,0 @@
/* unzip.h -- IO for uncompress .zip files using zlib
Version 0.15 beta, Mar 19th, 1998,
Copyright (C) 1998 Gilles Vollant
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Encryption and multi volume ZipFile (span) are not supported.
Old compressions used by old PKZip 1.x are not supported
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
CAN CHANGE IN FUTURE VERSION !!
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip */
#ifndef _unz_H
#define _unz_H
#ifndef _HBCOMPRESS_H
#include "hbcomprs.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagunzFile__ { int unused; } unzFile__;
typedef unzFile__ *unzFile;
#else
typedef voidp unzFile;
#endif
#define UNZ_OK (0)
#define UNZ_END_OF_LIST_OF_FILE (-100)
#define UNZ_ERRNO (Z_ERRNO)
#define UNZ_EOF (0)
#define UNZ_PARAMERROR (-102)
#define UNZ_BADZIPFILE (-103)
#define UNZ_INTERNALERROR (-104)
#define UNZ_CRCERROR (-105)
/* tm_unz contain date/time info */
typedef struct tm_unz_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_unz;
/* unz_global_info structure contain global data about the ZIPfile
These data comes from the end of central dir */
typedef struct unz_global_info_s
{
uLong number_entry; /* total number of entries in
the central dir on this disk */
uLong size_comment; /* size of the global comment of the zipfile */
} unz_global_info;
/* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_info_s
{
uLong version; /* version made by 2 bytes */
uLong version_needed; /* version needed to extract 2 bytes */
uLong flag; /* general purpose bit flag 2 bytes */
uLong compression_method; /* compression method 2 bytes */
uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
uLong crc; /* crc-32 4 bytes */
uLong compressed_size; /* compressed size 4 bytes */
uLong uncompressed_size; /* uncompressed size 4 bytes */
uLong size_filename; /* filename length 2 bytes */
uLong size_file_extra; /* extra field length 2 bytes */
uLong size_file_comment; /* file comment length 2 bytes */
uLong disk_num_start; /* disk number start 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
tm_unz tmu_date;
} unz_file_info;
extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
const char* fileName2,
int iCaseSensitivity));
/*
Compare two filename (fileName1,fileName2).
If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
or strcasecmp)
If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
(like 1 on Unix, 2 on Windows)
*/
extern unzFile ZEXPORT unzOpen OF((const char *path));
/*
Open a Zip file. path contain the full pathname (by example,
on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
"zlib/zlib111.zip".
If the zipfile cannot be opened (file don't exist or in not valid), the
return value is NULL.
Else, the return value is a unzFile Handle, usable with other function
of this unzip package.
*/
extern int ZEXPORT unzClose OF((unzFile file));
/*
Close a ZipFile opened with unzipOpen.
If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
unz_global_info *pglobal_info));
/*
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
return UNZ_OK if there is no problem. */
extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
char *szComment, uLong uSizeBuf));
/*
Get the global comment string of the ZipFile, in the szComment buffer.
uSizeBuf is the size of the szComment buffer.
return the number of byte copied or an error code <0
*/
/***************************************************************************/
/* Unzip package allow you browse the directory of the zipfile */
extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
/*
Set the current file of the zipfile to the first file.
return UNZ_OK if there is no problem
*/
extern int ZEXPORT unzGoToNextFile OF((unzFile file));
/*
Set the current file of the zipfile to the next file.
return UNZ_OK if there is no problem
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
*/
extern int ZEXPORT unzLocateFile OF((unzFile file,
const char *szFileName,
int iCaseSensitivity));
/*
Try locate the file szFileName in the zipfile.
For the iCaseSensitivity signification, see unzStringFileNameCompare
return value :
UNZ_OK if the file is found. It becomes the current file.
UNZ_END_OF_LIST_OF_FILE if the file is not found
*/
extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
unz_file_info *pfile_info,
char *szFileName,
uLong fileNameBufferSize,
void *extraField,
uLong extraFieldBufferSize,
char *szComment,
uLong commentBufferSize));
/*
Get Info about the current file
if pfile_info!=NULL, the *pfile_info structure will contain somes info about
the current file
if szFileName!=NULL, the filemane string will be copied in szFileName
(fileNameBufferSize is the size of the buffer)
if extraField!=NULL, the extra field information will be copied in extraField
(extraFieldBufferSize is the size of the buffer).
This is the Central-header version of the extra field
if szComment!=NULL, the comment string of the file will be copied in szComment
(commentBufferSize is the size of the buffer)
*/
/***************************************************************************/
/* for reading the content of the current zipfile, you can open it, read data
from it, and close it (you can close it before reading all the file)
*/
extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
/*
Open for reading data the current file in the zipfile.
If there is no error, the return value is UNZ_OK.
*/
extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
/*
Close the file in zip opened with unzOpenCurrentFile
Return UNZ_CRCERROR if all the file was read but the CRC is not good
*/
extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
voidp buf,
unsigned len));
/*
Read bytes from the current file (opened by unzOpenCurrentFile)
buf contain buffer where data must be copied
len the size of buf.
return the number of byte copied if somes bytes are copied
return 0 if the end of file was reached
return <0 with error code if there is an error
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
*/
extern z_off_t ZEXPORT unztell OF((unzFile file));
/*
Give the current position in uncompressed data
*/
extern int ZEXPORT unzeof OF((unzFile file));
/*
return 1 if the end of file was reached, 0 elsewhere
*/
extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
voidp buf,
unsigned len));
/*
Read extra field from the current file (opened by unzOpenCurrentFile)
This is the local-header version of the extra field (sometimes, there is
more info in the local-header version than in the central-header)
if buf==NULL, it return the size of the local extra field
if buf!=NULL, len is the size of the buffer, the extra header is copied in
buf.
the return value is the number of bytes copied in buf, or (if <0)
the error code
*/
#ifdef __cplusplus
}
#endif
#endif /* _unz_H */

View File

@@ -1,302 +0,0 @@
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2002 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#ifndef _ZCONF_H
#define _ZCONF_H
/*
#if _MSC_VER > 1000
#pragma warning (disable : 4131)
#pragma warning (disable : 4115)
#pragma warning (disable : 4127)
#pragma warning (disable : 4100)
#pragma warning (disable : 4244)
#pragma warning (disable : 4702)
#pragma warning (disable : 4206)
#endif // _MSC_VER > 1000
*/
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
#ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
# define inflateInit_ z_inflateInit_
# define inflate z_inflate
# define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset
# define deflateParams z_deflateParams
# define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateReset z_inflateReset
# define compress z_compress
# define compress2 z_compress2
# define uncompress z_uncompress
# define adler32 z_adler32
# define crc32 z_crc32
# define get_crc_table z_get_crc_table
# define Byte z_Byte
# define uInt z_uInt
# define uLong z_uLong
# define Bytef z_Bytef
# define charf z_charf
# define intf z_intf
# define uIntf z_uIntf
# define uLongf z_uLongf
# define voidpf z_voidpf
# define voidp z_voidp
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
# ifndef __32BIT__
# define __32BIT__
# endif
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#if defined(MSDOS) && !defined(__32BIT__)
# define MAXSEG_64K
#endif
#ifdef MSDOS
# define UNALIGNED_OK
#endif
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
# define STDC
#endif
#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
# ifndef STDC
# define STDC
# endif
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const
# endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Old Borland C incorrectly complains about missing returns: */
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
# define NEED_DUMMY_RETURN
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
/* Type declarations */
/* function prototypes */
#ifdef OF
#undef OF
#endif
/*
#ifndef OF
# ifdef STDC
*/
# define OF(args) args
/*
# else
# define OF(args) ()
# endif
#endif
*/
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR _far
# else
# define FAR far
# endif
#endif
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
# ifndef __32BIT__
# define SMALL_MEDIUM
# define FAR _far
# endif
#endif
/* Compile with -DZLIB_DLL for Windows DLL support */
#if defined(ZLIB_DLL)
# if defined(_WINDOWS) || defined(WINDOWS)
# ifdef FAR
# undef FAR
# endif
# include <windows.h>
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR _cdecl _export
# endif
# endif
# if defined (__BORLANDC__)
# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
# include <windows.h>
# define ZEXPORT __declspec(dllexport) WINAPI
# define ZEXPORTRVA __declspec(dllexport) WINAPIV
# else
# if defined (_Windows) && defined (__DLL__)
# define ZEXPORT _export
# define ZEXPORTVA _export
# endif
# endif
# endif
#endif
#if defined (__BEOS__)
# if defined (ZLIB_DLL)
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef FAR
# define FAR
#endif
#if !defined(MACOS) && !defined(TARGET_OS_MAC)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#ifdef HAVE_UNISTD_H
# include <sys/types.h> /* for off_t */
# include <unistd.h> /* for SEEK_* and off_t */
# define z_off_t off_t
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
#endif
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
# pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND")
# pragma map(inflateInit_,"ININ")
# pragma map(inflateInit2_,"ININ2")
# pragma map(inflateEnd,"INEND")
# pragma map(inflateSync,"INSY")
# pragma map(inflateSetDictionary,"INSEDI")
# pragma map(inflate_blocks,"INBL")
# pragma map(inflate_blocks_new,"INBLNE")
# pragma map(inflate_blocks_free,"INBLFR")
# pragma map(inflate_blocks_reset,"INBLRE")
# pragma map(inflate_codes_free,"INCOFR")
# pragma map(inflate_codes,"INCO")
# pragma map(inflate_fast,"INFA")
# pragma map(inflate_flush,"INFLU")
# pragma map(inflate_mask,"INMA")
# pragma map(inflate_set_dictionary,"INSEDI2")
# pragma map(inflate_copyright,"INCOPY")
# pragma map(inflate_trees_bits,"INTRBI")
# pragma map(inflate_trees_dynamic,"INTRDY")
# pragma map(inflate_trees_fixed,"INTRFI")
# pragma map(inflate_trees_free,"INTRFR")
#endif
#endif /* _ZCONF_H */

View File

@@ -1,152 +0,0 @@
/* zip.h -- IO for compress .zip files using zlib
Version 0.15 alpha, Mar 19th, 1998,
Copyright (C) 1998 Gilles Vollant
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
Encryption and multi volume ZipFile (span) are not supported.
Old compressions used by old PKZip 1.x are not supported
For uncompress .zip file, look at unzip.h
THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
CAN CHANGE IN FUTURE VERSION !!
I WAIT FEEDBACK at mail info@winimage.com
Visit also http://www.winimage.com/zLibDll/zip.htm for evolution
Condition of use and distribution are the same than zlib :
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/* for more info about .ZIP format, see
ftp://ftp.cdrom.com/pub/infozip/doc/appnote-970311-iz.zip
PkWare has also a specification at :
ftp://ftp.pkware.com/probdesc.zip
*/
#ifndef _zip_H
#define _zip_H
#ifndef _HBCOMPRESS_H
#include "hbcomprs.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
/* like the STRICT of WIN32, we define a pointer that cannot be converted
from (void*) without cast */
typedef struct TagzipFile__ { int unused; } zipFile__;
typedef zipFile__ *zipFile;
#else
typedef voidp zipFile;
#endif
#define ZIP_OK (0)
#define ZIP_ERRNO (Z_ERRNO)
#define ZIP_PARAMERROR (-102)
#define ZIP_INTERNALERROR (-104)
/* tm_zip contain date/time info */
typedef struct tm_zip_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
} tm_zip;
typedef struct
{
tm_zip tmz_date; /* date in understandable format */
uLong dosDate; /* if dos_date == 0, tmu_date is used */
/* uLong flag; */ /* general purpose bit flag 2 bytes */
uLong internal_fa; /* internal file attributes 2 bytes */
uLong external_fa; /* external file attributes 4 bytes */
} zip_fileinfo;
extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
/*
Create a zipfile.
pathname contain on Windows NT a filename like "c:\\zlib\\zlib111.zip" or on
an Unix computer "zlib/zlib111.zip".
if the file pathname exist and append=1, the zip will be created at the end
of the file. (useful if the file contain a self extractor code)
If the zipfile cannot be opened, the return value is NULL.
Else, the return value is a zipFile Handle, usable with other function
of this zip package.
*/
extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
const char* filename,
const zip_fileinfo* zipfi,
const void* extrafield_local,
uInt size_extrafield_local,
const void* extrafield_global,
uInt size_extrafield_global,
const char* comment,
int method,
int level));
/*
Open a file in the ZIP for writing.
filename : the filename in zip (if NULL, '-' without quote will be used
*zipfi contain supplemental information
if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
contains the extrafield data the the local header
if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
contains the extrafield data the the local header
if comment != NULL, comment contain the comment string
method contain the compression method (0 for store, Z_DEFLATED for deflate)
level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
*/
extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
const voidp buf,
unsigned len));
/*
Write data in the zipfile
*/
extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
/*
Close the current file in the zipfile
*/
extern int ZEXPORT zipClose OF((zipFile file,
const char* global_comment));
/*
Close the zipfile
*/
#ifdef __cplusplus
}
#endif
#endif /* _zip_H */

View File

@@ -1,54 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipAbstractFile.h $
// $Archive: /ZipArchive/ZipAbstractFile.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_ZIPABSTRACTFILE_H__46F247DE_21A6_4D12_AF64_B5A6B3CF4D57__INCLUDED_)
#define AFX_ZIPABSTRACTFILE_H__46F247DE_21A6_4D12_AF64_B5A6B3CF4D57__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ZipExport.h"
#include "zipstring.h"
class ZIP_API CZipAbstractFile
{
public:
enum { begin = SEEK_SET, // 0
current = SEEK_CUR, // 1
end = SEEK_END // 2
};
CZipAbstractFile(){}
virtual bool Open(LPCTSTR , UINT , bool ){return true;}
virtual void Close() = 0;
virtual void Flush() = 0;
virtual ZIP_ULONGLONG GetPosition() const = 0;
virtual ZIP_ULONGLONG Seek(ZIP_LONGLONG lOff, int nFrom) = 0;
virtual ZIP_ULONGLONG GetLength() const = 0;
virtual void SetLength(ZIP_ULONGLONG nNewLen) = 0;
virtual ZIP_ULONGLONG SeekToBegin(){return Seek(0, begin);}
virtual ZIP_ULONGLONG SeekToEnd(){return Seek(0, end);}
virtual CZipString GetFilePath() const = 0;
virtual UINT Read(void *lpBuf, UINT nCount) = 0;
virtual void Write(const void* lpBuf, UINT nCount) = 0;
virtual bool IsClosed() const = 0;
virtual ~CZipAbstractFile(){};
};
#endif // !defined(AFX_ZIPABSTRACTFILE_H__46F247DE_21A6_4D12_AF64_B5A6B3CF4D57__INCLUDED_)

File diff suppressed because it is too large Load Diff

View File

@@ -1,79 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipAutoBuffer.h $
// $Archive: /ZipArchive/ZipAutoBuffer.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
/**
* \file ZipAutoBuffer.h
* Interface for the CZipAutoBuffer class.
*
*/
#if !defined(AFX_ZIPAUTOBUFFER_H__DEC28C20_83FE_11D3_B7C3_EDEC47A8A86C__INCLUDED_)
#define AFX_ZIPAUTOBUFFER_H__DEC28C20_83FE_11D3_B7C3_EDEC47A8A86C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ZipExport.h"
/**
A smart buffer freeing its contents on destruction.
*/
class ZIP_API CZipAutoBuffer
{
public:
operator char*()
{
return m_pBuffer;
}
#ifndef __BORLANDC__
operator const char*() const // Borland seems to have problems with this
{
return m_pBuffer;
}
#endif
// may produce ambiguity on some compilers
// operator const char*() const
// {
// return m_pBuffer;
// }
const char* GetBuffer() const {return m_pBuffer;}
char* Allocate(DWORD iSize, bool bZeroMemory = false);
void Release();
DWORD GetSize() const
{
return m_iSize;
}
bool IsAllocated() const
{
return (m_pBuffer != NULL);
}
CZipAutoBuffer(DWORD iSize, bool bZeroMemory = false);
CZipAutoBuffer();
CZipAutoBuffer(const CZipAutoBuffer& buffer);
virtual ~CZipAutoBuffer();
CZipAutoBuffer& operator=(const CZipAutoBuffer& buffer);
protected:
char* m_pBuffer;
DWORD m_iSize;
};
#endif // !defined(AFX_ZIPAUTOBUFFER_H__DEC28C20_83FE_11D3_B7C3_EDEC47A8A86C__INCLUDED_)

View File

@@ -1,22 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipBaseException.h $
// $Archive: /ZipArchive_STL/ZipBaseException.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#ifndef __ZIPBASEEXCEPTION_H__
#define __ZIPBASEEXCEPTION_H__
typedef std::exception CZipBaseException;
#endif //__ZIPBASEEXCEPTION_H__

View File

@@ -1,554 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipCentralDir.h $
// $Archive: /ZipArchive/ZipCentralDir.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
/**
* \file ZipCentralDir.h
* Interface for the CZipCentralDir class.
*
*/
#if !defined(AFX_CENTRALDIR_H__859029E8_8927_4717_9D4B_E26E5DA12BAE__INCLUDED_)
#define AFX_CENTRALDIR_H__859029E8_8927_4717_9D4B_E26E5DA12BAE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
#pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
#endif
#include "zipexception.h"
#include "zipfileheader.h"
#include "zipautobuffer.h"
#include "zipcollections.h"
#include "zipcompatibility.h"
#include "ZipExport.h"
#define ZIPARCHIVE_DATADESCRIPTOR_LEN 12
/**
A class representing the central directory record in the archive.
*/
class ZIP_API CZipCentralDir
{
public:
/**
Used in fast finding files by the filename.
A structure for the internal use only.
\see CZipCentralDir::m_findarray
\see CZipArchive::GetFindFastElement
\see CZipArchive::FindFile
\see CZipArchive::EnableFindFast
*/
struct ZIP_API CZipFindFast
{
CZipFindFast()
{
m_uIndex = 0;
m_pHeader= NULL;
}
CZipFindFast(CZipFileHeader* pHeader, WORD uIndex):m_pHeader(pHeader), m_uIndex(uIndex){}
/**
A pointer to the structure in CZipCentralDir. We extract a name from it.
*/
CZipFileHeader* m_pHeader;
/**
The index in the central directory of the \e m_pHeader.
*/
WORD m_uIndex;
};
/**
Stores general information about the central directory record.
*/
struct ZIP_API Info
{
DWORD m_uCentrDirPos; ///< the position of the beginning of the central directory (as located by #Locate)
DWORD m_uBytesBeforeZip;///< The number of bytes before the actual zip archive in a file. It is non-zero for self-extracting archives.
WORD m_uThisDisk; ///< number of the disk with the central directory end record (the number of disks in the disk-spanning archive)
WORD m_uDiskWithCD; ///< number of the disk with the start of the central directory
WORD m_uDiskEntriesNo; ///< total number of entries in the central dir on this disk
WORD m_uEntriesNumber; ///< total number of entries in the central dir
DWORD m_uSize; ///< size of the central directory (valid only if #m_bOnDisk is \c true; use #GetSize instead)
DWORD m_uOffset; ///< offset of start of central directory with respect to the starting disk number
///< (as written in the central directory record);
///< valid only if #m_bOnDisk is \c true
bool m_bOnDisk; ///< \c true if the central directory is physically present in the archive
#if !defined(__GNUC__)
protected:
friend CZipCentralDir;
#endif
bool CheckIfOK_1()
{
return ((DWORD)m_uCentrDirPos >= m_uOffset + m_uSize);
}
void SetBytesBeforeZip(bool bIsSpan)
{
m_uBytesBeforeZip = bIsSpan ? 0 : m_uCentrDirPos - m_uSize - m_uOffset;
}
bool CheckIfOK_2()
{
return (m_uSize || !m_uEntriesNumber) && (m_uEntriesNumber || !m_uSize);
}
void DiskChange(int iCurrentDisk)
{
m_uThisDisk = (WORD)iCurrentDisk;
if (m_uEntriesNumber)
{
m_uDiskEntriesNo = 0;
}
else
{
m_uDiskWithCD = m_uThisDisk;
m_uOffset = 0;
}
}
};
CZipCentralDir();
virtual ~CZipCentralDir();
static char m_gszSignature[]; ///< central dir signature
char m_szSignature[4]; ///< end of central dir signature (must be 0x06054b50)
CZipAutoBuffer m_pszComment; ///< the archive comment
CZipAutoBuffer m_pLocalExtraField; ///< a local extra field
CZipFileHeader* m_pOpenedFile; ///< points to a currently opened file or NULL if no file is opened
/**
Called by CZipArchive::OpenInternal.
*/
void Init();
/**
Read the central directory from the archive.
\note Throws exceptions.
*/
void Read();
/**
Open the file.
\param uIndex
zero-based index of the file to open
\note Throws exceptions.
*/
void OpenFile(WORD uIndex);
/**
Test if the given file header index is valid.
\param uIndex
a zero-based index
\return \c true if the file with the given index exists inside the archive; otherwise \c false;
*/
bool IsValidIndex(int uIndex)const;
/**
Remove the file header from the central directory.
\param pHeader
the header to remove
\param iIndex if index is not known set it to -1
\param bShift
\note Throws exceptions.
*/
void RemoveFile(CZipFileHeader* pHeader, int iIndex = -1, bool bShift = true);
/**
Remove last file from the central directory.
*/
void RemoveLastFile(CZipFileHeader* pHeader = NULL, int iIndex = -1)
{
if (iIndex == -1)
{
iIndex = m_headers.GetSize() - 1;
if (iIndex == -1)
return;
}
if (!pHeader)
pHeader = m_headers[iIndex];
DWORD uNewSize = pHeader->m_uOffset + GetBytesBefore();
// then remove
RemoveFile(pHeader, iIndex);
m_pStorage->Flush();
m_pStorage->m_pFile->SetLength(uNewSize);
m_info.m_bOnDisk = false; // it is true when AutoFlush is set to true
}
/**
Remove all files
\note Throws exceptions.
*/
void RemoveAll();
/**
Cleanup the structure.
\param bEverything
- \c true - clear some attributes and remove all the file headers from memory
- \c false - do not remove the file headers. It is called in that manner
from CZipArchive::CloseFileAfterTestFailed so that the
next file can be tested for the integrity
\see CZipArchive::CloseFileAfterTestFailed
*/
void Clear(bool bEverything = true);
/**
Add a new file to the central directory.
\param header
copy data from it to the new file header
\param iReplaceIndex if different from -1, the index of the file to be replaced
\return the pointer to the new header
\note Throws exceptions.
*/
CZipFileHeader* AddNewFile(const CZipFileHeader & header, int iReplaceIndex = -1);
/**
return the header filename, converted if needed
*/
CZipString GetProperHeaderFileName(const CZipFileHeader* pHeader) const
{
if (!m_bConvertAfterOpen)
{
CZipFileHeader fh = *pHeader;
ConvertFileName(true, false, &fh);
return fh.GetFileName();
}
else
return pHeader->GetFileName();
}
/**
Remove physically the central directory from the archive.
Called during adding or deleting files.
\note Throws exceptions.
*/
void RemoveFromDisk();
/**
Get the central directory size.
\param bWhole
if \c true, include the size of the file headers
\return the size of the central directory
\see CZipArchive::GetCentralDirSize
*/
DWORD GetSize(bool bWhole = false) const;
/**
Close a file inside archive opened for reading.
\param bAfterException \c true if closing after exception
\note Throws exceptions.
*/
void CloseFile(bool bAfterException = false);
/**
Close a file inside archive opened for reading.
\note Throws exceptions.
*/
void CloseNewFile();
/**
Write the central directory to the archive.
\note Throws exceptions.
*/
void Write(CZipActionCallback* pCallback);
/**
\see CZipArchive::EnableFindFast
*/
void EnableFindFast(bool bEnable, bool bCaseSensitive);
/**
\see CZipArchive::FindFile
\note \e bSporadically set to \c false rebuilds #m_findarray if necessary
*/
int FindFile(LPCTSTR lpszFileName, bool bCaseSensitive, bool bSporadically, bool bFileNameOnly);
/**
\see CZipArchive::GetFindFastIndex
*/
int GetFindFastIndex(int iFindFastIndex)const
{
if (!IsValidIndex(iFindFastIndex) || !m_bFindFastEnabled)
{
// ASSERT(FALSE); //
return -1;
}
return m_findarray[iFindFastIndex].m_uIndex;
}
/**
Points to CZipArchive::m_storage.
*/
CZipStorage* m_pStorage;
/**
The size of the buffer used in searching for the central dir.
Set before opening the archive.
It is usually set with CZipArchive::SetAdvanced
(specify this value as the third argument).
\see CZipArchive::SetAdvanced
*/
int m_iBufferSize;
/**
Holds all the files inside archive info.
\see CZipFileHeader
*/
CZipArray<CZipFileHeader*> m_headers;
CZipFileHeader* operator[](int iIndex)
{
return m_headers[iIndex];
}
const CZipFileHeader* operator[](int iIndex) const
{
return m_headers[iIndex];
}
/**
- If \c true, the conversion of the filenames takes
place after opening the archive (after reading the central directory
from the file), and before writing the central directory back to
the archive.
- If \c false, the conversion takes place on each call to CZipArchive::GetFileInfo
Change is value with CZipArchive::SetConvertAfterOpen.
Set it to \c true when you plan to use CZipArchive::FindFile or get the stored files information. <BR>
Set it to \c false when you plan mostly to modify the archive.
\b Default: \c true
\note Set it before opening the archive.
\see CZipArchive::SetConvertAfterOpen
\see ConvertFileName
*/
bool m_bConvertAfterOpen;
/**
Convert the filename of the CZipFileHeader depending on the current system
and the system the zip file was created on (change slash to backslash or
vice versa, perform ANSI-OEM conversion if necessary).
\param bFromZip
if \c true, convert from archive format
\param bAfterOpen
if \c true, called after opening the archive or before closing
\param pHeader
the header to have filename converted; if \c NULL convert the currently
opened file
\see ZipCompatibility::FileNameUpdate
\see m_bConvertAfterOpen
*/
void ConvertFileName(bool bFromZip, bool bAfterOpen, CZipFileHeader* pHeader = NULL) const
{
if (bAfterOpen != m_bConvertAfterOpen)
return;
if (!pHeader)
{
pHeader = m_pOpenedFile;
ASSERT(pHeader);
}
ZipCompatibility::FileNameUpdate(*pHeader, bFromZip);
}
/**
Convert all the filenames to the system form.
Called by CZipArchive::FindFile
\see CZipArchive::FindFile
*/
void ConvertAll();
/**
\param lpszFileName
the name of the file to find, must be exactly the same (apart from case)
as it appears in the archive
\return the index in #m_findarray with the appropriate CZipFindFast structure
or \c -1 if there is no file with the given name
\see CZipArchive::FindFile
*/
int FindFileNameIndex(LPCTSTR lpszFileName) const;
DWORD GetBytesBefore() const {return m_info.m_uBytesBeforeZip;}
/**
Get the information about the central directory
*/
void GetInfo(Info& info) const {info = m_info;}
/**
\return the value of m_bFindFastEnabled
*/
bool IsFindFastEnabled(){return m_bFindFastEnabled;}
/**
Called by CZipArchive::RenameFile
*/
void RenameFile(WORD uIndex, LPCTSTR lpszNewName);
protected:
/**
Sort the files inside the archive headers by the order in the archive.
*/
void SortHeaders();
static int CompareHeaders(const void *pArg1, const void *pArg2)
{
CZipFileHeader* pw1 = *(CZipFileHeader**)pArg1;
CZipFileHeader* pw2 = *(CZipFileHeader**)pArg2;
if ((pw1->m_uOffset < pw2->m_uOffset && pw1->m_uDiskStart == pw2->m_uDiskStart)
|| (pw1->m_uDiskStart < pw2->m_uDiskStart))
return -1;
else if ((pw1->m_uOffset > pw2->m_uOffset && pw1->m_uDiskStart == pw2->m_uDiskStart)
|| (pw1->m_uDiskStart > pw2->m_uDiskStart))
return 1;
else
{
ASSERT(FALSE);
// two files with the same offsets on the same disk???
CZipException::Throw(CZipException::badZipFile);
return 0; // just for the compiler comfort
}
}
/**
Build #m_findarray.
*/
void BuildFindFastArray( bool bCaseSensitive );
/**
Used in fast finding files by the filename.
\see CZipFindFast
\see m_bFindFastEnabled
\see CZipArchive::FindFile
*/
CZipArray<CZipFindFast> m_findarray;
/**
If \c true, the there is an additional array build, to speed up the
finding process
CZipArchive::FindFile uses this array to perform a
binary search.
\b Default: \c false
\see CZipArchive::EnableFindFast
\see CZipArchive::FindFile
\see CZipCentralDir::m_findarray
*/
bool m_bFindFastEnabled;
/**
The \e lpszFileName and \e bCaseSensitive arguments
are the same as in the #FindFileNameIndex. The function get CZipFindFast
structure pointed by \e uIndex and compares the filename of CZipFileHeader
class stored in this structure with \e lpszFileName.
\param lpszFileName
\param uIndex
the index from #m_findarray
\return
- 0 if the filenames are the same
- < 0 if the filename stored in the array is less than \e lpszFileName
- > 0 if the filename stored in the array is greater than \e lpszFileName
*/
int CompareElement(LPCTSTR lpszFileName, WORD uIndex) const
{
return (m_findarray[uIndex].m_pHeader->GetFileName().*m_pCompare)(lpszFileName);
}
/**
Insert a new CZipFindFast element to the #m_findarray.
Initialize CZipFindFast object with \e pHeader and \e uIndex values.
*/
void InsertFindFastElement(CZipFileHeader* pHeader, WORD uIndex);
/**
A compare function (Collate or CollateNoCase) set once so as not
to check every time which one to use<BR>
ZIPSTRINGCOMPARE is defined in CZipString.h as: <BR>
<B><CODE> typedef int (CZipString::*ZIPSTRINGCOMPARE)( LPCTSTR ) const; </CODE></B>
*/
ZIPSTRINGCOMPARE m_pCompare;
/**
The way the m_findarray is sorted
*/
bool m_bCaseSensitive;
/**
\see Info
*/
Info m_info;
/**
\return the location of the beginning of the central dir end record in the archive
\note Throws exceptions.
*/
DWORD Locate();
/**
Read the file headers from the file.
\note Throws exceptions.
*/
void ReadHeaders();
/**
Free the memory allocated for the CZipFileHeader structures.
*/
void RemoveHeaders();
/**
Remove data descriptors from the write buffer in the disk spanning volume
that turned out to be one-disk only.
We do not remove them from password encrypted files.
\param bFromBuffer
if \c true, remove from the buffer in memory otherwise from the file on a disk
\return \c false if the file mapping to memory was not successful
Can happen only when \e bFormBuffer is \c false.
\note Throws exceptions.
*/
bool RemoveDataDescr(bool bFromBuffer);
/**
Write the file headers to the archive.
\note Throws exceptions.
*/
void WriteHeaders(CZipActionCallback* pCallback, bool bOneDisk);
/**
Write the central directory end record.
\return the size of the record
\note Throws exceptions.
*/
DWORD WriteCentralEnd();
/**
Throw an exception with the given code.
\param err
\see CZipException::Throw
*/
void ThrowError(int err) const;
};
#endif // !defined(AFX_CENTRALDIR_H__859029E8_8927_4717_9D4B_E26E5DA12BAE__INCLUDED_)

View File

@@ -1,180 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipCollections.h $
// $Archive: /ZipArchive_STL/ZipCollections.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#ifndef ZIPCOLLECTIONS_DOT_H
#define ZIPCOLLECTIONS_DOT_H
#if _MSC_VER > 1000
#pragma warning( push, 3 ) // STL "requirements"
#pragma warning (disable : 4284) //return type for 'identifier::operator >' is not a UDT or reference to a UDT. Will produce errors if applied using infix notation
#pragma warning (disable : 4018) //'expression' : signed/unsigned mismatch
#endif
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include "zipstring.h"
#include "ZipExport.h"
template<class TYPE>
class CZipArray : private std::vector<TYPE>
{
public:
#if __GNUC__ >= 3
typedef typename std::vector<TYPE>::iterator iterator;
typedef typename std::vector<TYPE> inherited;
#else
typedef std::vector<TYPE>::iterator iterator;
typedef std::vector<TYPE> inherited;
protected:
#endif
iterator GetIterFromIndex(int uIndex)
{
iterator iter = begin();
iter += uIndex;
// int t = 0; while (t != uIndex) {iter++;t++;}
return iter;
}
public:
void Sort(bool bAscending)
{
if (bAscending)
std::sort (begin (), end (), std::less<TYPE> ());
else
std::sort (begin (), end (), std::greater<TYPE> ());
}
int GetSize() const{return (int)size(); }
int GetUpperBound() const {return size() - 1;}
int Add(const TYPE& x) {push_back(x);return GetUpperBound();}
void RemoveAll() {clear();}
void RemoveAt(int uIndex) { erase(GetIterFromIndex(uIndex));}
void InsertAt(int uIndex, const TYPE& x){insert(GetIterFromIndex(uIndex), x);}
#ifndef _MSC_VER
TYPE& operator[](int iIndex)
{
return inherited::operator[](iIndex);
}
TYPE operator[](int iIndex) const
{
return inherited::operator[](iIndex);
}
#else
using inherited::operator[];
#endif
};
typedef CZipArray<CZipString> CZipStringArray;
typedef CZipArray<WORD> CZipWordArray;
template<class TYPE>
class ZIP_API CZipPtrList : private std::list<TYPE>
{
public:
#if __GNUC__ >= 3
typedef typename std::list<TYPE>::iterator iterator;
typedef typename std::list<TYPE>::const_iterator const_iterator;
#else
typedef std::list<TYPE>::iterator iterator;
typedef std::list<TYPE>::const_iterator const_iterator;
#endif
int GetCount() const {return size();}
void AddTail(const TYPE& x){push_back(x);}
void AddHead(const TYPE& x){push_front(x);}
void RemoveHead() {pop_front();}
void RemoveTail() {pop_back();}
void RemoveAll() {clear();}
TYPE& GetHead() {return front();}
TYPE GetHead() const {return front();}
TYPE& GetTail() {return back();}
TYPE GetTail() const {return back();}
iterator GetHeadPosition() { return begin();}
const_iterator GetHeadPosition() const { return begin();}
iterator GetTailPosition() { return back();}
TYPE& GetNext(iterator& pos) { return *pos++;}
const TYPE GetNext(const_iterator& pos) const{ return *pos++;}
TYPE& GetPrev(iterator& pos) { return *pos--;}
TYPE GetPrev(iterator& pos) const{ return *pos--;}
iterator Find(TYPE& x) { return std::find(begin(), end(), x);}
void RemoveAt(iterator& pos) { erase(pos);}
bool IteratorValid(const_iterator &iter) const
{
return iter != end();
}
bool IteratorValid(iterator &iter)
{
return iter != end();
}
iterator FindIndex(int iIndex)
{
iterator iter = begin();
int t = 0; while (t != iIndex) {iter++;t++;}
return iter;
}
const_iterator FindIndex(int iIndex) const
{
const_iterator iter = begin();
int t = 0; while (t != iIndex) {iter++;t++;}
return iter;
}
TYPE& GetAt(const iterator& pos) { return *pos;}
TYPE GetAt(const_iterator& pos) const{ return *pos;}
};
// simplified and partial only
template<class KEY, class VALUE>
class ZIP_API CZipMap : private std::map<KEY, VALUE>
{
public:
void SetAt( KEY key, VALUE newValue)
{
insert(std::map<KEY, VALUE>::value_type(key, newValue));
}
BOOL RemoveKey( KEY key )
{
return erase(key) != 0;
}
BOOL Lookup( KEY key, VALUE& rValue ) const
{
#if __GNUC__ >= 3
typename std::map<KEY,VALUE>::const_iterator iter ;
#else
const_iterator iter ;
#endif
iter = find(key) ;
if (iter == end())
return FALSE;
else
{
rValue = iter->second;
return TRUE;
}
}
};
#if defined(_MSC_VER) && (_MSC_VER > 1100)
#pragma warning( pop)
#endif
#endif /* ZIPCOLLECTIONS_DOT_H */

View File

@@ -1,107 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipCompatibility.h $
// $Archive: /ZipArchive/ZipCompatibility.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
/**
* \file ZipCompatibility.h
* ZipCompatibility namespace declaration.
*
*/
#if !defined(AFX_ZIPCOMPATIBILITY_H__8E8B9904_84C7_4B22_B364_A10ED0E7DAD6__INCLUDED_)
#define AFX_ZIPCOMPATIBILITY_H__8E8B9904_84C7_4B22_B364_A10ED0E7DAD6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CZipAutoBuffer;
class CZipFileHeader;
/**
Functions that provides the proper conversion of attributes
and filename strings between different system platforms.
*/
namespace ZipCompatibility
{
/**
The codes of the compatibility of the file attribute information.
\see CZipArchive::GetSystemCompatibility
\see CZipFileHeader::GetSystemCompatibility
\see ZipPlatform::GetSystemID
*/
enum ZipPlatforms
{
zcDosFat, ///< MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems)
zcAmiga, ///< Amiga
zcVaxVms, ///< VAX/VMS
zcUnix, ///< Unix / Linux
zcVmCms, ///< VM/CMS
zcAtari, ///< Atari ST
zcOs2Hpfs, ///< OS/2 H.P.F.S.
zcMacintosh, ///< Macintosh
zcZsystem, ///< Z-System
zcCpm, ///< CP/M
zcNtfs ///< Windows NTFS
};
/**
Check whether the system with the given code is supported by the ZipArchive library.
\param iCode
\link #ZipPlatforms the system code \endlink
\return \c true if supported
*/
bool IsPlatformSupported(int iCode);
/**
Convert the system attributes between different system platforms.
It calls one of the converting functions.
\param uAttr
attributes to convert
\param iFromSystem
system code to convert from
\param iToSystem
system code to convert to
\return the converted attributes
\note Throws exceptions.
\see ZipPlatforms
*/
DWORD ConvertToSystem(DWORD uAttr, int iFromSystem, int iToSystem);
/**
Convert the filename of the file inside archive.
This conversion may not change the size of the filename, otherwise an
error may occur in #ReadLocal while comparing the filename sizes.
\param header
the file header to have the filename converted
\param bFromZip
if \c true convert the path from the from it is stored in the archive
to the current system compatible form; otherwise vice-versa.
\see CZipCentralDir::ConvertFileName
*/ void FileNameUpdate(CZipFileHeader& header, bool bFromZip);
/**
Change the slash to backslash or vice-versa in \e buffer.
\param buffer
\param bReplaceSlash
if \c true, change slash to backslash
*/
void SlashBackslashChg(CZipAutoBuffer& buffer, bool bReplaceSlash);
};
#endif // !defined(AFX_ZIPCOMPATIBILITY_H__8E8B9904_84C7_4B22_B364_A10ED0E7DAD6__INCLUDED_)

View File

@@ -1,228 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipException.h $
// $Archive: /ZipArchive/ZipException.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
/**
* \file ZipException.h
* Interface for the CZipException class.
*
*/
#if !defined(AFX_ZIPEXCEPTION_H__E3546921_D728_11D3_B7C7_E77339672847__INCLUDED_)
#define AFX_ZIPEXCEPTION_H__E3546921_D728_11D3_B7C7_E77339672847__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#pragma warning( push )
#pragma warning (disable:4702) // disable "Unreachable code" warning in Throw function in the Release mode
#endif // _MSC_VER > 1000
#include "zipstring.h"
#include "zipbaseexception.h"
#include "ZipExport.h"
#define ZIP_ENABLE_ERROR_DESCRIPTION
/**
A class representing exceptions specific to the ZipArchive library.
Library exception class derived in the MFC version from \c CException
and in non-MFC version from \c std::exception.
*/
class ZIP_API CZipException : public CZipBaseException
{
public:
/**
\param iCause
error cause (takes one of the #ZipErrors enumeration codes)
\param lpszZipName
the name of the file where the error occurred (if applicable)
*/
CZipException(int iCause = generic, LPCTSTR lpszZipName = NULL);
CZipException::CZipException(CZipException& e)
{
m_szFileName = e.m_szFileName;
m_iCause = e.m_iCause;
}
/**
Throw an exception.
Throw CZipException* in the MFC version of the library
(the object must be deleted with Delete() method)
and CZipException in other versions.
The arguments are the same as in CZipException().
\param iZipError
\param lpszZipName
\see CZipException()
*/
static void Throw(int iZipError = CZipException::generic, LPCTSTR lpszZipName = NULL)
{
#ifdef _MFC_VER
throw new CZipException(iZipError, lpszZipName);
#else
CZipException e(iZipError, lpszZipName);
throw e;
#endif
}
/**
Convert a zlib library error code to a \link #ZipErrors CZipException error code \endlink
\param iZlibError
zlib library error code
\return \link #ZipErrors CZipException error code \endlink
*/
static int ZlibErrToZip(int iZlibError);
#ifdef ZIP_ENABLE_ERROR_DESCRIPTION
/**
Return the error description.
\note You need to have defined ZIP_ENABLE_ERROR_DESCRIPTION
(in file ZipException.h); undefine this value if you don't want to
store the messages in the library.
*/
CZipString GetErrorDescription();
/**
Return the description of the error based on system variables
(this function is provided only for compatibility with MFC \c CException::GetErrorMessage)
\param lpszError
a pointer to a buffer that will receive the error message
if \c NULL
\param nMaxError
the maximum number of characters the buffer can hold, including the NULL terminator
\return
\c TRUE if the error string is not empty
\note
- The function will not copy more than \c nMaxError 1 characters
to the buffer, and it always adds a trailing null to end the string;
if the buffer is too small, the error message will be truncated.
- You need to have defined ZIP_ENABLE_ERROR_DESCRIPTION
(in file ZipException.h); undefine this value if you don't want to
store the messages in the library.
*/
BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError, UINT* = NULL);
#endif //ZIP_ENABLE_ERROR_DESCRIPTION
/**
The name of the zip file where the error occurred.
*/
CZipString m_szFileName;
/**
The codes of errors thrown by the ZipArchive library
*/
enum ZipErrors
{
noError, ///< no error
// 1 - 42 reserved for errno (from STL) values - used only in non-MFC versions
// 43 - 99 reserved
generic = 100, ///< unknown error
badZipFile, ///< damaged or not a zip file
badCrc, ///< crc mismatched
noCallback, ///< no disk-spanning callback functor set
aborted, ///< callback functor's method Callback returned \c false while disk change in the disk-spanning archive
abortedAction, ///< callback functor's method Callback returned \c false in CZipArchive class members: AddNewFile, ExtractFile, TestFile, DeleteFile or DeleteFiles
abortedSafely, ///< the same as above, you may be sure that the operation was successfully completed before or it didn't cause any damage in the archive (break when counting before deleting files; see CZipArchive::cbDeleteCnt)
nonRemovable, ///< the disk selected for pkzipSpan archive is non removable
tooManyVolumes, ///< limit of the maximum volumes reached (999)
tooLongFileName, ///< the filename of the file added to the archive is too long
badPassword, ///< incorrect password set for the file being decrypted
dirWithSize, ///< during testing: found the directory with the size greater than 0
internal, ///< internal error
notRemoved, ///< error while removing a file (under Windows call GetLastError() to find out more)
notRenamed, ///< error while renaming a file (under Windows call GetLastError() to find out more)
platfNotSupp, ///< the platform that the zip file is being created for is not supported
cdirNotFound, ///< the central directory was not found in the archive (it is thrown also when the last disk of multi-disk archive is not in the drive when opening the archive)
streamEnd = 500, ///< zlib library error
needDict, ///< zlib library error
errNo, ///< zlib library error
streamError, ///< zlib library error
dataError, ///< zlib library error
memError, ///< zlib library error thrown by CZipMemFile as well
bufError, ///< zlib library error
versionError, ///< zlib library error
};
/**
A cause of the error - takes one of the #ZipErrors enumeration codes.
*/
int m_iCause;
#if __GNUC__ >=3
virtual ~CZipException() throw();
#else
virtual ~CZipException();
#endif
protected:
#ifdef ZIP_ENABLE_ERROR_DESCRIPTION
/**
Return the error description
\param iCause : error number
\param bNoLoop: if \c true tells not to search for en error description,
it the error is generic
\return
*/
CZipString GetInternalErrorDescription(int iCause, bool bNoLoop = false);
/**
Return the description of the error based on system variables
\return
*/
CZipString GetSystemErrorDescription();
#endif //ZIP_ENABLE_ERROR_DESCRIPTION
#ifdef _MFC_VER
DECLARE_DYNAMIC(CZipException)
#pragma warning( pop )
#endif
};
#endif // !defined(AFX_ZIPEXCEPTION_H__E3546921_D728_11D3_B7C7_E77339672847__INCLUDED_)

View File

@@ -1,116 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipFile.h $
// $Archive: /ZipArchive_STL/ZipFile.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_ZIPFILE_H__80609DE0_2C6D_4C94_A90C_0BE34A50C769__INCLUDED_)
#define AFX_ZIPFILE_H__80609DE0_2C6D_4C94_A90C_0BE34A50C769__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "zipabstractfile.h"
#include "zipstring.h"
#include "ZipExport.h"
#ifndef __GNUC__
#include <io.h>
#else
#include <unistd.h>
#include <errno.h>
#endif
class ZIP_API CZipFile :public CZipAbstractFile
{
void ThrowError() const;
public:
int m_hFile;
operator HANDLE();
enum OpenModes
{
modeRead = 0x0001,
modeWrite = 0x0002,
modeReadWrite = modeRead | modeWrite,
shareDenyWrite = 0x0004,
shareDenyRead = 0x0008,
shareDenyNone = 0x0010,
modeCreate = 0x0020,
modeNoTruncate = 0x0040,
};
CZipFile(LPCTSTR lpszFileName, UINT openFlags)
{
m_hFile = -1;
Open(lpszFileName, openFlags, true);
}
void Flush();
ZIP_ULONGLONG GetLength() const;
CZipString GetFilePath() const {return m_szFileName;}
bool IsClosed()const { return m_hFile == -1;}
bool Open(LPCTSTR lpszFileName, UINT openFlags, bool bThrow);
void Close()
{
if (IsClosed())
return;
if (close(m_hFile) != 0)
ThrowError();
else
{
m_szFileName.empty();
m_hFile = -1;
}
}
void Write(const void* lpBuf, UINT nCount)
{
if (write(m_hFile, lpBuf, nCount) != (int) nCount)
ThrowError();
}
ZIP_ULONGLONG GetPosition() const
{
#ifndef __GNUC__
long ret = tell(m_hFile);
#else
long ret = lseek(m_hFile, 0, SEEK_CUR);
#endif
if (ret == -1L)
ThrowError();
return ret;
}
void SetLength(ZIP_ULONGLONG nNewLen);
UINT Read(void *lpBuf, UINT nCount)
{
errno = 0;
int ret = read(m_hFile, lpBuf, nCount);
if (ret < (int) nCount && errno != 0)
ThrowError();
return ret;
}
ZIP_ULONGLONG Seek(ZIP_LONGLONG dOff, int nFrom)
{
long ret = lseek(m_hFile, (long)dOff, nFrom);
if (ret == -1)
ThrowError();
return ret;
}
CZipFile ();
virtual ~CZipFile (){Close();};
protected:
CZipString m_szFileName;
};
#endif // !defined(AFX_ZIPFILE_H__80609DE0_2C6D_4C94_A90C_0BE34A50C769__INCLUDED_)

View File

@@ -1,352 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipFileHeader.h $
// $Archive: /ZipArchive/ZipFileHeader.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
/**
* \file ZipFileHeader.h
* Interface for the CZipFileHeader class.
*
*/
#if !defined(AFX_FILEHEADER_H__0081FC65_C9C9_4D48_AF72_DBF37DF5E0CF__INCLUDED_)
#define AFX_FILEHEADER_H__0081FC65_C9C9_4D48_AF72_DBF37DF5E0CF__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ZipExport.h"
#include "zipstorage.h"
#include "zipautobuffer.h"
#include "sys/types.h"
#include "zipcompatibility.h"
#define ZIPARCHIVE_ENCR_HEADER_LEN 12
/**
Representation of a single file stored in the zip archive.
Modify all the class attributes BEFORE adding a file to and archive
( using CZipArchive::OpenNewFile ).
It is not possible to modify the data of the existing files in the archive
(it would mean updating all the information in the local headers
and the offsets would be changed as well when the filename would changed its size)
*/
class ZIP_API CZipFileHeader
{
friend class CZipCentralDir;
friend class CZipArchive;
friend void ZipCompatibility::FileNameUpdate(CZipFileHeader&, bool);
public:
CZipFileHeader();
virtual ~CZipFileHeader();
//
/**
Change slash to backslash or vice-versa in #m_pszFileName.
\param bWindowsStyle
if \c true, change slash to backslash; otherwise vice versa;
*/
/**
\return the filename size in characters (without NULL)
*/
WORD GetFileNameSize()const {return (WORD)m_pszFileName.GetSize();}
/**
\return the comment size in characters (without NULL)
*/
WORD GetCommentSize() const {return (WORD)m_pszComment.GetSize();}
/**
\return the extra field size in characters
*/
WORD GetExtraFieldSize()const{return (WORD)m_pExtraField.GetSize();}
/**
\return the filename
*/
CZipString GetFileName()const;
/**
Set the filename
\param lpszFileName
\return
\c true, if conversion from UNICODE to single byte was successful
(or if there was no conversion needed or possible); otherwise \c false;
*/
bool SetFileName(LPCTSTR lpszFileName);
/**
\return the file comment
*/
CZipString GetComment() const;
/**
Set the file comment.
\param lpszComment
\return
\c true, if conversion from UNICODE to single byte was successful
(or if there was no conversion needed or possible); otherwise \c false;
*/
bool SetComment(LPCTSTR lpszComment);
/**
\return \c true if the data descriptor is present
*/
bool IsDataDescr()const { return ((m_uFlag & 8) != 0); }
/**
\return
get the effective compressed size: if the file is encrypted, return less by the size of the encryption header
*/
DWORD GetEffComprSize()
{
return m_uComprSize - (IsEncrypted() ? ZIPARCHIVE_ENCR_HEADER_LEN : 0);
}
/**
\return
\c false if the file should be stored instead of being compressed
*/
bool CompressionEfficient()
{
DWORD uBefore = m_uUncomprSize;
// ignore the length of encryption header
DWORD uAfter = GetEffComprSize();
return uAfter <= uBefore;
}
/**
\return the compression ratio of the file
*/
float GetCompressionRatio()
{
return m_uUncomprSize ? ((float)m_uComprSize) * 100 / m_uUncomprSize : 0;
}
/**
\return \c if the file is encrypted ( a password is needed to extract this file)
\see CZipArchive::SetPassword
*/
bool IsEncrypted()const { return ((m_uFlag & 1) != 0); }
char m_szSignature[4]; ///< central file header signature
WORD m_uVersionMadeBy; ///< version made by and system compatibility
WORD m_uVersionNeeded; ///< version needed to extract
WORD m_uFlag; ///< general purpose bit flag
WORD m_uMethod; ///< compression method
WORD m_uModTime; ///< last mod file time
WORD m_uModDate; ///< last mod file date
DWORD m_uCrc32; ///< crc-32
DWORD m_uComprSize; ///< compressed size
DWORD m_uUncomprSize; ///< uncompressed size
// filename length 2 bytes
// WORD m_uFileNameSize;
// extra field length 2 bytes
// WORD m_uExtraFieldSize;
// file comment length 2 bytes
// WORD m_uCommentSize;
WORD m_uDiskStart; ///< disk number start
WORD m_uInternalAttr; ///< internal file attributes
protected:
DWORD m_uExternalAttr; ///< external file attributes
public:
DWORD m_uOffset; ///< relative offset of local header
CZipAutoBuffer m_pExtraField; ///< extra field (variable size)
static char m_gszSignature[]; ///< central file header signature
static char m_gszLocalSignature[]; ///< local file header signature
/**
Set #m_uModDate, #m_uModTime
(file modification time)
\param ttime
\see GetTime
*/
void SetTime(const time_t& ttime);
/**
\return the modification time
\see SetTime
*/
time_t GetTime()const;
/**
\param bLocal
if \c true return the local file header size or in the central directory otherwise
\return the total size of the structure depending on the \e bLocal parameter
*/
DWORD GetSize(bool bLocal = false)const;
/**
\return the system compatibility of the current file as
the one of ZipCompatibility::ZipPlatforms values;
usually the same as CZipArchive::GetSystemComatibility.
Software can use this information e.g. to determine the line
record format for text files etc.
ZipArchive library uses it to perform a proper attributes conversion.
\see CZipArchive::GetSystemComatibility
\see ZipPlatform::GetSystemID
*/
int GetSystemCompatibility()const
{
return (m_uVersionMadeBy & 0xFF00) >> 8;
}
/**
\return the attributes of the file converted to the current system compatible value
\note
- Throws exception if the archive system or the current system
is not supported by the ZipArchive library.
- (only Linux version): After obtaining the attributes, you need to shift them right by 16
*/
DWORD GetSystemAttr()const;
/**
\return
the original attributes as stored in the archive (without performing any conversion)
*/
DWORD GetOriginalAttributes() const {return m_uExternalAttr;}
/**
\return \c true, if this object represents a directory; otherwise \c false;
If #m_uExternalAttr value is zero, the function check for a presence of a path
separator at the end of the file name. If it is present, it is assumed to be a directory.
*/
bool IsDirectory()const;
protected:
/**
Set the system compatibility of the file.
\param iSystemID
one of ZipCompatibility::ZipPlatforms values
\see CZipArchive::GetSystemCompatibility
*/
void SetSystemCompatibility(int iSystemID)
{
m_uVersionMadeBy &= 0x00FF;
m_uVersionMadeBy |= (WORD)(iSystemID << 8);
}
/**
Set the system attributes
if you wish to set the attributes of this structure use CZipArchive::SetFileHeaderAttr()
\param uAttr
attributes to set
\note Throws exceptions if the archive system or the current system
is not supported by the ZipArchive library.
\see CZipArchive::SetFileHeaderAttr
\see GetSystemAttr
\see SetSystemCompatibility
*/
void SetSystemAttr(DWORD uAttr);
/**
Set the version made by number.
*/
void SetVersion(WORD uVersion)
{
if ((m_uVersionMadeBy & 0x00FF) != (uVersion & 0x00FF))
{
m_uVersionMadeBy &= 0xFF00;
m_uVersionMadeBy |= (WORD)(uVersion & 0x00FF);
}
}
/**
a filename
*/
CZipAutoBuffer m_pszFileName;
/**
a file comment
*/
CZipAutoBuffer m_pszComment;
/**
Fill the buffer with the current values of crc and compressed and
uncompressed sizes of the file.
*/
void GetCrcAndSizes(char* pBuffer)const;
/**
Check whether the actual values of crc and compressed and
uncompressed sizes of the file are the same as defined in
the file header.
\param pBuf
buffer with the mentioned data
\return \c true if they are the same; otherwise \c false;
*/
bool CheckCrcAndSizes(char* pBuf) const;
/**
Prepare the data for the class while adding a new file.
Called by CZipArchive::OpenNewFile
\param iLevel
a compression level
\param bSpan
\c true, if the data descriptor will be present because of spanning archive
\param bEncrypted
\c true, if the file will be encrypted
\return \c true if the sizes of the filename, extra field and comments
does not exceed \c unsigned \c short maximum value; otherwise \c false;
*/
bool PrepareData(int iLevel, bool bSpan, bool bEncrypted);
/**
Write the local file header to the \e storage
\param storage
\note Throws exceptions.
*/
void WriteLocal(CZipStorage& storage);
/**
Read the file header from the central directory record from \e pStorage.
\param *pStorage
\return \c true if the whole file header is on one disk in
a multi-disk archive; otherwise \c false;
\note Throws exceptions.
*/
bool Read(CZipStorage *pStorage);
/**
Read the local file header from \e pStorage and check for consistency.
\param *pStorage
\param iLocExtrFieldSize
receives local extra field size
\return \c false, if something goes wrong; otherwise \c true;
\note Throws exceptions.
*/
bool ReadLocal(CZipStorage *pStorage, WORD& iLocExtrFieldSize);
/**
Write the file header to \e pStorage.
\param *pStorage
\return the size of the file header
\note Throws exceptions.
*/
DWORD Write(CZipStorage *pStorage);
};
#endif // !defined(AFX_FILEHEADER_H__0081FC65_C9C9_4D48_AF72_DBF37DF5E0CF__INCLUDED_)

View File

@@ -1,80 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipFileMapping.h $
// $Archive: /ZipArchive/ZipFileMapping.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
//
// Check the site http://www.artpol-software.com for the updated version of the library.
////////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_AUTOHANDLE_H__D68326EA_D7FA_4792_AB1F_68D09533E399__INCLUDED_)
#define AFX_AUTOHANDLE_H__D68326EA_D7FA_4792_AB1F_68D09533E399__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "ZipFile.h"
namespace ziparchv
{
struct CZipFileMapping
{
CZipFileMapping()
{
m_hFileMap = NULL;
m_pFileMap = NULL;
}
bool CreateMapping(CZipFile* pFile)
{
if (!pFile)
return false;
m_hFileMap = CreateFileMapping((*pFile), NULL, PAGE_READWRITE,
0, 0, _T("ZipArchive Mapping File"));
if (!m_hFileMap)
return false;
// Get pointer to memory representing file
m_pFileMap = MapViewOfFile(m_hFileMap, FILE_MAP_WRITE, 0, 0, 0);
return (m_pFileMap != NULL);
}
void RemoveMapping()
{
if (m_pFileMap)
{
UnmapViewOfFile(m_pFileMap);
m_pFileMap = NULL;
}
if (m_hFileMap)
{
CloseHandle(m_hFileMap);
m_hFileMap = NULL;
}
}
~CZipFileMapping()
{
RemoveMapping();
}
char* GetMappedMemory()
{
return reinterpret_cast<char*> (m_pFileMap);
}
protected:
HANDLE m_hFileMap;
LPVOID m_pFileMap;
};
}
#endif // !defined(AFX_AUTOHANDLE_H__D68326EA_D7FA_4792_AB1F_68D09533E399__INCLUDED_)

View File

@@ -1,64 +0,0 @@
/**
* \file ZipInternalInfo.h
* Interface for the CZipInternalInfo structure.
*
* \author Tadeusz Dracz
*/
// Part of the ZipArchive library
//
// Copyright (C) 2000 - 2001 Tadeusz Dracz.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_ZIPINTERNALINFO_H__C6749101_590C_4F74_8121_B82E3BE9FA44__INCLUDED_)
#define AFX_ZIPINTERNALINFO_H__C6749101_590C_4F74_8121_B82E3BE9FA44__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "zipautobuffer.h"
#include "zconf.h"
#ifndef _HBCOMPRESS_H
#include "hbcomprs.h"
#endif
/**
The purpose of this structure is to hold the data that allow communication
with the zlib library
*/
ZEXPORT struct CZipInternalInfo
{
CZipInternalInfo();
virtual ~CZipInternalInfo();
/**
Allocate internal buffer of m_iBufferSize size
*/
void Init();
z_stream m_stream; ///< zlib library data stream
DWORD m_uUncomprLeft; ///< bytes left to uncompress
DWORD m_uComprLeft; ///< bytes left to decompress
DWORD m_uCrc32; ///< crc32 file control value
/**
The size of the buffer used in decompressing data.
Set before opening the archive.
It is usually set with CZipArchive::SetAdvanced
(specify this value as the second argument).
\see CZipArchive::SetAdvanced
*/
DWORD m_iBufferSize;
/**
This buffer caches data during compression and decompression.
*/
CZipAutoBuffer m_pBuffer;
};
#endif // !defined(AFX_ZIPINTERNALINFO_H__C6749101_590C_4F74_8121_B82E3BE9FA44__INCLUDED_)

View File

@@ -1,108 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipMemFile.h $
// $Archive: /ZipArchive/ZipMemFile.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
/**
* \file ZipMemFile.h
* Interface for the CZipMemFile class.
*
*/
#if !defined(AFX_ZIPMEMFILE_H__EA73AB25_6B51_4C5E_8D78_BAC95812598F__INCLUDED_)
#define AFX_ZIPMEMFILE_H__EA73AB25_6B51_4C5E_8D78_BAC95812598F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "hbapi.h"
#include "zipabstractfile.h"
#include "zipstring.h"
#include "ZipExport.h"
/**
A memory buffer which behaves like a physical file.
Automatically grows when necessary
*/
class ZIP_API CZipMemFile : public CZipAbstractFile
{
protected:
size_t m_nGrowBy, m_nPos;
size_t m_nBufSize, m_nDataSize;
BYTE* m_lpBuf;
bool m_bAutoDelete;
void Free()
{
if (m_lpBuf)
{
free(m_lpBuf);
m_lpBuf = NULL;
}
}
void Init()
{
m_nGrowBy = m_nPos = 0;
m_nBufSize = m_nDataSize = 0;
m_lpBuf = NULL;
}
void Grow(size_t nBytes);
public:
bool IsClosed() const { return m_lpBuf == NULL;}
void Flush(){}
ZIP_ULONGLONG Seek(ZIP_LONGLONG lOff, int nFrom);
ZIP_ULONGLONG GetLength() const {return m_nDataSize;}
void Write(const void* lpBuf, UINT nCount);
UINT Read(void* lpBuf, UINT nCount);
void SetLength(ZIP_ULONGLONG nNewLen);
CZipString GetFilePath() const {return _T("");}
CZipMemFile(long nGrowBy = 1024)
{
Init();
m_nGrowBy = nGrowBy;
m_bAutoDelete = true;
}
CZipMemFile(BYTE* lpBuf, UINT nBufSize, long nGrowBy = 0)
{
Init();
Attach(lpBuf, nBufSize, nGrowBy);
}
ZIP_ULONGLONG GetPosition() const { return m_nPos;}
void Attach(BYTE* lpBuf, UINT nBufSize, long nGrowBy = 0)
{
Close();
m_lpBuf = lpBuf;
m_nGrowBy = nGrowBy;
m_nBufSize = nBufSize;
m_nDataSize = nGrowBy == 0 ? nBufSize : 0;
m_bAutoDelete = false;
}
BYTE* Detach()
{
BYTE* b = m_lpBuf;
Init();
return b;
}
void Close()
{
if (m_bAutoDelete)
Free();
Init();
}
virtual ~CZipMemFile(){Close();}
};
#endif // !defined(AFX_ZIPMEMFILE_H__EA73AB25_6B51_4C5E_8D78_BAC95812598F__INCLUDED_)

View File

@@ -1,206 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipPathComponent.h $
// $Archive: /ZipArchive/ZipPathComponent.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
/**
* \file ZipPathComponent.h
* Interface for the CZipPathComponent class.
*
*/
#if !defined(AFX_ZIPPATHCOMPONENT_H__9B222C08_AD11_4138_96CC_1237511E3E37__INCLUDED_)
#define AFX_ZIPPATHCOMPONENT_H__9B222C08_AD11_4138_96CC_1237511E3E37__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "zipstring.h"
#include "ZipExport.h"
/**
A class splitting a file path into components.
*/
class ZIP_API CZipPathComponent
{
public:
CZipPathComponent(){}
virtual ~CZipPathComponent();
static const TCHAR m_cSeparator; ///< A system - specific default path separator. Defined in ZipPlatform.cpp.
/**
Append a path separator to \e szPath if it is not already there.
*/
static void AppendSeparator(CZipString& szPath)
{
RemoveSeparators(szPath);
szPath += m_cSeparator;
}
/**
Remove separators from the end of \e szPath
*/
static void RemoveSeparators(CZipString& szPath)
{
// szPath.TrimRight(m_cSeparator);
szPath.TrimRight(_T("\\/"));
}
/**
Remove separators from the beginning of \e szPath
*/
static void RemoveSeparatorsLeft(CZipString& szPath)
{
szPath.TrimLeft(_T("\\/"));
}
/**
\return \c true if \e c is a slash or a backslash
*/
static bool IsSeparator(TCHAR c)
{
return c == _T('\\') || c == _T('/');
}
/**
\return \c true if the path has a path separator at the and
*/
static bool HasEndingSeparator(const CZipString& szPath)
{
int iLen = szPath.GetLength();
if (iLen)
return IsSeparator(szPath[iLen - 1]);
else
return false;
}
/**
Construct the object and set a path.
\param lpszFullPath
the full path of the file
\see SetFullPath
*/
CZipPathComponent(LPCTSTR lpszFullPath)
{
SetFullPath(lpszFullPath);
}
// full path of the file (not a directory alone)
/**
Set the path.
\param lpszFullPath
a full path to the file (including a filename - the last element in the
path is assumed to be a filename)
*/
void SetFullPath(LPCTSTR lpszFullPath);
/**
\return the filename (without an extension)
*/
CZipString GetFileTitle() const { return m_szFileTitle;}
/**
Set the file title (without an extension).
\param lpszFileTitle
\return
*/
void SetFileTitle(LPCTSTR lpszFileTitle) { m_szFileTitle = lpszFileTitle;}
/**
Set the extension alone.
\param lpszExt
may but not have to contain a dot at the beginning
*/
void SetExtension(LPCTSTR lpszExt)
{
m_szFileExt = lpszExt;
m_szFileExt.TrimLeft(_T('.'));
}
/**
\return the file extension without a dot
*/
CZipString GetFileExt() const { return m_szFileExt;}
/**
\return the drive (no path separator at the end)
*/
CZipString GetFileDrive() const { return m_szDrive;}
/**
\return the full path without the drive (no separator at the beginning)
*/
CZipString GetNoDrive() const ;
/**
\return the filename including an extension
*/
CZipString GetFileName() const
{
CZipString szFullFileName = m_szFileTitle;
if (!m_szFileExt.IsEmpty())
{
szFullFileName += _T(".");
szFullFileName += m_szFileExt;
}
return szFullFileName;
}
/**
\return the full path of the file (including the filename)
*/
CZipString GetFullPath() const
{
CZipString szFullPath = GetFilePath();
CZipString szFileName = GetFileName();
if (!szFileName.IsEmpty())
{
szFullPath += m_cSeparator;
szFullPath += szFileName;
}
return szFullPath;
}
/**
\return the path of the file (without the separator at the end)
*/
CZipString GetFilePath() const
{
CZipString szDrive = m_szDrive;
CZipString szDir = m_szDirectory;
if (!szDrive.IsEmpty() && !szDir.IsEmpty())
szDrive += m_cSeparator;
return m_szPrefix + szDrive + szDir;
}
protected:
/**
\name Path components
*/
//@{
CZipString m_szDirectory, ///< a directory(ies) (one or more) without the path separators at the end and the beginning
m_szFileTitle, ///< a filename without an extension
m_szFileExt, ///< a file extension without a dot
m_szDrive, ///< a drive (if the system path standard uses it) without a path separator at the end
m_szPrefix; ///< a prefix (e.g. for the UNC path or Unicode path under Windows)
//@}
};
#endif // !defined(AFX_ZIPPATHCOMPONENT_H__9B222C08_AD11_4138_96CC_1237511E3E37__INCLUDED_)

View File

@@ -1,175 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipPlatform.h $
// $Archive: /ZipArchive/ZipPlatform.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
/**
* \file ZipPlatform.h
* ZipPlatform namespace declaration.
*
*/
#if !defined(AFX_ZipPlatform_H__E2FE6343_9D03_4F3C_A1F7_706C9F0ED978__INCLUDED_)
#define AFX_ZipPlatform_H__E2FE6343_9D03_4F3C_A1F7_706C9F0ED978__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CZipFileHeader;
class CZipAutoBuffer;
#include "zipstring.h"
#include "zippathcomponent.h"
#include <sys/types.h>
#include "ZipExport.h"
/**
Interface to the system API.
All functions have a system - specific implementation .
*/
namespace ZipPlatform
{
/**
return the default system case-sensitivity
*/
ZIP_API bool GetSystemCaseSensitivity();
/**
\return A current system name tag.
May be one of ZipCompatibility::ZipPlatforms values.
\see CZipArchive::GetSystemCompatibility
*/
ZIP_API int GetSystemID();
/**
\return the default file attributes for the current system
*/
ZIP_API DWORD GetDefaultAttributes();
/**
\return the default directory attributes for the current system
*/
ZIP_API DWORD GetDefaultDirAttributes();
/**
Get the free space on the device pointed by \e lpszPath
*/
ZIP_API DWORD GetDeviceFreeSpace(LPCTSTR lpszPath);
/**
Return the temporary file name ensuring there is enough size in the destination directory,.
Checking for the size is disabled by default.
*/
ZIP_API CZipString GetTmpFileName(LPCTSTR lpszPath = NULL, DWORD iSizeNeeded = DWORD(-1));
/**
\name Various operations on files and directories.
All the functions which are returning a \c bool value,
return \c true when the operation was successful.
*/
//@{
ZIP_API bool GetCurrentDirectory(CZipString& sz); ///< Get the current directory and store it in \e sz
ZIP_API bool ChangeDirectory(LPCTSTR lpDirectory);
ZIP_API bool SetFileAttr(LPCTSTR lpFileName, DWORD uAttr);
ZIP_API bool GetFileAttr(LPCTSTR lpFileName, DWORD& uAttr);
ZIP_API bool GetFileModTime(LPCTSTR lpFileName, time_t & ttime); ///< get the file modification time
ZIP_API bool GetFileSize(LPCTSTR lpszFileName, DWORD& dSize);
ZIP_API bool SetFileModTime(LPCTSTR lpFileName, time_t ttime); ///< set the file modification time
ZIP_API bool CreateDirectory(LPCTSTR lpDirectory);
ZIP_API bool SetVolLabel(LPCTSTR lpszPath, LPCTSTR lpszLabel); ///< \c lpszPath may point to a file on the device
ZIP_API bool ForceDirectory(LPCTSTR lpDirectory); ///< create nested directories at once
ZIP_API bool RemoveFile(LPCTSTR lpszFileName, bool bThrow = true);
ZIP_API bool RenameFile( LPCTSTR lpszOldName, LPCTSTR lpszNewName, bool bThrow = true);
#ifndef _MFC_VER
ZIP_API bool TruncateFile(int iDes, DWORD iSize);
ZIP_API int OpenFile(LPCTSTR lpszFileName, UINT iMode, int iShareMode);
ZIP_API bool FlushFile(int iDes); ///< flush the file to the disk.
ZIP_API int GetFileSystemHandle(int iDes); ///< return the underlying system handle
#endif
//@}
/**
\param lpszDir
\return \c true, if \e lpszDir directory exists; otherwise \c false;
*/
ZIP_API bool DirectoryExists(LPCTSTR lpszDir);
/**
\param lpszFilePath
may point to a file path or a directory on the device
\return \c true if the drive is removable.
Implemented only on Windows system, in all others always returns \c true.
*/
ZIP_API bool IsDriveRemovable(LPCTSTR lpszFilePath);
/**
\param uAttr
attributes value to test
\return \c true if the attributes are the directory attributes
*/
ZIP_API bool IsDirectory(DWORD uAttr);
/**
Perform the translation between ANSI and OEM character sets.
\remark
- The conversion is performed only for the zip archives created under Windows platform.
- Windows archiving programs convert a filename to OEM before adding it to the archive.
- OEM conversion only influences the ANSI values above 126, so it
affects only strings containing international characters.
\param buffer
buffer to be translated
\param bAnsiToOem
if \c true, convert ANSI to OEM
if \c false, OEM to ANSI
*/
ZIP_API void AnsiOem(CZipAutoBuffer& buffer, bool bAnsiToOem);
/**
Check if the given file or directory exists.
\param lpszName
\return
- -1 if the given file is a directory
- 1 a file
- 0 if there is no such a file
*/
ZIP_API int FileExists(LPCTSTR lpszName);
#ifdef _UNICODE
/**
Convert wide character string to single character string.
\param lpWide
Wide string to convert
\param szSingle
buffer to receive converted string (without the terminating NULL character)
\return
the \e szSingle buffer length, or \c -1 when not succeeded
\note Only in UNICODE version.
*/
ZIP_API int WideToSingle(LPCTSTR lpWide, CZipAutoBuffer &szSingle);
/**
Convert single character string to wide character string.
\param szSingle
single string to convert (no terminating NULL character at the end)
\param szWide
receives the wide string after the conversion
\return \e the length of the string after the conversion (without the NULL character),
or \c -1 when not succeeded
\note Only in UNICODE version.
*/
ZIP_API int SingleToWide(const CZipAutoBuffer &szSingle, CZipString& szWide);
#endif
};
#endif // !defined(AFX_ZipPlatform_H__E2FE6343_9D03_4F3C_A1F7_706C9F0ED978__INCLUDED_)

View File

@@ -1,588 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipStorage.h $
// $Archive: /ZipArchive/ZipStorage.h $
// $Date$ $Author$.
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
/**
* \file ZipStorage.h
* Interface for the CZipStorage class.
*
*/
#if !defined(AFX_ZIPSTORAGE_H__941824FE_3320_4794_BDE3_BE334ED8984B__INCLUDED_)
#define AFX_ZIPSTORAGE_H__941824FE_3320_4794_BDE3_BE334ED8984B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "zipfile.h"
#include "zipautobuffer.h"
#include "zipstring.h"
#include "zipmemfile.h"
#include "ZipExport.h"
/**
A base class for functional objects (functors) that are used as a callbacks during various actions.
You need to derive your own class and overload \c Callback method to use it.
Do not derive from CZipCallback directly but from CZipSpanCallback (as a callback when there is a need
for a disk change in a disk-spanning archive) or from CZipActionCallback for other actions.
*/
struct ZIP_API CZipCallback
{
/**
Method called as a callback.
Return \c false from inside the method to abort the current operation. If it is a span callback functor,
a CZipException with CZipException::aborted code will be thrown, otherwise the code will be CZipException::abortedAction or CZipException::abortedSafely.
The following actions can be safely aborted (without having the archive corrupted):
- counting bytes before deleting files
- testing
- saving central directory on non-disk-spanning archive
(saved data is removed in case of break and you can save it again);
it the archive is disk-spanning and if saving is aborted, the archive
will not be damaged, but saved part of the central directory will be not removed
and the new central directory will have to be saved after it
\note Overrride this method in the derived class. If you define this method inside the class declaration, it should be inlined
by the compiler making the action progress faster.
*/
virtual bool Callback(int iProgress) = 0;
CZipString m_szExternalFile; ///< if the action (adding, extracting or disk-spanning) uses an external file, its filename is stored here
};
/**
Derive from this a class to be used as a callback functor for the disk change callback.
You need to override member function CZipCallback::Callback. The meaning of \e iProgress parameter is the reason for calling:
- -1 : a disk needed for reading <BR>
other codes occurs during writing:
- >=0 : min. number of bytes needed
- -2 : the file with the archive name already exists on the disk
- -3 : the disk is probably write - protected
- -4 : couldn't create a file
Return \c false from the callback function to abort operation: the proper exception will be thrown.
\see CZipCallback::Callback
\see CZipArchive::SetSpanCallback
*/
struct ZIP_API CZipSpanCallback : public CZipCallback
{
DWORD m_uDiskNeeded; ///< the number of a disk needed (counting from 1)
};
/**
Derive from this a class to be used as a callback functors when adding, extracting, deleting, testing a file
or saving central directory.
You need to override member function CZipCallback::Callback. The meaning of \e iProgress parameter is the count
of data just processed. It is a smallest number of bytes after which the callback method is called and it depends
on the value of \e nBufSize in the CZipArchive methods that uses the callback feature. In case of saving the central
directory action it is the count of file headers just written (see CZipArchive::cbSave)
\see CZipCallback::Callback
\see CZipArchive::SetCallback
*/
struct ZIP_API CZipActionCallback : public CZipCallback
{
CZipActionCallback()
{
m_uTotalToDo = 0;
m_uTotalSoFar = 0;
}
/**
The type of the callback. It is set to one of CZipArchive::CallbackType values when the action begins.
It's useful if you have more than one callback assigned to the same functor.
*/
int m_iType;
/**
Used by the ZipArchive library to init the callback function with the filenames. Resets #m_uTotalToDo and #m_uTotalSoFar variables to 0.
#m_iType variable is already set to the proper value. Called at the beginning of the action.
*/
virtual void Init(LPCTSTR lpszFileInZip = NULL, LPCTSTR lpszExternalFile = NULL)
{
m_szFileInZip = lpszFileInZip;
m_szExternalFile = lpszExternalFile;
m_uTotalToDo = 0; // not yet known
m_uTotalSoFar = 0; // nothing yet done
}
/**
Called by the ZipArchive functions that use the callback feature after calculating total data to process.
\param uTotalToDo
total data to process; set #m_uTotalToDo to this value
*/
virtual void SetTotal(DWORD uTotalToDo)
{
m_uTotalToDo = uTotalToDo;
// m_uTotalSoFar = 0; // already done in CZipArchive::CZipClbckStrg::Get
}
/**
Total number of data to process. The value of this variable is set after calling by the library #SetTotal method (it is 0 before).
Depending on the action it is set then to:
- adding file: the size the external file being added (or if callback is CZipArchive::cbAddTmp, the size of compressed data: CZipFileHeader::m_uComprSize)
- extracting file: the size of uncompressed data (CZipFileHeader::m_uUncomprSize)
- testing file: the same as above
- deleting file: the count of bytes to move - the size of all files to remain above the first file to delete (calculated from offsets CZipFileHeader::m_uOffset
- saving central directory: the number of files in the archive
*/
DWORD m_uTotalToDo;
DWORD m_uTotalSoFar; ///< total number of bytes processed so far
CZipString m_szFileInZip; ///< file in zip archive being currently processed
/**
\return the number of bytes left to process
*/
DWORD LeftToDo() {return m_uTotalToDo - m_uTotalSoFar;}
/**
Called after the action finishes (it is not called in case of an exception, but
it is called before throwing CZipException::abortedAction or CZipException::abortedSafely)
*/
virtual void CallbackEnd()
{
ASSERT(m_uTotalSoFar == m_uTotalToDo);
};
/**
Used internally to call Callback and increase #m_uTotalSoFar by \e iProgress
*/
virtual bool operator()(int iProgress)
{
m_uTotalSoFar += iProgress;
return Callback(iProgress);
}
/**
Used only when creating map before deletion (see CZipArchive::cbDeleteCnt) or
saving the central directory record. You'll be notified every nth step (n is \e m_iStep value) with \e iProgress set to
\e m_iStep . Do not set it to low values or you can have a long waiting on archives
with huge number of files.
\b Default: 256.
*/
static int m_iStep;
/**
Used internally to return #m_iStep value but not 0 (return 1 in this case).
*/
int GetStep(){return m_iStep ? m_iStep : 1;} // do not allow 0 (crash)
};
/**
A low-level class - operates physically on archive (CZipArchive operates logically)
*/
class ZIP_API CZipStorage
{
friend class CZipCentralDir;
public:
/**
The type of the disk spanning archive.
\see CZipArchive::GetSpanMode
*/
enum ZipSpanMode {
noSpan, ///< no disk spanning
pkzipSpan, ///< \ref PKSpan "disk spanning compatible with PKZIP"
tdSpan, ///< \ref TDSpan "TD mode disk spanning archive"
/**
Detect the type automatically.
If the archive is on the removable device assume PKZIP compatible,
otherwise TD mode compatible.
*/
suggestedAuto,
/**
If the disk spanning archive is on the removable device
assume it is TD mode compatible
*/
suggestedTd
};
CZipStorage();
virtual ~CZipStorage();
/**
Open the archive in memory (new or existing).
The parameters are the same as CZipArchive::OpenMode.
\param mf
\param iMode
\note Throws exceptions.
\see CZipArchive::Open(LPCTSTR, int, int)
*/
void Open(CZipMemFile& mf, int iMode);
/**
Open or create an archive.
The parameters are the same as CZipArchive::Open.
\param szPathName
\param iMode
\param iVolumeSize
\note Throws exceptions.
\see CZipArchive::Open(CZipMemFile& , int);
*/
void Open(LPCTSTR szPathName, int iMode, int iVolumeSize);
/**
Close the disk-spanning archive and reopens as an existing disk-spanning archive or set mode to #noSpan
*/
void FinalizeSpan();
/**
Called only by CZipCentralDir::Read() when opening an existing archive.
\param uLastDisk
the disk number the central directory is on
\note Throws exceptions.
*/
void UpdateSpanMode(WORD uLastDisk);
/**
Write chunk of data to the archive.
\param pBuf
buffer with data
\param iSize
bytes to write
\param bAtOnce
if \c true, the whole data must fit in the current volume,
otherwise the disk change is performed
\note Throws exceptions.
*/
void Write(const void *pBuf, DWORD iSize, bool bAtOnce);
/**
Read chunk of data from the archive.
\param pBuf
buffer to receive data
\param iSize
bytes to read
\param bAtOnce
if \c true, the specified number of bytes must be read from the same
volume (no disk change allowed)
\note Throws exceptions.
*/
DWORD Read(void* pBuf, DWORD iSize, bool bAtOnce);
/**
Return the position in the file, taking into account the bytes in the write buffer.
\note Throws exceptions.
*/
DWORD GetPosition() const {return (DWORD)(m_pFile->GetPosition()) + m_uBytesInWriteBuffer;}
/**
Flush the data from the read buffer to the disk.
\note Throws exceptions.
*/
void Flush();
/**
Forces any data remaining in the file buffer to be written to the disk
*/
void FlushFile()
{
if (!m_bInMemory && !IsReadOnly())
m_pFile->Flush();
}
/**
A method used to change disks during writing to the disk spanning archive.
\param iNeeded
no of bytes needed on the disk
\param lpszFileName
the archive filename
\note Throws exceptions.
*/
void NextDisk(int iNeeded, LPCTSTR lpszFileName = NULL);
/**
\return a zero-based number of the current disk
*/
int GetCurrentDisk() const {return m_iCurrentDisk;}
/**
Change the disk during extract operations.
\param iNumber
a zero-based disk number requested
\return
*/
void ChangeDisk(int iNumber);
/**
Detect the span mode.
\return
- -1 - existing disk spanning archive opened
- 0 - no disk spanning archive
- 1 - disk spanning archive in creation
*/
int IsSpanMode() const
{
return m_iSpanMode == noSpan ? 0 : (m_bNewSpan ? 1 : -1);
}
/**
return \c true if the archive cannot be modified.
*/
bool IsReadOnly()
{
return m_bReadOnly || IsSpanMode() < 0;
}
/**
\param bAfterException
set to \c true after the library has throw an exception.
The simplified mode is used then.
In this case it'll be possible to reuse the object to operate on another
archive, but the current archive file will not be valid anyway.
\return the filepath of the archive (used by CZipArchive::Close)
\note Throws exceptions.
*/
CZipString Close(bool bAfterException);
/**
The size of the write buffer.
Set before opening the archive.
It is usually set with CZipArchive::SetAdvanced
(specify this value as the first argument).
\see CZipArchive::SetAdvanced
*/
int m_iWriteBufferSize;
/**
The physical archive file (on a storage device).
Not used when opening archive in memory
with Open(CZipMemFile& , int).
*/
CZipFile m_internalfile;
/**
The buffer representing the archive.
It is a physical file or a memory buffer depending on what
method was used to open the archive. In the first case it is
a pointer to #m_internalfile.
\see Open(LPCTSTR, int, int);
\see Open(CZipMemFile& mf, int)
*/
CZipAbstractFile* m_pFile;
/**
Takes one of the values of #ZipSpanMode.
*/
int m_iSpanMode;
/**
A callback functor which method \c Callback is called when there is a need for a disk change
while operating on a #pkzipSpan archive.
\see CZipArchive::SetSpanCallback
*/
CZipSpanCallback* m_pChangeDiskFunc;
/**
The signature of the extended header
*/
static char m_gszExtHeaderSignat[];
protected:
/**
Flush without writing. Can be used only on non-disk spanning archives.
*/
void EmptyWriteBuffer()
{
m_uBytesInWriteBuffer = 0;
}
/**
Open a physical file.
\param lpszName
the name of the file to open
\param uFlags
file open flags
\param bThrow
if \c true then throw an exception in case of failure
\return \c true if successful
*/
bool OpenFile(LPCTSTR lpszName, UINT uFlags, bool bThrow = true);
/**
Throw an exception with the given code.
\param err
\see CZipException::Throw
*/
void ThrowError(int err);
/**
Return the number of bytes left on the current volume.
*/
DWORD VolumeLeft() const;
/**
Rename last file in TD mode disk spanning archive when done with creating
*/
CZipString RenameLastFileInTDSpan();
/**
Write data to the internal buffer.
\param *pBuf
the buffer to copy data from
\param uSize
bytes to write
\note Throws exceptions.
*/
void WriteInternalBuffer(const char *pBuf, DWORD uSize);
/**
\return the number of free bytes on the current removable disk
*/
DWORD GetFreeVolumeSpace() const;
/**
Call the callback functor.
Throw an exception if the callback functor's method \c Callback returns \c false.
\param iCode
a code to be passed to the callback functor
\param szTemp
a string to be used as a filename (the second argument
of CZipException::Throw) when the exception must be thrown
\note Throws exceptions.
\see CZipArchive::SetSpanCallback
\see CZipException::Throw
*/
void CallCallback(int iCode, CZipString szTemp);
/**
Construct the name of the volume in #tdSpan mode.
\param bLast
must be \c true if constructing the last volume name (an extension "zip" is given)
\param lpszZipName
the name of the archive
\return
the new volume name
*/
CZipString GetTdVolumeName(bool bLast, LPCTSTR lpszZipName = NULL) const;
/**
Change the disk in #tdSpan mode
*/
CZipString ChangeTdRead();
/**
Change the disk in #pkzipSpan mode
*/
CZipString ChangePkzipRead();
/**
Used only in \ref TDSpan "TD span mode" . The value it holds depends on the open mode.
- Opened existing disk spanning archive - store the number of the last
disk ( the one with "zip" extension).
- Disk spanning archive in creation - the size of the volume.
\see CZipArchive::Open
\see CZipArchive::GetSpanMode
*/
int m_iTdSpanData;
/**
The extension of the last volume.
*/
CZipString m_szSpanExtension;
/**
\return the count bytes left free in the write buffer
*/
DWORD GetFreeInBuffer() const {return m_pWriteBuffer.GetSize() - m_uBytesInWriteBuffer;}
/**
Number of bytes available in the write buffer.
*/
DWORD m_uBytesInWriteBuffer;
/**
The value it holds depends on the open mode:
\par
- #tdSpan : the total size of the current volume
- #pkzipSpan: a free space on the current volume
*/
DWORD m_uCurrentVolSize;
/**
number of bytes left free in the write buffer
*/
DWORD m_uVolumeFreeInBuffer;
/**
Write buffer caching data.
*/
CZipAutoBuffer m_pWriteBuffer;
/**
Used only during disk spanning archive creation.
Tells how many bytes have been written physically to the current volume.
*/
DWORD m_iBytesWritten;
/**
\c True, if the current archive is a new disk spanning archive.
*/
bool m_bNewSpan;
/**
The current disk in a disk spanning archive.
Disk no 0 is the first disk.
*/
int m_iCurrentDisk;
/**
It is set to \e true when an archive is created in memory; \e false otherwise.
*/
bool m_bInMemory;
/**
It is set to \e true if OpenMode::zipOpenReadOnly was specified when opening the archive
*/
bool m_bReadOnly;
};
#endif // !defined(AFX_ZIPSTORAGE_H__941824FE_3320_4794_BDE3_BE334ED8984B__INCLUDED_)

View File

@@ -1,308 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipString.h $
// $Archive: /ZipArchive_STL/ZipString.h $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#ifndef __ZIPSTRING_H__
#define __ZIPSTRING_H__
#include "stdafx.h"
#if defined(_MSC_VER) && (_MSC_VER > 1100)
#pragma warning( push, 3 ) // STL requrements
#endif
/**
If you wish the class to respect your locale (if it is different from
English), you need to set it in your program with function
std::locale::global(std::locale("")) (to set it to be the same as your
system locale) or e.g. std::locale::global(std::locale("French"))
( to set it to a specified value); setlocale() function is not sufficient here.
*/
#include <string>
#include <algorithm>
#include <stdarg.h>
#include <stdio.h>
#include "ZipExport.h"
#ifndef __GNUC__
#ifndef _vsntprintf
#ifdef _UNICODE
#define _vsntprintf _vsnwprintf
#else
#define _vsntprintf _vsnprintf
#endif
#endif
#include <locale>
#else
#define _vsntprintf vsnprintf
#endif
typedef std::basic_string<TCHAR> stdbs;
/**
This is not a full MFC - CString replacement.
For now it contains mostly the methods required by ZipArchive library.
*/
class ZIP_API CZipString : public stdbs
{
void TrimInternalL(size_type iPos)
{
if (iPos == npos)
erase ();
if (iPos)
erase(0, iPos);
}
void TrimInternalR(size_type iPos)
{
if (iPos == npos)
erase ();
erase(++iPos);
}
#ifndef __GNUC__
static int zslen(const TCHAR* lpsz)
{
return lpsz ? (int)std::char_traits<TCHAR>::length(lpsz) : 0;
}
static TCHAR tl(TCHAR c)
{
return std::tolower<TCHAR>(c, std::locale());
}
static TCHAR tu(TCHAR c)
{
return std::toupper<TCHAR>(c, std::locale());
}
#else
#if __GNUC__ <3
static int zslen(const TCHAR* lpsz)
{
return lpsz ? std::string_char_traits<TCHAR>::length(lpsz) : 0;
}
#else
static int zslen(const TCHAR* lpsz)
{
return lpsz ? std::char_traits<TCHAR>::length(lpsz) : 0;
}
#endif
#endif
public:
CZipString(){}
explicit CZipString (TCHAR ch, int nRepeat = 1):stdbs(nRepeat, ch){}
CZipString( const CZipString& stringSrc ) {assign(stringSrc);}
CZipString( const stdbs& stringSrc ) {assign(stringSrc);}
CZipString( LPCTSTR lpsz ){if (!lpsz) Empty(); else assign(lpsz);}
operator LPCTSTR() const{return c_str();}
int GetLength() const {return (int) size();}
bool IsEmpty() const {return empty();}
void Empty() {erase(begin(), end());}
TCHAR GetAt (int iIndex) const{return at(iIndex);}
TCHAR operator[] (int iIndex) const{return at(iIndex);}
void SetAt( int nIndex, TCHAR ch ) {at(nIndex) = ch;}
LPTSTR GetBuffer(int nMinBufLength)
{
if ((int)size() < nMinBufLength)
resize(nMinBufLength);
return empty() ? const_cast<TCHAR*>(data()) : &(at(0));
}
void ReleaseBuffer( int nNewLength = -1 ) { resize(nNewLength > -1 ? nNewLength : zslen(c_str()));}
void TrimLeft( TCHAR chTarget )
{
TrimInternalL(find_first_not_of(chTarget));
}
void TrimLeft( LPCTSTR lpszTargets )
{
TrimInternalL(find_first_not_of(lpszTargets));
}
void TrimRight( TCHAR chTarget )
{
TrimInternalR(find_last_not_of(chTarget));
}
void TrimRight( LPCTSTR lpszTargets )
{
TrimInternalR(find_last_not_of(lpszTargets));
}
void Format(LPCTSTR lpszFormat, ...)
{
va_list arguments;
va_start (arguments, lpszFormat);
TCHAR* pBuf = NULL;
int iCounter = 1, uTotal = 0;
do
{
int nLen = sizeof(TCHAR) * iCounter*1024;
pBuf = (TCHAR*)realloc((void*)pBuf, nLen);
if (!pBuf)
return;
uTotal = _vsntprintf(pBuf, nLen - 1, lpszFormat, arguments);
if (uTotal == -1 || (uTotal == nLen - 1) ) // for some implementations
{
pBuf[nLen - 1] = _T('\0');
if (iCounter == 7)
break;
}
else
{
pBuf[uTotal] = _T('\0');
break;
}
} while (true);
va_end (arguments);
*this = pBuf;
free(pBuf);
}
void Insert( int nIndex, LPCTSTR pstr ){insert(nIndex, pstr, zslen(pstr));}
void Insert( int nIndex, TCHAR ch ) {insert(nIndex, 1, ch);}
int Delete( int nIndex, int nCount = 1 )
{
int iSize = (int) size();
int iToDelete = iSize < nIndex + nCount ? iSize - nIndex : nCount;
if (iToDelete > 0)
{
erase(nIndex, iToDelete);
iSize -= iToDelete;
}
return iSize;
}
void MakeLower()
{
#ifndef __GNUC__
// use_facet doesn't work here well (doesn't convert all the local characters properly)
std::transform(begin(),end(),begin(),tl);
#else
std::transform(begin(),end(),begin(),tolower);
#endif
}
void MakeUpper()
{
#ifndef __GNUC__
// use_facet doesn't work here well (doesn't convert all the local characters properly)
std::transform(begin(),end(),begin(),tu);
#else
std::transform(begin(),end(),begin(),toupper);
#endif
}
void MakeReverse()
{
std::reverse(begin(), end());
}
CZipString Left( int nCount ) const { return substr(0, nCount);}
CZipString Right( int nCount) const
{
nCount = (int)size() < nCount ? (int)size() : nCount;
return substr(size() - nCount);
}
CZipString Mid( int nFirst ) const {return substr(nFirst);}
CZipString Mid( int nFirst, int nCount ) const {return substr(nFirst, nCount);}
int Collate( LPCTSTR lpsz ) const
{
#ifndef __GNUC__
#ifdef _UNICODE
return wcscoll(c_str(), lpsz);
#else
return strcoll(c_str(), lpsz);
#endif
#else
// return compare(lpsz);
return strcoll(c_str(), lpsz);
#endif
}
int CollateNoCase( LPCTSTR lpsz ) const
{
CZipString s1(c_str()), s2(lpsz);
s1.MakeLower();
s2.MakeLower();
return s1.Collate(s2);
}
int Compare( LPCTSTR lpsz ) const
{
return compare(lpsz);
}
int CompareNoCase( LPCTSTR lpsz ) const
{
CZipString s1(c_str()), s2(lpsz);
s1.MakeLower();
s2.MakeLower();
return s1.Compare(s2);
}
bool operator != (LPCTSTR lpsz)
{
return Compare(lpsz) != 0;
}
#if __GNUC__ >=3
#else
bool operator == (LPCTSTR lpsz)
{
return Compare(lpsz) == 0;
}
#endif
int Find( TCHAR ch, int nStart = 0) const
{
return (int) find(ch, nStart);
}
int Find( LPCTSTR pstr, int nStart = 0) const
{
return (int) find(pstr, nStart);
}
int Replace( TCHAR chOld, TCHAR chNew )
{
int iCount = 0;
for (iterator it = begin(); it != end(); ++it)
if (*it == chOld)
{
*it = chNew;
iCount++;
}
return iCount;
}
};
/**
A poiter type to point to CZipString to Collate or CollateNoCase
or Compare or CompareNoCase
*/
typedef int (CZipString::*ZIPSTRINGCOMPARE)( LPCTSTR ) const;
/**
return a pointer to the function in CZipString structure,
used to compare elements depending on the arguments
*/
ZIP_API ZIPSTRINGCOMPARE GetCZipStrCompFunc(bool bCaseSensitive, bool bCollate = true);
#if defined(_MSC_VER) && (_MSC_VER > 1100)
#pragma warning( pop)
#endif
#endif //__ZIPSTRING_H__

View File

@@ -1,218 +0,0 @@
/* zutil.h -- internal interface and configuration of the compression library
* Copyright (C) 1995-2002 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* WARNING: this file should *not* be used by applications. It is
part of the implementation of the compression library and is
subject to change. Applications should only use zlib.h.
*/
/* @(#) $Id$ */
#ifndef _Z_UTIL_H
#define _Z_UTIL_H
#include "hbcomprs.h"
#ifdef STDC
# include <stddef.h>
# include <string.h>
# include <stdlib.h>
#endif
#ifdef NO_ERRNO_H
extern int errno;
#else
# include <errno.h>
#endif
#ifndef local
# define local static
#endif
/* compile with -Dlocal if your debugger can't find static symbols */
typedef unsigned char uch;
typedef uch FAR uchf;
typedef unsigned short ush;
typedef ush FAR ushf;
typedef unsigned long ulg;
extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
/* (size given to avoid silly warnings with Visual C++) */
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
#define ERR_RETURN(strm,err) \
return (strm->msg = (char*)ERR_MSG(err), (err))
/* To be used only when the state is known to be valid */
/* common constants */
#ifndef DEF_WBITS
# define DEF_WBITS MAX_WBITS
#endif
/* default windowBits for decompression. MAX_WBITS is for compression only */
#if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
#endif
/* default memLevel */
#define STORED_BLOCK 0
#define STATIC_TREES 1
#define DYN_TREES 2
/* The three kinds of block type */
#define MIN_MATCH 3
#define MAX_MATCH 258
/* The minimum and maximum match lengths */
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
/* target dependencies */
#ifdef MSDOS
# define OS_CODE 0x00
# if defined(__TURBOC__) || defined(__BORLANDC__)
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
/* Allow compilation with ANSI keywords only enabled */
void _Cdecl farfree( void *block );
void *_Cdecl farmalloc( unsigned long nbytes );
# else
# include <alloc.h>
# endif
# else /* MSC or DJGPP */
# include <malloc.h>
# endif
#endif
#ifdef OS2
# define OS_CODE 0x06
#endif
#ifdef WIN32 /* Window 95 & Windows NT */
# define OS_CODE 0x0b
#endif
#if defined(VAXC) || defined(VMS)
# define OS_CODE 0x02
# define F_OPEN(name, mode) \
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif
#ifdef AMIGA
# define OS_CODE 0x01
#endif
#if defined(ATARI) || defined(atarist)
# define OS_CODE 0x05
#endif
#if defined(MACOS) || defined(TARGET_OS_MAC)
# define OS_CODE 0x07
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include <unix.h> /* for fdopen */
# else
# ifndef fdopen
# define fdopen(fd,mode) NULL /* No fdopen() */
# endif
# endif
#endif
#ifdef __50SERIES /* Prime/PRIMOS */
# define OS_CODE 0x0F
#endif
#ifdef TOPS20
# define OS_CODE 0x0a
#endif
#if defined(_BEOS_) || defined(RISCOS)
# define fdopen(fd,mode) NULL /* No fdopen() */
#endif
#if (defined(_MSC_VER) && (_MSC_VER > 600))
# define fdopen(fd,type) _fdopen(fd,type)
#endif
/* Common defaults */
#ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */
#endif
#ifndef F_OPEN
# define F_OPEN(name, mode) fopen((name), (mode))
#endif
/* functions */
#ifdef HAVE_STRERROR
extern char *strerror OF((int));
# define zstrerror(errnum) strerror(errnum)
#else
# define zstrerror(errnum) ""
#endif
#if defined(pyr)
# define NO_MEMCPY
#endif
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
/* Use our own functions for small and medium model with MSC <= 5.0.
* You may have to use the same strategy for Borland C (untested).
* The __SC__ check is for Symantec.
*/
# define NO_MEMCPY
#endif
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
# define HAVE_MEMCPY
#endif
#ifdef HAVE_MEMCPY
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
# define zmemcpy _fmemcpy
# define zmemcmp _fmemcmp
# define zmemzero(dest, len) _fmemset(dest, 0, len)
# else
# define zmemcpy memcpy
# define zmemcmp memcmp
# define zmemzero(dest, len) memset(dest, 0, len)
# endif
#else
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
extern void zmemzero OF((Bytef* dest, uInt len));
#endif
/* Diagnostic functions */
#ifdef DEBUG
# include <stdio.h>
extern int z_verbose;
extern void z_error OF((char *m));
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
#else
# define Assert(cond,msg)
# define Trace(x)
# define Tracev(x)
# define Tracevv(x)
# define Tracec(c,x)
# define Tracecv(c,x)
#endif
typedef uLong (ZEXPORT *check_func) OF((uLong check, const Bytef *buf, uInt len));
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
void zcfree OF((voidpf opaque, voidpf ptr));
#define ZALLOC(strm, items, size) (*((strm)->zalloc))((strm)->opaque, (items), (size))
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
#endif /* _Z_UTIL_H */

View File

@@ -1,3 +0,0 @@
#!/bin/sh
cp Linux/ZipFileMapping.h zipfilemapping.h
make

View File

@@ -1,29 +0,0 @@
@echo off
rem
rem $Id$
rem
if not exist obj md obj
if not exist obj\b32 md obj\b32
:BUILD
make -fmakefile.bc %1 %2 %3 > make_b32.log
if "%1" == "clean" goto CLEAN
if "%1" == "CLEAN" goto CLEAN
if errorlevel 1 goto BUILD_ERR
:BUILD_OK
copy ..\..\lib\b32\hbzip.lib ..\..\lib > nul
goto EXIT
:BUILD_ERR
notepad make_b32.log
goto EXIT
:CLEAN
if exist make_b32.log del make_b32.log
:EXIT

View File

@@ -1,21 +0,0 @@
@echo off
rem
rem $Id$
rem
if not exist obj md obj
:BUILD
nmake -fmakefile.vc %1 %2 %3 > make_vc.log
if errorlevel 1 goto BUILD_ERR
:BUILD_OK
copy ..\..\lib\vc\hbzip.lib ..\..\lib > nul
goto EXIT
:BUILD_ERR
notepad make_vc.log
:EXIT

View File

@@ -1,20 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
// $Workfile: stdafx.cpp $
// $Archive: /ZipArchive/stdafx.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"

View File

@@ -1,19 +0,0 @@
#define B_BOXLINES "ÚÄ¿³ÙÄÀ³"
Function Main()
local aDir:=Directory("*.h")
local afiles:={}
Local x
local nLen
local aGauge
CLS
For x:=1 to len(aDir)
aadd(afiles,adir[x,1])
next
nLen=len(afiles)
aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²')
GaugeDisplay( aGauge )
Hb_ZIPFILE('test12.zip',afiles,8,{|nPos,cFile| GaugeUpdate(aGauge,nPos/nLen)})
Hb_ZIPFILE('test22.zip',afiles,8,{|nPos,cFile| qout(cFile)})
return nil

View File

@@ -1,41 +0,0 @@
#define B_BOXLINES "ÚÄ¿³ÙÄÀ³"
#include 'tzipfile.ch'
Function Main()
Local aArray,x,oZip
local aDir:=Directory("*.h")
local afiles:={}
local nLen
local aGauge
CLS
Create ZipFile oZip file "test9658.zip" BLOCK {|cFile| qOut(cFile)} COMPRESS
For x:=1 to len(aDir)
Add file adir[x,1] to oZip
// aadd(afiles,adir[x,1])
next
Activate zip oZip
?
? "Number of Files in this Zipfile",oZip:GetNumberofFiles()
/*
nLen=len(afiles)
aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²')
GaugeDisplay( aGauge )
Hb_ZIPFILE('test12.zip',afiles,8,{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen)})
Hb_ZIPFILE('test22.zip',afiles,8,{|nPos,cFile| qout(cFile)})
hb_zipfile('test22.zip',{'data/','data/hbdoc.obj','data/genhtm.obj'},8)
inkey(0)
local aGauge,nLen
aGauge := GaugeNew( 5, 5, 7,40 , "W/B", "W+/B" ,'²')
GaugeDisplay( aGauge )
x:= HB_GETUNZIPFILE('test22.zip')
? "number of files in zip",x
aArray:=HB_GETFILESINZIP('test22.zip')
for x:=1 to len(aArray)
? aArray[x]
next
nlen:=HB_GETUNZIPFILE('test22.zip')
hb_UNZIPFILE('test22.zip',{|cFile,nPos| GaugeUpdate(aGauge,nPos/nLen),qout(cFile)},.T.)
*/
RETURN nil

View File

@@ -1,116 +0,0 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Tzipfile Class
*
* Copyright 2000 Luiz Rafael Culik <culik@sl.conex.net>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#include 'hbclass.ch'
#include 'common.ch'
CLASS tZipFile
data cFile as CHARACTER init ""
Data aFiles as ARRAY init {}
Data aList as ARRAY init {}
Data bBlock as CODEBLOCK init {||NIL}
Data lOverwrite as LOGICAL init .f.
Data nCompMethod as NUMERIC init 8
Method New(cFile,nMethod,bBlock,lCompress,lOverwrite)
Method DoCompress()
Method DoUnzip()
method AddFile(cFile)
Method GetNumberofFiles()
Method GetList()
Method ShowList()
ENDCLASS
Method New(cFile,nMethod,bBlock,lCompress,lOverwrite) CLASS tZipFile
default lCompress to .t.
Default lOverWrite to .T.
if lCompress
Default nMethod to 8
Endif
::cFile := cFile
::nCompMethod := nMethod
::lOverWrite := lOverWrite
::aFiles := {}
::bBlock := bBlock
return Self
Method AddFile(cFile) CLASS tZipFile
if cFile != NIL
aadd(::aFiles,cFile)
endif
return Self
Method GetList() CLASS tZipFile
::aList := {}
::aList := HB_GETFILESINZIP(::cFile)
return Self
Method ShowList() CLASS tZipFile
local x
For x:=1 to len(::aList)
qout(::aList[x])
next
return Self
Method GetNumberofFiles() CLASS tZipFile
Local nFiles
nFiles:=HB_GETUNZIPFILE(::cFile)
return nFiles
Method doCompress() CLASS tZipFile
if HB_ZIPFILE(::cFile,::aFiles, ::nCompMethod,::bBlock,::lOverWrite)
Return .T.
endif
Return .F.
Method DoUnzip() CLASS tZipFile
IF HB_UNZIPFILE(::cFile,::bBlock,1)
Return .t.
endif
return .f.

View File

@@ -1,248 +0,0 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Harbour zip file compress function,
*
* Copyright 2000-2001 Luiz Rafael Culik <culik@sl.conex.net>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#include <hbzip2.h>
extern PHB_ITEM pArray;
HB_FUNC(HB_ZIPFILE)
{
if( ISCHAR(1) && ISCHAR(2))
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_CompressFileStd(hb___CheckFile(szFile),hb_parc(2),ISNUM(3) ? hb_parni(3) : (-1) ,hb_param( 4, HB_IT_BLOCK) ,ISLOG(5) ? hb_parl(5) : 0,hb_parc(6),ISLOG(7) ? hb_parl(7) : 0 ,ISLOG(8) ? hb_parl(8) : 0,hb_itemParam(9)));
}
if(ISCHAR(1) && ISARRAY(2))
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_CompressFile(hb___CheckFile(szFile),hb_param( 2, HB_IT_ARRAY ),ISNUM(3) ? hb_parni(3) : (-1) ,hb_param( 4,HB_IT_BLOCK),ISLOG(5) ? hb_parl(5) : 0,hb_parc(6),ISLOG(7) ? hb_parl(7) : 0,ISLOG(8) ? hb_parl(8) : 0,hb_itemParam(9)));
}
}
HB_FUNC(HB_GETFILESINZIP)
{
if( ISCHAR(1) )
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb___GetFilesNamesFromZip(hb___CheckFile(szFile),ISLOG(2) ? hb_parl(2) : 0);
hb_itemReturn(pArray);
hb_itemRelease(pArray);
}
}
HB_FUNC(HB_ZIPWITHPASSWORD)
{
hb_retl(hb_IsPassWord(hb_parc(1)));
}
HB_FUNC(HB_GETUNZIPFILE)
{
if( ISCHAR(1) )
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retni(hb___GetNumbersofFilestoUnzip(hb___CheckFile(szFile)));
}
}
HB_FUNC(HB_ZIPFILEBYTDSPAN)
{
if( ISCHAR(1) && ISCHAR(2))
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_CmpTdSpanStd(hb___CheckFile(szFile),hb_parc(2),ISNUM(3) ? hb_parni(3) : (-1),hb_param( 4, HB_IT_BLOCK) ,ISLOG(5) ? hb_parl(5) : 0, hb_parc(6) ,hb_param( 7,HB_IT_BLOCK),ISNUM(8) ? hb_parni(8) : 0,ISLOG(9) ? hb_parl(9) : 0,ISLOG(10) ? hb_parl(10) : 0,hb_itemParam(11)));
}
if(ISCHAR(1) && ISARRAY(2))
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_CmpTdSpan(hb___CheckFile(szFile),hb_param( 2, HB_IT_ARRAY ),ISNUM(3) ? hb_parni(3) : (-1) ,hb_param( 4,HB_IT_BLOCK),ISLOG(5) ? hb_parl(5) : 0 ,hb_parc(6) ,hb_param( 7,HB_IT_BLOCK),ISNUM(8) ? hb_parni(8) :0,ISLOG(9) ? hb_parl(9) : 0,ISLOG(10) ? hb_parl(10) : 0,hb_itemParam(11)));
}
}
HB_FUNC(HB_ZIPFILEBYPKSPAN)
{
if( ISCHAR(1) && ISCHAR(2))
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_CmpPkSpanStd(hb___CheckFile(szFile),hb_parc(2),ISNUM(3) ? hb_parni(3) : (-1),hb_param( 4, HB_IT_BLOCK) ,ISLOG(5) ? hb_parl(5) : 0, hb_parc(6),ISLOG(7) ? hb_parl(7) : 0,ISLOG(8) ? hb_parl(8) : 0,hb_itemParam(9)));
}
if(ISCHAR(1) && ISARRAY(2))
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_CmpPkSpan(hb___CheckFile(szFile),hb_param( 2, HB_IT_ARRAY ),ISNUM(3) ? hb_parni(3) : (-1),hb_param( 4,HB_IT_BLOCK),ISLOG(5) ? hb_parl(5) : 0,hb_parc(6),ISLOG(7) ? hb_parl(7) : 0,ISLOG(8) ? hb_parl(8) : 0,hb_itemParam(9)));
}
}
HB_FUNC(HB_UNZIPFILE)
{
if( ISCHAR(1) && ISCHAR(6) )
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_UnzipOne(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),ISCHAR(5) ? hb_parc(5) : NULL,hb_parc(6),hb_itemParam(7)));
}
if( ISCHAR(1) && ISARRAY(6) )
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_UnzipSel(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),ISCHAR(5) ? hb_parc(5) : NULL ,hb_param(6,HB_IT_ARRAY),hb_itemParam(7)));
}
if ( ! ISCHAR(6) && ! ISARRAY(6) )
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_UnzipAll(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),ISCHAR(5) ? hb_parc(5) : NULL,hb_param( 6, HB_IT_BLOCK),hb_itemParam(7)));
}
}
HB_FUNC(HB_SETDISKZIP)
{
hb_retl(hb___SetCallbackFunc(hb_itemParam(1)));
}
HB_FUNC(HB_ZIPDELETEFILES)
{
if (ISCHAR(1)&& ISCHAR(2))
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_DeleteOne(hb___CheckFile(szFile),hb_parc(2)));
}
if (ISCHAR(1)&&ISARRAY(2))
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_DeleteSel(hb___CheckFile(szFile),hb_param(2,HB_IT_ARRAY),ISLOG(3) ? hb_parl(3) : 0));
}
if (ISCHAR(1)&&ISNUM(2))
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_DeleteOneIndex(hb___CheckFile(szFile),hb_parni(2)));
}
}
HB_FUNC(HB_ZIPTESTPK)
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retni(hb_TestForPKS(hb___CheckFile(szFile)));
}
HB_FUNC(HB_SETBUFFER)
{
hb_SetZipBuff(ISNUM(1) ? hb_parni(1) : 65535,ISNUM(2) ? hb_parni(2) : 16384,ISNUM(3) ? hb_parni(3) : 32768);
}
HB_FUNC(HB_SETZIPCOMMENT)
{
hb_SetZipComment(hb_parc(1));
}
HB_FUNC(HB_GETZIPCOMMENT)
{
char *szComment=(char*)hb_GetZipComment(hb_parc(1));
hb_retc(szComment);
hb_xfree(szComment);
}
HB_FUNC(HB_UNZIPFILEINDEX)
{
if( ISCHAR(1) && ISNUM(6) )
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_UnzipOneIndex(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),hb_parc(5),hb_parni(6),hb_itemParam(7)));
}
if( ISCHAR(1) && ISARRAY(6) )
{
char szFile[_POSIX_PATH_MAX];
strcpy(szFile,hb_parc(1));
hb_retl(hb_UnzipSelIndex(hb___CheckFile(szFile),hb_param( 2, HB_IT_BLOCK),ISLOG(3) ? hb_parl(3) : 0 ,hb_parc(4),hb_parc(5),hb_param(6,HB_IT_ARRAY),hb_itemParam(7)));
}
}
HB_FUNC(HB_ZIPINMEMORY)
{
hb_retl(hb_CreateZipInMemory(hb_parc(1),hb_parc(2)));
}
/*
HB_FUNC(HB_SAVEZIPFROMMEMORY)
{
hb_retl(hb_SaveZipFileFromMemory());
}
*/

File diff suppressed because it is too large Load Diff

View File

@@ -1,108 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipAutoBuffer.cpp $
// $Archive: /ZipArchive_STL/ZipAutoBuffer.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipautobuffer.h"
#include <memory.h>
// #ifdef _DEBUG
// #undef THIS_FILE
// static char THIS_FILE[]=__FILE__;
// #define new DEBUG_NEW
// #endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CZipAutoBuffer::CZipAutoBuffer()
{
m_iSize = 0;
m_pBuffer = NULL;
}
CZipAutoBuffer::CZipAutoBuffer(DWORD iSize, bool bZeroMemory)
{
m_iSize = 0;
m_pBuffer = NULL;
Allocate(iSize, bZeroMemory);
}
CZipAutoBuffer::~CZipAutoBuffer()
{
Release();
}
void CZipAutoBuffer::Release()
{
if (m_pBuffer)
{
delete [] m_pBuffer;
m_iSize = 0;
m_pBuffer = NULL;
}
}
char* CZipAutoBuffer::Allocate(DWORD iSize, bool bZeroMemory)
{
if (iSize != m_iSize)
Release();
else
{
if (bZeroMemory)
memset(m_pBuffer, 0, iSize); // zerowanie bufora
return m_pBuffer;
}
if (iSize > 0)
{
m_pBuffer = new char [iSize];
if (bZeroMemory)
memset(m_pBuffer, 0, iSize); // zerowanie bufora
m_iSize = iSize;
}
else
m_pBuffer = NULL;
return m_pBuffer;
}
CZipAutoBuffer::CZipAutoBuffer(const CZipAutoBuffer& buffer)
{
m_pBuffer = NULL;
m_iSize = 0;
if (buffer.m_pBuffer)
{
Allocate(buffer.m_iSize);
memcpy(m_pBuffer, buffer.m_pBuffer, buffer.m_iSize);
}
}
CZipAutoBuffer& CZipAutoBuffer::operator=(const CZipAutoBuffer& buffer)
{
if (this == &buffer)
return *this;
Release();
if (buffer.m_pBuffer)
{
Allocate(buffer.m_iSize);
memcpy(m_pBuffer, buffer.m_pBuffer, buffer.m_iSize);
}
return *this;
}

View File

@@ -1,852 +0,0 @@
///////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipCentralDir.cpp $
// $Archive: /ZipArchive/ZipCentralDir.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipcentraldir.h"
#include "ziparchive.h"
#include "zipfilemapping.h"
#include "zipplatform.h"
#define CENTRALDIRSIZE 22
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
char CZipCentralDir::m_gszSignature[] = {0x50, 0x4b, 0x05, 0x06};
CZipCentralDir::CZipCentralDir()
{
m_bConvertAfterOpen = true;
m_bFindFastEnabled = false;
m_bCaseSensitive = false;
m_pCompare = GetCZipStrCompFunc(ZipPlatform::GetSystemCaseSensitivity());
m_pStorage = NULL;
m_pOpenedFile = NULL;
m_iBufferSize = 32768;
}
void CZipCentralDir::Init()
{
m_info.m_bOnDisk = false;
m_info.m_uBytesBeforeZip = m_info.m_uCentrDirPos = 0;
m_pOpenedFile = NULL;
m_pszComment.Release();
}
CZipCentralDir::~CZipCentralDir()
{
Clear();
}
void CZipCentralDir::Read()
{
ASSERT(m_pStorage);
WORD uCommentSize;
m_info.m_uCentrDirPos = Locate();
m_pStorage->m_pFile->Seek(m_info.m_uCentrDirPos, CZipAbstractFile::begin);
CZipAutoBuffer buf(CENTRALDIRSIZE);
int uRead = m_pStorage->m_pFile->Read(buf, CENTRALDIRSIZE);
if (uRead != CENTRALDIRSIZE)
ThrowError(CZipException::badZipFile);
memcpy(&m_szSignature, buf, 4);
memcpy(&m_info.m_uThisDisk, buf + 4, 2);
memcpy(&m_info.m_uDiskWithCD, buf + 6, 2);
memcpy(&m_info.m_uDiskEntriesNo,buf + 8, 2);
memcpy(&m_info.m_uEntriesNumber,buf + 10, 2);
memcpy(&m_info.m_uSize, buf + 12, 4);
memcpy(&m_info.m_uOffset, buf + 16, 4);
memcpy(&uCommentSize, buf + 20, 2);
buf.Release();
m_pStorage->UpdateSpanMode(m_info.m_uThisDisk);
// if m_uThisDisk is not zero, it is enough to say that it is a multi disk archive
ASSERT((!m_info.m_uThisDisk && (m_info.m_uEntriesNumber == m_info.m_uDiskEntriesNo) && !m_info.m_uDiskWithCD) || m_info.m_uThisDisk);
if (!m_pStorage->IsSpanMode() && !m_info.CheckIfOK_1())
ThrowError(CZipException::badZipFile);
if (uCommentSize)
{
m_pszComment.Allocate(uCommentSize);
uRead = m_pStorage->m_pFile->Read(m_pszComment, uCommentSize);
if (uRead != uCommentSize)
ThrowError(CZipException::badZipFile);
}
m_info.SetBytesBeforeZip(m_pStorage->IsSpanMode() != 0);
if (!m_info.CheckIfOK_2())
ThrowError(CZipException::badZipFile);
m_info.m_bOnDisk = true;
m_pStorage->ChangeDisk(m_info.m_uDiskWithCD);
if (!m_info.m_uSize)
return;
ReadHeaders();
}
DWORD CZipCentralDir::Locate()
{
// maximum size of end of central dir record
long uMaxRecordSize = 0xffff + CENTRALDIRSIZE;
DWORD uFileSize = m_pStorage->m_pFile->GetLength();
if ((DWORD)uMaxRecordSize > uFileSize)
uMaxRecordSize = uFileSize;
CZipAutoBuffer buf(m_iBufferSize);
long uPosInFile = 0;
int uRead = 0;
// backward reading
while (uPosInFile < uMaxRecordSize)
{
uPosInFile = uRead + m_iBufferSize;
if (uPosInFile > uMaxRecordSize)
uPosInFile = uMaxRecordSize;
int iToRead = uPosInFile - uRead;
m_pStorage->m_pFile->Seek(-uPosInFile, CZipAbstractFile::end);
int iActuallyRead = m_pStorage->m_pFile->Read(buf, iToRead);
if (iActuallyRead != iToRead)
ThrowError(CZipException::badZipFile);
// search from the very last bytes to prevent an error if inside archive
// there are packed other arhives
for (int i = iToRead - 4; i >=0 ; i--)
if (!memcmp((char*)buf + i, m_gszSignature, 4))
return uFileSize - (uPosInFile - i);
uRead += iToRead - 3;
}
ThrowError(CZipException::cdirNotFound);
return 0;
}
void CZipCentralDir::ThrowError(int err) const
{
CZipException::Throw(err, m_pStorage->m_pFile->GetFilePath());
}
void CZipCentralDir::ReadHeaders()
{
m_pStorage->m_pFile->Seek(m_info.m_uOffset + m_info.m_uBytesBeforeZip, CZipAbstractFile::begin);
RemoveHeaders(); //just in case
for (int i = 0; i < m_info.m_uEntriesNumber; i++)
{
CZipFileHeader* pHeader = new CZipFileHeader;
m_headers.Add(pHeader);
if (!pHeader->Read(m_pStorage))
ThrowError(CZipException::badZipFile);
ConvertFileName(true, true, pHeader);
}
SortHeaders(); // this is necessary when deleting files and removing data descriptors
if (m_bFindFastEnabled)
BuildFindFastArray(m_bCaseSensitive);
}
void CZipCentralDir::SortHeaders()
{
// we cannot use the Sort method of the CZipWordArray,
// because we store pointers (and we need to store pointers
// to make sure that the address of the CZipFileHeader structure
// remains the same while working with the library)
int iSize = m_headers.GetSize();
if (iSize)
qsort((void*)&(m_headers[0]),iSize , sizeof(CZipFileHeader*), CompareHeaders);
}
void CZipCentralDir::Clear(bool bEverything)
{
m_pOpenedFile = NULL;
m_pLocalExtraField.Release();
if (bEverything)
{
RemoveHeaders();
m_findarray.RemoveAll();
m_pszComment.Release();
}
}
bool CZipCentralDir::IsValidIndex(int uIndex)const
{
return uIndex < m_headers.GetSize() && uIndex >= 0;
}
void CZipCentralDir::OpenFile(WORD uIndex)
{
WORD uLocalExtraFieldSize;
m_pOpenedFile = (*this)[uIndex];
m_pStorage->ChangeDisk(m_pOpenedFile->m_uDiskStart);
m_pStorage->m_pFile->Seek(m_pOpenedFile->m_uOffset + m_info.m_uBytesBeforeZip, CZipAbstractFile::begin);
if (!m_pOpenedFile->ReadLocal(m_pStorage, uLocalExtraFieldSize))
ThrowError(CZipException::badZipFile);
m_pLocalExtraField.Release(); // just in case
if (uLocalExtraFieldSize)
{
int iCurrDsk = m_pStorage->GetCurrentDisk();
m_pLocalExtraField.Allocate(uLocalExtraFieldSize);
m_pStorage->Read(m_pLocalExtraField, uLocalExtraFieldSize, true);
if (m_pStorage->GetCurrentDisk() != iCurrDsk)
ThrowError(CZipException::badZipFile);
}
}
void CZipCentralDir::CloseFile(bool bAfterException)
{
if (!m_pOpenedFile)
return;
m_pLocalExtraField.Release();
if (!bAfterException && m_pOpenedFile->IsDataDescr())
{
CZipAutoBuffer buf(12);
m_pStorage->Read(buf, 4, false);
// in span mode, files that are divided between disks have bit 3 of flag set
// which tell about the presence of the data descriptor after the compressed data
// This signature may be in the disk spanning archive that is one volume only
// (it is detected as a non disk spanning archive)
if (memcmp(buf, CZipStorage::m_gszExtHeaderSignat, 4) != 0) // there is no signature
m_pStorage->m_pFile->Seek(-4, CZipAbstractFile::current);
m_pStorage->Read(buf, 12, false);
if (!m_pOpenedFile->CheckCrcAndSizes(buf))
ThrowError(CZipException::badZipFile);
}
m_pOpenedFile = NULL;
}
// add new header using the argument as a template
CZipFileHeader* CZipCentralDir::AddNewFile(const CZipFileHeader & header, int iReplaceIndex)
{
CZipFileHeader* pHeader = new CZipFileHeader(header);
m_pOpenedFile = pHeader;
WORD uIndex;
DWORD uOffset = 0;
bool bReplace = IsValidIndex(iReplaceIndex);
if (bReplace)
{
CZipFileHeader* pfh = m_headers[iReplaceIndex];
uOffset = pfh->m_uOffset + m_info.m_uBytesBeforeZip;
RemoveFile(pfh, iReplaceIndex, false);
m_headers.InsertAt(iReplaceIndex, pHeader);
uIndex = (WORD)iReplaceIndex;
}
else
uIndex = m_headers.Add(pHeader);
if (m_bFindFastEnabled)
InsertFindFastElement(pHeader, uIndex); // GetCount > 0, 'cos we've just added a header
RemoveFromDisk();
if (bReplace)
m_pStorage->m_pFile->Seek(uOffset, CZipAbstractFile::begin);
else
m_pStorage->m_pFile->SeekToEnd();
return pHeader;
}
void CZipCentralDir::RemoveFromDisk()
{
if (m_info.m_bOnDisk)
{
ASSERT(!m_pStorage->IsSpanMode()); // you can't add files to the existing disk span archive or to delete them from it
m_pStorage->m_pFile->SetLength(m_info.m_uBytesBeforeZip + m_info.m_uOffset);
m_info.m_bOnDisk = false;
}
else
m_pStorage->Flush(); // if remove from disk is requested, then the archive modification will follow, so flush the buffers
}
void CZipCentralDir::CloseNewFile()
{
CZipAutoBuffer buf(ZIPARCHIVE_DATADESCRIPTOR_LEN + 4);
short iToWrite = 0;
bool bIsSpan = m_pStorage->IsSpanMode() != 0;
bool bEncrypted = m_pOpenedFile->IsEncrypted();
if (m_pOpenedFile->IsDataDescr())
{
if (bIsSpan || bEncrypted)
{
memcpy(buf, m_pStorage->m_gszExtHeaderSignat, 4);
iToWrite += 4;
}
}
else /*if (!IsSpan)*/
{
ASSERT(!bIsSpan && !bEncrypted);
m_pStorage->Flush();
// the offset contains bytes before zip (set while writting the local header)
m_pStorage->m_pFile->Seek(m_pOpenedFile->m_uOffset + 14, CZipAbstractFile::begin);
// we don't have to restore the pointer, because before adding a new file,
// the pointer is moved to the end
}
m_pOpenedFile->GetCrcAndSizes(buf + iToWrite);
iToWrite += ZIPARCHIVE_DATADESCRIPTOR_LEN;
// offset set during writing the local header
m_pOpenedFile->m_uOffset -= m_info.m_uBytesBeforeZip;
// write the data descriptor and a disk spanning signature at once
m_pStorage->Write(buf, iToWrite, true);
if (!bIsSpan)
{
if (bEncrypted)
{
// write the information to the local header too
m_pStorage->Flush();
m_pStorage->m_pFile->Seek(m_info.m_uBytesBeforeZip + m_pOpenedFile->m_uOffset + 14, CZipAbstractFile::begin);
m_pStorage->Write(buf + 4, ZIPARCHIVE_DATADESCRIPTOR_LEN, true);
}
m_pStorage->Flush();
}
m_pOpenedFile = NULL;
}
void CZipCentralDir::Write(CZipActionCallback* pCallback)
{
if (m_info.m_bOnDisk)
return;
if (!m_pStorage->IsSpanMode())
{
m_pStorage->Flush();
m_pStorage->m_pFile->SeekToEnd();
}
// else
// // we are at the end already
m_info.m_uEntriesNumber = (WORD)m_headers.GetSize();
m_info.m_uSize = 0;
bool bDontAllowDiskChange = false;
// if there is a disk spanning archive in creation and it is only one-volume,
// (current disk is 0 so far, no bytes has been written so we know they are
// all in the buffer) make sure that it will be after writing central dir
// and make it a non disk spanning archive
if (m_pStorage->IsSpanMode() && m_pStorage->GetCurrentDisk() == 0)
{
DWORD uVolumeFree = m_pStorage->VolumeLeft();
// calculate the size of data descriptors already in the buffer or on the disk
// (they will be removed in the non disk spanning archive):
// multi span signature at the beginnig (4 bytes) + the size of the data
// descr. for each file (multi span signature + 12 bytes data)
// the number of bytes to add: central dir size - total to remove;
DWORD uToGrow = GetSize(true) - (4 + m_info.m_uEntriesNumber * (4 + 12));
if (uVolumeFree >= uToGrow)
// lets make sure it will be one-disk archive
{
// can the operation be done only in the buffer?
if (!m_pStorage->m_iBytesWritten && // no bytes on the disk yet
(m_pStorage->GetFreeInBuffer() >= uToGrow)) // is the buffer big enough?
{
RemoveDataDescr(true);
bDontAllowDiskChange = true; // if the disk change occurs somehow, we'll throw an error later
}
else
{
m_pStorage->Flush();
if (RemoveDataDescr(false))
bDontAllowDiskChange = true; // if the disk change occurs somehow, we'll throw an error later
}
}
}
try
{
WriteHeaders(pCallback, bDontAllowDiskChange || !m_pStorage->IsSpanMode());
m_info.m_uThisDisk = (WORD)m_pStorage->GetCurrentDisk();
DWORD uSize = WriteCentralEnd();
if (bDontAllowDiskChange)
{
if (m_pStorage->GetCurrentDisk() != 0)
ThrowError(CZipException::badZipFile);
}
// if after adding a central directory there is a disk change,
// update the information and write it again
if (m_info.m_uThisDisk != m_pStorage->GetCurrentDisk())
{
m_info.DiskChange(m_pStorage->GetCurrentDisk());
if (m_pStorage->m_uBytesInWriteBuffer >= uSize)
// if the data is still in the buffer, simply remove it
m_pStorage->m_uBytesInWriteBuffer -= uSize;
else
{
m_pStorage->Flush();
m_pStorage->m_iBytesWritten -= uSize;
m_pStorage->m_pFile->SeekToBegin();
}
WriteCentralEnd();
}
}
catch (...)
{
if (bDontAllowDiskChange)
{
m_pStorage->FinalizeSpan();
m_info.m_uThisDisk = 0;
}
throw;
}
m_info.m_bOnDisk = true;
}
void CZipCentralDir::WriteHeaders(CZipActionCallback* pCallback, bool bOneDisk)
{
m_info.m_uDiskEntriesNo = 0;
m_info.m_uDiskWithCD = (WORD)m_pStorage->GetCurrentDisk();
m_info.m_uOffset = m_pStorage->GetPosition() - m_info.m_uBytesBeforeZip;
if (!m_info.m_uEntriesNumber)
return;
WORD iDisk = m_info.m_uDiskWithCD;
int iStep = 0; // for the compiler
if (pCallback)
{
pCallback->Init();
pCallback->SetTotal(m_info.m_uEntriesNumber);
iStep = CZipActionCallback::m_iStep;// we don't want to wait forever
}
int iAborted = 0;
for (int i = 0; i < m_info.m_uEntriesNumber; i++)
{
CZipFileHeader* pHeader = (*this)[i];
CZipString szRemember;
if (m_bConvertAfterOpen)
// if CZipArchive::Flush is called we will be still using the archive, so restore changed name
szRemember = pHeader->GetFileName();
ConvertFileName(false, true, pHeader);
m_info.m_uSize += pHeader->Write(m_pStorage);
if (m_bConvertAfterOpen)
pHeader->SetFileName(szRemember);
if (m_pStorage->GetCurrentDisk() != iDisk)
{
m_info.m_uDiskEntriesNo = 1;
iDisk = (WORD)m_pStorage->GetCurrentDisk();
// update the information about the offset and starting disk if the
// first header was written on the new disk
if (i == 0)
{
m_info.m_uOffset = 0;
m_info.m_uDiskWithCD = iDisk;
}
}
else
m_info.m_uDiskEntriesNo++;
if (pCallback && !(i%iStep))
if (!pCallback->Callback(iStep))
{
if (bOneDisk)
{
if (!m_pStorage->IsSpanMode())
m_pStorage->EmptyWriteBuffer();
else
m_pStorage->Flush(); // must be flush before - flush was not called in span mode
// remove saved part from the disk
m_pStorage->m_pFile->SetLength(m_info.m_uBytesBeforeZip + m_info.m_uOffset);
// We can now abort safely
iAborted = CZipException::abortedSafely;
}
else
iAborted = CZipException::abortedAction;
break;
}
}
if (pCallback)
pCallback->CallbackEnd();
if (iAborted)
ThrowError(iAborted);
}
DWORD CZipCentralDir::WriteCentralEnd()
{
DWORD uSize = GetSize();
CZipAutoBuffer buf(uSize);
WORD uCommentSize = (WORD)m_pszComment.GetSize();
memcpy(buf, m_gszSignature, 4);
memcpy(buf + 4, &m_info.m_uThisDisk, 2);
memcpy(buf + 6, &m_info.m_uDiskWithCD, 2);
memcpy(buf + 8, &m_info.m_uDiskEntriesNo, 2);
memcpy(buf + 10, &m_info.m_uEntriesNumber, 2);
memcpy(buf + 12, &m_info.m_uSize, 4);
memcpy(buf + 16, &m_info.m_uOffset, 4);
memcpy(buf + 20, &uCommentSize, 2);
memcpy(buf + 22, m_pszComment, uCommentSize);
m_pStorage->Write(buf, uSize, true);
return uSize;
}
void CZipCentralDir::RemoveAll()
{
m_findarray.RemoveAll();
RemoveHeaders();
}
void CZipCentralDir::RemoveFile(CZipFileHeader* pHeader, int iIndex, bool bShift)
{
if (iIndex == -1)
{
int iCount = m_headers.GetSize();
for (int i = 0; i < iCount; i++)
if (pHeader == m_headers[i])
{
iIndex = i;
break;
}
}
ASSERT(iIndex != -1 || pHeader);
if (!pHeader)
pHeader = m_headers[iIndex];
if (m_bFindFastEnabled)
{
int i = FindFileNameIndex(pHeader->GetFileName());
ASSERT(i != -1);
int uIndex = m_findarray[i].m_uIndex;
m_findarray.RemoveAt(i);
// shift down the indexes
if (bShift)
{
int iSize = m_findarray.GetSize();
for (int j = 0; j < iSize; j++)
{
if (m_findarray[j].m_uIndex > uIndex)
m_findarray[j].m_uIndex--;
}
}
}
if (iIndex != -1)
{
delete pHeader;
m_headers.RemoveAt(iIndex);
}
}
DWORD CZipCentralDir::GetSize(bool bWhole) const
{
DWORD uHeaders = 0;
int iCount = m_headers.GetSize();
if (bWhole)
{
for (int i = 0; i < iCount; i++)
{
const CZipFileHeader* pHeader = m_headers[i];
uHeaders += pHeader->GetSize();
}
}
return CENTRALDIRSIZE + m_pszComment.GetSize() + uHeaders;
}
bool CZipCentralDir::RemoveDataDescr(bool bFromBuffer)
{
ziparchv::CZipFileMapping fm;
char* pFile;
DWORD uSize;
if (bFromBuffer)
{
uSize = m_pStorage->m_uBytesInWriteBuffer;
pFile = m_pStorage->m_pWriteBuffer;
}
else
{
uSize = m_pStorage->m_pFile->GetLength();
// we cannot use CZipMemFile in multidisk archive
// so it MUST be CZipFile
if (!fm.CreateMapping(static_cast<CZipFile*>(m_pStorage->m_pFile)))
return false;
pFile = fm.GetMappedMemory();
}
DWORD uOffsetToChange = 4;
DWORD uPosInBuffer = 0;
DWORD uExtraHeaderLen;
int iCount = m_headers.GetSize();
for (int i = 0; i < iCount; i++)
{
// update the flag value in the local and central header
// int uDataDescr = (m_headers[i]->m_uFlag & 8) ? (4 + 12) : 0;
CZipFileHeader* pHeader = m_headers[i];
char* pSour = pFile + pHeader->m_uOffset;
if (!pHeader->IsEncrypted())
{
// removing data descriptor
pHeader->m_uFlag &= ~8;
// update local header:
// write modified flag in the local header
memcpy(pSour + 6, &pHeader->m_uFlag, 2);
uExtraHeaderLen = 4/*ext. header signature*/ + 12/*data descriptor*/;
}
else
// do not remove data descriptors from encrypted files
uExtraHeaderLen = 0;
// update crc32 and sizes' values
pHeader->GetCrcAndSizes(pSour+ 14);
DWORD uToCopy = (i == (iCount - 1) ? uSize : m_headers[i + 1]->m_uOffset)
- pHeader->m_uOffset - uExtraHeaderLen;
memmove(pFile + uPosInBuffer, pSour, uToCopy);
uPosInBuffer += uToCopy;
pHeader->m_uOffset -= uOffsetToChange;
uOffsetToChange += uExtraHeaderLen;
}
if (bFromBuffer)
m_pStorage->m_uBytesInWriteBuffer = uPosInBuffer;
else
{
m_pStorage->m_iBytesWritten = uPosInBuffer;
fm.RemoveMapping();
m_pStorage->m_pFile->SetLength(uPosInBuffer);
}
return true;
}
void CZipCentralDir::RemoveHeaders()
{
int iCount = m_headers.GetSize();
for (int i = 0; i < iCount; i++)
delete m_headers[i];
m_headers.RemoveAll();
}
void CZipCentralDir::ConvertAll()
{
ASSERT(!m_bConvertAfterOpen);
int iCount = m_headers.GetSize();
for (int i = 0; i < iCount; i++)
ConvertFileName(true, false, m_headers[i]);
m_bConvertAfterOpen = true;
}
void CZipCentralDir::BuildFindFastArray( bool bCaseSensitive )
{
m_findarray.RemoveAll();
m_bCaseSensitive = bCaseSensitive;
m_pCompare = GetCZipStrCompFunc(bCaseSensitive);
int iCount = m_headers.GetSize();
if (!m_bConvertAfterOpen)
{
for (int i = 0; i < iCount; i++)
{
CZipFileHeader fh = *m_headers[i];
ConvertFileName(true, false, &fh);
InsertFindFastElement(&fh, i); // this method requires the name to be already converted
}
}
else
for (int i = 0; i < iCount; i++)
InsertFindFastElement(m_headers[i], i);
}
void CZipCentralDir::EnableFindFast(bool bEnable, bool bCaseSensitive)
{
if (m_bFindFastEnabled == bEnable)
return;
m_bFindFastEnabled = bEnable;
if (bEnable)
BuildFindFastArray(bCaseSensitive);
else
m_findarray.RemoveAll();
}
int CZipCentralDir::FindFile(LPCTSTR lpszFileName, bool bCaseSensitive, bool bSporadically, bool bFileNameOnly)
{
// this is required for fast finding and is done only once
if (!m_bConvertAfterOpen)
{
TRACE(_T("%s(%i) : Converting all the filenames.\n"),__FILE__,__LINE__);
ConvertAll();
}
if (!m_bFindFastEnabled)
EnableFindFast(true, bSporadically ? !bCaseSensitive : bCaseSensitive);
int iResult = -1;
if (bFileNameOnly)
{
// a non-effective search (treat an array as unsorted)
int iSize = m_findarray.GetSize();
for (int i = 0; i < iSize; i++)
{
CZipString sz = GetProperHeaderFileName(m_findarray[i].m_pHeader);
CZipPathComponent::RemoveSeparators(sz); // to find a dir
CZipPathComponent zpc(sz);
sz = zpc.GetFileName();
if ((sz.*m_pCompare)(lpszFileName) == 0)
{
iResult = i;
break;
}
}
}
else if (bCaseSensitive == m_bCaseSensitive)
iResult = FindFileNameIndex(lpszFileName);
else
{
if (bSporadically)
{
// a non-effective search (treat an array as unsorted)
int iSize = m_findarray.GetSize();
for (int i = 0; i < iSize; i++)
if (CompareElement(lpszFileName, (WORD)i) == 0)
{
iResult = i;
break;
}
}
else
{
BuildFindFastArray(bCaseSensitive);
iResult = FindFileNameIndex(lpszFileName);
}
}
return iResult == -1 ? -1 : m_findarray[iResult].m_uIndex;
}
void CZipCentralDir::InsertFindFastElement(CZipFileHeader* pHeader, WORD uIndex)
{
CZipString fileName = pHeader->GetFileName();
int iSize = m_findarray.GetSize();
// Our initial binary search range encompasses the entire array of filenames:
int start = 0;
int end = iSize;
// Keep halving our search range until we find the right place
// to insert the new element:
while ( start < end )
{
// Find the midpoint of the search range:
int midpoint = ( start + end ) / 2;
// Compare the filename with the filename at the midpoint of the current search range:
int result = CompareElement(fileName, (WORD)midpoint);
// If our filename is larger, it must fall in the first half of the search range:
if ( result > 0 )
{
end = midpoint;
}
// If it's smaller, it must fall in the last half:
else if ( result < 0 )
{
start = midpoint + 1;
}
// If they're equal, we can go ahead and insert here:
else
{
start = midpoint; break;
}
}
m_findarray.InsertAt(start, CZipFindFast(pHeader, WORD(uIndex == WORD(-1) ? iSize : uIndex /* just in case */)));
}
int CZipCentralDir::FindFileNameIndex(LPCTSTR lpszFileName) const
{
int start = 0;
int end = m_findarray.GetUpperBound();
// Keep halving our search range until we find the given element:
while ( start <= end )
{
// Find the midpoint of the search range:
int midpoint = ( start + end ) / 2;
// Compare the given filename with the filename at the midpoint of the search range:
int result = CompareElement(lpszFileName, (WORD)midpoint);
// If our filename is smaller, it must fall in the first half of the search range:
if ( result > 0 )
{
end = midpoint - 1;
}
// If it's larger, it must fall in the last half:
else if ( result < 0 )
{
start = midpoint + 1;
}
// If they're equal, return the result:
else
{
return midpoint;
}
}
// Signal failure:
return -1;
}
void CZipCentralDir::RenameFile(WORD uIndex, LPCTSTR lpszNewName)
{
CZipFileHeader* pHeader = m_headers[uIndex];
pHeader->SetFileName(lpszNewName);
if (!m_bConvertAfterOpen)
ZipCompatibility::FileNameUpdate(*pHeader, false);
if (m_bFindFastEnabled)
BuildFindFastArray(m_bCaseSensitive);
}

View File

@@ -1,586 +0,0 @@
/*
* $Id$
*/
/*
* Harbour Project source code:
* Zlib low level interface for Harbour
*
* Copyright 2000-2001 Luiz Rafael Culik <culik@sl.conex.net>
* www - http://www.harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
#define HB_OS_WIN_32_USED
#include "hbzip2.h"
extern PHB_ITEM pArray;
PHB_ITEM pDiskStatus=NULL;
PHB_ITEM pProgressInfo=NULL;
int iTotal=0;
CZipMemFile mf;
#ifdef __cplusplus
extern "C" {
#endif
extern HB_ZIP_INTERNAL pZipI;
bool hb_SetProgressofTdSpan(DWORD , int iSoFar, void* pData);
int hb_CompressFile(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress)
{
uLong uiCount;
uLong uiPos;
char szNewFile[MAXFILENAME];
int iCause;
BOOL bFileExist=hb_fsFile((BYTE*)szFile);
CZipArchive szZip;
BOOL bReturn = true;
DWORD dwSize;
if (szPassWord != NULL){
szZip.SetPassword(szPassWord);
}
try {
if (bFileExist && bOverWrite){
szZip.Open(szFile,CZipArchive::zipCreate,0);
}
else{
if (!bFileExist) {
szZip.Open(szFile,CZipArchive::zipCreate,0);
}
else {
szZip.Open(szFile,CZipArchive::zipOpen,0);
}
}
}
catch (CZipException* e)
{
iCause=e->m_iCause ;
bReturn=false;
}
catch(...){}
if (pZipI.szComment != NULL){
szZip.SetGlobalComment(pZipI.szComment);
hb_xfree(pZipI.szComment);
}
if (HB_IS_BLOCK(pProgress))
pProgressInfo=pProgress;
for (uiCount=1;(uiCount<= hb_arrayLen(pArray)) ;uiCount++)
{
const char *szDummy = (char *)hb_arrayGetCPtr(pArray,uiCount) ;
dwSize=GetCurrentFileSize(szDummy);
uiPos=uiCount;
if(pBlock !=NULL){
PHB_ITEM pFileName=hb_itemPutC(NULL,hb_arrayGetCPtr(pArray,uiCount));
PHB_ITEM pFilePos=hb_itemPutNI(NULL,uiCount);
hb_vmEvalBlockV( pBlock, 2, pFileName, pFilePos );
hb_itemRelease(pFileName);
hb_itemRelease(pFilePos);
}
try {
if (szPassWord != NULL){
szZip.SetPassword(szPassWord);
}
if (uiPos== hb_arrayLen(pArray))
iTotal+=dwSize;
if (!HB_IS_BLOCK(pProgress))
{
#if defined(HB_OS_WIN_32) || defined(__MINGW32__)
if (bDrive)
szZip.AddNewFileDrv(szDummy, iCompLevel, true,NULL,NULL,65536);
#endif
if (bPath)
szZip.AddNewFile(szDummy, iCompLevel, true,NULL,NULL,65536);
if (!bDrive && !bPath)
szZip.AddNewFile(szDummy, iCompLevel, false,NULL,NULL,65536);
}
else
{
#if defined(HB_OS_WIN_32) || defined(__MINGW32__)
if (bDrive)
szZip.AddNewFileDrv(szDummy, iCompLevel, true,hb_SetProgressofTdSpan,&(PHB_ITEM)pProgress,65536);
#endif
if (bPath)
szZip.AddNewFile(szDummy, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536);
if (!bDrive && !bPath)
szZip.AddNewFile(szDummy, iCompLevel, false,hb_SetProgressofTdSpan,&pProgress,65536);
}
/* iTotal+=dwSize;*/
if (uiPos== hb_arrayLen(pArray))
iTotal-=dwSize;
else
iTotal+=dwSize;
}
catch(...){}
}
try {
szZip.Close();
}
catch (CZipException* e)
{
iCause=e->m_iCause ;
bReturn=false;
}
catch(...){}
if (pProgressInfo)
hb_itemRelease(pProgressInfo );
return bReturn; /* to avoid warning */
}
int hb_CmpTdSpan(char *szFile,PHB_ITEM pArray,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress)
{
uLong uiCount;
char szNewFile[MAXFILENAME];
CZipArchive szZip;
int iCause;
BOOL bReturn=true;
uLong uiPos;
BOOL bFileExist=hb_fsFile((BYTE*)szFile);
DWORD dwSize;
if (pDiskBlock !=NULL){
pDiskStatus=pDiskBlock;
}
if (szPassWord != NULL){
szZip.SetPassword(szPassWord);
}
if (iSpanSize ==0) {
iSpanSize=1457664;
}
/*
try {
szZip.Open(szFile,CZipArchive::zipCreateSpan,iSpanSize);
}
*/
try {
if (bFileExist && bOverWrite){
szZip.Open(szFile,CZipArchive::zipCreateSpan,iSpanSize);
}
else{
if (!bFileExist) {
szZip.Open(szFile,CZipArchive::zipCreateSpan,iSpanSize);
}
else {
iCause=0;
bReturn=false;
return bReturn;
}
}
}
catch (CZipException* e)
{
iCause=e->m_iCause ;
bReturn=false;
}
catch(...){}
if (pZipI.szComment != NULL){
szZip.SetGlobalComment(pZipI.szComment);
hb_xfree(pZipI.szComment);
}
if (HB_IS_BLOCK(pProgress))
pProgressInfo=pProgress;
for (uiCount=1;(uiCount<= hb_arrayLen(pArray)) ;uiCount++)
{
const char *szDummy = (char *)hb_arrayGetCPtr(pArray,uiCount) ;
dwSize=GetCurrentFileSize(szDummy);
uiPos=uiCount;
if(pBlock !=NULL){
PHB_ITEM pFileName=hb_itemPutC(NULL,hb_arrayGetCPtr(pArray,uiCount));
PHB_ITEM pFilePos=hb_itemPutNI(NULL,uiCount);
hb_vmEvalBlockV( pBlock, 2, pFileName, pFilePos );
hb_itemRelease(pFileName);
hb_itemRelease(pFilePos);
}
try {
if (szPassWord != NULL){
szZip.SetPassword(szPassWord);
}
if (uiPos== hb_arrayLen(pArray))
iTotal+=dwSize;
if (!HB_IS_BLOCK(pProgress))
{
#if defined(HB_OS_WIN_32) || defined(__MINGW32__)
if (bDrive)
szZip.AddNewFileDrv(szDummy, iCompLevel, true,NULL,NULL,65536);
#endif
if (bPath)
szZip.AddNewFile(szDummy, iCompLevel, true,NULL,NULL,65536);
if (!bDrive && !bPath)
szZip.AddNewFile(szDummy, iCompLevel, false,NULL,NULL,65536);
}
else
{
#if defined(HB_OS_WIN_32) || defined(__MINGW32__)
if (bDrive)
szZip.AddNewFileDrv(szDummy, iCompLevel, true,hb_SetProgressofTdSpan,&(PHB_ITEM)pProgress,65536);
#endif
if (bPath)
szZip.AddNewFile(szDummy, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536);
if (!bDrive && !bPath)
szZip.AddNewFile(szDummy, iCompLevel, false,hb_SetProgressofTdSpan,&pProgress,65536);
}
if (uiPos== hb_arrayLen(pArray))
iTotal-=dwSize;
else
iTotal+=dwSize;
}
catch(...){}
}
try {
szZip.Close();
}
catch (CZipException* e)
{
iCause=e->m_iCause ;
bReturn=false;
}
catch(...){}
pDiskStatus=NULL ;
if (pProgressInfo)
hb_itemRelease(pProgressInfo );
return bReturn; /* to avoid warning */
}
/*
bool hb_SetProgressofTdSpan(DWORD , int iSoFar, void* pData){
int iReturn=1;
iSoFar+=iTotal;
PHB_ITEM pDisk;
pDisk= hb_itemPutNL(NULL,iTotal);
hb_vmEvalBlockV( pProgressInfo, 1,pDisk );
hb_itemRelease(pDisk);
return iReturn;
}
*/
bool hb_SetProgressofTdSpan(DWORD a, int iSoFar, void* pData){
int iReturn=1;
PHB_ITEM pDisk;
PHB_ITEM pTotal =hb_itemPutNL(NULL,a);
HB_SYMBOL_UNUSED( pData );
pDisk= hb_itemPutNL(NULL,iSoFar);
hb_vmEvalBlockV( pProgressInfo, 2,pDisk,pTotal);
hb_itemRelease(pDisk);
hb_itemRelease(pTotal);
return iReturn;
}
int hb_CompressFileStd(char *szFile,char *szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress)
{
uLong uiCount;
char szNewFile[MAXFILENAME];
int iCause;
BOOL bFileExist=hb_fsFile((BYTE*)szFile);
BOOL bReturn=true;
DWORD dwSize;
CZipArchive szZip;
if (szPassWord != NULL){
szZip.SetPassword(szPassWord);
}
try {
if (bFileExist && bOverWrite){
szZip.Open(szFile,CZipArchive::zipCreate,0);
}
else{
if (!bFileExist) {
szZip.Open(szFile,CZipArchive::zipCreate,0);
}
else {
szZip.Open(szFile,CZipArchive::zipOpen,0);
}
}
}
catch (CZipException* e)
{
iCause=e->m_iCause ;
bReturn=false;
}
if (pZipI.szComment != NULL){
szZip.SetGlobalComment(pZipI.szComment);
hb_xfree(pZipI.szComment);
}
if (HB_IS_BLOCK(pProgress))
pProgressInfo=pProgress;
try {
dwSize=GetCurrentFileSize(szFiletoCompress);
if (szPassWord != NULL){
szZip.SetPassword(szPassWord);
}
if(pBlock !=NULL){
PHB_ITEM pFileName=hb_itemPutC(NULL,szFiletoCompress );
hb_vmEvalBlockV( pBlock, 1, pFileName );
hb_itemRelease(pFileName);
}
if (!HB_IS_BLOCK(pProgress))
{
#if defined(HB_OS_WIN_32) || defined(__MINGW32__)
if (bDrive)
szZip.AddNewFileDrv((const char*)szFiletoCompress, iCompLevel, true,NULL,NULL,65536);
#endif
if (bPath)
szZip.AddNewFile((const char*)szFiletoCompress, iCompLevel, true,NULL,NULL,65536);
if (!bDrive && !bPath)
szZip.AddNewFile((const char*)szFiletoCompress, iCompLevel, false,NULL,NULL,65536);
}
else {
#if defined(HB_OS_WIN_32) || defined(__MINGW32__)
if (bDrive)
szZip.AddNewFileDrv((const char*)szFiletoCompress, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536);
#endif
if (bPath)
szZip.AddNewFile((const char*)szFiletoCompress, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536);
if (!bDrive && !bPath)
szZip.AddNewFile((const char*)szFiletoCompress, iCompLevel, false,hb_SetProgressofTdSpan,&pProgress,65536);
}
iTotal+=dwSize;
}
catch(...){}
try {
szZip.Close();
}
catch (CZipException* e)
{
iCause=e->m_iCause ;
bReturn=false;
}
catch(...){}
if (pProgressInfo)
hb_itemRelease(pProgressInfo );
return bReturn; /* to avoid warning */
}
int hb_CmpTdSpanStd(char *szFile,char * szFiletoCompress,int iCompLevel,PHB_ITEM pBlock,BOOL bOverWrite,char *szPassWord,PHB_ITEM pDiskBlock,int iSpanSize,BOOL bPath,BOOL bDrive,PHB_ITEM pProgress)
{
uLong uiCount;
char szNewFile[MAXFILENAME];
CZipArchive szZip;
int iCause;
BOOL bReturn=true;
DWORD dwSize;
BOOL bFileExist=hb_fsFile((BYTE*)szFile);
if (pDiskBlock !=NULL){
pDiskStatus=pDiskBlock;
}
if (szPassWord != NULL){
szZip.SetPassword(szPassWord);
}
if (iSpanSize ==0) {
iSpanSize=1457664;
}
try {
if (bFileExist && bOverWrite){
szZip.Open(szFile,CZipArchive::zipCreateSpan,iSpanSize);
}
else{
if (!bFileExist) {
szZip.Open(szFile,CZipArchive::zipCreateSpan,iSpanSize);
}
else {
iCause=0;
return false;
}
}
}
catch (CZipException& e)
{
iCause=e.m_iCause ;
}
catch(...){}
if (pZipI.szComment != NULL){
szZip.SetGlobalComment(pZipI.szComment);
hb_xfree(pZipI.szComment);
}
if (HB_IS_BLOCK(pProgress))
pProgressInfo=pProgress;
try {
if (szPassWord != NULL){
szZip.SetPassword(szPassWord);
}
dwSize=GetCurrentFileSize(szFiletoCompress);
if(pBlock !=NULL){
PHB_ITEM pFileName=hb_itemPutC(NULL,szFiletoCompress );
hb_vmEvalBlockV( pBlock, 1, pFileName );
hb_itemRelease(pFileName);
}
if (!HB_IS_BLOCK(pProgress))
{
#if defined(HB_OS_WIN_32) || defined(__MINGW32__)
if (bDrive)
szZip.AddNewFileDrv((const char*) szFiletoCompress, iCompLevel, true,NULL,NULL,65536);
#endif
if (bPath)
szZip.AddNewFile((const char*) szFiletoCompress, iCompLevel, true,NULL,NULL,65536);
if (!bDrive && !bPath)
szZip.AddNewFile((const char*) szFiletoCompress, iCompLevel, false,NULL,NULL,65536);
}
else {
#if defined(HB_OS_WIN_32) || defined(__MINGW32__)
if (bDrive)
szZip.AddNewFileDrv((const char*) szFiletoCompress, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536);
#endif
if (bPath)
szZip.AddNewFile((const char*) szFiletoCompress, iCompLevel, true,hb_SetProgressofTdSpan,&pProgress,65536);
if (!bDrive && !bPath)
szZip.AddNewFile((const char*) szFiletoCompress, iCompLevel, false,hb_SetProgressofTdSpan,&pProgress,65536);
}
iTotal+=dwSize;
}
catch(...){}
try {
szZip.Close();
}
catch (CZipException& e)
{
iCause=e.m_iCause ;
bReturn=false;
}
catch(...){}
pDiskStatus=NULL ;
if (pProgressInfo)
hb_itemRelease(pProgressInfo );
return bReturn; /* to avoid warning */
}
BOOL hb_CreateZipInMemory(char *szFileToCompress,char *szFile)
{
BOOL bReturn=FALSE;
CZipArchive zip;
CZipMemFile mf1;
CZipFile f;
zip.Open(mf1, CZipArchive::zipCreate);
zip.AddNewFile(szFileToCompress, 8, true,NULL,NULL,65536);
zip.Close();
if (szFile !=NULL)
{
if (f.Open(szFile, CZipFile::modeWrite|CZipFile::modeCreate, false))
{
int iLen = mf1.GetLength();
BYTE* b = mf1.Detach();
f.Write(b, iLen);
f.Close();
// must free detached memory
free(b);
bReturn=true;
}
}
return bReturn;
}
BOOL hb_SaveZipFileFromMemory(char *szFile)
{
CZipArchive zip;
CZipFile f;
BOOL bReturn=FALSE;
if (f.Open(szFile, CZipFile::modeWrite|CZipFile::modeCreate, false))
{
int iLen = mf.GetLength();
BYTE* b = mf.Detach();
f.Write(b, iLen);
f.Close();
// must free detached memory
free(b);
bReturn=TRUE;
}
return bReturn;
}
#if defined(HB_OS_WIN_32) || defined(__MINGW32__)
DWORD GetCurrentFileSize( LPCTSTR szFile)
{
DWORD dwFlags=FILE_ATTRIBUTE_ARCHIVE;
HANDLE hFind;
WIN32_FIND_DATA hFilesFind;
hFind = FindFirstFile(szFile,&hFilesFind);
if (hFind != INVALID_HANDLE_VALUE){
if (dwFlags & hFilesFind.dwFileAttributes) {
if(hFilesFind.nFileSizeHigh>0)
return ((hFilesFind.nFileSizeHigh*MAXDWORD)+hFilesFind.nFileSizeLow);
else
return (hFilesFind.nFileSizeLow);
}
}
FindClose(hFind);
return -1;
}
#endif
#ifdef __cplusplus
}
#endif

View File

@@ -1,214 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipCompatibility.cpp $
// $Archive: /ZipArchive/ZipCompatibility.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipcompatibility.h"
#include "zipplatform.h"
#include "zipexception.h"
#include "zipautobuffer.h"
#include "zipfileheader.h"
enum iInternalAttr
{
attROnly = 0x01,
attHidd = 0x02,
attSys = 0x04,
attDir = 0x10,
attArch = 0x20
};
// *********************** WINDOWS **************************
#ifndef _WIN32
#define FILE_ATTRIBUTE_READONLY 0x00000001
#define FILE_ATTRIBUTE_HIDDEN 0x00000002
#define FILE_ATTRIBUTE_SYSTEM 0x00000004
#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
#endif
// *********************** UINX **************************
#define USER_PERMISSIONS_MASK 0x01C00000
#define EXTRACT_USER_PERMISSIONS(x) ((x & USER_PERMISSIONS_MASK) >> 22)
#define CREATE_USER_PERMISSIONS(x) ((x & 0x0007) << 22)
#define GROUP_PERMISSIONS_MASK 0x00380000
#define EXTRACT_GROUP_PERMISSIONS ((x & GROUP_PERMISSIONS_MASK) >> 19)
#define CREATE_GROUP_PERMISSIONS(x) ((x & 0x0007) << 19)
#define OTHER_PERMISSIONS_MASK 0x00070000
#define EXTRACT_OTHER_PERMISSIONS ((x & OTHER_PERMISSIONS_MASK) >> 16)
#define CREATE_OTHER_PERMISSIONS(x) ((x & 0x0007) << 16)
#define UNIX_DIRECTORY_ATTRIBUTE 0x40000000
#define UNIX_FILE_ATTRIBUTE 0x80000000
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
using namespace ZipCompatibility;
typedef DWORD(*conv_func)(DWORD , bool );
DWORD AttrDos(DWORD , bool );
DWORD AttrUnix(DWORD, bool);
DWORD AttrMac(DWORD , bool );
// more to come...
conv_func conv_funcs[11] = {AttrDos,
NULL,
NULL,
AttrUnix,
NULL,
NULL,
AttrDos,
AttrMac,
NULL,
NULL,
AttrDos
};
DWORD ZipCompatibility::ConvertToSystem(DWORD uAttr, int iFromSystem, int iToSystem)
{
if (iToSystem != iFromSystem && iFromSystem < 11 && iToSystem < 11)
{
conv_func p = conv_funcs[iFromSystem], q = conv_funcs[iToSystem];
if (p && q)
uAttr = q( p(uAttr, true), false);
else
CZipException::Throw(CZipException::platfNotSupp);
}
return uAttr;
}
DWORD AttrDos(DWORD uAttr, bool )
{
return uAttr;
}
DWORD AttrUnix(DWORD uAttr, bool bFrom)
{
DWORD uNewAttr = 0;
if (bFrom)
{
if (uAttr & UNIX_DIRECTORY_ATTRIBUTE)
uNewAttr = attDir;
uAttr = EXTRACT_USER_PERMISSIONS (uAttr);
// we may set archive attribute if the file hasn't the execute permissions
//
if (!(uAttr & 1))
uNewAttr |= attArch ;
if (!(uAttr & 2))
uNewAttr |= attROnly;
if (!(uAttr & 4))
uNewAttr |= attHidd;
}
else
{
uNewAttr = 0; // we cannot assume that if the file hasn't the archive attribute set
//then it is executable and set execute permissions
if (!(uAttr & attHidd))
uNewAttr |= (CREATE_OTHER_PERMISSIONS (4) |
CREATE_GROUP_PERMISSIONS (4))
| CREATE_USER_PERMISSIONS (4);
if (!(uAttr & attROnly))
uNewAttr |= (CREATE_GROUP_PERMISSIONS (2) |
CREATE_USER_PERMISSIONS (2));
if (uAttr & attDir)
uNewAttr |= UNIX_DIRECTORY_ATTRIBUTE | attDir;
else
uNewAttr |= UNIX_FILE_ATTRIBUTE;
}
return uNewAttr;
}
DWORD AttrMac(DWORD uAttr, bool )
{
DWORD uNewAttr = uAttr & (attDir | attROnly);
// if (bFrom)
// {
//
// }
// else
// {
//
// }
return uNewAttr;
}
// ************************************************************************
ZIPINLINE bool ZipCompatibility::IsPlatformSupported(int iCode)
{
return iCode == zcDosFat || iCode == zcUnix || iCode == zcMacintosh
|| iCode == zcNtfs || iCode == zcOs2Hpfs;
}
void ZipCompatibility::FileNameUpdate(CZipFileHeader& header, bool bFromZip)
{
int iSysHeader = header.GetSystemCompatibility();
int iCurSystem = ZipPlatform::GetSystemID();
if (bFromZip)
{
if (iCurSystem == zcDosFat)
SlashBackslashChg(header.m_pszFileName, true);
if (iSysHeader == zcDosFat)
ZipPlatform::AnsiOem(header.m_pszFileName, false);
}
else
{
if (iSysHeader == zcDosFat)
{
ZipPlatform::AnsiOem(header.m_pszFileName, true);
}
SlashBackslashChg(header.m_pszFileName, false);
}
}
void ZipCompatibility::SlashBackslashChg(CZipAutoBuffer& buffer, bool bReplaceSlash)
{
char t1 = '\\' /*backslash*/, t2 = '/', c1, c2;
if (bReplaceSlash)
{
c1 = t1;
c2 = t2;
}
else
{
c1 = t2;
c2 = t1;
}
for (DWORD i = 0; i < buffer.GetSize(); i++)
{
if (buffer[i] == c2)
buffer[i] = c1;
}
}

View File

@@ -1,280 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipException.cpp $
// $Archive: /ZipArchive/ZipException.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipexception.h"
#include <errno.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#ifdef _MFC_VER
IMPLEMENT_DYNAMIC( CZipException, CException)
#endif
CZipException::CZipException(int iCause, LPCTSTR lpszZipName)
#ifdef _MFC_VER
:CException(TRUE)
#endif
{
m_iCause = iCause;
if (lpszZipName)
m_szFileName = lpszZipName;
}
//CZipException::~CZipException()
#if __GNUC__ >=3
CZipException::~CZipException() throw()
#else
CZipException::~CZipException()
#endif
{
}
// inline void CZipException::Throw(int iZipError, LPCTSTR lpszZipName)
// {
// #ifdef _MFC_VER
// throw new CZipException(iZipError, lpszZipName);
// #else
// CZipException e(iZipError, lpszZipName);
// throw e;
// #endif
// MSVC++: ignore "Unreachable code" warning here, it's due to
// optimizations
// }
int CZipException::ZlibErrToZip(int iZlibError)
{
switch (iZlibError)
{
case 2://Z_NEED_DICT:
return CZipException::needDict;
case 1://Z_STREAM_END:
return CZipException::streamEnd;
case -1://Z_ERRNO:
return CZipException::errNo;
case -2://Z_STREAM_ERROR:
return CZipException::streamError;
case -3://Z_DATA_ERROR:
return CZipException::dataError;
case -4://Z_MEM_ERROR:
return CZipException::memError;
case -5://Z_BUF_ERROR:
return CZipException::bufError;
case -6://Z_VERSION_ERROR:
return CZipException::versionError;
default:
return CZipException::generic;
}
}
#ifdef ZIP_ENABLE_ERROR_DESCRIPTION
BOOL CZipException::GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
UINT* )
{
if (!lpszError || !nMaxError)
return FALSE;
CZipString sz = GetErrorDescription();
if (sz.IsEmpty())
return FALSE;
UINT iLen = sz.GetLength();
if (nMaxError - 1 < iLen)
iLen = nMaxError - 1;
LPTSTR lpsz = sz.GetBuffer(iLen);
#ifdef _UNICODE
wcsncpy(lpszError, lpsz, iLen);
#else
strncpy(lpszError, lpsz, iLen);
#endif
lpszError[iLen] = _T('\0');
return TRUE;
}
CZipString CZipException::GetErrorDescription()
{
return GetInternalErrorDescription(m_iCause);
}
CZipString CZipException::GetSystemErrorDescription()
{
#ifdef WIN32
DWORD x = GetLastError();
if (x)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, x, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL);
CZipString sz = (LPCTSTR)lpMsgBuf;
LocalFree(lpMsgBuf);
return sz;
}
#endif
return GetInternalErrorDescription(errno == 0 ? generic : errno, true);
}
CZipString CZipException::GetInternalErrorDescription(int iCause, bool bNoLoop)
{
CZipString sz;
switch (iCause)
{
case EROFS:
sz = _T("Read-only file system");
break;
case ESPIPE:
sz = _T("Illegal seek");
break;
case ENOSPC:
sz = _T("No space left on device");
break;
case EFBIG:
sz = _T("File too large");
break;
case EMFILE:
sz = _T("Too many open files");
break;
case ENFILE:
sz = _T("File table overflow");
break;
case EINVAL:
sz = _T("Invalid argument");
break;
case EISDIR:
sz = _T("Is a directory");
break;
case ENOTDIR:
sz = _T("Not a directory");
break;
case ENODEV:
sz = _T("No such device");
break;
case EXDEV:
sz = _T("Cross-device link");
break;
case EEXIST:
sz = _T("File exists");
break;
case EFAULT:
sz = _T("Bad address");
break;
case EACCES:
sz = _T("Permission denied");
break;
case ENOMEM:
sz = _T("Not enough space");
break;
case EBADF:
sz = _T("Bad file number");
break;
case ENXIO:
sz = _T("No such device or address");
break;
case EIO:
sz = _T("I/O error");
break;
case EINTR:
sz = _T("Interrupted system call");
break;
case ENOENT:
sz = _T("No such file or directory");
break;
case EPERM:
sz = _T("Not super-user");
break;
case badZipFile:
sz = _T("Damaged or not a zip file");
break;
case badCrc:
sz = _T("Crc mismatched");
break;
case noCallback:
sz = _T("No disk-spanning callback functor set");
break;
case aborted:
sz = _T("Disk change aborted");
break;
case abortedAction:
sz = _T("Action aborted");
break;
case abortedSafely:
sz = _T("Action aborted safely");
break;
case nonRemovable:
sz = _T("The device selected for the disk spanning archive is non removable");
break;
case tooManyVolumes:
sz = _T("Limit of the maximum volumes reached (999)");
break;
case tooLongFileName:
sz = _T("The filename of the file being added to the archive is too long");
break;
case badPassword:
sz = _T("Incorrect password set for the file being decrypted");
break;
case dirWithSize:
sz = _T("During testing found the directory with the size greater than 0");
break;
case internal:
sz = _T("Internal error");
break;
case notRemoved:
sz.Format(_T("%s (%s)"), _T("Error while removing a file"), (LPCTSTR)GetSystemErrorDescription());
break;
case notRenamed:
sz.Format(_T("%s (%s)"), _T("Error while renaming a file"), (LPCTSTR)GetSystemErrorDescription());
break;
case platfNotSupp:
sz = _T("Cannot create the file for the specified platform");
break;
case cdirNotFound:
sz = _T("The central directory was not found in the archive (or you were trying to open not the last disk of a multi-disk archive)");
break;
case streamEnd:
sz = _T("Zlib Library error (end of stream)");
break;
case errNo:
sz = GetInternalErrorDescription(errno != errNo ? errno : generic);
break;
case streamError:
sz = _T("Zlib library error (stream error)");
break;
case dataError:
sz = _T("Zlib library error (data error)");
break;
case memError:
sz = _T("Not enough memory");
break;
case bufError:
sz = _T("Zlib library error (buffer error)");
break;
case versionError:
sz = _T("Zlib library error (version error)");
break;
default:
sz = bNoLoop ? _T("Unknown error") :(LPCTSTR) GetSystemErrorDescription();
}
return sz;
}
#endif //ZIP_ENABLE_ERROR_DESCRIPTION

View File

@@ -1,114 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipFile.cpp $
// $Archive: /ZipArchive_STL/ZipFile.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipfile.h"
#include "zipexception.h"
#include "zipplatform.h"
#include <fcntl.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CZipFile::CZipFile()
{
m_hFile = -1;
}
void CZipFile::ThrowError() const
{
CZipException::Throw(errno, m_szFileName);
}
ZIP_ULONGLONG CZipFile::GetLength() const
{
// cannot use Seek here, Seek is not const
long lLen, lCur;
lCur = lseek(m_hFile, 0, current);
if (lCur == -1)
ThrowError();
lLen = lseek(m_hFile, 0, end);
// first get back
lseek(m_hFile, lCur, begin);
if (lLen == -1)
ThrowError();
return lLen;
}
bool CZipFile::Open(LPCTSTR lpszFileName, UINT openFlags, bool bThrow)
{
if (!IsClosed())
Close();
#ifndef __GNUC__
UINT iNewFlags = O_BINARY;
#else
UINT iNewFlags = 0;
#endif
bool bReadOnly = false;
if (openFlags & CZipFile::modeCreate)
iNewFlags |= O_CREAT;
if ((openFlags & CZipFile::modeReadWrite) == CZipFile::modeReadWrite)
iNewFlags |= O_RDWR;
else if (openFlags & CZipFile::modeRead)
{
// O_RDONLY is defined as 0
bReadOnly = true;
iNewFlags |= O_RDONLY;
}
else if (openFlags & CZipFile::modeWrite)
iNewFlags |= O_WRONLY;
if (!(openFlags & CZipFile::modeNoTruncate) && !bReadOnly)
iNewFlags |= O_TRUNC;
m_hFile = ZipPlatform::OpenFile(lpszFileName, iNewFlags, openFlags & 0x1C);
if (m_hFile == -1)
if (bThrow)
ThrowError();
else
return false;
m_szFileName = lpszFileName;
return true;
}
void CZipFile::SetLength(ZIP_ULONGLONG nNewLen)
{
ZipPlatform::TruncateFile(m_hFile, (DWORD)nNewLen);
}
void CZipFile::Flush()
{
if (!ZipPlatform::FlushFile(m_hFile))
ThrowError();
}
CZipFile::operator HANDLE()
{
int fh = ZipPlatform::GetFileSystemHandle(m_hFile);
if (fh == -1)
ThrowError();
return (HANDLE)fh;
}

View File

@@ -1,340 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipFileHeader.cpp $
// $Archive: /ZipArchive_STL/ZipFileHeader.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipfileheader.h"
#include "zipautobuffer.h"
#include "ziparchive.h"
#include "zipplatform.h"
#include "zipcompatibility.h"
#include <time.h>
#define FILEHEADERSIZE 46
#define LOCALFILEHEADERSIZE 30
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
char CZipFileHeader::m_gszSignature[] = {0x50, 0x4b, 0x01, 0x02};
char CZipFileHeader::m_gszLocalSignature[] = {0x50, 0x4b, 0x03, 0x04};
CZipFileHeader::CZipFileHeader()
{
m_uExternalAttr = 0;//ZipPlatform::GetDefaultAttributes();
m_uModDate = m_uModTime = 0;
m_uMethod = Z_DEFLATED;
// SetSystemCompatibility(ZipPlatform::m_sSystemID);
}
CZipFileHeader::~CZipFileHeader()
{
}
// read the header from the central dir
bool CZipFileHeader::Read(CZipStorage *pStorage)
{
// // just in case
// m_pszComment.Release();
// m_pszFileName.Release();
WORD uFileNameSize, uCommentSize, uExtraFieldSize;
CZipAutoBuffer buf(FILEHEADERSIZE);
pStorage->Read(buf, FILEHEADERSIZE, true);
memcpy(&m_szSignature, buf, 4);
memcpy(&m_uVersionMadeBy, buf + 4, 2);
memcpy(&m_uVersionNeeded, buf + 6, 2);
memcpy(&m_uFlag, buf + 8, 2);
memcpy(&m_uMethod, buf + 10, 2);
memcpy(&m_uModTime, buf + 12, 2);
memcpy(&m_uModDate, buf + 14, 2);
memcpy(&m_uCrc32, buf + 16, 4);
memcpy(&m_uComprSize, buf + 20, 4);
memcpy(&m_uUncomprSize, buf + 24, 4);
memcpy(&uFileNameSize, buf + 28, 2);
memcpy(&uExtraFieldSize, buf + 30, 2);
memcpy(&uCommentSize, buf + 32, 2);
memcpy(&m_uDiskStart, buf + 34, 2);
memcpy(&m_uInternalAttr, buf + 36, 2);
memcpy(&m_uExternalAttr, buf + 38, 4);
memcpy(&m_uOffset, buf + 42, 4);
buf.Release();
if (memcmp(m_szSignature, m_gszSignature, 4) != 0)
return false;
int iCurDsk = pStorage->GetCurrentDisk();
m_pszFileName.Allocate(uFileNameSize); // don't add NULL at the end
pStorage->Read(m_pszFileName, uFileNameSize, true);
if (uExtraFieldSize)
{
ASSERT(!m_pExtraField.IsAllocated());
m_pExtraField.Allocate(uExtraFieldSize);
pStorage->Read(m_pExtraField, uExtraFieldSize, true);
}
if (uCommentSize)
{
m_pszComment.Allocate(uCommentSize);
pStorage->Read(m_pszComment, uCommentSize, true);
}
return pStorage->GetCurrentDisk() == iCurDsk; // check that the whole header is on the one disk
}
time_t CZipFileHeader::GetTime()const
{
struct tm atm;
atm.tm_sec = (m_uModTime & ~0xFFE0) << 1;
atm.tm_min = (m_uModTime & ~0xF800) >> 5;
atm.tm_hour = m_uModTime >> 11;
atm.tm_mday = m_uModDate & ~0xFFE0;
atm.tm_mon = ((m_uModDate & ~0xFE00) >> 5) - 1;
atm.tm_year = (m_uModDate >> 9) + 80;
atm.tm_isdst = -1;
return mktime(&atm);
}
// write the header to the central dir
DWORD CZipFileHeader::Write(CZipStorage *pStorage)
{
WORD uFileNameSize = GetFileNameSize(), uCommentSize = GetCommentSize(),
uExtraFieldSize = GetExtraFieldSize();
DWORD iSize = FILEHEADERSIZE + uFileNameSize + uCommentSize + uExtraFieldSize;
CZipAutoBuffer buf(iSize);
memcpy(buf, &m_szSignature, 4);
memcpy(buf + 4, &m_uVersionMadeBy, 2);
memcpy(buf + 6, &m_uVersionNeeded, 2);
memcpy(buf + 8, &m_uFlag, 2);
memcpy(buf + 10, &m_uMethod, 2);
memcpy(buf + 12, &m_uModTime, 2);
memcpy(buf + 14, &m_uModDate, 2);
memcpy(buf + 16, &m_uCrc32, 4);
memcpy(buf + 20, &m_uComprSize, 4);
memcpy(buf + 24, &m_uUncomprSize, 4);
memcpy(buf + 28, &uFileNameSize, 2);
memcpy(buf + 30, &uExtraFieldSize, 2);
memcpy(buf + 32, &uCommentSize, 2);
memcpy(buf + 34, &m_uDiskStart, 2);
memcpy(buf + 36, &m_uInternalAttr, 2);
memcpy(buf + 38, &m_uExternalAttr, 4);
memcpy(buf + 42, &m_uOffset, 4);
memcpy(buf + 46, m_pszFileName, uFileNameSize);
if (uExtraFieldSize)
memcpy(buf + 46 + uFileNameSize, m_pExtraField, uExtraFieldSize);
if (uCommentSize)
memcpy(buf + 46 + uFileNameSize + uExtraFieldSize, m_pszComment, uCommentSize);
pStorage->Write(buf, iSize, true);
return iSize;
}
bool CZipFileHeader::ReadLocal(CZipStorage *pStorage, WORD& iLocExtrFieldSize)
{
char buf[LOCALFILEHEADERSIZE];
pStorage->Read(buf, LOCALFILEHEADERSIZE, true);
if (memcmp(buf, m_gszLocalSignature, 4) != 0)
return false;
bool bIsDataDescr = (((WORD)*(buf + 6)) & 8) != 0;
WORD uFileNameSize = GetFileNameSize();
WORD uTemp;
memcpy(&uTemp, buf+6, 2); // give the priority to the local flag
if ((uTemp & 0xf) != (m_uFlag & 0xf))
m_uFlag = uTemp;
if ((memcmp(buf + 8, &m_uMethod, 2) != 0)
|| (m_uMethod && (m_uMethod != Z_DEFLATED))
|| (memcmp(buf + 26, &uFileNameSize, 2) != 0))
return false;
// jeszcze mo¿naby porównaæ nazwy plików
if (!bIsDataDescr/* || !pStorage->IsSpanMode()*/)
if (!CheckCrcAndSizes(buf + 14))
return false;
memcpy(&iLocExtrFieldSize, buf + 28, 2);
pStorage->m_pFile->Seek(uFileNameSize, CZipAbstractFile::current);
return true;
}
void CZipFileHeader::SetTime(const time_t & ttime)
{
tm* gt = localtime(&ttime);
WORD year = (WORD)(gt->tm_year + 1900);
if (year <= 1980)
year = 0;
else
year -= 1980;
m_uModDate = (WORD) (gt->tm_mday + ((gt->tm_mon + 1)<< 5) + (year << 9));
m_uModTime = (WORD) ((gt->tm_sec >> 1) + (gt->tm_min << 5) +
(gt->tm_hour << 11));
}
// the buffer contains crc32, compressed and uncompressed sizes to be compared
// with the actual values
bool CZipFileHeader::CheckCrcAndSizes(char *pBuf) const
{
return (memcmp(pBuf, &m_uCrc32, 4) == 0) && (memcmp(pBuf + 4, &m_uComprSize, 4) == 0)
&& (memcmp(pBuf + 8, &m_uUncomprSize, 4) == 0);
}
// write the local header
void CZipFileHeader::WriteLocal(CZipStorage& storage)
{
// extra field is local by now
WORD uFileNameSize = GetFileNameSize(), uExtraFieldSize = GetExtraFieldSize();
DWORD iLocalSize = LOCALFILEHEADERSIZE + uExtraFieldSize + uFileNameSize;
CZipAutoBuffer buf(iLocalSize);
memcpy(buf, m_gszLocalSignature, 4);
memcpy(buf + 4, &m_uVersionNeeded, 2);
memcpy(buf + 6, &m_uFlag, 2);
memcpy(buf + 8, &m_uMethod, 2);
memcpy(buf + 10, &m_uModTime, 2);
memcpy(buf + 12, &m_uModDate, 2);
memcpy(buf + 14, &m_uCrc32, 4);
memcpy(buf + 18, &m_uComprSize, 4);
memcpy(buf + 22, &m_uUncomprSize, 4);
memcpy(buf + 26, &uFileNameSize, 2);
memcpy(buf + 28, &uExtraFieldSize, 2);
memcpy(buf + 30, m_pszFileName, uFileNameSize);
memcpy(buf + 30 + uFileNameSize, m_pExtraField, uExtraFieldSize);
// possible disk change before writing to the file in the disk spanning mode
// so write the local header first
storage.Write(buf, iLocalSize, true);
// it was only local information, use CZipArchive::SetExtraField to set the file extra field in the central directory
m_pExtraField.Release();
m_uDiskStart = (WORD)storage.GetCurrentDisk();
m_uOffset = storage.GetPosition() - iLocalSize;
}
// prepare the data before adding a new file
bool CZipFileHeader::PrepareData(int iLevel, bool bSpan, bool bEncrypted)
{
memcpy(m_szSignature, m_gszSignature, 4);
m_uInternalAttr = 0;
m_uVersionNeeded = IsDirectory() ? 0xa : 0x14; // 1.0 or 2.0
SetVersion((WORD)(0x14));
m_uCrc32 = 0;
m_uComprSize = 0;
m_uUncomprSize = 0;
if (iLevel == 0)
m_uMethod = 0;
if ((m_uMethod != Z_DEFLATED) && (m_uMethod != 0))
m_uMethod = Z_DEFLATED;
m_uFlag = 0;
if (m_uMethod == Z_DEFLATED)
switch (iLevel)
{
case 1:
m_uFlag |= 6;
break;
case 2:
m_uFlag |= 4;
break;
case 8:
case 9:
m_uFlag |= 2;
break;
}
if (bSpan || bEncrypted)
m_uFlag |= 8; // data descriptor present
if (bEncrypted)
{
m_uComprSize = ZIPARCHIVE_ENCR_HEADER_LEN; // encrypted header
m_uFlag |= 1; // encrypted file
}
return !(m_pszComment.GetSize() > USHRT_MAX || m_pszFileName.GetSize() > USHRT_MAX
|| m_pExtraField.GetSize() > USHRT_MAX);
}
void CZipFileHeader::GetCrcAndSizes(char * pBuffer)const
{
memcpy(pBuffer, &m_uCrc32, 4);
memcpy(pBuffer + 4, &m_uComprSize, 4);
memcpy(pBuffer + 8, &m_uUncomprSize, 4);
}
DWORD CZipFileHeader::GetSize(bool bLocal)const
{
if (bLocal)
return LOCALFILEHEADERSIZE + GetExtraFieldSize() + GetFileNameSize();
else
return FILEHEADERSIZE + GetExtraFieldSize() + GetFileNameSize() + GetCommentSize();
}
bool CZipFileHeader::SetComment(LPCTSTR lpszComment)
{
return CZipArchive::WideToSingle(lpszComment, m_pszComment) != -1;
}
CZipString CZipFileHeader::GetComment() const
{
CZipString temp;
CZipArchive::SingleToWide(m_pszComment, temp);
return temp;
}
bool CZipFileHeader::SetFileName(LPCTSTR lpszFileName)
{
return CZipArchive::WideToSingle(lpszFileName, m_pszFileName) != -1;
}
CZipString CZipFileHeader::GetFileName()const
{
CZipString temp;
CZipArchive::SingleToWide(m_pszFileName, temp);
return temp;
}
bool CZipFileHeader::IsDirectory()const
{
return ZipPlatform::IsDirectory(GetSystemAttr());
}
DWORD CZipFileHeader::GetSystemAttr()const
{
int iSystemComp = GetSystemCompatibility();
if (ZipCompatibility::IsPlatformSupported(iSystemComp))
{
if (!m_uExternalAttr && CZipPathComponent::HasEndingSeparator(GetFileName()))
return ZipPlatform::GetDefaultDirAttributes(); // can happen
else
return ZipCompatibility::ConvertToSystem(m_uExternalAttr, iSystemComp, ZipPlatform::GetSystemID());
}
else
return CZipPathComponent::HasEndingSeparator(GetFileName()) ? ZipPlatform::GetDefaultDirAttributes() : ZipPlatform::GetDefaultAttributes();
}
void CZipFileHeader::SetSystemAttr(DWORD uAttr)
{
m_uExternalAttr = ZipCompatibility::ConvertToSystem(uAttr, ZipPlatform::GetSystemID(), GetSystemCompatibility());
}

View File

@@ -1,98 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipMemFile.cpp $
// $Archive: /ZipArchive/ZipMemFile.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipmemfile.h"
#include "zipexception.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
void CZipMemFile::Grow(size_t nGrowTo)
{
if (m_nBufSize < (UINT)nGrowTo)
{
if (m_nGrowBy == 0)
CZipException::Throw(CZipException::memError);
size_t nNewSize = m_nBufSize;
while (nNewSize < nGrowTo)
nNewSize += m_nGrowBy;
BYTE* lpNew;
if (m_lpBuf)
lpNew = (BYTE*)hb_xrealloc((void*) m_lpBuf, nNewSize);
else
lpNew = (BYTE*)hb_xalloc(nNewSize);
if (!lpNew)
CZipException::Throw(CZipException::memError);
m_nBufSize = nNewSize;
m_lpBuf = lpNew;
}
}
void CZipMemFile::SetLength(ZIP_ULONGLONG nNewLen)
{
if (m_nBufSize < (UINT)nNewLen)
Grow((size_t)nNewLen);
else
m_nPos = (size_t)nNewLen;
m_nDataSize = (size_t)nNewLen;
}
UINT CZipMemFile::Read(void *lpBuf, UINT nCount)
{
if (m_nPos > m_nDataSize)
return 0;
UINT nToRead = (m_nPos + nCount > m_nDataSize) ? m_nDataSize - m_nPos : nCount;
memcpy(lpBuf, m_lpBuf + m_nPos, nToRead);
m_nPos += nToRead;
return nToRead;
}
void CZipMemFile::Write(const void *lpBuf, UINT nCount)
{
if (!nCount)
return;
if (m_nPos + nCount > m_nBufSize)
Grow(m_nPos + nCount);
memcpy(m_lpBuf + m_nPos, lpBuf, nCount);
m_nPos += nCount;
if (m_nPos > m_nDataSize)
m_nDataSize = m_nPos;
}
ZIP_ULONGLONG CZipMemFile::Seek(ZIP_LONGLONG lOff, int nFrom)
{
ZIP_ULONGLONG lNew = m_nPos;
if (nFrom == CZipAbstractFile::begin)
lNew = lOff;
else if (nFrom == CZipAbstractFile::current)
lNew += lOff;
else if (nFrom == CZipAbstractFile::end)
lNew = m_nDataSize + lOff;
else
return lNew;
if (lNew< 0)
CZipException::Throw(CZipException::memError);
m_nPos = (size_t)lNew;
return lNew;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,76 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipPathComponent.cpp $
// $Archive: /ZipArchive/ZipPathComponent.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zippathcomponent.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CZipPathComponent::~CZipPathComponent()
{
}
void CZipPathComponent::SetFullPath(LPCTSTR lpszFullPath)
{
TCHAR szDrive[_MAX_DRIVE];
TCHAR szDir[_MAX_DIR];
TCHAR szFname[_MAX_FNAME];
TCHAR szExt[_MAX_EXT];
CZipString szTempPath(lpszFullPath);
const CZipString szPrefix = _T("\\\\?\\unc\\");
int i = -1, iLen = szPrefix.GetLength();
if (iLen > szTempPath.GetLength())
iLen = szTempPath.GetLength();
CZipString szPossiblePrefix = szTempPath.Left(iLen);
szPossiblePrefix.MakeLower(); // must perform case insensitive comparison
while (++i < iLen && szPossiblePrefix[i] == szPrefix[i]);
if (i == 2 || i == 4 || i == 8) // unc path, unicode path or unc path meeting windows file name conventions
{
m_szPrefix = szTempPath.Left(i);
szTempPath = szTempPath.Mid(i);
}
else
m_szPrefix.Empty();
_tsplitpath(szTempPath, szDrive , szDir, szFname, szExt);
m_szDrive = szDrive;
m_szDirectory = szDir;
m_szDirectory.TrimLeft(m_cSeparator);
m_szDirectory.TrimRight(m_cSeparator);
SetExtension(szExt);
m_szFileTitle = szFname;
}
CZipString CZipPathComponent::GetNoDrive() const
{
CZipString szPath = m_szDirectory;
CZipString szFileName = GetFileName();
if (!szFileName.IsEmpty() && !szPath.IsEmpty())
szPath += m_cSeparator;
szPath += szFileName;
return szPath;
}

View File

@@ -1,351 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipPlatform.cpp $
// $Archive: /ZipArchive/ZipPlatform.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipplatform.h"
#include "zipfileheader.h"
#include "zipexception.h"
#include "zipautobuffer.h"
#include <sys/stat.h>
#if defined _MSC_VER && !defined __BORLANDC__ /*_MSC_VER may be defined in Borland after converting the VC project */
#include <sys/utime.h>
#else
#include <utime.h>
#endif
#include <direct.h>
#include <io.h>
#include <time.h>
#include "zippathcomponent.h"
#include "zipcompatibility.h"
const TCHAR CZipPathComponent::m_cSeparator = _T('\\');
#ifndef _UTIMBUF_DEFINED
#define _utimbuf utimbuf
#endif
DWORD ZipPlatform::GetDeviceFreeSpace(LPCTSTR lpszPath)
{
DWORD SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters;
CZipPathComponent zpc (lpszPath);
CZipString szDrive = zpc.GetFileDrive();
if (!GetDiskFreeSpace(
szDrive,
&SectorsPerCluster,
&BytesPerSector,
&NumberOfFreeClusters,
&TotalNumberOfClusters))
{
CZipPathComponent::AppendSeparator(szDrive); // in spite of what is written in MSDN it is sometimes needed (on fixed disks)
if (!GetDiskFreeSpace(
szDrive,
&SectorsPerCluster,
&BytesPerSector,
&NumberOfFreeClusters,
&TotalNumberOfClusters))
return 0;
}
__int64 total = SectorsPerCluster * BytesPerSector * NumberOfFreeClusters;
return (DWORD)total;
}
bool ZipPlatform::GetFileSize(LPCTSTR lpszFileName, DWORD& dSize)
{
HANDLE f = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, 0, NULL);
if (!f)
return false;
DWORD dwSize;
dwSize = ::GetFileSize(f, NULL);
CloseHandle(f);
if (dwSize == 0xFFFFFFFF)
return false;
dSize = dwSize;
return true;
}
CZipString ZipPlatform::GetTmpFileName(LPCTSTR lpszPath, DWORD iSizeNeeded)
{
TCHAR empty[] = _T("");
CZipString tempPath;
bool bCheckTemp = true;
if (lpszPath)
{
tempPath = lpszPath;
bCheckTemp = GetDeviceFreeSpace(tempPath) < iSizeNeeded;
}
if (bCheckTemp)
{
DWORD size = GetTempPath(0, NULL);
if (size == 0)
return empty;
GetTempPath(size, tempPath.GetBuffer(size));
tempPath.ReleaseBuffer();
if (GetDeviceFreeSpace(tempPath) < iSizeNeeded)
{
if (!GetCurrentDirectory(tempPath) || GetDeviceFreeSpace(tempPath) < iSizeNeeded)
return empty;
}
}
CZipString tempName;
if (!GetTempFileName(tempPath, _T("ZAR"), 0, tempName.GetBuffer(_MAX_PATH)))
return empty;
tempName.ReleaseBuffer();
return tempName;
}
bool ZipPlatform::GetCurrentDirectory(CZipString& sz)
{
DWORD i = ::GetCurrentDirectory(0, NULL);
if (!i)
return false;
TCHAR* pBuf = new TCHAR[i];
bool b = true;
if (!::GetCurrentDirectory(i, pBuf))
b = false;
else
sz = pBuf;
delete[] pBuf;
return b;
}
bool ZipPlatform::SetFileAttr(LPCTSTR lpFileName, DWORD uAttr)
{
return ::SetFileAttributes(lpFileName, uAttr) != 0;
}
bool ZipPlatform::GetFileAttr(LPCTSTR lpFileName, DWORD& uAttr)
{
// not using MFC due to MFC bug (attr is one byte there)
DWORD temp = ::GetFileAttributes(lpFileName);
if (temp == ( DWORD )-1)
return false;
uAttr = temp;
return true;
}
bool ZipPlatform::GetFileModTime(LPCTSTR lpFileName, time_t & ttime)
{
#if defined _MSC_VER && !defined __BORLANDC__ /*_MSC_VER may be defined in Borland after converting the VC project */
struct _stat st;
if (_tstat(lpFileName, &st) != 0)
#else
struct stat st;
if (stat(lpFileName, &st) != 0)
#endif
return false;
ttime = st.st_mtime;
return ttime != -1;
}
bool ZipPlatform::SetFileModTime(LPCTSTR lpFileName, time_t ttime)
{
struct _utimbuf ub;
ub.actime = time(NULL);
ub.modtime = ttime == -1 ? time(NULL) : ttime; // if wrong file time, set it to the current
return _tutime(lpFileName, &ub) == 0;
}
bool ZipPlatform::ChangeDirectory(LPCTSTR lpDirectory)
{
return _tchdir(lpDirectory) == 0; // returns 0 if ok
}
int ZipPlatform::FileExists(LPCTSTR lpszName)
{
if (_taccess(lpszName, 0) == 0)
{
if (DirectoryExists(lpszName))
return -1;
return 1;
}
else
return 0;
}
ZIPINLINE bool ZipPlatform::IsDriveRemovable(LPCTSTR lpszFilePath)
{
CZipPathComponent zpc(lpszFilePath);
return ::GetDriveType(zpc.GetFileDrive()) == DRIVE_REMOVABLE;
}
ZIPINLINE bool ZipPlatform::SetVolLabel(LPCTSTR lpszPath, LPCTSTR lpszLabel)
{
CZipPathComponent zpc(lpszPath);
CZipString szDrive = zpc.GetFileDrive();
CZipPathComponent::AppendSeparator(szDrive);
return ::SetVolumeLabel(szDrive, lpszLabel) != 0;
}
ZIPINLINE void ZipPlatform::AnsiOem(CZipAutoBuffer& buffer, bool bAnsiToOem)
{
if (bAnsiToOem)
CharToOemBuffA(buffer, buffer, buffer.GetSize());
else
OemToCharBuffA(buffer, buffer, buffer.GetSize());
}
ZIPINLINE bool ZipPlatform::RemoveFile(LPCTSTR lpszFileName, bool bThrow)
{
if (!::DeleteFile((LPTSTR)lpszFileName))
if (bThrow)
CZipException::Throw(CZipException::notRemoved, lpszFileName);
else
return false;
return true;
}
ZIPINLINE bool ZipPlatform::RenameFile( LPCTSTR lpszOldName, LPCTSTR lpszNewName, bool bThrow)
{
if (!::MoveFile((LPTSTR)lpszOldName, (LPTSTR)lpszNewName))
if (bThrow)
CZipException::Throw(CZipException::notRenamed, lpszOldName);
else
return false;
return true;
}
ZIPINLINE bool ZipPlatform::IsDirectory(DWORD uAttr)
{
return (uAttr & FILE_ATTRIBUTE_DIRECTORY) != 0;
}
ZIPINLINE bool ZipPlatform::CreateDirectory(LPCTSTR lpDirectory)
{
return ::CreateDirectory(lpDirectory, NULL) != 0;
}
ZIPINLINE DWORD ZipPlatform::GetDefaultAttributes()
{
return 0x81a40020; // make it readable under Unix
}
ZIPINLINE DWORD ZipPlatform::GetDefaultDirAttributes()
{
return 0x41ff0010; // make it readable under Unix
}
ZIPINLINE int ZipPlatform::GetSystemID()
{
return ZipCompatibility::zcDosFat;
}
ZIPINLINE bool ZipPlatform::GetSystemCaseSensitivity()
{
return false;
}
#ifdef _UNICODE
int ZipPlatform::WideToSingle(LPCTSTR lpWide, CZipAutoBuffer &szSingle)
{
size_t wideLen = wcslen(lpWide);
if (wideLen == 0)
{
szSingle.Release();
return 0;
}
// iLen does not include terminating character
int iLen = WideCharToMultiByte(CP_ACP,0, lpWide, wideLen, szSingle,
0, NULL, NULL);
if (iLen > 0)
{
szSingle.Allocate(iLen, true);
iLen = WideCharToMultiByte(CP_ACP,0, lpWide , wideLen, szSingle,
iLen, NULL, NULL);
ASSERT(iLen != 0);
}
else // here it means error
{
szSingle.Release();
iLen --;
}
return iLen;
}
int ZipPlatform::SingleToWide(const CZipAutoBuffer &szSingle, CZipString& szWide)
{
int singleLen = szSingle.GetSize();
// iLen doesn't include terminating character
int iLen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szSingle.GetBuffer(), singleLen, NULL, 0);
if (iLen > 0)
{
iLen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szSingle.GetBuffer(), singleLen,
szWide.GetBuffer(iLen) , iLen);
szWide.ReleaseBuffer(iLen);
ASSERT(iLen != 0);
}
else
{
szWide.Empty();
iLen --; // return -1
}
return iLen;
}
#endif
#ifndef _MFC_VER
#include <io.h>
#include <share.h>
bool ZipPlatform::TruncateFile(int iDes, DWORD iSize)
{
int ret = chsize(iDes, iSize);
return ret != -1;
}
int ZipPlatform::OpenFile(LPCTSTR lpszFileName, UINT iMode, int iShareMode)
{
switch (iShareMode)
{
case (CZipFile::shareDenyWrite & CZipFile::shareDenyRead):
iShareMode = SH_DENYRW;
break;
case (CZipFile::shareDenyRead):
iShareMode = SH_DENYRD;
break;
case (CZipFile::shareDenyWrite):
iShareMode = SH_DENYWR;
break;
default:
iShareMode = SH_DENYNO;
}
return _tsopen(lpszFileName, iMode, iShareMode, S_IREAD | S_IWRITE /*required only when O_CREAT mode*/);
}
bool ZipPlatform::FlushFile(int iDes)
{
return _commit(iDes) == 0;
}
int ZipPlatform::GetFileSystemHandle(int iDes)
{
return _get_osfhandle(iDes);
}
#endif //_MFC_VER

View File

@@ -1,48 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipPlatformComm.cpp $
// $Archive: /ZipArchive/ZipPlatformComm.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipplatform.h"
using namespace ZipPlatform;
bool ZipPlatform::DirectoryExists(LPCTSTR lpszDir)
{
CZipString sz;
if (!GetCurrentDirectory(sz))
return false;
if (!ChangeDirectory(lpszDir))
return false;
ChangeDirectory(sz);
return true;
}
bool ZipPlatform::ForceDirectory(LPCTSTR lpDirectory)
{
ASSERT(lpDirectory);
CZipString szDirectory = lpDirectory;
szDirectory.TrimRight(CZipPathComponent::m_cSeparator);
CZipPathComponent zpc(szDirectory);
if ((zpc.GetFilePath() == szDirectory) ||
(FileExists(szDirectory) == -1))
return true;
if (!ForceDirectory(zpc.GetFilePath()))
return false;
if (!CreateDirectory(szDirectory))
return false;
return true;
}

View File

@@ -1,461 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// $Workfile: ZipStorage.cpp $
// $Archive: /ZipArchive/ZipStorage.cpp $
// $Date$ $Author$
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyright 2000-2003 by Tadeusz Dracz (http://www.artpol-software.com/)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// For the licensing details see the file License.txt
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "zipstorage.h"
#include "ziparchive.h"
// #include "ZipPathComponent.h"
#include "zipplatform.h"
//////////////////////////////////////////////////////////////////////
// disk spanning objectives:
// - sinature at the first disk at the beginning
// - headers and central dir records not divided between disks
// - each file has a data descriptor preceded by the signature
// (bit 3 set in flag);
int CZipActionCallback::m_iStep = 256;
char CZipStorage::m_gszExtHeaderSignat[] = {0x50, 0x4b, 0x07, 0x08};
CZipStorage::CZipStorage()
{
m_pChangeDiskFunc = NULL;
m_iWriteBufferSize = 65536;
m_iCurrentDisk = -1;
m_pFile = NULL;
}
CZipStorage::~CZipStorage()
{
}
DWORD CZipStorage::Read(void *pBuf, DWORD iSize, bool bAtOnce)
{
if (iSize == 0)
return 0;
DWORD iRead = 0;
while (!iRead)
{
iRead = m_pFile->Read(pBuf, iSize);
if (!iRead)
if (IsSpanMode())
ChangeDisk(m_iCurrentDisk + 1);
else
ThrowError(CZipException::badZipFile);
}
if (iRead == iSize)
return iRead;
else if (bAtOnce || !IsSpanMode())
ThrowError(CZipException::badZipFile);
while (iRead < iSize)
{
ChangeDisk(m_iCurrentDisk + 1);
UINT iNewRead = m_pFile->Read((char*)pBuf + iRead, iSize - iRead);
if (!iNewRead && iRead < iSize)
ThrowError(CZipException::badZipFile);
iRead += iNewRead;
}
return iRead;
}
void CZipStorage::Open(LPCTSTR szPathName, int iMode, int iVolumeSize)
{
m_pWriteBuffer.Allocate(m_iWriteBufferSize);
m_uBytesInWriteBuffer = 0;
m_bNewSpan = false;
m_pFile = &m_internalfile;
m_bInMemory = false;
if ((iMode == CZipArchive::zipCreate) ||(iMode == CZipArchive::zipCreateSpan)) // create new archive
{
m_bReadOnly = false;
m_iCurrentDisk = 0;
if (iMode == CZipArchive::zipCreate)
{
m_iSpanMode = noSpan;
OpenFile(szPathName, CZipFile::modeCreate | CZipFile::modeReadWrite);
}
else // create disk spanning archive
{
m_bNewSpan = true;
m_iBytesWritten = 0;
if (iVolumeSize <= 0) // pkzip span
{
if (!m_pChangeDiskFunc)
ThrowError(CZipException::noCallback);
if (!ZipPlatform::IsDriveRemovable(szPathName))
ThrowError(CZipException::nonRemovable);
m_iSpanMode = pkzipSpan;
}
else
{
m_iTdSpanData = iVolumeSize;
m_iSpanMode = tdSpan;
}
NextDisk(4, szPathName);
Write(m_gszExtHeaderSignat, 4, true);
}
}
else // open existing
{
m_bReadOnly = iMode == CZipArchive::zipOpenReadOnly;
OpenFile(szPathName, CZipFile::modeNoTruncate |
(m_bReadOnly ? CZipFile::modeRead : CZipFile::modeReadWrite));
// m_uData, i m_iSpanMode are automatically set during reading the central dir
m_iSpanMode = iVolumeSize == 0 ? suggestedAuto : suggestedTd;
}
}
void CZipStorage::Open(CZipMemFile& mf, int iMode)
{
m_pWriteBuffer.Allocate(m_iWriteBufferSize);
m_uBytesInWriteBuffer = 0;
m_bNewSpan = false;
m_pFile = &mf;
m_bInMemory = true;
if (iMode == CZipArchive::zipCreate)
{
m_iCurrentDisk = 0;
m_iSpanMode = noSpan;
mf.SetLength(0);
}
else // open existing
{
mf.SeekToBegin();
m_iSpanMode = suggestedAuto;
}
}
void CZipStorage::ChangeDisk(int iNumber)
{
if (iNumber == m_iCurrentDisk)
return;
ASSERT(m_iSpanMode != noSpan);
m_iCurrentDisk = iNumber;
OpenFile(m_iSpanMode == pkzipSpan ? ChangePkzipRead() : ChangeTdRead(),
CZipFile::modeNoTruncate | CZipFile::modeRead);
}
void CZipStorage::ThrowError(int err)
{
CZipException::Throw(err, m_pFile->GetFilePath());
}
bool CZipStorage::OpenFile(LPCTSTR lpszName, UINT uFlags, bool bThrow)
{
return m_pFile->Open(lpszName, uFlags | CZipFile::shareDenyWrite, bThrow);
}
CZipString CZipStorage::ChangePkzipRead()
{
CZipString szTemp = m_pFile->GetFilePath();
m_pFile->Close();
CallCallback(-1 , szTemp);
return szTemp;
}
CZipString CZipStorage::ChangeTdRead()
{
CZipString szTemp = GetTdVolumeName(m_iCurrentDisk == m_iTdSpanData);
m_pFile->Close();
return szTemp;
}
CZipString CZipStorage::RenameLastFileInTDSpan()
{
ASSERT(m_iSpanMode == tdSpan);
// give to the last volume the zip extension
CZipString szFileName = m_pFile->GetFilePath();
CZipString szNewFileName = GetTdVolumeName(true);
if (!m_bInMemory)
{
m_pFile->Flush();
m_pFile->Close();
}
if (ZipPlatform::FileExists(szNewFileName))
ZipPlatform::RemoveFile(szNewFileName);
ZipPlatform::RenameFile(szFileName, szNewFileName);
return szNewFileName;
}
CZipString CZipStorage::Close(bool bAfterException)
{
bool bClose = true;
CZipString sz;
if (!bAfterException)
{
Flush();
if ((m_iSpanMode == tdSpan) && (m_bNewSpan))
{
sz = RenameLastFileInTDSpan();
bClose = false;// already closed in RenameLastFileInTDSpan
}
}
if (sz.IsEmpty())
sz = m_pFile->GetFilePath();
if (bClose && !m_bInMemory)
{
FlushFile();
m_pFile->Close();
}
m_pWriteBuffer.Release();
m_iCurrentDisk = -1;
m_iSpanMode = noSpan;
m_pFile = NULL;
return sz;
}
CZipString CZipStorage::GetTdVolumeName(bool bLast, LPCTSTR lpszZipName) const
{
CZipString szFilePath = lpszZipName ? lpszZipName : (LPCTSTR)m_pFile->GetFilePath();
CZipPathComponent zpc(szFilePath);
CZipString szExt;
if (bLast)
szExt = m_szSpanExtension;
else
szExt.Format(_T("%.3d"), m_iCurrentDisk);
zpc.SetExtension(szExt);
return zpc.GetFullPath();
}
void CZipStorage::NextDisk(int iNeeded, LPCTSTR lpszFileName)
{
Flush();
ASSERT(m_iSpanMode != noSpan);
if (m_iBytesWritten)
{
m_iBytesWritten = 0;
m_iCurrentDisk++;
if (m_iCurrentDisk >= 999)
ThrowError(CZipException::tooManyVolumes);
}
CZipString szFileName;
bool bPkSpan = (m_iSpanMode == pkzipSpan);
if (bPkSpan)
szFileName = lpszFileName ? lpszFileName : (LPCTSTR)m_pFile->GetFilePath();
else
szFileName = GetTdVolumeName(false, lpszFileName);
if (!m_pFile->IsClosed())
{
m_pFile->Flush();
m_pFile->Close();
}
if (bPkSpan)
{
int iCode = iNeeded;
while (true)
{
CallCallback(iCode, szFileName);
if (ZipPlatform::FileExists(szFileName))
iCode = -2;
else
{
CZipString label;
label.Format(_T("pkback# %.3d"), m_iCurrentDisk + 1);
if (!ZipPlatform::SetVolLabel(szFileName, label))
iCode = -3;
else if (!OpenFile(szFileName, CZipFile::modeCreate | CZipFile::modeReadWrite, false))
iCode = -4;
else
break;
}
}
m_uCurrentVolSize = GetFreeVolumeSpace();
}
else
{
m_uCurrentVolSize = m_iTdSpanData;
OpenFile(szFileName, CZipFile::modeCreate | CZipFile::modeReadWrite);
}
}
void CZipStorage::CallCallback(int iCode, CZipString szTemp)
{
ASSERT(m_pChangeDiskFunc);
m_pChangeDiskFunc->m_szExternalFile = szTemp;
m_pChangeDiskFunc->m_uDiskNeeded = m_iCurrentDisk + 1;
if (!m_pChangeDiskFunc->Callback(iCode))
CZipException::Throw(CZipException::aborted, szTemp);
}
DWORD CZipStorage::GetFreeVolumeSpace() const
{
ASSERT (m_iSpanMode == pkzipSpan);
CZipString szTemp = m_pFile->GetFilePath();
if (szTemp.IsEmpty()) // called once when creating a disk spanning archive
return 0;
else
{
CZipPathComponent zpc(szTemp);
return ZipPlatform::GetDeviceFreeSpace(zpc.GetFilePath());
}
}
void CZipStorage::UpdateSpanMode(WORD uLastDisk)
{
m_iCurrentDisk = uLastDisk;
if (uLastDisk)
{
// disk spanning detected
CZipString szFilePath = m_pFile->GetFilePath();
if (m_iSpanMode == suggestedAuto)
m_iSpanMode = ZipPlatform::IsDriveRemovable(szFilePath) ?
pkzipSpan : tdSpan;
else
{
ASSERT(m_iSpanMode == suggestedTd);
m_iSpanMode = tdSpan;
}
if (m_iSpanMode == pkzipSpan)
{
if (!m_pChangeDiskFunc)
ThrowError(CZipException::noCallback);
}
else /*if (m_iSpanMode == tdSpan)*/
m_iTdSpanData = uLastDisk; // disk with .zip extension ( the last one)
CZipPathComponent zpc(szFilePath);
m_szSpanExtension = zpc.GetFileExt();
m_pWriteBuffer.Release(); // no need for this in this case
}
else
m_iSpanMode = noSpan;
}
void CZipStorage::Write(const void *pBuf, DWORD iSize, bool bAtOnce)
{
if (!IsSpanMode())
WriteInternalBuffer((char*)pBuf, iSize);
else
{
// if not at once, one byte is enough free space
DWORD iNeeded = bAtOnce ? iSize : 1;
DWORD uTotal = 0;
while (uTotal < iSize)
{
DWORD uFree;
while ((uFree = VolumeLeft()) < iNeeded)
{
if ((m_iSpanMode == tdSpan) && !m_iBytesWritten && !m_uBytesInWriteBuffer)
// in the tdSpan mode, if the size of the archive is less
// than the size of the packet to be written at once,
// increase once the size of the volume
m_uCurrentVolSize = iNeeded;
else
NextDisk(iNeeded);
}
DWORD uLeftToWrite = iSize - uTotal;
DWORD uToWrite = uFree < uLeftToWrite ? uFree : uLeftToWrite;
WriteInternalBuffer((char*)pBuf + uTotal, uToWrite);
if (bAtOnce)
return;
else
uTotal += uToWrite;
}
}
}
void CZipStorage::WriteInternalBuffer(const char *pBuf, DWORD uSize)
{
DWORD uWritten = 0;
while (uWritten < uSize)
{
DWORD uFreeInBuffer = GetFreeInBuffer();
if (uFreeInBuffer == 0)
{
Flush();
uFreeInBuffer = m_pWriteBuffer.GetSize();
}
DWORD uLeftToWrite = uSize - uWritten;
DWORD uToCopy = uLeftToWrite < uFreeInBuffer ? uLeftToWrite : uFreeInBuffer;
memcpy(m_pWriteBuffer + m_uBytesInWriteBuffer, pBuf + uWritten, uToCopy);
uWritten += uToCopy;
m_uBytesInWriteBuffer += uToCopy;
}
}
DWORD CZipStorage::VolumeLeft() const
{
// for pkzip span m_uCurrentVolSize is updated after each flush()
return m_uCurrentVolSize - m_uBytesInWriteBuffer - ((m_iSpanMode == pkzipSpan) ? 0 : m_iBytesWritten);
}
void CZipStorage::Flush()
{
if (m_iSpanMode != noSpan)
m_iBytesWritten += m_uBytesInWriteBuffer;
if (m_uBytesInWriteBuffer)
{
m_pFile->Write(m_pWriteBuffer, m_uBytesInWriteBuffer);
m_uBytesInWriteBuffer = 0;
}
if (m_iSpanMode == pkzipSpan)
// after writing it is difficult to predict the free space due to
// not completly written clusters, write operation may start from
// the new cluster
m_uCurrentVolSize = GetFreeVolumeSpace();
}
void CZipStorage::FinalizeSpan()
{
ASSERT(IsSpanMode() == 1); // span in creation
ASSERT(!m_bInMemory);
CZipString szFileName;
if ((m_iSpanMode == tdSpan) && (m_bNewSpan))
szFileName = RenameLastFileInTDSpan();
else
{
szFileName = m_pFile->GetFilePath();
// the file is already closed
m_pFile->Close();
}
m_bNewSpan = false;
if (m_iCurrentDisk == 0) // one-disk span was converted to normal archive
m_iSpanMode = noSpan;
else
m_iTdSpanData = m_iCurrentDisk;
OpenFile(szFileName, CZipFile::modeNoTruncate | (m_iSpanMode == noSpan ? CZipFile::modeReadWrite : CZipFile::modeRead));
}