X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fcross_windows.cc;h=200b724854731b2582110f752d45abf87921831b;hp=04ee26271b7a5c80595c1ce87e38b87a2de5fad1;hb=bbe336ee97c86c424f8f94e0f947f8e3b20e7123;hpb=3339d3bce70afe9ae2ca10e9fcfc4b54b748fbf4 diff --git a/src/lib/cross_windows.cc b/src/lib/cross_windows.cc index 04ee26271..200b72485 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" @@ -26,6 +28,8 @@ #include "config.h" #include "exceptions.h" #include "dcpomatic_assert.h" +#include "util.h" +#include #include #include extern "C" { @@ -40,8 +44,11 @@ extern "C" { #include #include #undef DATADIR -#include +#include +#include #include +#include +#include #include #include #include @@ -157,7 +164,7 @@ run_ffprobe (boost::filesystem::path content, boost::filesystem::path out) return; } - auto o = fopen_boost (out, "w"); + dcp::File o(out, "w"); if (!o) { LOG_ERROR_NC (N_("ffprobe call failed (could not create output file)")); return; @@ -171,10 +178,10 @@ run_ffprobe (boost::filesystem::path content, boost::filesystem::path out) if (!ReadFile(child_stderr_read, buffer, sizeof(buffer), &read, 0) || read == 0) { break; } - fwrite (buffer, read, 1, o); + o.write(buffer, read, 1); } - fclose (o); + o.close(); WaitForSingleObject (process_info.hProcess, INFINITE); CloseHandle (process_info.hProcess); @@ -205,16 +212,9 @@ resources_path () boost::filesystem::path -xsd_path () +libdcp_resources_path () { - return directory_containing_executable().parent_path() / "xsd"; -} - - -boost::filesystem::path -tags_path () -{ - return directory_containing_executable().parent_path() / "tags"; + return resources_path (); } @@ -234,26 +234,6 @@ disk_writer_path () #endif -/* Apparently there is no way to create an ofstream using a UTF-8 - filename under Windows. We are hence reduced to using fopen - with this wrapper. -*/ -FILE * -fopen_boost (boost::filesystem::path p, string t) -{ - wstring w (t.begin(), t.end()); - /* c_str() here should give a UTF-16 string */ - return _wfopen (p.c_str(), w.c_str ()); -} - - -int -dcpomatic_fseek (FILE* stream, int64_t offset, int whence) -{ - return _fseeki64 (stream, offset, whence); -} - - void Waker::nudge () { @@ -317,10 +297,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; } @@ -356,7 +335,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; } @@ -611,8 +600,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) { @@ -634,11 +621,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; } @@ -658,3 +648,27 @@ dcpomatic::get_process_id () return dcp::raw_convert(GetCurrentProcessId()); } + +bool +show_in_file_manager (boost::filesystem::path, boost::filesystem::path select) +{ + std::wstringstream args; + args << "/select," << select; + auto const r = ShellExecute (0, L"open", L"explorer.exe", args.str().c_str(), 0, SW_SHOWDEFAULT); + return (reinterpret_cast(r) <= 32); +} + + +ArgFixer::ArgFixer(int, char**) +{ + auto cmd_line = GetCommandLineW(); + auto wide_argv = CommandLineToArgvW(cmd_line, &_argc); + + _argv_strings.resize(_argc); + _argv = new char*[_argc]; + for (int i = 0; i < _argc; ++i) { + _argv_strings[i] = wchar_to_utf8(wide_argv[i]); + _argv[i] = const_cast(_argv_strings[i].c_str()); + } +} +