00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00022 #if !defined(ZIPARCHIVE_FILEFILTER_DOT_H)
00023 #define ZIPARCHIVE_FILEFILTER_DOT_H
00024
00025 #if _MSC_VER > 1000
00026 #pragma once
00027 #pragma warning( push )
00028 #pragma warning (disable : 4100) // unreferenced formal parameter
00029 #endif
00030
00031 #include "stdafx.h"
00032 #include "ZipExport.h"
00033 #include "FileInfo.h"
00034 #include "Wildcard.h"
00035 #include "ZipPlatform.h"
00036 #include "ZipCollections.h"
00037
00038 namespace ZipArchiveLib
00039 {
00048 class ZIP_API CFileFilter
00049 {
00050 public:
00051
00061 CFileFilter(bool bInverted = false)
00062 :m_bInverted(bInverted)
00063 {
00064 }
00065
00106 bool Evaluate(LPCTSTR lpszParentDir, LPCTSTR lpszName, const CFileInfo& info)
00107 {
00108 bool ret = Accept(lpszParentDir, lpszName, info);
00109 if (!HandlesInversion())
00110 return m_bInverted ? !ret : ret;
00111 return ret;
00112 }
00113
00130 void SetInverted(bool bInverted = true) { m_bInverted = bInverted;}
00131
00143 bool IsInverted() const {return m_bInverted;}
00144
00169 virtual bool HandlesFile(const CFileInfo& info)
00170 {
00171 return !info.IsDirectory();
00172 }
00173
00174 virtual ~CFileFilter()
00175 {
00176 }
00177 protected:
00210 virtual bool Accept(LPCTSTR lpszParentDir, LPCTSTR lpszName, const CFileInfo& info)
00211 {
00212 return true;
00213 }
00214
00236 virtual bool HandlesInversion() const
00237 {
00238 return false;
00239 }
00240 bool m_bInverted;
00241
00242 };
00243
00244
00255 class ZIP_API CNameFileFilter : public CFileFilter
00256 {
00257 CWildcard m_matcher;
00258 int m_iAppliesToTypes;
00259 public:
00260
00270 enum AppliesToTypes
00271 {
00272 toFile = 0x1,
00273 toDirectory = 0x2,
00274 toAll = toFile | toDirectory
00275 };
00276
00306 CNameFileFilter(LPCTSTR lpszPattern = _T("*"), bool bInverted = false, int iAppliesToTypes = toFile, bool bCaseSensitive = ZipPlatform::GetSystemCaseSensitivity())
00307 :CFileFilter(bInverted), m_matcher(lpszPattern, bCaseSensitive)
00308 {
00309 m_iAppliesToTypes = iAppliesToTypes;
00310 }
00311
00326 bool AppliesToType(int iType)
00327 {
00328 return (m_iAppliesToTypes & iType) == iType;
00329 }
00330
00341 void SetAppliesToTypes(int iType) { m_iAppliesToTypes = iType; }
00342
00352 int GetAppliesToTypes() {return m_iAppliesToTypes;}
00353
00370 bool HandlesFile(const CFileInfo& info)
00371 {
00372 return info.IsDirectory() ? AppliesToType(toDirectory) : AppliesToType(toFile);
00373 }
00374 protected:
00375 virtual bool Accept(LPCTSTR, LPCTSTR lpszName, const CFileInfo& info)
00376 {
00377 return m_matcher.IsMatch(lpszName);
00378 }
00379 };
00380
00389 class ZIP_API CGroupFileFilter : public CFileFilter
00390 {
00391
00392 public:
00393
00397 enum GroupType
00398 {
00399 And,
00400 Or
00401 };
00402
00427 CGroupFileFilter(GroupType groupType = CGroupFileFilter::And, bool bAutoDelete = true, bool bInverted = false)
00428 :CFileFilter(bInverted), m_iType(groupType), m_bAutoDelete(bAutoDelete)
00429 {
00430 }
00431
00438 void Add(CFileFilter* pFilter)
00439 {
00440 m_filters.Add(pFilter);
00441 }
00442
00449 CFileFilter* GetAt(ZIP_ARRAY_SIZE_TYPE uIndex)
00450 {
00451 return m_filters[uIndex];
00452 }
00453
00460 const CFileFilter* GetAt(ZIP_ARRAY_SIZE_TYPE uIndex) const
00461 {
00462 return m_filters[uIndex];
00463 }
00464
00471 const CFileFilter* operator[] (ZIP_ARRAY_SIZE_TYPE uIndex) const
00472 {
00473 return GetAt(uIndex);
00474 }
00475
00482 CFileFilter* operator[] (ZIP_ARRAY_SIZE_TYPE uIndex)
00483 {
00484 return GetAt(uIndex);
00485 }
00486
00498 void RemoveAt(ZIP_ARRAY_SIZE_TYPE uIndex)
00499 {
00500 CFileFilter* filter = m_filters[uIndex];
00501
00502 m_filters.RemoveAt(uIndex);
00503 if (m_bAutoDelete)
00504 delete filter;
00505 }
00506
00507
00518 void Clear()
00519 {
00520 if (m_filters.GetSize() == 0)
00521 return;
00522
00523 ZIP_ARRAY_SIZE_TYPE i = m_filters.GetSize() - 1;
00524 for (; ;)
00525 {
00526 RemoveAt(i);
00527 if (i == 0)
00528 break;
00529 i--;
00530 }
00531 }
00532
00540 ZIP_ARRAY_SIZE_TYPE GetSize()
00541 {
00542 return m_filters.GetSize();
00543 }
00544
00554 void SetType(GroupType iType) {m_iType = iType;}
00555
00565 GroupType GetType() const {return m_iType;}
00566
00579 void SetAutoDelete(bool bAutoDelete) {m_bAutoDelete = bAutoDelete;}
00580
00590 bool IsAutoDelete() const {return m_bAutoDelete;}
00591
00603 bool HandlesFile(const CFileInfo& info)
00604 {
00605 for (ZIP_ARRAY_SIZE_TYPE i = 0; i < m_filters.GetSize(); i++)
00606
00607 if (m_filters[i]->HandlesFile(info))
00608 return true;
00609 return false;
00610 }
00611
00612
00613 ~CGroupFileFilter()
00614 {
00615 Clear();
00616 }
00617
00618 protected:
00619
00620 virtual bool Accept(LPCTSTR lpszParentDir, LPCTSTR lpszName, const CFileInfo& info);
00630 bool HandlesInversion() const
00631 {
00632 return true;
00633 }
00634 GroupType m_iType;
00635 bool m_bAutoDelete;
00636
00637 private:
00638
00639 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
00640 #pragma warning (push)
00641 #pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
00642 #endif
00643
00644 CZipArray<CFileFilter*> m_filters;
00645
00646 #if (_MSC_VER > 1000) && (defined ZIP_HAS_DLL)
00647 #pragma warning( pop)
00648 #endif
00649
00650 };
00651 }
00652
00653 #if _MSC_VER > 1000
00654 #pragma warning( pop )
00655 #endif
00656
00657 #endif