added exit and notification on 7z lib not found

This commit is contained in:
Luis Ángel San Martín 2013-11-24 12:55:03 +01:00
parent 92331af971
commit 8255637028
12 changed files with 105 additions and 13 deletions

View File

@ -81,7 +81,8 @@ HEADERS += $$PWD/../common/comic.h \
$$PWD/../common/folder.h \
$$PWD/../common/library_item.h \
$$PWD/yacreader_local_client.h \
$$PWD/../common/http_worker.h
$$PWD/../common/http_worker.h \
$$PWD/../common/exit_check.h \
SOURCES += $$PWD/../common/comic.cpp \
$$PWD/configuration.cpp \
@ -113,8 +114,9 @@ SOURCES += $$PWD/../common/comic.cpp \
$$PWD/../common/folder.cpp \
$$PWD/../common/library_item.cpp \
$$PWD/yacreader_local_client.cpp \
$$PWD/../common/http_worker.cpp \
$$PWD/../common/yacreader_global.cpp \
$$PWD/../common/http_worker.cpp \
$$PWD/../common/yacreader_global.cpp \
$$PWD/../common/exit_check.cpp \
include($$PWD/../custom_widgets/custom_widgets_yacreader.pri)
include($$PWD/../compressed_archive/wrapper.pri)

View File

@ -11,7 +11,7 @@
#include <QTranslator>
#include "main_window_viewer.h"
#include "configuration.h"
#include "exit_check.h"
#if defined(WIN32) && defined(_DEBUG)
@ -45,5 +45,7 @@ int main(int argc, char * argv[])
Configuration::getConfiguration().save();
YACReader::exitCheck(ret);
return ret;
}

View File

@ -96,7 +96,8 @@ HEADERS += comic_flow.h \
yacreader_main_toolbar.h \
comics_remover.h \
../common/http_worker.h \
yacreader_libraries.h
yacreader_libraries.h \
../common/exit_check.cpp \
SOURCES += comic_flow.cpp \
create_library_dialog.cpp \
@ -138,7 +139,8 @@ SOURCES += comic_flow.cpp \
comics_remover.cpp \
../common/http_worker.cpp \
../common/yacreader_global.cpp \
yacreader_libraries.cpp
yacreader_libraries.cpp \
../common/exit_check.cpp \
include(./server/server.pri)

View File

