📄 urlutil.c
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "vsdistrict.h"
#include "voltfile.h"
#include "deftrans.h"
#include "volti18n.h"
#include "errorctx.h"
int mIcRegisterWithBrowser (
VoltLibCtx *libCtx
)
{
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_SET_FNCT_LINE (fnctLine)
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, VT_ERROR_UNIMPLEMENTED, VT_ERROR_TYPE_PRIMARY,
fnctLine, "mIcRegisterWithBrowser", (char *)0)
return (VT_ERROR_UNIMPLEMENTED);
}
#if VOLT_OS == VOLT_WINDOWS_32
#include <tchar.h>
#include <windows.h>
#include <wininet.h>
#include <process.h>
static BOOL GotoURLReg (LPCTSTR lpszUrl, int nShowCmd);
static LONG GetRegKey (HKEY hKeyBase, LPCTSTR lpSubKey, LPTSTR lpszRetData);
int mDoActivateURL (
VoltLibCtx *libCtx,
unsigned char *url
)
{
int status;
BOOL bRet;
#ifdef UNICODE
LPWSTR wideURL = (LPWSTR)0;
#endif
LPCTSTR urlToUse;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
#ifdef UNICODE
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltConvertMultiByteToWideAlloc (
url, CP_UTF8, &wideURL, libCtx);
if (status != 0)
break;
urlToUse = (LPCTSTR)wideURL;
#else
urlToUse = (LPCTSTR)url;
#endif
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NETWORK_CONNECT;
bRet = GotoURLReg ((LPCTSTR)urlToUse, SW_SHOWNORMAL);
if (bRet != TRUE)
break;
status = 0;
} while (0);
#ifdef UNICODE
if (wideURL != (LPWSTR)0)
Z2Free (wideURL);
#endif
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, errorType,
fnctLine, "mDoActivateURL", (char *)0)
return (status);
}
static BOOL GotoURLReg (
LPCTSTR lpszUrl,
int nShowCmd
)
{
BOOL bRetVal = FALSE;
TCHAR pszKey[VOLT_MAX_PATH + VOLT_MAX_PATH];
PROCESS_INFORMATION ProcessInformation;
#if VOLT_COMPILER != VOLT_MS_EVC_4_0
STARTUPINFO StartupInfo =
{
sizeof(STARTUPINFO),
NULL,
NULL,
NULL,
0, 0,
0, 0,
0, 0,
0,
STARTF_USESHOWWINDOW,
nShowCmd,
0,
NULL,
NULL,
NULL,
NULL
};
#else
//ignore value
STARTUPINFO StartupInfo =
{
sizeof(STARTUPINFO),
NULL,
NULL,
NULL,
0, 0,
0, 0,
0, 0,
0,
0,
0,
0,
NULL,
NULL,
NULL,
NULL
};
#endif
/* get the .htm regkey and lookup the program
*/
if (GetRegKey (HKEY_CLASSES_ROOT, _T(".htm"), pszKey) == ERROR_SUCCESS)
{
lstrcat (pszKey, _T("\\shell\\open\\command"));
if (GetRegKey (HKEY_CLASSES_ROOT, pszKey, pszKey) == ERROR_SUCCESS)
{
LPTSTR lpchPos = _tcsstr(pszKey, _T("\"%1\""));
// if no quotes
if (lpchPos == NULL)
{
// now check for %1, without the quotes
lpchPos = _tcsstr (pszKey, _T("%1"));
if (lpchPos == NULL)
// if no parameter
lpchPos = pszKey + lstrlen (pszKey) - 1;
else
// remove the parameter
*lpchPos = _T('\0');
}
else
{
// remove the parameter
*lpchPos = _T('\0');
}
lstrcat (lpchPos, _T(" "));
lstrcat (lpchPos, lpszUrl);
bRetVal = CreateProcess (
NULL,
pszKey,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&StartupInfo,
&ProcessInformation);
if (bRetVal)
{
CloseHandle(ProcessInformation.hProcess);
CloseHandle(ProcessInformation.hThread);
}
}
}
return bRetVal;
}
static LONG GetRegKey (
HKEY hKeyBase,
LPCTSTR lpSubKey,
LPTSTR lpszRetData
)
{
HKEY hKey;
LONG lRetVal;
lRetVal = RegOpenKeyEx (hKeyBase, lpSubKey, 0, KEY_QUERY_VALUE, &hKey);
if (lRetVal == ERROR_SUCCESS)
{
TCHAR pszData[VOLT_MAX_PATH];
DWORD dwDataSize = sizeof(pszData);
lRetVal = RegQueryValueEx (
hKey, NULL, NULL, NULL, (LPBYTE)pszData, &dwDataSize);
if (lRetVal == ERROR_SUCCESS)
lstrcpy (lpszRetData, pszData);
RegCloseKey (hKey);
}
return lRetVal;
}
#else
int mDoActivateURL (
VoltLibCtx *libCtx,
unsigned char *url
)
{
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_SET_FNCT_LINE (fnctLine)
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, VT_ERROR_UNIMPLEMENTED, VT_ERROR_TYPE_PRIMARY,
fnctLine, "mDoActivateURL", (char *)0)
return (VT_ERROR_UNIMPLEMENTED);
}
#endif /* VOLT_OS == VOLT_WINDOWS_32 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -