Updater things...
This commit is contained in:
parent
e07afaa35f
commit
226e1d69e3
3 changed files with 29 additions and 195 deletions
|
@ -18,11 +18,13 @@
|
||||||
|
|
||||||
|
|
||||||
FormUpdater::FormUpdater(QWidget *parent)
|
FormUpdater::FormUpdater(QWidget *parent)
|
||||||
: QMainWindow(parent),
|
: QMainWindow(parent, Qt::Dialog | Qt::WindowStaysOnTopHint),
|
||||||
m_state(NoState),
|
m_state(NoState),
|
||||||
m_txtOutput(new QTextEdit(this)),
|
m_txtOutput(new QTextEdit(this)),
|
||||||
m_parsedArguments(QHash<QString, QString>()) {
|
m_parsedArguments(QHash<QString, QString>()) {
|
||||||
|
|
||||||
|
m_txtOutput->setAutoFormatting(QTextEdit::AutoNone);
|
||||||
|
m_txtOutput->setAcceptRichText(true);
|
||||||
m_txtOutput->setFontPointSize(10.0);
|
m_txtOutput->setFontPointSize(10.0);
|
||||||
m_txtOutput->setReadOnly(true);
|
m_txtOutput->setReadOnly(true);
|
||||||
m_txtOutput->setFocusPolicy(Qt::StrongFocus);
|
m_txtOutput->setFocusPolicy(Qt::StrongFocus);
|
||||||
|
@ -35,6 +37,9 @@ FormUpdater::FormUpdater(QWidget *parent)
|
||||||
setCentralWidget(m_txtOutput);
|
setCentralWidget(m_txtOutput);
|
||||||
setWindowTitle("RSS Guard updater");
|
setWindowTitle("RSS Guard updater");
|
||||||
setWindowIcon(QIcon(APP_ICON_PATH));
|
setWindowIcon(QIcon(APP_ICON_PATH));
|
||||||
|
|
||||||
|
qApp->setQuitOnLastWindowClosed(true);
|
||||||
|
|
||||||
moveToCenterAndResize();
|
moveToCenterAndResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +48,6 @@ FormUpdater::~FormUpdater() {
|
||||||
|
|
||||||
void FormUpdater::startUpgrade() {
|
void FormUpdater::startUpgrade() {
|
||||||
printHeading("Welcome to RSS Guard updater");
|
printHeading("Welcome to RSS Guard updater");
|
||||||
|
|
||||||
printText("Analyzing updater arguments...");
|
printText("Analyzing updater arguments...");
|
||||||
|
|
||||||
if (QApplication::arguments().size() != 5) {
|
if (QApplication::arguments().size() != 5) {
|
||||||
|
@ -54,18 +58,8 @@ void FormUpdater::startUpgrade() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain parameters.
|
// Process arguments.
|
||||||
QStringList arguments = QApplication::arguments();
|
saveArguments();
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
printArguments();
|
printArguments();
|
||||||
|
|
||||||
if (!printUpdateInformation() || !doPreparationCleanup() || !doExtractionAndCopying()) {
|
if (!printUpdateInformation() || !doPreparationCleanup() || !doExtractionAndCopying()) {
|
||||||
|
@ -77,13 +71,31 @@ void FormUpdater::startUpgrade() {
|
||||||
|
|
||||||
doFinalCleanup();
|
doFinalCleanup();
|
||||||
|
|
||||||
|
printText("Application was upgraded without serious errors.");
|
||||||
|
|
||||||
if (!QProcess::startDetached(m_parsedArguments["rssguard_executable_path"])) {
|
if (!QProcess::startDetached(m_parsedArguments["rssguard_executable_path"])) {
|
||||||
printText("RSS Guard was not started successfully. Start it manually.");
|
printText("RSS Guard was not started successfully. Start it manually.");
|
||||||
m_state = ExitError;
|
m_state = ExitError;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
m_state = ExitNormal;
|
||||||
|
}
|
||||||
|
|
||||||
printText("\nPress any key to exit updater...");
|
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() {
|
void FormUpdater::printArguments() {
|
||||||
|
|
|
@ -24,6 +24,7 @@ class FormUpdater : public QMainWindow {
|
||||||
virtual ~FormUpdater();
|
virtual ~FormUpdater();
|
||||||
|
|
||||||
void startUpgrade();
|
void startUpgrade();
|
||||||
|
void saveArguments();
|
||||||
void printArguments();
|
void printArguments();
|
||||||
bool printUpdateInformation();
|
bool printUpdateInformation();
|
||||||
bool doPreparationCleanup();
|
bool doPreparationCleanup();
|
||||||
|
|
|
@ -36,193 +36,14 @@
|
||||||
// 2) - string with future version,
|
// 2) - string with future version,
|
||||||
// 3) - path to RSS Guard ("rssguard.exe") file,
|
// 3) - path to RSS Guard ("rssguard.exe") file,
|
||||||
// 4) - path to update file (stored in TEMP folder).
|
// 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.
|
// Instantiate base application object.
|
||||||
QtSingleApplication application(APP_LOW_NAME, argc, argv);
|
QtSingleApplication application(APP_LOW_NAME, argc, argv);
|
||||||
|
|
||||||
FormUpdater main_form;
|
FormUpdater main_form;
|
||||||
|
|
||||||
main_form.show();
|
main_form.show();
|
||||||
main_form.startUpgrade();
|
main_form.startUpgrade();
|
||||||
|
|
||||||
return application.exec();
|
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<std::streamsize>::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<std::streamsize>::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<std::streamsize>::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<std::streamsize>::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<std::streamsize>::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<std::streamsize>::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<std::streamsize>::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<std::streamsize>::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<std::streamsize>::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<std::streamsize>::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<std::streamsize>::max(), '\n');
|
|
||||||
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EXIT_SUCCESS;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue