fix: 修复遍历缓存文件的错误

This commit is contained in:
刘旭 2022-07-12 19:47:04 +08:00
commit 6760a2c869

View file

@ -269,10 +269,11 @@ void EffectCacheManager::Save(std::string_view effectName, std::string_view hash
std::wregex regex(fmt::format(L"^{}_{:02x}[0-9,a-f]{{{}}}$", StrUtils::UTF8ToUTF16(effectName), desc.flags,
Utils::Hasher::Get().GetHashLength() * 2), std::wregex::optimize | std::wregex::nosubs);
WIN32_FIND_DATA findData;
HANDLE hFind = Utils::SafeHandle(FindFirstFile(StrUtils::ConcatW(CACHE_DIR, L"\\*").c_str(), &findData));
WIN32_FIND_DATA findData{};
HANDLE hFind = Utils::SafeHandle(FindFirstFileEx(StrUtils::ConcatW(CACHE_DIR, L"\\*").c_str(),
FindExInfoBasic, &findData, FindExSearchNameMatch, nullptr, FIND_FIRST_EX_LARGE_FETCH));
if (hFind) {
while (FindNextFile(hFind, &findData)) {
do {
if (StrUtils::StrLen(findData.cFileName) < 8) {
continue;
}
@ -286,7 +287,8 @@ void EffectCacheManager::Save(std::string_view effectName, std::string_view hash
Logger::Get().Win32Error(StrUtils::Concat("删除缓存文件 ",
StrUtils::UTF16ToUTF8(findData.cFileName), " 失败"));
}
}
} while (FindNextFile(hFind, &findData));
FindClose(hFind);
} else {
Logger::Get().Win32Error("查找缓存文件失败");