]> git.lyx.org Git - lyx.git/blobdiff - src/support/os_win32.cpp
Outliner: distinguish non-active refs from broken refs
[lyx.git] / src / support / os_win32.cpp
index 9078f594d747c6c8b17e8326382acf14548ef985..82e57d2eb69adfe1a72074505bae21856b58016b 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <io.h>
 #include <direct.h> // _getdrive
+#include <fileapi.h> // GetFinalPathNameByHandle
 #include <shlobj.h>  // SHGetFolderPath
 #include <windef.h>
 #include <shellapi.h>
@@ -97,7 +98,7 @@ BOOL terminate_handler(DWORD event)
        return FALSE;
 }
 
-} // namespace anon
+} // namespace
 
 void init(int argc, char ** argv[])
 {
@@ -158,6 +159,11 @@ void init(int argc, char ** argv[])
         */
 
 
+       // Remove PYTHONPATH from the environment as it may point to an
+       // external python installation and cause reconfigure failures.
+       unsetEnv("PYTHONPATH");
+
+
 #if defined(_MSC_VER) && (_MSC_VER >= 1900)
        // Removing an argument from argv leads to an assertion on Windows
        // when compiling with MSVC 2015 in debug mode (see bug #10440).
@@ -442,23 +448,6 @@ string latex_path_list(string const & p)
 }
 
 
-bool is_valid_strftime(string const & p)
-{
-       string::size_type pos = p.find_first_of('%');
-       while (pos != string::npos) {
-               if (pos + 1 == string::npos)
-                       break;
-               if (!containsOnly(p.substr(pos + 1, 1),
-                       "aAbBcdfHIjmMpSUwWxXyYzZ%"))
-                       return false;
-               if (pos + 2 == string::npos)
-                     break;
-               pos = p.find_first_of('%', pos + 2);
-       }
-       return true;
-}
-
-
 // returns a string suitable to be passed to popen when
 // reading a pipe
 char const * popen_read_mode()
@@ -606,45 +595,18 @@ string real_path(string const & path)
        // See http://msdn.microsoft.com/en-us/library/aa366789(VS.85).aspx
        QString const qpath = get_long_path(toqstr(path));
        HANDLE hpath = CreateFileW((wchar_t *) qpath.utf16(), GENERIC_READ,
-                               FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+                               FILE_SHARE_READ, NULL, OPEN_EXISTING,
+                               FILE_FLAG_BACKUP_SEMANTICS, NULL);
 
        if (hpath == INVALID_HANDLE_VALUE) {
                // The file cannot be accessed.
                return path;
        }
 
-       // Get the file size.
-       DWORD size_hi = 0;
-       DWORD size_lo = GetFileSize(hpath, &size_hi);
-
-       if (size_lo == 0 && size_hi == 0) {
-               // A zero-length file cannot be mapped.
-               CloseHandle(hpath);
-               return path;
-       }
-
-       // Create a file mapping object.
-       HANDLE hmap = CreateFileMapping(hpath, NULL, PAGE_READONLY, 0, 1, NULL);
-
-       if (!hmap) {
-               CloseHandle(hpath);
-               return path;
-       }
-
-       // Create a file mapping to get the file name.
-       void * pmem = MapViewOfFile(hmap, FILE_MAP_READ, 0, 0, 1);
-
-       if (!pmem) {
-               CloseHandle(hmap);
-               CloseHandle(hpath);
-               return path;
-       }
-
        TCHAR realpath[MAX_PATH + 1];
 
-       if (!GetMappedFileName(GetCurrentProcess(), pmem, realpath, MAX_PATH)) {
-               UnmapViewOfFile(pmem);
-               CloseHandle(hmap);
+       DWORD size = GetFinalPathNameByHandle(hpath, realpath, MAX_PATH, VOLUME_NAME_NT);
+       if (size > MAX_PATH) {
                CloseHandle(hpath);
                return path;
        }
@@ -690,8 +652,6 @@ string real_path(string const & path)
                        while (*p++) ;
                } while (!found && *p);
        }
-       UnmapViewOfFile(pmem);
-       CloseHandle(hmap);
        CloseHandle(hpath);
        string const retpath = subst(string(realpath), '\\', '/');
        return FileName::fromFilesystemEncoding(retpath).absFileName();