1
0
Fork 0

Launcher: Install-scenery dialog supports .zips

Use the improved Simgear archive support to allow the WS2.0 zips
to be extracted
This commit is contained in:
James Turner 2018-07-04 11:36:30 +01:00
parent 728a5b13db
commit ab5342888b
2 changed files with 15 additions and 12 deletions

View file

@ -37,11 +37,11 @@
#include <simgear/io/untar.hxx> #include <simgear/io/untar.hxx>
class SceneryExtractor : public simgear::TarExtractor class SceneryExtractor : public simgear::ArchiveExtractor
{ {
public: public:
SceneryExtractor(const SGPath& root) : SceneryExtractor(const SGPath& root) :
TarExtractor(root) ArchiveExtractor(root)
{} {}
protected: protected:
@ -88,7 +88,8 @@ public:
f.open(QIODevice::ReadOnly); f.open(QIODevice::ReadOnly);
QByteArray firstData = f.read(8192); QByteArray firstData = f.read(8192);
if (!simgear::TarExtractor::isTarData((uint8_t*) firstData.data(), firstData.count())) { auto archiveType = simgear::ArchiveExtractor::determineType((uint8_t*) firstData.data(), firstData.count());
if (archiveType == simgear::ArchiveExtractor::Invalid) {
emit extractionError(path,tr("file does not appear to be a scenery archive.")); emit extractionError(path,tr("file does not appear to be a scenery archive."));
m_error = true; m_error = true;
return; return;
@ -112,7 +113,7 @@ private:
void extractNextArchive() void extractNextArchive()
{ {
SGPath root(m_extractDir.toStdString()); SGPath root(m_extractDir.toStdString());
m_untar.reset(new SceneryExtractor(root)); m_archive.reset(new SceneryExtractor(root));
QString path = m_remainingPaths.front(); QString path = m_remainingPaths.front();
m_remainingPaths.pop_front(); m_remainingPaths.pop_front();
@ -126,17 +127,18 @@ private:
while (!f.atEnd()) { while (!f.atEnd()) {
QByteArray bytes = f.read(4 * 1024 * 1024); QByteArray bytes = f.read(4 * 1024 * 1024);
m_untar->extractBytes(bytes.constData(), bytes.size()); m_archive->extractBytes((const uint8_t*) bytes.constData(), bytes.size());
m_bytesRead += bytes.size(); m_bytesRead += bytes.size();
if (m_untar->hasError()) { if (m_archive->hasError()) {
break; break;
} }
emit progress((m_bytesRead * 100) / m_totalBytes); emit progress((m_bytesRead * 100) / m_totalBytes);
} }
if (m_untar->hasError() || !m_untar->isAtEndOfArchive()) { m_archive->flush();
if (m_archive->hasError() || !m_archive->isAtEndOfArchive()) {
emit extractionError(path, tr("unarchiving failed")); emit extractionError(path, tr("unarchiving failed"));
m_error = true; m_error = true;
// try to clean up? // try to clean up?
@ -145,7 +147,7 @@ private:
QString m_extractDir; QString m_extractDir;
QStringList m_remainingPaths; QStringList m_remainingPaths;
std::unique_ptr<simgear::TarExtractor> m_untar; std::unique_ptr<simgear::ArchiveExtractor> m_archive;
bool m_error; bool m_error;
quint64 m_totalBytes; quint64 m_totalBytes;
quint64 m_bytesRead; quint64 m_bytesRead;
@ -243,7 +245,7 @@ void InstallSceneryDialog::pickFiles()
{ {
QStringList downloads = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation); QStringList downloads = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation);
QStringList files = QFileDialog::getOpenFileNames(this, tr("Choose scenery to install"), QStringList files = QFileDialog::getOpenFileNames(this, tr("Choose scenery to install"),
downloads.first(), "*.tar *.gz *.tgz"); downloads.first(), "Compressed data (*.tar *.gz *.tgz *.zip)");
if (!files.isEmpty()) { if (!files.isEmpty()) {
QDir d(m_downloadDir); QDir d(m_downloadDir);
if (!d.exists("Scenery")) { if (!d.exists("Scenery")) {

View file

@ -201,14 +201,15 @@ Item {
height: Math.max(installTarballText.implicitHeight, installTarballButton.height) height: Math.max(installTarballText.implicitHeight, installTarballButton.height)
Button { Button {
id: installTarballButton id: installTarballButton
text: "Install add-on scenery" text: qsTr("Install add-on scenery")
onClicked: { onClicked: {
var path = _addOns.installCustomScenery(); var path = _addOns.installCustomScenery();
if (path !== "") { if (path !== "") {
// insert into scenery paths if not already present // insert into scenery paths if not already present
for (var p in _addOns.sceneryPaths) { var sceneryPaths = _addOns.sceneryPaths
if (p === path) for (var i = 0; i < sceneryPaths.length; i++) {
if (sceneryPaths[i] === path)
return; // found, we are are done return; // found, we are are done
} }