From: <no...@us...> - 2003-06-20 20:19:12
|
Log Message: ----------- Changes to updater to check requirements on files Still needs to be able to handle files in use Modified Files: -------------- /cvsroot/decaldev/source/DenAgent: AutoUpdate.h AutoUpdate.cpp Revision Data ------------- Index: AutoUpdate.h =================================================================== RCS file: /cvsroot/decaldev/source/DenAgent/AutoUpdate.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- AutoUpdate.h 27 May 2002 17:39:28 -0000 1.3 +++ AutoUpdate.h 20 Jun 2003 20:19:11 -0000 1.4 @@ -24,6 +24,15 @@ AU_TYPE_BETADLL }; +class UpdateRequirement +{ +public: + UpdateRequirement(std::string File, std::string Version): + sFile(File), sVers(Version) { } + std::string sFile; + std::string sVers; +}; + class AutoUpdateSource { public: AutoUpdateSource(std::string decalPath, AutoUpdateType type, std::string localTarget, std::string remoteSource, std::string requiredVersion); @@ -32,6 +41,8 @@ std::string getSource(); std::string getDestination(); AutoUpdateType getType(); + bool isOutDatedVersion(std::string sFile, int nMajor, int nMinor, int nPatch, int nBuild); + void AddRequirement(UpdateRequirement reqUpdate); private: std::string m_LocalTarget; @@ -39,6 +50,7 @@ std::string m_RequiredVersion; std::string m_DecalDir; AutoUpdateType m_Type; + std::vector<UpdateRequirement> m_Requirements; }; class AutoUpdate { Index: AutoUpdate.cpp =================================================================== RCS file: /cvsroot/decaldev/source/DenAgent/AutoUpdate.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- AutoUpdate.cpp 23 May 2003 02:20:47 -0000 1.9 +++ AutoUpdate.cpp 20 Jun 2003 20:19:11 -0000 1.10 @@ -81,7 +81,6 @@ if (OpenFile(localTarget.c_str(), &targetFile, OF_EXIST) == HFILE_ERROR) { // It didn't exist, we must update - return true; } @@ -132,42 +131,28 @@ return true ; // if error reading xml, assume needs updating } } else if (m_Type == AU_TYPE_DLL || m_Type == AU_TYPE_BETADLL) { - // Extract the DLL version - DWORD dwDummy, dwVerSize; - - dwVerSize = ::GetFileVersionInfoSize(const_cast<LPTSTR>(localTarget.c_str()), &dwDummy); - - if (dwVerSize == 0) { - return true; // if file vsn not available, assume needs updating - } else { - BYTE *pbVersionInfo = reinterpret_cast< BYTE * >(::_alloca(dwVerSize)); - - ::GetFileVersionInfo(const_cast<LPTSTR>(localTarget.c_str()), 0, dwVerSize, pbVersionInfo); - - VS_FIXEDFILEINFO *vffi; - UINT nLength = sizeof(VS_FIXEDFILEINFO); - - if(::VerQueryValue(pbVersionInfo, _T("\\"), reinterpret_cast<LPVOID *>(&vffi), &nLength)) { - // Got it, so format it - int locMajor(0), locMinor(0), locPatch(0), locBuild(0) ; - locMajor = static_cast<int>(HIWORD(vffi->dwFileVersionMS)); - locMinor = static_cast<int>(LOWORD(vffi->dwFileVersionMS)); - locPatch = static_cast<int>(HIWORD(vffi->dwFileVersionLS)); - locBuild = static_cast<int>(LOWORD(vffi->dwFileVersionLS)); - if (locMajor==reqMajor) { - if (locMinor==reqMinor) { - if (locPatch==reqPatch) { - return locBuild<reqBuild ; - } else { - return locPatch<reqPatch ; - } - } else { - return locMinor<reqMinor ; - } - } else { - return locMajor<reqMajor ; + // Check to see if the file itself needs updating + if (isOutDatedVersion(localTarget, reqMajor, reqMinor, reqPatch, reqBuild)) + { + // File is outdated, check requirements + std::vector<UpdateRequirement>::iterator it; + for (it = m_Requirements.begin(); it != m_Requirements.end(); ++it) + { + UpdateRequirement ur = *it; + localTarget = m_DecalDir + "/" + ur.sFile; + sscanf(ur.sVers.c_str(), "%i.%i.%i.%i", &reqMajor, &reqMinor, &reqPatch, &reqBuild); + if (isOutDatedVersion(localTarget, reqMajor, reqMinor, reqPatch, reqBuild)) + { + std::string sMsg = m_LocalTarget + " cannot be updated because one or more dependencies is outdated"; + ::MessageBox(0, _T(sMsg.c_str()), NULL, S_OK); + return false; } } + return true; + } + else // File is newer, ignore requirements and exit + { + return false; } } // if anything went wrong or we were unable to tell whether it should be updated @@ -187,6 +172,54 @@ return m_Type; } +bool AutoUpdateSource::isOutDatedVersion(std::string sFile, int nMajor, int nMinor, int nPatch, int nBuild) +{ + // Extract the DLL version + DWORD dwDummy, dwVerSize; + + dwVerSize = ::GetFileVersionInfoSize(const_cast<LPTSTR>(sFile.c_str()), &dwDummy); + + if (dwVerSize == 0) + { + return true; // if file vsn not available, assume needs updating + } else { + BYTE *pbVersionInfo = reinterpret_cast< BYTE * >(::_alloca(dwVerSize)); + + ::GetFileVersionInfo(const_cast<LPTSTR>(sFile.c_str()), 0, dwVerSize, pbVersionInfo); + + VS_FIXEDFILEINFO *vffi; + UINT nLength = sizeof(VS_FIXEDFILEINFO); + + if(::VerQueryValue(pbVersionInfo, _T("\\"), reinterpret_cast<LPVOID *>(&vffi), &nLength)) + { + // Got it, so format it + int locMajor(0), locMinor(0), locPatch(0), locBuild(0) ; + locMajor = static_cast<int>(HIWORD(vffi->dwFileVersionMS)); + locMinor = static_cast<int>(LOWORD(vffi->dwFileVersionMS)); + locPatch = static_cast<int>(HIWORD(vffi->dwFileVersionLS)); + locBuild = static_cast<int>(LOWORD(vffi->dwFileVersionLS)); + if (locMajor==nMajor) { + if (locMinor==nMinor) { + if (locPatch==nPatch) { + return locBuild<nBuild ; + } else { + return locPatch<nPatch ; + } + } else { + return locMinor<nMinor ; + } + } else { + return locMajor<nMajor ; + } + } + } +} + +void AutoUpdateSource::AddRequirement(UpdateRequirement reqUpdate) +{ + m_Requirements.push_back(reqUpdate); +} + // AutoUpdate AutoUpdate::AutoUpdate(std::string decalDir) { @@ -297,6 +330,39 @@ version = OLE2T(bResult); AutoUpdateSource aUSource(m_DecalDir, type, localFile, remoteFile, version); + //if the source is dll || beta check for requirements + if (type == AU_TYPE_DLL || type == AU_TYPE_BETADLL) + { + MSXML::IXMLDOMNodeListPtr xmlReqs = NULL;//xmlFile->selectNodes(_T("requirement")); //pDoc->selectNodes(_T("/updatelist/file")); + xmlReqs = xmlFile->getElementsByTagName(_T("requirement")); + + if (xmlReqs.GetInterfacePtr() == NULL) + continue; + + for (MSXML::IXMLDOMElementPtr xmlNode = xmlReqs->nextNode(); xmlNode.GetInterfacePtr() != NULL; xmlNode = xmlReqs->nextNode()) + { + std::string sLocalFile, sVersion; + + // Read the file name + vResult = xmlNode->getAttribute("file"); + if (vResult.vt != VT_BSTR) + continue; + + bResult = vResult.bstrVal; + sLocalFile = OLE2T(bResult); + + // Read the version + vResult = xmlNode->getAttribute("version"); + if (vResult.vt != VT_BSTR) + continue; + + bResult = vResult.bstrVal; + sVersion = OLE2T(bResult); + + UpdateRequirement uReq(sLocalFile, sVersion); + aUSource.AddRequirement(uReq); + } + } // Add the source to the cache m_RemoteSources.push_back(aUSource); } |