Add config option for default KDM type.
[dcpomatic.git] / src / lib / cross_windows.cc
index 723828d7e235dce6617e01041389756ad6201620..324b8cd8bd5cab03e3eb59266f7fbb2ea12f499a 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>
@@ -208,16 +210,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 ();
 }
 
 
@@ -255,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 {
@@ -394,7 +392,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;
 }
 
 
@@ -672,11 +680,14 @@ Drive::unmount ()
 
 
 boost::filesystem::path
-config_path ()
+config_path (optional<string> version)
 {
        boost::filesystem::path p;
        p /= g_get_user_config_dir ();
        p /= "dcpomatic2";
+       if (version) {
+               p /= *version;
+       }
        return p;
 }