2021-01-18 07:28:54 +00:00
|
|
|
/* Copyright 2013-2021 MultiMC Contributors
|
2013-12-04 18:34:12 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-02-09 00:51:14 +00:00
|
|
|
#include "net/NetJob.h"
|
2015-02-08 16:56:14 +00:00
|
|
|
#include "GoUpdate.h"
|
2022-04-26 00:33:17 +01:00
|
|
|
#include "ExternalUpdater.h"
|
2013-12-04 18:34:12 +00:00
|
|
|
|
2022-04-21 03:34:13 +01:00
|
|
|
#ifdef Q_OS_MAC
|
2022-04-26 00:33:17 +01:00
|
|
|
#include "MacSparkleUpdater.h"
|
2022-04-21 03:34:13 +01:00
|
|
|
#endif
|
|
|
|
|
2021-07-25 18:11:59 +01:00
|
|
|
class UpdateChecker : public QObject
|
2013-12-04 18:34:12 +00:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
Q_OBJECT
|
2013-12-04 18:34:12 +00:00
|
|
|
|
|
|
|
public:
|
2021-11-21 22:21:12 +00:00
|
|
|
UpdateChecker(shared_qobject_ptr<QNetworkAccessManager> nam, QString channelUrl, QString currentChannel, int currentBuild);
|
2022-04-26 00:33:17 +01:00
|
|
|
void checkForUpdate(const QString& updateChannel, bool notifyNoUpdate);
|
2018-07-15 13:51:05 +01:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Causes the update checker to download the channel list from the URL specified in config.h (generated by CMake).
|
|
|
|
* If this isn't called before checkForUpdate(), it will automatically be called.
|
|
|
|
*/
|
|
|
|
void updateChanList(bool notifyNoUpdate);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* An entry in the channel list.
|
|
|
|
*/
|
|
|
|
struct ChannelListEntry
|
|
|
|
{
|
|
|
|
QString id;
|
|
|
|
QString name;
|
|
|
|
QString description;
|
|
|
|
QString url;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Returns a the current channel list.
|
|
|
|
* If the channel list hasn't been loaded, this list will be empty.
|
|
|
|
*/
|
|
|
|
QList<ChannelListEntry> getChannelList() const;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Returns false if the channel list is empty.
|
|
|
|
*/
|
|
|
|
bool hasChannels() const;
|
2013-12-05 19:52:55 +00:00
|
|
|
|
2022-04-21 03:34:13 +01:00
|
|
|
/*!
|
2022-04-26 00:33:17 +01:00
|
|
|
* Returns a pointer to an object that controls the external updater, or nullptr if an external updater is not used.
|
2022-04-21 03:34:13 +01:00
|
|
|
*/
|
2022-04-26 00:33:17 +01:00
|
|
|
ExternalUpdater *getExternalUpdater();
|
2022-04-21 03:34:13 +01:00
|
|
|
|
2013-12-05 19:52:55 +00:00
|
|
|
signals:
|
2018-07-15 13:51:05 +01:00
|
|
|
//! Signal emitted when an update is available. Passes the URL for the repo and the ID and name for the version.
|
|
|
|
void updateAvailable(GoUpdate::Status status);
|
2013-12-05 19:52:55 +00:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
//! Signal emitted when the channel list finishes loading or fails to load.
|
|
|
|
void channelListLoaded();
|
2013-12-05 19:52:55 +00:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
void noUpdateFound();
|
2013-12-24 21:00:07 +00:00
|
|
|
|
2013-12-05 19:52:55 +00:00
|
|
|
private slots:
|
2018-07-15 13:51:05 +01:00
|
|
|
void updateCheckFinished(bool notifyNoUpdate);
|
|
|
|
void updateCheckFailed();
|
2013-12-05 19:52:55 +00:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
void chanListDownloadFinished(bool notifyNoUpdate);
|
|
|
|
void chanListDownloadFailed(QString reason);
|
2013-12-05 19:52:55 +00:00
|
|
|
|
2013-12-04 18:34:12 +00:00
|
|
|
private:
|
2018-07-15 13:51:05 +01:00
|
|
|
friend class UpdateCheckerTest;
|
|
|
|
|
2021-11-21 22:21:12 +00:00
|
|
|
shared_qobject_ptr<QNetworkAccessManager> m_network;
|
|
|
|
|
|
|
|
NetJob::Ptr indexJob;
|
2018-07-15 13:51:05 +01:00
|
|
|
QByteArray indexData;
|
2021-11-21 22:21:12 +00:00
|
|
|
NetJob::Ptr chanListJob;
|
2018-07-15 13:51:05 +01:00
|
|
|
QByteArray chanlistData;
|
|
|
|
|
2021-09-04 20:27:09 +01:00
|
|
|
QString m_channelUrl;
|
2018-07-15 13:51:05 +01:00
|
|
|
|
|
|
|
QList<ChannelListEntry> m_channels;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* True while the system is checking for updates.
|
|
|
|
* If checkForUpdate is called while this is true, it will be ignored.
|
|
|
|
*/
|
|
|
|
bool m_updateChecking = false;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* True if the channel list has loaded.
|
|
|
|
* If this is false, trying to check for updates will call updateChanList first.
|
|
|
|
*/
|
|
|
|
bool m_chanListLoaded = false;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Set to true while the channel list is currently loading.
|
|
|
|
*/
|
|
|
|
bool m_chanListLoading = false;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Set to true when checkForUpdate is called while the channel list isn't loaded.
|
|
|
|
* When the channel list finishes loading, if this is true, the update checker will check for updates.
|
|
|
|
*/
|
|
|
|
bool m_checkUpdateWaiting = false;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* if m_checkUpdateWaiting, this is the last used update channel
|
|
|
|
*/
|
|
|
|
QString m_deferredUpdateChannel;
|
|
|
|
|
|
|
|
int m_currentBuild = -1;
|
|
|
|
QString m_currentChannel;
|
|
|
|
QString m_currentRepoUrl;
|
|
|
|
|
|
|
|
QString m_newRepoUrl;
|
2022-04-21 03:34:13 +01:00
|
|
|
|
2022-04-26 00:33:17 +01:00
|
|
|
/*!
|
|
|
|
* If not a nullptr, then the updater here will be used instead of the old updater that uses GoUpdate when
|
|
|
|
* checking for updates.
|
|
|
|
*
|
|
|
|
* As a result, signals from this class won't be emitted, and most of the functions in this class other
|
|
|
|
* than checkForUpdate are not useful. Call functions from this external updater object instead.
|
|
|
|
*/
|
|
|
|
ExternalUpdater *m_externalUpdater = nullptr;
|
2013-12-04 18:34:12 +00:00
|
|
|
};
|
|
|
|
|