fix: bring back JAR Folder mods
what is this?
This commit is contained in:
parent
a8089b76c0
commit
c4cb7ddc4f
@ -73,6 +73,39 @@ bool MMCZip::mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &containe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MMCZip::compressDirFiles(QuaZip *zip, QString dir, QFileInfoList files)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto result = compressDirFiles(&zip, dir, files);
|
||||||
|
|
||||||
|
zip.close();
|
||||||
|
if(zip.getZipError()!=0) {
|
||||||
|
QFile::remove(fileCompressed);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// ours
|
// ours
|
||||||
bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod>& mods)
|
bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const QList<Mod>& mods)
|
||||||
{
|
{
|
||||||
@ -121,15 +154,22 @@ bool MMCZip::createModdedJar(QString sourceJarPath, QString targetJarPath, const
|
|||||||
}
|
}
|
||||||
else if (mod.type() == Mod::MOD_FOLDER)
|
else if (mod.type() == Mod::MOD_FOLDER)
|
||||||
{
|
{
|
||||||
|
// untested, but seems to be unused / not possible to reach
|
||||||
// FIXME: buggy - does not work with addedFiles
|
// FIXME: buggy - does not work with addedFiles
|
||||||
auto filename = mod.filename();
|
auto filename = mod.filename();
|
||||||
QString what_to_zip = filename.absoluteFilePath();
|
QString what_to_zip = filename.absoluteFilePath();
|
||||||
QDir dir(what_to_zip);
|
QDir dir(what_to_zip);
|
||||||
dir.cdUp();
|
dir.cdUp();
|
||||||
QString parent_dir = dir.absolutePath();
|
QString parent_dir = dir.absolutePath();
|
||||||
return false;
|
auto files = QFileInfoList();
|
||||||
// TODO: implement custom compressSubDir:
|
MMCZip::collectFileListRecursively(what_to_zip, nullptr, &files, nullptr);
|
||||||
if (!JlCompress::compressSubDir(&zipOut, what_to_zip, parent_dir, addedFiles))
|
|
||||||
|
for (auto e : files) {
|
||||||
|
if (addedFiles.contains(e.filePath()))
|
||||||
|
files.removeAll(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!MMCZip::compressDirFiles(&zipOut, parent_dir, files))
|
||||||
{
|
{
|
||||||
zipOut.close();
|
zipOut.close();
|
||||||
QFile::remove(targetJarPath);
|
QFile::remove(targetJarPath);
|
||||||
@ -345,29 +385,3 @@ bool MMCZip::collectFileListRecursively(const QString& rootDir, const QString& s
|
|||||||
}
|
}
|
||||||
return true;
|
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;
|
|
||||||
}
|
|
||||||
|
@ -34,6 +34,24 @@ namespace MMCZip
|
|||||||
bool mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained,
|
bool mergeZipFiles(QuaZip *into, QFileInfo from, QSet<QString> &contained,
|
||||||
const FilterFunction filter = nullptr);
|
const FilterFunction filter = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compress directory, by providing a list of files to compress
|
||||||
|
* \param zip target archive
|
||||||
|
* \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(QuaZip *zip, QString dir, QFileInfoList files);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* take a source jar, add mods to it, resulting in target jar
|
* take a source jar, add mods to it, resulting in target jar
|
||||||
*/
|
*/
|
||||||
@ -99,13 +117,4 @@ namespace MMCZip
|
|||||||
* \return true for success or false for failure
|
* \return true for success or false for failure
|
||||||
*/
|
*/
|
||||||
bool collectFileListRecursively(const QString &rootDir, const QString &subDir, QFileInfoList *files, FilterFunction excludeFilter);
|
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);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user