Fix home_directory() with non-US-English pathnames on Windows (#2203).
authorCarl Hetherington <cth@carlh.net>
Tue, 8 Mar 2022 19:57:08 +0000 (20:57 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 8 Mar 2022 23:25:53 +0000 (00:25 +0100)
src/lib/cross_windows.cc
src/lib/wscript
wscript

index a425186f1816d88cf4b3559ad64c1514245a8b12..4990f53eecb3f1634f81545919b6f34fc55c8678 100644 (file)
@@ -44,7 +44,9 @@ extern "C" {
 #include <fileapi.h>
 #undef DATADIR
 #include <shlwapi.h>
+#include <shlobj.h>
 #include <shellapi.h>
+#include <knownfolders.h>
 #include <fcntl.h>
 #include <fstream>
 #include <map>
@@ -397,7 +399,17 @@ maybe_open_console ()
 boost::filesystem::path
 home_directory ()
 {
-       return boost::filesystem::path(getenv("userprofile"));
+       PWSTR wide_path;
+       auto result = SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &wide_path);
+
+       if (result != S_OK) {
+               CoTaskMemFree(wide_path);
+               return boost::filesystem::path("c:\\");
+       }
+
+       auto path = wchar_to_utf8(wide_path);
+       CoTaskMemFree(wide_path);
+       return path;
 }
 
 
index 2bf740c34363d1f9bf4e043dee9503ea88a1899a..914fc69f97bcee93e9a746e3067aac0ded6e251a 100644 (file)
@@ -217,7 +217,7 @@ def build(bld):
             obj.uselib += ' POLKIT'
 
     if bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32:
-        obj.uselib += ' WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE SETUPAPI'
+        obj.uselib += ' WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE SETUPAPI OLE32 UUID'
         obj.source += ' cross_windows.cc'
     if bld.env.TARGET_OSX:
         obj.source += ' cross_osx.cc'
diff --git a/wscript b/wscript
index 08f0f285a7149a04111a98a5e3381783cdbf684a..d1b9fd46d7d2d34c7483f90973ff85459d30ab25 100644 (file)
--- a/wscript
+++ b/wscript
@@ -173,6 +173,7 @@ def configure(conf):
         conf.check(lib='winmm', uselib_store='WINMM', msg="Checking for library winmm")
         conf.check(lib='ksuser', uselib_store='KSUSER', msg="Checking for library ksuser")
         conf.check(lib='setupapi', uselib_store='SETUPAPI', msg="Checking for library setupapi")
+        conf.check(lib='uuid', uselib_store='UUID', msg="Checking for library uuid")
         boost_lib_suffix = '-mt-x32' if conf.options.target_windows_32 else '-mt-x64'
         boost_thread = 'boost_thread' + boost_lib_suffix
         conf.check_cxx(fragment="""