]> git.lyx.org Git - lyx.git/blobdiff - src/support/os_win32.cpp
Let paragraph::requestSpellcheck() consider contained insets
[lyx.git] / src / support / os_win32.cpp
index e15af13acfbdd0fd0f6f4d241bf712fa6f3d9d66..1d40e56742a6f51a8e18c97056b839c8d2c1548d 100644 (file)
 
 #include <config.h>
 
+#include "support/os_win32.h"
+
 #include "LyXRC.h"
 
 #include "support/os.h"
-#include "support/os_win32.h"
 
 #include "support/debug.h"
 #include "support/environment.h"
 #include "support/lassert.h"
 
 #include <cstdlib>
+#include <iostream>
 #include <vector>
 
 #include <QString>
 
 #include <io.h>
 #include <direct.h> // _getdrive
+#include <fileapi.h> // GetFinalPathNameByHandle
 #include <shlobj.h>  // SHGetFolderPath
 #include <windef.h>
 #include <shellapi.h>
@@ -227,8 +230,8 @@ void init(int argc, char ** argv[])
                        // to the outer split which sets cygdrive with its
                        // contents until the first blank, discarding the
                        // unneeded return value.
-                       if (p.first != -1 && prefixIs(p.second, "Prefix"))
-                               split(split(p.second, '\n'), cygdrive, ' ');
+                       if (p.valid && prefixIs(p.result, "Prefix"))
+                               split(split(p.result, '\n'), cygdrive, ' ');
                }
        }
 
@@ -594,45 +597,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;
        }
@@ -678,8 +654,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();