Extract 7z loading to it's own function

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
This commit is contained in:
Luis Ángel San Martín
2024-09-15 15:50:09 +02:00
parent bb36368ad2
commit 63fcde8035
5 changed files with 26 additions and 24 deletions

View File

@ -141,12 +141,7 @@ void LibraryCreator::run()
stopRunning = false; stopRunning = false;
canceled = false; canceled = false;
#if !defined use_unarr && !defined use_libarchive #if !defined use_unarr && !defined use_libarchive
// check for 7z lib auto sevenzLib = YACReader::load7zLibrary();
#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
if (!sevenzLib->load()) { if (!sevenzLib->load()) {
QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl; QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl;

View File

@ -45,12 +45,7 @@ void XMLInfoLibraryScanner::scanFolder(const QString &source, const QString &tar
void XMLInfoLibraryScanner::run() void XMLInfoLibraryScanner::run()
{ {
#if !defined use_unarr && !defined use_libarchive #if !defined use_unarr && !defined use_libarchive
// check for 7z lib auto sevenzLib = YACReader::load7zLibrary();
#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
if (!sevenzLib->load()) { if (!sevenzLib->load()) {
QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl; QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl;

View File

@ -1,6 +1,8 @@
#include "yacreader_global.h" #include "yacreader_global.h"
#include <QModelIndex> #include <QModelIndex>
#include <QLibrary>
#include <QCoreApplication>
using namespace YACReader; using namespace YACReader;
@ -119,3 +121,17 @@ void YACReader::iterate(const QModelIndex &index,
for (int i = 0; i < rows; ++i) for (int i = 0; i < rows; ++i)
iterate(model->index(i, 0, index), model, iteration); iterate(model->index(i, 0, index), model, iteration);
} }
QLibrary *YACReader::load7zLibrary()
{
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
auto yacreader7zPath = QString(LIBDIR) + "/yacreader/7z.so";
if (QLibrary::isLibrary(yacreader7zPath)) {
return new QLibrary(yacreader7zPath);
} else {
return new QLibrary(QString(LIBDIR) + "/7zip/7z.so");
}
#else
return new QLibrary(QCoreApplication::applicationDirPath() + "/utils/7z");
#endif
}

View File

@ -6,6 +6,8 @@
#include <QMetaType> #include <QMetaType>
#include <QAbstractItemModel> #include <QAbstractItemModel>
class QLibrary;
#define VERSION "9.15.0" #define VERSION "9.15.0"
// Used to check if the database needs to be updated, the version is stored in the database. // Used to check if the database needs to be updated, the version is stored in the database.
@ -100,6 +102,7 @@ QDataStream &operator>>(QDataStream &stream, OpenComicSource &source);
QString getSettingsPath(); QString getSettingsPath();
QString colorToName(LabelColors colors); QString colorToName(LabelColors colors);
QString labelColorToRGBString(LabelColors color); QString labelColorToRGBString(LabelColors color);
QLibrary *load7zLibrary();
void iterate(const QModelIndex &index, void iterate(const QModelIndex &index,
const QAbstractItemModel *model, const QAbstractItemModel *model,

View File

@ -2,6 +2,7 @@
#include "compressed_archive.h" #include "compressed_archive.h"
#include "extract_delegate.h" #include "extract_delegate.h"
#include "yacreader_global.h"
#include <QLibrary> #include <QLibrary>
#include <QFileInfo> #include <QFileInfo>
@ -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) }; const unsigned char arj[2] = { static_cast<unsigned char>(0x60), static_cast<unsigned char>(0xEA) };
CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent) 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; szInterface = new SevenZipInterface;
// load functions // load functions
@ -174,18 +175,10 @@ CompressedArchive::~CompressedArchive()
bool CompressedArchive::loadFunctions() bool CompressedArchive::loadFunctions()
{ {
// LOAD library // LOAD library
if (sevenzLib == 0) { if (sevenzLib == nullptr) {
#if defined Q_OS_UNIX && !defined Q_OS_MACOS sevenzLib = YACReader::load7zLibrary();
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->load()) { if (!sevenzLib->load()) {
qDebug() << "Error Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl; 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 QCoreApplication::exit(700); // TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound