|
|
|
@ -1025,34 +1025,71 @@ LONG GetRegKey(HKEY key, LPCSTR subkey, LPSTR retdata)
|
|
|
|
|
}
|
|
|
|
|
#endif // NL_OS_WINDOWS
|
|
|
|
|
|
|
|
|
|
bool openURL (const char *url)
|
|
|
|
|
static bool openDocWithExtension (const char *document, const char *ext)
|
|
|
|
|
{
|
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
|
char key[1024];
|
|
|
|
|
if (GetRegKey(HKEY_CLASSES_ROOT, ".html", key) == ERROR_SUCCESS)
|
|
|
|
|
// First try ShellExecute()
|
|
|
|
|
HINSTANCE result = ShellExecuteA(NULL, "open", document, NULL, NULL, SW_SHOWDEFAULT);
|
|
|
|
|
|
|
|
|
|
// If it failed, get the .htm regkey and lookup the program
|
|
|
|
|
if ((uintptr_t)result <= HINSTANCE_ERROR)
|
|
|
|
|
{
|
|
|
|
|
lstrcatA(key, "\\shell\\open\\command");
|
|
|
|
|
char key[MAX_PATH + MAX_PATH];
|
|
|
|
|
|
|
|
|
|
if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS)
|
|
|
|
|
if (GetRegKey(HKEY_CLASSES_ROOT, ext, key) == ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
char *pos;
|
|
|
|
|
pos = strstr(key, "\"%1\"");
|
|
|
|
|
if (pos == NULL) { // No quotes found
|
|
|
|
|
pos = strstr(key, "%1"); // Check for %1, without quotes
|
|
|
|
|
if (pos == NULL) // No parameter at all...
|
|
|
|
|
pos = key+lstrlenA(key)-1;
|
|
|
|
|
else
|
|
|
|
|
*pos = '\0'; // Remove the parameter
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*pos = '\0'; // Remove the parameter
|
|
|
|
|
|
|
|
|
|
lstrcatA(pos, " ");
|
|
|
|
|
lstrcatA(pos, url);
|
|
|
|
|
int res = WinExec(key,SW_SHOWDEFAULT);
|
|
|
|
|
return (res>31);
|
|
|
|
|
lstrcatA(key, "\\shell\\open\\command");
|
|
|
|
|
|
|
|
|
|
if (GetRegKey(HKEY_CLASSES_ROOT, key, key) == ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
char *pos = strstr(key, "\"%1\"");
|
|
|
|
|
|
|
|
|
|
if (pos == NULL)
|
|
|
|
|
{
|
|
|
|
|
// No quotes found
|
|
|
|
|
// Check for %1, without quotes
|
|
|
|
|
pos = strstr(key, "%1");
|
|
|
|
|
|
|
|
|
|
if (pos == NULL)
|
|
|
|
|
{
|
|
|
|
|
// No parameter at all...
|
|
|
|
|
pos = key+lstrlenA(key)-1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Remove the parameter
|
|
|
|
|
*pos = '\0';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Remove the parameter
|
|
|
|
|
*pos = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lstrcatA(pos, " ");
|
|
|
|
|
lstrcatA(pos, document);
|
|
|
|
|
int res = WinExec(key, SW_SHOWDEFAULT);
|
|
|
|
|
return (res>31);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
// TODO: implement for Linux and Mac OS X
|
|
|
|
|
nlunreferenced(document);
|
|
|
|
|
#endif // NL_OS_WINDOWS
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool openURL (const char *url)
|
|
|
|
|
{
|
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
|
return openDocWithExtension(url, "htm");
|
|
|
|
|
#elif defined(NL_OS_MAC)
|
|
|
|
|
return launchProgram("open", url);
|
|
|
|
|
#elif defined(NL_OS_UNIX)
|
|
|
|
@ -1060,53 +1097,17 @@ bool openURL (const char *url)
|
|
|
|
|
#else
|
|
|
|
|
nlwarning("openURL() is not implemented for this OS");
|
|
|
|
|
#endif // NL_OS_WINDOWS
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool openDoc (const char *document)
|
|
|
|
|
{
|
|
|
|
|
#ifdef NL_OS_WINDOWS
|
|
|
|
|
string ext = CFile::getExtension (document);
|
|
|
|
|
char key[MAX_PATH + MAX_PATH];
|
|
|
|
|
|
|
|
|
|
// First try ShellExecute()
|
|
|
|
|
HINSTANCE result = ShellExecuteA(NULL, "open", document, NULL,NULL, SW_SHOWDEFAULT);
|
|
|
|
|
// get extension from document fullpath
|
|
|
|
|
string ext = CFile::getExtension(document);
|
|
|
|
|
|
|
|
|
|
// If it failed, get the .htm regkey and lookup the program
|
|
|
|
|
if ((uintptr_t)result <= HINSTANCE_ERROR)
|
|
|
|
|
{
|
|
|
|
|
if (GetRegKey(HKEY_CLASSES_ROOT, ext.c_str(), key) == ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
lstrcatA(key, "\\shell\\open\\command");
|
|
|
|
|
|
|
|
|
|
if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
char *pos;
|
|
|
|
|
pos = strstr(key, "\"%1\"");
|
|
|
|
|
if (pos == NULL) { // No quotes found
|
|
|
|
|
pos = strstr(key, "%1"); // Check for %1, without quotes
|
|
|
|
|
if (pos == NULL) // No parameter at all...
|
|
|
|
|
pos = key+lstrlenA(key)-1;
|
|
|
|
|
else
|
|
|
|
|
*pos = '\0'; // Remove the parameter
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
*pos = '\0'; // Remove the parameter
|
|
|
|
|
|
|
|
|
|
lstrcatA(pos, " ");
|
|
|
|
|
lstrcatA(pos, document);
|
|
|
|
|
int res = WinExec(key,SW_SHOWDEFAULT);
|
|
|
|
|
return (res>31);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return true;
|
|
|
|
|
#else
|
|
|
|
|
// TODO: implement for Linux and Mac OS X
|
|
|
|
|
nlunreferenced(document);
|
|
|
|
|
#endif // NL_OS_WINDOWS
|
|
|
|
|
return false;
|
|
|
|
|
// try to open document
|
|
|
|
|
return openDocWithExtension(document, ext.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // NLMISC
|
|
|
|
|