static BOOL pIsUpdateRequiredVersion( LPTSTR szFilename, ULONG ulMinVer) { // get version of update package DWORD dwUpdateMSVer; DWORD dwRet = GetFileVersionNumber(szFilename, &dwUpdateMSVer, NULL); if (ERROR_SUCCESS != dwRet) { // can't obtain version information; assume not proper version DBGPRT_INFO(_FT("Can't obtain version information for update package;") _T("assuming it is not the proper version\n")); return FALSE; } // compare version at source to required minimum ULONG ulSourceVer = HIWORD(dwUpdateMSVer) * 100 + LOWORD(dwUpdateMSVer); if (ulSourceVer < ulMinVer) { // source version won't get us to our minimum version DBGPRT_INFO(_FT("The update package is improper version for upgrade.") _T("Update package Version = %d, Minimum Version = %d.\n"), ulSourceVer, ulMinVer); return FALSE; } return TRUE; }
bool IsUpdateRequiredVersion(__in LPSTR szFilename, ULONG ulMinVer) { // get version of update package DWORD dwUpdateMSVer; DWORD dwRet = GetFileVersionNumber(szFilename, &dwUpdateMSVer, NULL); if (ERROR_SUCCESS != dwRet) { // can't obtain version information; assume not proper version DebugMsg("[Info] Can't obtain version information for update package; assuming it is not the proper version\n"); return false; } // compare version at source to required minimum ULONG ulSourceVer = HIWORD(dwUpdateMSVer) * 100 + LOWORD(dwUpdateMSVer); if (ulSourceVer < ulMinVer) { // source version won't get us to our minimum version char szDebugOutput[MAX_STR_LENGTH] = {0}; DebugMsg("[Info] The update package is improper version for upgrade. Update package Version = %d, Minimum Version = %d.\n", ulSourceVer, ulMinVer); return false; } return true; }
bool IsMsiUpgradeNecessary(ULONG ulReqMsiMinVer) { // attempt to load msi.dll in the system directory char szSysMsiDll[MAX_PATH] = {0}; char szSystemFolder[MAX_PATH] = {0}; DWORD dwRet = WIN::GetSystemDirectory(szSystemFolder, MAX_PATH); if (0 == dwRet || MAX_PATH < dwRet) { // failure or buffer too small; assume upgrade is necessary DebugMsg("[Info] Can't obtain system directory; assuming upgrade is necessary"); return true; } if (FAILED(StringCchCopy(szSysMsiDll, sizeof(szSysMsiDll)/sizeof(szSysMsiDll[0]), szSystemFolder)) || FAILED(StringCchCat(szSysMsiDll, sizeof(szSysMsiDll)/sizeof(szSysMsiDll[0]), "\\MSI.DLL"))) { // failure to get path to msi.dll; assume upgrade is necessary DebugMsg("[Info] Can't obtain msi.dll path; assuming upgrade is necessary"); return true; } HINSTANCE hinstMsiSys = LoadLibrary(szSysMsiDll); if (0 == hinstMsiSys) { // can't load msi.dll; assume upgrade is necessary DebugMsg("[Info] Can't load msi.dll; assuming upgrade is necessary"); return true; } FreeLibrary(hinstMsiSys); // get version on msi.dll DWORD dwInstalledMSVer; dwRet = GetFileVersionNumber(szSysMsiDll, &dwInstalledMSVer, NULL); if (ERROR_SUCCESS != dwRet) { // can't obtain version information; assume upgrade is necessary DebugMsg("[Info] Can't obtain version information; assuming upgrade is necessary"); return true; } // compare version in system to the required minimum ULONG ulInstalledVer = HIWORD(dwInstalledMSVer) * 100 + LOWORD(dwInstalledMSVer); if (ulInstalledVer < ulReqMsiMinVer) { // upgrade is necessary DebugMsg("[Info] Windows Installer upgrade is required. System Version = %d, Minimum Version = %d.\n", ulInstalledVer, ulReqMsiMinVer); return true; } // no upgrade is necessary DebugMsg("[Info] No upgrade is necessary. System version meets minimum requirements\n"); return false; }
tstring CUtils::GetFileVersionStr(const tstring& strFilePath) { INT64 i = GetFileVersionNumber(strFilePath); int i1 = i/100000000; int i2 = (i%100000000)/1000000; int i3 = ((i%100000000)%1000000)/10000; int i4 = ((i%100000000)%1000000)%10000; return StrUtils::Format(_T("%d.%d.%d.%d"), i1, i2, i3, i4); }
BOOL IsMsiUpgradeNecessary(ULONG ulReqMsiMinVer) { // attempt to load msi.dll in the system directory HRESULT hr; TCHAR szSysMsiDll[MAX_PATH] = {0}; TCHAR szSystemFolder[MAX_PATH] = {0}; DWORD dwRet = ::GetSystemDirectory(szSystemFolder, MAX_PATH); if (0 == dwRet || MAX_PATH < dwRet) { // failure or buffer too small; assume upgrade is necessary DBGPRT_INFO(_FT("Can't obtain system directory; assuming upgrade is necessary")); return TRUE; } hr = ::StringCchCopy( szSysMsiDll, sizeof(szSysMsiDll)/sizeof(szSysMsiDll[0]), szSystemFolder); if (FAILED(hr)) { // failure to get path to msi.dll; assume upgrade is necessary DBGPRT_INFO(_FT("Can't obtain msi.dll path; assuming upgrade is necessary\n")); return TRUE; } hr = ::StringCchCat( szSysMsiDll, sizeof(szSysMsiDll)/sizeof(szSysMsiDll[0]), _T("\\MSI.DLL")); if (FAILED(hr)) { // failure to get path to msi.dll; assume upgrade is necessary DBGPRT_INFO(_FT("Can get path to msi.dll; assuming upgrade is necessary\n")); return TRUE; } HINSTANCE hinstMsiSys = ::LoadLibrary(szSysMsiDll); if (NULL == hinstMsiSys) { // can't load msi.dll; assume upgrade is necessary DBGPRT_INFO(_FT("Can't load msi.dll; assuming upgrade is necessary\n")); return TRUE; } ::FreeLibrary(hinstMsiSys); // get version on msi.dll DWORD dwInstalledMSVer; dwRet = GetFileVersionNumber(szSysMsiDll, &dwInstalledMSVer, NULL); if (ERROR_SUCCESS != dwRet) { // can't obtain version information; assume upgrade is necessary DBGPRT_INFO(_FT("Can't obtain version information; assuming upgrade is necessary\n")); return TRUE; } // compare version in system to the required minimum ULONG ulInstalledVer = HIWORD(dwInstalledMSVer) * 100 + LOWORD(dwInstalledMSVer); if (ulInstalledVer < ulReqMsiMinVer) { // upgrade is necessary DBGPRT_INFO(_FT("Windows Installer upgrade is required. System Version = %d, Minimum Version = %d.\n"), ulInstalledVer, ulReqMsiMinVer); return TRUE; } // no upgrade is necessary DBGPRT_INFO(_FT("No upgrade is necessary. System version meets minimum requirements\n")); return FALSE; }
HRESULT SetupInstallService() { TSAUTO(); wchar_t currentDllPath[MAX_PATH]; if(!GetModuleFileName(g_hModule, currentDllPath, MAX_PATH)) { return HRESULT_FROM_WIN32(::GetLastError()); } wchar_t serviceDllPath[MAX_PATH]; if(!GetAllUsersPublicPath(serviceDllPath, MAX_PATH)) { TSERROR4CXX("Failed to get public path."); return false; } std::size_t pathLength = std::wcslen(serviceDllPath); if(pathLength == 0 || pathLength + 1 == sizeof(serviceDllPath) / sizeof(serviceDllPath[0])) { return false; } if(serviceDllPath[pathLength - 1] != '\\') { serviceDllPath[pathLength++] = '\\'; } // ADClean\\addin\\CleanSvc.dll const wchar_t* addinSuffix = L"ADClean\\addin\\CleanSvc.dll"; std::size_t addinSuffixLength = std::wcslen(addinSuffix); if(pathLength + addinSuffixLength + 1 > sizeof(serviceDllPath) / sizeof(serviceDllPath[0])) { return false; } std::copy(addinSuffix, addinSuffix + addinSuffixLength + 1, serviceDllPath + pathLength); if(IsServiceInstalled()) { if(::PathFileExists(serviceDllPath)) { // 版本比较 DWORD old_v1, old_v2, old_v3, old_v4; DWORD new_v1, new_v2, new_v3, new_v4; if(!GetFileVersionNumber(serviceDllPath, old_v1, old_v2, old_v3, old_v4) || !GetFileVersionNumber(currentDllPath, new_v1, new_v2, new_v3, new_v4)) { TSERROR4CXX("Failed to get file version number."); if(!GetFileVersionNumber(serviceDllPath, old_v1, old_v2, old_v3, old_v4)) { TSINFO4CXX(serviceDllPath); } else { TSINFO4CXX(currentDllPath); } return false; } if(old_v1 > new_v1 || old_v2 > new_v2 || old_v3 > new_v3 || old_v4 > new_v4) { TSERROR4CXX("The old service dll is later than this."); return false; } } UninstallService(); } if(!CopyFilesToPublicFolder()) { TSERROR4CXX("CopyFilesToPublicFolder return false."); return E_FAIL; } return CreateGreenShieldService(serviceDllPath); }