From e1dd20db0c987a1fac9e00e617310f8c3941abb1 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 29 Mar 2021 15:41:13 +0200 Subject: [PATCH] Gui: fix unicode handling of path names on Windows --- src/App/Application.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/App/Application.cpp b/src/App/Application.cpp index e4fc6d6afc..206767c1ae 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -2852,11 +2852,11 @@ void Application::ExtractUserPath() #elif defined(FC_OS_WIN32) WCHAR szPath[MAX_PATH]; - char dest[MAX_PATH*3]; // Get the default path where we can save our documents. It seems that // 'CSIDL_MYDOCUMENTS' doesn't work on all machines, so we use 'CSIDL_PERSONAL' // which does the same. if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, szPath))) { + char dest[MAX_PATH * 3]; WideCharToMultiByte(CP_UTF8, 0, szPath, -1,dest, 256, NULL, NULL); mConfig["UserHomePath"] = dest; } @@ -2872,12 +2872,9 @@ void Application::ExtractUserPath() // kept. There we create a directory with name of the vendor and a sub-directory with name // of the application. if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, szPath))) { - // convert to UTF8 - WideCharToMultiByte(CP_UTF8, 0, szPath, -1,dest, 256, NULL, NULL); - - boost::filesystem::path appData(dest); + boost::filesystem::path appData(szPath); if (!userData.isEmpty()) - appData = userData.toUtf8().data(); + appData = userData.toStdWString(); if (!boost::filesystem::exists(appData)) { // This should never ever happen @@ -2903,10 +2900,12 @@ void Application::ExtractUserPath() } } - mConfig["UserAppData"] = appData.string() + PATHSEP; + QString dataPath = QString::fromStdWString(appData.wstring()); + mConfig["UserAppData"] = dataPath.toStdString() + PATHSEP; // Create the default macro directory - auto macroDir = getUserMacroDir(); + QString macroPath = QString::fromStdString(getUserMacroDir()); + boost::filesystem::path macroDir = macroPath.toStdWString(); if (!boost::filesystem::exists(macroDir) && !Py_IsInitialized()) { try { boost::filesystem::create_directories(macroDir);