Fix move_matching_files Windows codepath in migration code

Need to turn strings wide for the UTF-16 Win32 API functions...
This commit is contained in:
ROllerozxa 2026-05-31 21:49:16 +02:00
commit f564ba2e3f
2 changed files with 7 additions and 11 deletions

View file

@ -274,11 +274,6 @@ if(EMSCRIPTEN)
set(CMAKE_EXE_LINKER_FLAGS " ${LIBRARY_FLAGS} -pthread -sPTHREAD_POOL_SIZE=20 -sINITIAL_MEMORY=2013265920 -sALLOW_MEMORY_GROWTH=1 -sTOTAL_STACK=16Mb -sFETCH=1")
endif()
if(WIN32)
# Clang 22 made this an error which breaks compilation, downgrade to warning again
string(APPEND COMMON_FLAGS " -Wno-error=incompatible-pointer-types ")
endif()
set(COMMON_FLAGS_DEBUG "${COMMON_FLAGS} -O0 -ggdb -DDEBUG=1")
set(COMMON_FLAGS_RELEASE "${COMMON_FLAGS} -DNDEBUG=1 -fomit-frame-pointer")

View file

@ -178,8 +178,9 @@ static int dir_exists(const char *path) {
static void move_matching_files(const char *srcdir, const char *dstdir, const char *ext) {
#ifdef TMS_BACKEND_WINDOWS
char pattern[MAX_PATH];
snprintf(pattern, sizeof(pattern), "%s\\*.%s", srcdir, ext);
// As Windows is UTF-16 and we have UNICODE defined, we need to convert everything to UTF-16...
wchar_t pattern[MAX_PATH];
swprintf(pattern, MAX_PATH, L"%hs\\*.%hs", srcdir, ext);
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(pattern, &ffd);
@ -188,11 +189,11 @@ static void move_matching_files(const char *srcdir, const char *dstdir, const ch
do {
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
char src[MAX_PATH], dst[MAX_PATH];
snprintf(src, sizeof(src), "%s\\%s", srcdir, ffd.cFileName);
snprintf(dst, sizeof(dst), "%s\\%s", dstdir, ffd.cFileName);
wchar_t src[MAX_PATH], dst[MAX_PATH];
swprintf(src, MAX_PATH, L"%hs\\%s", srcdir, ffd.cFileName);
swprintf(dst, MAX_PATH, L"%hs\\%s", dstdir, ffd.cFileName);
rename(src, dst);
MoveFile(src, dst);
} while (FindNextFile(hFind, &ffd) != 0);
FindClose(hFind);