Updater stuff. Some Windows build Fixes, file replacement logic

This commit is contained in:
Mark Watkins 2011-12-17 04:15:57 +10:00
parent 2d130f1e0c
commit c4abab8cfc
5 changed files with 42 additions and 62 deletions

View File

@ -70,7 +70,6 @@ SOURCES += main.cpp\
common_gui.cpp \ common_gui.cpp \
SleepLib/loader_plugins/intellipap_loader.cpp \ SleepLib/loader_plugins/intellipap_loader.cpp \
SleepLib/calcs.cpp \ SleepLib/calcs.cpp \
UpdateWindow.cpp \
updateparser.cpp \ updateparser.cpp \
quazip/zip.c \ quazip/zip.c \
quazip/unzip.c \ quazip/unzip.c \
@ -80,7 +79,8 @@ SOURCES += main.cpp\
quazip/quacrc32.cpp \ quazip/quacrc32.cpp \
quazip/quaadler32.cpp \ quazip/quaadler32.cpp \
quazip/qioapi.cpp \ quazip/qioapi.cpp \
quazip/JlCompress.cpp quazip/JlCompress.cpp \
UpdaterWindow.cpp
unix:SOURCES += qextserialport/posix_qextserialport.cpp unix:SOURCES += qextserialport/posix_qextserialport.cpp
unix:!macx:SOURCES += qextserialport/qextserialenumerator_unix.cpp unix:!macx:SOURCES += qextserialport/qextserialenumerator_unix.cpp
@ -139,7 +139,6 @@ HEADERS += \
SleepLib/loader_plugins/intellipap_loader.h \ SleepLib/loader_plugins/intellipap_loader.h \
SleepLib/calcs.h \ SleepLib/calcs.h \
version.h \ version.h \
UpdateWindow.h \
updateparser.h \ updateparser.h \
quazip/zip.h \ quazip/zip.h \
quazip/unzip.h \ quazip/unzip.h \
@ -153,7 +152,8 @@ HEADERS += \
quazip/quaadler32.h \ quazip/quaadler32.h \
quazip/JlCompress.h \ quazip/JlCompress.h \
quazip/ioapi.h \ quazip/ioapi.h \
quazip/crypt.h quazip/crypt.h \
UpdaterWindow.h
FORMS += \ FORMS += \
@ -166,7 +166,7 @@ FORMS += \
profileselect.ui \ profileselect.ui \
newprofile.ui \ newprofile.ui \
exportcsv.ui \ exportcsv.ui \
UpdateWindow.ui UpdaterWindow.ui
RESOURCES += \ RESOURCES += \
Resources.qrc \ Resources.qrc \

View File

