From 02d6107c97b48888362e7c6a70dcac323c89d741 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 17 Dec 2023 21:23:58 +0100 Subject: ZipArchive: Update to the 4.6.9 release --- zip/ZipArchive/DirEnumerator.cpp | 93 +++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 21 deletions(-) (limited to 'zip/ZipArchive/DirEnumerator.cpp') diff --git a/zip/ZipArchive/DirEnumerator.cpp b/zip/ZipArchive/DirEnumerator.cpp index eb6fa16..53185ee 100644 --- a/zip/ZipArchive/DirEnumerator.cpp +++ b/zip/ZipArchive/DirEnumerator.cpp @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////////// -// This source file is part of the ZipArchive library source distribution and -// is Copyrighted 2000 - 2007 by Artpol Software - Tadeusz Dracz +// This source file is part of the ZipArchive Library Open Source distribution +// and is Copyrighted 2000 - 2022 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 @@ -9,10 +9,11 @@ // // For the licensing details refer to the License.txt file. // -// Web Site: http://www.artpol-software.com +// Web Site: https://www.artpol-software.com //////////////////////////////////////////////////////////////////////////////// #include "stdafx.h" + #if defined _MSC_VER && _MSC_VER < 1300 // STL warnings #pragma warning (push, 3) @@ -20,6 +21,7 @@ #include "DirEnumerator.h" #include "FileFilter.h" +#include "ZipAutoBuffer.h" #include @@ -48,6 +50,44 @@ namespace ZipArchiveLib #define ZIP_ENUMERATOR_FOR_GNUC #endif +#ifdef ZIP_ENUMERATOR_FOR_GNUC + class CFindHandleReleaser + { + DIR* m_handle; + public: + CFindHandleReleaser(DIR* handle) + :m_handle(handle) + { + } + ~CFindHandleReleaser() + { + closedir(m_handle); + } + }; +#else + class CFindHandleReleaser + { +#if _MSC_VER > 1200 + intptr_t m_handle; +#else + long m_handle; +#endif + public: +#if _MSC_VER > 1200 + CFindHandleReleaser(intptr_t handle) +#else + CFindHandleReleaser(long handle) +#endif + :m_handle(handle) + { + } + ~CFindHandleReleaser() + { + _findclose(m_handle); + } + }; +#endif + bool CDirEnumerator::Start(CFileFilter& filter) { @@ -63,25 +103,37 @@ bool CDirEnumerator::Start(CFileFilter& filter) EnterDirectory(); #ifdef ZIP_ENUMERATOR_FOR_GNUC - DIR* dp = opendir(m_szCurrentDirectory); + _ZIP_WIDE_TO_MULTIBYTE(m_szCurrentDirectory, currentDirectory) + + DIR* dp = opendir(currentDirectory); if (dp) { + CFindHandleReleaser handleReleaser(dp); while (true) { struct dirent* entry = readdir(dp); if (!entry) - break; - CZipString path(m_szCurrentDirectory + entry->d_name); + break; + LPCTSTR name; + #ifdef _UNICODE + CZipString nameWide; + ZipPlatform::MultiByteToWide(entry->d_name, -1, nameWide, 0); + name = nameWide; + #else + name = entry->d_name; + #endif + CZipString path(m_szCurrentDirectory + name); + _ZIP_WIDE_TO_MULTIBYTE(path, pathMultiByte) + #if !defined __APPLE__ && !defined __CYGWIN__ struct stat64 sStats; - if (stat64(path, &sStats) == -1) + if (stat64(pathMultiByte, &sStats) == -1) #else struct stat sStats; - if (stat(path, &sStats) == -1) + if (stat(pathMultiByte, &sStats) == -1) #endif continue; - - LPCTSTR name = entry->d_name; + CFileInfo info; info.m_uAttributes = sStats.st_mode; @@ -96,6 +148,7 @@ bool CDirEnumerator::Start(CFileFilter& filter) #endif if( (hFile = _tfindfirsti64( (LPTSTR)(LPCTSTR)szFullFileName, &ffInfo )) != -1L ) { + CFindHandleReleaser handleReleaser(hFile); do { LPCTSTR name = ffInfo.name; @@ -114,14 +167,14 @@ bool CDirEnumerator::Start(CFileFilter& filter) #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; + info.m_tCreationTime = sStats.st_ctime; + info.m_tModificationTime = sStats.st_mtime; + info.m_tLastAccessTime = 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; + info.m_tCreationTime = ffInfo.time_create; + info.m_tModificationTime = ffInfo.time_write; + info.m_tLastAccessTime = ffInfo.time_access; CZipString path(m_szCurrentDirectory + ffInfo.name); #endif @@ -129,7 +182,7 @@ bool CDirEnumerator::Start(CFileFilter& filter) { bool bAllow; if (filter.HandlesFile(info)) - bAllow = filter.Evaluate(path, name, info); + bAllow = filter.Evaluate(path, name, info) && Process(path, info); else // examine directory, if the filter cannot decide bAllow = true; @@ -154,13 +207,11 @@ bool CDirEnumerator::Start(CFileFilter& filter) } #ifdef ZIP_ENUMERATOR_FOR_GNUC - } - closedir(dp); + } } #else } - while (_tfindnexti64(hFile, &ffInfo) == 0L); - _findclose(hFile); + while (_tfindnexti64(hFile, &ffInfo) == 0L); } #endif ExitDirectory(); -- cgit v1.2.3