-// EmuFront
-// Copyright 2010 Mikko Keinänen
-//
-// This file is part of EmuFront.
-//
-//
-// EmuFront is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as published by
-// the Free Software Foundation and appearing in the file gpl.txt included in the
-// packaging of this file.
-//
-// EmuFront is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
-
+/*
+** EmuFront
+** Copyright 2010 Mikko Keinänen
+**
+** This file is part of EmuFront.
+**
+**
+** EmuFront is free software: you can redistribute it and/or modify
+** it under the terms of the GNU General Public License version 2 as published by
+** the Free Software Foundation and appearing in the file gpl.txt included in the
+** packaging of this file.
+**
+** EmuFront is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
+*/
#include <QDir>
#include <QDebug>
#include <QProcess>
#include <QProgressDialog>
#include "fileutil.h"
#include "zlib.h" /* crc32 */
-#include "../exceptions/emufrontexception.h"
-#include "../dataobjects/setup.h"
-#include "../dataobjects/mediaimage.h"
-#include "../dataobjects/mediaimagecontainer.h"
-#include "../dataobjects/mediatype.h"
-#include "../dataobjects/platform.h"
-#include "../db/dbmediaimagecontainer.h"
+#include "emufrontexception.h"
+#include "setup.h"
+#include "mediaimage.h"
+#include "mediaimagecontainer.h"
+#include "mediatype.h"
+#include "platform.h"
+#include "dbmediaimagecontainer.h"
#include "unziphelper.h"
FileUtil::FileUtil(QObject *parent) : QObject(parent)
/* Throws EmuFrontException */
int FileUtil::scanFilePath(FilePathObject *fp,
QStringList filters, DbMediaImageContainer *dbMic,
- QProgressDialog &progressDialog)
+ QProgressDialog *progressDialog)
{
if (!fp->getSetup()){
throw EmuFrontException(tr("Setup not available with %1.").arg(fp->getName()));
QFileInfoList list = dir.entryInfoList();
//qDebug() << "We have " << list.count() << " files to go through.";
QList<MediaImageContainer*> containers;
- progressDialog.setMinimum(0);
- progressDialog.setMaximum(list.size());
- for (int i = 0; i < list.size(); ++i)
- {
- progressDialog.setValue(i);
- if (progressDialog.wasCanceled())
- break;
- QFileInfo fileInfo = list.at(i);
- //qDebug() << QString("%1 %2").arg(fileInfo.size(), 10).arg(fileInfo.absoluteFilePath());
+ try {
+ progressDialog->setMinimum(0);
+ progressDialog->setMaximum(list.size());
+ for (int i = 0; i < list.size(); ++i)
+ {
+ progressDialog->setValue(i);
+ if (progressDialog->wasCanceled())
+ break;
+ QFileInfo fileInfo = list.at(i);
+ //qDebug() << QString("%1 %2").arg(fileInfo.size(), 10).arg(fileInfo.absoluteFilePath());
- //... and collect the contents of each archive
- QMap<QString, EmuFrontObject*> files = unzipHelper->listContents(fileInfo.absoluteFilePath(), fp);
+ //... and collect the contents of each archive
+ QMap<QString, EmuFrontObject*> files = unzipHelper->listContents(fileInfo.absoluteFilePath(), fp);
- if (files.count() > 0)
- {
- // read crc32 checksum for media image container
- quint32 crc = readCrc32(fileInfo.absoluteFilePath());
- FilePathObject *fpo = new FilePathObject(*fp);
- MediaImageContainer *con = new MediaImageContainer (
- fileInfo.fileName(),
- QString("%1").arg(crc, 0, 16),
- fileInfo.size(),
- files,
- fpo // we need a copy since MediaImageContainers are deleted and the original filepath object would get deleted also.
- );
- containers.append(con);
- ++count;
- //qDebug() << "We have " << containers.count() << " containers.";
+ if (files.count() > 0)
+ {
+ // read crc32 checksum for media image container
+ quint32 crc = readCrc32(fileInfo.absoluteFilePath());
+ FilePathObject *fpo = new FilePathObject(*fp);
+ MediaImageContainer *con = new MediaImageContainer (
+ fileInfo.fileName(),
+ QString("%1").arg(crc, 0, 16),
+ fileInfo.size(),
+ files,
+ fpo // we need a copy since MediaImageContainers are deleted and the original filepath object would get deleted also.
+ );
+ containers.append(con);
+ ++count;
+ //qDebug() << "We have " << containers.count() << " containers.";
- if (containers.count() >= MIC_BUFFER_SIZE) {
- //qDebug() << "We have " << containers.count() << " containers .. storing to db.";
- dbMic->storeContainers(containers, fp);
- qDeleteAll(containers);
- containers.clear();
- //qDebug() << "containers now: " << containers.count();
+ if (containers.count() >= MIC_BUFFER_SIZE) {
+ //qDebug() << "We have " << containers.count() << " containers .. storing to db.";
+ showDbUpdating(progressDialog);
+ dbMic->storeContainers(containers, fp);
+ hideDbUpdating(progressDialog);
+ qDeleteAll(containers);
+ containers.clear();
+ //qDebug() << "containers now: " << containers.count();
+ }
+ //qDebug() << "We have " << containers.size() << " containers.";
+ } // files.count() > 0
+ else {
+ qDebug() << "No files from container " << fileInfo.absoluteFilePath();
}
- //qDebug() << "We have " << containers.size() << " containers.";
- } // files.count() > 0
- else {
- qDebug() << "No files from container " << fileInfo.absoluteFilePath();
}
- }
- progressDialog.setValue(list.size());
- if (containers.count() > 0) {
- //qDebug() << "Storing the rest " << containers.count() << " containers.";
- dbMic->storeContainers(containers, fp);
+ progressDialog->setValue(list.size());
+ if (containers.count() > 0) {
+ //qDebug() << "Storing the rest " << containers.count() << " containers.";
+ //emit dbUpdateInProgress();
+ showDbUpdating(progressDialog);
+ dbMic->storeContainers(containers, fp);
+ hideDbUpdating(progressDialog);
+ //emit dbUpdateFinished();
+ qDeleteAll(containers);
+ containers.clear();
+ } } catch (EmuFrontException &e) { qDebug() << "Got exception " << e.what() << ", aborting & deleting created data objects.";
qDeleteAll(containers);
- containers.clear();
-
+ throw e;
}
//qDebug() << "Done scanning files!";
return count;
}
/* Uses crc32 from zlib.h to count crc32 checksum value */
+/* Throws EmuFrontException */
quint32 FileUtil::readCrc32(QString filePath)
{
// todo ... use some crc32 tool for this ... or maybe use md5 or something like that!!!
QString ext = filename.section('.', -1);
return supportedFileExtensions.contains(ext, Qt::CaseInsensitive);
}
+
+void FileUtil::showDbUpdating(QProgressDialog *progressDialog)
+{
+ qDebug() << "DB updating";
+ // TODO: the following is not currently working
+ progressDialog->setWindowTitle(tr("Updating DB... please wait!"));
+ progressDialog->setEnabled(false);
+}
+
+void FileUtil::hideDbUpdating(QProgressDialog *progressDialog)
+{
+ qDebug() << "DB update finished";
+ // TODO: the following is not currently working
+ progressDialog->setEnabled(true);
+ progressDialog->setWindowTitle(tr("Scanning files"));
+}
+