1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Dust off windows updater code

This commit is contained in:
tux3 2015-12-10 04:37:07 +01:00
parent ef019a9ae3
commit f13eba1a9c
6 changed files with 51 additions and 35 deletions

View File

@ -44,7 +44,7 @@ const QString AutoUpdater::platform = "win64";
const QString AutoUpdater::platform = "win32";
#endif
const QString AutoUpdater::updaterBin = "qtox-updater.exe";
const QString AutoUpdater::updateServer = "https://qtox-win.pkg.tox.chat";
const QString AutoUpdater::updateServer = "http://45.79.166.124";
unsigned char AutoUpdater::key[crypto_sign_PUBLICKEYBYTES] =
{
@ -80,12 +80,9 @@ bool AutoUpdater::isUpdateAvailable()
if (isDownloadingUpdate)
return false;
VersionInfo newVersion = getUpdateVersion();
if (newVersion.timestamp <= TIMESTAMP
|| newVersion.versionString.isEmpty() || newVersion.versionString == GIT_VERSION)
return false;
else
return true;
QByteArray updateFlist = getUpdateFlist();
QList<UpdateFileMeta> diff = genUpdateDiff(parseFlist(updateFlist));
return !diff.isEmpty();
}
AutoUpdater::VersionInfo AutoUpdater::getUpdateVersion()
@ -227,35 +224,34 @@ QByteArray AutoUpdater::getUpdateFlist()
return flist;
}
QByteArray AutoUpdater::getLocalFlist()
{
QByteArray flist;
QFile flistFile("flist");
if (!flistFile.open(QIODevice::ReadOnly))
{
qWarning() << "getLocalFlist: Can't open local flist";
return flist;
}
flist = flistFile.readAll();
flistFile.close();
return flist;
}
QList<AutoUpdater::UpdateFileMeta> AutoUpdater::genUpdateDiff(QList<UpdateFileMeta> updateFlist)
{
QList<UpdateFileMeta> diff;
QList<UpdateFileMeta> localFlist = parseFlist(getLocalFlist());
for (UpdateFileMeta file : updateFlist)
if (!localFlist.contains(file))
if (!isUpToDate(file))
diff += file;
return diff;
}
bool AutoUpdater::isUpToDate(AutoUpdater::UpdateFileMeta fileMeta)
{
QString appDir = qApp->applicationDirPath();
qDebug() << "App path:"<<appDir;
QFile file(appDir+QDir::separator()+fileMeta.installpath);
if (!file.open(QIODevice::ReadOnly))
return false;
// If the data we have is corrupted or old, mark it for update
QByteArray data = file.readAll();
if (crypto_sign_verify_detached(fileMeta.sig, (unsigned char*)data.data(), data.size(), key) != 0)
return false;
return true;
}
AutoUpdater::UpdateFile AutoUpdater::getUpdateFile(UpdateFileMeta fileMeta)
{
UpdateFile file;
@ -307,7 +303,7 @@ bool AutoUpdater::downloadUpdate()
return false;
}
qDebug() << "Need to update " << diff.size() << " files";
qDebug() << "Need to update" << diff.size() << "files";
// Create an empty directory to download updates into
QString updateDirStr = Settings::getInstance().getSettingsDirPath() + "/update/";
@ -497,9 +493,25 @@ void AutoUpdater::checkUpdatesAsyncInteractiveWorker()
QString updateDirStr = Settings::getInstance().getSettingsDirPath() + "/update/";
QDir updateDir(updateDirStr);
if ((updateDir.exists() && QFile(updateDirStr+"flist").exists())
|| GUI::askQuestion(QObject::tr("Update", "The title of a message box"),
QObject::tr("An update is available, do you want to download it now?\nIt will be installed when qTox restarts."), true, false))
if (updateDir.exists() && QFile(updateDirStr+"flist").exists())
{
downloadUpdate();
return;
}
VersionInfo newVersion = getUpdateVersion();
QString contentText = QObject::tr("An update is available, do you want to download it now?\n"
"It will be installed when qTox restarts.");
if (!newVersion.versionString.isEmpty())
contentText += "\n\n" + QObject::tr("Version %1, %2").arg(newVersion.versionString,
QDateTime::fromMSecsSinceEpoch(newVersion.timestamp*1000).toString());
if (GUI::askQuestion(QObject::tr("Update", "The title of a message box"),
contentText, true, false))
{
downloadUpdate();
}

View File

@ -101,10 +101,10 @@ protected:
/// Gets the update server's flist. Returns an empty array on error
/// Will try to follow qTox's proxy settings, may block and processEvents
static QByteArray getUpdateFlist();
/// Gets the local flist. Returns an empty array on error
static QByteArray getLocalFlist();
/// Generates a list of files we need to update
static QList<UpdateFileMeta> genUpdateDiff(QList<UpdateFileMeta> updateFlist);
/// Checks if we have an up to date version of this file locally installed
static bool isUpToDate(UpdateFileMeta file);
/// Tries to fetch the file from the update server. Returns a file with a null QByteArray on error.
/// Note that a file with an empty but non-null QByteArray is not an error, merely a file of size 0.
/// Will try to follow qTox's proxy settings, may block and processEvents

View File

@ -22,11 +22,12 @@
#include "serialize.h"
#include <QFile>
#include <QDebug>
#include <QMessageBox>
unsigned char key[crypto_sign_PUBLICKEYBYTES] =
{
0xa5, 0x80, 0xf3, 0xb7, 0xd0, 0x10, 0xc0, 0xf9, 0xd6, 0xcf, 0x48, 0x15, 0x99, 0x70, 0x92, 0x49,
0xf6, 0xe8, 0xe5, 0xe2, 0x6c, 0x73, 0x8c, 0x48, 0x25, 0xed, 0x01, 0x72, 0xf7, 0x6c, 0x17, 0x28
0x20, 0x89, 0x39, 0xaa, 0x9a, 0xe8, 0xb5, 0x21, 0x0e, 0xac, 0x02, 0xa9, 0xc4, 0x92, 0xd9, 0xa2,
0x17, 0x83, 0xbd, 0x78, 0x0a, 0xda, 0x33, 0xcd, 0xa5, 0xc6, 0x44, 0xc7, 0xfc, 0xed, 0x00, 0x13
};
QByteArray getLocalFlist()

View File

@ -13,6 +13,8 @@ TEMPLATE = app
CONFIG += c++11
QMAKE_CXXFLAGS += -fno-exceptions
SOURCES += main.cpp\
widget.cpp \
settingsDir.cpp \

View File

@ -115,6 +115,7 @@ void Widget::update()
setProgress(1);
QList<UpdateFileMeta> updateFlist = parseFlist(updateFlistData);
setProgress(2);
QList<UpdateFileMeta> diff = genUpdateDiff(updateFlist);
setProgress(4);

View File

@ -84,7 +84,7 @@
</rect>
</property>
<property name="text">
<string>&lt;a href=&quot;https://tox.im&quot;&gt;https://tox.im&lt;/a&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://tox.im&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#0000ff;&quot;&gt;https://tox.chat&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>