示例#1
0
	const RawDataDAT2::s_info& DAT2::getInfo(const std::string& name) const {
		type_filelist::const_iterator i = findFileEntry(name);
		if (i == m_filelist.end()) {
			throw NotFound(name);
		}
		return i->second;
	}
示例#2
0
// checkFileChanges(watcher)
static FileEntry* checkFileChanges(ClipWatcher* watcher)
{
    WCHAR dirpath[MAX_PATH];
    StringCchPrintf(dirpath, _countof(dirpath), L"%s\\*.*", watcher->srcdir);

    WIN32_FIND_DATA data;
    FileEntry* found = NULL;

    HANDLE fft = FindFirstFile(dirpath, &data);
    if (fft == NULL) goto fail;

    for (;;) {
        LPWSTR name = data.cFileName;
        int index = rindex(name, L'.');
        if (0 <= index && wcsnicmp(name, watcher->name, index) != 0) {
            WCHAR path[MAX_PATH];
            StringCchPrintf(path, _countof(path), L"%s\\%s",
                            watcher->srcdir, name);
            HANDLE fp = CreateFile(path, GENERIC_READ, FILE_SHARE_READ,
                                   NULL, OPEN_EXISTING,
                                   (FILE_ATTRIBUTE_NORMAL |
                                    FILE_FLAG_NO_BUFFERING),
                                   NULL);
            if (fp != INVALID_HANDLE_VALUE) {
                DWORD hash = getFileHash(fp, 256);
                FILETIME mtime;
                GetFileTime(fp, NULL, NULL, &mtime);
                if (logfp != NULL) {
                    fwprintf(logfp, L"check: name=%s (%08x, %08x)\n",
                             name, hash, mtime.dwLowDateTime);
                }
                FileEntry* entry = findFileEntry(watcher->files, path);
                if (entry == NULL) {
                    if (logfp != NULL) {
                        fwprintf(logfp, L"added: name=%s\n", name);
                    }
                    entry = (FileEntry*) malloc(sizeof(FileEntry));
                    StringCchCopy(entry->path, _countof(entry->path), path);
                    entry->hash = hash;
                    entry->mtime = mtime;
                    entry->next = watcher->files;
                    watcher->files = entry;
                    found = entry;
                } else if (hash != entry->hash ||
                           CompareFileTime(&mtime, &(entry->mtime)) != 0) {
                    if (logfp != NULL) {
                        fwprintf(logfp, L"updated: name=%s\n", name);
                    }
                    entry->hash = hash;
                    entry->mtime = mtime;
                    found = entry;
                }
                CloseHandle(fp);
            }
        }
        if (!FindNextFile(fft, &data)) break;
    }
    FindClose(fft);

fail:
    return found;
}
示例#3
0
	bool DAT2::fileExists(const std::string& name) const {
		return findFileEntry(name) != m_filelist.end();
	}