| 350 | } |
| 351 | |
| 352 | BOOL ShellCache::IsPathAllowed(LPCWSTR path) |
| 353 | { |
| 354 | RefreshIfNeeded(); |
| 355 | Locker lock(m_critSec); |
| 356 | const Tristate allowed = pathFilter.IsPathAllowed(path); |
| 357 | if (allowed != Tristate::Unknown) |
| 358 | return allowed == Tristate::True ? TRUE : FALSE; |
| 359 | |
| 360 | UINT drivetype = 0; |
| 361 | const int drivenumber = PathGetDriveNumber(path); |
| 362 | if ((drivenumber >= 0) && (drivenumber <= 25)) |
| 363 | { |
| 364 | drivetype = drivetypecache[drivenumber]; |
| 365 | if ((drivetype == -1) || ((GetTickCount64() - drivetypeticker) > DRIVETYPETIMEOUT)) |
| 366 | { |
| 367 | if ((DWORD(drivefloppy) == 0) && ((drivenumber == 0) || (drivenumber == 1))) |
| 368 | drivetype = DRIVE_REMOVABLE; |
| 369 | else if (PathIsNetworkPath(path)) |
| 370 | drivetype = DRIVE_REMOTE; |
| 371 | else |
| 372 | { |
| 373 | wchar_t pathbuf[MAX_PATH + 4] = { 0 }; // MAX_PATH ok here. PathStripToRoot works with partial paths too. |
| 374 | wcsncpy_s(pathbuf, path, _countof(pathbuf) - 1); |
| 375 | PathStripToRoot(pathbuf); |
| 376 | PathAddBackslash(pathbuf); |
| 377 | CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L": GetDriveType for %s, Drive %d\n", pathbuf, drivenumber); |
| 378 | drivetype = GetDriveType(pathbuf); |
| 379 | } |
| 380 | drivetypecache[drivenumber] = drivetype; |
| 381 | drivetypeticker = GetTickCount64(); |
| 382 | } |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | if (PathIsNetworkPath(path)) |
| 387 | drivetype = DRIVE_REMOTE; |
| 388 | else |
| 389 | { |
| 390 | wchar_t pathbuf[MAX_PATH + 4] = { 0 }; // MAX_PATH ok here. PathStripToRoot works with partial paths too. |
| 391 | wcsncpy_s(pathbuf, path, _countof(pathbuf) - 1); |
| 392 | PathStripToRoot(pathbuf); |
| 393 | PathAddBackslash(pathbuf); |
| 394 | if (wcsncmp(pathbuf, drivetypepathcache, MAX_PATH - 1) == 0) // MAX_PATH ok. |
| 395 | drivetype = drivetypecache[26]; |
| 396 | else |
| 397 | { |
| 398 | CTraceToOutputDebugString::Instance()(_T(__FUNCTION__) L"GetDriveType for %s\n", pathbuf); |
| 399 | drivetype = GetDriveType(pathbuf); |
| 400 | drivetypecache[26] = drivetype; |
| 401 | wcsncpy_s(drivetypepathcache, pathbuf, MAX_PATH - 1); // MAX_PATH ok. |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | if ((drivetype == DRIVE_REMOVABLE) && (!IsRemovable())) |
| 406 | return FALSE; |
| 407 | if ((drivetype == DRIVE_FIXED) && (!IsFixed())) |
| 408 | return FALSE; |
| 409 | if (((drivetype == DRIVE_REMOTE) || (drivetype == DRIVE_NO_ROOT_DIR)) && (!IsRemote())) |
no test coverage detected