Example #1
0
VersionString extractOpenStudioVersion(const QVariant& variant) {
  QJsonObject topLevel = QJsonDocument::fromVariant(variant).object();
  if (topLevel.contains("metadata")) {
    topLevel = topLevel["metadata"].toObject();
  }
  
  OptionalVersionString version;
  if (topLevel.contains("openstudio_version")) {
    version = VersionString(topLevel["openstudio_version"].toString().toStdString());
  }
  else if (topLevel.contains("version")) {
    version = VersionString(topLevel["version"].toString().toStdString());
  }
  else {
    LOG_FREE_AND_THROW("openstudio.core.Json","No version identifier found in QJSON variant.");
  }
  OS_ASSERT(version);
  if (version.get() > VersionString(openStudioVersion())) {
    LOG_FREE(Warn,"openstudio.Json","Loading json file from version " << version
             << " with OpenStudio version " << VersionString(openStudioVersion())
             << ". OpenStudio json files are not designed to be forwards-compatible. "
             << "Unexpected behavior may result.")
  }

  return version.get();
}
Example #2
0
void Component::parseBCLSearchResult(const BCLSearchResult & bclSearchResult)
{
  m_componentType = bclSearchResult.componentType().c_str();
  m_name = bclSearchResult.name().c_str();
  m_uid = bclSearchResult.uid().c_str();
  m_versionId = bclSearchResult.versionId().c_str();
  m_description = bclSearchResult.description().c_str();
  m_fidelityLevel = bclSearchResult.fidelityLevel().c_str();

  m_attributes = bclSearchResult.attributes();
  m_files = bclSearchResult.files();
  m_provenances = bclSearchResult.provenances();
  m_tags = bclSearchResult.tags();

  std::string componentVersion;
  Q_FOREACH(const BCLFile & file, m_files){
    if (file.usageType() == "script" && file.softwareProgram() == "OpenStudio"){
      componentVersion = file.identifier();
      break;
    }
  }
  if (!componentVersion.empty() && VersionString(componentVersion) > VersionString(openStudioVersion())){
    m_available = false;
  }else{
    m_available = true;
  }
}
Example #3
0
  UpdateManager::UpdateManager(const std::string& appName, const std::string& url)
    : m_appName(appName), m_finished(false), m_error(false), 
      m_newMajorRelease(false), m_newMinorRelease(false), m_newPatchRelease(false), 
      m_mostRecentVersion(openStudioVersion()), m_manager(new QNetworkAccessManager(this))
  {
    Application::instance().processEvents(); // a kludge to make sure that updatemanager works correctly in a non-application environment on unix



    connect(m_manager, &QNetworkAccessManager::finished, this, &UpdateManager::replyFinished);
    
    connect(this, &UpdateManager::processed, this, &UpdateManager::replyProcessed);
  
    m_request = new QNetworkRequest(QUrl(QString::fromStdString(url)));
    
    m_reply = m_manager->get(*m_request);
  }
Example #4
0
  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;
  }
Example #5
0
 std::string UpdateManager::updateUrl() const
 {
   return std::string("https://www.openstudio.net/update.html?app=") + appName() + std::string("&version=") + openStudioVersion();
 }
Example #6
0
Version::Version(const Model& model)
  : ModelObject(iddObjectType(),model)
{
  OS_ASSERT(getImpl<detail::Version_Impl>());
  setVersionIdentifier( openStudioVersion() );
}
Example #7
0
/// get the QApplication, if no QApplication has been set this will create a default one
QCoreApplication* ApplicationSingleton::application(bool gui)
{
  if (!m_qApplication){

    if (QCoreApplication::instance())
    {

      m_qApplication = QCoreApplication::instance();

    } else {

      QCoreApplication::setAttribute(Qt::AA_DontUseNativeMenuBar, true);
      QCoreApplication::setAttribute(Qt::AA_MacPluginApplication, true);

      // Add this path for gem case (possibly deprecated)
      QCoreApplication::addLibraryPath(toQString(getApplicationRunDirectory() / toPath("plugins")));

      // And for any other random cases (possibly deprecated, applies to super-built Qt on Linux)
      QCoreApplication::addLibraryPath(toQString(getApplicationRunDirectory().parent_path() / toPath("share/openstudio-" + openStudioVersion() + "/qtplugins")));

      // Make the run path the backup plugin search location
      QCoreApplication::addLibraryPath(toQString(getApplicationRunDirectory()));

      // Make the ruby path the default plugin search location
#if defined(Q_OS_MAC)
      openstudio::path p = getApplicationRunDirectory().parent_path().parent_path().parent_path() / toPath("Ruby/openstudio");
      QCoreApplication::addLibraryPath(toQString(p));
#elif defined(Q_OS_WIN)
      openstudio::path p = getApplicationRunDirectory().parent_path() / toPath("Ruby/openstudio");
      QCoreApplication::addLibraryPath(toQString(p));
#endif

      static char *argv[] = {nullptr};
      static int argc = sizeof(argv) / sizeof(char*) - 1;

      // Load the qpa plugin (If SketchUp is loading the OpenStudio plugin, the SketchUp run path will be added to the end of libraryPaths)
      if (gui){
        m_qApplication = new QApplication(argc, argv);
        dynamic_cast<QApplication*>(m_qApplication)->setQuitOnLastWindowClosed(false);
      }else{
        m_qApplication = new QCoreApplication(argc, argv);
      }

      
      m_defaultInstance = true;

      // check if we are in a SketchUp process
      #if _WIN32 || _MSC_VER
        if (gui){
          DWORD pId = GetCurrentProcessId();
          //HMODULE hModule = GetModuleHandle(NULL); // same as hInstance
          LPTSTR className = new TCHAR[255];
          LPTSTR typeName = new TCHAR[255];
          HWND h = GetTopWindow(0);
          while (h)
          {
            DWORD pId2;
            GetWindowThreadProcessId(h, &pId2);

            if (pId == pId2){

              GetClassName(h, className, 255);
              GetWindowText(h, typeName, 255);

              if (boost::regex_match(toString(typeName), boost::regex(".*- SketchUp.*"))){
                m_sketchUpWidget = new QWinWidget(h);
                break;
              }
            }

            h = GetNextWindow(h, GW_HWNDNEXT);
          }

          delete[] className;
          delete[] typeName;
        }
      #endif

    }
  }

  return m_qApplication;
}
Example #8
0
QVariant jsonMetadata() {
  QVariantMap metadata;
  metadata["openstudio_version"] = toQString(openStudioVersion());
  return metadata;
}