@ -14,17 +14,17 @@
#include "SleepLib/preferences.h" #include "SleepLib/preferences.h"
#include "quazip/quazip.h" #include "quazip/quazip.h"
#include "quazip/quazipfile.h" #include "quazip/quazipfile.h"
#include "UpdateWindow.h" #include "UpdaterWindow.h"
#include "ui_UpdateWindow.h" #include "ui_UpdaterWindow.h"
#include "version.h" #include "version.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "common_gui.h" #include "common_gui.h"
extern MainWindow * mainwin; extern MainWindow * mainwin;
UpdateWindow::UpdateWindow(QWidget *parent) : UpdaterWindow::UpdaterWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::UpdateWindow) ui(new Ui::UpdaterWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -55,17 +55,16 @@ UpdateWindow::UpdateWindow(QWidget *parent) :
ui->stackedWidget->setCurrentIndex(0); ui->stackedWidget->setCurrentIndex(0);
} }
UpdateWindow::~UpdateWindow() UpdaterWindow::~UpdaterWindow()
{ {
disconnect(netmanager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); disconnect(netmanager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
delete ui; delete ui;
} }
void UpdateWindow::checkForUpdates() void UpdaterWindow::checkForUpdates()
{ {
QString filename=QApplication::applicationDirPath()+QDir::separator()+"update.xml"; QString filename=QApplication::applicationDirPath()+QDir::separator()+"update.xml";
qDebug() << filename;
// Check updates.xml file if it's still recent.. // Check updates.xml file if it's still recent..
if (QFile::exists(filename)) { if (QFile::exists(filename)) {
QFileInfo fi(filename); QFileInfo fi(filename);
@ -90,7 +89,7 @@ void UpdateWindow::checkForUpdates()
dltime.start(); dltime.start();
} }
void UpdateWindow::dataReceived() void UpdaterWindow::dataReceived()
{ {
//HttpStatusCodeAttribute //HttpStatusCodeAttribute
QString rs=reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); QString rs=reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
@ -102,7 +101,7 @@ void UpdateWindow::dataReceived()
file.write(read); file.write(read);
} }
void UpdateWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) void UpdaterWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{ {
QString rs=reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(); QString rs=reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
if (rs!="200") return; if (rs!="200") return;
@ -119,7 +118,7 @@ void UpdateWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
int elapsed=dltime.elapsed(); int elapsed=dltime.elapsed();
} }
void UpdateWindow::requestFile() void UpdaterWindow::requestFile()
{ {
if (!update) return; if (!update) return;
QProgressBar *bar=qobject_cast<QProgressBar *>(ui->tableWidget->cellWidget(current_row,3)); QProgressBar *bar=qobject_cast<QProgressBar *>(ui->tableWidget->cellWidget(current_row,3));
@ -159,7 +158,7 @@ void UpdateWindow::requestFile()
connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this, SLOT(downloadProgress(qint64,qint64))); connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this, SLOT(downloadProgress(qint64,qint64)));
} }
void UpdateWindow::ParseUpdateXML(QIODevice * dev) void UpdaterWindow::ParseUpdateXML(QIODevice * dev)
{ {
QXmlInputSource src(dev); QXmlInputSource src(dev);
QXmlSimpleReader reader; QXmlSimpleReader reader;
@ -256,7 +255,7 @@ void UpdateWindow::ParseUpdateXML(QIODevice * dev)
} }
} }
void UpdateWindow::replyFinished(QNetworkReply * reply) void UpdaterWindow::replyFinished(QNetworkReply * reply)
{ {
netmanager->disconnect(reply,SIGNAL(downloadProgress(qint64,qint64)),this, SLOT(downloadProgress(qint64,qint64))); netmanager->disconnect(reply,SIGNAL(downloadProgress(qint64,qint64)),this, SLOT(downloadProgress(qint64,qint64)));
if (reply->error()==QNetworkReply::NoError) { if (reply->error()==QNetworkReply::NoError) {
@ -332,15 +331,18 @@ void UpdateWindow::replyFinished(QNetworkReply * reply)
int fsize=files.size(); int fsize=files.size();
QByteArray ba; QByteArray ba;
QStringList update_txt; QStringList update_txt;
QStringList unzipped;
QStringList original; QString apppath=QApplication::applicationDirPath()+QDir::separator();
QString backups=apppath+"Backups"+QDir::separator();
QString downloads=apppath+"Downloads"+QDir::separator();
QDir().mkpath(backups);
for (int i=0;i<fsize;i++) { for (int i=0;i<fsize;i++) {
ui->plainTextEdit->appendPlainText("Extracting "+files.at(i)); ui->plainTextEdit->appendPlainText("Extracting "+files.at(i));
QuaZipFile qzf(file.fileName(),files.at(i)); QuaZipFile qzf(file.fileName(),files.at(i));
qzf.open(QuaZipFile::ReadOnly); qzf.open(QuaZipFile::ReadOnly);
QString path=QApplication::applicationDirPath()+QDir::separator()+"Download"+QDir::separator()+files.at(i); QString path=downloads+files.at(i);
if (path.endsWith(QDir::separator())) { if (path.endsWith(QDir::separator())) {
QDir().mkpath(path); QDir().mkpath(path);
if (update->unzipped_path.isEmpty()) if (update->unzipped_path.isEmpty())
@ -357,8 +359,12 @@ void UpdateWindow::replyFinished(QNetworkReply * reply)
if (!line.isNull()) update_txt.append(line); if (!line.isNull()) update_txt.append(line);
} while (!line.isNull()); } while (!line.isNull());
} else { } else {
unzipped.append(path); QString fn=files.at(i).section("/",-1);
original.append(QApplication::applicationDirPath()+QDir::separator()+files.at(i).section("/",-1)); if (f.exists(backups+fn)) f.remove(backups+fn);
if (!f.rename(apppath+fn,backups+fn)) {
errors++;
}
f.setFileName(path); f.setFileName(path);
f.open(QFile::WriteOnly); f.open(QFile::WriteOnly);
f.write(ba); f.write(ba);
@ -373,33 +379,6 @@ void UpdateWindow::replyFinished(QNetworkReply * reply)
} }
zip.close(); zip.close();
if (!errors) { if (!errors) {
for (int i=0;i<unzipped.size();i++) {
if (QFile::copy(unzipped[i],original[i])) {
ui->plainTextEdit->appendPlainText("Copied "+unzipped[i]+" to "+original[i]);
} else {
QFile f(original[i]);
if (f.exists()) {
if (!f.remove()) {
f.rename(original[i],original[i]+".bak");
ui->plainTextEdit->appendPlainText("Renaming "+original[i]);
} else {
ui->plainTextEdit->appendPlainText("Removing "+original[i]);
}
}
if (QFile::copy(unzipped[i],original[i])) {
ui->plainTextEdit->appendPlainText("Copied "+unzipped[i]+" to "+original[i]);
} else {
ui->plainTextEdit->appendPlainText("Copy Failed");
failed=true;
}
}
}
// Parse replacement instructions file? or just dump zip over the top?
// To clean up or not to clean up... is a reasonably valid question.
//file.remove();
} }
} }
@ -438,12 +417,12 @@ void UpdateWindow::replyFinished(QNetworkReply * reply)
} }
} }
void UpdateWindow::on_CloseButton_clicked() void UpdaterWindow::on_CloseButton_clicked()
{ {
close(); close();
} }
void UpdateWindow::upgradeNext() void UpdaterWindow::upgradeNext()
{ {
QTableWidgetItem *item; QTableWidgetItem *item;
bool fnd=false; bool fnd=false;
@ -486,7 +465,7 @@ void UpdateWindow::upgradeNext()
} }
void UpdateWindow::on_upgradeButton_clicked() void UpdaterWindow::on_upgradeButton_clicked()
{ {
if (!updates.size()) return; if (!updates.size()) return;
ui->tableWidget->clearContents(); ui->tableWidget->clearContents();
@ -519,7 +498,7 @@ void UpdateWindow::on_upgradeButton_clicked()
upgradeNext(); upgradeNext();
} }
void UpdateWindow::on_FinishedButton_clicked() void UpdaterWindow::on_FinishedButton_clicked()
{ {
if (success) if (success)
mainwin->RestartApplication(); mainwin->RestartApplication();

View File

@ -11,18 +11,18 @@
#include "updateparser.h" #include "updateparser.h"
namespace Ui { namespace Ui {
class UpdateWindow; class UpdaterWindow;
} }
enum RequestMode { RM_None, RM_CheckUpdates, RM_GetFile, RM_UpdateQT }; enum RequestMode { RM_None, RM_CheckUpdates, RM_GetFile, RM_UpdateQT };
class UpdateWindow : public QMainWindow class UpdaterWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UpdateWindow(QWidget *parent = 0); explicit UpdaterWindow(QWidget *parent = 0);
~UpdateWindow(); ~UpdaterWindow();
void checkForUpdates(); void checkForUpdates();
void ParseUpdateXML(QIODevice * dev); void ParseUpdateXML(QIODevice * dev);
@ -44,7 +44,7 @@ private slots:
private: private:
UpdateParser updateparser; UpdateParser updateparser;
Ui::UpdateWindow *ui; Ui::UpdaterWindow *ui;
QSystemTrayIcon *systray; QSystemTrayIcon *systray;
QMenu *systraymenu; QMenu *systraymenu;
RequestMode requestmode; RequestMode requestmode;

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>UpdateWindow</class> <class>UpdaterWindow</class>
<widget class="QMainWindow" name="UpdateWindow"> <widget class="QMainWindow" name="UpdaterWindow">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@ -365,6 +365,7 @@
</customwidgets> </customwidgets>
<resources> <resources>
<include location="Resources.qrc"/> <include location="Resources.qrc"/>
<include location="resources.qrc"/>
</resources> </resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -30,7 +30,7 @@
#include "exportcsv.h" #include "exportcsv.h"
#include "SleepLib/schema.h" #include "SleepLib/schema.h"
#include "Graphs/glcommon.h" #include "Graphs/glcommon.h"
#include "UpdateWindow.h" #include "UpdaterWindow.h"
QProgressBar *qprogress; QProgressBar *qprogress;
QLabel *qstatus; QLabel *qstatus;
@ -517,7 +517,7 @@ void MainWindow::CheckForUpdates()
void MainWindow::on_actionCheck_for_Updates_triggered() void MainWindow::on_actionCheck_for_Updates_triggered()
{ {
UpdateWindow *w=new UpdateWindow(this); UpdaterWindow *w=new UpdaterWindow(this);
w->checkForUpdates(); w->checkForUpdates();