Files
harbour-core/harbour/contrib/hbziparch/DirEnumerator.cpp
Viktor Szakats 40338a87d6 2008-06-24 00:35 UTC+0200 Viktor Szakats (harbour.01 syenar hu)
* contrib/hbziparch/_features.h
   * contrib/hbziparch/_platform.h
   * contrib/hbziparch/Aes.cpp
   * contrib/hbziparch/Aes.h
   * contrib/hbziparch/BaseLibCompressor.cpp
   * contrib/hbziparch/BaseLibCompressor.h
   * contrib/hbziparch/BytesWriter.h
   * contrib/hbziparch/Bzip2Compressor.cpp
   * contrib/hbziparch/Bzip2Compressor.h
   * contrib/hbziparch/DeflateCompressor.cpp
   * contrib/hbziparch/DeflateCompressor.h
   * contrib/hbziparch/DirEnumerator.cpp
   * contrib/hbziparch/DirEnumerator.h
   * contrib/hbziparch/FileFilter.cpp
   * contrib/hbziparch/FileFilter.h
   * contrib/hbziparch/FileInfo.h
   * contrib/hbziparch/Hmac.cpp
   * contrib/hbziparch/Hmac.h
   * contrib/hbziparch/RandomPool.cpp
   * contrib/hbziparch/RandomPool.h
   * contrib/hbziparch/Sha1.cpp
   * contrib/hbziparch/Sha1.h
   * contrib/hbziparch/std_mfc.h
   * contrib/hbziparch/std_stl.h
   * contrib/hbziparch/Wildcard.cpp
   * contrib/hbziparch/Wildcard.h
   * contrib/hbziparch/ZipAbstractFile.h
   * contrib/hbziparch/ZipAesCryptograph.cpp
   * contrib/hbziparch/ZipAesCryptograph.h
   * contrib/hbziparch/ZipArchive.cpp
   * contrib/hbziparch/ZipArchive.h
   * contrib/hbziparch/ZipAutoBuffer.cpp
   * contrib/hbziparch/ZipAutoBuffer.h
   * contrib/hbziparch/ZipBaseException.h
   * contrib/hbziparch/ZipCallback.h
   * contrib/hbziparch/ZipCallbackProvider.h
   * contrib/hbziparch/ZipCentralDir.cpp
   * contrib/hbziparch/ZipCentralDir.h
   * contrib/hbziparch/ZipCollections.h
   * contrib/hbziparch/ZipCollections_mfc.h
   * contrib/hbziparch/ZipCollections_stl.h
   * contrib/hbziparch/ZipCompatibility.cpp
   * contrib/hbziparch/ZipCompatibility.h
   * contrib/hbziparch/ZipCompressor.cpp
   * contrib/hbziparch/ZipCompressor.h
   * contrib/hbziparch/ZipCrc32Cryptograph.cpp
   * contrib/hbziparch/ZipCrc32Cryptograph.h
   * contrib/hbziparch/ZipCryptograph.cpp
   * contrib/hbziparch/ZipCryptograph.h
   * contrib/hbziparch/ZipException.cpp
   * contrib/hbziparch/ZipException.h
   * contrib/hbziparch/ZipExtraData.cpp
   * contrib/hbziparch/ZipExtraData.h
   * contrib/hbziparch/ZipExtraField.cpp
   * contrib/hbziparch/ZipExtraField.h
   * contrib/hbziparch/ZipFile.h
   * contrib/hbziparch/ZipFile_mfc.cpp
   * contrib/hbziparch/ZipFile_mfc.h
   * contrib/hbziparch/ZipFile_stl.cpp
   * contrib/hbziparch/ZipFile_stl.h
   * contrib/hbziparch/ZipFileHeader.cpp
   * contrib/hbziparch/ZipFileHeader.h
   * contrib/hbziparch/ZipFileMapping.h
   * contrib/hbziparch/ZipFileMapping_lnx.h
   * contrib/hbziparch/ZipFileMapping_win.h
   * contrib/hbziparch/ZipMemFile.cpp
   * contrib/hbziparch/ZipMemFile.h
   * contrib/hbziparch/ZipMutex.h
   * contrib/hbziparch/ZipMutex_lnx.h
   * contrib/hbziparch/ZipMutex_win.h
   * contrib/hbziparch/ZipPathComponent.h
   * contrib/hbziparch/ZipPlatform.h
   * contrib/hbziparch/ZipPlatformComm.cpp
   * contrib/hbziparch/ZipStorage.cpp
   * contrib/hbziparch/ZipStorage.h
   * contrib/hbziparch/ZipString.h
   * contrib/hbziparch/ZipString_mfc.h
   * contrib/hbziparch/ZipString_stl.h
   * contrib/hbziparch/ZipStringStoreSettings.h
     + ZipArchive lib update finished.
     ; Pass 2/2
     ; Please test.
2008-06-23 22:41:33 +00:00

186 lines
4.2 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyrighted 2000 - 2007 by Artpol Software - 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 refer to the License.txt file.
//
// Web Site: http://www.artpol-software.com
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#if defined _MSC_VER && _MSC_VER < 1300
// STL warnings
#pragma warning (push, 3)
#endif
#include "DirEnumerator.h"
#include "FileFilter.h"
#include <queue>
#if defined __GNUC__ && !defined __MINGW32__
#include <sys/stat.h>
#include <dirent.h>
#else
#include <io.h>
#ifdef __BORLANDC__
#ifndef _tfindfirsti64
#define _tfindfirsti64 __tfindfirsti64
#endif
#ifndef _tfindnexti64
#define _tfindnexti64 __tfindnexti64
#endif
#ifndef _tfinddatai64_t
#define _tfinddatai64_t __tfinddatai64_t
#endif
#endif
#endif
namespace ZipArchiveLib
{
#if defined __GNUC__ && !defined __MINGW32__
#define ZIP_ENUMERATOR_FOR_GNUC
#endif
bool CDirEnumerator::Start(CFileFilter& filter)
{
OnEnumerationBegin();
std::queue<CZipString> dirs;
dirs.push(CZipString(m_lpszDirectory));
bool ret = true;
do
{
m_szCurrentDirectory = dirs.front();
dirs.pop();
CZipPathComponent::AppendSeparator(m_szCurrentDirectory);
EnterDirectory();
#ifdef ZIP_ENUMERATOR_FOR_GNUC
DIR* dp = opendir(m_szCurrentDirectory);
if (dp)
{
while (true)
{
struct dirent* entry = readdir(dp);
if (!entry)
break;
CZipString path(m_szCurrentDirectory + entry->d_name);
#if !defined __APPLE__ && !defined __CYGWIN__
struct stat64 sStats;
if (stat64(path, &sStats) == -1)
#else
struct stat sStats;
if (stat(path, &sStats) == -1)
#endif
continue;
LPCTSTR name = entry->d_name;
CFileInfo info;
info.m_uAttributes = sStats.st_mode;
#else
CZipString szFullFileName = m_szCurrentDirectory + _T("*");
_tfinddatai64_t ffInfo;
#if _MSC_VER > 1200
intptr_t hFile;
#else
long hFile;
#endif
if( (hFile = _tfindfirsti64( (LPTSTR)(LPCTSTR)szFullFileName, &ffInfo )) != -1L )
{
do
{
LPCTSTR name = ffInfo.name;
CFileInfo info;
info.m_uAttributes = ffInfo.attrib;
#endif
bool isDir;
if (ZipPlatform::IsDirectory(info.m_uAttributes))
{
if (!m_bRecursive || IsDots(name))
continue;
isDir = true;
}
else
isDir = false;
#ifdef ZIP_ENUMERATOR_FOR_GNUC
info.m_uSize = (ZIP_FILE_USIZE)sStats.st_size;
info.m_uCreateTime = sStats.st_ctime;
info.m_uModTime = sStats.st_mtime;
info.m_uAccessTime = sStats.st_atime;
#else
info.m_uSize = (ZIP_FILE_USIZE)ffInfo.size;
info.m_uCreateTime = ffInfo.time_create;
info.m_uModTime = ffInfo.time_write;
info.m_uAccessTime = ffInfo.time_access;
CZipString path(m_szCurrentDirectory + ffInfo.name);
#endif
if (isDir)
{
bool bAllow;
if (filter.HandlesFile(info))
bAllow = filter.Evaluate(path, name, info);
else
// examine directory, if the filter cannot decide
bAllow = true;
if (bAllow)
dirs.push(path);
}
else
{
bool bAllow;
if (filter.HandlesFile(info))
bAllow = filter.Evaluate(path, name, info);
else
// skip file, if the filter cannot decide
bAllow = false;
if (bAllow && !Process(path, info))
{
ret = false;
break;
}
}
#ifdef ZIP_ENUMERATOR_FOR_GNUC
}
closedir(dp);
}
#else
}
while (_tfindnexti64(hFile, &ffInfo) == 0L);
_findclose(hFile);
}
#endif
ExitDirectory();
}
while(!dirs.empty() && ret);
OnEnumerationEnd(ret);
return ret;
}
bool CDirEnumerator::IsDots(LPCTSTR lpszName)
{
CZipString name(lpszName);
return name.Compare(_T(".")) == 0 || name.Compare(_T("..")) == 0;
}
} // namespace
#if defined _MSC_VER && _MSC_VER < 1300
// STL warnings
#pragma warning (pop)
#endif