Commit 92370d96 authored by Ingemar Ceicer's avatar Ingemar Ceicer

checkforupdates

parent fbeb2410
......@@ -16,109 +16,132 @@
*/
#include "checkforupdates.h"
#include "hash.h"
void CheckForUpdates::check(const std::string &sprak)
{
if(sprak == "sv_SE")
applicationHomepage = APPLICATION_HOMEPAGE;
else
applicationHomepage = APPLICATION_HOMEPAGE_ENG;
QUrl url(VERSION_PATH);
auto *nam = new QNetworkAccessManager(this);
reply = nam->get(QNetworkRequest(url));
QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(checkForUpdates(QNetworkReply*)));
}
void CheckForUpdates::checkForUpdates(QNetworkReply *reply)
{
QByteArray bytes = reply->readAll(); // bytes
QString version = (QString) bytes; // string
version = version.trimmed();
if(version == "")
QMessageBox::critical(this, APPLICATION_NAME " " VERSION, tr("No Internet connection was found.\nPlease check your Internet settings and firewall."));
else {
int ver = jfrVersion(version);
switch(ver) {
case 0:
QMessageBox::information(this, APPLICATION_NAME " " VERSION, tr("\nThere is a later version of ") + APPLICATION_NAME + "<br>" + tr("Please download from") + "<p><a href=\"" + applicationHomepage + "\">" + applicationHomepage + "</a></p><p>" + tr("Latest version: ") + version + "</p>");
break;
case 1:
QMessageBox::information(this, APPLICATION_NAME " " VERSION, tr("\nYour version of ") + APPLICATION_NAME + tr(" is later than the latest official version ") + "(" + version + ").");
break;
case 2:
QMessageBox::information(this, APPLICATION_NAME " " VERSION, tr("\nYou have the latest version of ") + APPLICATION_NAME + ".");
break;
default:
QMessageBox::information(this, APPLICATION_NAME " " VERSION, tr("\nThere was an error when the version was checked."));
break;
};
}
}
#include "checkforupdates.h"
void CheckForUpdates::checkOnStart(const std::string &sprak)
void CheckForUpdates::check(const QString &progName, const QString &currentVersion, const QString &versionPath, const QString &downloadPath)
{
if(sprak == "sv_SE")
applicationHomepage = APPLICATION_HOMEPAGE;
else
applicationHomepage = APPLICATION_HOMEPAGE_ENG;
QUrl url(VERSION_PATH);
auto *nam = new QNetworkAccessManager(this);
reply = nam->get(QNetworkRequest(url));
QObject::connect(nam, SIGNAL(finished(QNetworkReply*)), this, SLOT(checkForUpdatesOnStart(QNetworkReply*)));
QUrl url(versionPath);
auto *nam = new QNetworkAccessManager(nullptr);
auto *reply = nam->get(QNetworkRequest(url));
QObject::connect(reply, &QNetworkReply::finished, [this, reply, versionPath, progName, currentVersion, downloadPath ]() {
QByteArray bytes = reply->readAll(); // bytes
QString newVersion(bytes); // string
newVersion = newVersion.trimmed();
int index = newVersion.indexOf('\n');
QString onlyNewVersion = newVersion.left(index);
QString infoVersion = newVersion.mid(index);
QString info = "";
if(index > 0) {
info = moreInfo(infoVersion);
}
if(onlyNewVersion == "")
QMessageBox::critical(this, progName + " " + currentVersion, tr("No Internet connection was found.\nPlease check your Internet settings and firewall."));
else {
int ver = jfrVersion(currentVersion, onlyNewVersion);
switch(ver) {
case 0:
QMessageBox::information(this, progName + " " + currentVersion, tr("\nThere is a later version of ") + progName + "<br>" + tr("Please ") + "<p><a href=\"" + downloadPath + "\">" + tr("Download") + "</a></p><p>" + tr("Latest version: ") + onlyNewVersion + info + "</p>");
break;
case 1:
QMessageBox::information(this, progName + " " + currentVersion, tr("\nYour version of ") + progName + tr(" is later than the latest official version ") + "(" + onlyNewVersion + ").");
break;
case 2:
QMessageBox::information(this, progName + " " + currentVersion, tr("\nYou have the latest version of ") + progName + ".");
break;
default:
QMessageBox::information(this, progName + " " + currentVersion, tr("\nThere was an error when the version was checked."));
break;
}
}
});
}
void CheckForUpdates::checkForUpdatesOnStart(QNetworkReply *reply)
void CheckForUpdates::checkOnStart(const QString &progName, const QString &currentVersion, const QString &versionPath, const QString &downloadPath)
{
QByteArray bytes = reply->readAll(); // bytes
QString version = (QString) bytes; // string
version = version.trimmed();
int ver = jfrVersion(version);
if(ver == 0)
QMessageBox::information(this, APPLICATION_NAME " " VERSION, tr("\nThere is a later version of ") + APPLICATION_NAME + "<br>" + tr("Please download from") + "<p><a href=\"" + applicationHomepage + "\">" + applicationHomepage + "</a></p><p>" + tr("Latest version: ") + version + "</p>");
QUrl url(versionPath);
auto *nam = new QNetworkAccessManager(nullptr);
auto *reply = nam->get(QNetworkRequest(url));
QObject::connect(reply, &QNetworkReply::finished, [this, reply, versionPath, progName, currentVersion, downloadPath ]() {
QByteArray bytes = reply->readAll(); // bytes
QString newVersion(bytes); // string
newVersion = newVersion.trimmed();
int index = newVersion.indexOf('\n');
QString onlyNewVersion = newVersion.left(index);
QString infoVersion = newVersion.mid(index);
QString info = "";
if(index > 0) {
info = moreInfo(infoVersion);
}
if(onlyNewVersion == "") {
QMessageBox::critical(this, progName + " " + currentVersion, tr("No Internet connection was found.\nPlease check your Internet settings and firewall."));
} else {
int ver = jfrVersion(currentVersion, onlyNewVersion);
qDebug() << ver;
if(ver == 0) {
QMessageBox::information(this, progName + " " + currentVersion, tr("\nThere is a later version of ") + progName + "<br>" + tr("Please ") + "<p><a href=\"" + downloadPath + "\">" + tr("Download") + "</a></p><p>" + tr("Latest version: ") + onlyNewVersion + info + "</p>");
} else if(ver == 3) {
QMessageBox::information(this, progName + " " + currentVersion, tr("\nThere was an error when the version was checked."));
}
}
});
}
// private:
int CheckForUpdates::jfrVersion(const QString &version)
int CheckForUpdates::jfrVersion(const QString &currentVersion, const QString &newVersion)
{
int v, tv;
bool ok;
QString this_version(VERSION);
QStringList l_this_version = this_version.split(".");
QStringList l_version = version.split(".");
int newVer;
int currentVer;
bool ok = true;
QStringList listCurrentVersion = currentVersion.split(".");
QStringList listNewVersion = newVersion.split(".");
for(int i = 0; i <= 2; i++) {
v = l_version[i].toInt(&ok, 10);
tv = l_this_version[i].toInt(&ok, 10);
currentVer = listCurrentVersion.at(i).toInt(&ok, 10);
newVer = listNewVersion.at(i).toInt(&ok, 10);
if(!ok)
return 3;
if(v > tv)
if(newVer > currentVer)
return 0;
if(v < tv)
if(newVer < currentVer)
return 1;
}
return 2;
}
QString CheckForUpdates::moreInfo(const QString &infoVersion)
{
QList<QString> listInfo;
listInfo = infoVersion.split('\n');
QString news;
if(listInfo.size() > 0) {
news = "<br><i>" + tr("New updates:") + "</i>";
QList<QString>::iterator it;
for(it = listInfo.begin() + 1; it != listInfo.end(); ++it)
news.append("<br>" + *it);
} else {
news = "";
}
return news;
}
CheckForUpdates::CheckForUpdates()
{
this->setAttribute(Qt::WA_DeleteOnClose, true);
}
CheckForUpdates::~CheckForUpdates()
{
delete this;
......
......@@ -16,22 +16,30 @@
*/
/*
Skall vara definierade:
VERSION_PATH
APPLICATION_NAME
VERSION
APPLICATION_HOMEPAGE
APPLICATION_HOMEPAGE _ENG
*/
Parameters (QString)
program Name [ progName ]
Current version (x.y.z) [ currentVersion ]
URL of the latest version file [ versionPath ]
Download [ downloadPath ]
#ifndef CHECKFORUPDATESH
#define CHECKFORUPDATESH
#include <QtWidgets>
#include <QNetworkReply>
#include <string>
connect(ui->actionCheckForUpdates, &QAction::triggered, [this] {
myCheckForUpdates.check(PROG_NAME, VERSION, VERSION_PATH, DOWNLOAD_PATH);
});
Eller
connect(ui->actionCheckForUpdates, &QAction::triggered, [] {
CheckForUpdates *cu = new CheckForUpdates;
cu->check(PROG_NAME, VERSION, VERSION_PATH, DOWNLOAD_PATH);
});
using namespace std;
*/
#ifndef CHECKFORUPDATES_H
#define CHECKFORUPDATES_H
#include <QMessageBox>
#include <QNetworkReply>
class CheckForUpdates : public QWidget
{
......@@ -40,25 +48,16 @@ class CheckForUpdates : public QWidget
private:
QString applicationHomepage;
QNetworkReply const *reply;
int jfrVersion(const QString &);
private slots:
void checkForUpdates(QNetworkReply*);
void checkForUpdatesOnStart(QNetworkReply*);
int jfrVersion(const QString &currentVersion, const QString &newVersion);
QString moreInfo(const QString &infoVersion);
public:
void check(const string &);
void checkOnStart(const string &);
~CheckForUpdates();
void check(const QString &progName, const QString &currentVersion, const QString &versionPath, const QString &downloadPath);
void checkOnStart(const QString &progName, const QString &currentVersion, const QString &versionPath, const QString &downloadPath);
~CheckForUpdates();
CheckForUpdates();
};
#endif // CHECKFORUPDATESH
#endif // CHECKFORUPDATES_H
......@@ -86,7 +86,11 @@ Hash::Hash(QWidget *parent) :
connect(ui->actionShowFullPathInHashSumFile, SIGNAL(triggered()), this, SLOT(showFullPathInHashSumFile()));
// Help
connect(ui->actionHelp, SIGNAL(triggered()), this, SLOT(help()));
connect(ui->actionCheckForUpdates, SIGNAL(triggered()), this, SLOT(checkForUpdates()));
// connect(ui->actionCheckForUpdates, SIGNAL(triggered()), this, SLOT(checkForUpdates()));
connect(ui->actionCheckForUpdates, &QAction::triggered, [this] {
CheckForUpdates *cu = new CheckForUpdates;
cu->check(APPLICATION_NAME, VERSION, VERSION_PATH, DOWNLOAD_PATH);
});
connect(ui->actionLicense, SIGNAL(triggered()), this, SLOT(license()));
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
connect(ui->actionVersionHistory, SIGNAL(triggered()), this, SLOT(versionhistory()));
......@@ -920,21 +924,7 @@ void Hash::writeTimeDateInHashSumFile()
delete k;
}
void Hash::checkForUpdates()
{
auto *cfu = new CheckForUpdates;
QString conf_file_name = QDir::toNativeSeparators("/" APPLICATION_NAME ".conf");
k = new Config(conf_file_name);
std::string sp = k->getConf("language");
delete k;
if(sp == "sv_SE")
cfu->check("sv_SE");
else if(sp == "el_GR")
cfu->check("el_GR");
else
cfu->check("us_EN");
}
void Hash::license()
{
......@@ -3119,8 +3109,8 @@ void Hash::setStartConfig()
if(s == "1") {
ui->actionCheckOnStart->setChecked(true);
auto *cfu = new CheckForUpdates;
cfu->checkOnStart(lang);
CheckForUpdates *cu = new CheckForUpdates;
cu->checkOnStart(APPLICATION_NAME, VERSION, VERSION_PATH, DOWNLOAD_PATH);
}
s = k->getConf("saveChecksumListWhereFilesAre", "0");
......
......@@ -35,10 +35,10 @@
#define VERSION_PATH "http://bin.ceicer.com/hash/version.txt"
#define VERSION_PATH "http://bin.ceicer.com/hash/version2.txt"
#define APPLICATION_NAME "hashSum"
#define EXECUTABLE_NAME "hashsum"
#define VERSION "2.5.0"
#define VERSION "2.5.1"
#define BUILD_DATE_TIME __DATE__ " " __TIME__
#define CURRENT_YEAR "2020"
#define LICENCE_VERSION "3"
......@@ -47,6 +47,7 @@
#define PROGRAMMER_PHONE "+46706361747"
#define APPLICATION_HOMEPAGE "http://ceicer.org/hash/index.php"
#define APPLICATION_HOMEPAGE_ENG "http://ceicer.org/hash/index_eng.php"
#define DOWNLOAD_PATH "https://gitlab.com/posktomten/hashsum/-/wikis/DOWNLOADS"
#define elGR_TRANSLATOR "www.geogeo.gr"
#define deDE_TRANSLATOR "Benjamin Weis"
......@@ -91,6 +92,7 @@ private:
QDialog *d{};
void setStartConfig();
void setEndConfig();
bool doChecksum(const QString &);
......@@ -137,7 +139,6 @@ private:
bool printDuplicates(const QStringList &likadana, const QString &jfrFile, const QString &directoryName);
private slots:
void checkForUpdates();
void about();
void checkOnStart();
void saveChecksumListWhereFilesAre();
......
2.5.0
Test
Jätte br!
ä ä öö
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