fix loading error when loading from Chinese path

pull/2/head
ink-soul 2023-06-13 14:50:25 +08:00
parent 59ea17fe3f
commit d8f01324d0
3 changed files with 14 additions and 15 deletions

View File

@ -1,10 +1,3 @@
/*
* Vulkan utilities
*
* Copyright(C) 2018 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license(MIT) (http://opensource.org/licenses/MIT)
*/
#pragma once #pragma once

View File

@ -1687,23 +1687,27 @@ PlumageRender::PlumageRender()
// TO DO : language switch // TO DO : language switch
if (gui->header(chineseUI.model)) { if (gui->header(chineseUI.model)) {
if (gui->button(chineseUI.openNewModel)) { if (gui->button(chineseUI.openNewModel)) {
std::string filename = ""; std::wstring filename = L"";
char buffer[MAX_PATH]; wchar_t buffer[MAX_PATH];
OPENFILENAME ofn; OPENFILENAMEW ofn;
ZeroMemory(&buffer, sizeof(buffer)); ZeroMemory(&buffer, sizeof(buffer));
ZeroMemory(&ofn, sizeof(ofn)); ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); ofn.lStructSize = sizeof(ofn);
ofn.lpstrFilter = "glTF files\0*.gltf;*.glb\0"; ofn.lpstrFilter = L"glTF files\0*.gltf;*.glb\0";
ofn.lpstrFile = buffer; ofn.lpstrFile = buffer;
ofn.nMaxFile = MAX_PATH; ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = "Select a glTF file to load"; ofn.lpstrTitle = L"Select a glTF file to load";
ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
if (GetOpenFileNameA(&ofn)) { if (GetOpenFileNameW(&ofn)) {
filename = buffer; filename = buffer;
} }
if (!filename.empty()) { if (!filename.empty()) {
vkDeviceWaitIdle(device); vkDeviceWaitIdle(device);
loadScene(filename); std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::string stringFilename = converter.to_bytes(filename);
loadScene(stringFilename);
setupDescriptors(); setupDescriptors();
updateCBs = true; updateCBs = true;
} }

View File

@ -8,6 +8,8 @@
#include <chrono> #include <chrono>
#include <map> #include <map>
#include <io.h> #include <io.h>
#include <locale>
#include <codecvt>
#include "algorithm" #include "algorithm"