diff options
| author | Carl Hetherington <cth@carlh.net> | 2022-03-08 20:57:08 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2022-03-09 17:02:51 +0100 |
| commit | ed425cfa13bff05b09303d3739f96af5b8cd30a0 (patch) | |
| tree | 69a4732d55d3aa7c4bd1b6388cd6bb6e180d807e /src/lib | |
| parent | da166a57a566ebb9ca79e3859d48b1320b587118 (diff) | |
Fix home_directory() with non-US-English pathnames on Windows (#2203).
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/cross_windows.cc | 14 | ||||
| -rw-r--r-- | src/lib/wscript | 2 |
2 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/cross_windows.cc b/src/lib/cross_windows.cc index 49eec3c28..aebf28189 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> @@ -396,7 +398,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 e12390ab7..22fb144bc 100644 --- a/src/lib/wscript +++ b/src/lib/wscript @@ -225,7 +225,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' |
