2023-05-31 07:03:44 +01:00
|
|
|
// SPDX-FileCopyrightText: 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prism Launcher - Minecraft Launcher
|
|
|
|
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
|
|
|
*
|
|
|
|
* This program is free 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, version 3.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QFlag>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QLocalSocket>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <memory>
|
2023-06-26 00:10:06 +01:00
|
|
|
#include <optional>
|
2023-05-31 07:03:44 +01:00
|
|
|
|
2023-06-02 23:15:25 +01:00
|
|
|
#include "QObjectPtr.h"
|
|
|
|
#include "net/Download.h"
|
|
|
|
|
2023-05-31 07:03:44 +01:00
|
|
|
#define PRISM_EXTERNAL_EXE
|
|
|
|
#include "FileSystem.h"
|
|
|
|
|
2023-06-25 22:21:55 +01:00
|
|
|
#include "GitHubRelease.h"
|
2023-05-31 07:03:44 +01:00
|
|
|
|
2023-06-01 22:55:20 +01:00
|
|
|
class PrismUpdaterApp : public QApplication {
|
2023-05-31 07:03:44 +01:00
|
|
|
// friends for the purpose of limiting access to deprecated stuff
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
enum Status { Starting, Failed, Succeeded, Initialized, Aborted };
|
2023-06-01 22:55:20 +01:00
|
|
|
PrismUpdaterApp(int& argc, char** argv);
|
|
|
|
virtual ~PrismUpdaterApp();
|
2023-05-31 07:03:44 +01:00
|
|
|
void loadReleaseList();
|
|
|
|
void run();
|
|
|
|
Status status() const { return m_status; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
void fail(const QString& reason);
|
|
|
|
void abort(const QString& reason);
|
|
|
|
void showFatalErrorMessage(const QString& title, const QString& content);
|
|
|
|
|
2023-06-24 13:02:48 +01:00
|
|
|
bool loadPrismVersionFromExe(const QString& exe_path);
|
2023-06-02 23:15:25 +01:00
|
|
|
|
2023-05-31 07:03:44 +01:00
|
|
|
void downloadReleasePage(const QString& api_url, int page);
|
2023-06-19 06:34:23 +01:00
|
|
|
int parseReleasePage(const QByteArray* response);
|
2023-06-04 02:41:54 +01:00
|
|
|
|
2023-05-31 07:03:44 +01:00
|
|
|
bool needUpdate(const GitHubRelease& release);
|
2023-06-04 02:41:54 +01:00
|
|
|
|
|
|
|
GitHubRelease getLatestRelease();
|
2023-05-31 07:03:44 +01:00
|
|
|
GitHubRelease selectRelease();
|
|
|
|
QList<GitHubRelease> newerReleases();
|
|
|
|
QList<GitHubRelease> nonDraftReleases();
|
|
|
|
|
2023-06-04 02:41:54 +01:00
|
|
|
void printReleases();
|
|
|
|
|
|
|
|
QList<GitHubReleaseAsset> validReleaseArtifacts(const GitHubRelease& release);
|
|
|
|
GitHubReleaseAsset selectAsset(const QList<GitHubReleaseAsset>& assets);
|
|
|
|
void performUpdate(const GitHubRelease& release);
|
2023-06-05 04:58:28 +01:00
|
|
|
void performInstall(QFileInfo file);
|
|
|
|
void unpackAndInstall(QFileInfo file);
|
|
|
|
void backupAppDir();
|
2023-06-19 06:34:23 +01:00
|
|
|
std::optional<QDir> unpackArchive(QFileInfo file);
|
2023-06-04 02:41:54 +01:00
|
|
|
|
|
|
|
QFileInfo downloadAsset(const GitHubReleaseAsset& asset);
|
2023-06-24 13:02:48 +01:00
|
|
|
bool callAppImageUpdate();
|
|
|
|
|
2023-06-25 06:21:16 +01:00
|
|
|
void moveAndFinishUpdate(QDir target);
|
2023-06-04 02:41:54 +01:00
|
|
|
|
2023-06-02 23:15:25 +01:00
|
|
|
public slots:
|
|
|
|
void downloadError(QString reason);
|
|
|
|
|
|
|
|
private:
|
2023-05-31 07:03:44 +01:00
|
|
|
const QString& root() { return m_rootPath; }
|
|
|
|
|
2023-06-05 04:58:28 +01:00
|
|
|
bool isPortable() { return m_isPortable; }
|
2023-05-31 07:03:44 +01:00
|
|
|
|
2023-06-19 06:34:23 +01:00
|
|
|
void clearUpdateLog();
|
|
|
|
void logUpdate(const QString& msg);
|
|
|
|
|
2023-05-31 07:03:44 +01:00
|
|
|
QString m_rootPath;
|
2023-06-19 06:34:23 +01:00
|
|
|
QString m_dataPath;
|
2023-06-05 04:58:28 +01:00
|
|
|
bool m_isPortable = false;
|
|
|
|
bool m_isAppimage = false;
|
|
|
|
bool m_isFlatpak = false;
|
2023-06-04 02:41:54 +01:00
|
|
|
QString m_appimagePath;
|
2023-05-31 07:03:44 +01:00
|
|
|
QString m_prismExecutable;
|
|
|
|
QUrl m_prismRepoUrl;
|
|
|
|
Version m_userSelectedVersion;
|
|
|
|
bool m_checkOnly;
|
|
|
|
bool m_forceUpdate;
|
|
|
|
bool m_printOnly;
|
2023-06-05 04:58:28 +01:00
|
|
|
bool m_selectUI;
|
2023-05-31 07:03:44 +01:00
|
|
|
bool m_allowDowngrade;
|
|
|
|
|
2023-06-25 06:21:16 +01:00
|
|
|
QString m_updateLogPath;
|
|
|
|
|
2023-05-31 07:03:44 +01:00
|
|
|
QString m_prismBinaryName;
|
2023-06-19 06:34:23 +01:00
|
|
|
QString m_prismVersion;
|
2023-06-24 13:02:48 +01:00
|
|
|
int m_prismVersionMajor = -1;
|
|
|
|
int m_prismVersionMinor = -1;
|
2023-05-31 07:03:44 +01:00
|
|
|
QString m_prsimVersionChannel;
|
|
|
|
QString m_prismGitCommit;
|
|
|
|
|
2023-06-19 06:34:23 +01:00
|
|
|
GitHubRelease m_install_release;
|
|
|
|
|
2023-05-31 07:03:44 +01:00
|
|
|
Status m_status = Status::Starting;
|
2023-06-02 23:15:25 +01:00
|
|
|
shared_qobject_ptr<QNetworkAccessManager> m_network;
|
|
|
|
QString m_current_url;
|
|
|
|
Task::Ptr m_current_task;
|
2023-05-31 07:03:44 +01:00
|
|
|
QList<GitHubRelease> m_releases;
|
|
|
|
|
|
|
|
public:
|
|
|
|
std::unique_ptr<QFile> logFile;
|
|
|
|
bool logToConsole = false;
|
|
|
|
|
|
|
|
#if defined Q_OS_WIN32
|
|
|
|
// used on Windows to attach the standard IO streams
|
|
|
|
bool consoleAttached = false;
|
|
|
|
#endif
|
|
|
|
};
|