diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index a0b258fc10..99478e2b84 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -140,7 +140,7 @@ target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) # link required hifi libraries link_hifi_libraries(shared octree environment gpu model fbx networking entities avatars audio audio-client animation script-engine physics - render-utils entities-renderer ui) + render-utils entities-renderer ui auto-update) add_dependency_external_projects(sdl2) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 803955f02c..39d93986d8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -59,6 +59,7 @@ #include <AddressManager.h> #include <AmbientOcclusionEffect.h> #include <AudioInjector.h> +#include <AutoUpdate.h> #include <DeferredLightingEffect.h> #include <DependencyManager.h> #include <EntityScriptingInterface.h> @@ -539,8 +540,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : // allow you to move an entity around in your hand _entityEditSender.setPacketsPerSecond(3000); // super high!! - checkVersion(); - _overlays.init(); // do this before scripts load _runningScriptsWidget->setRunningScripts(getRunningScripts()); @@ -612,6 +611,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : ddeTracker->init(); connect(ddeTracker.data(), &FaceTracker::muteToggled, this, &Application::faceTrackerMuteToggled); #endif + + AutoUpdate* applicationUpdater = new AutoUpdate; + applicationUpdater->checkForUpdate(); } @@ -4404,72 +4406,6 @@ void Application::toggleLogDialog() { } } -void Application::checkVersion() { - QNetworkRequest latestVersionRequest((QUrl(CHECK_VERSION_URL))); - latestVersionRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); - latestVersionRequest.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache); - QNetworkReply* reply = NetworkAccessManager::getInstance().get(latestVersionRequest); - connect(reply, SIGNAL(finished()), SLOT(parseVersionXml())); -} - -void Application::parseVersionXml() { - - #ifdef Q_OS_WIN32 - QString operatingSystem("win"); - #endif - - #ifdef Q_OS_MAC - QString operatingSystem("mac"); - #endif - - #ifdef Q_OS_LINUX - QString operatingSystem("ubuntu"); - #endif - - QString latestVersion; - QUrl downloadUrl; - QString releaseNotes("Unavailable"); - QNetworkReply* sender = qobject_cast<QNetworkReply*>(QObject::sender()); - - QXmlStreamReader xml(sender); - - while (!xml.atEnd() && !xml.hasError()) { - if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name() == operatingSystem) { - while (!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == operatingSystem)) { - if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name().toString() == "version") { - xml.readNext(); - latestVersion = xml.text().toString(); - } - if (xml.tokenType() == QXmlStreamReader::StartElement && xml.name().toString() == "url") { - xml.readNext(); - downloadUrl = QUrl(xml.text().toString()); - } - xml.readNext(); - } - } - xml.readNext(); - } - - if (!shouldSkipVersion(latestVersion) && applicationVersion() != latestVersion) { - new UpdateDialog(_glWidget, releaseNotes, latestVersion, downloadUrl); - } - sender->deleteLater(); -} - -bool Application::shouldSkipVersion(QString latestVersion) { - QFile skipFile(SKIP_FILENAME); - skipFile.open(QIODevice::ReadWrite); - QString skipVersion(skipFile.readAll()); - return (skipVersion == latestVersion || applicationVersion() == "dev"); -} - -void Application::skipVersion(QString latestVersion) { - QFile skipFile(SKIP_FILENAME); - skipFile.open(QIODevice::WriteOnly | QIODevice::Truncate); - skipFile.seek(0); - skipFile.write(latestVersion.toStdString().c_str()); -} - void Application::takeSnapshot() { QMediaPlayer* player = new QMediaPlayer(); QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav"); diff --git a/interface/src/Application.h b/interface/src/Application.h index b6efb6420b..2b3530531f 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -66,7 +66,6 @@ #include "ui/SnapshotShareDialog.h" #include "ui/LodToolsDialog.h" #include "ui/LogDialog.h" -#include "ui/UpdateDialog.h" #include "ui/overlays/Overlays.h" #include "ui/ApplicationOverlay.h" #include "ui/RunningScriptsWidget.h" @@ -311,8 +310,6 @@ public: NodeToJurisdictionMap& getEntityServerJurisdictions() { return _entityServerJurisdictions; } - void skipVersion(QString latestVersion); - QStringList getRunningScripts() { return _scriptEnginesHash.keys(); } ScriptEngine* getScriptEngine(QString scriptHash) { return _scriptEnginesHash.contains(scriptHash) ? _scriptEnginesHash[scriptHash] : NULL; } @@ -454,8 +451,6 @@ private slots: void restoreMirrorView(); void shrinkMirrorView(); - void parseVersionXml(); - void manageRunningScriptsWidgetVisibility(bool shown); void runTests(); @@ -624,9 +619,6 @@ private: FileLogger* _logger; - void checkVersion(); - void displayUpdateDialog(); - bool shouldSkipVersion(QString latestVersion); void takeSnapshot(); TouchEvent _lastTouchEvent; diff --git a/interface/src/ui/UpdateDialog.cpp b/interface/src/ui/UpdateDialog.cpp deleted file mode 100644 index 40b32d66e3..0000000000 --- a/interface/src/ui/UpdateDialog.cpp +++ /dev/null @@ -1,55 +0,0 @@ -// -// UpdateDialog.cpp -// interface/src/ui -// -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include <QDesktopServices> - -#include "ui_updateDialog.h" - -#include "Application.h" -#include "UpdateDialog.h" - - -UpdateDialog::UpdateDialog(QWidget *parent, const QString& releaseNotes, const QString& latestVersion, const QUrl& downloadURL) : - QDialog(parent), - _latestVersion(latestVersion), - _downloadUrl(downloadURL) -{ - Ui::Dialog dialogUI; - dialogUI.setupUi(this); - - QString updateRequired = QString("You are currently running build %1, the latest build released is %2." - "\n\nPlease download and install the most recent release to access the latest features and bug fixes.") - .arg(Application::getInstance()->applicationVersion(), latestVersion); - - setAttribute(Qt::WA_DeleteOnClose); - - QPushButton* downloadButton = findChild<QPushButton*>("downloadButton"); - QPushButton* skipButton = findChild<QPushButton*>("skipButton"); - QPushButton* closeButton = findChild<QPushButton*>("closeButton"); - QLabel* updateContent = findChild<QLabel*>("updateContent"); - - updateContent->setText(updateRequired); - - connect(downloadButton, SIGNAL(released()), this, SLOT(handleDownload())); - connect(skipButton, SIGNAL(released()), this, SLOT(handleSkip())); - connect(closeButton, SIGNAL(released()), this, SLOT(close())); - - QMetaObject::invokeMethod(this, "show", Qt::QueuedConnection); -} - -void UpdateDialog::handleDownload() { - QDesktopServices::openUrl(_downloadUrl); - Application::getInstance()->quit(); -} - -void UpdateDialog::handleSkip() { - Application::getInstance()->skipVersion(_latestVersion); - this->close(); -} diff --git a/interface/src/ui/UpdateDialog.h b/interface/src/ui/UpdateDialog.h deleted file mode 100644 index 15a97bf024..0000000000 --- a/interface/src/ui/UpdateDialog.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// UpdateDialog.h -// interface/src/ui -// -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_UpdateDialog_h -#define hifi_UpdateDialog_h - -#include <QWidget> - -class UpdateDialog : public QDialog { - Q_OBJECT - -public: - UpdateDialog(QWidget* parent, const QString& releaseNotes, const QString& latestVersion, const QUrl& downloadURL); - -private: - QString _latestVersion; - QUrl _downloadUrl; - -private slots: - void handleDownload(); - void handleSkip(); -}; - -#endif // hifi_UpdateDialog_h diff --git a/interface/ui/updateDialog.ui b/interface/ui/updateDialog.ui deleted file mode 100644 index fc375e17c2..0000000000 --- a/interface/ui/updateDialog.ui +++ /dev/null @@ -1,132 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>Dialog</class> - <widget class="QDialog" name="Dialog"> - <property name="windowModality"> - <enum>Qt::NonModal</enum> - </property> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>750</width> - <height>213</height> - </rect> - </property> - <property name="cursor"> - <cursorShape>PointingHandCursor</cursorShape> - </property> - <property name="windowTitle"> - <string>Update Required</string> - </property> - <property name="styleSheet"> - <string notr="true">background-color: rgb(255, 255, 255);</string> - </property> - <widget class="QLabel" name="updateContent"> - <property name="geometry"> - <rect> - <x>50</x> - <y>20</y> - <width>641</width> - <height>111</height> - </rect> - </property> - <property name="font"> - <font> - <family>Arial</family> - <pointsize>-1</pointsize> - </font> - </property> - <property name="styleSheet"> - <string notr="true">font-family: Arial; -font-size: 20px;</string> - </property> - <property name="text"> - <string/> - </property> - <property name="wordWrap"> - <bool>true</bool> - </property> - </widget> - <widget class="QWidget" name="layoutWidget"> - <property name="geometry"> - <rect> - <x>360</x> - <y>160</y> - <width>374</width> - <height>42</height> - </rect> - </property> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QPushButton" name="downloadButton"> - <property name="cursor"> - <cursorShape>PointingHandCursor</cursorShape> - </property> - <property name="styleSheet"> - <string notr="true"> background-color: #333333; -border-width: 0; -border-radius: 9px; -border-radius: 9px; -font-family: Arial; -font-size: 18px; -font-weight: 100; -color: #b7b7b7; -width: 120px; -height: 40px;</string> - </property> - <property name="text"> - <string>Download</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="skipButton"> - <property name="cursor"> - <cursorShape>PointingHandCursor</cursorShape> - </property> - <property name="styleSheet"> - <string notr="true"> background-color: #333333; -border-width: 0; -border-radius: 9px; -border-radius: 9px; -font-family: Arial; -font-size: 18px; -font-weight: 100; -color: #b7b7b7; -width: 120px; -height: 40px;</string> - </property> - <property name="text"> - <string>Skip Version</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="closeButton"> - <property name="cursor"> - <cursorShape>PointingHandCursor</cursorShape> - </property> - <property name="styleSheet"> - <string notr="true"> background-color: #333333; -border-width: 0; -border-radius: 9px; -border-radius: 9px; -font-family: Arial; -font-size: 18px; -font-weight: 100; -color: #b7b7b7; -width: 120px; -height: 40px;</string> - </property> - <property name="text"> - <string>Close</string> - </property> - </widget> - </item> - </layout> - </widget> - </widget> - <resources/> - <connections/> -</ui> diff --git a/libraries/auto-update/CMakeLists.txt b/libraries/auto-update/CMakeLists.txt new file mode 100644 index 0000000000..0419048169 --- /dev/null +++ b/libraries/auto-update/CMakeLists.txt @@ -0,0 +1,3 @@ +set(TARGET_NAME auto-update) +setup_hifi_library(Network) +link_hifi_libraries(shared networking) diff --git a/libraries/auto-update/src/AutoUpdate.cpp b/libraries/auto-update/src/AutoUpdate.cpp new file mode 100644 index 0000000000..8132f2ee60 --- /dev/null +++ b/libraries/auto-update/src/AutoUpdate.cpp @@ -0,0 +1,87 @@ +// +// AutoUpdate.cpp +// libraries/auto-update/src +// +// Created by Leonardo Murillo on 6/1/2015. +// Copyright 2015 High Fidelity, Inc. +// +// +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include <NetworkAccessManager.h> +#include <SharedUtil.h> +#include "AutoUpdate.h" + +AutoUpdate::AutoUpdate() { +#ifdef Q_OS_WIN32 + _operatingSystem = "windows"; +#endif +#ifdef Q_OS_MAC + _operatingSystem = "mac"; +#endif +#ifdef Q_OS_LINUX + _operatingSystem = "ubuntu"; +#endif +} + +AutoUpdate::~AutoUpdate() { + qDebug() << "[LEOTEST] The object is now destroyed"; +} + +void AutoUpdate::checkForUpdate() { + this->getLatestVersionData(); + +} + +void AutoUpdate::getLatestVersionData() { + QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); + QNetworkRequest latestVersionRequest(BUILDS_XML_URL); + latestVersionRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); + QNetworkReply* reply = networkAccessManager.get(latestVersionRequest); + connect(reply, SIGNAL(finished()), this, SLOT(parseLatestVersionData())); + connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(handleError(QNetworkReply::NetworkError))); +} + + +void AutoUpdate::parseLatestVersionData() { + QNetworkReply* sender = qobject_cast<QNetworkReply*>(QObject::sender()); + + QXmlStreamReader xml(sender); + + while (!xml.atEnd() && !xml.hasError()) { + if (xml.name().toString() == "project" && + xml.attributes().hasAttribute("name") && + xml.attributes().value("name").toString() == "interface") { + xml.readNext(); + + while (!xml.atEnd() && !xml.hasError() && xml.name().toString() != "project") { + if (xml.name().toString() == "platform" && + xml.attributes().hasAttribute("name") && + xml.attributes().value("name").toString() == _operatingSystem) { + xml.readNext(); + while (!xml.atEnd() && !xml.hasError() && + xml.name().toString() != "platform") { + + if (xml.name().toString() == "build" && xml.tokenType() != QXmlStreamReader::EndElement) { + xml.readNext(); + QString version = xml.readElementText(); + xml.readNext(); + QString url = xml.readElementText(); + qDebug() << "[LEOTEST] Release version " << version << " downloadable at: " << url; + } + + xml.readNext(); + } + } + xml.readNext(); + } + + } else { + xml.readNext(); + } + } + sender->deleteLater(); +} \ No newline at end of file diff --git a/libraries/auto-update/src/AutoUpdate.h b/libraries/auto-update/src/AutoUpdate.h new file mode 100644 index 0000000000..ee0434fde8 --- /dev/null +++ b/libraries/auto-update/src/AutoUpdate.h @@ -0,0 +1,63 @@ +// +// AutoUpdate.h +// libraries/auto-update/src +// +// Created by Leonardo Murillo on 6/1/2015. +// Copyright 2015 High Fidelity, Inc. +// +// +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef __hifi__AutoUpdate__ +#define __hifi__AutoUpdate__ + +#include <QtCore/QObject> +#include <QtCore/QSettings> +#include <QDebug> +#include <QString> +#include <QUrl> +#include <QMap> +#include <QNetworkRequest> +#include <QNetworkReply> +#include <QNetworkConfiguration> +#include <QNetworkAccessManager> +#include <QXmlStreamReader> +#include <QXmlStreamAttributes> + + +const QUrl BUILDS_XML_URL("https://highfidelity.com/builds.xml"); + +class AutoUpdate : public QObject { + Q_OBJECT +public: + // Methods + AutoUpdate(); + ~AutoUpdate(); + + void checkForUpdate(); + QMap<int, QMap<QString, QString>> getBuildData() { return _builds; } + void appendBuildData(int versionNumber, + QString downloadURL, + int pullRequestNumber, + QString releaseNotes); + +public slots: + +private: + // Members + QMap<int, QMap<QString, QString>> _builds; + QString _operatingSystem; + + // Methods + void getLatestVersionData(); + void performAutoUpdate(); + void downloadUpdateVersion(); + +private slots: + void parseLatestVersionData(); +}; + +#endif /* defined(__hifi__AutoUpdate__) */