VOID WINAPI HashCalcWalkDirectory( PHASHCALCCONTEXT phcctx, PTSTR pszPath, UINT cchPath ) { HANDLE hFind; WIN32_FIND_DATA finddata; PTSTR pszPathAppend = pszPath + cchPath; *pszPathAppend = TEXT('\\'); SSCpy2Ch(++pszPathAppend, TEXT('*'), 0); if ((hFind = FindFirstFile(pszPath, &finddata)) == INVALID_HANDLE_VALUE) return; do { // Add 1 to the length since we are also going to count the slash that // was added at the end of the directory UINT cchLeaf = (UINT)SSLen(finddata.cFileName) + 1; UINT cchNew = cchPath + cchLeaf; if (phcctx->status == CANCEL_REQUESTED) break; if ( (!(finddata.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE)) && (cchNew < MAX_PATH_BUFFER - 2) ) { SSChainNCpy(pszPathAppend, finddata.cFileName, cchLeaf); if (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // Directory: Recurse if (!IsSpecialDirectoryName(finddata.cFileName)) HashCalcWalkDirectory(phcctx, pszPath, cchNew); } else { // File: Add to the list UINT cbPathBuffer = (cchNew + 1) * sizeof(TCHAR); PHASHCALCITEM pItem = SLAddItem(phcctx->hList, NULL, sizeof(HASHCALCITEM) + cbPathBuffer); if (pItem) { pItem->bValid = FALSE; pItem->cchPath = cchNew; memcpy(pItem->szPath, pszPath, cbPathBuffer); if (phcctx->cchMax < cchNew) phcctx->cchMax = cchNew; ++phcctx->cTotal; } } } } while (FindNextFile(hFind, &finddata)); FindClose(hFind); }
LONG_PTR WINAPI HashVerifyFindItem( PHASHVERIFYCONTEXT phvctx, LPNMLVFINDITEM pfi ) { PHASHVERIFYITEM pItem; INT cchCompare, iStart = pfi->iStart; LONG_PTR i; if (pfi->lvfi.flags & (LVFI_PARAM | LVFI_NEARESTXY)) goto not_found; // Unsupported search types if (!(pfi->lvfi.flags & (LVFI_PARTIAL | LVFI_STRING))) goto not_found; // No valid search type specified // According to the documentation, LVFI_STRING without a corresponding // LVFI_PARTIAL should match the FULL string, but when the user sends // keyboard input (which uses a partial match), the notification does not // have the LVFI_PARTIAL flag, so we should just always assume LVFI_PARTIAL // INT cchCompare = (pfi->lvfi.flags & LVFI_PARTIAL) ? 0 : 1; // cchCompare += SSLen(pfi->lvfi.psz); // The above code should have been correct, but it is not... cchCompare = (INT)SSLen(pfi->lvfi.psz); // Fix out-of-range indices; by casting to unsigned, we also catch negatives if ((UINT)iStart > phvctx->cTotal) iStart = phvctx->cTotal; for (i = iStart; i < (INT)phvctx->cTotal; ++i) { pItem = phvctx->index[i]; if (StrCmpNI(pItem->pszDisplayName, pfi->lvfi.psz, cchCompare) == 0) return(i); } if (pfi->lvfi.flags & LVFI_WRAP) { for (i = 0; i < iStart; ++i) { pItem = phvctx->index[i]; if (StrCmpNI(pItem->pszDisplayName, pfi->lvfi.psz, cchCompare) == 0) return(i); } } not_found: return(-1); }
BOOL WINAPI RegSetSZ( HKEY hKey, LPCTSTR lpValueName, LPCTSTR lpData ) { return(RegSetValueEx(hKey, lpValueName, 0, REG_SZ, (LPBYTE)lpData, ((DWORD)SSLen(lpData) + 1) * sizeof(lpData[0])) == ERROR_SUCCESS); }