2017-01-08 09:28:05 +05:30
|
|
|
/* Copyright 2013-2017 MultiMC Contributors
|
2013-12-05 00:04:12 +05:30
|
|
|
*
|
|
|
|
* 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 06:21:14 +05:30
|
|
|
#include "net/NetJob.h"
|
2015-02-08 22:26:14 +05:30
|
|
|
#include "GoUpdate.h"
|
2013-12-05 00:04:12 +05:30
|
|
|
|
2015-09-05 22:16:57 +05:30
|
|
|
#include "multimc_logic_export.h"
|
|
|
|
|
|
|
|
class MULTIMC_LOGIC_EXPORT UpdateChecker : public QObject
|
2013-12-05 00:04:12 +05:30
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2015-02-08 22:26:14 +05:30
|
|
|
UpdateChecker(QString channelListUrl, QString currentChannel, int currentBuild);
|
2015-01-31 21:29:03 +05:30
|
|
|
void checkForUpdate(QString updateChannel, bool notifyNoUpdate);
|
2013-12-14 20:32:51 +05:30
|
|
|
|
2013-12-05 00:04:12 +05:30
|
|
|
/*!
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-07-14 04:27:54 +05:30
|
|
|
void updateChanList(bool notifyNoUpdate);
|
2013-12-05 00:04:12 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* An entry in the channel list.
|
|
|
|
*/
|
|
|
|
struct ChannelListEntry
|
|
|
|
{
|
|
|
|
QString id;
|
|
|
|
QString name;
|
|
|
|
QString description;
|
|
|
|
QString url;
|
|
|
|
};
|
|
|
|
|
2013-12-06 01:22:55 +05:30
|
|
|
/*!
|
|
|
|
* Returns a the current channel list.
|
|
|
|
* If the channel list hasn't been loaded, this list will be empty.
|
|
|
|
*/
|
|
|
|
QList<ChannelListEntry> getChannelList() const;
|
|
|
|
|
|
|
|
/*!
|
2014-01-05 07:16:47 +05:30
|
|
|
* Returns false if the channel list is empty.
|
2013-12-06 01:22:55 +05:30
|
|
|
*/
|
|
|
|
bool hasChannels() const;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
//! Signal emitted when an update is available. Passes the URL for the repo and the ID and name for the version.
|
2015-02-08 22:26:14 +05:30
|
|
|
void updateAvailable(GoUpdate::Status status);
|
2013-12-06 01:22:55 +05:30
|
|
|
|
|
|
|
//! Signal emitted when the channel list finishes loading or fails to load.
|
|
|
|
void channelListLoaded();
|
|
|
|
|
2013-12-25 02:30:07 +05:30
|
|
|
void noUpdateFound();
|
|
|
|
|
2013-12-06 01:22:55 +05:30
|
|
|
private slots:
|
2013-12-25 02:30:07 +05:30
|
|
|
void updateCheckFinished(bool notifyNoUpdate);
|
2013-12-06 01:22:55 +05:30
|
|
|
void updateCheckFailed();
|
|
|
|
|
2014-07-14 04:27:54 +05:30
|
|
|
void chanListDownloadFinished(bool notifyNoUpdate);
|
2015-04-26 17:17:14 +05:30
|
|
|
void chanListDownloadFailed(QString reason);
|
2013-12-06 01:22:55 +05:30
|
|
|
|
2013-12-05 00:04:12 +05:30
|
|
|
private:
|
2013-12-14 23:49:14 +05:30
|
|
|
friend class UpdateCheckerTest;
|
|
|
|
|
2013-12-05 00:04:12 +05:30
|
|
|
NetJobPtr indexJob;
|
2016-05-28 23:24:17 +05:30
|
|
|
QByteArray indexData;
|
2013-12-05 00:04:12 +05:30
|
|
|
NetJobPtr chanListJob;
|
2016-05-28 23:24:17 +05:30
|
|
|
QByteArray chanlistData;
|
2013-12-05 00:04:12 +05:30
|
|
|
|
|
|
|
QString m_channelListUrl;
|
|
|
|
|
|
|
|
QList<ChannelListEntry> m_channels;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* True while the system is checking for updates.
|
|
|
|
* If checkForUpdate is called while this is true, it will be ignored.
|
|
|
|
*/
|
2016-05-28 23:24:17 +05:30
|
|
|
bool m_updateChecking = false;
|
2013-12-05 00:04:12 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* True if the channel list has loaded.
|
|
|
|
* If this is false, trying to check for updates will call updateChanList first.
|
|
|
|
*/
|
2016-05-28 23:24:17 +05:30
|
|
|
bool m_chanListLoaded = false;
|
2013-12-05 00:04:12 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* Set to true while the channel list is currently loading.
|
|
|
|
*/
|
2016-05-28 23:24:17 +05:30
|
|
|
bool m_chanListLoading = false;
|
2013-12-05 00:04:12 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-05-28 23:24:17 +05:30
|
|
|
bool m_checkUpdateWaiting = false;
|
2015-01-31 21:29:03 +05:30
|
|
|
|
|
|
|
/*!
|
|
|
|
* if m_checkUpdateWaiting, this is the last used update channel
|
|
|
|
*/
|
|
|
|
QString m_deferredUpdateChannel;
|
2015-02-08 22:26:14 +05:30
|
|
|
|
2015-01-31 21:29:03 +05:30
|
|
|
int m_currentBuild = -1;
|
2015-02-08 22:26:14 +05:30
|
|
|
QString m_currentChannel;
|
|
|
|
QString m_currentRepoUrl;
|
|
|
|
|
|
|
|
QString m_newRepoUrl;
|
2013-12-05 00:04:12 +05:30
|
|
|
};
|
|
|
|
|