From e38adf6006e36928af92b317a1605eee063d70ed Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Thu, 29 Jun 2023 14:01:11 -0700 Subject: [PATCH] fix(updater) fixes form first round of testing - reset update time after check Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- buildconfig/BuildConfig.cpp.in | 7 ++- launcher/Application.cpp | 40 +++++++++++----- launcher/Application.h | 3 ++ launcher/ui/MainWindow.cpp | 8 ++-- launcher/updater/PrismExternalUpdater.cpp | 46 +++++++++++++++++-- .../updater/prismupdater/PrismUpdater.cpp | 21 +++++++-- 6 files changed, 95 insertions(+), 30 deletions(-) diff --git a/buildconfig/BuildConfig.cpp.in b/buildconfig/BuildConfig.cpp.in index e8e8a4ef8..b1c9b5bef 100644 --- a/buildconfig/BuildConfig.cpp.in +++ b/buildconfig/BuildConfig.cpp.in @@ -77,6 +77,8 @@ Config::Config() if (BUILD_PLATFORM == "macOS" && !MAC_SPARKLE_PUB_KEY.isEmpty() && !MAC_SPARKLE_APPCAST_URL.isEmpty()) { UPDATER_ENABLED = true; + } else if(!UPDATER_GITHUB_REPO.isEmpty() && !BUILD_ARTIFACT.isEmpty()) { + UPDATER_ENABLED = true; } GIT_COMMIT = "@Launcher_GIT_COMMIT@"; @@ -97,10 +99,7 @@ Config::Config() if (GIT_REFSPEC.startsWith("refs/heads/")) { VERSION_CHANNEL = GIT_REFSPEC; - VERSION_CHANNEL.remove("refs/heads/"); - if(!UPDATER_GITHUB_REPO.isEmpty() && !BUILD_PLATFORM.isEmpty()) { - UPDATER_ENABLED = true; - } + VERSION_CHANNEL.remove("refs/heads/"); } else if (!GIT_COMMIT.isEmpty()) { diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 1a381a045..c59bea8d6 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -584,6 +584,8 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) qDebug() << "Git refspec : " << BuildConfig.GIT_REFSPEC; qDebug() << "Compiled for : " << BuildConfig.systemID(); qDebug() << "Compiled by : " << BuildConfig.compilerID(); + qDebug() << "Build Artifact : " << BuildConfig.BUILD_ARTIFACT; + qDebug() << "Updates Enabeled : " << (updaterEnabled() ? "Yes" : "No"); if (adjustedBy.size()) { qDebug() << "Work dir before adjustment : " << origcwdPath; qDebug() << "Work dir after adjustment : " << QDir::currentPath(); @@ -856,18 +858,12 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) } // initialize the updater - if (BuildConfig.UPDATER_ENABLED) { + if (updaterEnabled()) { qDebug() << "Initializing updater"; #ifdef Q_OS_MAC m_updater.reset(new MacSparkleUpdater()); #else - auto exe_name = QStringLiteral("%1_updater").arg(BuildConfig.LAUNCHER_APP_BINARY_NAME); -#if defined Q_OS_WIN32 - exe_name.append(".exe"); -#endif - auto updater_binary = QFileInfo(QDir(m_rootPath).absoluteFilePath(exe_name)); - if (updater_binary.isFile()) - m_updater.reset(new PrismExternalUpdater(m_rootPath, m_dataPath)); + m_updater.reset(new PrismExternalUpdater(applicationDirPath(), m_dataPath)); #endif qDebug() << "<> Updater started."; } @@ -1000,6 +996,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) msgBox.setDefaultButton(QMessageBox::Abort); msgBox.setModal(true); msgBox.setDetailedText(FS::read(update_log_path)); + msgBox.adjustSize(); auto res = msgBox.exec(); switch (res) { case QMessageBox::Ignore: { @@ -1030,6 +1027,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) msgBox.setDefaultButton(QMessageBox::Abort); msgBox.setModal(true); msgBox.setDetailedText(FS::read(update_log_path)); + msgBox.adjustSize(); auto res = msgBox.exec(); switch (res) { case QMessageBox::Ignore: { @@ -1056,10 +1054,12 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) "for details.") .arg(BuildConfig.printableVersionString()) .arg(update_log_path); - auto msgBox = QMessageBox(QMessageBox::Information, tr("Update Succeeded"), infoMsg, QMessageBox::Ok); - msgBox.setDefaultButton(QMessageBox::Ok); - msgBox.setDetailedText(FS::read(update_log_path)); - msgBox.exec(); + auto msgBox = new QMessageBox(QMessageBox::Information, tr("Update Succeeded"), infoMsg, QMessageBox::Ok); + msgBox->setDefaultButton(QMessageBox::Ok); + msgBox->setDetailedText(FS::read(update_log_path)); + msgBox->setAttribute(Qt::WA_DeleteOnClose); + msgBox->adjustSize(); + msgBox->open(); FS::deletePath(update_success_marker.absoluteFilePath()); } } @@ -1127,6 +1127,22 @@ bool Application::createSetupWizard() return false; } +bool Application::updaterEnabled() { +#if defined(Q_OS_MAC) + return BuildConfig.UPDATER_ENABLED; +#else + return BuildConfig.UPDATER_ENABLED && QFileInfo(updaterBinaryName()).isFile(); +#endif +} + +QString Application::updaterBinaryName() { + auto exe_name = QStringLiteral("%1_updater").arg(BuildConfig.LAUNCHER_APP_BINARY_NAME); +#if defined Q_OS_WIN32 + exe_name.append(".exe"); +#endif + return exe_name; +} + bool Application::event(QEvent* event) { #ifdef Q_OS_MACOS diff --git a/launcher/Application.h b/launcher/Application.h index baf64575d..c87ee2652 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -216,6 +216,9 @@ public: int suitableMaxMem(); + bool updaterEnabled(); + QString updaterBinaryName(); + signals: void updateAllowedChanged(bool status); void globalSettingsAboutToOpen(); diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 496738e32..16d696dc8 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -215,7 +215,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->actionDISCORD->setVisible(!BuildConfig.DISCORD_URL.isEmpty()); ui->actionREDDIT->setVisible(!BuildConfig.SUBREDDIT_URL.isEmpty()); - ui->actionCheckUpdate->setVisible(BuildConfig.UPDATER_ENABLED); + ui->actionCheckUpdate->setVisible(APPLICATION->updaterEnabled()); #ifndef Q_OS_MAC ui->actionAddToPATH->setVisible(false); @@ -388,7 +388,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi updateNewsLabel(); } - if (BuildConfig.UPDATER_ENABLED) { + if (APPLICATION->updaterEnabled()) { bool updatesAllowed = APPLICATION->updatesAreAllowed(); updatesAllowedChanged(updatesAllowed); @@ -781,7 +781,7 @@ void MainWindow::repopulateAccountsMenu() void MainWindow::updatesAllowedChanged(bool allowed) { - if(!BuildConfig.UPDATER_ENABLED) + if(!APPLICATION->updaterEnabled()) { return; } @@ -1259,7 +1259,7 @@ void MainWindow::on_actionViewCentralModsFolder_triggered() void MainWindow::checkForUpdates() { - if(BuildConfig.UPDATER_ENABLED) + if(APPLICATION->updaterEnabled()) { APPLICATION->triggerUpdateCheck(); } diff --git a/launcher/updater/PrismExternalUpdater.cpp b/launcher/updater/PrismExternalUpdater.cpp index 969897405..7f987204a 100644 --- a/launcher/updater/PrismExternalUpdater.cpp +++ b/launcher/updater/PrismExternalUpdater.cpp @@ -40,7 +40,7 @@ class PrismExternalUpdater::Private { public: - QDir appDir; + QDir binDir; QDir dataDir; QTimer updateTimer; bool allowBeta; @@ -50,10 +50,10 @@ class PrismExternalUpdater::Private { std::unique_ptr settings; }; -PrismExternalUpdater::PrismExternalUpdater(const QString& appDir, const QString& dataDir) +PrismExternalUpdater::PrismExternalUpdater(const QString& binDir, const QString& dataDir) { priv = new PrismExternalUpdater::Private(); - priv->appDir = QDir(appDir); + priv->binDir = QDir(binDir); priv->dataDir = QDir(dataDir); auto settings_file = priv->dataDir.absoluteFilePath("prismlauncher_update.cfg"); priv->settings = std::make_unique(settings_file, QSettings::Format::IniFormat); @@ -97,20 +97,42 @@ void PrismExternalUpdater::checkForUpdates() if (priv->allowBeta) args.append("--pre-release"); - proc.start(priv->appDir.absoluteFilePath(exe_name), args); + proc.start(priv->binDir.absoluteFilePath(exe_name), args); auto result_start = proc.waitForStarted(5000); if (!result_start) { auto err = proc.error(); qDebug() << "Failed to start updater after 5 seconds." << "reason:" << err << proc.errorString(); + auto msgBox = QMessageBox(QMessageBox::Information, tr("Update Check Failed"), + tr("Failed to start after 5 seconds\nReason: %1.").arg(proc.errorString())); + + msgBox.adjustSize(); + msgBox.exec(); + priv->lastCheck = QDateTime::currentDateTime(); + priv->settings->setValue("last_check", priv->lastCheck.toString(Qt::ISODate)); + priv->settings->sync(); + resetAutoCheckTimer(); + return; } QCoreApplication::processEvents(); auto result_finished = proc.waitForFinished(60000); if (!result_finished) { + proc.kill(); auto err = proc.error(); + auto output = proc.readAll(); qDebug() << "Updater failed to close after 60 seconds." << "reason:" << err << proc.errorString(); + auto msgBox = QMessageBox(QMessageBox::Information, tr("Update Check Failed"), + tr("Updater failed to close 60 seconds\nReason: %1.").arg(proc.errorString())); + msgBox.setDetailedText(output); + msgBox.adjustSize(); + msgBox.exec(); + priv->lastCheck = QDateTime::currentDateTime(); + priv->settings->setValue("last_check", priv->lastCheck.toString(Qt::ISODate)); + priv->settings->sync(); + resetAutoCheckTimer(); + return; } auto exit_code = proc.exitCode(); @@ -127,6 +149,8 @@ void PrismExternalUpdater::checkForUpdates() { qDebug() << "No update available"; auto msgBox = QMessageBox(QMessageBox::Information, tr("No Update Available"), tr("You are running the latest version.")); + + msgBox.adjustSize(); msgBox.exec(); } break; @@ -137,6 +161,8 @@ void PrismExternalUpdater::checkForUpdates() auto msgBox = QMessageBox(QMessageBox::Warning, tr("Update Check Error"), tr("There was an error running the update check.")); msgBox.setDetailedText(std_error); + + msgBox.adjustSize(); msgBox.exec(); } break; @@ -159,11 +185,19 @@ void PrismExternalUpdater::checkForUpdates() // unknown error code { qDebug() << "Updater exited with unknown code" << exit_code; + auto msgBox = QMessageBox(QMessageBox::Information, tr("Unknown Update Error"), + tr("The updater exited with an unknown condition.\nExit Code: %1").arg(exit_code)); + auto detail_txt = tr("StdOut: %1\nStdErr: %2").arg(std_output).arg(std_error); + msgBox.setDetailedText(detail_txt); + + msgBox.adjustSize(); + msgBox.exec(); } } priv->lastCheck = QDateTime::currentDateTime(); priv->settings->setValue("last_check", priv->lastCheck.toString(Qt::ISODate)); priv->settings->sync(); + resetAutoCheckTimer(); } bool PrismExternalUpdater::getAutomaticallyChecksForUpdates() @@ -247,6 +281,8 @@ void PrismExternalUpdater::offerUpdate(const QString& version_name, const QStrin if (should_skip) { auto msgBox = QMessageBox(QMessageBox::Information, tr("No Update Available"), tr("There are no new updates available.")); + + msgBox.adjustSize(); msgBox.exec(); return; } @@ -285,7 +321,7 @@ void PrismExternalUpdater::performUpdate(const QString& version_tag) if (priv->allowBeta) args.append("--pre-release"); - auto result = proc.startDetached(priv->appDir.absoluteFilePath(exe_name), args); + auto result = proc.startDetached(priv->binDir.absoluteFilePath(exe_name), args); if (!result) { qDebug() << "Failed to start updater:" << proc.error() << proc.errorString(); } diff --git a/launcher/updater/prismupdater/PrismUpdater.cpp b/launcher/updater/prismupdater/PrismUpdater.cpp index ef7e505b9..1859d5262 100644 --- a/launcher/updater/prismupdater/PrismUpdater.cpp +++ b/launcher/updater/prismupdater/PrismUpdater.cpp @@ -350,14 +350,14 @@ PrismUpdaterApp::PrismUpdaterApp(int& argc, char** argv) : QApplication(argc, ar { // setup logging static const QString baseLogFile = BuildConfig.LAUNCHER_NAME + "Updater" + (m_checkOnly ? "-CheckOnly" : "") + "-%0.log"; - static const QString logBase = FS::PathCombine("logs", baseLogFile); + static const QString logBase = FS::PathCombine(m_dataPath, "logs", baseLogFile); auto moveFile = [](const QString& oldName, const QString& newName) { QFile::remove(newName); QFile::copy(oldName, newName); QFile::remove(oldName); }; - if (FS::ensureFolderPathExists("logs")) { + if (FS::ensureFolderPathExists("logs")) { // enough history to track both launches of the updater during a portable install moveFile(logBase.arg(1), logBase.arg(2)); moveFile(logBase.arg(0), logBase.arg(1)); } @@ -442,6 +442,7 @@ PrismUpdaterApp::PrismUpdaterApp(int& argc, char** argv) : QApplication(argc, ar qDebug() << "Git refspec : " << BuildConfig.GIT_REFSPEC; qDebug() << "Compiled for : " << BuildConfig.systemID(); qDebug() << "Compiled by : " << BuildConfig.compilerID(); + qDebug() << "Build Artifact : " << BuildConfig.BUILD_ARTIFACT; if (adjustedBy.size()) { qDebug() << "Data dir before adjustment : " << origCwdPath; qDebug() << "Data dir after adjustment : " << m_dataPath; @@ -521,6 +522,7 @@ void PrismUpdaterApp::showFatalErrorMessage(const QString& title, const QString& msgBox->setDefaultButton(QMessageBox::Ok); msgBox->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextBrowserInteraction); msgBox->setIcon(QMessageBox::Critical); + msgBox->adjustSize(); msgBox->exec(); exit(1); } @@ -658,6 +660,7 @@ void PrismUpdaterApp::moveAndFinishUpdate(QDir target) QProgressDialog progress(tr("Backing up install at %1").arg(applicationDirPath()), "", 0, file_list.length()); progress.setCancelButton(nullptr); + progress.adjustSize(); progress.show(); QCoreApplication::processEvents(); @@ -766,10 +769,13 @@ QList PrismUpdaterApp::validReleaseArtifacts(const GitHubRel if (BuildConfig.BUILD_ARTIFACT.isEmpty()) qWarning() << "Build platform is not set!"; for (auto asset : release.assets) { - if (!m_isAppimage && asset.name.toLower().endsWith("appimage")) + if (!m_isAppimage && asset.name.toLower().endsWith("appimage")) { + qDebug() << "Rejecting" << asset.name << "because it is an AppImage"; continue; - else if (m_isAppimage && !asset.name.toLower().endsWith("appimage")) + } else if (m_isAppimage && !asset.name.toLower().endsWith("appimage")) { + qDebug() << "Rejecting" << asset.name << "because it is not an AppImage"; continue; + } auto asset_name = asset.name.toLower(); auto platform = BuildConfig.BUILD_ARTIFACT.toLower(); auto system_is_arm = QSysInfo::buildCpuArchitecture().contains("arm64"); @@ -786,6 +792,8 @@ QList PrismUpdaterApp::validReleaseArtifacts(const GitHubRel for_platform = false; if (((m_isPortable && for_portable) || (!m_isPortable && !for_portable)) && for_platform) { + qDebug() << "Rejecting" << asset.name << "|" + << "For Platform:" << (for_platform ? "Yes" : "No") << "For Portable:" << (for_portable ? "Yes" : "No"); valid.append(asset); } } @@ -849,6 +857,7 @@ QFileInfo PrismUpdaterApp::downloadAsset(const GitHubReleaseAsset& asset) auto download = Net::Download::makeFile(file_url, out_file_path); download->setNetwork(m_network); auto progress_dialog = ProgressDialog(); + progress_dialog.adjustSize(); if (progress_dialog.execWithTask(download.get()) == QDialog::Rejected) showFatalErrorMessage(tr("Download Aborted"), tr("Download of %1 aborted by user").arg(file_url.toString())); @@ -954,6 +963,7 @@ void PrismUpdaterApp::performInstall(QFileInfo file) msgBox.setInformativeText(infoMsg); msgBox.setStandardButtons(QMessageBox::Ignore | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Cancel); + msgBox.adjustSize(); switch (msgBox.exec()) { case QMessageBox::AcceptRole: break; @@ -971,7 +981,7 @@ void PrismUpdaterApp::performInstall(QFileInfo file) logUpdate(tr("Updating from %1 to %2").arg(m_prismVersion).arg(m_install_release.tag_name)); if (m_isPortable || file.suffix().toLower() == "zip") { write_lock_file(update_lock_path, QDateTime::currentDateTime(), m_prismVersion, m_install_release.tag_name, applicationDirPath(), - m_dataPath); + m_dataPath); logUpdate(tr("Updating portable install at %1").arg(applicationDirPath())); unpackAndInstall(file); } else { @@ -1065,6 +1075,7 @@ void PrismUpdaterApp::backupAppDir() QProgressDialog progress(tr("Backing up install at %1").arg(applicationDirPath()), "", 0, file_list.length()); progress.setCancelButton(nullptr); + progress.adjustSize(); progress.show(); QCoreApplication::processEvents(); int i = 0;