#include <config.h>
-/* The GetLongPathNameA function declaration in
- * <winbase.h> under MinGW or Cygwin is protected
- * by the WINVER macro which is defined in <windef.h>
- *
- * SHGFP_TYPE_CURRENT is defined in <shlobj.h> for __W32API_VERSION >= 3.2
- * where it is protected by _WIN32_IE.
- * It is missing in earlier versions of the MinGW w32api headers.
- */
-#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__CYGWIN32__)
-# include <w32api.h>
-# define WINVER 0x0500
-# define _WIN32_IE 0x0500
-#endif
-
#include "support/os.h"
#include "support/os_win32.h"
#include "support/lstrings.h"
+#include "support/filetools.h"
#include "debug.h"
#include <string>
-#include <windows.h>
-
/* The GetLongPathName macro may be defined on the compiling machine,
* but we must use a bit of trickery if the resulting executable is
* to run on a Win95 machine.
#include <io.h>
#include <direct.h> // _getdrive
#include <shlobj.h> // SHGetFolderPath
+#include <windef.h>
+#include <shellapi.h>
+#include <shlwapi.h>
-// Needed by older versions of MinGW.
-#if defined (__W32API_MAJOR_VERSION) && \
- defined (__W32API_MINOR_VERSION) && \
- (__W32API_MAJOR_VERSION < 3 || \
- __W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION < 2)
-# define SHGFP_TYPE_CURRENT 0
+// Must define SHGFP_TYPE_CURRENT for older versions of MinGW.
+#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__CYGWIN32__)
+# include <w32api.h>
+# if __W32API_MAJOR_VERSION < 3 || \
+ __W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION < 2
+# define SHGFP_TYPE_CURRENT 0
+# endif
#endif
using std::endl;
using std::string;
+using lyx::support::runCommand;
+using lyx::support::split;
+
namespace lyx {
namespace support {
namespace os {
+namespace {
+
+bool windows_style_tex_paths_ = true;
+
+string cygdrive = "/cygdrive";
+
+} // namespace anon
+
void init(int /* argc */, char * argv[])
{
/* Note from Angus, 17 Jan 2005:
* shell scripts failed, for mysterious reasons...
*
* I've chosen for now, therefore, to simply add Ruurd's original
- * code as-is.
+ * code as-is. A wrapper program hidecmd.c has been added to
+ * development/Win32 which hides the console window of lyx when
+ * lyx is invoked as a parameter of hidecmd.exe.
*/
- // Close the console when run (probably)
- // not run from command prompt
- char WindowTitle[1024];
- if (GetConsoleTitle(WindowTitle, sizeof(WindowTitle)) == 0) {
- // Could not get the title, so we just leave things as they are
- return;
- }
- if ((strcmp(WindowTitle, argv[0]) == 0) ||
- (strcmp(WindowTitle, "LyX") == 0)) {
- // format a "unique" newWindowTitle
- wsprintf(WindowTitle, "%d/%d",
- GetTickCount(),
- GetCurrentProcessId());
- // change current window title
- SetConsoleTitle(WindowTitle);
- // ensure window title has been updated
- Sleep(40);
- // look for newWindowTitle
- HWND const hwndFound = FindWindow(NULL, WindowTitle);
- // If found, hide it
- if (hwndFound != NULL)
- ShowWindow( hwndFound, SW_HIDE);
+ // If cygwin is detected, query the cygdrive prefix
+ HKEY regKey;
+ char buf[MAX_PATH];
+ DWORD bufSize = sizeof(buf);
+ LONG retVal;
+
+ retVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ "Software\\Cygnus Solutions\\Cygwin\\mounts v2",
+ 0, KEY_QUERY_VALUE, ®Key);
+ if (retVal != ERROR_SUCCESS) {
+ retVal = RegOpenKeyEx(HKEY_CURRENT_USER,
+ "Software\\Cygnus Solutions\\Cygwin\\mounts v2",
+ 0, KEY_QUERY_VALUE, ®Key);
+ }
+ if (retVal == ERROR_SUCCESS) {
+ retVal = RegQueryValueEx(regKey, "cygdrive prefix", NULL, NULL,
+ (LPBYTE) buf, &bufSize);
+ RegCloseKey(regKey);
+ if ((retVal == ERROR_SUCCESS) && (bufSize <= MAX_PATH))
+ cygdrive = buf;
}
}
string const get_long_path(string const & short_path)
{
- std::vector<char> long_path(PATH_MAX);
+ std::vector<char> long_path(MAX_PATH);
DWORD result = GetLongPathName(short_path.c_str(),
&long_path[0], long_path.size());
}
+string external_path_list(string const & p)
+{
+ return subst(p, '/', '\\');
+}
+
+
+string internal_path_list(string const & p)
+{
+ return subst(p, '\\', '/');
+}
+
+
+string latex_path(string const & p)
+{
+ // We may need a posix style path or a windows style path (depending
+ // on windows_style_tex_paths_), but we use always forward slashes,
+ // since it gets written into a .tex file.
+
+ if (!windows_style_tex_paths_ && is_absolute_path(p)) {
+ string const drive = p.substr(0, 2);
+ string const cygprefix = cygdrive + "/" + drive.substr(0, 1);
+ string const cygpath = subst(subst(p, '\\', '/'), drive, cygprefix);
+ lyxerr[Debug::LATEX]
+ << "<Path correction for LaTeX> ["
+ << p << "]->>["
+ << cygpath << ']' << endl;
+ return cygpath;
+ }
+ return subst(p, '\\', '/');
+}
+
+
// (Claus H.) On Win32 both Unix and Win32/DOS pathnames are used.
// Therefore an absolute path could be either a pathname starting
// with a slash (Unix) or a pathname starting with a drive letter
}
-void cygwin_path_fix(bool)
-{}
+void windows_style_tex_paths(bool use_windows_paths)
+{
+ windows_style_tex_paths_ = use_windows_paths;
+}
namespace {
folder_path_func_ = reinterpret_cast<function_pointer>(::GetProcAddress(folder_module_, "SHGetFolderPathA"));
if (folder_path_func_ == 0) {
lyxerr << "Unable to find SHGetFolderPathA in shfolder.dll\n"
- "Don't know how to proceed. Sorry."
+ "Don't know how to proceed. Sorry."
<< std::endl;
bail_out();
}
// Eg CSIDL_PERSONAL -> "C:/Documents and Settings/USERNAME/My Documents"
string const GetFolderPath::operator()(folder_id _id) const
{
- char folder_path[PATH_MAX];
+ char folder_path[MAX_PATH];
int id = 0;
switch (_id) {
return (result == 0) ? os::internal_path(folder_path) : string();
}
+
+bool canAutoOpenFile(string const & ext, auto_open_mode const mode)
+{
+ if (ext.empty())
+ return false;
+
+ string const full_ext = "." + ext;
+
+ DWORD bufSize = MAX_PATH + 100;
+ TCHAR buf[MAX_PATH + 100];
+ // reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc
+ // /platform/shell/reference/shlwapi/registry/assocquerystring.asp
+ char const * action = (mode == VIEW) ? "open" : "edit";
+ return S_OK == AssocQueryString(0, ASSOCSTR_EXECUTABLE,
+ full_ext.c_str(), action, buf, &bufSize);
+}
+
+
+bool autoOpenFile(string const & filename, auto_open_mode const mode)
+{
+ // reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc
+ // /platform/shell/reference/functions/shellexecute.asp
+ char const * action = (mode == VIEW) ? "open" : "edit";
+ return reinterpret_cast<int>(ShellExecute(NULL, action,
+ filename.c_str(), NULL, NULL, 1)) > 32;
+}
+
+
} // namespace os
} // namespace support
} // namespace lyx