fix: 修复视频无法从vfs加载

This commit is contained in:
2025-03-12 18:02:36 +08:00
parent c5f5899f20
commit f15d9fecaa
3 changed files with 71 additions and 5 deletions

43
vfs.cpp
View File

@@ -3,6 +3,7 @@
#include "str_util.h"
#include "fileop.h"
#include "shlwapi.h"
#include "time_util.h"
VFS::VFS() {
WCHAR exePath[MAX_PATH];
@@ -42,7 +43,7 @@ bool VFS::AddArchive(std::string path) {
}
std::string name = st.name;
name = str_util::str_replace(name, "/", "\\");
files[name] = st.size;
files[name] = st;
}
return true;
}
@@ -74,7 +75,7 @@ bool VFS::AddArchiveFromResource(HMODULE hModule, int resourceID) {
}
std::string name = st.name;
name = str_util::str_replace(name, "/", "\\");
files[name] = st.size;
files[name] = st;
}
return true;
}
@@ -193,7 +194,7 @@ DWORD VFS::GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh) {
}
auto data = *f;
auto name = data.second;
auto size = files[name];
auto size = files[name].size;
if (lpFileSizeHigh) {
*lpFileSizeHigh = size >> 32;
}
@@ -208,7 +209,7 @@ BOOL VFS::GetFileSizeEx(HANDLE hFile, PLARGE_INTEGER lpFileSize) {
}
auto data = *f;
auto name = data.second;
auto size = files[name];
auto size = files[name].size;
lpFileSize->LowPart = size & 0xFFFFFFFF;
lpFileSize->HighPart = size >> 32;
return TRUE;
@@ -239,3 +240,37 @@ DWORD VFS::SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceTo
std::string VFS::GetBasePath() {
return base_path;
}
BOOL VFS::GetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation) {
std::string path;
if (!wchar_util::wstr_to_str(path, lpFileName, CP_UTF8)) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
path = str_util::str_replace(path, "/", "\\");
if (fileop::isabs(path)) {
path = fileop::relpath(path, base_path);
}
auto c = files.find(path);
if (c == files.end()) {
SetLastError(ERROR_FILE_NOT_FOUND);
return FALSE;
}
auto st = (*c).second;
if (fInfoLevelId == GetFileExInfoStandard) {
if (!lpFileInformation) {
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
WIN32_FILE_ATTRIBUTE_DATA data;
data.dwFileAttributes = FILE_ATTRIBUTE_READONLY;
time_util::time_t_to_file_time(st.mtime, &data.ftLastWriteTime);
data.ftCreationTime = data.ftLastWriteTime;
data.ftLastAccessTime = data.ftLastWriteTime;
data.nFileSizeHigh = st.size >> 32;
data.nFileSizeLow = st.size & 0xFFFFFFFF;
memcpy(lpFileInformation, &data, sizeof(data));
return TRUE;
}
return FALSE;
}