@ -5,6 +5,9 @@
#include <QDebug>
#include <QSqlQuery>
#include <QSqlRecord>
#include <QApplication>
#include <QLibrary>
#include "data_base_management.h"
#include "qnaturalsorting.h"
#include "db_helper.h"
@ -12,6 +15,8 @@
#include "compressed_archive.h"
#include "comic.h"
#include "yacreader_global.h"
#include "QsLog.h"
#include <algorithm>
@ -61,6 +66,16 @@ void LibraryCreator::run()
{
stopRunning = false;
//check for 7z lib
QLibrary *sevenzLib = new QLibrary("./utils/7z");
if(!sevenzLib->load())
{
QLOG_ERROR() << "Loading 7z.dll : " + sevenzLib->errorString() << endl;
QApplication::exit(YACReader::SevenZNotFound);
exit();
}
sevenzLib->deleteLater();
if(_mode == CREATOR)
{
QLOG_INFO() << "Starting to create new library ( " << _source << "," << _target << ")";
@ -465,6 +480,9 @@ void LibraryCreator::update(QDir dirS)
}
}
}
bool ThumbnailCreator::crash = false;
ThumbnailCreator::ThumbnailCreator(QString fileSource, QString target, int coverPage)
:_fileSource(fileSource),_target(target),_numPages(0),_coverPage(coverPage)
{
@ -520,7 +538,16 @@ void ThumbnailCreator::create()
else
{
if(crash)
return;
CompressedArchive archive(_fileSource);
if(!archive.toolsLoaded())
{
QLOG_WARN() << "Extracting cover: 7z lib not loaded";
crash = true;
return;
}
if(!archive.isValid())
QLOG_WARN() << "Extracting cover: file format not supported " << _fileSource;
//se filtran para obtener sólo los formatos soportados

View File

@ -72,6 +72,7 @@
int _numPages;
QPixmap _cover;
int _coverPage;
static bool crash;
public slots:
void create();

View File

@ -9,6 +9,7 @@
#include <QFileInfo>
#include <QSettings>
#include <QLibrary>
#include <QMessageBox>
#include "yacreader_global.h"
#include "startup.h"
@ -16,6 +17,7 @@
#include "comic_db.h"
#include "db_helper.h"
#include "yacreader_libraries.h"
#include "exit_check.h"
#include "QsLog.h"
#include "QsLogDest.h"
@ -186,12 +188,14 @@ int main( int argc, char ** argv )
int ret = app.exec();
QLOG_INFO() << "YACReaderLibrary closed with exit code :" << ret;
YACReader::exitCheck(ret);
//server shutdown
s->stop();
delete s;
QLOG_INFO() << "YACReaderLibrary closed";
QsLogging::Logger::destroyInstance();
return ret;

View File

@ -413,6 +413,8 @@ QList<QVector<quint32> > FileComic::getSections(int & sectionIndex)
void FileComic::process()
{
CompressedArchive archive(_path);
if(!archive.toolsLoaded())
return;
//se filtran para obtener sólo los formatos soportados
_order = archive.getFileNames();
_fileNames = filter(_order);

21
common/exit_check.cpp Normal file
View File

@ -0,0 +1,21 @@
#include "exit_check.h"
#include "yacreader_global.h"
#include <QMessageBox>
using namespace YACReader;
void YACReader::exitCheck(int ret)
{
switch(ret)
{
case YACReader::SevenZNotFound:
QMessageBox::critical(0,QObject::tr("7z lib not found"),QObject::tr("unable to load 7z lib from ./utils"));
break;
default:
break;
}
}

9
common/exit_check.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef EXIT_CHECK_H
#define EXIT_CHECK_H
namespace YACReader
{
void exitCheck(int ret);
}
#endif

View File

@ -88,6 +88,11 @@ namespace YACReader
Opened = 2
};
enum YACReaderErrors
{
SevenZNotFound = 700
};
QString getSettingsPath();
}

View File

@ -3,11 +3,13 @@
#include <QLibrary>
#include <QDebug>
#include <QApplication>
#include "open_callbacks.h"
#include "extract_callbacks.h"
#include "yacreader_global.h"
//DEFINE_GUID(CLSID_CFormat7z,0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);
//DEFINE_GUID(IArchiveKK,0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x06, 0x00, 0x60, 0x00, 0x00);
@ -56,12 +58,14 @@ struct SevenZipInterface {
//SevenZipInterface * szInterface;
CompressedArchive::CompressedArchive(const QString & filePath, QObject *parent) :
QObject(parent),sevenzLib(0),valid(false)
QObject(parent),sevenzLib(0),valid(false),tools(false)
{
szInterface = new SevenZipInterface;
//load functions
loadFunctions();
if(!loadFunctions())
return;
tools = true;
//load file
if(szInterface->createObjectFunc != 0)
{
@ -106,7 +110,7 @@ CompressedArchive::~CompressedArchive()
delete sevenzLib;
}
void CompressedArchive::loadFunctions()
bool CompressedArchive::loadFunctions()
{
//LOAD library
//TODO check if this works in OSX (7z.so instead of 7z.dylib)
@ -115,7 +119,11 @@ void CompressedArchive::loadFunctions()
if(sevenzLib == 0)
sevenzLib = new QLibrary("./utils/7z");
if(!sevenzLib->load())
{
qDebug() << "Loading 7z.dll : " + sevenzLib->errorString() << endl;
QApplication::exit(YACReader::SevenZNotFound); //TODO app still crashing
return false;
}
else
{
qDebug() << "Loading functions" << endl;
@ -135,6 +143,8 @@ void CompressedArchive::loadFunctions()
if((szInterface->setLargePageModeFunc = (SetLargePageModeFunc)sevenzLib->resolve("SetLargePageMode")) == 0)
qDebug() << "fail loading function : SetLargePageMode" << endl;
}
return true;
}
QList<QString> CompressedArchive::getFileNames()
@ -170,6 +180,11 @@ bool CompressedArchive::isValid()
return valid;
}
bool CompressedArchive::toolsLoaded()
{
return tools;
}
int CompressedArchive::getNumFiles()
{
quint32 numItems = 0;

View File

@ -41,10 +41,12 @@ public slots:
QByteArray getRawDataAtIndex(int index);
QList<QString> getFileNames();
bool isValid();
bool toolsLoaded();
private:
SevenZipInterface * szInterface;
QLibrary * sevenzLib;
void loadFunctions();
bool loadFunctions();
bool tools;
bool valid;
};