Headless server: simplify system config logger

This commit is contained in:
Felix Kauselmann
2018-01-28 13:32:56 +01:00
commit 2cbbf8d433
1048 changed files with 104347 additions and 0 deletions

View File

@ -0,0 +1,17 @@
Starting with YACReader 9.0.0 all versions of YACReader use (lib)unarr >= 1.0.1
as decompression backend. For Windows and MacOSX precompiled libraries
are available in the dependencies folder (not included in the source tarballs!).
For all other operating systems or users who wish to compile unarr themselves,
source code and build instructions are available at https://github.com/selmf/unarr/
For best performance it is recommended to build and install unarr as a shared
library.
Users who prefer an embedded build can also download a snapshot from
https://github.com/selmf/unarr/archive/master.zip and extract it in this folder.
The build system will then detect the presence of the source code and include it
in the build process. However, as the embedded build option uses different
compiler flags and does not include any options to detect and make use of libraries
like zlib, bzip2 or lzma embedded builds will have slower extraction speed
and won't support zip files with bzip2 or xz compression.

View File

@ -0,0 +1,133 @@
#include "compressed_archive.h"
#include <QFileInfo>
#include <QDebug>
#include "extract_delegate.h"
#include <unarr.h>
CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) :
QObject(parent),valid(false),tools(true),numFiles(0),ar(NULL),stream(NULL)
{
//open file
#ifdef Q_OS_WIN
stream = ar_open_file_w((wchar_t *)filePath.utf16());
#else
stream = ar_open_file(filePath.toLocal8Bit().constData());
#endif
if (!stream)
{
return;
}
//open archive
ar = ar_open_rar_archive(stream);
//TODO: build unarr with 7z support and test this!
//if (!ar) ar = ar_open_7z_archive(stream);
if (!ar) ar = ar_open_tar_archive(stream);
//zip detection is costly, so it comes last...
if (!ar) ar = ar_open_zip_archive(stream, false);
if (!ar)
{
return;
}
//initial parse
while (ar_parse_entry(ar))
{
//make sure we really got a file header
if (ar_entry_get_size(ar) > 0)
{
fileNames.append(ar_entry_get_name(ar));
offsets.append(ar_entry_get_offset(ar));
numFiles++;
}
}
if (!ar_at_eof(ar))
{
//fail if the initial parse didn't reach EOF
//this might be a bit too drastic
qDebug() << "Error while parsing archive";
return;
}
if (numFiles > 0)
{
valid = true;
}
}
CompressedArchive::~CompressedArchive()
{
ar_close_archive(ar);
ar_close(stream);
}
QList<QString> CompressedArchive::getFileNames()
{
return fileNames;
}
bool CompressedArchive::isValid()
{
return valid;
}
bool CompressedArchive::toolsLoaded()
{
//for backwards compatibilty
return tools;
}
int CompressedArchive::getNumFiles()
{
return numFiles;
}
void CompressedArchive::getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate)
{
if (indexes.isEmpty())
return;
QByteArray buffer;
int i=0;
while (i < indexes.count())
{
if(delegate->isCancelled())
{
return;
}
//use the offset list so we generated so we're not getting any non-page files
ar_parse_entry_at(ar, offsets.at(indexes.at(i))); //set ar_entry to start of indexes
buffer.resize(ar_entry_get_size(ar));
if (ar_entry_uncompress(ar, buffer.data(), buffer.size())) //did we extract it?
{
delegate->fileExtracted(indexes.at(i), buffer); //return extracted file
}
else
{
delegate->crcError(indexes.at(i)); //we could not extract it...
}
i++;
}
}
QByteArray CompressedArchive::getRawDataAtIndex(int index)
{
QByteArray buffer;
if(index >= 0 && index < getNumFiles())
{
ar_parse_entry_at(ar, offsets.at(index));
buffer.resize(ar_entry_get_size(ar));
if(ar_entry_uncompress(ar, buffer.data(), buffer.size()))
{
return buffer;
}
else
{
return QByteArray();
}
}
return buffer;
}

View File

@ -0,0 +1,37 @@
#ifndef COMPRESSED_ARCHIVE_H
#define COMPRESSED_ARCHIVE_H
#include <QObject>
#include "extract_delegate.h"
extern"C" {
#include <unarr.h>
}
class CompressedArchive : public QObject
{
Q_OBJECT
public:
explicit CompressedArchive(const QString & filePath, QObject *parent = 0);
~CompressedArchive();
signals:
public slots:
int getNumFiles();
void getAllData(const QVector<quint32> & indexes, ExtractDelegate * delegate=0);
QByteArray getRawDataAtIndex(int index);
QList<QString> getFileNames();
bool isValid();
bool toolsLoaded();
private:
bool tools;
bool valid;
QList<QString> fileNames;
int numFiles;
ar_archive *ar;
ar_stream *stream;
QList<qint64> offsets;
};
#endif // COMPRESSED_ARCHIVE_H

View File

