예제 #1
0
static void BenchMD5Size(void *data, size_t dataSize, char *desc)
{
    unsigned char d1[16], d2[16];
    Timer t1;
    CalcMD5Digest((unsigned char*)data, dataSize, d1);
    double dur1 = t1.GetTimeInMs();

    Timer t2;
    CalcMD5DigestWin(data, dataSize, d2);
    bool same = memeq(d1, d2, 16);
    CrashAlwaysIf(!same);
    double dur2 = t2.GetTimeInMs();
    double diff = dur1 - dur2;
    printf("%s\nCalcMD5Digest   : %f ms\nCalcMD5DigestWin: %f ms\ndiff: %f\n", desc, dur1, dur2, diff);
}
예제 #2
0
// 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];
    ScopedMem<char> pathU(str::conv::ToUtf8(filePath));
    if (path::HasVariableDriveLetter(filePath))
        pathU[0] = '?'; // ignore the drive letter, if it might change
    CalcMD5Digest((unsigned char *)pathU.Get(), str::Len(pathU), digest);
    ScopedMem<char> fingerPrint(str::MemToHex(digest, 16));

    ScopedMem<WCHAR> thumbsPath(AppGenDataFilename(THUMBNAILS_DIR_NAME));
    if (!thumbsPath)
        return NULL;
    ScopedMem<WCHAR> fname(str::conv::FromAnsi(fingerPrint));

    return str::Format(L"%s\\%s.png", thumbsPath, fname);
}
예제 #3
0
// 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());
}