NOISSUE do not try to restore file permissions when importing modpacks
This commit is contained in:
parent
2a81e21f5e
commit
50b8412a26
@ -99,7 +99,7 @@ void InstanceImportTask::extractAndTweak()
|
|||||||
QDir extractDir(m_stagingPath);
|
QDir extractDir(m_stagingPath);
|
||||||
qDebug() << "Attempting to create instance from" << m_archivePath;
|
qDebug() << "Attempting to create instance from" << m_archivePath;
|
||||||
|
|
||||||
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, m_archivePath, extractDir.absolutePath());
|
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractDir, m_archivePath, extractDir.absolutePath(), MMCZip::Option::NoPermissions);
|
||||||
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &InstanceImportTask::extractFinished);
|
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &InstanceImportTask::extractFinished);
|
||||||
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &InstanceImportTask::extractAborted);
|
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &InstanceImportTask::extractAborted);
|
||||||
m_extractFutureWatcher.setFuture(m_extractFuture);
|
m_extractFutureWatcher.setFuture(m_extractFuture);
|
||||||
|
@ -45,11 +45,6 @@ bool copyData(QIODevice &inFile, QIODevice &outFile)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList MMCZip::extractDir(QString fileCompressed, QString dir)
|
|
||||||
{
|
|
||||||
return JlCompress::extractDir(fileCompressed, dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool compressFile(QuaZip *zip, QString fileName, QString fileDest)
|
bool compressFile(QuaZip *zip, QString fileName, QString fileDest)
|
||||||
{
|
{
|
||||||
if (!zip)
|
if (!zip)
|
||||||
@ -394,7 +389,7 @@ bool removeFile(QStringList listFile)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fileDest)
|
bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fileDest, MMCZip::Options opts)
|
||||||
{
|
{
|
||||||
if(!zip)
|
if(!zip)
|
||||||
return false;
|
return false;
|
||||||
@ -409,7 +404,6 @@ bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fi
|
|||||||
if (!inFile.open(QIODevice::ReadOnly) || inFile.getZipError() != UNZ_OK)
|
if (!inFile.open(QIODevice::ReadOnly) || inFile.getZipError() != UNZ_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Controllo esistenza cartella file risultato
|
|
||||||
QDir curDir;
|
QDir curDir;
|
||||||
if (fileDest.endsWith('/'))
|
if (fileDest.endsWith('/'))
|
||||||
{
|
{
|
||||||
@ -433,7 +427,7 @@ bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fi
|
|||||||
QFile::Permissions srcPerm = info.getPermissions();
|
QFile::Permissions srcPerm = info.getPermissions();
|
||||||
if (fileDest.endsWith('/') && QFileInfo(fileDest).isDir())
|
if (fileDest.endsWith('/') && QFileInfo(fileDest).isDir())
|
||||||
{
|
{
|
||||||
if (srcPerm != 0)
|
if (!opts.testFlag(Option::NoPermissions) && srcPerm != 0)
|
||||||
{
|
{
|
||||||
QFile(fileDest).setPermissions(srcPerm);
|
QFile(fileDest).setPermissions(srcPerm);
|
||||||
}
|
}
|
||||||
@ -460,14 +454,14 @@ bool MMCZip::extractFile(QuaZip *zip, const QString &fileName, const QString &fi
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (srcPerm != 0)
|
if (!opts.testFlag(Option::NoPermissions) && srcPerm != 0)
|
||||||
{
|
{
|
||||||
outFile.setPermissions(srcPerm);
|
outFile.setPermissions(srcPerm);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target)
|
QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QString &target, MMCZip::Options opts)
|
||||||
{
|
{
|
||||||
QDir directory(target);
|
QDir directory(target);
|
||||||
QStringList extracted;
|
QStringList extracted;
|
||||||
@ -488,7 +482,7 @@ QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QSt
|
|||||||
{
|
{
|
||||||
absFilePath += "/";
|
absFilePath += "/";
|
||||||
}
|
}
|
||||||
if (!extractFile(zip, "", absFilePath))
|
if (!MMCZip::extractFile(zip, "", absFilePath, opts))
|
||||||
{
|
{
|
||||||
removeFile(extracted);
|
removeFile(extracted);
|
||||||
return QStringList();
|
return QStringList();
|
||||||
@ -497,3 +491,13 @@ QStringList MMCZip::extractSubDir(QuaZip *zip, const QString & subdir, const QSt
|
|||||||
} while (zip->goToNextFile());
|
} while (zip->goToNextFile());
|
||||||
return extracted;
|
return extracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList MMCZip::extractDir(QString fileCompressed, QString dir, MMCZip::Options opts)
|
||||||
|
{
|
||||||
|
QuaZip zip(fileCompressed);
|
||||||
|
if (!zip.open(QuaZip::mdUnzip))
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return MMCZip::extractSubDir(&zip, "", dir, opts);
|
||||||
|
}
|
||||||
|
@ -49,16 +49,6 @@ namespace MMCZip
|
|||||||
*/
|
*/
|
||||||
bool MULTIMC_LOGIC_EXPORT createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod>& mods);
|
bool MULTIMC_LOGIC_EXPORT createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod>& mods);
|
||||||
|
|
||||||
/**
|
|
||||||
* Extract a whole archive.
|
|
||||||
*
|
|
||||||
* \param fileCompressed The name of the archive.
|
|
||||||
* \param dir The directory to extract to, the current directory if
|
|
||||||
* left empty.
|
|
||||||
* \return The list of the full paths of the files extracted, empty on failure.
|
|
||||||
*/
|
|
||||||
QStringList MULTIMC_LOGIC_EXPORT extractDir(QString fileCompressed, QString dir = QString());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a single file in archive by file name (not path)
|
* Find a single file in archive by file name (not path)
|
||||||
*
|
*
|
||||||
@ -74,15 +64,31 @@ namespace MMCZip
|
|||||||
*/
|
*/
|
||||||
bool MULTIMC_LOGIC_EXPORT findFilesInZip(QuaZip * zip, const QString & what, QStringList & result, const QString &root = QString());
|
bool MULTIMC_LOGIC_EXPORT findFilesInZip(QuaZip * zip, const QString & what, QStringList & result, const QString &root = QString());
|
||||||
|
|
||||||
|
enum Option {
|
||||||
|
NoPermissions = 1
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(Options, Option)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract a single file to a destination
|
* Extract a single file to a destination
|
||||||
*
|
*
|
||||||
* \return true if it succeeds
|
* \return true if it succeeds
|
||||||
*/
|
*/
|
||||||
bool MULTIMC_LOGIC_EXPORT extractFile(QuaZip *zip, const QString &fileName, const QString &fileDest);
|
bool MULTIMC_LOGIC_EXPORT extractFile(QuaZip *zip, const QString &fileName, const QString &fileDest, Options opts = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract a subdirectory from an archive
|
* Extract a subdirectory from an archive
|
||||||
*/
|
*/
|
||||||
QStringList MULTIMC_LOGIC_EXPORT extractSubDir(QuaZip *zip, const QString & subdir, const QString &target);
|
QStringList MULTIMC_LOGIC_EXPORT extractSubDir(QuaZip *zip, const QString & subdir, const QString &target, Options opts = 0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract a whole archive.
|
||||||
|
*
|
||||||
|
* \param fileCompressed The name of the archive.
|
||||||
|
* \param dir The directory to extract to, the current directory if left empty.
|
||||||
|
* \param opts Extra options.
|
||||||
|
* \return The list of the full paths of the files extracted, empty on failure.
|
||||||
|
*/
|
||||||
|
QStringList MULTIMC_LOGIC_EXPORT extractDir(QString fileCompressed, QString dir, Options opts = 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user