mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
212 lines
7.1 KiB
C++
212 lines
7.1 KiB
C++
#include <QtCore>
|
|
|
|
#include "comic_db.h"
|
|
#include "db_helper.h"
|
|
#include "startup.h"
|
|
#include "yacreader_global.h"
|
|
#include "yacreader_libraries.h"
|
|
#include "yacreader_local_server.h"
|
|
|
|
#include "QsLog.h"
|
|
#include "QsLogDest.h"
|
|
|
|
using namespace QsLogging;
|
|
|
|
void logSystemAndConfig()
|
|
{
|
|
QLOG_INFO() << "---------- System & configuration ----------";
|
|
#if defined(Q_OS_WIN)
|
|
switch (QSysInfo::windowsVersion())
|
|
{
|
|
case QSysInfo::WV_NT:
|
|
QLOG_INFO() << "SO : Windows NT";
|
|
break;
|
|
case QSysInfo::WV_2000:
|
|
QLOG_INFO() << "SO : Windows 2000";
|
|
break;
|
|
case QSysInfo::WV_XP:
|
|
QLOG_INFO() << "SO : Windows XP";
|
|
break;
|
|
case QSysInfo::WV_2003:
|
|
QLOG_INFO() << "SO : Windows 2003";
|
|
break;
|
|
case QSysInfo::WV_VISTA:
|
|
QLOG_INFO() << "SO : Windows Vista";
|
|
break;
|
|
case QSysInfo::WV_WINDOWS7:
|
|
QLOG_INFO() << "SO : Windows 7";
|
|
break;
|
|
case QSysInfo::WV_WINDOWS8:
|
|
QLOG_INFO() << "SO : Windows 8";
|
|
break;
|
|
default:
|
|
QLOG_INFO() << "Windows (unknown version)";
|
|
break;
|
|
}
|
|
|
|
#elif defined(Q_OS_MAC)
|
|
|
|
switch (QSysInfo::MacVersion())
|
|
{
|
|
case QSysInfo::MV_SNOWLEOPARD:
|
|
QLOG_INFO() << "SO : MacOSX Snow Leopard";
|
|
break;
|
|
case QSysInfo::MV_LION:
|
|
QLOG_INFO() << "SO : MacOSX Lion";
|
|
break;
|
|
case QSysInfo::MV_MOUNTAINLION:
|
|
QLOG_INFO() << "SO : MacOSX Mountain Lion";
|
|
break;
|
|
#if QT_VERSION >= 0x050000
|
|
case QSysInfo::MV_MAVERICKS:
|
|
QLOG_INFO() << "SO : MacOSX Maverics";
|
|
break;
|
|
#endif
|
|
default:
|
|
QLOG_INFO() << "SO : MacOSX (unknown version)";
|
|
break;
|
|
}
|
|
|
|
#elif defined(Q_OS_LINUX)
|
|
QLOG_INFO() << "SO : Linux (unknown version)";
|
|
|
|
#else
|
|
QLOG_INFO() << "SO : Unknown";
|
|
#endif
|
|
|
|
#ifdef Q_OS_WIN
|
|
if(QLibrary::isLibrary(QCoreApplication::applicationDirPath()+"/utils/7z.dll"))
|
|
#elif defined Q_OS_UNIX && !defined Q_OS_MAC
|
|
if(QLibrary::isLibrary(QString(LIBDIR)+"/yacreader/7z.so") | QLibrary::isLibrary(QString(LIBDIR)+"/p7zip/7z.so"))
|
|
#else
|
|
if(QLibrary::isLibrary(QApplication::applicationDirPath()+"/utils/7z.so"))
|
|
#endif
|
|
QLOG_INFO() << "7z : found";
|
|
else
|
|
QLOG_ERROR() << "7z : not found";
|
|
|
|
/* TODO: qrencode could be helpfull for showing a qr code in the web client for client devices
|
|
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
|
if(QFileInfo(QString(BINDIR)+"/qrencode").exists())
|
|
#else
|
|
if(QFileInfo(QCoreApplication::applicationDirPath()+"/utils/qrencode.exe").exists() || QFileInfo("./util/qrencode").exists())
|
|
#endif
|
|
QLOG_INFO() << "qrencode : found";
|
|
else
|
|
QLOG_INFO() << "qrencode : not found";
|
|
*/
|
|
|
|
QLOG_INFO() << "Libraries: " << DBHelper::getLibraries().getLibraries();
|
|
QLOG_INFO() << "--------------------------------------------";
|
|
}
|
|
|
|
QCoreApplication* createApplication(int &argc, char *argv[])
|
|
{
|
|
for (int i = 1; i < argc; ++i)
|
|
if (!qstrcmp(argv[i], "--no-gui"))
|
|
return new QCoreApplication(argc, argv);
|
|
return new QCoreApplication(argc, argv);
|
|
}
|
|
|
|
int main( int argc, char ** argv )
|
|
{
|
|
QScopedPointer<QCoreApplication> app(createApplication(argc, argv));
|
|
|
|
app->setApplicationName("YACReaderLibraryServer");
|
|
app->setOrganizationName("YACReader");
|
|
//simple command line parser
|
|
//will be replaced by QCommandLineParser in the future
|
|
//TODO: support for file and directory arguments
|
|
if (argc > 1)
|
|
{
|
|
QTextStream parser(stdout);
|
|
QStringList optlist = QCoreApplication::arguments().filter(QRegExp ("^-{1,2}"));
|
|
if (optlist.contains("--version") || optlist.contains("-v"))
|
|
{
|
|
parser << app->applicationName() << " " << QString(VERSION) << endl << "Copyright 2014 by Luis Angel San Martin Rodriguez" << endl;
|
|
return 0;
|
|
}
|
|
if (optlist.contains("--help") || optlist.contains("-h"))
|
|
{
|
|
parser << endl << "Usage:" << "\tYACReaderLibrary [Option]" << endl << endl;
|
|
parser << "Options:" << endl;
|
|
parser << " none\t\t\tStart YACReaderLibrary" << endl;
|
|
parser << " -h, --help\t\tDisplay help text and exit." << endl;
|
|
parser << " -v, --version\t\tDisplay version information and exit." << endl;
|
|
return 0;
|
|
}
|
|
if (optlist.contains("--no-gui"))
|
|
{
|
|
parser << "You're running YACReaderLibrary in non-gui mode. Press Ctrl+C to exit." << endl;
|
|
}
|
|
}
|
|
|
|
QString destLog = YACReader::getSettingsPath()+"/yacreaderlibrary.log";
|
|
QDir().mkpath(YACReader::getSettingsPath());
|
|
|
|
Logger& logger = Logger::instance();
|
|
logger.setLoggingLevel(QsLogging::TraceLevel);
|
|
|
|
DestinationPtr fileDestination(DestinationFactory::MakeFileDestination(
|
|
destLog, EnableLogRotation, MaxSizeBytes(1048576), MaxOldLogCount(2)));
|
|
DestinationPtr debugDestination(DestinationFactory::MakeDebugOutputDestination());
|
|
logger.addDestination(debugDestination);
|
|
logger.addDestination(fileDestination);
|
|
|
|
QTranslator translator;
|
|
QString sufix = QLocale::system().name();
|
|
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
|
translator.load(QString(DATADIR)+"/yacreader/languages/yacreaderlibrary_"+sufix);
|
|
#else
|
|
translator.load(QCoreApplication::applicationDirPath()+"/languages/yacreaderlibrary_"+sufix);
|
|
#endif
|
|
app->installTranslator(&translator);
|
|
|
|
QTranslator viewerTranslator;
|
|
#if defined Q_OS_UNIX && !defined Q_OS_MAC
|
|
viewerTranslator.load(QString(DATADIR)+"/yacreader/languages/yacreader_"+sufix);
|
|
#else
|
|
viewerTranslator.load(QCoreApplication::applicationDirPath()+"/languages/yacreader_"+sufix);
|
|
#endif
|
|
app->installTranslator(&viewerTranslator);
|
|
app->setApplicationName("YACReaderLibrary");
|
|
|
|
qRegisterMetaType<ComicDB>("ComicDB");
|
|
|
|
|
|
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci�n del fichero de config con el servidor
|
|
settings->beginGroup("libraryConfig");
|
|
|
|
//server
|
|
Startup *s = new Startup();
|
|
s->start();
|
|
|
|
QLOG_INFO() << "YACReaderLibraryServer attempting to start";
|
|
|
|
logSystemAndConfig();
|
|
|
|
if(YACReaderLocalServer::isRunning()) //s�lo se permite una instancia de YACReaderLibrary
|
|
{
|
|
QLOG_WARN() << "another instance of YACReaderLibrary is running";
|
|
QsLogging::Logger::destroyInstance();
|
|
return 0;
|
|
}
|
|
QLOG_INFO() << "YACReaderLibrary starting";
|
|
|
|
YACReaderLocalServer * localServer = new YACReaderLocalServer();
|
|
|
|
int ret = app->exec();
|
|
|
|
QLOG_INFO() << "YACReaderLibrary closed with exit code :" << ret;
|
|
|
|
//shutdown
|
|
s->stop();
|
|
delete s;
|
|
localServer->close();
|
|
delete localServer;
|
|
|
|
QsLogging::Logger::destroyInstance();
|
|
|
|
return ret;
|
|
}
|