#include "FaceApp.h" #include std::wstring UTF8ToWideString(const std::string& utf8str) { if (utf8str.empty()) return L""; int wideLen = MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), -1, nullptr, 0); if (wideLen == 0) { throw std::runtime_error("UTF-8转换失败"); } std::vector buffer(wideLen); MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), -1, buffer.data(), wideLen); return std::wstring(buffer.data()); } std::wstring ReadUTF8File(const std::string& filePath) { std::ifstream file(filePath, std::ios::binary); if (!file.is_open()) { throw std::runtime_error("无法打开UTF-8文件: " + filePath); } // 读取文件所有内容 std::string content((std::istreambuf_iterator(file)), std::istreambuf_iterator()); file.close(); // 将UTF-8字符串转换为宽字符串 return UTF8ToWideString(content); } std::wstring ReadFileWithChinesePath(const std::wstring& filePath) { // 使用二进制模式打开文件 std::ifstream file(filePath, std::ios::binary); if (!file.is_open()) { std::wcout << L"无法打开文件: " << filePath << std::endl; return L""; } // 读取文件内容到std::string std::string context; file.seekg(0, std::ios::end); context.resize(file.tellg()); file.seekg(0, std::ios::beg); file.read(&context[0], context.size()); file.close(); return UTF8ToWideString(context); } int main() { std::string path = "chinese.txt"; std::wstring chinese = ReadUTF8File(path); std::wstring chinese_path = UTF8ToWideString("d:/测试目录/中文文件.txt"); std::wstring content = ReadFileWithChinesePath(chinese_path); InitArg init_arg; Motion motion; motion.type = "bottom_makeup"; motion.technique = "base_makeup"; motion.step = "press2"; motion.show_type = "direction"; motion.png_name = "test"; motion.png_num = 1; # init_arg.motion = motion; //motion.type = "底妆"; //motion.technique = "基础上妆"; //motion.step = "2按压"; //motion.show_type = "区域"; //motion.png_name = "pic"; //motion.png_num = 1; init_arg.action_fps = 3; init_arg.zoom = 1.5f; string json_str = json(init_arg).dump(); FaceApp app; app.SetInitArg(json_str.c_str()); app.initVulkan(); app.mainLoop(); //try { // app.mainLoop(); //} catch (const std::exception& e) { // std::cerr << e.what() << std::endl; // return EXIT_FAILURE; //} app.cleanup(); return EXIT_SUCCESS; }