mirror of https://github.com/qTox/qTox.git
Browse Source
The auto-updater is essentially done, except for the GUI. For now this is only an API. The API works, but the tools to manage the update server would need some lovepull/689/head
22 changed files with 1246 additions and 45 deletions
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
||||
See the COPYING file for more details. |
||||
*/ |
||||
|
||||
|
||||
#include "widget.h" |
||||
#include <QApplication> |
||||
|
||||
int main(int argc, char *argv[]) |
||||
{ |
||||
QApplication a(argc, argv); |
||||
Widget w; |
||||
w.show(); |
||||
|
||||
return a.exec(); |
||||
} |
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
<RCC> |
||||
<qresource prefix="/"> |
||||
<file>res/qtox-256x256.png</file> |
||||
</qresource> |
||||
</RCC> |
After Width: | Height: | Size: 5.5 KiB |
@ -0,0 +1,254 @@
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
||||
See the COPYING file for more details. |
||||
*/ |
||||
|
||||
|
||||
#include "serialize.h" |
||||
|
||||
QByteArray doubleToData(double num) |
||||
{ |
||||
union |
||||
{ |
||||
char tab[8]; |
||||
double n; |
||||
} castUnion; |
||||
//char n[8];
|
||||
//*((double*) n) = num;
|
||||
|
||||
castUnion.n=num; |
||||
return QByteArray(castUnion.tab,8); |
||||
} |
||||
|
||||
QByteArray floatToData(float num) |
||||
{ |
||||
union |
||||
{ |
||||
char tab[4]; |
||||
float n; |
||||
} castUnion; |
||||
|
||||
castUnion.n=num; |
||||
return QByteArray(castUnion.tab,4); |
||||
} |
||||
|
||||
float dataToFloat(QByteArray data) |
||||
{ |
||||
union |
||||
{ |
||||
char tab[4]; |
||||
float n; |
||||
} castUnion; |
||||
|
||||
castUnion.tab[0]=data.data()[0]; |
||||
castUnion.tab[1]=data.data()[1]; |
||||
castUnion.tab[2]=data.data()[2]; |
||||
castUnion.tab[3]=data.data()[3]; |
||||
return castUnion.n; |
||||
} |
||||
|
||||
// Converts a string into PNet string data
|
||||
QByteArray stringToData(QString str) |
||||
{ |
||||
QByteArray data(4,0); |
||||
// Write the size in a Uint of variable lenght (8-32 bits)
|
||||
int i=0; |
||||
uint num1 = (uint)str.toUtf8().size(); |
||||
while (num1 >= 0x80) |
||||
{ |
||||
data[i] = (unsigned char)(num1 | 0x80); i++; |
||||
num1 = num1 >> 7; |
||||
} |
||||
data[i]=num1; |
||||
data.resize(i+1); |
||||
data+=str.toUtf8(); |
||||
return data; |
||||
} |
||||
|
||||
QString dataToString(QByteArray data) |
||||
{ |
||||
// Variable UInt32
|
||||
unsigned char num3; |
||||
int num = 0; |
||||
int num2 = 0; |
||||
int i=0; |
||||
do |
||||
{ |
||||
num3 = data[i]; i++; |
||||
num |= (num3 & 0x7f) << num2; |
||||
num2 += 7; |
||||
} while ((num3 & 0x80) != 0); |
||||
unsigned int strlen = (uint) num; |
||||
|
||||
if (!strlen) |
||||
return QString(); |
||||
|
||||
data = data.right(data.size()-i); // Remove the strlen
|
||||
data.truncate(strlen); |
||||
return QString(data); |
||||
} |
||||
|
||||
float dataToRangedSingle(float min, float max, int numberOfBits, QByteArray data) |
||||
{ |
||||
uint endvalue=0; |
||||
uint value=0; |
||||
if (numberOfBits <= 8) |
||||
{ |
||||
endvalue = (uchar)data[0]; |
||||
goto done; |
||||
} |
||||
value = (uchar)data[0]; |
||||
numberOfBits -= 8; |
||||
if (numberOfBits <= 8) |
||||
{ |
||||
endvalue = (value | ((uint) ((uchar)data[1]) << 8)); |
||||
goto done; |
||||
} |
||||
value |= (uint) (((uchar)data[1]) << 8); |
||||
numberOfBits -= 8; |
||||
if (numberOfBits <= 8) |
||||
{ |
||||
uint num2 = (uint) (((uchar)data[2]) << 0x10); |
||||
endvalue = (value | num2); |
||||
goto done; |
||||
} |
||||
value |= (uint) (((uchar)data[2]) << 0x10); |
||||
numberOfBits -= 8; |
||||
endvalue = (value | ((uint) (((uchar)data[3]) << 0x18))); |
||||
goto done; |
||||
|
||||
done: |
||||
|
||||
float num = max - min; |
||||
int num2 = (((int) 1) << numberOfBits) - 1; |
||||
float num3 = endvalue; |
||||
float num4 = num3 / ((float) num2); |
||||
return (min + (num4 * num)); |
||||
} |
||||
|
||||
QByteArray rangedSingleToData(float value, float min, float max, int numberOfBits) |
||||
{ |
||||
QByteArray data; |
||||
float num = max - min; |
||||
float num2 = (value - min) / num; |
||||
int num3 = (((int) 1) << numberOfBits) - 1; |
||||
uint source = num3 * num2; |
||||
|
||||
if (numberOfBits <= 8) |
||||
{ |
||||
data += (unsigned char)source; |
||||
return data; |
||||
} |
||||
data += (unsigned char)source; |
||||
numberOfBits -= 8; |
||||
if (numberOfBits <= 8) |
||||
{ |
||||
data += (unsigned char)source>>8; |
||||
return data; |
||||
} |
||||
data += (unsigned char)source>>8; |
||||
numberOfBits -= 8; |
||||
if (numberOfBits <= 8) |
||||
{ |
||||
data += (unsigned char)source>>16; |
||||
return data; |
||||
} |
||||
data += (unsigned char)source>>16; |
||||
data += (unsigned char)source>>24; |
||||
|
||||
return data; |
||||
} |
||||
|
||||
uint8_t dataToUint8(QByteArray data) |
||||
{ |
||||
return (uint8_t)data[0]; |
||||
} |
||||
|
||||
uint16_t dataToUint16(QByteArray data) |
||||
{ |
||||
return ((uint16_t)(uint8_t)data[0]) |
||||
+(((uint16_t)(uint8_t)data[1])<<8); |
||||
} |
||||
|
||||
uint32_t dataToUint32(QByteArray data) |
||||
{ |
||||
return ((uint32_t)(uint8_t)data[0]) |
||||
+(((uint32_t)(uint8_t)data[1])<<8) |
||||
+(((uint32_t)(uint8_t)data[2])<<16) |
||||
+(((uint32_t)(uint8_t)data[3])<<24); |
||||
} |
||||
|
||||
uint64_t dataToUint64(QByteArray data) |
||||
{ |
||||
return ((uint64_t)(uint8_t)data[0]) |
||||
+(((uint64_t)(uint8_t)data[1])<<8) |
||||
+(((uint64_t)(uint8_t)data[2])<<16) |
||||
+(((uint64_t)(uint8_t)data[3])<<24) |
||||
+(((uint64_t)(uint8_t)data[4])<<32) |
||||
+(((uint64_t)(uint8_t)data[5])<<40) |
||||
+(((uint64_t)(uint8_t)data[6])<<48) |
||||
+(((uint64_t)(uint8_t)data[7])<<56); |
||||
} |
||||
|
||||
unsigned getVUint32Size(QByteArray data) |
||||
{ |
||||
unsigned lensize=0; |
||||
{ |
||||
unsigned char num3; |
||||
do { |
||||
num3 = data[lensize]; |
||||
lensize++; |
||||
} while ((num3 & 0x80) != 0); |
||||
} |
||||
return lensize; |
||||
} |
||||
|
||||
QByteArray uint8ToData(uint8_t num) |
||||
{ |
||||
QByteArray data(1,0); |
||||
data[0] = (uint8_t)num; |
||||
return data; |
||||
} |
||||
|
||||
QByteArray uint16ToData(uint16_t num) |
||||
{ |
||||
QByteArray data(2,0); |
||||
data[0] = (uint8_t)(num & 0xFF); |
||||
data[1] = (uint8_t)((num>>8) & 0xFF); |
||||
return data; |
||||
} |
||||
|
||||
QByteArray uint32ToData(uint32_t num) |
||||
{ |
||||
QByteArray data(4,0); |
||||
data[0] = (uint8_t)(num & 0xFF); |
||||
data[1] = (uint8_t)((num>>8) & 0xFF); |
||||
data[2] = (uint8_t)((num>>16) & 0xFF); |
||||
data[3] = (uint8_t)((num>>24) & 0xFF); |
||||
return data; |
||||
} |
||||
|
||||
QByteArray uint64ToData(uint64_t num) |
||||
{ |
||||
QByteArray data(8,0); |
||||
data[0] = (uint8_t)(num & 0xFF); |
||||
data[1] = (uint8_t)((num>>8) & 0xFF); |
||||
data[2] = (uint8_t)((num>>16) & 0xFF); |
||||
data[3] = (uint8_t)((num>>24) & 0xFF); |
||||
data[4] = (uint8_t)((num>>32) & 0xFF); |
||||
data[5] = (uint8_t)((num>>40) & 0xFF); |
||||
data[6] = (uint8_t)((num>>48) & 0xFF); |
||||
data[7] = (uint8_t)((num>>56) & 0xFF); |
||||
return data; |
||||
} |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
||||
See the COPYING file for more details. |
||||
*/ |
||||
|
||||
|
||||
#ifndef SERIALIZE_H |
||||
#define SERIALIZE_H |
||||
|
||||
#include <cstdint> |
||||
#include <QByteArray> |
||||
#include <QString> |
||||
|
||||
/// Most of those functions are unsafe unless otherwise specified
|
||||
/// Do not use them on untrusted data (e.g. check a signature first)
|
||||
|
||||
QByteArray doubleToData(double num); |
||||
QByteArray floatToData(float num); |
||||
float dataToFloat(QByteArray data); |
||||
QByteArray stringToData(QString str); |
||||
QString dataToString(QByteArray data); |
||||
float dataToRangedSingle(float min, float max, int numberOfBits, QByteArray data); |
||||
QByteArray rangedSingleToData(float value, float min, float max, int numberOfBits); |
||||
uint8_t dataToUint8(QByteArray data); |
||||
uint16_t dataToUint16(QByteArray data); |
||||
uint32_t dataToUint32(QByteArray data); |
||||
uint64_t dataToUint64(QByteArray data); |
||||
unsigned getVUint32Size(QByteArray data); |
||||
QByteArray uint8ToData(uint8_t num); |
||||
QByteArray uint16ToData(uint16_t num); |
||||
QByteArray uint32ToData(uint32_t num); |
||||
QByteArray uint64ToData(uint64_t num); |
||||
|
||||
#endif // SERIALIZE_H
|
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
||||
See the COPYING file for more details. |
||||
*/ |
||||
|
||||
|
||||
#include "settingsDir.h" |
||||
#include <QFile> |
||||
#include <QSettings> |
||||
#include <QDir> |
||||
#include <QStandardPaths> |
||||
|
||||
const QString FILENAME = "settings.ini"; |
||||
|
||||
QString getSettingsDirPath() |
||||
{ |
||||
if (isToxPortableEnabled()) |
||||
return "."; |
||||
|
||||
#ifdef Q_OS_WIN |
||||
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) |
||||
+ QDir::separator() + "AppData" + QDir::separator() + "Roaming" + QDir::separator() + "tox"); |
||||
#else |
||||
return QDir::cleanPath(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + QDir::separator() + "tox"); |
||||
#endif |
||||
} |
||||
|
||||
bool isToxPortableEnabled() |
||||
{ |
||||
QFile portableSettings(FILENAME); |
||||
if (portableSettings.exists()) |
||||
{ |
||||
QSettings ps(FILENAME, QSettings::IniFormat); |
||||
ps.beginGroup("General"); |
||||
return ps.value("makeToxPortable", false).toBool(); |
||||
} |
||||
else |
||||
{ |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
||||
See the COPYING file for more details. |
||||
*/ |
||||
|
||||
|
||||
#ifndef SETTINGSDIR_H |
||||
#define SETTINGSDIR_H |
||||
|
||||
#include <QString> |
||||
|
||||
QString getSettingsDirPath(); |
||||
|
||||
bool isToxPortableEnabled(); |
||||
|
||||
#endif // SETTINGSDIR_H
|
@ -0,0 +1,115 @@
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
||||
See the COPYING file for more details. |
||||
*/ |
||||
|
||||
|
||||
#include "update.h" |
||||
#include "serialize.h" |
||||
#include <QFile> |
||||
#include <QDebug> |
||||
|
||||
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 |
||||
}; |
||||
|
||||
QByteArray 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<UpdateFileMeta> genUpdateDiff(QList<UpdateFileMeta> updateFlist) |
||||
{ |
||||
QList<UpdateFileMeta> diff; |
||||
QList<UpdateFileMeta> localFlist = parseFlist(getLocalFlist()); |
||||
|
||||
for (UpdateFileMeta file : updateFlist) |
||||
if (!localFlist.contains(file)) |
||||
diff += file; |
||||
|
||||
return diff; |
||||
} |
||||
|
||||
QList<UpdateFileMeta> parseFlist(QByteArray flistData) |
||||
{ |
||||
QList<UpdateFileMeta> flist; |
||||
|
||||
if (flistData.isEmpty()) |
||||
{ |
||||
qWarning() << "AutoUpdater::parseflist: Empty data"; |
||||
return flist; |
||||
} |
||||
|
||||
// Check version
|
||||
if (flistData[0] != '1') |
||||
{ |
||||
qWarning() << "AutoUpdater: parseflist: Bad version "<<(uint8_t)flistData[0]; |
||||
return flist; |
||||
} |
||||
flistData = flistData.mid(1); |
||||
|
||||
// Check signature
|
||||
if (flistData.size() < (int)(crypto_sign_BYTES)) |
||||
{ |
||||
qWarning() << "AutoUpdater::parseflist: Truncated data"; |
||||
return flist; |
||||
} |
||||
else |
||||
{ |
||||
QByteArray msgData = flistData.mid(crypto_sign_BYTES); |
||||
unsigned char* msg = (unsigned char*)msgData.data(); |
||||
if (crypto_sign_verify_detached((unsigned char*)flistData.data(), msg, msgData.size(), key) != 0) |
||||
{ |
||||
qCritical() << "AutoUpdater: parseflist: FORGED FLIST FILE"; |
||||
return flist; |
||||
} |
||||
flistData = flistData.mid(crypto_sign_BYTES); |
||||
} |
||||
|
||||
// Parse. We assume no errors handling needed since the signature is valid.
|
||||
while (!flistData.isEmpty()) |
||||
{ |
||||
UpdateFileMeta newFile; |
||||
|
||||
memcpy(newFile.sig, flistData.data(), crypto_sign_BYTES); |
||||
flistData = flistData.mid(crypto_sign_BYTES); |
||||
|
||||
newFile.id = dataToString(flistData); |
||||
flistData = flistData.mid(newFile.id.size() + getVUint32Size(flistData)); |
||||
|
||||
newFile.installpath = dataToString(flistData); |
||||
flistData = flistData.mid(newFile.installpath.size() + getVUint32Size(flistData)); |
||||
|
||||
newFile.size = dataToUint64(flistData); |
||||
flistData = flistData.mid(8); |
||||
|
||||
flist += newFile; |
||||
} |
||||
|
||||
return flist; |
||||
} |
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
||||
See the COPYING file for more details. |
||||
*/ |
||||
|
||||
|
||||
#ifndef UPDATE_H |
||||
#define UPDATE_H |
||||
|
||||
#include <QByteArray> |
||||
#include <QString> |
||||
#include <sodium.h> |
||||
|
||||
struct UpdateFileMeta |
||||
{ |
||||
unsigned char sig[crypto_sign_BYTES]; ///< Signature of the file (ed25519)
|
||||
QString id; ///< Unique id of the file
|
||||
QString installpath; ///< Local path including the file name. May be relative to qtox-updater or absolute
|
||||
uint64_t size; ///< Size in bytes of the file
|
||||
|
||||
bool operator==(const UpdateFileMeta& other) |
||||
{ |
||||
return (size == other.size |
||||
&& id == other.id && installpath == other.installpath |
||||
&& memcmp(sig, other.sig, crypto_sign_BYTES) == 0); |
||||
} |
||||
}; |
||||
|
||||
struct UpdateFile |
||||
{ |
||||
UpdateFileMeta metadata; |
||||
QByteArray data; |
||||
}; |
||||
|
||||
/// Gets the local flist. Returns an empty array on error
|
||||
QByteArray getLocalFlist(); |
||||
/// Parses and validates a flist file. Returns an empty list on error
|
||||
QList<UpdateFileMeta> parseFlist(QByteArray flistData); |
||||
/// Generates a list of files we need to update
|
||||
QList<UpdateFileMeta> genUpdateDiff(QList<UpdateFileMeta> updateFlist); |
||||
|
||||
extern unsigned char key[crypto_sign_PUBLICKEYBYTES]; |
||||
|
||||
#endif // UPDATE_H
|
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
#------------------------------------------------- |
||||
# |
||||
# Project created by QtCreator 2014-11-09T21:09:08 |
||||
# |
||||
#------------------------------------------------- |
||||
|
||||
QT += core gui |
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets |
||||
|
||||
TARGET = qtox-updater |
||||
TEMPLATE = app |
||||
|
||||
CONFIG += c++11 |
||||
|
||||
SOURCES += main.cpp\ |
||||
widget.cpp \ |
||||
settingsDir.cpp \ |
||||
update.cpp \ |
||||
serialize.cpp |
||||
|
||||
HEADERS += widget.h \ |
||||
settingsDir.h \ |
||||
update.h \ |
||||
serialize.h |
||||
|
||||
FORMS += widget.ui |
||||
|
||||
RESOURCES += \ |
||||
res.qrc |
||||
|
||||
INCLUDEPATH += libs/include |
||||
|
||||
RC_FILE = windows/updater.rc |
||||
|
||||
LIBS += -L$$PWD/libs/lib/ -lsodium |
@ -0,0 +1,156 @@
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
||||
See the COPYING file for more details. |
||||
*/ |
||||
|
||||
|
||||
#include "widget.h" |
||||
#include "ui_widget.h" |
||||
|
||||
#include <QDir> |
||||
#include <QFile> |
||||
#include <QProcess> |
||||
#include <QMessageBox> |
||||
#include <QMetaObject> |
||||
|
||||
#include "settingsDir.h" |
||||
#include "update.h" |
||||
|
||||
#ifdef Q_OS_WIN |
||||
const bool supported = true; |
||||
const QString QTOX_PATH = "qtox.exe"; |
||||
#else |
||||
const bool supported = false; |
||||
const QString QTOX_PATH; |
||||
#endif |
||||
|
||||
Widget::Widget(QWidget *parent) : |
||||
QWidget(parent), |
||||
ui(new Ui::Widget) |
||||
{ |
||||
ui->setupUi(this); |
||||
|
||||
// Updates only for supported platforms
|
||||
if (!supported) |
||||
{ |
||||
fatalError(tr("The qTox updater is not supported on this platform.")); |
||||
} |
||||
|
||||
QMetaObject::invokeMethod(this, "update", Qt::QueuedConnection); |
||||
} |
||||
|
||||
Widget::~Widget() |
||||
{ |
||||
delete ui; |
||||
} |
||||
|
||||
void Widget::setProgress(int value) |
||||
{ |
||||
ui->progress->setValue(value); |
||||
qApp->processEvents(); |
||||
} |
||||
|
||||
void Widget::fatalError(QString message) |
||||
{ |
||||
QMessageBox::critical(this,tr("Error"), message+'\n'+tr("qTox will restart now.")); |
||||
deleteUpdate(); |
||||
startQToxAndExit(); |
||||
} |
||||
|
||||
void Widget::deleteUpdate() |
||||
{ |
||||
QDir updateDir(getSettingsDirPath()+"/update/"); |
||||
updateDir.removeRecursively(); |
||||
} |
||||
|
||||
void Widget::startQToxAndExit() |
||||
{ |
||||
QProcess::startDetached(QTOX_PATH); |
||||
exit(0); |
||||
} |
||||
|
||||
void Widget::update() |
||||
{ |
||||
/// 1. Find and parse the update (0-5%)
|
||||
// Check that the dir exists
|
||||
QString updateDirStr = getSettingsDirPath()+"/update/"; |
||||
QDir updateDir(updateDirStr); |
||||
if (!updateDir.exists()) |
||||
fatalError(tr("No update found.")); |
||||
|
||||
// Check that we have a flist and that every file on the diff exists
|
||||
QFile updateFlistFile(updateDirStr+"flist"); |
||||
if (!updateFlistFile.open(QIODevice::ReadOnly)) |
||||
fatalError(tr("The update is incomplete.")); |
||||
QByteArray updateFlistData = updateFlistFile.readAll(); |
||||
updateFlistFile.close(); |
||||
|
||||
setProgress(1); |
||||
|
||||
QList<UpdateFileMeta> updateFlist = parseFlist(updateFlistData); |
||||
setProgress(2); |
||||
QList<UpdateFileMeta> diff = genUpdateDiff(updateFlist); |
||||
setProgress(4); |
||||
for (UpdateFileMeta fileMeta : diff) |
||||
if (!QFile::exists(updateDirStr+fileMeta.installpath)) |
||||
fatalError(tr("The update is incomplete.")); |
||||
setProgress(5); |
||||
|
||||
/// 2. Check the update (5-50%)
|
||||
float checkProgressStep = 45/diff.size(); |
||||
float checkProgress = 5; |
||||
for (UpdateFileMeta fileMeta : diff) |
||||
{ |
||||
UpdateFile file; |
||||
file.metadata = fileMeta; |
||||
|
||||
QFile fileFile(updateDirStr+fileMeta.installpath); |
||||
if (!fileFile.open(QIODevice::ReadOnly)) |
||||
fatalError(tr("Update files are unreadable.")); |
||||
file.data = fileFile.readAll(); |
||||
fileFile.close(); |
||||
|
||||
if (file.data.size() != (int)fileMeta.size) |
||||
fatalError(tr("Update files are corrupted.")); |
||||
|
||||
if (crypto_sign_verify_detached(file.metadata.sig, (unsigned char*)file.data.data(), |
||||
file.data.size(), key) != 0) |
||||
fatalError(tr("Update files are corrupted.")); |
||||
|
||||
checkProgress += checkProgressStep; |
||||
setProgress(checkProgress); |
||||
} |
||||
setProgress(50); |
||||
|
||||
/// 3. Install the update (50-95%)
|
||||
float installProgressStep = 45/diff.size(); |
||||
float installProgress = 50; |
||||
for (UpdateFileMeta fileMeta : diff) |
||||
{ |
||||
QFile fileFile(updateDirStr+fileMeta.installpath); |
||||
if (!fileFile.copy(fileMeta.installpath)) |
||||
fatalError(tr("Unable to copy the update's files.")); |
||||
|
||||
installProgress += installProgressStep; |
||||
setProgress(installProgress); |
||||
} |
||||
setProgress(95); |
||||
|
||||
/// 4. Delete the update (95-100%)
|
||||
deleteUpdate(); |
||||
setProgress(100); |
||||
|
||||
/// 5. Start qTox and exit
|
||||
startQToxAndExit(); |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox. |
||||
|
||||
This program is libre software: you can redistribute it and/or modify |
||||
it under the terms of the GNU General Public License as published by |
||||
the Free Software Foundation, either version 3 of the License, or |
||||
(at your option) any later version. |
||||
This program is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
|
||||
See the COPYING file for more details. |
||||
*/ |
||||
|
||||
|
||||
#ifndef WIDGET_H |
||||
#define WIDGET_H |
||||
|
||||
#include <QWidget> |
||||
|
||||
namespace Ui { |
||||
class Widget; |
||||
} |
||||
|
||||
class Widget : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
explicit Widget(QWidget *parent = 0); |
||||
~Widget(); |
||||
|
||||
// Utilities
|
||||
void setProgress(int value); |
||||
|
||||
// Noreturn
|
||||
void fatalError(QString message); ///< Calls deleteUpdate and startQToxAndExit
|
||||
void deleteUpdate(); |
||||
void startQToxAndExit(); |
||||
|
||||
public slots: |
||||
// Finds and applies the update
|
||||
void update(); |
||||
|
||||
private: |
||||
Ui::Widget *ui; |
||||
}; |
||||
|
||||
#endif // WIDGET_H
|
@ -0,0 +1,139 @@
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<ui version="4.0"> |
||||
<class>Widget</class> |
||||
<widget class="QWidget" name="Widget"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>0</y> |
||||
<width>401</width> |
||||
<height>224</height> |
||||
</rect> |
||||
</property> |
||||
<property name="windowTitle"> |
||||
<string>qTox Updater</string> |
||||
</property> |
||||
<property name="windowIcon"> |
||||
<iconset resource="res.qrc"> |
||||
<normaloff>:/res/qtox-256x256.png</normaloff>:/res/qtox-256x256.png</iconset> |
||||
</property> |
||||
<widget class="QLabel" name="label"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>0</x> |
||||
<y>13</y> |
||||
<width>191</width> |
||||
<height>191</height> |
||||
</rect> |
||||
</property> |
||||
<property name="text"> |
||||
<string/> |
||||
</property> |
||||
<property name="pixmap"> |
||||
<pixmap resource="res.qrc">:/res/qtox-256x256.png</pixmap> |
||||
</property> |
||||
<property name="scaledContents"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
<widget class="QProgressBar" name="progress"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>206</x> |
||||
<y>95</y> |
||||
<width>171</width> |
||||
<height>20</height> |
||||
</rect> |
||||
</property> |
||||
<property name="minimum"> |
||||
<number>0</number> |
||||
</property> |
||||
<property name="value"> |
||||
<number>0</number> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignCenter</set> |
||||
</property> |
||||
<property name="invertedAppearance"> |
||||
<bool>false</bool> |
||||
</property> |
||||
</widget> |
||||
<widget class="QLabel" name="label_2"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>205</x> |
||||
<y>115</y> |
||||
<width>171</width> |
||||
<height>20</height> |
||||
</rect> |
||||
</property> |
||||
<property name="text"> |
||||
<string>Updating qTox ...</string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignCenter</set> |
||||
</property> |
||||
</widget> |
||||
<widget class="QLabel" name="label_3"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>201</x> |
||||
<y>170</y> |
||||
<width>181</width> |
||||
<height>20</height> |
||||
</rect> |
||||
</property> |
||||
<property name="text"> |
||||
<string><a href="https://tox.im">https://tox.im</a></string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignCenter</set> |
||||
</property> |
||||
<property name="openExternalLinks"> |
||||
<bool>true</bool> |
||||
</property> |
||||
</widget> |
||||
<widget class="QLabel" name="label_4"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>200</x> |
||||
<y>183</y> |
||||
<width>181</width> |
||||
<height>20</height> |
||||
</rect> |
||||
</property> |
||||
<property name="text"> |
||||
<string><a href="https://github.com/tux3/qtox">https://github.com/tux3/qtox</a></string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignCenter</set> |
||||
</property> |
||||
</widget> |
||||
<widget class="QLabel" name="label_5"> |
||||
<property name="geometry"> |
||||
<rect> |
||||
<x>195</x> |
||||
<y>32</y> |
||||
<width>191</width> |
||||
<height>31</height> |
||||
</rect> |
||||
</property> |
||||
<property name="font"> |
||||
<font> |
||||
<pointsize>14</pointsize> |
||||
</font> |
||||
</property> |
||||
<property name="text"> |
||||
<string>qTox Update</string> |
||||
</property> |
||||
<property name="alignment"> |
||||
<set>Qt::AlignCenter</set> |
||||
</property> |
||||
</widget> |
||||
</widget> |
||||
<layoutdefault spacing="6" margin="11"/> |
||||
<resources> |
||||
<include location="res.qrc"/> |
||||
</resources> |
||||
<connections/> |
||||
</ui> |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
||||
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> |
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"> |
||||
<security> |
||||
<requestedPrivileges> |
||||
<requestedExecutionLevel |
||||
level="requireAdministrator" |
||||
uiAccess="false"/> |
||||
</requestedPrivileges> |
||||
</security> |
||||
</trustInfo> |
||||
</assembly> |
After Width: | Height: | Size: 17 KiB |
Loading…
Reference in new issue