refactor: rename app class

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers 2023-06-01 14:55:20 -07:00
parent 5627b4a9c5
commit f619a04fe7
6 changed files with 49 additions and 49 deletions

View File

@ -567,12 +567,12 @@ set(LINKEXE_SOURCES
DesktopServices.cpp DesktopServices.cpp
) )
set(WINDOWSUPDATEREXE_SOURCES set(PRISMUPDATER_SOURCES
updater/windows/WindowsUpdater.h updater/prismupdater/PrismUpdater.h
updater/windows/WindowsUpdater.cpp updater/prismupdater/PrismUpdater.cpp
updater/windows/UpdaterDialogs.h updater/prismupdater/UpdaterDialogs.h
updater/windows/UpdaterDialogs.cpp updater/prismupdater/UpdaterDialogs.cpp
updater/windows/GitHubRelease.h updater/prismupdater/GitHubRelease.h
Json.h Json.h
Json.cpp Json.cpp
FileSystem.h FileSystem.h
@ -1094,8 +1094,8 @@ qt_add_resources(LAUNCHER_RESOURCES
../${Launcher_Branding_LogoQRC} ../${Launcher_Branding_LogoQRC}
) )
qt_wrap_ui(WINDOWSUPDATER_UI qt_wrap_ui(PRISMUPDATER_UI
updater/windows/SelectReleaseDialog.ui updater/prismupdater/SelectReleaseDialog.ui
) )
######## Windows resource files ######## ######## Windows resource files ########
@ -1183,9 +1183,9 @@ install(TARGETS ${Launcher_Name}
if(WIN32 OR (DEFINED Launcher_BUILD_UPDATER AND Launcher_BUILD_UPDATER) ) if(WIN32 OR (DEFINED Launcher_BUILD_UPDATER AND Launcher_BUILD_UPDATER) )
# Updater # Updater
add_library(windows_updater_logic STATIC ${WINDOWSUPDATEREXE_SOURCES} ${WINDOWSUPDATER_UI}) add_library(prism_updater_logic STATIC ${PRISMUPDATER_SOURCES} ${PRISMUPDATER_UI})
target_include_directories(windows_updater_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(prism_updater_logic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(windows_updater_logic target_link_libraries(prism_updater_logic
systeminfo systeminfo
BuildConfig BuildConfig
ghcFilesystem::ghc_filesystem ghcFilesystem::ghc_filesystem
@ -1196,8 +1196,8 @@ if(WIN32 OR (DEFINED Launcher_BUILD_UPDATER AND Launcher_BUILD_UPDATER) )
cmark::cmark cmark::cmark
) )
add_executable("${Launcher_Name}_updater" WIN32 updater/windows/windows_main.cpp) add_executable("${Launcher_Name}_updater" WIN32 updater/prismupdater/updater_main.cpp)
target_link_libraries("${Launcher_Name}_updater" windows_updater_logic) target_link_libraries("${Launcher_Name}_updater" prism_updater_logic)
if(DEFINED Launcher_APP_BINARY_NAME) if(DEFINED Launcher_APP_BINARY_NAME)
set_target_properties("${Launcher_Name}_updater" PROPERTIES OUTPUT_NAME "${Launcher_APP_BINARY_NAME}_updater") set_target_properties("${Launcher_Name}_updater" PROPERTIES OUTPUT_NAME "${Launcher_APP_BINARY_NAME}_updater")
@ -1229,7 +1229,7 @@ if(WIN32 OR (DEFINED Launcher_BUILD_FILELINKER AND Launcher_BUILD_FILELINKER))
${Launcher_QT_LIBS} ${Launcher_QT_LIBS}
) )
add_executable("${Launcher_Name}_filelink" WIN32 filelink/main.cpp) add_executable("${Launcher_Name}_filelink" WIN32 filelink/filelink_main.cpp)
target_sources("${Launcher_Name}_filelink" PRIVATE filelink/filelink.exe.manifest) target_sources("${Launcher_Name}_filelink" PRIVATE filelink/filelink.exe.manifest)

View File

@ -20,7 +20,7 @@
* *
*/ */
#include "WindowsUpdater.h" #include "PrismUpdater.h"
#include "BuildConfig.h" #include "BuildConfig.h"
#include <cstdlib> #include <cstdlib>
@ -68,7 +68,7 @@ namespace fs = ghc::filesystem;
#include <DesktopServices.h> #include <DesktopServices.h>
#include "UpdaterDialogs.h" #include "updater/prismupdater/UpdaterDialogs.h"
#include "FileSystem.h" #include "FileSystem.h"
#include "Json.h" #include "Json.h"
@ -83,7 +83,7 @@ void appDebugOutput(QtMsgType type, const QMessageLogContext& context, const QSt
QString out = qFormatLogMessage(type, context, msg); QString out = qFormatLogMessage(type, context, msg);
out += QChar::LineFeed; out += QChar::LineFeed;
WindowsUpdaterApp* app = static_cast<WindowsUpdaterApp*>(QCoreApplication::instance()); PrismUpdaterApp* app = static_cast<PrismUpdaterApp*>(QCoreApplication::instance());
app->logFile->write(out.toUtf8()); app->logFile->write(out.toUtf8());
app->logFile->flush(); app->logFile->flush();
if (app->logToConsole) { if (app->logToConsole) {
@ -92,7 +92,7 @@ void appDebugOutput(QtMsgType type, const QMessageLogContext& context, const QSt
} }
} }
WindowsUpdaterApp::WindowsUpdaterApp(int& argc, char** argv) : QApplication(argc, argv) PrismUpdaterApp::PrismUpdaterApp(int& argc, char** argv) : QApplication(argc, argv)
{ {
#if defined Q_OS_WIN32 #if defined Q_OS_WIN32
// attach the parent console // attach the parent console
@ -313,7 +313,7 @@ WindowsUpdaterApp::WindowsUpdaterApp(int& argc, char** argv) : QApplication(argc
loadReleaseList(); loadReleaseList();
} }
WindowsUpdaterApp::~WindowsUpdaterApp() PrismUpdaterApp::~PrismUpdaterApp()
{ {
qDebug() << "updater shutting down"; qDebug() << "updater shutting down";
// Shut down logger by setting the logger function to nothing // Shut down logger by setting the logger function to nothing
@ -334,21 +334,21 @@ WindowsUpdaterApp::~WindowsUpdaterApp()
m_reply->deleteLater(); m_reply->deleteLater();
} }
void WindowsUpdaterApp::fail(const QString& reason) void PrismUpdaterApp::fail(const QString& reason)
{ {
qCritical() << qPrintable(reason); qCritical() << qPrintable(reason);
m_status = Failed; m_status = Failed;
exit(1); exit(1);
} }
void WindowsUpdaterApp::abort(const QString& reason) void PrismUpdaterApp::abort(const QString& reason)
{ {
qCritical() << qPrintable(reason); qCritical() << qPrintable(reason);
m_status = Aborted; m_status = Aborted;
exit(2); exit(2);
} }
void WindowsUpdaterApp::showFatalErrorMessage(const QString& title, const QString& content) void PrismUpdaterApp::showFatalErrorMessage(const QString& title, const QString& content)
{ {
m_status = Failed; m_status = Failed;
auto msgBox = new QMessageBox(); auto msgBox = new QMessageBox();
@ -362,7 +362,7 @@ void WindowsUpdaterApp::showFatalErrorMessage(const QString& title, const QStrin
exit(1); exit(1);
} }
void WindowsUpdaterApp::run() void PrismUpdaterApp::run()
{ {
qDebug() << "found" << m_releases.length() << "releases on github"; qDebug() << "found" << m_releases.length() << "releases on github";
qDebug() << "loading exe at " << m_prismExecutable; qDebug() << "loading exe at " << m_prismExecutable;
@ -424,14 +424,14 @@ void WindowsUpdaterApp::run()
exit(0); exit(0);
} }
void WindowsUpdaterApp::printReleases() void PrismUpdaterApp::printReleases()
{ {
for (auto release : m_releases) { for (auto release : m_releases) {
std::cout << release.name.toStdString() << " Version: " << release.tag_name.toStdString() << std::endl; std::cout << release.name.toStdString() << " Version: " << release.tag_name.toStdString() << std::endl;
} }
} }
QList<GitHubRelease> WindowsUpdaterApp::nonDraftReleases() QList<GitHubRelease> PrismUpdaterApp::nonDraftReleases()
{ {
QList<GitHubRelease> nonDraft; QList<GitHubRelease> nonDraft;
for (auto rls : m_releases) { for (auto rls : m_releases) {
@ -441,7 +441,7 @@ QList<GitHubRelease> WindowsUpdaterApp::nonDraftReleases()
return nonDraft; return nonDraft;
} }
QList<GitHubRelease> WindowsUpdaterApp::newerReleases() QList<GitHubRelease> PrismUpdaterApp::newerReleases()
{ {
QList<GitHubRelease> newer; QList<GitHubRelease> newer;
for (auto rls : nonDraftReleases()) { for (auto rls : nonDraftReleases()) {
@ -451,7 +451,7 @@ QList<GitHubRelease> WindowsUpdaterApp::newerReleases()
return newer; return newer;
} }
GitHubRelease WindowsUpdaterApp::selectRelease() GitHubRelease PrismUpdaterApp::selectRelease()
{ {
QList<GitHubRelease> releases; QList<GitHubRelease> releases;
@ -475,12 +475,12 @@ GitHubRelease WindowsUpdaterApp::selectRelease()
return release; return release;
} }
void WindowsUpdaterApp::performUpdate(const GitHubRelease& release) void PrismUpdaterApp::performUpdate(const GitHubRelease& release)
{ {
qDebug() << "Updating to" << release.tag_name; qDebug() << "Updating to" << release.tag_name;
} }
void WindowsUpdaterApp::loadPrismVersionFromExe(const QString& exe_path) void PrismUpdaterApp::loadPrismVersionFromExe(const QString& exe_path)
{ {
QProcess proc = QProcess(); QProcess proc = QProcess();
proc.start(exe_path, { "-v" }); proc.start(exe_path, { "-v" });
@ -509,7 +509,7 @@ void WindowsUpdaterApp::loadPrismVersionFromExe(const QString& exe_path)
m_prismGitCommit = lines.takeFirst().simplified(); m_prismGitCommit = lines.takeFirst().simplified();
} }
void WindowsUpdaterApp::loadReleaseList() void PrismUpdaterApp::loadReleaseList()
{ {
auto github_repo = m_prismRepoUrl; auto github_repo = m_prismRepoUrl;
if (github_repo.host() != "github.com") if (github_repo.host() != "github.com")
@ -526,7 +526,7 @@ void WindowsUpdaterApp::loadReleaseList()
downloadReleasePage(api_url, 1); downloadReleasePage(api_url, 1);
} }
void WindowsUpdaterApp::downloadReleasePage(const QString& api_url, int page) void PrismUpdaterApp::downloadReleasePage(const QString& api_url, int page)
{ {
int per_page = 30; int per_page = 30;
auto page_url = QString("%1?per_page=%2&page=%3").arg(api_url).arg(QString::number(per_page)).arg(QString::number(page)); auto page_url = QString("%1?per_page=%2&page=%3").arg(api_url).arg(QString::number(per_page)).arg(QString::number(page));
@ -549,18 +549,18 @@ void WindowsUpdaterApp::downloadReleasePage(const QString& api_url, int page)
} }
}); });
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) // QNetworkReply::errorOccurred added in 5.15
connect(rep, &QNetworkReply::errorOccurred, this, &WindowsUpdaterApp::downloadError); connect(rep, &QNetworkReply::errorOccurred, this, &PrismUpdaterApp::downloadError);
#else #else
connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &WindowsUpdaterApp::downloadError); connect(rep, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &WindowsUpdaterApp::downloadError);
#endif #endif
connect(rep, &QNetworkReply::sslErrors, this, &WindowsUpdaterApp::sslErrors); connect(rep, &QNetworkReply::sslErrors, this, &PrismUpdaterApp::sslErrors);
connect(rep, &QNetworkReply::readyRead, this, [this, responce]() { connect(rep, &QNetworkReply::readyRead, this, [this, responce]() {
auto data = m_reply->readAll(); auto data = m_reply->readAll();
responce->append(data); responce->append(data);
}); });
} }
int WindowsUpdaterApp::parseReleasePage(const QByteArray* responce) int PrismUpdaterApp::parseReleasePage(const QByteArray* responce)
{ {
if (responce->isEmpty()) // empty page if (responce->isEmpty()) // empty page
return 0; return 0;
@ -607,7 +607,7 @@ int WindowsUpdaterApp::parseReleasePage(const QByteArray* responce)
return num_releases; return num_releases;
} }
GitHubRelease WindowsUpdaterApp::getLatestRelease() GitHubRelease PrismUpdaterApp::getLatestRelease()
{ {
GitHubRelease latest; GitHubRelease latest;
for (auto release : m_releases) { for (auto release : m_releases) {
@ -618,13 +618,13 @@ GitHubRelease WindowsUpdaterApp::getLatestRelease()
return latest; return latest;
} }
bool WindowsUpdaterApp::needUpdate(const GitHubRelease& release) bool PrismUpdaterApp::needUpdate(const GitHubRelease& release)
{ {
auto current_ver = Version(QString("%1.%2").arg(QString::number(m_prismVersionMajor)).arg(QString::number(m_prismVersionMinor))); auto current_ver = Version(QString("%1.%2").arg(QString::number(m_prismVersionMajor)).arg(QString::number(m_prismVersionMinor)));
return current_ver < release.version; return current_ver < release.version;
} }
void WindowsUpdaterApp::downloadError(QNetworkReply::NetworkError error) void PrismUpdaterApp::downloadError(QNetworkReply::NetworkError error)
{ {
if (error == QNetworkReply::OperationCanceledError) { if (error == QNetworkReply::OperationCanceledError) {
abort(QString("Aborted %1").arg(m_reply->url().toString())); abort(QString("Aborted %1").arg(m_reply->url().toString()));
@ -633,7 +633,7 @@ void WindowsUpdaterApp::downloadError(QNetworkReply::NetworkError error)
} }
} }
void WindowsUpdaterApp::sslErrors(const QList<QSslError>& errors) void PrismUpdaterApp::sslErrors(const QList<QSslError>& errors)
{ {
int i = 1; int i = 1;
QString err_msg; QString err_msg;

View File

@ -39,15 +39,15 @@
#define PRISM_EXTERNAL_EXE #define PRISM_EXTERNAL_EXE
#include "FileSystem.h" #include "FileSystem.h"
#include "updater/windows/GitHubRelease.h" #include "updater/prismupdater/GitHubRelease.h"
class WindowsUpdaterApp : public QApplication { class PrismUpdaterApp : public QApplication {
// friends for the purpose of limiting access to deprecated stuff // friends for the purpose of limiting access to deprecated stuff
Q_OBJECT Q_OBJECT
public: public:
enum Status { Starting, Failed, Succeeded, Initialized, Aborted }; enum Status { Starting, Failed, Succeeded, Initialized, Aborted };
WindowsUpdaterApp(int& argc, char** argv); PrismUpdaterApp(int& argc, char** argv);
virtual ~WindowsUpdaterApp(); virtual ~PrismUpdaterApp();
void loadReleaseList(); void loadReleaseList();
void run(); void run();
Status status() const { return m_status; } Status status() const { return m_status; }

View File

@ -4,7 +4,7 @@
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include "Version.h" #include "Version.h"
#include "updater/windows/GitHubRelease.h" #include "updater/prismupdater/GitHubRelease.h"
namespace Ui { namespace Ui {
class SelectReleaseDialog; class SelectReleaseDialog;

View File

@ -22,20 +22,20 @@
#include "updater/windows/WindowsUpdater.h" #include "updater/prismupdater/PrismUpdater.h"
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
WindowsUpdaterApp wUpApp(argc, argv); PrismUpdaterApp wUpApp(argc, argv);
switch(wUpApp.status()) { switch(wUpApp.status()) {
case WindowsUpdaterApp::Starting: case PrismUpdaterApp::Starting:
case WindowsUpdaterApp::Initialized: case PrismUpdaterApp::Initialized:
{ {
return wUpApp.exec(); return wUpApp.exec();
} }
case WindowsUpdaterApp::Failed: case PrismUpdaterApp::Failed:
return 1; return 1;
case WindowsUpdaterApp::Succeeded: case PrismUpdaterApp::Succeeded:
return 0; return 0;
default: default:
return -1; return -1;