2012-06-25 22:24:58 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 by Dominik Riebeling
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-01-27 11:01:56 +00:00
|
|
|
#include <QThread>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QFileDialog>
|
2012-06-25 22:24:58 +00:00
|
|
|
#include "backupdialog.h"
|
|
|
|
#include "ui_backupdialogfrm.h"
|
|
|
|
#include "rbsettings.h"
|
|
|
|
#include "progressloggergui.h"
|
|
|
|
#include "ziputil.h"
|
|
|
|
#include "rockboxinfo.h"
|
2013-11-03 10:08:18 +00:00
|
|
|
#include "Logger.h"
|
2012-06-25 22:24:58 +00:00
|
|
|
|
|
|
|
class BackupSizeThread : public QThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void run(void);
|
|
|
|
void setPath(QString p) { m_path = p; }
|
|
|
|
qint64 currentSize(void) { return m_currentSize; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_path;
|
|
|
|
qint64 m_currentSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void BackupSizeThread::run(void)
|
|
|
|
{
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "Thread started, calculating" << m_path;
|
2012-06-25 22:24:58 +00:00
|
|
|
m_currentSize = 0;
|
|
|
|
|
|
|
|
QDirIterator it(m_path, QDirIterator::Subdirectories);
|
|
|
|
while(it.hasNext()) {
|
|
|
|
m_currentSize += QFileInfo(it.next()).size();
|
|
|
|
}
|
2013-11-03 10:08:18 +00:00
|
|
|
LOG_INFO() << "Thread done, sum:" << m_currentSize;
|
2012-06-25 22:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BackupDialog::BackupDialog(QWidget* parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
|
|
m_thread = new BackupSizeThread();
|
|
|
|
connect(m_thread, SIGNAL(finished()), this, SLOT(updateSizeInfo()));
|
|
|
|
connect(m_thread, SIGNAL(terminated()), this, SLOT(updateSizeInfo()));
|
|
|
|
|
|
|
|
connect(ui.buttonCancel, SIGNAL(clicked()), this, SLOT(close()));
|
|
|
|
connect(ui.buttonCancel, SIGNAL(clicked()), m_thread, SLOT(quit()));
|
|
|
|
connect(ui.buttonChange, SIGNAL(clicked()), this, SLOT(changeBackupPath()));
|
|
|
|
connect(ui.buttonBackup, SIGNAL(clicked()), this, SLOT(backup()));
|
|
|
|
|
|
|
|
ui.backupSize->setText(tr("Installation size: calculating ..."));
|
|
|
|
m_mountpoint = RbSettings::value(RbSettings::Mountpoint).toString();
|
|
|
|
|
|
|
|
m_backupName = RbSettings::value(RbSettings::BackupPath).toString();
|
|
|
|
if(m_backupName.isEmpty()) {
|
|
|
|
m_backupName = m_mountpoint;
|
|
|
|
}
|
|
|
|
RockboxInfo info(m_mountpoint);
|
|
|
|
m_backupName += "/.backup/rockbox-backup-" + info.version() + ".zip";
|
|
|
|
ui.backupLocation->setText(QDir::toNativeSeparators(m_backupName));
|
|
|
|
|
|
|
|
m_thread->setPath(m_mountpoint + "/.rockbox");
|
|
|
|
m_thread->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BackupDialog::changeBackupPath(void)
|
|
|
|
{
|
|
|
|
QString backupString = QFileDialog::getSaveFileName(this,
|
|
|
|
tr("Select Backup Filename"), m_backupName, "*.zip");
|
|
|
|
// only update if a filename was entered, ignore if cancelled
|
|
|
|
if(!backupString.isEmpty()) {
|
|
|
|
m_backupName = backupString;
|
|
|
|
ui.backupLocation->setText(QDir::toNativeSeparators(m_backupName));
|
|
|
|
RbSettings::setValue(RbSettings::BackupPath, QFileInfo(m_backupName).absolutePath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BackupDialog::updateSizeInfo(void)
|
|
|
|
{
|
|
|
|
double size = m_thread->currentSize() / (1024 * 1024);
|
|
|
|
QString unit = "MiB";
|
|
|
|
|
|
|
|
if(size > 1024) {
|
|
|
|
size /= 1024;
|
|
|
|
unit = "GiB";
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.backupSize->setText(tr("Installation size: %L1 %2").arg(size, 0, 'g', 4).arg(unit));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BackupDialog::backup(void)
|
|
|
|
{
|
2012-06-30 09:58:45 +00:00
|
|
|
if(QFileInfo(m_backupName).isFile()) {
|
|
|
|
if(QMessageBox::warning(this, tr("File exists"),
|
|
|
|
tr("The selected backup file already exists. Overwrite?"),
|
|
|
|
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-06-25 22:24:58 +00:00
|
|
|
m_logger = new ProgressLoggerGui(this);
|
|
|
|
connect(m_logger, SIGNAL(closed()), this, SLOT(close()));
|
|
|
|
m_logger->show();
|
|
|
|
m_logger->addItem(tr("Starting backup ..."),LOGINFO);
|
|
|
|
QCoreApplication::processEvents();
|
|
|
|
|
|
|
|
// create dir, if it doesnt exist
|
|
|
|
QFileInfo backupFile(m_backupName);
|
|
|
|
if(!QDir(backupFile.path()).exists())
|
|
|
|
{
|
|
|
|
QDir a;
|
|
|
|
a.mkpath(backupFile.path());
|
|
|
|
}
|
|
|
|
|
|
|
|
// create backup
|
|
|
|
ZipUtil zip(this);
|
|
|
|
connect(&zip, SIGNAL(logProgress(int, int)), m_logger, SLOT(setProgress(int, int)));
|
|
|
|
connect(&zip, SIGNAL(logItem(QString, int)), m_logger, SLOT(addItem(QString, int)));
|
|
|
|
zip.open(m_backupName, QuaZip::mdCreate);
|
|
|
|
|
|
|
|
QString mp = m_mountpoint + "/.rockbox";
|
|
|
|
if(zip.appendDirToArchive(mp, m_mountpoint)) {
|
|
|
|
m_logger->addItem(tr("Backup successful."), LOGINFO);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_logger->addItem(tr("Backup failed!"), LOGERROR);
|
|
|
|
}
|
|
|
|
zip.close();
|
|
|
|
m_logger->setFinished();
|
|
|
|
}
|
|
|
|
|