static void hexstrTest() { unsigned char buf[6] = {1, 2, 33, 255, 0, 18}; unsigned char buf2[6] = {0}; AutoFree s(_MemToHex(&buf)); utassert(str::Eq(s, "010221ff0012")); bool ok = _HexToMem(s, &buf2); utassert(ok); utassert(memeq(buf, buf2, sizeof(buf))); FILETIME ft1, ft2; GetSystemTimeAsFileTime(&ft1); s.Set(_MemToHex(&ft1)); _HexToMem(s, &ft2); DWORD diff = FileTimeDiffInSecs(ft1, ft2); utassert(0 == diff); utassert(FileTimeEq(ft1, ft2)); s.Set(str::MemToHex(nullptr, 0)); utassert(str::Eq(s, "")); ok = str::HexToMem(s, nullptr, 0); utassert(ok); }
// TODO: create in TEMP directory instead? static WCHAR* GetThumbnailPath(const WCHAR* filePath) { // create a fingerprint of a (normalized) path for the file name // I'd have liked to also include the file's last modification time // in the fingerprint (much quicker than hashing the entire file's // content), but that's too expensive for files on slow drives unsigned char digest[16]; // TODO: why is this happening? Seen in crash reports e.g. 35043 if (!filePath) return nullptr; OwnedData pathU(str::conv::ToUtf8(filePath)); if (!pathU.Get()) return nullptr; if (path::HasVariableDriveLetter(filePath)) pathU.Get()[0] = '?'; // ignore the drive letter, if it might change CalcMD5Digest((unsigned char*)pathU.Get(), str::Len(pathU.Get()), digest); AutoFree fingerPrint(_MemToHex(&digest)); AutoFreeW thumbsPath(AppGenDataFilename(THUMBNAILS_DIR_NAME)); if (!thumbsPath) return nullptr; AutoFreeW fname(str::conv::FromAnsi(fingerPrint)); return str::Format(L"%s\\%s.png", thumbsPath.Get(), fname.Get()); }