2014-11-09 22:51:00 +08:00
|
|
|
/*
|
|
|
|
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 AUTOUPDATE_H
|
|
|
|
#define AUTOUPDATE_H
|
|
|
|
|
|
|
|
#include <QString>
|
2014-11-10 00:55:38 +08:00
|
|
|
#include <QList>
|
|
|
|
#include <sodium.h>
|
2014-11-09 22:51:00 +08:00
|
|
|
|
2014-11-10 06:24:23 +08:00
|
|
|
/// For now we only support auto updates on Windows, although extending it is not a technical issue.
|
|
|
|
/// Linux and Mac users are expected to use their package managers or update manually through official channels.
|
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
#define AUTOUPDATE_ENABLED 1
|
2014-11-12 05:37:51 +08:00
|
|
|
#elif defined(Q_OS_OSX)
|
2014-11-14 07:01:49 +08:00
|
|
|
#define AUTOUPDATE_ENABLED 1
|
2014-11-10 06:24:23 +08:00
|
|
|
#else
|
|
|
|
#define AUTOUPDATE_ENABLED 0
|
|
|
|
#endif
|
|
|
|
|
2014-11-09 22:51:00 +08:00
|
|
|
/// Handles checking and applying updates for qTox
|
2014-11-10 06:24:23 +08:00
|
|
|
/// Do *NOT* use auto update unless AUTOUPDATE_ENABLED is defined to 1
|
2014-11-09 22:51:00 +08:00
|
|
|
class AutoUpdater
|
|
|
|
{
|
2014-11-10 00:55:38 +08:00
|
|
|
public:
|
|
|
|
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
|
2014-11-10 06:24:23 +08:00
|
|
|
|
|
|
|
bool operator==(const UpdateFileMeta& other)
|
|
|
|
{
|
|
|
|
return (size == other.size
|
|
|
|
&& id == other.id && installpath == other.installpath
|
|
|
|
&& memcmp(sig, other.sig, crypto_sign_BYTES) == 0);
|
|
|
|
}
|
2014-11-10 00:55:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct UpdateFile
|
|
|
|
{
|
|
|
|
UpdateFileMeta metadata;
|
|
|
|
QByteArray data;
|
|
|
|
};
|
|
|
|
|
2014-11-13 21:09:35 +08:00
|
|
|
struct VersionInfo
|
|
|
|
{
|
|
|
|
uint64_t timestamp;
|
|
|
|
QString versionString;
|
|
|
|
};
|
|
|
|
|
2014-11-09 22:51:00 +08:00
|
|
|
public:
|
2014-11-10 07:31:29 +08:00
|
|
|
/// Connects to the qTox update server, if an updat is found shows a dialog to the user asking to download it
|
|
|
|
/// Runs asynchronously in its own thread, and will return immediatly
|
|
|
|
/// Will call isUpdateAvailable, and as such may processEvents
|
|
|
|
static void checkUpdatesAsyncInteractive();
|
2014-11-09 22:51:00 +08:00
|
|
|
/// Connects to the qTox update server, returns true if an update is available for download
|
|
|
|
/// Will call getUpdateVersion, and as such may block and processEvents
|
|
|
|
static bool isUpdateAvailable();
|
2014-11-13 21:09:35 +08:00
|
|
|
/// Fetch the version info of the last update available from the qTox update server
|
2014-11-09 22:51:00 +08:00
|
|
|
/// Will try to follow qTox's proxy settings, may block and processEvents
|
2014-11-13 21:09:35 +08:00
|
|
|
static VersionInfo getUpdateVersion();
|
2014-11-10 06:24:23 +08:00
|
|
|
/// Will try to download an update, if successful returns true and qTox will apply it after a restart
|
2014-11-10 00:55:38 +08:00
|
|
|
/// Will try to follow qTox's proxy settings, may block and processEvents
|
2014-11-10 06:24:23 +08:00
|
|
|
static bool downloadUpdate();
|
2015-01-05 16:35:55 +08:00
|
|
|
/// Returns true if an update is downloaded and ready to be installed,
|
|
|
|
/// if so, call installLocalUpdate.
|
|
|
|
/// If an update was partially downloaded, the function will resume asynchronously and return false
|
2014-11-10 06:24:23 +08:00
|
|
|
static bool isLocalUpdateReady();
|
|
|
|
/// Launches the qTox updater to try to install the local update and exits immediately
|
|
|
|
/// Will not check that the update actually exists, use isLocalUpdateReady first for that
|
|
|
|
/// The qTox updater will restart us after the update is done
|
|
|
|
/// Note: If we fail to start the qTox updater, we will delete the update and exit
|
|
|
|
[[ noreturn ]] static void installLocalUpdate();
|
2015-01-05 16:54:03 +08:00
|
|
|
/// Aborting will make some functions try to return early
|
|
|
|
/// Call before qTox exits to avoid the updater running in the background
|
|
|
|
static void abortUpdates();
|
2014-11-10 00:55:38 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/// Parses and validates a flist file. Returns an empty list on error
|
2014-11-10 06:24:23 +08:00
|
|
|
static QList<UpdateFileMeta> parseFlist(QByteArray flistData);
|
|
|
|
/// 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);
|
|
|
|
/// 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.
|
2014-11-10 00:55:38 +08:00
|
|
|
/// Will try to follow qTox's proxy settings, may block and processEvents
|
2014-11-10 06:24:23 +08:00
|
|
|
static UpdateFile getUpdateFile(UpdateFileMeta fileMeta);
|
2014-11-10 07:31:29 +08:00
|
|
|
/// Does the actual work for checkUpdatesAsyncInteractive
|
|
|
|
/// Blocking, but otherwise has the same properties than checkUpdatesAsyncInteractive
|
|
|
|
static void checkUpdatesAsyncInteractiveWorker();
|
2014-11-09 22:51:00 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
AutoUpdater() = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Constants
|
|
|
|
static const QString updateServer; ///< Hostname of the qTox update server
|
|
|
|
static const QString platform; ///< Name of platform we're trying to get updates for
|
|
|
|
static const QString checkURI; ///< URI of the file containing the latest version string
|
|
|
|
static const QString flistURI; ///< URI of the file containing info on each file (hash, signature, size, name, ..)
|
|
|
|
static const QString filesURI; ///< URI of the actual files of the latest version
|
2014-11-10 06:24:23 +08:00
|
|
|
static const QString updaterBin; ///< Path to the qtox-updater binary
|
2014-11-09 22:51:00 +08:00
|
|
|
static unsigned char key[];
|
2015-01-05 16:54:03 +08:00
|
|
|
static bool abortFlag; ///< If true, try to abort everything.
|
2014-11-09 22:51:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // AUTOUPDATE_H
|