4 #include "OSDaB-Zip/unzip.h"
5 #include "../exceptions/emufrontexception.h"
6 #include "../dataobjects/setup.h"
7 #include "../dataobjects/mediaimage.h"
8 #include "../dataobjects/mediaimagecontainer.h"
10 FileUtil::FileUtil(QObject *parent) : QObject(parent)
13 QList<MediaImageContainer*> FileUtil::scanFilePath(const FilePathObject *fp, QStringList filters)
15 QList<MediaImageContainer*> containers;
16 QDir dir(fp->getName());
17 if (!dir.exists() || !dir.isReadable())
18 throw EmuFrontException(tr("Directory %1 doesn't exists or isn't readable!").arg(fp->getName()));
20 dir.setFilter(QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::Readable);
22 if (filters.count() > 0) dir.setNameFilters(filters);
24 // we'll go through the filtered archive files...
25 QFileInfoList list = dir.entryInfoList();
26 for (int i = 0; i < list.size(); ++i)
28 QFileInfo fileInfo = list.at(i);
29 qDebug() << QString("%1 %2").arg(fileInfo.size(), 10).arg(fileInfo.absoluteFilePath());
32 //... and collect the contents of each archive
33 QList<MediaImage*> files = listContents(fileInfo.absoluteFilePath(), fp);
35 // if the archive contained supported file types we will create a media image container object
38 // - media image objects in a list
39 // - time created / updated
40 if (files.count() > 0)
42 MediaImageContainer *con = new MediaImageContainer();
43 containers.append(con);
46 /*foreach (EmuFrontFileObject *o, files)
48 qDebug() << o->getFilename();
54 QList<MediaImage*> FileUtil::listContents(const QString filePath, const FilePathObject *fp)
58 UnZip::ErrorCode ec = uz.openArchive(filePath);
60 throw EmuFrontException(tr("Error while opening zip-file %1, error code %2").arg(filePath).arg(ec));
62 Setup *sup = fp->getSetup();
63 QList<UnZip::ZipEntry> list = uz.entryList();
64 QList<MediaImage*> fileList;
65 foreach(UnZip::ZipEntry entry, list)
67 qDebug() << "We have an entry " << entry.filename
68 << "with crc32 " << entry.crc32
69 << " and file size " << entry.uncompressedSize;
71 if (isSupportedFile(entry.filename, sup->getSupportedFileTypeExtensions()))
73 MediaImage *effo = new MediaImage();
82 bool FileUtil::isSupportedFile(const QString filename, const QStringList supportedFileExtensions)
84 QString ext = filename.section('.', -1);
85 return (supportedFileExtensions.indexOf(ext) > -1);