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

View File

@ -14,17 +14,17 @@
#include "SleepLib/preferences.h"
#include "quazip/quazip.h"
#include "quazip/quazipfile.h"
#include "UpdateWindow.h"
#include "ui_UpdateWindow.h"
#include "UpdaterWindow.h"
#include "ui_UpdaterWindow.h"
#include "version.h"
#include "mainwindow.h"
#include "common_gui.h"
extern MainWindow * mainwin;
UpdateWindow::UpdateWindow(QWidget *parent) :
UpdaterWindow::UpdaterWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::UpdateWindow)
ui(new Ui::UpdaterWindow)
{
ui->setupUi(this);
@ -55,17 +55,16 @@ UpdateWindow::UpdateWindow(QWidget *parent) :
ui->stackedWidget->setCurrentIndex(0);
}
UpdateWindow::~UpdateWindow()
UpdaterWindow::~UpdaterWindow()
{
disconnect(netmanager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
delete ui;
}
void UpdateWindow::checkForUpdates()
void UpdaterWindow::checkForUpdates()
{
QString filename=QApplication::applicationDirPath()+QDir::separator()+"update.xml";
qDebug() << filename;
// Check updates.xml file if it's still recent..
if (QFile::exists(filename)) {
QFileInfo fi(filename);
@ -90,7 +89,7 @@ void UpdateWindow::checkForUpdates()
dltime.start();
}
void UpdateWindow::dataReceived()
void UpdaterWindow::dataReceived()
{
//HttpStatusCodeAttribute
QString rs=reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
@ -102,7 +101,7 @@ void UpdateWindow::dataReceived()
file.write(read);
}
void UpdateWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
void UpdaterWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
{
QString rs=reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
if (rs!="200") return;
@ -119,7 +118,7 @@ void UpdateWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
int elapsed=dltime.elapsed();
}
void UpdateWindow::requestFile()
void UpdaterWindow::requestFile()
{
if (!update) return;
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)));
}
void UpdateWindow::ParseUpdateXML(QIODevice * dev)
void UpdaterWindow::ParseUpdateXML(QIODevice * dev)
{
QXmlInputSource src(dev);
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)));
if (reply->error()==QNetworkReply::NoError) {
@ -332,15 +331,18 @@ void UpdateWindow::replyFinished(QNetworkReply * reply)
int fsize=files.size();
QByteArray ba;
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++) {
ui->plainTextEdit->appendPlainText("Extracting "+files.at(i));
QuaZipFile qzf(file.fileName(),files.at(i));
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())) {
QDir().mkpath(path);
if (update->unzipped_path.isEmpty())
@ -357,8 +359,12 @@ void UpdateWindow::replyFinished(QNetworkReply * reply)
if (!line.isNull()) update_txt.append(line);
} while (!line.isNull());
} else {
unzipped.append(path);
original.append(QApplication::applicationDirPath()+QDir::separator()+files.at(i).section("/",-1));
QString fn=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.open(QFile::WriteOnly);
f.write(ba);
@ -373,33 +379,6 @@ void UpdateWindow::replyFinished(QNetworkReply * reply)
}
zip.close();
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();
}
void UpdateWindow::upgradeNext()
void UpdaterWindow::upgradeNext()
{
QTableWidgetItem *item;
bool fnd=false;
@ -486,7 +465,7 @@ void UpdateWindow::upgradeNext()
}
void UpdateWindow::on_upgradeButton_clicked()
void UpdaterWindow::on_upgradeButton_clicked()
{
if (!updates.size()) return;
ui->tableWidget->clearContents();
@ -519,7 +498,7 @@ void UpdateWindow::on_upgradeButton_clicked()
upgradeNext();
}
void UpdateWindow::on_FinishedButton_clicked()
void UpdaterWindow::on_FinishedButton_clicked()
{
if (success)
mainwin->RestartApplication();

View File

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

View File

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

View File

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