1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
|
// DirItem.h
#ifndef ZIP7_INC_DIR_ITEM_H
#define ZIP7_INC_DIR_ITEM_H
#ifdef _WIN32
#include "../../../Common/MyLinux.h"
#endif
#include "../../../Common/MyString.h"
#include "../../../Windows/FileFind.h"
#include "../../../Windows/PropVariant.h"
#include "../../../Windows/TimeUtils.h"
#include "../../Common/UniqBlocks.h"
#include "../../Archive/IArchive.h"
struct CDirItemsStat
{
UInt64 NumDirs;
UInt64 NumFiles;
UInt64 NumAltStreams;
UInt64 FilesSize;
UInt64 AltStreamsSize;
UInt64 NumErrors;
// UInt64 Get_NumItems() const { return NumDirs + NumFiles + NumAltStreams; }
UInt64 Get_NumDataItems() const { return NumFiles + NumAltStreams; }
UInt64 GetTotalBytes() const { return FilesSize + AltStreamsSize; }
bool IsEmpty() const { return
0 == NumDirs
&& 0 == NumFiles
&& 0 == NumAltStreams
&& 0 == FilesSize
&& 0 == AltStreamsSize
&& 0 == NumErrors; }
CDirItemsStat():
NumDirs(0),
NumFiles(0),
NumAltStreams(0),
FilesSize(0),
AltStreamsSize(0),
NumErrors(0)
{}
};
struct CDirItemsStat2: public CDirItemsStat
{
UInt64 Anti_NumDirs;
UInt64 Anti_NumFiles;
UInt64 Anti_NumAltStreams;
// UInt64 Get_NumItems() const { return Anti_NumDirs + Anti_NumFiles + Anti_NumAltStreams + CDirItemsStat::Get_NumItems(); }
UInt64 Get_NumDataItems2() const { return Anti_NumFiles + Anti_NumAltStreams + CDirItemsStat::Get_NumDataItems(); }
bool IsEmpty() const { return CDirItemsStat::IsEmpty()
&& 0 == Anti_NumDirs
&& 0 == Anti_NumFiles
&& 0 == Anti_NumAltStreams; }
CDirItemsStat2():
Anti_NumDirs(0),
Anti_NumFiles(0),
Anti_NumAltStreams(0)
{}
};
Z7_PURE_INTERFACES_BEGIN
#define Z7_IFACEN_IDirItemsCallback(x) \
virtual HRESULT ScanError(const FString &path, DWORD systemError) x \
virtual HRESULT ScanProgress(const CDirItemsStat &st, const FString &path, bool isDir) x \
Z7_IFACE_DECL_PURE(IDirItemsCallback)
Z7_PURE_INTERFACES_END
struct CArcTime
{
FILETIME FT;
UInt16 Prec;
Byte Ns100;
bool Def;
CArcTime()
{
Clear();
}
void Clear()
{
FT.dwHighDateTime = FT.dwLowDateTime = 0;
Prec = 0;
Ns100 = 0;
Def = false;
}
bool IsZero() const
{
return FT.dwLowDateTime == 0 && FT.dwHighDateTime == 0 && Ns100 == 0;
}
int CompareWith(const CArcTime &a) const
{
const int res = CompareFileTime(&FT, &a.FT);
if (res != 0)
return res;
if (Ns100 < a.Ns100) return -1;
if (Ns100 > a.Ns100) return 1;
return 0;
}
UInt64 Get_FILETIME_as_UInt64() const
{
return (((UInt64)FT.dwHighDateTime) << 32) + FT.dwLowDateTime;
}
UInt32 Get_DosTime() const
{
FILETIME ft2 = FT;
if ((Prec == k_PropVar_TimePrec_Base + 8 ||
Prec == k_PropVar_TimePrec_Base + 9)
&& Ns100 != 0)
{
UInt64 u64 = Get_FILETIME_as_UInt64();
// we round up even small (ns < 100ns) as FileTimeToDosTime()
if (u64 % 20000000 == 0)
{
u64++;
ft2.dwHighDateTime = (DWORD)(u64 >> 32);
ft2.dwHighDateTime = (DWORD)u64;
}
}
// FileTimeToDosTime() is expected to round up in Windows
UInt32 dosTime;
// we use simplified code with utctime->dos.
// do we need local time instead here?
NWindows::NTime::FileTime_To_DosTime(ft2, dosTime);
return dosTime;
}
int GetNumDigits() const
{
if (Prec == k_PropVar_TimePrec_Unix ||
Prec == k_PropVar_TimePrec_DOS)
return 0;
if (Prec == k_PropVar_TimePrec_HighPrec)
return 9;
if (Prec == k_PropVar_TimePrec_0)
return 7;
int digits = (int)Prec - (int)k_PropVar_TimePrec_Base;
if (digits < 0)
digits = 0;
return digits;
}
void Write_To_FiTime(CFiTime &dest) const
{
#ifdef _WIN32
dest = FT;
#else
if (FILETIME_To_timespec(FT, dest))
if ((Prec == k_PropVar_TimePrec_Base + 8 ||
Prec == k_PropVar_TimePrec_Base + 9)
&& Ns100 != 0)
{
dest.tv_nsec += Ns100;
}
#endif
}
// (Def) is not set
void Set_From_FILETIME(const FILETIME &ft)
{
FT = ft;
// Prec = k_PropVar_TimePrec_CompatNTFS;
Prec = k_PropVar_TimePrec_Base + 7;
Ns100 = 0;
}
// (Def) is not set
// it set full form precision: k_PropVar_TimePrec_Base + numDigits
void Set_From_FiTime(const CFiTime &ts)
{
#ifdef _WIN32
FT = ts;
Prec = k_PropVar_TimePrec_Base + 7;
// Prec = k_PropVar_TimePrec_Base; // for debug
// Prec = 0; // for debug
Ns100 = 0;
#else
unsigned ns100;
FiTime_To_FILETIME_ns100(ts, FT, ns100);
Ns100 = (Byte)ns100;
Prec = k_PropVar_TimePrec_Base + 9;
#endif
}
void Set_From_Prop(const PROPVARIANT &prop)
{
FT = prop.filetime;
unsigned prec = 0;
unsigned ns100 = 0;
const unsigned prec_Temp = prop.wReserved1;
if (prec_Temp != 0
&& prec_Temp <= k_PropVar_TimePrec_1ns
&& prop.wReserved3 == 0)
{
const unsigned ns100_Temp = prop.wReserved2;
if (ns100_Temp < 100)
{
ns100 = ns100_Temp;
prec = prec_Temp;
}
}
Prec = (UInt16)prec;
Ns100 = (Byte)ns100;
Def = true;
}
};
struct CDirItem: public NWindows::NFile::NFind::CFileInfoBase
{
UString Name;
#ifndef UNDER_CE
CByteBuffer ReparseData;
#ifdef _WIN32
// UString ShortName;
CByteBuffer ReparseData2; // fixed (reduced) absolute links for WIM format
bool AreReparseData() const { return ReparseData.Size() != 0 || ReparseData2.Size() != 0; }
#else
bool AreReparseData() const { return ReparseData.Size() != 0; }
#endif // _WIN32
#endif // !UNDER_CE
void Copy_From_FileInfoBase(const NWindows::NFile::NFind::CFileInfoBase &fi)
{
(NWindows::NFile::NFind::CFileInfoBase &)*this = fi;
}
int PhyParent;
int LogParent;
int SecureIndex;
#ifdef _WIN32
#else
int OwnerNameIndex;
int OwnerGroupIndex;
#endif
// bool Attrib_IsDefined;
CDirItem():
PhyParent(-1)
, LogParent(-1)
, SecureIndex(-1)
#ifdef _WIN32
#else
, OwnerNameIndex(-1)
, OwnerGroupIndex(-1)
#endif
// , Attrib_IsDefined(true)
{
}
CDirItem(const NWindows::NFile::NFind::CFileInfo &fi,
int phyParent, int logParent, int secureIndex):
CFileInfoBase(fi)
, Name(fs2us(fi.Name))
#if defined(_WIN32) && !defined(UNDER_CE)
// , ShortName(fs2us(fi.ShortName))
#endif
, PhyParent(phyParent)
, LogParent(logParent)
, SecureIndex(secureIndex)
#ifdef _WIN32
#else
, OwnerNameIndex(-1)
, OwnerGroupIndex(-1)
#endif
{}
};
class CDirItems
{
UStringVector Prefixes;
CIntVector PhyParents;
CIntVector LogParents;
UString GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const;
HRESULT EnumerateDir(int phyParent, int logParent, const FString &phyPrefix);
public:
CObjectVector<CDirItem> Items;
bool SymLinks;
bool ScanAltStreams;
bool ExcludeDirItems;
bool ExcludeFileItems;
bool ShareForWrite;
/* it must be called after anotrher checks */
bool CanIncludeItem(bool isDir) const
{
return isDir ? !ExcludeDirItems : !ExcludeFileItems;
}
CDirItemsStat Stat;
#if !defined(UNDER_CE)
HRESULT SetLinkInfo(CDirItem &dirItem, const NWindows::NFile::NFind::CFileInfo &fi,
const FString &phyPrefix);
#endif
#if defined(_WIN32) && !defined(UNDER_CE)
CUniqBlocks SecureBlocks;
CByteBuffer TempSecureBuf;
bool _saclEnabled;
bool ReadSecure;
HRESULT AddSecurityItem(const FString &path, int &secureIndex);
HRESULT FillFixedReparse();
#endif
#ifndef _WIN32
C_UInt32_UString_Map OwnerNameMap;
C_UInt32_UString_Map OwnerGroupMap;
bool StoreOwnerName;
HRESULT FillDeviceSizes();
#endif
IDirItemsCallback *Callback;
CDirItems();
void AddDirFileInfo(int phyParent, int logParent, int secureIndex,
const NWindows::NFile::NFind::CFileInfo &fi);
HRESULT AddError(const FString &path, DWORD errorCode);
HRESULT AddError(const FString &path);
HRESULT ScanProgress(const FString &path);
// unsigned GetNumFolders() const { return Prefixes.Size(); }
FString GetPhyPath(unsigned index) const;
UString GetLogPath(unsigned index) const;
unsigned AddPrefix(int phyParent, int logParent, const UString &prefix);
void DeleteLastPrefix();
// HRESULT EnumerateOneDir(const FString &phyPrefix, CObjectVector<NWindows::NFile::NFind::CDirEntry> &files);
HRESULT EnumerateOneDir(const FString &phyPrefix, CObjectVector<NWindows::NFile::NFind::CFileInfo> &files);
HRESULT EnumerateItems2(
const FString &phyPrefix,
const UString &logPrefix,
const FStringVector &filePaths,
FStringVector *requestedPaths);
void ReserveDown();
};
struct CArcItem
{
UInt64 Size;
UString Name;
CArcTime MTime; // it can be mtime of archive file, if MTime is not defined for item in archive
bool IsDir;
bool IsAltStream;
bool Size_Defined;
bool Censored;
UInt32 IndexInServer;
CArcItem():
IsDir(false),
IsAltStream(false),
Size_Defined(false),
Censored(false)
{}
};
#endif
|