move some functions from MMCZip to use libarchive
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@@ -57,6 +57,7 @@
|
||||
|
||||
#include "FileSystem.h"
|
||||
#include "PSaveFile.h"
|
||||
#include "archive/ArchiveReader.h"
|
||||
|
||||
using std::nullopt;
|
||||
using std::optional;
|
||||
@@ -244,36 +245,37 @@ void World::readFromFS(const QFileInfo& file)
|
||||
|
||||
void World::readFromZip(const QFileInfo& file)
|
||||
{
|
||||
QuaZip zip(file.absoluteFilePath());
|
||||
m_isValid = zip.open(QuaZip::mdUnzip);
|
||||
if (!m_isValid) {
|
||||
MMCZip::ArchiveReader r(file.absoluteFilePath());
|
||||
|
||||
if (m_isValid = r.collectFiles(); !m_isValid) {
|
||||
return;
|
||||
}
|
||||
auto location = MMCZip::findFolderOfFileInZip(&zip, "level.dat");
|
||||
m_isValid = !location.isEmpty();
|
||||
if (!m_isValid) {
|
||||
|
||||
QString path;
|
||||
const QString levelDat = "level.dat";
|
||||
for (auto filePath : r.getFiles()) {
|
||||
QFileInfo fi(filePath);
|
||||
if (fi.fileName().compare(levelDat, Qt::CaseInsensitive) == 0) {
|
||||
m_containerOffsetPath = filePath.chopped(levelDat.length());
|
||||
path = filePath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_isValid = !m_containerOffsetPath.isEmpty(); !m_isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto zippedFile = r.goToFile(path);
|
||||
if (m_isValid = !!zippedFile; !m_isValid) {
|
||||
return;
|
||||
}
|
||||
m_containerOffsetPath = location;
|
||||
QuaZipFile zippedFile(&zip);
|
||||
// read the install profile
|
||||
m_isValid = zip.setCurrentFile(location + "level.dat");
|
||||
m_levelDatTime = zippedFile->dateTime();
|
||||
if (!m_isValid) {
|
||||
return;
|
||||
}
|
||||
m_isValid = zippedFile.open(QIODevice::ReadOnly);
|
||||
QuaZipFileInfo64 levelDatInfo;
|
||||
zippedFile.getFileInfo(&levelDatInfo);
|
||||
auto modTime = levelDatInfo.getNTFSmTime();
|
||||
if (!modTime.isValid()) {
|
||||
modTime = levelDatInfo.dateTime;
|
||||
}
|
||||
m_levelDatTime = modTime;
|
||||
if (!m_isValid) {
|
||||
return;
|
||||
}
|
||||
loadFromLevelDat(zippedFile.readAll());
|
||||
zippedFile.close();
|
||||
loadFromLevelDat(zippedFile->readAll());
|
||||
}
|
||||
|
||||
bool World::install(const QString& to, const QString& name)
|
||||
@@ -284,10 +286,7 @@ bool World::install(const QString& to, const QString& name)
|
||||
}
|
||||
bool ok = false;
|
||||
if (m_containerFile.isFile()) {
|
||||
QuaZip zip(m_containerFile.absoluteFilePath());
|
||||
if (!zip.open(QuaZip::mdUnzip)) {
|
||||
return false;
|
||||
}
|
||||
MMCZip::ArchiveReader zip(m_containerFile.absoluteFilePath());
|
||||
ok = !MMCZip::extractSubDir(&zip, m_containerOffsetPath, finalPath);
|
||||
} else if (m_containerFile.isDir()) {
|
||||
QString from = m_containerFile.filePath();
|
||||
@@ -350,7 +349,7 @@ optional<QString> read_string(nbt::value& parent, const char* name)
|
||||
return nullopt;
|
||||
}
|
||||
auto& tag_str = namedValue.as<nbt::tag_string>();
|
||||
return QString::fromStdString(tag_str.get());
|
||||
return QString::fromUtf8(tag_str.get());
|
||||
} catch ([[maybe_unused]] const std::out_of_range& e) {
|
||||
// fallback for old world formats
|
||||
qWarning() << "String NBT tag" << name << "could not be found.";
|
||||
|
||||
Reference in New Issue
Block a user