diff --git a/YACReader/YACReader.pri b/YACReader/YACReader.pri index 578fe087..799bcbbf 100644 --- a/YACReader/YACReader.pri +++ b/YACReader/YACReader.pri @@ -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) diff --git a/YACReader/configuration.cpp b/YACReader/configuration.cpp index 48f2daaa..a89aab3d 100644 --- a/YACReader/configuration.cpp +++ b/YACReader/configuration.cpp @@ -7,6 +7,8 @@ #include #include +#include "yacreader_global.h" + Configuration::Configuration() { //read configuration @@ -77,7 +79,7 @@ void Configuration::load(const QString & path) alwaysOnTop = false; //load from file - QFile f(QCoreApplication::applicationDirPath()+path); + QFile f(YACReader::getSettingsPath()+path); f.open(QIODevice::ReadOnly); QTextStream txtS(&f); QString content = txtS.readAll(); @@ -158,61 +160,3 @@ void Configuration::load(const QString & path) i++; } } - -void Configuration::save() -{ - QFile f(QCoreApplication::applicationDirPath()+"/YACReader.conf"); - if(!f.open(QIODevice::WriteOnly)) - { - QMessageBox::critical(NULL,tr("Saving config file...."),tr("There was a problem saving YACReader configuration. Please, check if you have enough permissions in the YACReader root folder.")); - } - else - { - QTextStream txtS(&f); - - txtS << PATH << "\n"; - txtS << defaultPath << "\n"; - - txtS << MAG_GLASS_SIZE << "\n"; - txtS << magnifyingGlassSize.width() <<","<< magnifyingGlassSize.height() << "\n"; - - txtS << ZOOM_LEVEL << "\n"; - txtS << zoomLevel << "\n"; - - txtS << SLIDE_SIZE << "\n"; - txtS << gotoSlideSize.height() << "\n"; - - txtS << FIT << "\n"; - txtS << (int)adjustToWidth << "\n"; - - txtS << FLOW_TYPE << "\n"; - txtS << (int)flowType << "\n"; - - txtS << FULLSCREEN << "\n"; - txtS << (int)fullScreen << "\n"; - - txtS << FIT_TO_WIDTH_RATIO << "\n"; - txtS << fitToWidthRatio << "\n"; - - txtS << Y_WINDOW_POS << "\n"; - txtS << windowPos.x() << "," << windowPos.y() << "\n"; - - txtS << Y_WINDOW_SIZE << "\n"; - txtS << windowSize.width() << "," << windowSize.height() << "\n"; - - txtS << MAXIMIZED << "\n"; - txtS << (int)maximized << "\n"; - - txtS << DOUBLE_PAGE << "\n"; - txtS << (int)doublePage << "\n"; - - txtS << ADJUST_TO_FULL_SIZE << "\n"; - txtS << (int) adjustToFullSize << "\n"; - - txtS << BACKGROUND_COLOR << "\n"; - txtS << backgroundColor.red() << "," << backgroundColor.green() << "," << backgroundColor.blue() << "\n"; - - txtS << ALWAYS_ON_TOP << "\n"; - txtS << (int)alwaysOnTop << "\n"; - } -} diff --git a/YACReader/configuration.h b/YACReader/configuration.h index 558d2b81..7ef6b7ff 100644 --- a/YACReader/configuration.h +++ b/YACReader/configuration.h @@ -89,9 +89,6 @@ using namespace YACReader; void setLastVersionCheck(const QDate & date){ settings->setValue(LAST_VERSION_CHECK,date);} int getNumDaysBetweenVersionChecks() {return settings->value(NUM_DAYS_BETWEEN_VERSION_CHECKS,1).toInt();} void setNumDaysBetweenVersionChecks(int days) {return settings->setValue(NUM_DAYS_BETWEEN_VERSION_CHECKS,days);} - - void save(); - }; #endif diff --git a/YACReader/main.cpp b/YACReader/main.cpp index ed5796c5..cafae393 100644 --- a/YACReader/main.cpp +++ b/YACReader/main.cpp @@ -11,7 +11,7 @@ #include #include "main_window_viewer.h" #include "configuration.h" - +#include "exit_check.h" #if defined(WIN32) && defined(_DEBUG) @@ -43,7 +43,9 @@ int main(int argc, char * argv[]) int ret = app.exec(); - Configuration::getConfiguration().save(); + //Configuration::getConfiguration().save(); + YACReader::exitCheck(ret); + return ret; } diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 0cb06f31..75fb7e73 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -1008,7 +1008,7 @@ void MainWindowViewer::getSiblingComics(QString path,QString currentComic) int index = list.indexOf(currentComic); if(index == -1) //comic not found { - QFile f(QCoreApplication::applicationDirPath()+"/errorLog.txt"); + /*QFile f(QCoreApplication::applicationDirPath()+"/errorLog.txt"); if(!f.open(QIODevice::WriteOnly)) { QMessageBox::critical(NULL,tr("Saving error log file...."),tr("There was a problem saving YACReader error log file. Please, check if you have enough permissions in the YACReader root folder.")); @@ -1025,7 +1025,7 @@ void MainWindowViewer::getSiblingComics(QString path,QString currentComic) txtS << s << '\n'; } f.close(); - } + }*/ } previousComicPath = nextComicPath = ""; diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index fd94b0e8..67a38ba2 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -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) diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp index 66486cb0..656e2d4f 100644 --- a/YACReaderLibrary/library_creator.cpp +++ b/YACReaderLibrary/library_creator.cpp @@ -5,6 +5,9 @@ #include #include #include +#include +#include + #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 @@ -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 diff --git a/YACReaderLibrary/library_creator.h b/YACReaderLibrary/library_creator.h index c4afc4bd..26479fd2 100644 --- a/YACReaderLibrary/library_creator.h +++ b/YACReaderLibrary/library_creator.h @@ -72,6 +72,7 @@ int _numPages; QPixmap _cover; int _coverPage; + static bool crash; public slots: void create(); diff --git a/YACReaderLibrary/main.cpp b/YACReaderLibrary/main.cpp index 96c46a1b..5619b4b3 100644 --- a/YACReaderLibrary/main.cpp +++ b/YACReaderLibrary/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #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; diff --git a/YACReaderLibrary/yacreader_libraries.cpp b/YACReaderLibrary/yacreader_libraries.cpp index 686c5f28..2e5e3cd2 100644 --- a/YACReaderLibrary/yacreader_libraries.cpp +++ b/YACReaderLibrary/yacreader_libraries.cpp @@ -94,8 +94,8 @@ QMap > YACReaderLibraries::getLibraries() void YACReaderLibraries::addLibrary(const QString &name, const QString &path) { int newID=0; - foreach(QString name, libraries.keys()) - newID = qMax(0,libraries.value(name).first); + foreach(QString lName, libraries.keys()) + newID = qMax(newID,libraries.value(lName).first); newID++; libraries.insert(name,QPair(newID,path)); } diff --git a/common/bookmarks.cpp b/common/bookmarks.cpp index 3edf920b..d60d8b60 100644 --- a/common/bookmarks.cpp +++ b/common/bookmarks.cpp @@ -7,6 +7,8 @@ #include #include +#include "yacreader_global.h" + Bookmarks::Bookmarks() :lastPageIndex(0) { @@ -123,7 +125,7 @@ void Bookmarks::save() //----------------------------------------------------------------------------- void BookmarksList::load() { - QFile f(QCoreApplication::applicationDirPath()+"/bookmarks.yacr"); + QFile f(YACReader::getSettingsPath()+"/bookmarks.yacr"); if(f.open(QIODevice::ReadOnly)) { QDataStream dataS(&f); @@ -134,7 +136,7 @@ void BookmarksList::load() void BookmarksList::save() { - QFile f(QCoreApplication::applicationDirPath()+"/bookmarks.yacr"); + QFile f(YACReader::getSettingsPath()+"/bookmarks.yacr"); f.open(QIODevice::WriteOnly); QDataStream dataS(&f); if(list.count()>numMaxBookmarks) @@ -169,4 +171,4 @@ BookmarksList::Bookmark BookmarksList::get(const QString & comicID) { //if(list.contains(comicID) return list.value(comicID); -} \ No newline at end of file +} diff --git a/common/comic.cpp b/common/comic.cpp index bfaef792..f5119943 100644 --- a/common/comic.cpp +++ b/common/comic.cpp @@ -413,6 +413,8 @@ QList > 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); diff --git a/common/exit_check.cpp b/common/exit_check.cpp new file mode 100644 index 00000000..6d1cca54 --- /dev/null +++ b/common/exit_check.cpp @@ -0,0 +1,21 @@ +#include "exit_check.h" + +#include "yacreader_global.h" + +#include + +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; + } + +} + diff --git a/common/exit_check.h b/common/exit_check.h new file mode 100644 index 00000000..a2c0b19a --- /dev/null +++ b/common/exit_check.h @@ -0,0 +1,9 @@ +#ifndef EXIT_CHECK_H +#define EXIT_CHECK_H + +namespace YACReader +{ + void exitCheck(int ret); +} + +#endif diff --git a/common/yacreader_global.h b/common/yacreader_global.h index 1b5c7b27..909904d2 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -88,6 +88,11 @@ namespace YACReader Opened = 2 }; + enum YACReaderErrors + { + SevenZNotFound = 700 + }; + QString getSettingsPath(); } diff --git a/compressed_archive/compressed_archive.cpp b/compressed_archive/compressed_archive.cpp index 71e9178f..f6535d33 100644 --- a/compressed_archive/compressed_archive.cpp +++ b/compressed_archive/compressed_archive.cpp @@ -3,11 +3,13 @@ #include #include - +#include #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 CompressedArchive::getFileNames() @@ -170,6 +180,11 @@ bool CompressedArchive::isValid() return valid; } +bool CompressedArchive::toolsLoaded() +{ + return tools; +} + int CompressedArchive::getNumFiles() { quint32 numItems = 0; diff --git a/compressed_archive/compressed_archive.h b/compressed_archive/compressed_archive.h index ff643c9f..29ccf1c0 100644 --- a/compressed_archive/compressed_archive.h +++ b/compressed_archive/compressed_archive.h @@ -41,10 +41,12 @@ public slots: QByteArray getRawDataAtIndex(int index); QList getFileNames(); bool isValid(); + bool toolsLoaded(); private: SevenZipInterface * szInterface; QLibrary * sevenzLib; - void loadFunctions(); + bool loadFunctions(); + bool tools; bool valid; };