Commit 440b1803 authored by Jan Möbius's avatar Jan Möbius

Implemented Windows update check for core

save update info in ini file

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@2936 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 7439750d
...@@ -245,6 +245,22 @@ void Core::readApplicationOptions(INIFile& _ini) { ...@@ -245,6 +245,22 @@ void Core::readApplicationOptions(INIFile& _ini) {
if( _ini.get_entry(doSlotDebugging, "Options", "SlotDebugging") ) if( _ini.get_entry(doSlotDebugging, "Options", "SlotDebugging") )
OpenFlipper::Options::doSlotDebugging(doSlotDebugging); OpenFlipper::Options::doSlotDebugging(doSlotDebugging);
//============================================================================
// Update information
//============================================================================
QString updateUrl = "";
if( _ini.get_entry(updateUrl, "Options", "UpdateURL") )
OpenFlipper::Options::updateUrl(updateUrl);
QString updateUsername = "";
if( _ini.get_entry(updateUsername, "Options", "UpdateUsername") )
OpenFlipper::Options::updateUsername(updateUsername);
QString updatePassword = "";
if( _ini.get_entry(updatePassword, "Options", "UpdatePassword") )
OpenFlipper::Options::updatePassword(updatePassword);
} }
} }
...@@ -323,6 +339,13 @@ void Core::writeApplicationOptions(INIFile& _ini) { ...@@ -323,6 +339,13 @@ void Core::writeApplicationOptions(INIFile& _ini) {
// max Framerate // max Framerate
_ini.add_entry("Options","SlotDebugging",OpenFlipper::Options::doSlotDebugging() ); _ini.add_entry("Options","SlotDebugging",OpenFlipper::Options::doSlotDebugging() );
//============================================================================
// Update information
//============================================================================
_ini.add_entry("Options","UpdateURL",OpenFlipper::Options::updateUrl() );
_ini.add_entry("Options","UpdateUsername",OpenFlipper::Options::updateUsername() );
_ini.add_entry("Options","UpdatePassword",OpenFlipper::Options::updatePassword() );
//============================================================================ //============================================================================
//dontLoad Plugins //dontLoad Plugins
//============================================================================ //============================================================================
......
...@@ -214,7 +214,7 @@ int main(int argc, char **argv) ...@@ -214,7 +214,7 @@ int main(int argc, char **argv)
std::signal(SIGSEGV, segfaultHandling); std::signal(SIGSEGV, segfaultHandling);
#endif #endif
OpenFlipper::Options::windowTitle("OpenFlipper v0.8"); OpenFlipper::Options::windowTitle("OpenFlipper v" + OpenFlipper::Options::coreVersion());
//====================================================== //======================================================
// Parse command line Options // Parse command line Options
......
...@@ -130,6 +130,15 @@ static bool debug_ = false; ...@@ -130,6 +130,15 @@ static bool debug_ = false;
/// Slot Debugging /// Slot Debugging
static bool doSlotDebugging_ = false; static bool doSlotDebugging_ = false;
/// URL for updates
static QString updateURL_ = "";
/// Username for updates
static QString updateUsername_ = "";
/// Password for updates
static QString updatePassword_ = "";
/// enable logging to file /// enable logging to file
static bool logFileEnabled_; static bool logFileEnabled_;
...@@ -528,6 +537,34 @@ bool doSlotDebugging( ) { ...@@ -528,6 +537,34 @@ bool doSlotDebugging( ) {
return doSlotDebugging_; return doSlotDebugging_;
} }
void updateUrl( QString _url ) {
updateURL_ = _url;
}
QString updateUrl( ) {
return updateURL_;
}
void updateUsername( QString _username ) {
updateUsername_ = _username;
}
QString updateUsername( ) {
return updateUsername_;
}
void updatePassword( QString _password ) {
updatePassword_ = _password;
}
QString updatePassword( ) {
return updatePassword_;
}
QString coreVersion() {
return QString("0.9");
}
} }
} }
......
...@@ -523,6 +523,54 @@ bool doSlotDebugging( ); ...@@ -523,6 +523,54 @@ bool doSlotDebugging( );
/** @} */ /** @} */
//===========================================================================
/** @name Update Options
* @{ */
//===========================================================================
/** Set Server URL to check for updates
*/
DLLEXPORT
void updateUrl( QString _url );
/** Get Server URL to check for updates
*/
DLLEXPORT
QString updateUrl( );
/** Set Username for updates
*/
DLLEXPORT
void updateUsername( QString _username );
/** Get Username for updates
*/
DLLEXPORT
QString updateUsername( );
/** Set Password for updates
*/
DLLEXPORT
void updatePassword( QString _password );
/** Get Password for updates
*/
DLLEXPORT
QString updatePassword( );
/** @} */
//===========================================================================
/** @name Version information
* @{ */
//===========================================================================
/// Version of OpenFlipper Core
DLLEXPORT
QString coreVersion();
/** @} */
} }
} }
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <OpenFlipper/common/GlobalOptions.hh> #include <OpenFlipper/common/GlobalOptions.hh>
#include <ACG/Scenegraph/DrawModes.hh> #include <ACG/Scenegraph/DrawModes.hh>
#include <OpenFlipper/ACGHelper/DrawModeConverter.hh> #include <OpenFlipper/ACGHelper/DrawModeConverter.hh>
#include <OpenFlipper/INIFile/INIFile.hh>
OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, QWidget *parent) OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, QWidget *parent)
: QWidget(parent), : QWidget(parent),
...@@ -102,6 +103,11 @@ void OptionsWidget::showEvent ( QShowEvent * event ) { ...@@ -102,6 +103,11 @@ void OptionsWidget::showEvent ( QShowEvent * event ) {
restrictFPS->setChecked( OpenFlipper::Options::restrictFrameRate() ); restrictFPS->setChecked( OpenFlipper::Options::restrictFrameRate() );
FPS->setValue( OpenFlipper::Options::maxFrameRate() ); FPS->setValue( OpenFlipper::Options::maxFrameRate() );
// updates
updateUser->setText( OpenFlipper::Options::updateUsername() );
updatePass->setText( OpenFlipper::Options::updatePassword() );
updateURL->setText( OpenFlipper::Options::updateUrl( ) );
// debugging // debugging
slotDebugging->setChecked(OpenFlipper::Options::doSlotDebugging()); slotDebugging->setChecked(OpenFlipper::Options::doSlotDebugging());
...@@ -203,6 +209,11 @@ void OptionsWidget::slotApply() { ...@@ -203,6 +209,11 @@ void OptionsWidget::slotApply() {
OpenFlipper::Options::restrictFrameRate( restrictFPS->isChecked() ); OpenFlipper::Options::restrictFrameRate( restrictFPS->isChecked() );
OpenFlipper::Options::maxFrameRate( FPS->value() ); OpenFlipper::Options::maxFrameRate( FPS->value() );
// updates
OpenFlipper::Options::updateUrl( updateURL->text() );
OpenFlipper::Options::updateUsername( updateUser->text() );
OpenFlipper::Options::updatePassword( updatePass->text() );
// Debugging // Debugging
OpenFlipper::Options::doSlotDebugging(slotDebugging->isChecked()); OpenFlipper::Options::doSlotDebugging(slotDebugging->isChecked());
...@@ -281,7 +292,7 @@ void OptionsWidget::slotCheckUpdates() { ...@@ -281,7 +292,7 @@ void OptionsWidget::slotCheckUpdates() {
// http://www.graphics.rwth-aachen.de/restricted/OpenFlipper-SIL/ // http://www.graphics.rwth-aachen.de/restricted/OpenFlipper-SIL/
downloadType = VERSIONS_FILE; downloadType = VERSIONS_FILE;
QString ServerMainURL = updateURL->text() + "Versions.txt"; QString ServerMainURL = updateURL->text() + "Versions.ini";
startDownload(ServerMainURL); startDownload(ServerMainURL);
...@@ -290,6 +301,82 @@ void OptionsWidget::slotCheckUpdates() { ...@@ -290,6 +301,82 @@ void OptionsWidget::slotCheckUpdates() {
void OptionsWidget::slotGetUpdates() { void OptionsWidget::slotGetUpdates() {
} }
bool OptionsWidget::isNewer(QString _current, QString _latest) {
QStringList latestVersionParts = _latest.split('.');
QStringList currentVersionParts = _current.split('.');
bool newer = false;
for ( int i = 0 ; i < latestVersionParts.size(); ++i ) {
if ( i+1 > currentVersionParts.size() ) {
// Versions are identical up to now. But latest version has additional version => updated
newer = true;
break;
}
bool ok = false;
double latest = latestVersionParts[i].toInt(&ok);
double current = currentVersionParts[i].toInt(&ok);
if ( !ok )
std::cerr << "Error when parsing version strings!" << std::endl;
if ( latest > current ) {
newer = true;
break;
}
}
return newer;
}
void OptionsWidget::compareVersions() {
QString fileName = QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "Versions.ini" ;
INIFile ini;
if ( ! ini.connect(fileName,false) ) {
std::cerr << "Failed to connect to Versions ini file" << std::endl;
return;
}
statusLabel->setText("Checking for new versions");
bool newerVersionsAvailable = false;
QString updatedComponents = "Updates found for ";
if ( OpenFlipper::Options::isWindows() ) {
QString coreVersion;
if ( ini.get_entry(coreVersion, "Core" , "VersionWindows" )) {
if ( isNewer( OpenFlipper::Options::coreVersion(), coreVersion ) ) {
std::cerr << "Newer Version found for Core!" << std::endl;
std::cerr << "Latest Version is " << coreVersion.toStdString() << std::endl;
std::cerr << "Current Version is " << OpenFlipper::Options::coreVersion().toStdString() << std::endl;
newerVersionsAvailable = true;
updatedComponents += "Core " + OpenFlipper::Options::coreVersion() + " -> " + coreVersion;
}
}
} else {
std::cerr << "Updates for linux not implemented yet" << std::endl;
}
if ( newerVersionsAvailable ) {
statusLabel->setText(updatedComponents);
}
ini.disconnect();
}
void OptionsWidget::httpRequestFinished(int requestId, bool error) void OptionsWidget::httpRequestFinished(int requestId, bool error)
{ {
if (requestId != httpGetId) if (requestId != httpGetId)
...@@ -326,6 +413,11 @@ void OptionsWidget::httpRequestFinished(int requestId, bool error) ...@@ -326,6 +413,11 @@ void OptionsWidget::httpRequestFinished(int requestId, bool error)
checkUpdateButton->setEnabled(true); checkUpdateButton->setEnabled(true);
delete file; delete file;
file = 0; file = 0;
if ( !error ) {
if ( downloadType == VERSIONS_FILE )
compareVersions();
}
} }
void OptionsWidget::readResponseHeader(const QHttpResponseHeader &responseHeader) void OptionsWidget::readResponseHeader(const QHttpResponseHeader &responseHeader)
......
...@@ -97,8 +97,15 @@ class OptionsWidget : public QWidget, public Ui::OptionsWidget ...@@ -97,8 +97,15 @@ class OptionsWidget : public QWidget, public Ui::OptionsWidget
} downloadType; } downloadType;
private: private:
/// Starts the download of the given file
void startDownload( QString _url ); void startDownload( QString _url );
/// Compares the versions from the downloaded Versions file with the current versions
void compareVersions();
/// Compares two version strings and returns if a newer Version is available
bool isNewer(QString _current, QString _latest);
private slots: private slots:
// This slot is called when a http request has been finished // This slot is called when a http request has been finished
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment