mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Update version checker for github.
This commit is contained in:
parent
a2c0c65006
commit
a658b0595e
@ -1,82 +1,82 @@
|
|||||||
#include "check_new_version.h"
|
#include "check_new_version.h"
|
||||||
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
|
||||||
#define PREVIOUS_VERSION_TESTING "6.0.0"
|
#define PREVIOUS_VERSION_TESTING "6.0.0"
|
||||||
|
|
||||||
HttpVersionChecker::HttpVersionChecker()
|
HttpVersionChecker::HttpVersionChecker()
|
||||||
:HttpWorker("https://bitbucket.org/luisangelsm/yacreader/wiki/Home")
|
:HttpWorker("https://bitbucket.org/luisangelsm/yacreader/wiki/Home")
|
||||||
{
|
{
|
||||||
connect(this,SIGNAL(dataReady(const QByteArray &)),this,SLOT(checkNewVersion(const QByteArray &)));
|
connect(this,SIGNAL(dataReady(const QByteArray &)),this,SLOT(checkNewVersion(const QByteArray &)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HttpVersionChecker::checkNewVersion(const QByteArray & data)
|
void HttpVersionChecker::checkNewVersion(const QByteArray & data)
|
||||||
{
|
{
|
||||||
checkNewVersion(QString(data));
|
checkNewVersion(QString(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HttpVersionChecker::checkNewVersion(QString sourceContent)
|
bool HttpVersionChecker::checkNewVersion(QString sourceContent)
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
QRegExp rx("YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}win32");
|
QRegExp rx("YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}win32");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
||||||
QRegExp rx("YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}X11");
|
QRegExp rx("YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}X11");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
QRegExp rx("YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}Mac");
|
QRegExp rx("YACReader\\-([0-9]+).([0-9]+).([0-9]+)\\.?([0-9]+)?.{0,5}Mac");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
bool newVersion = false;
|
bool newVersion = false;
|
||||||
bool sameVersion = true;
|
bool sameVersion = true;
|
||||||
//bool currentVersionIsNewer = false;
|
//bool currentVersionIsNewer = false;
|
||||||
#ifdef QT_DEBUG
|
#ifdef QT_DEBUG
|
||||||
QString version(PREVIOUS_VERSION_TESTING);
|
QString version(PREVIOUS_VERSION_TESTING);
|
||||||
#else
|
#else
|
||||||
QString version(VERSION);
|
QString version(VERSION);
|
||||||
#endif
|
#endif
|
||||||
QStringList sl = version.split(".");
|
QStringList sl = version.split(".");
|
||||||
if((index = rx.indexIn(sourceContent))!=-1)
|
if((index = rx.indexIn(sourceContent))!=-1)
|
||||||
{
|
{
|
||||||
int length = qMin(sl.size(),(rx.cap(4)!="")?4:3);
|
int length = qMin(sl.size(),(rx.cap(4)!="")?4:3);
|
||||||
for(int i=0;i<length;i++)
|
for(int i=0;i<length;i++)
|
||||||
{
|
{
|
||||||
if(rx.cap(i+1).toInt()<sl.at(i).toInt())
|
if(rx.cap(i+1).toInt()<sl.at(i).toInt())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(rx.cap(i+1).toInt()>sl.at(i).toInt()){
|
if(rx.cap(i+1).toInt()>sl.at(i).toInt()){
|
||||||
newVersion=true;
|
newVersion=true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sameVersion = sameVersion && rx.cap(i+1).toInt()==sl.at(i).toInt();
|
sameVersion = sameVersion && rx.cap(i+1).toInt()==sl.at(i).toInt();
|
||||||
}
|
}
|
||||||
if(!newVersion && sameVersion)
|
if(!newVersion && sameVersion)
|
||||||
{
|
{
|
||||||
if((sl.size()==3)&&(rx.cap(4)!=""))
|
if((sl.size()==3)&&(rx.cap(4)!=""))
|
||||||
newVersion = true;
|
newVersion = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(newVersion == true)
|
if(newVersion == true)
|
||||||
{
|
{
|
||||||
emit newVersionDetected();
|
emit newVersionDetected();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user