X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fcross_windows.cc;h=f7638083656c2731411075144fbd10f8b72f9a2b;hb=809bcfd85fad2ef7d4131c054be4cccd5bcc9d05;hp=f778a60e15088d932d85cb33a2ed9620c09d91f0;hpb=a5f481aae19a6ef5b0cad48edaea5b58fc00ee05;p=dcpomatic.git diff --git a/src/lib/cross_windows.cc b/src/lib/cross_windows.cc index f778a60e1..f76380836 100644 --- a/src/lib/cross_windows.cc +++ b/src/lib/cross_windows.cc @@ -19,6 +19,8 @@ */ +#define UNICODE 1 + #include "cross.h" #include "compose.hpp" #include "log.h" @@ -42,7 +44,9 @@ extern "C" { #include #undef DATADIR #include +#include #include +#include #include #include #include @@ -206,16 +210,9 @@ resources_path () boost::filesystem::path -xsd_path () -{ - return directory_containing_executable().parent_path() / "xsd"; -} - - -boost::filesystem::path -tags_path () +libdcp_resources_path () { - return directory_containing_executable().parent_path() / "tags"; + return resources_path (); } @@ -253,14 +250,17 @@ fix_long_path (boost::filesystem::path long_path) { using namespace boost::filesystem; - path fixed = "\\\\?\\"; - if (boost::algorithm::starts_with(long_path.string(), fixed.string())) { + if (boost::algorithm::starts_with(long_path.string(), "\\\\")) { + /* This could mean it starts with \\ (i.e. a SMB path) or \\?\ (a long path) + * or a variety of other things... anyway, we'll leave it alone. + */ return long_path; } /* We have to make the path canonical but we can't call canonical() on the long path * as it will fail. So we'll sort of do it ourselves (possibly badly). */ + path fixed = "\\\\?\\"; if (long_path.is_absolute()) { fixed += long_path.make_preferred(); } else { @@ -353,10 +353,9 @@ static string wchar_to_utf8 (wchar_t const * s) { int const length = (wcslen(s) + 1) * 2; - char* utf8 = new char[length]; - WideCharToMultiByte (CP_UTF8, 0, s, -1, utf8, length, 0, 0); - string u (utf8); - delete[] utf8; + std::vector utf8(length); + WideCharToMultiByte (CP_UTF8, 0, s, -1, utf8.data(), length, 0, 0); + string u (utf8.data()); return u; } @@ -392,7 +391,17 @@ maybe_open_console () boost::filesystem::path home_directory () { - return boost::filesystem::path(getenv("HOMEDRIVE")) / boost::filesystem::path(getenv("HOMEPATH")); + 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; } @@ -647,8 +656,6 @@ Drive::unmount () DCPOMATIC_ASSERT (_mount_points.size() == 1); string const device_name = String::compose ("\\\\.\\%1", _mount_points.front()); string const truncated = device_name.substr (0, device_name.length() - 1); - //LOG_DISK("Actually opening %1", _device); - //HANDLE device = CreateFileA (_device.c_str(), (GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); LOG_DISK("Actually opening %1", truncated); HANDLE device = CreateFileA (truncated.c_str(), (GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); if (device == INVALID_HANDLE_VALUE) { @@ -670,11 +677,14 @@ Drive::unmount () boost::filesystem::path -config_path () +config_path (optional version) { boost::filesystem::path p; p /= g_get_user_config_dir (); p /= "dcpomatic2"; + if (version) { + p /= *version; + } return p; }