diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-03-08 20:57:08 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-03-09 00:25:53 +0100 |
| commit | b6f3afcad13523038bc42eef9ddecb58a2ae8e70 (patch) | |
| tree | c9f470292380a46bd8450122cd2ae1160ae31b77 | |
| parent | a04c9c056235b136853953dd12e6079d3a4129b1 (diff) | |
Fix home_directory() with non-US-English pathnames on Windows (#2203).
| -rw-r--r-- | src/lib/cross_windows.cc | 14 | ||||
| -rw-r--r-- | src/lib/wscript | 2 | ||||
| -rw-r--r-- | wscript | 1 |
3 files changed, 15 insertions, 2 deletions
diff --git a/src/lib/cross_windows.cc b/src/lib/cross_windows.cc index a425186f1..4990f53ee 100644 --- a/src/lib/cross_windows.cc +++ b/src/lib/cross_windows.cc @@ -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; } diff --git a/src/lib/wscript b/src/lib/wscript index 2bf740c34..914fc69f9 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -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' @@ -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=""" |
