android 平台跑通中文路径
This commit is contained in:
@@ -21,6 +21,34 @@ void VK_CHECK(VkResult ret)
|
||||
//#endif
|
||||
// return path;
|
||||
//}
|
||||
#ifdef _WIN32
|
||||
std::vector<unsigned char> AppBase::readFileUnsignedCharWin32(const std::wstring path, bool example)
|
||||
{
|
||||
std::vector<unsigned char> buffer;
|
||||
|
||||
std::wstring enginePath = L"app/src/main/assets/" + path;
|
||||
if (example)
|
||||
{
|
||||
enginePath = L"example/src/main/assets/" + path;
|
||||
}
|
||||
std::ifstream file{ enginePath, std::ios::ate | std::ios::binary };
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
throw std::runtime_error("failed to open file: ");
|
||||
}
|
||||
|
||||
size_t fileSize = static_cast<size_t>(file.tellg());
|
||||
buffer.resize(fileSize);
|
||||
|
||||
file.seekg(0);
|
||||
file.read((char*)buffer.data(), fileSize);
|
||||
file.close();
|
||||
|
||||
|
||||
return buffer;
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
std::vector<unsigned char> AppBase::readFileUnsignedChar(const std::string& path, bool example)
|
||||
{
|
||||
|
||||
+19
-1
@@ -17,6 +17,7 @@
|
||||
#define logOut std::cout
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include "../app/src/main/cpp/AndroidOut.h"
|
||||
#define logOut aout
|
||||
@@ -69,7 +70,7 @@ public:
|
||||
//std::string getPath(const std::string path);
|
||||
VkShaderModule createShaderModule(VkDevice& device, const std::vector<char>& code);
|
||||
const std::vector<const char*> validationLayers = {"VK_LAYER_KHRONOS_validation"};
|
||||
protected:
|
||||
|
||||
long long getCurrentTimeMillis() {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
auto duration = now.time_since_epoch();
|
||||
@@ -87,6 +88,23 @@ protected:
|
||||
void pickPhysicalDevice(VkPhysicalDevice& physicalDevice, VkSurfaceKHR& surface);
|
||||
#ifdef _WIN32
|
||||
GLFWwindow *window;
|
||||
std::vector<unsigned char> readFileUnsignedCharWin32(const std::wstring path, bool example);
|
||||
static 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<wchar_t> buffer(wideLen);
|
||||
MultiByteToWideChar(CP_UTF8, 0, utf8str.c_str(), -1,
|
||||
buffer.data(), wideLen);
|
||||
|
||||
return std::wstring(buffer.data());
|
||||
}
|
||||
#endif
|
||||
|
||||
bool enableValidationLayers = true;
|
||||
|
||||
@@ -639,10 +639,10 @@ Texture Application::loadTexture(std::string path, Texture& tex, bool srgb)
|
||||
processWithVulkan(image.data(), w, h, w * 4, image.size(), tex, srgb);
|
||||
return tex;
|
||||
}
|
||||
|
||||
Texture Application::loadTextureExample(std::string path, Texture& tex, bool srgb)
|
||||
#ifdef _WIN32
|
||||
Texture Application::loadTextureExample(std::wstring path, Texture& tex, bool srgb)
|
||||
{
|
||||
std::vector<unsigned char> data = readFileUnsignedChar(path, true);
|
||||
std::vector<unsigned char> data = readFileUnsignedCharWin32(path, true);
|
||||
std::vector<unsigned char> image;
|
||||
unsigned w, h;
|
||||
unsigned error = lodepng::decode(image, w, h, data, LCT_RGBA, 8);
|
||||
@@ -650,6 +650,10 @@ Texture Application::loadTextureExample(std::string path, Texture& tex, bool srg
|
||||
return tex;
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
|
||||
|
||||
void Application::createTexture(VkDevice device, VkPhysicalDevice physicalDevice, int width, int height, Texture& texture, bool srgb)
|
||||
{
|
||||
|
||||
@@ -75,7 +75,9 @@ protected:
|
||||
|
||||
protected:
|
||||
Texture loadTexture(std::string path, Texture& tex, bool srgb);
|
||||
Texture loadTextureExample(std::string path, Texture& tex, bool srgb);
|
||||
#ifdef _WIN32
|
||||
Texture loadTextureExample(std::wstring path, Texture& tex, bool srgb);
|
||||
#endif
|
||||
|
||||
uint32_t findMemoryType(VkPhysicalDevice physicalDevice, uint32_t typeFilter,
|
||||
VkMemoryPropertyFlags properties);
|
||||
|
||||
+6
-3
@@ -1146,16 +1146,19 @@ void FaceApp::changeMotion(Motion& motion)
|
||||
_curMotion = _initArg.motion;
|
||||
for (int i = 0; i < _curMotion.png_num; ++i)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
|
||||
string path_name = path + "/" + _curMotion.png_name + std::to_string(i) + ".png";
|
||||
#ifdef _WIN32
|
||||
loadTextureExample(path_name, m_texs[i], true);
|
||||
loadTextureExample(UTF8ToWideString(path_name), m_texs[i], true);
|
||||
if (kThick)
|
||||
{
|
||||
string path_name_ex = path + "/" + _curMotion.png_name + std::to_string(i) + "_thick.png";
|
||||
loadTextureExample(path_name_ex, m_texs_ex[i], true);
|
||||
loadTextureExample(UTF8ToWideString(path_name_ex), m_texs_ex[i], true);
|
||||
}
|
||||
#else
|
||||
string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
|
||||
string path_name = path + "/" + _curMotion.png_name + std::to_string(i) + ".png";
|
||||
loadTexture(path_name, m_texs[i], true);
|
||||
if (kThick)
|
||||
{
|
||||
|
||||
+12
-27
@@ -1,23 +1,8 @@
|
||||
|
||||
#include "FaceApp.h"
|
||||
#include <windows.h>
|
||||
|
||||
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<wchar_t> 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)
|
||||
{
|
||||
@@ -32,7 +17,7 @@ std::wstring ReadUTF8File(const std::string& filePath)
|
||||
file.close();
|
||||
|
||||
// 将UTF-8字符串转换为宽字符串
|
||||
return UTF8ToWideString(content);
|
||||
return AppBase::UTF8ToWideString(content);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,23 +36,23 @@ std::wstring ReadFileWithChinesePath(const std::wstring& filePath) {
|
||||
file.seekg(0, std::ios::beg);
|
||||
file.read(&context[0], context.size());
|
||||
file.close();
|
||||
return UTF8ToWideString(context);
|
||||
return AppBase::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);
|
||||
//std::string path = "chinese.txt";
|
||||
//std::wstring chinese = ReadUTF8File(path);
|
||||
//std::wstring chinese_path = AppBase::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.type = "底妆";
|
||||
motion.technique = "基础上妆";
|
||||
motion.step = "2按压";
|
||||
motion.show_type = "方向示意图";
|
||||
motion.png_name = "test";
|
||||
motion.png_num = 1;
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user