From 226e1d69e3b72d74a51cdd4110826d63c3c203be Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 14 Apr 2014 13:55:25 +0200 Subject: [PATCH] Updater things... --- src/updater/formupdater.cpp | 42 ++++++--- src/updater/formupdater.h | 1 + src/updater/main.cpp | 181 +----------------------------------- 3 files changed, 29 insertions(+), 195 deletions(-) diff --git a/src/updater/formupdater.cpp b/src/updater/formupdater.cpp index 929001255..ac1bea4ef 100644 --- a/src/updater/formupdater.cpp +++ b/src/updater/formupdater.cpp @@ -18,11 +18,13 @@ FormUpdater::FormUpdater(QWidget *parent) - : QMainWindow(parent), + : QMainWindow(parent, Qt::Dialog | Qt::WindowStaysOnTopHint), m_state(NoState), m_txtOutput(new QTextEdit(this)), m_parsedArguments(QHash()) { + m_txtOutput->setAutoFormatting(QTextEdit::AutoNone); + m_txtOutput->setAcceptRichText(true); m_txtOutput->setFontPointSize(10.0); m_txtOutput->setReadOnly(true); m_txtOutput->setFocusPolicy(Qt::StrongFocus); @@ -35,6 +37,9 @@ FormUpdater::FormUpdater(QWidget *parent) setCentralWidget(m_txtOutput); setWindowTitle("RSS Guard updater"); setWindowIcon(QIcon(APP_ICON_PATH)); + + qApp->setQuitOnLastWindowClosed(true); + moveToCenterAndResize(); } @@ -43,7 +48,6 @@ FormUpdater::~FormUpdater() { void FormUpdater::startUpgrade() { printHeading("Welcome to RSS Guard updater"); - printText("Analyzing updater arguments..."); if (QApplication::arguments().size() != 5) { @@ -54,18 +58,8 @@ void FormUpdater::startUpgrade() { return; } - // Obtain parameters. - QStringList arguments = QApplication::arguments(); - - m_parsedArguments["updater_path"] = QDir::toNativeSeparators(qApp->applicationFilePath()); - m_parsedArguments["current_version"] = arguments.at(1); - m_parsedArguments["next_version"] = arguments.at(2); - m_parsedArguments["rssguard_executable_path"] = QDir::toNativeSeparators(arguments.at(3)); - m_parsedArguments["rssguard_path"] = QDir::toNativeSeparators(QFileInfo(m_parsedArguments["rssguard_executable_path"]).absolutePath()); - m_parsedArguments["update_file_path"] = QDir::toNativeSeparators(arguments.at(4)); - m_parsedArguments["temp_path"] = QDir::toNativeSeparators(QFileInfo(m_parsedArguments["update_file_path"]).absolutePath()); - m_parsedArguments["output_temp_path"] = m_parsedArguments["temp_path"] + QDir::separator() + APP_LOW_NAME; - + // Process arguments. + saveArguments(); printArguments(); if (!printUpdateInformation() || !doPreparationCleanup() || !doExtractionAndCopying()) { @@ -77,13 +71,31 @@ void FormUpdater::startUpgrade() { doFinalCleanup(); + printText("Application was upgraded without serious errors."); + if (!QProcess::startDetached(m_parsedArguments["rssguard_executable_path"])) { printText("RSS Guard was not started successfully. Start it manually."); m_state = ExitError; } + else { + m_state = ExitNormal; + } printText("\nPress any key to exit updater..."); - m_state = ExitNormal; +} + +void FormUpdater::saveArguments() { + // Obtain parameters. + QStringList arguments = QApplication::arguments(); + + m_parsedArguments["updater_path"] = QDir::toNativeSeparators(qApp->applicationFilePath()); + m_parsedArguments["current_version"] = arguments.at(1); + m_parsedArguments["next_version"] = arguments.at(2); + m_parsedArguments["rssguard_executable_path"] = QDir::toNativeSeparators(arguments.at(3)); + m_parsedArguments["rssguard_path"] = QDir::toNativeSeparators(QFileInfo(m_parsedArguments["rssguard_executable_path"]).absolutePath()); + m_parsedArguments["update_file_path"] = QDir::toNativeSeparators(arguments.at(4)); + m_parsedArguments["temp_path"] = QDir::toNativeSeparators(QFileInfo(m_parsedArguments["update_file_path"]).absolutePath()); + m_parsedArguments["output_temp_path"] = m_parsedArguments["temp_path"] + QDir::separator() + APP_LOW_NAME; } void FormUpdater::printArguments() { diff --git a/src/updater/formupdater.h b/src/updater/formupdater.h index 4806eb48f..a67ec4925 100644 --- a/src/updater/formupdater.h +++ b/src/updater/formupdater.h @@ -24,6 +24,7 @@ class FormUpdater : public QMainWindow { virtual ~FormUpdater(); void startUpgrade(); + void saveArguments(); void printArguments(); bool printUpdateInformation(); bool doPreparationCleanup(); diff --git a/src/updater/main.cpp b/src/updater/main.cpp index 79ac16255..4df4d94d0 100644 --- a/src/updater/main.cpp +++ b/src/updater/main.cpp @@ -36,193 +36,14 @@ // 2) - string with future version, // 3) - path to RSS Guard ("rssguard.exe") file, // 4) - path to update file (stored in TEMP folder). -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) { // Instantiate base application object. QtSingleApplication application(APP_LOW_NAME, argc, argv); - FormUpdater main_form; main_form.show(); main_form.startUpgrade(); return application.exec(); - - /* - qDebug("\n===== RSS Guard updater ====\n"); - - if (argc != 5) { - qDebug("Insufficient arguments passed. Update process cannot proceed."); - qDebug("Press any key to exit updater..."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - return EXIT_FAILURE; - } - - QString this_process_path = QDir::toNativeSeparators(application.applicationFilePath()); - QString current_version(argv[1]); - QString next_version(argv[2]); - QString rssguard_executable_path(argv[3]); - QString rssguard_path = QDir::toNativeSeparators(QFileInfo(rssguard_executable_path).absolutePath()); - QString update_file_path(argv[4]); - QString temp_path = QDir::toNativeSeparators(QFileInfo(update_file_path).absolutePath()); - QString output_temp_path = temp_path + QDir::separator() + APP_LOW_NAME; - - qDebug("Starting updater."); - qDebug("Version changes from %s to %s.", - qPrintable(current_version), - qPrintable(next_version)); - - qDebug("\n===== Files & versions ====\n"); - - qDebug("This process:\n -> %s", qPrintable(this_process_path)); - qDebug("Application executable:\n -> %s", qPrintable(rssguard_executable_path)); - qDebug("TEMP path:\n -> %s", qPrintable(temp_path)); - - qDebug("\n===== Update file metadata ====\n"); - - bool update_file_exists = QFile::exists(update_file_path); - - qDebug("Update file exists:\n -> %s", update_file_exists ? "yes" : "no"); - qDebug("Update file path:\n -> %s", qPrintable(update_file_path)); - qDebug("Update file size:\n -> %lld bytes", QFileInfo(update_file_path).size()); - - if (!update_file_exists) { - qDebug("\nUpdate file does NOT exist. Updater cannot proceed."); - qDebug("Press any key to exit updater..."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - return EXIT_FAILURE; - } - - qDebug("\n===== Cleanup ====\n"); - - // Check if main RSS Guard instance is running. - if (application.sendMessage(APP_QUIT_INSTANCE)) { - qDebug("RSS Guard application is running. Quitting it."); - } - - // Remove old folders. - if (QDir(output_temp_path).exists()) { - if (!removeDir(output_temp_path)) { - qDebug("Cleanup of old temporary files failed."); - qDebug("Press any key to exit updater..."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - return EXIT_FAILURE; - } - } - - QString extractor(APP_7ZA_EXECUTABLE); - QStringList extractor_arguments; - - qDebug("Old temporary files removed."); - - if (!removeDir(rssguard_path, - QStringList() << extractor, - QStringList() << "data")) { - qDebug("Full cleanup of actual RSS Guard installation failed."); - qDebug("Some files from old installation may persist."); - } - - if (!QFile::rename(this_process_path, this_process_path + ".old")) { - qDebug("Updater executable was not renamed and it will not be updated."); - } - - qDebug("Update files are ready. Press any key to proceed..."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - extractor_arguments << "x" << update_file_path << "-r" << - "-y" << QString("-o%1").arg(output_temp_path); - - qDebug("\n===== Decompression =====\n"); - - switch (QProcess::execute(extractor, extractor_arguments)) { - case -1: - qDebug("Decompressor crashed. Upgrading process failed."); - - qDebug("Press any key to exit updater..."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - return EXIT_FAILURE; - - case -2: - qDebug("Decompressor was not started successfully. Upgrading process failed."); - - qDebug("Press any key to exit updater..."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - return EXIT_FAILURE; - - case 0: - qDebug("Decompression is done. Proceeding to copying files to application directory."); - break; - - default: - qDebug("Unspecified error occured."); - - qDebug("Press any key to exit updater..."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - return EXIT_FAILURE; - } - - qDebug("\n===== Copying =====\n"); - - // Find "rssguard" subfolder path in - QFileInfoList rssguard_temp_root = QDir(output_temp_path).entryInfoList(QDir::Dirs | - QDir::NoDotAndDotDot | - QDir::NoSymLinks); - - if (rssguard_temp_root.size() != 1) { - qDebug("Could not find root of downloaded application data."); - - qDebug("Press any key to exit updater..."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - return EXIT_FAILURE; - } - - QString rssguard_single_temp_root = rssguard_temp_root.at(0).absoluteFilePath(); - - if (!copyPath(rssguard_single_temp_root, rssguard_path)) { - qDebug("Critical error appeared during copying of application files."); - - qDebug("Press any key to exit updater..."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - return EXIT_FAILURE; - } - - qDebug("\n===== Cleanup =====\n"); - - removeDir(output_temp_path); - QFile::remove(update_file_path); - - qDebug("Temporary files removed."); - - qDebug("Press any key to exit updater and start RSS Guard."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - if (!QProcess::startDetached(rssguard_executable_path)) { - qDebug("RSS Guard was not started successfully. Start it manually."); - - qDebug("Press any key to exit updater..."); - - std::cin.ignore(std::numeric_limits::max(), '\n'); - - return EXIT_FAILURE; - } - - return EXIT_SUCCESS;*/ }