fix: bring back instance exports
This commit is contained in:
parent
71516e6c72
commit
a8089b76c0
@ -311,3 +311,63 @@ bool MMCZip::extractFile(QString fileCompressed, QString file, QString target)
|
|||||||
}
|
}
|
||||||
return MMCZip::extractRelFile(&zip, file, target);
|
return MMCZip::extractRelFile(&zip, file, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MMCZip::collectFileListRecursively(const QString& rootDir, const QString& subDir, QFileInfoList *files,
|
||||||
|
MMCZip::FilterFunction excludeFilter) {
|
||||||
|
QDir rootDirectory(rootDir);
|
||||||
|
if (!rootDirectory.exists()) return false;
|
||||||
|
|
||||||
|
QDir directory;
|
||||||
|
if (subDir == nullptr)
|
||||||
|
directory = rootDirectory;
|
||||||
|
else
|
||||||
|
directory = QDir(subDir);
|
||||||
|
|
||||||
|
if (!directory.exists()) return false; // shouldn't ever happen
|
||||||
|
|
||||||
|
// recurse directories
|
||||||
|
QFileInfoList entries = directory.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden);
|
||||||
|
for (const auto& e: entries) {
|
||||||
|
if (!collectFileListRecursively(rootDir, e.filePath(), files, excludeFilter))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// collect files
|
||||||
|
entries = directory.entryInfoList(QDir::Files);
|
||||||
|
for (const auto& e: entries) {
|
||||||
|
QString relativeFilePath = rootDirectory.relativeFilePath(e.absoluteFilePath());
|
||||||
|
if (excludeFilter && excludeFilter(relativeFilePath)) {
|
||||||
|
qDebug() << "Skipping file " << relativeFilePath;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
files->append(e.filePath()); // we want the original paths for MMCZip::compressDirFiles
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MMCZip::compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files)
|
||||||
|
{
|
||||||
|
QuaZip zip(fileCompressed);
|
||||||
|
QDir().mkpath(QFileInfo(fileCompressed).absolutePath());
|
||||||
|
if(!zip.open(QuaZip::mdCreate)) {
|
||||||
|
QFile::remove(fileCompressed);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDir directory(dir);
|
||||||
|
if (!directory.exists()) return false;
|
||||||
|
|
||||||
|
for (auto e : files) {
|
||||||
|
auto filePath = directory.relativeFilePath(e.absoluteFilePath());
|
||||||
|
if( !JlCompress::compressFile(&zip, e.absoluteFilePath(), filePath)) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
zip.close();
|
||||||
|
if(zip.getZipError()!=0) {
|
||||||
|
QFile::remove(fileCompressed);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -90,4 +90,22 @@ namespace MMCZip
|
|||||||
*/
|
*/
|
||||||
bool extractFile(QString fileCompressed, QString file, QString dir);
|
bool extractFile(QString fileCompressed, QString file, QString dir);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Populate a QFileInfoList with a directory tree recursively, while allowing to excludeFilter what shouldn't be included.
|
||||||
|
* \param rootDir directory to start off
|
||||||
|
* \param subDir subdirectory, should be nullptr for first invocation
|
||||||
|
* \param files resulting list of QFileInfo
|
||||||
|
* \param excludeFilter function to excludeFilter which files shouldn't be included (returning true means to excude)
|
||||||
|
* \return true for success or false for failure
|
||||||
|
*/
|
||||||
|
bool collectFileListRecursively(const QString &rootDir, const QString &subDir, QFileInfoList *files, FilterFunction excludeFilter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compress directory, by providing a list of files to compress
|
||||||
|
* \param fileCompressed target archive file
|
||||||
|
* \param dir directory that will be compressed (to compress with relative paths)
|
||||||
|
* \param files list of files to compress
|
||||||
|
* \return true for success or false for failure
|
||||||
|
*/
|
||||||
|
bool compressDirFiles(QString fileCompressed, QString dir, QFileInfoList files);
|
||||||
}
|
}
|
||||||
|
@ -403,10 +403,13 @@ bool ExportInstanceDialog::doExport()
|
|||||||
|
|
||||||
auto & blocked = proxyModel->blockedPaths();
|
auto & blocked = proxyModel->blockedPaths();
|
||||||
using std::placeholders::_1;
|
using std::placeholders::_1;
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
auto files = QFileInfoList();
|
||||||
return false;
|
if (!MMCZip::collectFileListRecursively(m_instance->instanceRoot(), nullptr, &files,
|
||||||
// TODO Reimplement custom compressDir:
|
std::bind(&SeparatorPrefixTree<'/'>::covers, blocked, _1))) {
|
||||||
if (!JlCompress::compressDir(output, m_instance->instanceRoot(), name, std::bind(&SeparatorPrefixTree<'/'>::covers, blocked, _1)))
|
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!MMCZip::compressDirFiles(output, m_instance->instanceRoot(), files))
|
||||||
{
|
{
|
||||||
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user