mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-18 01:22:38 -05:00
rbutil: improve the backup function.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17463 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9c54187678
commit
d24eb9e461
9 changed files with 203 additions and 66 deletions
|
|
@ -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())
|
||||
{
|
||||
QString backupName = QFileDialog::getSaveFileName(this,"Select Backup Filename",settings->mountpoint());
|
||||
logger->show();
|
||||
RbZip backup;
|
||||
backup.createZip(backupName,settings->mountpoint() + "/.rockbox",logger);
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,12 +31,13 @@ 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);
|
||||
void updateDataReadProgress(int read, int total);
|
||||
void changeBackupPath();
|
||||
|
||||
private:
|
||||
Ui::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>&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>&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>&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><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt; font-weight:600;">Backup Location:</span></p></body></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>&Don't use locally cached copy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ class RbUtilQt : public QMainWindow
|
|||
void updateInfo(void);
|
||||
void updateTabs(int);
|
||||
|
||||
void updateDataReadProgress(int read, int total);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 "";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ bool recRmdir( const QString &dirName );
|
|||
QString resolvePathCase(QString path);
|
||||
|
||||
QUrl systemProxy(void);
|
||||
QString installedVersion(QString mountpoint);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue