other-licenses/7zstub/src/Windows/FileFind.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/7zstub/src/Windows/FileFind.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,176 @@
     1.4 +// Windows/FileFind.h
     1.5 +
     1.6 +#ifndef __WINDOWS_FILEFIND_H
     1.7 +#define __WINDOWS_FILEFIND_H
     1.8 +
     1.9 +#include "../Common/String.h"
    1.10 +#include "../Common/Types.h"
    1.11 +#include "FileName.h"
    1.12 +#include "Defs.h"
    1.13 +
    1.14 +namespace NWindows {
    1.15 +namespace NFile {
    1.16 +namespace NFind {
    1.17 +
    1.18 +namespace NAttributes
    1.19 +{
    1.20 +  inline bool IsReadOnly(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_READONLY) != 0; }
    1.21 +  inline bool IsHidden(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_HIDDEN) != 0; }
    1.22 +  inline bool IsSystem(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_SYSTEM) != 0; }
    1.23 +  inline bool IsDirectory(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0; }
    1.24 +  inline bool IsArchived(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ARCHIVE) != 0; }
    1.25 +  inline bool IsCompressed(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_COMPRESSED) != 0; }
    1.26 +  inline bool IsEncrypted(DWORD attributes) { return (attributes & FILE_ATTRIBUTE_ENCRYPTED) != 0; }
    1.27 +}
    1.28 +
    1.29 +class CFileInfoBase
    1.30 +{ 
    1.31 +  bool MatchesMask(UINT32 mask) const  { return ((Attributes & mask) != 0); }
    1.32 +public:
    1.33 +  DWORD Attributes;
    1.34 +  FILETIME CreationTime;  
    1.35 +  FILETIME LastAccessTime; 
    1.36 +  FILETIME LastWriteTime;
    1.37 +  UInt64 Size;
    1.38 +  
    1.39 +  #ifndef _WIN32_WCE
    1.40 +  UINT32 ReparseTag;
    1.41 +  #else
    1.42 +  DWORD ObjectID; 
    1.43 +  #endif
    1.44 +
    1.45 +  bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }
    1.46 +  bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }
    1.47 +  bool IsDirectory() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }
    1.48 +  bool IsEncrypted() const { return MatchesMask(FILE_ATTRIBUTE_ENCRYPTED); }
    1.49 +  bool IsHidden() const { return MatchesMask(FILE_ATTRIBUTE_HIDDEN); }
    1.50 +  bool IsNormal() const { return MatchesMask(FILE_ATTRIBUTE_NORMAL); }
    1.51 +  bool IsOffline() const { return MatchesMask(FILE_ATTRIBUTE_OFFLINE); }
    1.52 +  bool IsReadOnly() const { return MatchesMask(FILE_ATTRIBUTE_READONLY); }
    1.53 +  bool HasReparsePoint() const { return MatchesMask(FILE_ATTRIBUTE_REPARSE_POINT); }
    1.54 +  bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }
    1.55 +  bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }
    1.56 +  bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }
    1.57 +};
    1.58 +
    1.59 +class CFileInfo: public CFileInfoBase
    1.60 +{ 
    1.61 +public:
    1.62 +  CSysString Name;
    1.63 +  bool IsDots() const;
    1.64 +};
    1.65 +
    1.66 +#ifdef _UNICODE
    1.67 +typedef CFileInfo CFileInfoW;
    1.68 +#else
    1.69 +class CFileInfoW: public CFileInfoBase
    1.70 +{ 
    1.71 +public:
    1.72 +  UString Name;
    1.73 +  bool IsDots() const;
    1.74 +};
    1.75 +#endif
    1.76 +
    1.77 +class CFindFile
    1.78 +{
    1.79 +  friend class CEnumerator;
    1.80 +  HANDLE _handle;
    1.81 +  bool _handleAllocated;
    1.82 +public:
    1.83 +  bool IsHandleAllocated() const { return _handleAllocated; }
    1.84 +  CFindFile(): _handleAllocated(false) {}
    1.85 +  ~CFindFile() {  Close(); }
    1.86 +  bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);
    1.87 +  bool FindNext(CFileInfo &fileInfo);
    1.88 +  #ifndef _UNICODE
    1.89 +  bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);
    1.90 +  bool FindNext(CFileInfoW &fileInfo);
    1.91 +  #endif
    1.92 +  bool Close();
    1.93 +};
    1.94 +
    1.95 +bool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);
    1.96 +
    1.97 +bool DoesFileExist(LPCTSTR name);
    1.98 +#ifndef _UNICODE
    1.99 +bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);
   1.100 +bool DoesFileExist(LPCWSTR name);
   1.101 +#endif
   1.102 +
   1.103 +class CEnumerator
   1.104 +{
   1.105 +  CFindFile _findFile;
   1.106 +  CSysString _wildcard;
   1.107 +  bool NextAny(CFileInfo &fileInfo);
   1.108 +public:
   1.109 +  CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}
   1.110 +  CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}
   1.111 +  bool Next(CFileInfo &fileInfo);
   1.112 +  bool Next(CFileInfo &fileInfo, bool &found);
   1.113 +};
   1.114 +
   1.115 +#ifdef _UNICODE
   1.116 +typedef CEnumerator CEnumeratorW;
   1.117 +#else
   1.118 +class CEnumeratorW
   1.119 +{
   1.120 +  CFindFile _findFile;
   1.121 +  UString _wildcard;
   1.122 +  bool NextAny(CFileInfoW &fileInfo);
   1.123 +public:
   1.124 +  CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}
   1.125 +  CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}
   1.126 +  bool Next(CFileInfoW &fileInfo);
   1.127 +  bool Next(CFileInfoW &fileInfo, bool &found);
   1.128 +};
   1.129 +#endif
   1.130 +
   1.131 +class CFindChangeNotification
   1.132 +{
   1.133 +  HANDLE _handle;
   1.134 +public:
   1.135 +  operator HANDLE () { return _handle; }
   1.136 +  CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}
   1.137 +  ~CFindChangeNotification() {  Close(); }
   1.138 +  bool Close();
   1.139 +  HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);
   1.140 +  #ifndef _UNICODE
   1.141 +  HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);
   1.142 +  #endif
   1.143 +  bool FindNext()
   1.144 +    { return BOOLToBool(::FindNextChangeNotification(_handle)); }
   1.145 +};
   1.146 +
   1.147 +#ifndef _WIN32_WCE
   1.148 +bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);
   1.149 +#ifndef _UNICODE
   1.150 +bool MyGetLogicalDriveStrings(UStringVector &driveStrings);
   1.151 +#endif
   1.152 +#endif
   1.153 +
   1.154 +inline bool MyGetCompressedFileSize(LPCTSTR fileName, UInt64 &size)
   1.155 +{
   1.156 +  DWORD highPart;
   1.157 +  DWORD lowPart = ::GetCompressedFileSize(fileName, &highPart);
   1.158 +  if (lowPart == INVALID_FILE_SIZE)
   1.159 +    if (::GetLastError() != NO_ERROR)
   1.160 +      return false;
   1.161 +  size = (UInt64(highPart) << 32) | lowPart;
   1.162 +  return true;
   1.163 +}
   1.164 +
   1.165 +inline bool MyGetCompressedFileSizeW(LPCWSTR fileName, UInt64 &size)
   1.166 +{
   1.167 +  DWORD highPart;
   1.168 +  DWORD lowPart = ::GetCompressedFileSizeW(fileName, &highPart);
   1.169 +  if (lowPart == INVALID_FILE_SIZE)
   1.170 +    if (::GetLastError() != NO_ERROR)
   1.171 +      return false;
   1.172 +  size = (UInt64(highPart) << 32) | lowPart;
   1.173 +  return true;
   1.174 +}
   1.175 +
   1.176 +}}}
   1.177 +
   1.178 +#endif
   1.179 +

mercurial