?? jelreginstaller.cpp
字號:
"Could not write \"Java Options\" registry parameter.\n"); bResult &= false; } } else { UpdateJarParameter(szBuf); nResult = RegSetValueEx(hVersionKey, arszValues[1], 0, REG_SZ, (LPBYTE)szBuf, (_tcslen(szBuf) + 1) * sizeof(TCHAR)); if(ERROR_SUCCESS == nResult) { InstallerLog::Log(Debug, "Updating \"Java Options\" registry parameter: %s\n", (LPCSTR)szBuf); } else { InstallerLog::Log(Error, "Could not write \"Java Options\" registry parameter.\n"); bResult &= false; } } // "jEdit Target" -- must always be set CString strJEditTarget; dwValueSize = MAX_PATH; nResult = RegQueryValueEx(hVersionKey, arszValues[2], 0, 0, (LPBYTE)szBuf, &dwValueSize); if(nResult != ERROR_SUCCESS || dwValueSize == 0 || strstr(szBuf, "jedit.jar") != 0) { strJEditTarget = _T("\""); strJEditTarget += pData->strInstallDir; strJEditTarget += _T("\\jedit.jar\""); } else { strJEditTarget = _T("org.gjt.sp.jedit.jEdit"); } nResult = RegSetValueEx(hVersionKey, arszValues[2], 0, REG_SZ, (LPBYTE)(LPCTSTR)strJEditTarget, InstallData::GetBufferByteLen(strJEditTarget)); if(ERROR_SUCCESS == nResult) { InstallerLog::Log(Debug, "Writing \"jEdit Target\" registry parameter: %s\n", (LPCSTR)strJEditTarget); } else { InstallerLog::Log(Error, "Could not write \"jEdit Target\" registry parameter.\n"); bResult &= false; } // "jEdit Options" - default is no options; // make sure an empty item is written dwValueSize = MAX_PATH; nResult = RegQueryValueEx(hVersionKey, arszValues[3], 0, 0, (LPBYTE)szBuf, &dwValueSize); if(!bUseOldParameters || nResult != ERROR_SUCCESS) { // "jEdit Options" char szBuf = 0; nResult = RegSetValueEx(hVersionKey, arszValues[3], 0, REG_SZ, (LPBYTE)&szBuf, sizeof(TCHAR)); if(ERROR_SUCCESS == nResult) { InstallerLog::Log(Debug, "Writing empty \"jEdit Options\" registry parameter.\n"); } else { InstallerLog::Log(Error, "Could not write \"jEdit Options\" registry parameter.\n"); bResult &= false; } } // "jEdit Working Directory" // always change working directory, so you can't get // an orphan entry following an uninstall of another version CString strWorkingDir(pData->strInstallDir); nResult = RegSetValueEx(hVersionKey, arszValues[4], 0, REG_SZ, (LPBYTE)(LPCTSTR)strWorkingDir, InstallData::GetBufferByteLen(strWorkingDir)); if(ERROR_SUCCESS == nResult) { InstallerLog::Log(Debug, "Writing \"jEdit Working Directory\" registry parameter: %s\n", (LPCTSTR)strWorkingDir); } else { InstallerLog::Log(Error, "Could not write \"jEdit Working Directory\" registry parameter.\n"); bResult &= false; } // "Launcher GUID" nResult = RegSetValueEx(hVersionKey, arszValues[5], 0, REG_SZ, (LPBYTE)(LPCTSTR)pData->strInstallGUID, InstallData::GetBufferByteLen(pData->strInstallGUID)); if(ERROR_SUCCESS == nResult) { InstallerLog::Log(Debug, "Writing \"Launcher GUID\" registry parameter: %s\n", (LPCTSTR)pData->strInstallGUID); } else { InstallerLog::Log(Error, "Could not write \"Launcher GUID\" registry parameter.\n"); bResult &= false; } // "Installation Dir" nResult = RegSetValueEx(hVersionKey, arszValues[6], 0, REG_SZ, (LPBYTE)(LPCTSTR)pData->strInstallDir, InstallData::GetBufferByteLen(pData->strInstallDir)); if(ERROR_SUCCESS == nResult) { InstallerLog::Log(Debug, "Writing \"Installation Dir\" registry parameter: %s\n", (LPCTSTR)pData->strInstallDir); } else { InstallerLog::Log(Error, "Could not write \"Installation Dir\" registry parameter.\n"); bResult &= false; } // "Launcher Log Level": set to -1 if not previously set dwValueSize = MAX_PATH; nResult = RegQueryValueEx(hVersionKey, arszValues[7], 0, 0, (LPBYTE)szBuf, &dwValueSize); if(!bUseOldParameters || nResult != ERROR_SUCCESS || dwValueSize == 0) { DWORD dwDebug = (DWORD)-1; nResult = RegSetValueEx(hVersionKey, arszValues[7], 0, REG_DWORD, (LPBYTE)&dwDebug, sizeof(DWORD)); if(ERROR_SUCCESS == nResult) { InstallerLog::Log(Debug, "Writing \"Launcher Log Level\" registry parameter: %d\n", dwDebug); } else { InstallerLog::Log(Error, "Could not write \"Launcher Log Level\" registry parameter.\n"); bResult &= false; } } RegCloseKey(hVersionKey); RegCloseKey(hLauncherKey); InstallerLog::Log(Message, "Registration of command line parameters %s.\n", bResult ? "succeeded" : "failed"); return S_OK;}// if "jEdit.jar" appears in the parameter,// get the associated directory and change to the// current install directoryvoid JELRegistryInstaller::UpdateJarParameter(LPTSTR lpszParam){ CString strLCParam(lpszParam); strLCParam.MakeLower(); const TCHAR *pJar = lpszParam + strLCParam.Find(_T("jedit.jar")); if(pJar <= lpszParam) return; bool quoted = false; const TCHAR *pStart = lpszParam; const TCHAR *p; for(p = lpszParam; p < pJar; ++p) { switch (*p) { case _T(';'): pStart = p; break; case _T(' '): if(!quoted) pStart = p; break; case _T('\"'): quoted = !quoted; if(quoted) pStart = p; break; default: break; } } // now pStart points to the beginning of the jedit.jar path, // or a leading space, quote or semicolon; next we trim bool bContinue = true; for(p = pStart; bContinue && p < pJar; ++p) { switch(*p) { case _T(';'): case _T(' '): case _T('\"'): pStart = p; break; default: bContinue = false; break; } } // now we replace from pStart to pJar with the new install dir char szNewParam[MAX_PATH]; ZeroMemory(szNewParam, MAX_PATH); lstrcpyn(szNewParam, lpszParam, pStart - lpszParam); lstrcat(szNewParam, pData->strInstallDir); lstrcat(szNewParam, _T("\\")); lstrcat(szNewParam, pJar); lstrcpy(lpszParam, szNewParam);}HRESULT JELRegistryInstaller::Uninstall(){ UnregisterCmdLineParameters(); CString strDir(pData->strInstallDir); // unregister proxy/stub DLL CString strPath(strDir); strPath += _T("\\jeservps.dll"); RegisterDLL(strPath, FALSE); // clean up proxy/stub; this is interface GUID CString strPxStubCLSID(_T("CLSID\\{E53269FA-8A5C-42B0-B3BC-82254F4FCED4}")); RegDeleteKey(HKEY_CLASSES_ROOT, strPxStubCLSID + _T("\\InProcServer32")); RegDeleteKey(HKEY_CLASSES_ROOT, strPxStubCLSID); // unregister COM Server strPath = strDir; strPath += _T("\\jeditsrv.exe"); RegisterEXE(strPath, FALSE); CheckUnregisterCtxMenu(); // delete HKEY_CLASSES_ROOT\JEdit.JEditLauncher and interface key if nothing is left HKEY hLauncherKey; if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CLASSES_ROOT, _T("JEdit.JEditLauncher"), 0, KEY_ALL_ACCESS, &hLauncherKey)) { RegDeleteKey(hLauncherKey, _T("CLSID")); RegDeleteKey(hLauncherKey, _T("CurVer")); RegCloseKey(hLauncherKey); RegDeleteKey(HKEY_CLASSES_ROOT, _T("JEdit.JEditLauncher")); } CString strInterfaceKey(_T("Interface\\{E53269FA-8A5C-42B0-B3BC-82254F4FCED4}")); if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CLASSES_ROOT, strInterfaceKey, 0, KEY_ALL_ACCESS, &hLauncherKey)) { RegDeleteKey(hLauncherKey, _T("NumMethods")); RegDeleteKey(hLauncherKey, _T("ProxyStubClsid")); RegDeleteKey(hLauncherKey, _T("ProxyStubClsid32")); RegDeleteKey(hLauncherKey, _T("TypeLib")); RegCloseKey(hLauncherKey); RegDeleteKey(HKEY_CLASSES_ROOT, strInterfaceKey); } return S_OK;}HRESULT JELRegistryInstaller::UnregisterCmdLineParameters(){ HKEY hKey; // delete command line parameters and any empty parent keys CString strLauncherParamKey((LPCSTR)IDS_REG_LAUNCHER_PARAM_KEY); int nResult = RegOpenKeyEx(HKEY_CURRENT_USER, strLauncherParamKey, 0, KEY_ALL_ACCESS, &hKey); if(nResult == ERROR_SUCCESS) { CString strVersion(pData->strInstallVersion); RegDeleteKey(hKey, strVersion); DWORD dwSubkeys; RegQueryInfoKey(hKey, 0, 0, 0, &dwSubkeys, 0, 0, 0, 0, 0, 0, 0); if(dwSubkeys == 0) { RegCloseKey(hKey); if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\www.jedit.org"), 0, KEY_ALL_ACCESS, &hKey)) { RegDeleteKey(hKey, _T("jEditLauncher")); RegQueryInfoKey(hKey, 0, 0, 0, &dwSubkeys, 0, 0, 0, 0, 0, 0, 0); if(dwSubkeys == 0) { RegCloseKey(hKey); if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software"), 0, KEY_ALL_ACCESS, &hKey)) { RegDeleteKey(hKey, _T("www.jedit.org")); } } } } } RegCloseKey(hKey); return S_OK;}// Unregisters ctx menu handler if the current version is installedHRESULT JELRegistryInstaller::CheckUnregisterCtxMenu(){ // first get the CLSID of the installed handler CString strCtxMenuKey((LPCSTR)IDS_REG_CTXMENU_KEY); CString strCurCtxMenuCLSID; HKEY hCtxMenuKey; int nResult = RegOpenKeyEx(HKEY_CLASSES_ROOT, strCtxMenuKey, 0, KEY_ALL_ACCESS, &hCtxMenuKey); if(nResult == ERROR_SUCCESS) { CStringBuf<>buf(strCurCtxMenuCLSID); DWORD dwlength = buf * sizeof(TCHAR); nResult = RegQueryValueEx(hCtxMenuKey, 0, 0, 0, (LPBYTE)buf, &dwlength); } RegCloseKey(hCtxMenuKey); // now get the path to the handler module from the CLSID CString strCurCtxMenuPath; CString strServerKey(_T("CLSID\\")); strServerKey += strCurCtxMenuCLSID; strServerKey += _T("\\InprocServer32"); nResult = RegOpenKeyEx(HKEY_CLASSES_ROOT, strServerKey, 0, KEY_ALL_ACCESS, &hCtxMenuKey); if(nResult == ERROR_SUCCESS) { CStringBuf<>buf(strCurCtxMenuPath); DWORD dwlength = buf * sizeof(TCHAR); nResult = RegQueryValueEx(hCtxMenuKey, 0, 0, 0, (LPBYTE)buf, &dwlength); } RegCloseKey(hCtxMenuKey); // NOTE: Ctx menu now always installed // now compare the installed handler's path to // the path in this version and delete the key if they match// CString strPath(pData->arPathNames[pData->nIndexSubjectVer]);// strPath += _T("\\jeshlstb.dll");// TCHAR szInstalledPath[MAX_PATH], szCurPath[MAX_PATH];// GetShortPathName(strCurCtxMenuPath, szInstalledPath, MAX_PATH);// GetShortPathName(strPath, szCurPath, MAX_PATH);// HRESULT hr = S_OK;// if(_tcsicmp(szInstalledPath, szCurPath) == 0)// { RegDeleteKey(HKEY_CLASSES_ROOT, strCtxMenuKey); RegisterDLL(strCurCtxMenuPath, FALSE);// }// else hr = S_FALSE; return S_OK;}HRESULT JELRegistryInstaller::SendMessage(LPVOID p){ p; return E_NOTIMPL;}LONG JELRegistryInstaller::RegCopyKey(HKEY SrcKey, HKEY TrgKey, TCHAR* TrgSubKeyName){ HKEY SrcSubKey; HKEY TrgSubKey; int ValEnumIndx=0; int KeyEnumIndx=0; char ValName[MAX_PATH+1]; char KeyName[MAX_PATH+1]; DWORD size; DWORD VarType; LONG nResult; DWORD KeyDisposition; FILETIME LastWriteTime; CString strBuffer; // create target key nResult = RegCreateKeyEx(TrgKey, TrgSubKeyName, NULL, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &TrgSubKey, &KeyDisposition); if(nResult != ERROR_SUCCESS) return nResult; do { do { // read value from source key CStringBuf<1024> buffer(strBuffer); ULONG buffSize = (ULONG)buffer.Size(); size=MAX_PATH+1; nResult = RegEnumValue(SrcKey, ValEnumIndx, ValName, &size, NULL, &VarType, buffer, &buffSize); // done copying this key if (nResult == ERROR_NO_MORE_ITEMS) { nResult = ERROR_SUCCESS; break; } if(nResult != ERROR_SUCCESS) break; // write value to target key nResult = RegSetValueEx(TrgSubKey, ValName, NULL, VarType, buffer, buffSize); if(nResult != ERROR_SUCCESS) break; // read next value ValEnumIndx++; } while (nResult == ERROR_SUCCESS); // if copying under the same key avoid endless recursions TCHAR TrgSubKeyNameRoot[1024]; do { // enum sub keys size=MAX_PATH+1; nResult = RegEnumKeyEx(SrcKey, KeyEnumIndx++, KeyName, &size, NULL, NULL, NULL, &LastWriteTime); lstrcpyn(TrgSubKeyNameRoot, TrgSubKeyName, lstrlen(TrgSubKeyName) + 1); } while ((SrcKey == TrgKey) && (nResult == ERROR_SUCCESS) && !lstrcmpi(KeyName, TrgSubKeyNameRoot)); // done copying this key if (nResult == ERROR_NO_MORE_ITEMS) break; // unknown error return if (nResult != ERROR_SUCCESS) break; // open the source subkey InstallerLog::Log(Debug, "Opening sub key %s\n", KeyName); nResult = RegOpenKeyEx(SrcKey, KeyName, NULL, KEY_ALL_ACCESS, &SrcSubKey); if(nResult != ERROR_SUCCESS) break; // recurs with the subkey nResult = RegCopyKey(SrcSubKey, TrgSubKey, KeyName); if(nResult != ERROR_SUCCESS) break; nResult = RegCloseKey(SrcSubKey); if(nResult != ERROR_SUCCESS) break; } while (true); RegCloseKey(TrgSubKey); if (nResult == ERROR_NO_MORE_ITEMS) return ERROR_SUCCESS; else return nResult;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -