fix: cannot recognize non-ASCII file name on Windows

This commit is contained in:
TaurusXin 2024-02-12 21:52:56 +08:00
parent 1cfc29560d
commit 5cfe439e48
Signed by: taurusxin
GPG Key ID: C334DCA04AC2D2CC
2 changed files with 18 additions and 14 deletions

View File

@ -19,6 +19,12 @@ target_include_directories(ncmdump PRIVATE taglib/taglib)
target_include_directories(ncmdump PRIVATE taglib/taglib/toolkit)
target_include_directories(ncmdump PRIVATE taglib/taglib/mpeg/id3v2)
if(WIN32)
if(CMAKE_COMPILER_IS_GNUCXX)
target_link_options(ncmdump PRIVATE -O2 -municode)
endif()
endif()
include(GNUInstallDirs)
install(TARGETS ncmdump
BUNDLE DESTINATION .

View File

@ -5,7 +5,7 @@
#include <vector>
#include <filesystem>
#if defined(_WIN32) && defined(_MSC_VER)
#if defined(_WIN32)
#include <Windows.h>
#endif
@ -47,13 +47,13 @@ void processFilesInFolder(const fs::path& folderPath) {
}
}
#if defined(_WIN32) && defined(_MSC_VER)
#if defined(_WIN32)
int wmain(int argc, wchar_t* argv[])
#else
int main(int argc, char **argv)
#endif
{
#if defined(_WIN32) && defined(_MSC_VER)
#if defined(_WIN32) && defined(__MINGW64__)
SetConsoleOutputCP(CP_UTF8);
#endif
@ -67,7 +67,7 @@ int main(int argc, char **argv)
bool folderProvided = false;
#if defined(_WIN32) && defined(_MSC_VER)
#if defined(_WIN32)
#define COMPARE_STR(s1, s2) (wcscmp(s1, s2) == 0)
#define HELP_SHORT L"-h"
#define HELP_LONG L"--help"
@ -95,11 +95,9 @@ int main(int argc, char **argv)
return 1;
}
} else {
#if defined(_WIN32) && defined(_MSC_VER)
int multiByteStrSize = WideCharToMultiByte(CP_UTF8, 0, argv[1], -1, NULL, 0, NULL, NULL);
char *multiByteStr = new char[multiByteStrSize];
WideCharToMultiByte(CP_UTF8, 0, argv[i], -1, multiByteStr, multiByteStrSize, NULL, NULL);
fs::path path(multiByteStr);
#if defined(_WIN32)
std::wstring wFilePath(argv[i]);
fs::path path(wFilePath);
#else
fs::path path(argv[i]);
#endif