| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/ccpro/zipdatasource.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "zipdatasource.h"cxx . . $ `<file>/src/core/ccpro/zipdatasource.h`/ |
| 5 | |
| 6 | #include <QByteArray> |
| 7 | #include <QIODevice> |
| 8 | #include <QString> |
| 9 | #include <algorithm> |
| 10 | #include <format> |
| 11 | #include <iterator> |
| 12 | #include <quazip.h> |
| 13 | #include <quazipfile.h> |
| 14 | #include <stdexcept> |
| 15 | |
| 16 | ZipDataSourcecxx . . $ ZipDataSource#::ZipDataSourcecxx . . $ ZipDataSource#ZipDataSource(769d1bd79eb25b11).(stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# const &path) noexcept |
| 17 | : path_cxx . . $ ZipDataSource#path_.(path) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | stdcxx . . $ std/::stringcxx . . $ std/string# ZipDataSourcecxx . . $ ZipDataSource#::sourcecxx . . $ ZipDataSource#source(219584694fe2b248).() const |
| 22 | { |
| 23 | return path_cxx . . $ ZipDataSource#path_..stringcxx . . $ std/filesystem/__cxx11/path#string(219584694fe2b248).(); |
| 24 | } |
| 25 | |
| 26 | bool ZipDataSourcecxx . . $ ZipDataSource#::readcxx . . $ ZipDataSource#read(6cf0d5dcdcb5ad06).(stdcxx . . $ std/::stringcxx . . $ std/string# const &internalDataPath, |
| 27 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<char> &data) |
| 28 | { |
| 29 | if (!internalDataPath.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) { |
| 30 | QuaZipcxx . . $ QuaZip# zipcxx . . $ QuaZip#QuaZip(3520e46b33348bf6).(QStringcxx . . $ QString#::fromStdStringcxx . . $ QString#fromStdString(24a2e9bdf24626eb).(sourcecxx . . $ ZipDataSource#source(219584694fe2b248).())); |
| 31 | if (zip.opencxx . . $ QuaZip#open(fd0432b046ebdc00).(QuaZipcxx . . $ QuaZip#::mdUnzipcxx . . $ QuaZip#mdUnzip.)) { |
| 32 | if (zip.setCurrentFilecxx . . $ QuaZip#setCurrentFile(9b6ab16de944193e).(QStringcxx . . $ QString#::fromStdStringcxx . . $ QString#fromStdString(24a2e9bdf24626eb).(internalDataPath))) { |
| 33 | |
| 34 | QuaZipFilecxx . . $ QuaZipFile# filecxx . . $ QuaZipFile#QuaZipFile(32ccc81e403473f6).(&zip); |
| 35 | if (file.opencxx . . $ QuaZipFile#open(da34f43c1eae080c).(QIODevicecxx . . $ QFlags#QFlags(93d577a3e9528307).::ReadOnlycxx . . $ QIODeviceBase#ReadOnly.)) { |
| 36 | |
| 37 | data.clearcxx . . $ std/vector#clear(ced63f7c635d850d).(); |
| 38 | auto fileData = file.readAllcxx . . $ QIODevice#readAll(b3c286cec66e09f4).(); |
| 39 | stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4).(fileData.cbegincxx . . $ QByteArray#cbegin(ba32b354807b2b81).(), fileData.cendcxx . . $ QByteArray#cend(ba32b354807b2b81).(), stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(data)); |
| 40 | |
| 41 | file.closecxx . . $ QuaZipFile#close(49f6e7a06ebc5aa8).(); |
| 42 | zip.closecxx . . $ QuaZip#close(49f6e7a06ebc5aa8).(); |
| 43 | return true; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | zip.closecxx . . $ QuaZip#close(49f6e7a06ebc5aa8).(); |
| 48 | } |
| 49 | else { |
| 50 | throw stdcxx . . $ std/::runtime_errorcxx . . $ std/runtime_error#(stdcxx . . $ std/::formatcxx . . $ std/format(7a9e6f4918cdc192).("Failed to open file {}"cxx . . $ std/basic_format_string#basic_format_string(edcd8b2679e9bd1a)., sourcecxx . . $ ZipDataSource#source(219584694fe2b248).())); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | return false; |
| 55 | } |