GUI updater works...
This commit is contained in:
parent
c3513a3c9e
commit
7be1c7e1ac
3 changed files with 133 additions and 61 deletions
|
|
@ -5,19 +5,123 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
|
|
||||||
FormUpdater::FormUpdater(QWidget *parent) : QMainWindow(parent) {
|
FormUpdater::FormUpdater(QWidget *parent)
|
||||||
|
: QMainWindow(parent),
|
||||||
|
m_state(NoState),
|
||||||
|
m_txtOutput(new QTextEdit(this)) {
|
||||||
|
|
||||||
|
m_txtOutput->setReadOnly(true);
|
||||||
|
m_txtOutput->setFocusPolicy(Qt::NoFocus);
|
||||||
|
|
||||||
|
setCentralWidget(m_txtOutput);
|
||||||
setWindowTitle("RSS Guard updater");
|
setWindowTitle("RSS Guard updater");
|
||||||
setWindowIcon(QIcon(APP_ICON_PATH));
|
setWindowIcon(QIcon(APP_ICON_PATH));
|
||||||
|
|
||||||
moveToCenterAndResize();
|
moveToCenterAndResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
FormUpdater::~FormUpdater() {
|
FormUpdater::~FormUpdater() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FormUpdater::startUpgrade() {
|
||||||
|
m_txtOutput->append("Welcome to RSS Guard updater.");
|
||||||
|
|
||||||
|
if (QApplication::arguments().size() != 5) {
|
||||||
|
m_txtOutput->append("Insufficient arguments passed. Update process cannot proceed.");
|
||||||
|
m_txtOutput->append("Press any key to exit updater...");
|
||||||
|
m_state = ExitError;
|
||||||
|
// Ted je nastavenej state a pri keyPressEvent se appka ukonci
|
||||||
|
}
|
||||||
|
|
||||||
|
// do datovejch memberu teto tridy ulozit argumenty a pokracovat
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormUpdater::keyPressEvent(QKeyEvent* event) {
|
||||||
|
event->ignore();
|
||||||
|
|
||||||
|
switch (m_state) {
|
||||||
|
case NoState:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ExitNormal:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ExitError:
|
||||||
|
qApp->quit();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FormUpdater::moveToCenterAndResize() {
|
void FormUpdater::moveToCenterAndResize() {
|
||||||
resize(500, 400);
|
resize(500, 400);
|
||||||
move(qApp->desktop()->screenGeometry().center() - rect().center());
|
move(qApp->desktop()->screenGeometry().center() - rect().center());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FormUpdater::removeDirectory(const QString& directory_name,
|
||||||
|
const QStringList& exception_file_list,
|
||||||
|
const QStringList& exception_folder_list) {
|
||||||
|
bool result = true;
|
||||||
|
QDir dir(directory_name);
|
||||||
|
|
||||||
|
if (dir.exists(directory_name)) {
|
||||||
|
foreach (QFileInfo info,
|
||||||
|
dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
|
||||||
|
if (info.isDir()) {
|
||||||
|
if (!exception_folder_list.contains(info.fileName())) {
|
||||||
|
result &= removeDirectory(info.absoluteFilePath(), exception_file_list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!exception_file_list.contains(info.fileName())) {
|
||||||
|
result &= QFile::remove(info.absoluteFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result &= dir.rmdir(directory_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FormUpdater::copyDirectory(QString source, QString destination) {
|
||||||
|
QDir dir(source);
|
||||||
|
|
||||||
|
if (! dir.exists()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
||||||
|
QString dst_path = destination + QDir::separator() + d;
|
||||||
|
dir.mkpath(dst_path);
|
||||||
|
copyDirectory(source + QDir::separator() + d, dst_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (QString f, dir.entryList(QDir::Files)) {
|
||||||
|
QString original_file = source + QDir::separator() + f;
|
||||||
|
QString destination_file = destination + QDir::separator() + f;
|
||||||
|
|
||||||
|
if (!QFile::exists(destination_file) || QFile::remove(destination_file)) {
|
||||||
|
if (QFile::copy(original_file, destination_file)) {
|
||||||
|
qDebug("Copied file %s", qPrintable(f));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug("Failed to copy file %s", qPrintable(original_file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug("Failed to remove file %s", qPrintable(original_file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,43 @@
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
|
||||||
|
|
||||||
|
class QTextEdit;
|
||||||
|
class QKeyEvent;
|
||||||
|
|
||||||
class FormUpdater : public QMainWindow {
|
class FormUpdater : public QMainWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum UpdaterState {
|
||||||
|
NoState,
|
||||||
|
ExitNormal,
|
||||||
|
ExitError
|
||||||
|
};
|
||||||
|
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
explicit FormUpdater(QWidget *parent = 0);
|
explicit FormUpdater(QWidget *parent = 0);
|
||||||
virtual ~FormUpdater();
|
virtual ~FormUpdater();
|
||||||
|
|
||||||
|
void startUpgrade();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void moveToCenterAndResize();
|
void moveToCenterAndResize();
|
||||||
|
|
||||||
|
// File/directory manipulators.
|
||||||
|
bool copyDirectory(QString source, QString destination);
|
||||||
|
bool removeDirectory(const QString & directory_name,
|
||||||
|
const QStringList &exception_file_list = QStringList(),
|
||||||
|
const QStringList &exception_folder_list = QStringList());
|
||||||
|
|
||||||
|
private:
|
||||||
|
UpdaterState m_state;
|
||||||
|
QTextEdit *m_txtOutput;
|
||||||
|
|
||||||
|
QString m_rssguardExecutablePath;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FORMUPDATER_H
|
#endif // FORMUPDATER_H
|
||||||
|
|
|
||||||
|
|
@ -29,65 +29,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
/*
|
|
||||||
bool removeDir(const QString & dirName,
|
|
||||||
const QStringList &exception_file_list = QStringList(),
|
|
||||||
const QStringList &exception_folder_list = QStringList()) {
|
|
||||||
bool result = true;
|
|
||||||
QDir dir(dirName);
|
|
||||||
|
|
||||||
if (dir.exists(dirName)) {
|
|
||||||
foreach (QFileInfo info,
|
|
||||||
dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) {
|
|
||||||
if (info.isDir()) {
|
|
||||||
if (!exception_folder_list.contains(info.fileName())) {
|
|
||||||
result &= removeDir(info.absoluteFilePath(), exception_file_list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!exception_file_list.contains(info.fileName())) {
|
|
||||||
result &= QFile::remove(info.absoluteFilePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result &= dir.rmdir(dirName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool copyPath(QString src, QString dst) {
|
|
||||||
QDir dir(src);
|
|
||||||
|
|
||||||
if (! dir.exists()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
|
|
||||||
QString dst_path = dst + QDir::separator() + d;
|
|
||||||
dir.mkpath(dst_path);
|
|
||||||
copyPath(src + QDir::separator() + d, dst_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (QString f, dir.entryList(QDir::Files)) {
|
|
||||||
QString original_file = src + QDir::separator() + f;
|
|
||||||
QString destination_file = dst + QDir::separator() + f;
|
|
||||||
|
|
||||||
if (!QFile::exists(destination_file) || QFile::remove(destination_file)) {
|
|
||||||
if (QFile::copy(original_file, destination_file)) {
|
|
||||||
qDebug("Copied file %s", qPrintable(f));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug("Failed to copy file %s", qPrintable(original_file));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug("Failed to remove file %s", qPrintable(original_file));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
// Main entry point to "rssguard_updater.exe".
|
// Main entry point to "rssguard_updater.exe".
|
||||||
// It expects 4 ARGUMENTS:
|
// It expects 4 ARGUMENTS:
|
||||||
// 0) - the actual path of this process,
|
// 0) - the actual path of this process,
|
||||||
|
|
@ -102,6 +43,7 @@ int main(int argc, char *argv[]) {
|
||||||
FormUpdater main_form;
|
FormUpdater main_form;
|
||||||
|
|
||||||
main_form.show();
|
main_form.show();
|
||||||
|
main_form.startUpgrade();
|
||||||
|
|
||||||
return application.exec();
|
return application.exec();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue