更新VFS类以支持大小写不敏感的文件查找,修复文件未找到时的错误处理

This commit is contained in:
2025-03-03 20:34:05 +08:00
parent e6a24c54a6
commit 446f41deac
3 changed files with 35 additions and 7 deletions

24
vfs.hpp
View File

@@ -3,6 +3,28 @@
#include <string>
#include <unordered_map>
#include <Windows.h>
#include "str_util.h"
struct CaseInsensitiveHash {
size_t operator()(const std::string& str) const {
// 创建字符串的小写副本
std::string lowercaseStr = str_util::tolower(str);
// 对小写字符串使用标准哈希函数
return std::hash<std::string>{}(lowercaseStr);
}
};
// 比较函数,忽略大小写
struct CaseInsensitiveEqual {
bool operator()(const std::string& left, const std::string& right) const {
return left.size() == right.size() &&
std::equal(left.begin(), left.end(), right.begin(),
[](unsigned char a, unsigned char b) {
return std::tolower(a) == std::tolower(b);
});
}
};
class VFS {
public:
@@ -17,7 +39,7 @@ class VFS {
void CloseHandle(HANDLE hFile);
DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
std::unordered_map<std::string, zip_uint64_t> files;
std::unordered_map<std::string, zip_uint64_t, CaseInsensitiveHash, CaseInsensitiveEqual> files;
std::string GetBasePath();
private:
std::string base_path;