From 321e5f342e841b9898f300838c637898074eac26 Mon Sep 17 00:00:00 2001 From: TaurusXin Date: Sat, 6 Apr 2024 12:09:03 +0800 Subject: [PATCH] fix: parse UTF-8 path to lib --- CMakeLists.txt | 5 +++-- src/lib/libncmdump.cpp | 44 +++++++++++++++++++++++------------------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index caf42dc..d1edf00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,20 +19,21 @@ FILE(GLOB COMMON_SOURCES src/ncmcrypt.cpp src/utils/*.cpp) FILE(GLOB EXECUTABLE_SOURCES src/main.cpp) FILE(GLOB LIBRARY_HEADERS src/lib/libncmdump.h) FILE(GLOB LIBRARY_SOURCES src/lib/*.cpp) -FILE(GLOB WIN_EXEC_SOURCES src/platform/win32_init.cpp) +FILE(GLOB WIN_SOURCES src/platform/win32_init.cpp) if(WIN32) add_executable(ncmdump_exec ${COMMON_HEADERS} ${COMMON_SOURCES} ${EXECUTABLE_SOURCES} - ${WIN_EXEC_SOURCES} + ${WIN_SOURCES} ) add_library(ncmdump_lib SHARED ${COMMON_HEADERS} ${COMMON_SOURCES} ${LIBRARY_HEADERS} ${LIBRARY_SOURCES} + ${WIN_SOURCES} ) set_target_properties(ncmdump_lib PROPERTIES OUTPUT_NAME "libncmdump") diff --git a/src/lib/libncmdump.cpp b/src/lib/libncmdump.cpp index c0911e0..ad5c94f 100644 --- a/src/lib/libncmdump.cpp +++ b/src/lib/libncmdump.cpp @@ -1,27 +1,31 @@ #include "libncmdump.h" +#include + +namespace fs = std::filesystem; extern "C" { - API NeteaseCrypt* CreateNeteaseCrypt(const char* path) { - return new NeteaseCrypt(std::string(path)); - } + API NeteaseCrypt* CreateNeteaseCrypt(const char* path) { + fs::path fPath = fs::u8path(path); + return new NeteaseCrypt(fPath.u8string()); + } - API int Dump(NeteaseCrypt* neteaseCrypt) { - try - { - neteaseCrypt->Dump(); - } - catch (const std::invalid_argument& e) - { - return 1; - } - return 0; - } + API int Dump(NeteaseCrypt* neteaseCrypt) { + try + { + neteaseCrypt->Dump(); + } + catch (const std::invalid_argument& e) + { + return 1; + } + return 0; + } - API void FixMetadata(NeteaseCrypt* neteaseCrypt) { - neteaseCrypt->FixMetadata(); - } + API void FixMetadata(NeteaseCrypt* neteaseCrypt) { + neteaseCrypt->FixMetadata(); + } - API void DestroyNeteaseCrypt(NeteaseCrypt* neteaseCrypt) { - delete neteaseCrypt; - } + API void DestroyNeteaseCrypt(NeteaseCrypt* neteaseCrypt) { + delete neteaseCrypt; + } } \ No newline at end of file