Fix failure to load DCPs from SMB shares (#2123).
[dcpomatic.git] / src / lib / cross_windows.cc
index 723828d7e235dce6617e01041389756ad6201620..49eec3c28ff01b19a18c427f16521eea869a67e8 100644 (file)
@@ -255,14 +255,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 {
@@ -355,10 +358,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<char> utf8(length);
+       WideCharToMultiByte (CP_UTF8, 0, s, -1, utf8.data(), length, 0, 0);
+       string u (utf8.data());
        return u;
 }
 
@@ -672,11 +674,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;
 }