Skip to content

Commit

Permalink
Extract 7z loading to it's own function
Browse files Browse the repository at this point in the history
This will unify 7z loading in all scenarios and it also fixes the search path in Linux, now the apps will always try to load 7z.so from LIBDIR/yacreader/7z.so, if it fails they'll try 7zip/7z.so
  • Loading branch information
luisangelsm committed Sep 15, 2024
1 parent bb36368 commit 6ccfc51
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
7 changes: 1 addition & 6 deletions YACReaderLibrary/library_creator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,7 @@ void LibraryCreator::run()
stopRunning = false;
canceled = false;
#if !defined use_unarr && !defined use_libarchive
// check for 7z lib
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
QLibrary *sevenzLib = new QLibrary(QString(LIBDIR) + "/7zip/7z.so");
#else
QLibrary *sevenzLib = new QLibrary(QCoreApplication::applicationDirPath() + "/utils/7z");
#endif
auto sevenzLib = YACReader::load7zLibrary();

if (!sevenzLib->load()) {
QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl;
Expand Down
7 changes: 1 addition & 6 deletions YACReaderLibrary/xml_info_library_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ void XMLInfoLibraryScanner::scanFolder(const QString &source, const QString &tar
void XMLInfoLibraryScanner::run()
{
#if !defined use_unarr && !defined use_libarchive
// check for 7z lib
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
QLibrary *sevenzLib = new QLibrary(QString(LIBDIR) + "/7zip/7z.so");
#else
QLibrary *sevenzLib = new QLibrary(QCoreApplication::applicationDirPath() + "/utils/7z");
#endif
auto sevenzLib = YACReader::load7zLibrary();

if (!sevenzLib->load()) {
QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl;
Expand Down
16 changes: 16 additions & 0 deletions common/yacreader_global.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "yacreader_global.h"

#include <QModelIndex>
#include <QLibrary>
#include <QCoreApplication>

using namespace YACReader;

Expand Down Expand Up @@ -119,3 +121,17 @@ void YACReader::iterate(const QModelIndex &index,
for (int i = 0; i < rows; ++i)
iterate(model->index(i, 0, index), model, iteration);
}

QLibrary *YACReader::load7zLibrary()
{
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
QFileInfo sevenzlibrary(QString(LIBDIR) + "/yacreader/7z.so");
if (sevenzlibrary.exists()) {
return new QLibrary(sevenzlibrary.absoluteFilePath());
} else {
retrun new QLibrary(QString(LIBDIR) + "/7zip/7z.so");
}
#else
return new QLibrary(QCoreApplication::applicationDirPath() + "/utils/7z");
#endif
}
3 changes: 3 additions & 0 deletions common/yacreader_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <QMetaType>
#include <QAbstractItemModel>

class QLibrary;

#define VERSION "9.15.0"

// Used to check if the database needs to be updated, the version is stored in the database.
Expand Down Expand Up @@ -100,6 +102,7 @@ QDataStream &operator>>(QDataStream &stream, OpenComicSource &source);
QString getSettingsPath();
QString colorToName(LabelColors colors);
QString labelColorToRGBString(LabelColors color);
QLibrary *load7zLibrary();

void iterate(const QModelIndex &index,
const QAbstractItemModel *model,
Expand Down
17 changes: 5 additions & 12 deletions compressed_archive/compressed_archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "compressed_archive.h"
#include "extract_delegate.h"
#include "yacreader_global.h"

#include <QLibrary>
#include <QFileInfo>
Expand Down Expand Up @@ -78,7 +79,7 @@ const unsigned char tar[6] = "ustar";
const unsigned char arj[2] = { static_cast<unsigned char>(0x60), static_cast<unsigned char>(0xEA) };

CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
: QObject(parent), sevenzLib(0), valid(false), tools(false)
: QObject(parent), sevenzLib(nullptr), tools(false), valid(false)
{
szInterface = new SevenZipInterface;
// load functions
Expand Down Expand Up @@ -174,18 +175,10 @@ CompressedArchive::~CompressedArchive()
bool CompressedArchive::loadFunctions()
{
// LOAD library
if (sevenzLib == 0) {
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
QFileInfo sevenzlibrary(QString(LIBDIR) + "/yacreader/7z.so");
if (sevenzlibrary.exists()) {
sevenzLib = new QLibrary(sevenzlibrary.absoluteFilePath());
} else {
sevenzLib = new QLibrary(QString(LIBDIR) + "/7zip/7z.so");
}
#else
sevenzLib = new QLibrary(QCoreApplication::applicationDirPath() + "/utils/7z");
#endif
if (sevenzLib == nullptr) {
sevenzLib = YACReader::load7zLibrary();
}

if (!sevenzLib->load()) {
qDebug() << "Error Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl;
QCoreApplication::exit(700); // TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound
Expand Down

0 comments on commit 6ccfc51

Please sign in to comment.