VersionString::VersionString(const std::string& version) : m_str(version) { boost::regex versionRegex("(\\d+)\\.(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?"); boost::smatch m; if (boost::regex_match(version,m,versionRegex)) { m_major = boost::lexical_cast<int>(std::string(m[1].first,m[1].second)); m_minor = boost::lexical_cast<int>(std::string(m[2].first,m[2].second)); int n = m.size(); if (3 < n) { std::string temp(m[3].first,m[3].second); if (!temp.empty()) { m_patch = boost::lexical_cast<int>(temp); } } if (4 < n) { std::string temp(m[4].first,m[4].second); if (!temp.empty()) { m_build = boost::lexical_cast<int>(temp); } } } else { LOG_FREE_AND_THROW("openstudio.utilities.VersionString", "Could not parse '" << version << "' as a version string."); } }
bool UpdateManager::checkRelease(const QDomElement& release) { bool updateAvailable = false; try{ std::string version = release.attribute("version").toStdString(); std::string currentVersion = openStudioVersion(); boost::regex versionRegex("^([0-9]+)\\.([0-9]+)\\.([0-9]+).*?"); boost::smatch versionMatch; boost::smatch currentVersionMatch; if( boost::regex_search(version, versionMatch, versionRegex) && boost::regex_search(currentVersion, currentVersionMatch, versionRegex)){ std::string versionMajorString = std::string(versionMatch[1].first,versionMatch[1].second); boost::trim(versionMajorString); std::string versionMinorString = std::string(versionMatch[2].first,versionMatch[2].second); boost::trim(versionMinorString); std::string versionPatchString = std::string(versionMatch[3].first,versionMatch[3].second); boost::trim(versionPatchString); unsigned versionMajor = boost::lexical_cast<unsigned>(versionMajorString); unsigned versionMinor = boost::lexical_cast<unsigned>(versionMinorString); unsigned versionPatch = boost::lexical_cast<unsigned>(versionPatchString); std::string currentVersionMajorString = std::string(currentVersionMatch[1].first,currentVersionMatch[1].second); boost::trim(currentVersionMajorString); std::string currentVersionMinorString = std::string(currentVersionMatch[2].first,currentVersionMatch[2].second); boost::trim(currentVersionMinorString); std::string currentVersionPatchString = std::string(currentVersionMatch[3].first,currentVersionMatch[3].second); boost::trim(currentVersionPatchString); unsigned currentVersionMajor = boost::lexical_cast<unsigned>(currentVersionMajorString); unsigned currentVersionMinor = boost::lexical_cast<unsigned>(currentVersionMinorString); unsigned currentVersionPatch = boost::lexical_cast<unsigned>(currentVersionPatchString); if (versionMajor > currentVersionMajor){ m_newMajorRelease = true; updateAvailable = true; }else if(versionMajor == currentVersionMajor){ if (versionMinor > currentVersionMinor){ m_newMinorRelease = true; updateAvailable = true; }else if(versionMinor == currentVersionMinor){ if (versionPatch > currentVersionPatch){ m_newPatchRelease = true; updateAvailable = true; } } } if (updateAvailable){ // only set download url to most recent (e.g. first) release if (m_updateMessages.empty()){ m_mostRecentVersion = version; m_mostRecentDownloadUrl = release.attribute("download").toStdString(); } // add messages from all releases newer than current m_updateMessages.push_back(release.firstChild().toCDATASection().data().toStdString()); } } }catch(const std::exception& e){ LOG(Error, e.what()); } return updateAvailable; }