Work on GUI updater.

This commit is contained in:
Martin Rotter 2014-04-14 08:40:09 +02:00
parent 7be1c7e1ac
commit 3bbdbb1920
9 changed files with 197 additions and 100 deletions

View File

@ -458,7 +458,6 @@ set(APP_TEXT
resources/text/COPYING_GNU_GPL resources/text/COPYING_GNU_GPL
resources/text/COPYING_GNU_GPL_HTML resources/text/COPYING_GNU_GPL_HTML
resources/text/COPYING_BSD resources/text/COPYING_BSD
resources/text/AUTHORS
) )
# Setup source & header files for "rssguard_updater". # Setup source & header files for "rssguard_updater".

View File

@ -1,10 +0,0 @@
<body>
Authors and contributors:
<ul>
<li>Martin Rotter &lt;<a href=\"mailto://rotter.martinos@gmail.com\">rotter.martinos@gmail.com</a>&gt; (author of RSS Guard)</li>
<li>snakebite & tiheum (authors of KFaenza/Faenza icon theme)</li>
<li>Digia Plc (author of QtSingleApplication component)</li>
<li>Artem Galichkin &lt;<a href=\"mailto://doomer3d@gmail.com\">doomer3d@gmail.com</a>&gt; (author of original QKeySequenceWidget component)</li>
<li>Elbert Pol (OS/2 packages maintainer & tester).</li>
</ul>
</body>

View File

@ -67,16 +67,6 @@ FormAbout::FormAbout(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormAbout)
} }
file.close(); file.close();
file.setFileName(APP_INFO_PATH + "/AUTHORS");
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
m_ui->m_txtThanks->setText(text_stream.readAll());
}
else {
//: File containing list of authors was not found.
m_ui->m_txtThanks->setText(tr("Authors information not found."));
}
file.close();
file.setFileName(APP_INFO_PATH + "/CHANGELOG"); file.setFileName(APP_INFO_PATH + "/CHANGELOG");
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
m_ui->m_txtChangelog->setText(text_stream.readAll()); m_ui->m_txtChangelog->setText(text_stream.readAll());

View File

@ -132,8 +132,8 @@
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="acceptRichText"> <property name="acceptRichText">
<bool>false</bool> <bool>false</bool>
@ -157,7 +157,7 @@ p, li { white-space: pre-wrap; }
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<item> <item>
<widget class="QToolBox" name="toolBox"> <widget class="QToolBox" name="m_toolBox">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
@ -166,12 +166,12 @@ p, li { white-space: pre-wrap; }
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>67</width> <width>685</width>
<height>66</height> <height>184</height>
</rect> </rect>
</property> </property>
<property name="autoFillBackground"> <property name="autoFillBackground">
<bool>false</bool> <bool>true</bool>
</property> </property>
<attribute name="label"> <attribute name="label">
<string>GNU GPL License (applies to RSS Guard source code)</string> <string>GNU GPL License (applies to RSS Guard source code)</string>
@ -180,7 +180,16 @@ p, li { white-space: pre-wrap; }
<string>GNU GPL License</string> <string>GNU GPL License</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="margin"> <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -215,8 +224,8 @@ p, li { white-space: pre-wrap; }
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans Mono'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans Mono'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set> <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
@ -233,15 +242,24 @@ p, li { white-space: pre-wrap; }
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>85</width> <width>98</width>
<height>66</height> <height>69</height>
</rect> </rect>
</property> </property>
<attribute name="label"> <attribute name="label">
<string>BSD License (applies to QtSingleApplication source code)</string> <string>BSD License (applies to QtSingleApplication source code)</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">
<property name="margin"> <property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
@ -276,8 +294,8 @@ p, li { white-space: pre-wrap; }
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans Mono'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'DejaVu Sans Mono'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif';&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set> <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
@ -300,49 +318,6 @@ p, li { white-space: pre-wrap; }
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="m_tabThanks">
<attribute name="title">
<string>Thanks to</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QTextBrowser" name="m_txtThanks">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="html">
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="tabStopWidth">
<number>30</number>
</property>
<property name="acceptRichText">
<bool>false</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="m_lblThanks">
<property name="text">
<string>Thanks to page is available only in English language.</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="m_tabChangelog"> <widget class="QWidget" name="m_tabChangelog">
<attribute name="title"> <attribute name="title">
<string>Changelog</string> <string>Changelog</string>
@ -360,8 +335,8 @@ p, li { white-space: pre-wrap; }
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans Serif'; font-size:9pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="acceptRichText"> <property name="acceptRichText">
<bool>false</bool> <bool>false</bool>

View File