@ -0,0 +1,15 @@
#ifndef EXTRACT_DELEGATE_H
#define EXTRACT_DELEGATE_H
#include <QByteArray>
class ExtractDelegate
{
public:
virtual void fileExtracted(int index, const QByteArray & rawData) = 0;
virtual void crcError(int index) = 0;
virtual void unknownError(int index) = 0;
virtual bool isCancelled() = 0;
};
#endif //EXTRACT_DELEGATE_H

View File

@ -0,0 +1,54 @@
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += $$PWD/extract_delegate.h \
$$PWD/compressed_archive.h
SOURCES += $$PWD/compressed_archive.cpp
unix:!macx {
!contains(QT_CONFIG, no-pkg-config):packagesExist(libunarr) {
message(Using system provided unarr installation found by pkg-config.)
CONFIG += link_pkgconfig
PKGCONFIG += libunarr
DEFINES += use_unarr
}
else:exists(/usr/include/unarr.h):exists(/usr/lib/libunarr.so) {
message(Using system provided unarr installation.)
LIBS += -lunarr
DEFINES += use_unarr
}
}
else:macx:exists(../../dependencies/unarr/macx/libunarr.a) {
message(Found prebuilt unarr library in dependencies directory.)
INCLUDEPATH += $$PWD/../../dependencies/unarr/macx
LIBS += -L$$PWD/../../dependencies/unarr/macx -lunarr -lz -lbz2
DEFINES += use_unarr
}
else:win32:exists(../../dependencies/unarr/win/unarr.h) {
message(Found prebuilt unarr library in dependencies directory.)
INCLUDEPATH += $$PWD/../../dependencies/unarr/win
contains(QMAKE_TARGET.arch, x86_64): {
LIBS += -L$$PWD/../../dependencies/unarr/win/x64 -lunarr
} else {
LIBS += -L$$PWD/../../dependencies/unarr/win/x86 -lunarr
}
DEFINES += use_unarr UNARR_IS_SHARED_LIBRARY
}
else:exists ($$PWD/unarr-master) {
message(Found unarr source-code)
message(Unarr will be build as a part of YACReader)
# qmake based unarr build system
# this should only be used for testing or as a last resort
include(unarr.pro)
DEFINES += use_unarr
}
else {
error(Missing dependency: unarr decrompression backend. Please install libunarr on your system\
or provide a copy of the unarr source code in compressed_archive/unarr/unarr-master)
}

View File

@ -0,0 +1,46 @@
INCLUDEPATH += $$PWD/unarr-master/
DEPENDPATH += $$PWD/unarr-master/
unix:QMAKE_CFLAGS_RELEASE -= "-O2"
unix:QMAKE_CFLAGS_RELEASE += "-O3"
unix:QMAKE_CFLAGS_RELEASE += "-DNDEBUG"
unix:QMAKE_CFLAGS += "-D_FILE_OFFSET_BITS=64"
win32:QMAKE_CFLAGS_RELEASE += "/DNDEBUG"
HEADERS+=$$PWD/unarr-master/common/allocator.h\
$$PWD/unarr-master/common/unarr-imp.h\
$$PWD/unarr-master/lzmasdk/7zTypes.h\
$$PWD/unarr-master/lzmasdk/CpuArch.h\
$$PWD/unarr-master/lzmasdk/Ppmd7.h\
$$PWD/unarr-master/lzmasdk/Ppmd.h\
$$PWD/unarr-master/lzmasdk/LzmaDec.h\
$$PWD/unarr-master/lzmasdk/Ppmd8.h\
$$PWD/unarr-master/tar/tar.h\
$$PWD/unarr-master/_7z/_7z.h\
$$PWD/unarr-master/unarr.h
SOURCES+=$$PWD/unarr-master/common/conv.c\
$$PWD/unarr-master/common/custalloc.c\
$$PWD/unarr-master/common/unarr.c\
$$PWD/unarr-master/common/crc32.c\
$$PWD/unarr-master/common/stream.c\
$$PWD/unarr-master/lzmasdk/CpuArch.c\
$$PWD/unarr-master/lzmasdk/Ppmd7.c\
$$PWD/unarr-master/lzmasdk/Ppmd8.c\
$$PWD/unarr-master/lzmasdk/LzmaDec.c\
$$PWD/unarr-master/lzmasdk/Ppmd7Dec.c\
$$PWD/unarr-master/lzmasdk/Ppmd8Dec.c\
$$PWD/unarr-master/zip/inflate.c\
$$PWD/unarr-master/zip/parse-zip.c\
$$PWD/unarr-master/zip/uncompress-zip.c\
$$PWD/unarr-master/zip/zip.c\
$$PWD/unarr-master/rar/filter-rar.c\
$$PWD/unarr-master/rar/parse-rar.c\
$$PWD/unarr-master/rar/rarvm.c\
$$PWD/unarr-master/rar/huffman-rar.c\
$$PWD/unarr-master/rar/rar.c\
$$PWD/unarr-master/rar/uncompress-rar.c\
$$PWD/unarr-master/tar/parse-tar.c\
$$PWD/unarr-master/tar/tar.c\
$$PWD/unarr-master/_7z/_7z.c