+ string const texinputs = os::latex_path_list(
+ replaceCurdirPath(path, lyxrc.texinputs_prefix));
+ string const otherinputs = os::latex_path_list(path);
+ string const sep = windows_style_tex_paths_ ? ";" : ":";
+ string const oldtexinputs = getEnv("TEXINPUTS");
+ string const newtexinputs = "." + sep + texinputs + sep + oldtexinputs;
+ string const oldbibinputs = getEnv("BIBINPUTS");
+ string const newbibinputs = "." + sep + otherinputs + sep + oldbibinputs;
+ string const oldbstinputs = getEnv("BSTINPUTS");
+ string const newbstinputs = "." + sep + otherinputs + sep + oldbstinputs;
+ string const oldtexfonts = getEnv("TEXFONTS");
+ string const newtexfonts = "." + sep + otherinputs + sep + oldtexfonts;
+ if (!path.empty() && !lyxrc.texinputs_prefix.empty()) {
+ setEnv("TEXINPUTS", newtexinputs);
+ setEnv("BIBINPUTS", newbibinputs);
+ setEnv("BSTINPUTS", newbstinputs);
+ setEnv("TEXFONTS", newtexfonts);
+ }
+
+ QString const wname = toqstr(filename);
+
+ // reference: http://msdn.microsoft.com/en-us/library/bb762153.aspx
+ wchar_t const * action = (mode == VIEW) ? L"open" : L"edit";
+ bool success = reinterpret_cast<intptr_t>(ShellExecuteW(NULL, action,
+ reinterpret_cast<wchar_t const *>(wname.utf16()),
+ NULL, NULL, 1)) > 32;
+
+ if (!path.empty() && !lyxrc.texinputs_prefix.empty()) {
+ setEnv("TEXINPUTS", oldtexinputs);
+ setEnv("BIBINPUTS", oldbibinputs);
+ setEnv("BSTINPUTS", oldbstinputs);
+ setEnv("TEXFONTS", oldtexfonts);
+ }
+ return success;
+}
+
+
+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,
+ FILE_FLAG_BACKUP_SEMANTICS, NULL);
+
+ if (hpath == INVALID_HANDLE_VALUE) {
+ // The file cannot be accessed.
+ return path;
+ }
+
+ TCHAR realpath[MAX_PATH + 1];
+
+ DWORD size = GetFinalPathNameByHandle(hpath, realpath, MAX_PATH, VOLUME_NAME_NT);
+ if (size > MAX_PATH) {
+ CloseHandle(hpath);
+ return path;
+ }
+
+ // Translate device name to UNC prefix or drive letters.
+ TCHAR tmpbuf[MAX_PATH] = TEXT("\\Device\\Mup\\");
+ UINT namelen = _tcslen(tmpbuf);
+ if (_tcsnicmp(realpath, tmpbuf, namelen) == 0) {
+ // UNC path
+ _snprintf(tmpbuf, MAX_PATH, "\\\\%s", realpath + namelen);
+ strncpy(realpath, tmpbuf, MAX_PATH);
+ realpath[MAX_PATH] = '\0';
+ } else if (GetLogicalDriveStrings(MAX_PATH - 1, tmpbuf)) {
+ // Check whether device name corresponds to some local drive.
+ TCHAR name[MAX_PATH];
+ TCHAR drive[3] = TEXT(" :");
+ bool found = false;
+ TCHAR * p = tmpbuf;
+ do {
+ // Copy the drive letter to the template string
+ drive[0] = *p;
+ // Look up each device name
+ if (QueryDosDevice(drive, name, MAX_PATH)) {
+ namelen = _tcslen(name);
+ if (namelen < MAX_PATH) {
+ found = _tcsnicmp(realpath, name, namelen) == 0;
+ if (found) {
+ // Repl. device spec with drive
+ TCHAR tempfile[MAX_PATH];
+ _snprintf(tempfile,
+ MAX_PATH,
+ "%s%s",
+ drive,
+ realpath + namelen);
+ strncpy(realpath,
+ tempfile,
+ MAX_PATH);
+ realpath[MAX_PATH] = '\0';
+ }
+ }
+ }
+ // Advance p to the next NULL character.
+ while (*p++) ;
+ } while (!found && *p);
+ }
+ CloseHandle(hpath);
+ string const retpath = subst(string(realpath), '\\', '/');
+ return FileName::fromFilesystemEncoding(retpath).absFileName();