⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jelreginstaller.cpp

📁 Java写的文本编辑器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * JELRegInstaller.cpp - part of jEditLauncher package * Copyright (C) 2001 John Gellene * jgellene@nyc.rr.com * * Notwithstanding the terms of the General Public License, the author grants * permission to compile and link object code generated by the compilation of * this program with object code and libraries that are not subject to the * GNU General Public License, provided that the executable output of such * compilation shall be distributed with source code on substantially the * same basis as the jEditLauncher package of which this program is a part. * By way of example, a distribution would satisfy this condition if it * included a working makefile for any freely available make utility that * runs on the Windows family of operating systems. This condition does not * require a licensee of this software to distribute any proprietary software * (including header files and libraries) that is licensed under terms * prohibiting redistribution to third parties. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * $Id: JELRegInstaller.cpp,v 1.9 2001/09/08 01:17:10 jgellene Exp $ */#include "stdafx.h"#include <string.h>#include "InstallData.h"#include "CtxMenuDlg.h"#include "StringPtr.h"#include "InstallerLog.h"#include "JELRegInstaller.h"#include <assert.h>#include <stdlib.h> // for itoa in debug/* Implementation of JELRegistryInstaller */JELRegistryInstaller::JELRegistryInstaller(const InstallData *ptrData,										   Installer *ptrOwner)	: pData(ptrData), pOwner(ptrOwner) {}JELRegistryInstaller::~JELRegistryInstaller() {}HRESULT JELRegistryInstaller::Install(){	InstallerLog::Log("Commencing installation of registry entires. . . .\n");	HRESULT hr;	// register proxy/stub DLL	CString strPath(pData->strInstallDir);	strPath += _T("\\jeservps.dll");	if(FAILED(hr = RegisterDLL(strPath, TRUE)))		return hr;	// registration of unlaunch for "Add/Remove Programs" applet	// other data added by COM server	RegisterUninstall();	// register COM server	strPath = pData->strInstallDir;	strPath += _T("\\jeditsrv.exe");	if(FAILED(hr = RegisterEXE(strPath)))	{		// TODO: try to restore former setting		return hr;	}	// register the context menu handler	if(FAILED(hr = RegisterDLL(pData->strInstallPath, TRUE)))		return hr;	// if we are still using the temporary file name, fix the	// registration entry so it will be correct after rebooting	if(pData->bUsingTempFileName)	{		if(FAILED(hr = CorrectTempCtxReg()))			return hr;	}	// tell parent object to update active version in InstallData	DWORD dwMsg = (MsgInstall << 16) | pData->nIndexSubjectVer;	pOwner->SendMessage((LPVOID)&dwMsg);	RegisterPrimaryVersion();	RegisterCmdLineParameters();	return hr;}HRESULT JELRegistryInstaller::RegisterDLL(LPCTSTR szPath, BOOL bRegister){	if(bRegister)	{		InstallerLog::Log("Registering %s. . .  ", szPath);	}	FARPROC proc = 0;	HRESULT hr;	LPCTSTR szProc = bRegister ? _T("DllRegisterServer") :		_T("DllUnregisterServer");	HMODULE hModule = ::LoadLibrary(szPath);	if(hModule == 0 || (proc = GetProcAddress(hModule, szProc)) == 0		|| S_OK != (proc)())	{		if(bRegister)			InstallerLog::Log("Registration failed.\n");		hr = E_FAIL;	}	else	{		if(bRegister)			InstallerLog::Log("Registration succeeded.\n");		hr = S_OK;	}	if(hModule != 0)		FreeLibrary(hModule);	return hr;}HRESULT JELRegistryInstaller::RegisterEXE(LPCTSTR szPath, BOOL bRegister){	if(bRegister)	{		InstallerLog::Log("Registering %s. . .  ", szPath);	}	CString strCmdLine(szPath);	strCmdLine += (bRegister ? _T(" /RegServer") : _T(" /UnregServer"));	CStringBuf<> bufCmdLine(strCmdLine);	STARTUPINFO si;	::ZeroMemory(&si, sizeof(si));	PROCESS_INFORMATION pi;	BOOL bReturn =  CreateProcess(0, bufCmdLine, 0, 0, 0, 0, 0, 0, &si, &pi);	if(!bReturn)	{		if(bRegister)			InstallerLog::Log("Registration failed.\n");		DWORD swError = GetLastError();	}	else	{		if(bRegister)			InstallerLog::Log("Registration succeeded.\n");	}	return bReturn ? S_OK : E_FAIL;}HRESULT JELRegistryInstaller::CorrectTempCtxReg(){	HKEY hKey = 0;	CString strClassKeyPath((LPCSTR)IDS_REG_CTX_SERVER_KEY);	int nResult = RegOpenKeyEx(HKEY_CLASSES_ROOT,		strClassKeyPath, 0, KEY_SET_VALUE, &hKey);	if(nResult == ERROR_SUCCESS)	{		nResult = RegSetValueEx(hKey, 0, 0, REG_SZ,			(const LPBYTE)(LPCTSTR)pData->strInstallFinalPath,			InstallData::GetBufferByteLen(pData->strInstallFinalPath));	}	RegCloseKey(hKey);	return nResult == ERROR_SUCCESS ? S_OK : E_FAIL;}HRESULT JELRegistryInstaller::RegisterUninstall(){	InstallerLog::Log("Registering uninstall data for Add/Remove programs...\n");	HKEY hKey;	CString strUninstallKey((LPCSTR)IDS_REG_UNINSTALL_KEY);	strUninstallKey += pData->strInstallVersion;	::OutputDebugString(strUninstallKey);	int nResult = RegCreateKeyEx(HKEY_CURRENT_USER,		strUninstallKey, 0, 0, REG_OPTION_NON_VOLATILE,		KEY_WRITE, 0, &hKey, 0);	if(nResult == ERROR_SUCCESS)	{		InstallerLog::Log("Found uninstall key\n");		CString strUninstall(pData->strInstallDir);		strUninstall += "\\unlaunch.exe";		nResult = RegSetValueEx(hKey, "UninstallString", 0, REG_SZ,			(const LPBYTE)(LPCTSTR)strUninstall,			InstallData::GetBufferByteLen(strUninstall));		InstallerLog::Log("UninstallString %s.\n",			nResult == ERROR_SUCCESS ? "OK" : "error");		CString strInstall(pData->strInstallDir);		strInstall += "\\jedit.exe /i ";		strInstall += pData->strJavaHome;		nResult = RegSetValueEx(hKey, "InstallPath", 0, REG_SZ,			(const LPBYTE)(LPCTSTR)strInstall,			InstallData::GetBufferByteLen(strInstall));		InstallerLog::Log("Install Path %s.\n", 			nResult == ERROR_SUCCESS ? "OK" : "error");		CString strDisplayIcon(pData->strInstallDir);		strDisplayIcon += "\\jedit.exe, 0";		nResult = RegSetValueEx(hKey, "DisplayIcon", 0, REG_SZ,			(const LPBYTE)(LPCTSTR)strDisplayIcon,			InstallData::GetBufferByteLen(strDisplayIcon));		InstallerLog::Log("Display Icon %s.\n",			nResult == ERROR_SUCCESS ? "OK" : "error");	}	else		InstallerLog::Log("Could not find uninstall registry key\n");	RegCloseKey(hKey);	InstallerLog::Log(nResult == ERROR_SUCCESS ?		"Uninstall registration succeeded.\n" :		"Uninstall registration failed.\n");	return (nResult == ERROR_SUCCESS ? S_OK : E_FAIL);}HRESULT JELRegistryInstaller::RegisterPrimaryVersion(){	InstallerLog::Log("Checking for multiple installations. . . .\n");	if(pData->nInstalledVersions == 0)		return S_FALSE;	int nIndexPrimaryVer = pData->nIndexSubjectVer;	if(pData->nInstalledVersions > 1)	{		CChooseCtxMenuDlg dlg(pData);		dlg.DoModal();		nIndexPrimaryVer = dlg.GetCtxVersionIndex();	}	DWORD dwMessage = (MsgChangePrimary << 16) | nIndexPrimaryVer;	pOwner->SendMessage((LPVOID)&dwMessage);	// register scripting object and designated context menu handler	// get default value for GUID	// get ProgID under GUID	// default value becomes default value for class 'JEdit.JEditLauncher'	// CLSID is GUID	// CurVer is ProgID	CString strClassKey(_T("CLSID\\"));	CString& strGUID = pData->arGUID[nIndexPrimaryVer];	strClassKey += strGUID;	CString strClassName;	CString strCurVer;	CString strCurVerDir;	HKEY hKey;	int nResult;	int nCounter = 20;	// waiting for possible registration of new server in separate thread	do	{		Sleep(50);		nResult = RegOpenKeyEx(HKEY_CLASSES_ROOT, strClassKey, 0,			KEY_READ | KEY_QUERY_VALUE, &hKey);	} while(nResult != ERROR_SUCCESS && --nCounter != 0);	if(nResult == ERROR_SUCCESS)	{		CStringBuf<>pClassBuf(strClassName);		DWORD dwLength = pClassBuf.Size();		RegQueryValueEx(hKey, 0, 0, 0, (LPBYTE)pClassBuf, &dwLength);		HKEY hSubkey;		nResult = RegOpenKeyEx(hKey, _T("ProgID"), 0, KEY_READ, &hSubkey);		if(nResult == ERROR_SUCCESS)		{			CStringBuf<>pCurVerBuf(strCurVer);			dwLength = pCurVerBuf.Size();			RegQueryValueEx(hSubkey, 0, 0, 0, (LPBYTE)pCurVerBuf, &dwLength);		}		RegCloseKey(hSubkey);		nResult = RegOpenKeyEx(hKey, _T("LocalServer32"), 0, KEY_READ, &hSubkey);		if(nResult == ERROR_SUCCESS)		{			CStringBuf<>pCurVerDirBuf(strCurVerDir);			dwLength = pCurVerDirBuf.Size();			RegQueryValueEx(hSubkey, 0, 0, 0, (LPBYTE)pCurVerDirBuf, &dwLength);			InstallData::ShortenToDirectory(pCurVerDirBuf);		}		RegCloseKey(hSubkey);	}	RegCloseKey(hKey);	nResult = RegCreateKeyEx(HKEY_CLASSES_ROOT, _T("JEdit.JEditLauncher"), 0, 0, 0,		KEY_ALL_ACCESS, 0, &hKey, 0);	if(nResult == ERROR_SUCCESS)	{		RegSetValueEx(hKey, 0, 0, REG_SZ, (LPBYTE)(LPCTSTR)strClassName,			InstallData::GetBufferByteLen(strClassName));		HKEY hSubkey;		nResult = RegCreateKeyEx(hKey, _T("CLSID"), 0, 0, 0, KEY_ALL_ACCESS,			0, &hSubkey, 0);		if(nResult == ERROR_SUCCESS)		{			RegSetValueEx(hSubkey, 0, 0, REG_SZ, (LPBYTE)(LPCTSTR)strGUID,				InstallData::GetBufferByteLen(strGUID));		}		RegCloseKey(hSubkey);		nResult = RegCreateKeyEx(hKey, _T("CurVer"), 0, 0, 0, KEY_ALL_ACCESS,			0, &hSubkey, 0);		if(nResult == ERROR_SUCCESS)		{			RegSetValueEx(hSubkey, 0, 0, REG_SZ, (LPBYTE)(LPCTSTR)strCurVer,				InstallData::GetBufferByteLen(strCurVer));		}		RegCloseKey(hSubkey);	}	RegCloseKey(hKey);	if(nResult != ERROR_SUCCESS)		return E_FAIL;	if(nIndexPrimaryVer != pData->nIndexSubjectVer)	{		InstallerLog::Log("Found multiple versions, registering version found in:\n");		InstallerLog::Log((LPCTSTR)strCurVerDir);		CString strNewPrimaryPath(strCurVerDir);		strNewPrimaryPath += _T("\\jeshlstb.dll");		RegisterDLL(strNewPrimaryPath, TRUE);		strNewPrimaryPath = strCurVerDir;		strNewPrimaryPath += _T("\\jeservps.dll");		RegisterDLL(strNewPrimaryPath, TRUE);		strNewPrimaryPath = strCurVerDir;		strNewPrimaryPath += _T("\\jeditsrv.exe");		RegisterEXE(strNewPrimaryPath, TRUE);	}	return S_OK;}HRESULT JELRegistryInstaller::RegisterCmdLineParameters(){	InstallerLog::Log("Registering command line parameters. . . .\n");	HKEY hLauncherKey, hVersionKey;	DWORD dwDisp;	int nResult;	DWORD dwValueSize;	TCHAR szBuf[MAX_PATH];	TCHAR* arszValues[] = { _T("Java Executable"),							_T("Java Options"),							_T("jEdit Target"),							_T("jEdit Options"),							_T("jEdit Working Directory"),							_T("Launcher GUID"),							_T("Installation Directory") };/*	enum { JavaExec, JavaOptions, jEditTarget, jEditOptions,			Server, WorkingDir, GUID, InstallDir };*/	// ask if parameters should be retained from last installation	bool bUseOldParameters = false;	if(pData->nIndexCurrentVer != -1		&& IDYES == MessageBox(0,			"Do you wish to retain command line parameters from your existing installation of jEditLauncher?",			"jEditLauncher", MB_ICONQUESTION | MB_YESNO))	{		InstallerLog::Log("Using parameters from existing installation.\n");		bUseOldParameters = true;	}	else	{		InstallerLog::Log("Writing default parameters.\n");	}	CString strLauncherParamKeyPath((LPCSTR)IDS_REG_LAUNCHER_PARAM_KEY);	RegCreateKeyEx(HKEY_CURRENT_USER, strLauncherParamKeyPath, 0, 0, 0,			KEY_ALL_ACCESS, 0, &hLauncherKey, 0);	CString strVersion(pData->arVersionNames[pData->nIndexSubjectVer]);	RegCreateKeyEx(hLauncherKey, strVersion, 0, 0, 0,		KEY_ALL_ACCESS, 0, &hVersionKey, &dwDisp);	// "Java Executable"	if(!bUseOldParameters)	{		nResult = RegQueryValueEx(hVersionKey, arszValues[0], 0, 0, 0, &dwValueSize);		if(nResult != ERROR_SUCCESS || dwValueSize == 0)		{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -