From 63fcde8035bec9a00c60a9aeded844c3beb25d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sun, 15 Sep 2024 15:50:09 +0200 Subject: [PATCH] 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 --- YACReaderLibrary/library_creator.cpp | 7 +------ YACReaderLibrary/xml_info_library_scanner.cpp | 7 +------ common/yacreader_global.cpp | 16 ++++++++++++++++ common/yacreader_global.h | 3 +++ compressed_archive/compressed_archive.cpp | 17 +++++------------ 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp index 609c91db..85ab00a9 100644 --- a/YACReaderLibrary/library_creator.cpp +++ b/YACReaderLibrary/library_creator.cpp @@ -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; diff --git a/YACReaderLibrary/xml_info_library_scanner.cpp b/YACReaderLibrary/xml_info_library_scanner.cpp index 3f59e254..2740e416 100644 --- a/YACReaderLibrary/xml_info_library_scanner.cpp +++ b/YACReaderLibrary/xml_info_library_scanner.cpp @@ -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; diff --git a/common/yacreader_global.cpp b/common/yacreader_global.cpp index 6801af99..afd0dcdf 100644 --- a/common/yacreader_global.cpp +++ b/common/yacreader_global.cpp @@ -1,6 +1,8 @@ #include "yacreader_global.h" #include +#include +#include using namespace YACReader; @@ -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 + 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 +} diff --git a/common/yacreader_global.h b/common/yacreader_global.h index 8a97beb7..b8a13bba 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -6,6 +6,8 @@ #include #include +class QLibrary; + #define VERSION "9.15.0" // 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 colorToName(LabelColors colors); QString labelColorToRGBString(LabelColors color); +QLibrary *load7zLibrary(); void iterate(const QModelIndex &index, const QAbstractItemModel *model, diff --git a/compressed_archive/compressed_archive.cpp b/compressed_archive/compressed_archive.cpp index 1eb4a07f..db78019f 100644 --- a/compressed_archive/compressed_archive.cpp +++ b/compressed_archive/compressed_archive.cpp @@ -2,6 +2,7 @@ #include "compressed_archive.h" #include "extract_delegate.h" +#include "yacreader_global.h" #include #include @@ -78,7 +79,7 @@ const unsigned char tar[6] = "ustar"; const unsigned char arj[2] = { static_cast(0x60), static_cast(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 @@ -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