Skip to content

Commit 6ccfc51

Browse files
committed
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
1 parent bb36368 commit 6ccfc51

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

YACReaderLibrary/library_creator.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,7 @@ void LibraryCreator::run()
141141
stopRunning = false;
142142
canceled = false;
143143
#if !defined use_unarr && !defined use_libarchive
144-
// check for 7z lib
145-
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
146-
QLibrary *sevenzLib = new QLibrary(QString(LIBDIR) + "/7zip/7z.so");
147-
#else
148-
QLibrary *sevenzLib = new QLibrary(QCoreApplication::applicationDirPath() + "/utils/7z");
149-
#endif
144+
auto sevenzLib = YACReader::load7zLibrary();
150145

151146
if (!sevenzLib->load()) {
152147
QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl;

YACReaderLibrary/xml_info_library_scanner.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ void XMLInfoLibraryScanner::scanFolder(const QString &source, const QString &tar
4545
void XMLInfoLibraryScanner::run()
4646
{
4747
#if !defined use_unarr && !defined use_libarchive
48-
// check for 7z lib
49-
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
50-
QLibrary *sevenzLib = new QLibrary(QString(LIBDIR) + "/7zip/7z.so");
51-
#else
52-
QLibrary *sevenzLib = new QLibrary(QCoreApplication::applicationDirPath() + "/utils/7z");
53-
#endif
48+
auto sevenzLib = YACReader::load7zLibrary();
5449

5550
if (!sevenzLib->load()) {
5651
QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl;

common/yacreader_global.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "yacreader_global.h"
22

33
#include <QModelIndex>
4+
#include <QLibrary>
5+
#include <QCoreApplication>
46

57
using namespace YACReader;
68

@@ -119,3 +121,17 @@ void YACReader::iterate(const QModelIndex &index,
119121
for (int i = 0; i < rows; ++i)
120122
iterate(model->index(i, 0, index), model, iteration);
121123
}
124+
125+
QLibrary *YACReader::load7zLibrary()
126+
{
127+
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
128+
QFileInfo sevenzlibrary(QString(LIBDIR) + "/yacreader/7z.so");
129+
if (sevenzlibrary.exists()) {
130+
return new QLibrary(sevenzlibrary.absoluteFilePath());
131+
} else {
132+
retrun new QLibrary(QString(LIBDIR) + "/7zip/7z.so");
133+
}
134+
#else
135+
return new QLibrary(QCoreApplication::applicationDirPath() + "/utils/7z");
136+
#endif
137+
}

common/yacreader_global.h

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <QMetaType>
77
#include <QAbstractItemModel>
88

9+
class QLibrary;
10+
911
#define VERSION "9.15.0"
1012

1113
// 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);
100102
QString getSettingsPath();
101103
QString colorToName(LabelColors colors);
102104
QString labelColorToRGBString(LabelColors color);
105+
QLibrary *load7zLibrary();
103106

104107
void iterate(const QModelIndex &index,
105108
const QAbstractItemModel *model,

compressed_archive/compressed_archive.cpp

+5-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "compressed_archive.h"
44
#include "extract_delegate.h"
5+
#include "yacreader_global.h"
56

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

8081
CompressedArchive::CompressedArchive(const QString &filePath, QObject *parent)
81-
: QObject(parent), sevenzLib(0), valid(false), tools(false)
82+
: QObject(parent), sevenzLib(nullptr), tools(false), valid(false)
8283
{
8384
szInterface = new SevenZipInterface;
8485
// load functions
@@ -174,18 +175,10 @@ CompressedArchive::~CompressedArchive()
174175
bool CompressedArchive::loadFunctions()
175176
{
176177
// LOAD library
177-
if (sevenzLib == 0) {
178-
#if defined Q_OS_UNIX && !defined Q_OS_MACOS
179-
QFileInfo sevenzlibrary(QString(LIBDIR) + "/yacreader/7z.so");
180-
if (sevenzlibrary.exists()) {
181-
sevenzLib = new QLibrary(sevenzlibrary.absoluteFilePath());
182-
} else {
183-
sevenzLib = new QLibrary(QString(LIBDIR) + "/7zip/7z.so");
184-
}
185-
#else
186-
sevenzLib = new QLibrary(QCoreApplication::applicationDirPath() + "/utils/7z");
187-
#endif
178+
if (sevenzLib == nullptr) {
179+
sevenzLib = YACReader::load7zLibrary();
188180
}
181+
189182
if (!sevenzLib->load()) {
190183
qDebug() << "Error Loading 7z.dll : " + sevenzLib->errorString() << Qt::endl;
191184
QCoreApplication::exit(700); // TODO yacreader_global can't be used here, it is GUI dependant, YACReader::SevenZNotFound

0 commit comments

Comments
 (0)