@ -18,10 +18,10 @@
#ifndef FORMSTANDARDFEEDDETAILS_H #ifndef FORMSTANDARDFEEDDETAILS_H
#define FORMSTANDARDFEEDDETAILS_H #define FORMSTANDARDFEEDDETAILS_H
#include <QDialog>
#include "ui_formfeeddetails.h" #include "ui_formfeeddetails.h"
#include <QDialog>
namespace Ui { namespace Ui {
class FormFeedDetails; class FormFeedDetails;

View File

@ -18,14 +18,14 @@
#ifndef FORMUPDATE_H #ifndef FORMUPDATE_H
#define FORMUPDATE_H #define FORMUPDATE_H
#include <QDialog>
#include <QPushButton>
#include <QNetworkReply>
#include "ui_formupdate.h" #include "ui_formupdate.h"
#include "miscellaneous/systemfactory.h" #include "miscellaneous/systemfactory.h"
#include <QDialog>
#include <QPushButton>
#include <QNetworkReply>
namespace Ui { namespace Ui {
class FormUpdate; class FormUpdate;

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>607</width> <width>607</width>
<height>322</height> <height>366</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -71,8 +71,8 @@
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt; <string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt; &lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; } p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt; &lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> &lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
<property name="textInteractionFlags"> <property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set> <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>

View File

@ -1,6 +1,7 @@
#include "updater/formupdater.h" #include "updater/formupdater.h"
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "qtsingleapplication/qtsingleapplication.h"
#include <QApplication> #include <QApplication>
#include <QDesktopWidget> #include <QDesktopWidget>
@ -12,15 +13,24 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QKeyEvent> #include <QKeyEvent>
#include <QProcess> #include <QProcess>
#include <QProcessEnvironment>
#include <QScrollBar>
FormUpdater::FormUpdater(QWidget *parent) FormUpdater::FormUpdater(QWidget *parent)
: QMainWindow(parent), : QMainWindow(parent),
m_state(NoState), m_state(NoState),
m_txtOutput(new QTextEdit(this)) { m_txtOutput(new QTextEdit(this)),
m_parsedArguments(QHash<QString, QString>()) {
m_txtOutput->setFontPointSize(10.0);
m_txtOutput->setReadOnly(true); m_txtOutput->setReadOnly(true);
m_txtOutput->setFocusPolicy(Qt::NoFocus); m_txtOutput->setFocusPolicy(Qt::StrongFocus);
m_txtOutput->setContextMenuPolicy(Qt::DefaultContextMenu);
m_txtOutput->setTextInteractionFlags(Qt::TextSelectableByMouse |
Qt::TextSelectableByKeyboard |
Qt::LinksAccessibleByKeyboard |
Qt::LinksAccessibleByMouse);
setCentralWidget(m_txtOutput); setCentralWidget(m_txtOutput);
setWindowTitle("RSS Guard updater"); setWindowTitle("RSS Guard updater");
@ -32,20 +42,131 @@ FormUpdater::~FormUpdater() {
} }
void FormUpdater::startUpgrade() { void FormUpdater::startUpgrade() {
m_txtOutput->append("Welcome to RSS Guard updater."); printHeading("Welcome to RSS Guard updater");
printText("Analyzing updater arguments...");
if (QApplication::arguments().size() != 5) { if (QApplication::arguments().size() != 5) {
m_txtOutput->append("Insufficient arguments passed. Update process cannot proceed."); printText("Insufficient arguments passed. Update process cannot proceed.");
m_txtOutput->append("Press any key to exit updater..."); printText("\nPress any key to exit updater...");
m_state = ExitError; m_state = ExitError;
// Ted je nastavenej state a pri keyPressEvent se appka ukonci return;
} }
// do datovejch memberu teto tridy ulozit argumenty a pokracovat // 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;
printArguments();
if (!printUpdateInformation()) {
printText("Update file does not exist or is corrupted.");
printText("\nPress any key to exit updater...");
m_state = ExitError;
return;
}
doPreparationCleanup();
doExtractionAndCopying();
}
void FormUpdater::printArguments() {
printNewline();
printHeading("Arguments");
printText(QString("Updater executable file:\n -> %1").arg(m_parsedArguments["updater_path"]));
printText(QString("Application executable file:\n -> %1").arg(m_parsedArguments["rssguard_executable_path"]));
printText(QString("Temp folder:\n -> %1").arg(m_parsedArguments["temp_path"]));
printText(QString("Application temp folder:\n -> %1").arg(m_parsedArguments["output_temp_path"]));
}
bool FormUpdater::printUpdateInformation() {
bool update_file_exists = QFile::exists(m_parsedArguments["update_file_path"]);
printNewline();
printHeading("Update information");
printText(QString("Version change:\n -> %1 --> %2").arg(m_parsedArguments["current_version"], m_parsedArguments["next_version"]));
printText(QString("Update file:\n -> %1").arg(m_parsedArguments["update_file_path"]));
printText(QString("Update file exists:\n -> %1").arg(update_file_exists ? "yes" : "no"));
printText(QString("Update file size:\n -> %1 bytes").arg(QFileInfo(m_parsedArguments["update_file_path"]).size()));
return update_file_exists;
}
bool FormUpdater::doPreparationCleanup() {
printNewline();
printHeading("Initial cleanup");
// Check if main RSS Guard instance is running.
if (static_cast<QtSingleApplication*>(qApp)->sendMessage(APP_QUIT_INSTANCE)) {
printText("The main application is running. Quitting it.");
}
else {
printText("The main application is not running.");
}
// Remove old folders.
if (QDir(m_parsedArguments["output_temp_path"]).exists()) {
if (!removeDirectory(m_parsedArguments["output_temp_path"])) {
printText("Cleanup of old temporary files failed.");
return false;
}
}
if (!removeDirectory(m_parsedArguments["rssguard_path"],
QStringList() << APP_7ZA_EXECUTABLE,
QStringList() << "data")) {
printText("Full cleanup of actual RSS Guard installation failed.");
printText("Some files from old installation may persist.");
}
if (!QFile::rename(m_parsedArguments["updater_path"], m_parsedArguments["updater_path"] + ".old")) {
qDebug("Updater executable was not renamed and it will not be updated.");
}
return true;
}
bool FormUpdater::doExtractionAndCopying() {
QStringList extractor_arguments;
extractor_arguments << "x" << m_parsedArguments["update_file_path"] << "-r" <<
"-y" << QString("-o%1").arg(m_parsedArguments["output_temp_path"]);
QProcess process_extractor(this);
process_extractor.setEnvironment(QProcessEnvironment::systemEnvironment().toStringList());
process_extractor.setProcessChannelMode(QProcess::MergedChannels);
process_extractor.start(APP_7ZA_EXECUTABLE, extractor_arguments);
if (process_extractor.waitForFinished()) {
printText("Extraction of update files failed.");
return false;
}
printText("Extraction done successfully.");
return true;
} }
void FormUpdater::keyPressEvent(QKeyEvent* event) { void FormUpdater::keyPressEvent(QKeyEvent* event) {
if (event->matches(QKeySequence::Copy)) {
event->accept();
return;
}
else {
event->ignore(); event->ignore();
}
switch (m_state) { switch (m_state) {
case NoState: case NoState:
@ -63,8 +184,22 @@ void FormUpdater::keyPressEvent(QKeyEvent* event) {
} }
} }
void FormUpdater::printHeading(const QString &header) {
m_txtOutput->setAlignment(Qt::AlignCenter);
m_txtOutput->append(QString("****** %1 ******\n").arg(header));
}
void FormUpdater::printText(const QString &text) {
m_txtOutput->setAlignment(Qt::AlignLeft);
m_txtOutput->append(text);
}
void FormUpdater::printNewline() {
m_txtOutput->append("\n");
}
void FormUpdater::moveToCenterAndResize() { void FormUpdater::moveToCenterAndResize() {
resize(500, 400); resize(600, 400);
move(qApp->desktop()->screenGeometry().center() - rect().center()); move(qApp->desktop()->screenGeometry().center() - rect().center());
} }

View File

@ -3,6 +3,8 @@
#include <QMainWindow> #include <QMainWindow>
#include <QHash>
class QTextEdit; class QTextEdit;
class QKeyEvent; class QKeyEvent;
@ -22,11 +24,18 @@ class FormUpdater : public QMainWindow {
virtual ~FormUpdater(); virtual ~FormUpdater();
void startUpgrade(); void startUpgrade();
void printArguments();
bool printUpdateInformation();
bool doPreparationCleanup();
bool doExtractionAndCopying();
protected: protected:
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
private: private:
void printText(const QString &text);
void printNewline();
void printHeading(const QString &header);
void moveToCenterAndResize(); void moveToCenterAndResize();
// File/directory manipulators. // File/directory manipulators.
@ -39,8 +48,7 @@ class FormUpdater : public QMainWindow {
UpdaterState m_state; UpdaterState m_state;
QTextEdit *m_txtOutput; QTextEdit *m_txtOutput;
QString m_rssguardExecutablePath; QHash<QString, QString> m_parsedArguments;
}; };
#endif // FORMUPDATER_H #endif // FORMUPDATER_H