Skip to content

Commit

Permalink
Using KArchive to read tar.gz (doesn't work)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasaglia committed Nov 20, 2023
1 parent 5e3715c commit 9a7e831
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions src/gui/emoji/emoji_set_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include <QNetworkRequest>
#include <QDesktopServices>

#include "utils/tar.hpp"
#include <KTar>
#include <KCompressionDevice>

#include "emoji/emoji_set.hpp"
#include "glaxnimate_app.hpp"
#include "emoji_dialog.hpp"
Expand Down Expand Up @@ -200,15 +202,39 @@ void glaxnimate::emoji::EmojiSetDialog::download_selected()

QByteArray data = reply->readAll();
reply->close();

QDir output = d->sets[row].path;
glaxnimate::utils::tar::TapeArchive tar(data);
for ( const auto& entry : tar )
output.makeAbsolute();
qDebug() << reply->open(QIODevice::ReadOnly);
KCompressionDevice decompressed(reply, false, KCompressionDevice::GZip);
qDebug() << decompressed.open(QIODevice::ReadOnly);
KTar tar(&decompressed);
if ( !tar.open(QIODevice::ReadOnly) )
{
if ( !tar.errorString().isEmpty() )
d->set_download_status(row, "package-broken", tar.errorString());
else
d->set_download_status(row, "package-broken", tr("Could not open archive"));
d->ui.progress_bar->setVisible(false);
return;
}

for ( const auto& entry_name : tar.directory()->entries() )
{
if ( entry.path().startsWith(prefix_scalable) || entry.path().startsWith(prefix_raster) )
tar.extract(entry, output);
auto entry = tar.directory()->entry(entry_name);
qDebug() << entry_name << entry->name();
if ( entry_name.startsWith(prefix_scalable) || entry_name.startsWith(prefix_raster) )
{
tar.directory()->file(entry_name)->copyTo(output.path());
// QString output_file_path = output.absoluteFilePath(entry_name);
// output.mkpath(QFileInfo(entry_name).path());
// QFile output(output_file_path);
// output.open(QIODevice::WriteOnly);
// output.write(tar.directory()->file(entry_name)->data());
}
}
if ( !tar.error().isEmpty() )
d->set_download_status(row, "package-broken", tar.error());
if ( !tar.errorString().isEmpty() )
d->set_download_status(row, "package-broken", tar.errorString());
else if ( !output.exists() )
d->set_download_status(row, "package-broken", tr("Didn't download any files"));
else
Expand Down

0 comments on commit 9a7e831

Please sign in to comment.