summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Wenger <domonoky@googlemail.com>2008-05-11 18:22:42 +0000
committerDominik Wenger <domonoky@googlemail.com>2008-05-11 18:22:42 +0000
commitd24eb9e461ca1d25a83d825d355710ebdbe509b5 (patch)
tree117e5f9e22aa0d4de63f32d27e86e0d471a683e5
parent9c54187678281077b8700c1c107f54a0b40d7050 (diff)
rbutil: improve the backup function.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17463 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--rbutil/rbutilqt/install.cpp69
-rw-r--r--rbutil/rbutilqt/install.h9
-rw-r--r--rbutil/rbutilqt/installfrm.ui101
-rw-r--r--rbutil/rbutilqt/rbutilqt.cpp40
-rw-r--r--rbutil/rbutilqt/rbutilqt.h1
-rw-r--r--rbutil/rbutilqt/rbzip.cpp14
-rw-r--r--rbutil/rbutilqt/rbzip.h11
-rw-r--r--rbutil/rbutilqt/utils.cpp23
-rw-r--r--rbutil/rbutilqt/utils.h1
9 files changed, 203 insertions, 66 deletions
diff --git a/rbutil/rbutilqt/install.cpp b/rbutil/rbutilqt/install.cpp
index 4461a6a633..e9f1f61837 100644
--- a/rbutil/rbutilqt/install.cpp
+++ b/rbutil/rbutilqt/install.cpp
@@ -20,15 +20,31 @@
#include "install.h"
#include "ui_installfrm.h"
#include "rbzip.h"
+#include "utils.h"
-Install::Install(QWidget *parent) : QDialog(parent)
+Install::Install(RbSettings *sett,QWidget *parent) : QDialog(parent)
{
+ settings = sett;
ui.setupUi(this);
connect(ui.radioCurrent, SIGNAL(toggled(bool)), this, SLOT(setCached(bool)));
connect(ui.radioStable, SIGNAL(toggled(bool)), this, SLOT(setDetailsStable(bool)));
connect(ui.radioCurrent, SIGNAL(toggled(bool)), this, SLOT(setDetailsCurrent(bool)));
connect(ui.radioArchived, SIGNAL(toggled(bool)), this, SLOT(setDetailsArchived(bool)));
+ connect(ui.changeBackup,SIGNAL(pressed()),this,SLOT(changeBackupPath()));
+
+ //! check if rockbox is already installed
+ QString version = installedVersion(settings->mountpoint());
+
+ if(version != "")
+ {
+ ui.Backupgroup->show();
+ ui.backupLocation->setText(settings->mountpoint() + ".backup/rockbox-backup-"+version+".zip");
+ }
+ else
+ {
+ ui.Backupgroup->hide();
+ }
}
@@ -84,17 +100,32 @@ void Install::accept()
}
settings->sync();
- //! check if rockbox is already installed
- if(QDir(settings->mountpoint() + "/.rockbox").exists())
+ //! check if we should backup
+ if(ui.backup->isChecked())
{
- if(QMessageBox::question(this, tr("Installed Rockbox detected"),
- tr("Rockbox installation detected. Do you want to backup first?"),
- QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
+ logger->addItem(tr("Beginning Backup..."),LOGINFO);
+ QString backupName = ui.backupLocation->text();
+
+ //! create dir, if it doesnt exist
+ QFileInfo backupFile(backupName);
+ if(!QDir(backupFile.path()).exists())
+ {
+ QDir a;
+ a.mkpath(backupFile.path());
+ }
+
+ //! create backup
+ RbZip backup;
+ connect(&backup,SIGNAL(zipProgress(int,int)),this,SLOT(updateDataReadProgress(int,int)));
+ if(backup.createZip(backupName,settings->mountpoint() + "/.rockbox") == Zip::Ok)
+ {
+ logger->addItem(tr("Backup successfull"),LOGOK);
+ }
+ else
{
- QString backupName = QFileDialog::getSaveFileName(this,"Select Backup Filename",settings->mountpoint());
- logger->show();
- RbZip backup;
- backup.createZip(backupName,settings->mountpoint() + "/.rockbox",logger);
+ logger->addItem(tr("Backup failed!"),LOGERROR);
+ logger->abort();
+ return;
}
}
@@ -116,6 +147,19 @@ void Install::accept()
}
+void Install::changeBackupPath()
+{
+ ui.backupLocation->setText(QFileDialog::getSaveFileName(this,"Select Backup Filename",ui.backupLocation->text()));
+}
+
+void Install::updateDataReadProgress(int read, int total)
+{
+ logger->setProgressMax(total);
+ logger->setProgressValue(read);
+ //qDebug() << "progress:" << read << "/" << total;
+
+}
+
// Zip installer has finished
void Install::done(bool error)
{
@@ -216,7 +260,4 @@ void Install::setVersionStrings(QMap<QString, QString> ver)
qDebug() << "Install::setVersionStrings" << version;
}
-void Install::setSettings(RbSettings *sett)
-{
- settings = sett;
-}
+
diff --git a/rbutil/rbutilqt/install.h b/rbutil/rbutilqt/install.h
index db4c06ced4..9c4705697e 100644
--- a/rbutil/rbutilqt/install.h
+++ b/rbutil/rbutilqt/install.h
@@ -31,14 +31,15 @@ class Install : public QDialog
{
Q_OBJECT
public:
- Install(QWidget *parent = 0);
- void setSettings(RbSettings* sett);
+ Install(RbSettings* sett,QWidget *parent = 0);
void setVersionStrings(QMap<QString, QString>);
public slots:
void accept(void);
-
- private:
+ void updateDataReadProgress(int read, int total);
+ void changeBackupPath();
+
+ private:
Ui::InstallFrm ui;
ProgressLoggerGui* logger;
RbSettings* settings;
diff --git a/rbutil/rbutilqt/installfrm.ui b/rbutil/rbutilqt/installfrm.ui
index f46e8ae69e..6a2a541f64 100644
--- a/rbutil/rbutilqt/installfrm.ui
+++ b/rbutil/rbutilqt/installfrm.ui
@@ -16,7 +16,7 @@
<string>Install Rockbox</string>
</property>
<layout class="QGridLayout" >
- <item rowspan="6" row="0" column="0" >
+ <item rowspan="9" row="0" column="0" >
<widget class="QLabel" name="label" >
<property name="text" >
<string/>
@@ -98,35 +98,12 @@
</layout>
</widget>
</item>
- <item row="3" column="1" colspan="2" >
- <widget class="QCheckBox" name="checkBoxCache" >
- <property name="toolTip" >
- <string>Rockbox Utility stores copies of Rockbox it has downloaded on the local hard disk to save network traffic. If your local copy is no longer working, tick this box to download a fresh copy.</string>
- </property>
- <property name="text" >
- <string>&amp;Don't use locally cached copy</string>
- </property>
- </widget>
- </item>
- <item row="4" column="3" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="5" column="1" >
+ <item row="8" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
- <property name="sizeHint" >
+ <property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
@@ -134,7 +111,7 @@
</property>
</spacer>
</item>
- <item row="5" column="2" colspan="2" >
+ <item row="8" column="2" colspan="2" >
<layout class="QHBoxLayout" >
<item>
<widget class="QPushButton" name="buttonOk" >
@@ -142,7 +119,8 @@
<string>&amp;Install</string>
</property>
<property name="icon" >
- <iconset resource="rbutilqt.qrc" >:/icons/go-next.png</iconset>
+ <iconset resource="rbutilqt.qrc" >
+ <normaloff>:/icons/go-next.png</normaloff>:/icons/go-next.png</iconset>
</property>
</widget>
</item>
@@ -152,12 +130,77 @@
<string>&amp;Cancel</string>
</property>
<property name="icon" >
- <iconset resource="rbutilqt.qrc" >:/icons/process-stop.png</iconset>
+ <iconset resource="rbutilqt.qrc" >
+ <normaloff>:/icons/process-stop.png</normaloff>:/icons/process-stop.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
+ <item row="7" column="2" >
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0" >
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="3" column="1" colspan="3" >
+ <widget class="QGroupBox" name="Backupgroup" >
+ <property name="title" >
+ <string>Backup</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" >
+ <item row="0" column="0" colspan="2" >
+ <widget class="QCheckBox" name="backup" >
+ <property name="text" >
+ <string>Backup before installing</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0" >
+ <widget class="QLabel" name="label_3" >
+ <property name="text" >
+ <string>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
+p, li { white-space: pre-wrap; }
+&lt;/style>&lt;/head>&lt;body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
+&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">&lt;span style=" font-size:8pt; font-weight:600;">Backup Location:&lt;/span>&lt;/p>&lt;/body>&lt;/html></string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" >
+ <widget class="QLabel" name="backupLocation" >
+ <property name="text" >
+ <string>Backup location</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="2" >
+ <widget class="QPushButton" name="changeBackup" >
+ <property name="text" >
+ <string>Change</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item row="5" column="1" >
+ <widget class="QCheckBox" name="checkBoxCache" >
+ <property name="toolTip" >
+ <string>Rockbox Utility stores copies of Rockbox it has downloaded on the local hard disk to save network traffic. If your local copy is no longer working, tick this box to download a fresh copy.</string>
+ </property>
+ <property name="text" >
+ <string>&amp;Don't use locally cached copy</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources>
diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp
index f9fbd48568..187e369d32 100644
--- a/rbutil/rbutilqt/rbutilqt.cpp
+++ b/rbutil/rbutilqt/rbutilqt.cpp
@@ -465,16 +465,37 @@ bool RbUtilQt::installAuto()
QString myversion = "r" + versmap.value("bleed_rev");
//! check if rockbox is already installed
- if(QDir(settings->mountpoint() + "/.rockbox").exists())
+ QString rbVersion = installedVersion(settings->mountpoint());
+ if(rbVersion != "")
{
if(QMessageBox::question(this, tr("Installed Rockbox detected"),
tr("Rockbox installation detected. Do you want to backup first?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
{
- QString backupName = QFileDialog::getSaveFileName(this,"Select Backup Filename",settings->mountpoint());
- logger->show();
+ logger->addItem(tr("Beginning Backup..."),LOGINFO);
+ QString backupName = settings->mountpoint() + ".backup/rockbox-backup-"+rbVersion+".zip";
+
+ //! create dir, if it doesnt exist
+ QFileInfo backupFile(backupName);
+ if(!QDir(backupFile.path()).exists())
+ {
+ QDir a;
+ a.mkpath(backupFile.path());
+ }
+
+ //! create backup
RbZip backup;
- backup.createZip(backupName,settings->mountpoint() + "/.rockbox",logger);
+ connect(&backup,SIGNAL(zipProgress(int,int)),this,SLOT(updateDataReadProgress(int,int)));
+ if(backup.createZip(backupName,settings->mountpoint() + "/.rockbox") == Zip::Ok)
+ {
+ logger->addItem(tr("Backup successfull"),LOGOK);
+ }
+ else
+ {
+ logger->addItem(tr("Backup failed!"),LOGERROR);
+ logger->abort();
+ return false;
+ }
}
}
@@ -493,10 +514,17 @@ bool RbUtilQt::installAuto()
return true;
}
+void RbUtilQt::updateDataReadProgress(int read, int total)
+{
+ logger->setProgressMax(total);
+ logger->setProgressValue(read);
+ //qDebug() << "progress:" << read << "/" << total;
+
+}
+
void RbUtilQt::install()
{
- Install *installWindow = new Install(this);
- installWindow->setSettings(settings);
+ Install *installWindow = new Install(settings,this);
buildInfo.open();
QSettings info(buildInfo.fileName(), QSettings::IniFormat, this);
diff --git a/rbutil/rbutilqt/rbutilqt.h b/rbutil/rbutilqt/rbutilqt.h
index 76d05c1175..8de5ea0113 100644
--- a/rbutil/rbutilqt/rbutilqt.h
+++ b/rbutil/rbutilqt/rbutilqt.h
@@ -107,6 +107,7 @@ class RbUtilQt : public QMainWindow
void updateInfo(void);
void updateTabs(int);
+ void updateDataReadProgress(int read, int total);
};
#endif
diff --git a/rbutil/rbutilqt/rbzip.cpp b/rbutil/rbutilqt/rbzip.cpp
index 23abef89b9..def838dec4 100644
--- a/rbutil/rbutilqt/rbzip.cpp
+++ b/rbutil/rbutilqt/rbzip.cpp
@@ -21,14 +21,12 @@
#include <QtCore>
-Zip::ErrorCode RbZip::createZip(QString zip,QString dir,ProgressloggerInterface *dp)
+Zip::ErrorCode RbZip::createZip(QString zip,QString dir)
{
- m_logger = dp;
Zip::ErrorCode error = Ok;
m_curEntry = 1;
- int numEntrys=0;
+ m_numEntrys=0;
- m_logger->addItem(tr("Creating Backup: %1").arg(zip),LOGINFO);
QCoreApplication::processEvents();
// get number of entrys in dir
@@ -36,10 +34,10 @@ Zip::ErrorCode RbZip::createZip(QString zip,QString dir,ProgressloggerInterface
while (it.hasNext())
{
it.next();
- numEntrys++;
+ m_numEntrys++;
QCoreApplication::processEvents();
}
- m_logger->setProgressMax(numEntrys);
+
//! create zip
error = Zip::createArchive(zip);
@@ -54,13 +52,13 @@ Zip::ErrorCode RbZip::createZip(QString zip,QString dir,ProgressloggerInterface
//! close zip
error = Zip::closeArchive();
- return error;
+ return error;
}
void RbZip::progress()
{
m_curEntry++;
- m_logger->setProgressValue(m_curEntry);
+ emit zipProgress(m_curEntry,m_numEntrys);
QCoreApplication::processEvents(); // update UI
}
diff --git a/rbutil/rbutilqt/rbzip.h b/rbutil/rbutilqt/rbzip.h
index faf3ce7f4c..da535fdfda 100644
--- a/rbutil/rbutilqt/rbzip.h
+++ b/rbutil/rbutilqt/rbzip.h
@@ -23,19 +23,20 @@
#include <QtCore>
#include "zip/zip.h"
-#include "progressloggerinterface.h"
-
class RbZip : public QObject, public Zip
{
Q_OBJECT
public:
- Zip::ErrorCode createZip(QString zip,QString dir,ProgressloggerInterface *dp);
+ Zip::ErrorCode createZip(QString zip,QString dir);
virtual void progress();
-
+
+ signals:
+ void zipProgress(int, int);
+
private:
int m_curEntry;
- ProgressloggerInterface *m_logger;
+ int m_numEntrys;
};
#endif
diff --git a/rbutil/rbutilqt/utils.cpp b/rbutil/rbutilqt/utils.cpp
index 4fc863677c..a552b5cd5e 100644
--- a/rbutil/rbutilqt/utils.cpp
+++ b/rbutil/rbutilqt/utils.cpp
@@ -134,3 +134,26 @@ QUrl systemProxy(void)
return QUrl("");
#endif
}
+
+QString installedVersion(QString mountpoint)
+{
+ // read rockbox-info.txt
+ QFile info(mountpoint +"/.rockbox/rockbox-info.txt");
+ if(!info.open(QIODevice::ReadOnly))
+ {
+ return "";
+ }
+
+ QString target, features,version;
+ while (!info.atEnd()) {
+ QString line = info.readLine();
+
+ if(line.contains("Version:"))
+ {
+ return line.remove("Version:").trimmed();
+ }
+ }
+ info.close();
+ return "";
+}
+
diff --git a/rbutil/rbutilqt/utils.h b/rbutil/rbutilqt/utils.h
index 8ca782fc05..9b0b026921 100644
--- a/rbutil/rbutilqt/utils.h
+++ b/rbutil/rbutilqt/utils.h
@@ -28,6 +28,7 @@ bool recRmdir( const QString &dirName );
QString resolvePathCase(QString path);
QUrl systemProxy(void);
+QString installedVersion(QString mountpoint);
#endif