From 647c96ecacd3d3a720e2dce7a8b121b9e4c0ebcd Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 14 Jul 2003 06:23:44 +0000 Subject: [PATCH] simplify --- stepmania/src/archutils/Win32/GotoURL.cpp | 71 ++++++++++++----------- stepmania/src/archutils/Win32/GotoURL.h | 2 +- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/stepmania/src/archutils/Win32/GotoURL.cpp b/stepmania/src/archutils/Win32/GotoURL.cpp index 6e4dd49575..3b6b02d75c 100644 --- a/stepmania/src/archutils/Win32/GotoURL.cpp +++ b/stepmania/src/archutils/Win32/GotoURL.cpp @@ -1,54 +1,57 @@ #include "global.h" #include "GotoURL.h" -static LONG GetRegKey(HKEY key, const char *subkey, LPTSTR retdata) +LONG GetRegKey(HKEY key, CString subkey, LPTSTR retdata) { HKEY hkey; LONG retval = RegOpenKeyEx(key, subkey, 0, KEY_QUERY_VALUE, &hkey); - if (retval == ERROR_SUCCESS) { - long datasize = MAX_PATH; - TCHAR data[MAX_PATH]; - RegQueryValue(hkey, NULL, data, &datasize); - lstrcpy(retdata,data); - RegCloseKey(hkey); - } + if (retval != ERROR_SUCCESS) + return retval; - return retval; + long datasize = MAX_PATH; + TCHAR data[MAX_PATH]; + RegQueryValue(hkey, "emulation", data, &datasize); + strcpy(retdata,data); + RegCloseKey(hkey); + + return ERROR_SUCCESS; } -HINSTANCE GotoURL(const char *url) -{ - TCHAR key[MAX_PATH + MAX_PATH]; +bool GotoURL(CString url) +{ // First try ShellExecute() - HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL, SW_SHOWDEFAULT); + int result = (int) ShellExecute(NULL, "open", url, NULL,NULL, SW_SHOWDEFAULT); // If it failed, get the .htm regkey and lookup the program - if ((UINT)result <= HINSTANCE_ERROR) { + if (result > 32) + return true; - if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), key) == ERROR_SUCCESS) { - lstrcat(key, _T("\\shell\\open\\command")); + char key[2*MAX_PATH]; + if (GetRegKey(HKEY_CLASSES_ROOT, ".htm", key) != ERROR_SUCCESS) + return false; - if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS) { - TCHAR *pos; - pos = _tcsstr(key, _T("\"%1\"")); - if (pos == NULL) { // No quotes found - pos = strstr(key, _T("%1")); // Check for %1, without quotes - if (pos == NULL) // No parameter at all... - pos = key+lstrlen(key)-1; - else - *pos = '\0'; // Remove the parameter - } - else - *pos = '\0'; // Remove the parameter + strcpy(key, "\\shell\\open\\command"); - lstrcat(pos, _T(" ")); - lstrcat(pos, url); - result = (HINSTANCE) WinExec(key,SW_SHOWDEFAULT); - } - } + if (GetRegKey(HKEY_CLASSES_ROOT,key,key) != ERROR_SUCCESS) + return false; + + char *pos = _tcsstr(key, "\"%1\""); + if (pos == NULL) + { + // No quotes found. Check for %1 without quotes + pos = strstr(key, _T("%1")); + if (pos == NULL) + pos = key+lstrlen(key)-1; // No parameter. + else + *pos = '\0'; // Remove the parameter } + else + *pos = '\0'; // Remove the parameter - return result; + strcat(pos, " "); + strcat(pos, url); + + return WinExec(key,SW_SHOWDEFAULT) > 32; } diff --git a/stepmania/src/archutils/Win32/GotoURL.h b/stepmania/src/archutils/Win32/GotoURL.h index 1a7af7d3a9..e3976103c6 100644 --- a/stepmania/src/archutils/Win32/GotoURL.h +++ b/stepmania/src/archutils/Win32/GotoURL.h @@ -1,6 +1,6 @@ #ifndef GOTO_URL_H #define GOTO_URL_H -HINSTANCE GotoURL(const char *url); +bool GotoURL(CString url); #endif \ No newline at end of file