Implement utils_file_exists, use wide strings for paths

This commit is contained in:
mkrsym1 2023-08-04 21:09:16 +03:00
parent 4911f8d903
commit 592ce62e6b
4 changed files with 12 additions and 7 deletions

View File

@ -2,6 +2,7 @@
#include <stdint.h>
uint32_t utils_file_crc32c(const char *filePath);
int utils_file_exists(const wchar_t *filePath);
uint32_t utils_file_crc32c(const wchar_t *filePath);
char utils_env_enabled(const char *env);

View File

@ -24,7 +24,7 @@ const struct crc_id_pair HI3_REGIONS[] = {
};
void hi3_fill_data(struct game_data *buf) {
uint32_t crc = utils_file_crc32c("UnityPlayer.dll");
uint32_t crc = utils_file_crc32c(L"UnityPlayer.dll");
enum game_id id = GAME_INVALID;
for (size_t i = 0; i < sizeof(HI3_REGIONS) / sizeof(struct crc_id_pair); i++) {

View File

@ -70,7 +70,7 @@ static void _unityplayer_callback(HMODULE unityModule) {
}
void hsr_fill_data(struct game_data *buf) {
uint32_t crc = utils_file_crc32c("UnityPlayer.dll");
uint32_t crc = utils_file_crc32c(L"UnityPlayer.dll");
enum game_id id = GAME_INVALID;
for (size_t i = 0; i < sizeof(HSR_REGIONS) / sizeof(struct crc_id_pair); i++) {

View File

@ -5,10 +5,14 @@
#include <utils.h>
uint32_t utils_file_crc32c(const char *filePath) {
HANDLE file = CreateFileA(filePath, FILE_READ_ACCESS, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
int utils_file_exists(const wchar_t *filePath) {
return GetFileAttributesW(filePath) != INVALID_FILE_ATTRIBUTES;
}
uint32_t utils_file_crc32c(const wchar_t *filePath) {
HANDLE file = CreateFileW(filePath, FILE_READ_ACCESS, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (!file) {
msg_err_a("Could not open file: %s", filePath);
msg_err_w(L"Could not open file: %ls", filePath);
}
LARGE_INTEGER fileSize;
@ -17,7 +21,7 @@ uint32_t utils_file_crc32c(const char *filePath) {
HANDLE hMap = CreateFileMappingA(file, NULL, PAGE_READONLY, 0, 0, NULL);
char *map = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
if (!map) {
msg_err_a("Could not create file mapping for %s", filePath);
msg_err_w(L"Could not create file mapping for %ls", filePath);
}
uint32_t crc = crc32c(0, (unsigned char*)map, fileSize.QuadPart);