From a90ae0249d3b302dc259fa5e58e6443821cc9fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 14 Sep 2026 22:42:16 +0800 Subject: [PATCH] IO (Windows): prefers unicode APIs --- src/common/impl/io_windows.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/common/impl/io_windows.c b/src/common/impl/io_windows.c index 65115a34d..48380c2ff 100644 --- a/src/common/impl/io_windows.c +++ b/src/common/impl/io_windows.c @@ -1,4 +1,5 @@ #include "fastfetch.h" +#include "common/debug.h" #include "common/io.h" #include "common/strutil.h" #include "common/time.h" @@ -160,7 +161,9 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data) { FF_AUTO_CLOSE_FD HANDLE handle = CreateFileW(fileNameW, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (handle == INVALID_HANDLE_VALUE) { - if (GetLastError() == ERROR_PATH_NOT_FOUND) { + DWORD errorCode = GetLastError(); + FF_DEBUG("Failed to open file: %s - %s", fileName, ffDebugWin32Error(errorCode)); + if (errorCode == ERROR_PATH_NOT_FOUND) { if (!createSubfolders(fileNameW)) { return false; } @@ -498,11 +501,25 @@ FFNativeFD ffGetNullFD(void) { } bool ffRemoveFile(const char* fileName) { - return DeleteFileA(fileName) != FALSE; + wchar_t fileNameW[MAX_PATH]; + ULONG len; + if (!NT_SUCCESS(RtlUTF8ToUnicodeN(fileNameW, (ULONG) sizeof(fileNameW), &len, fileName, (ULONG) strlen(fileName) + 1))) { + return false; + } + + bool ret = DeleteFileW(fileNameW) != FALSE; + FF_DEBUG("Deleting file: %s - %s", fileName, ret ? "Success" : ffDebugWin32Error(GetLastError())); + return ret; } uint64_t ffPathGetMtime(const char* path) { - FF_AUTO_CLOSE_FD HANDLE handle = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + wchar_t fileNameW[MAX_PATH]; + ULONG len; + if (!NT_SUCCESS(RtlUTF8ToUnicodeN(fileNameW, (ULONG) sizeof(fileNameW), &len, path, (ULONG) strlen(path) + 1))) { + return 0; + } + + FF_AUTO_CLOSE_FD HANDLE handle = CreateFileW(fileNameW, GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (handle == INVALID_HANDLE_VALUE) { // file doesn't exist or isn't accessible return 0;