mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 21:14:33 -04:00
Add .gitattributes rules for text and binary handling
This commit is contained in:
@ -1,148 +1,148 @@
|
||||
#include "console_ui_library_creator.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "library_creator.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
|
||||
ConsoleUILibraryCreator::ConsoleUILibraryCreator(QObject *parent) :
|
||||
QObject(parent), numComicsProcessed(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::createLibrary(const QString & name, const QString & path)
|
||||
{
|
||||
QEventLoop eventLoop;
|
||||
LibraryCreator * libraryCreator = new LibraryCreator();
|
||||
|
||||
QDir pathDir(path);
|
||||
if (!pathDir.exists())
|
||||
{
|
||||
std::cout << "Directory not found." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
|
||||
|
||||
YACReaderLibraries yacreaderLibraries;
|
||||
yacreaderLibraries.load();
|
||||
if (yacreaderLibraries.contains(name))
|
||||
{
|
||||
std::cout << "A Library named \"" << name.toUtf8().constData() << "\" already exists in database." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
libraryCreator->createLibrary(cleanPath,QDir::cleanPath(pathDir.absolutePath()+"/.yacreaderlibrary"));
|
||||
|
||||
connect(libraryCreator, &LibraryCreator::finished, this, &ConsoleUILibraryCreator::done);
|
||||
connect(libraryCreator, &LibraryCreator::comicAdded, this, &ConsoleUILibraryCreator::newComic);
|
||||
connect(libraryCreator, &LibraryCreator::failedCreatingDB, this, &ConsoleUILibraryCreator::manageCreatingError);
|
||||
|
||||
connect(libraryCreator, &LibraryCreator::finished, &eventLoop, &QEventLoop::quit);
|
||||
|
||||
std::cout << "Processing comics";
|
||||
|
||||
libraryCreator->start();
|
||||
eventLoop.exec();
|
||||
|
||||
yacreaderLibraries.addLibrary(name, cleanPath);
|
||||
yacreaderLibraries.save();
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::updateLibrary(const QString & path)
|
||||
{
|
||||
QEventLoop eventLoop;
|
||||
LibraryCreator * libraryCreator = new LibraryCreator();
|
||||
|
||||
QDir pathDir(path);
|
||||
if (!pathDir.exists())
|
||||
{
|
||||
std::cout << "Directory not found." << std::endl;
|
||||
return;
|
||||
}
|
||||
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
|
||||
|
||||
libraryCreator->updateLibrary(cleanPath,QDir::cleanPath(pathDir.absolutePath()+"/.yacreaderlibrary"));
|
||||
|
||||
connect(libraryCreator, &LibraryCreator::finished, this, &ConsoleUILibraryCreator::done);
|
||||
connect(libraryCreator, &LibraryCreator::comicAdded, this, &ConsoleUILibraryCreator::newComic);
|
||||
connect(libraryCreator, &LibraryCreator::failedOpeningDB, this, &ConsoleUILibraryCreator::manageUpdatingError);
|
||||
|
||||
connect(libraryCreator, &LibraryCreator::finished, &eventLoop, &QEventLoop::quit);
|
||||
|
||||
std::cout << "Processing comics";
|
||||
|
||||
libraryCreator->start();
|
||||
eventLoop.exec();
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::addExistingLibrary(const QString & name, const QString & path)
|
||||
{
|
||||
QDir pathDir(path);
|
||||
if (!pathDir.exists())
|
||||
{
|
||||
std::cout << "Directory not found." << std::endl;
|
||||
return;
|
||||
}
|
||||
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
|
||||
|
||||
if (!QDir(cleanPath + "/.yacreaderlibrary").exists())
|
||||
{
|
||||
std::cout << "No library database found in directory." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
YACReaderLibraries yacreaderLibraries;
|
||||
yacreaderLibraries.load();
|
||||
if (yacreaderLibraries.contains(name))
|
||||
{
|
||||
std::cout << "A Library named \"" << name.toUtf8().constData() << "\" already exists in the database." << std::endl;
|
||||
return;
|
||||
}
|
||||
yacreaderLibraries.addLibrary(name, cleanPath);
|
||||
yacreaderLibraries.save();
|
||||
|
||||
std::cout << "Library added : " << name.toUtf8().constData() << " at " << cleanPath.toUtf8().constData() << std::endl;
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::removeLibrary(const QString & name)
|
||||
{
|
||||
//TODO add error handling
|
||||
YACReaderLibraries yacreaderLibraries;
|
||||
yacreaderLibraries.load();
|
||||
if (!yacreaderLibraries.contains(name))
|
||||
{
|
||||
std::cout << "No Library named \"" << name.toUtf8().constData() << "\" in database." << std::endl;
|
||||
return;
|
||||
}
|
||||
yacreaderLibraries.remove(name);
|
||||
yacreaderLibraries.save();
|
||||
|
||||
std::cout << "Library removed : " << name.toUtf8().constData() << std::endl;
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::newComic(const QString & /*relativeComicPath*/, const QString & /*coverPath*/)
|
||||
{
|
||||
numComicsProcessed++;
|
||||
std::cout << ".";
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::manageCreatingError(const QString & error)
|
||||
{
|
||||
std::cout << std::endl << "Error creating library! " << error.toUtf8().constData() << std::endl;
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::manageUpdatingError(const QString & error)
|
||||
{
|
||||
std::cout << std::endl << "Error updating library! " << error.toUtf8().constData() << std::endl;
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::done()
|
||||
{
|
||||
std::cout << "Done!" << std::endl;
|
||||
|
||||
if(numComicsProcessed > 0)
|
||||
std::cout << "Number of comics processed = " << numComicsProcessed << std::endl;
|
||||
}
|
||||
#include "console_ui_library_creator.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "library_creator.h"
|
||||
#include "yacreader_libraries.h"
|
||||
|
||||
|
||||
ConsoleUILibraryCreator::ConsoleUILibraryCreator(QObject *parent) :
|
||||
QObject(parent), numComicsProcessed(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::createLibrary(const QString & name, const QString & path)
|
||||
{
|
||||
QEventLoop eventLoop;
|
||||
LibraryCreator * libraryCreator = new LibraryCreator();
|
||||
|
||||
QDir pathDir(path);
|
||||
if (!pathDir.exists())
|
||||
{
|
||||
std::cout << "Directory not found." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
|
||||
|
||||
YACReaderLibraries yacreaderLibraries;
|
||||
yacreaderLibraries.load();
|
||||
if (yacreaderLibraries.contains(name))
|
||||
{
|
||||
std::cout << "A Library named \"" << name.toUtf8().constData() << "\" already exists in database." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
libraryCreator->createLibrary(cleanPath,QDir::cleanPath(pathDir.absolutePath()+"/.yacreaderlibrary"));
|
||||
|
||||
connect(libraryCreator, &LibraryCreator::finished, this, &ConsoleUILibraryCreator::done);
|
||||
connect(libraryCreator, &LibraryCreator::comicAdded, this, &ConsoleUILibraryCreator::newComic);
|
||||
connect(libraryCreator, &LibraryCreator::failedCreatingDB, this, &ConsoleUILibraryCreator::manageCreatingError);
|
||||
|
||||
connect(libraryCreator, &LibraryCreator::finished, &eventLoop, &QEventLoop::quit);
|
||||
|
||||
std::cout << "Processing comics";
|
||||
|
||||
libraryCreator->start();
|
||||
eventLoop.exec();
|
||||
|
||||
yacreaderLibraries.addLibrary(name, cleanPath);
|
||||
yacreaderLibraries.save();
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::updateLibrary(const QString & path)
|
||||
{
|
||||
QEventLoop eventLoop;
|
||||
LibraryCreator * libraryCreator = new LibraryCreator();
|
||||
|
||||
QDir pathDir(path);
|
||||
if (!pathDir.exists())
|
||||
{
|
||||
std::cout << "Directory not found." << std::endl;
|
||||
return;
|
||||
}
|
||||
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
|
||||
|
||||
libraryCreator->updateLibrary(cleanPath,QDir::cleanPath(pathDir.absolutePath()+"/.yacreaderlibrary"));
|
||||
|
||||
connect(libraryCreator, &LibraryCreator::finished, this, &ConsoleUILibraryCreator::done);
|
||||
connect(libraryCreator, &LibraryCreator::comicAdded, this, &ConsoleUILibraryCreator::newComic);
|
||||
connect(libraryCreator, &LibraryCreator::failedOpeningDB, this, &ConsoleUILibraryCreator::manageUpdatingError);
|
||||
|
||||
connect(libraryCreator, &LibraryCreator::finished, &eventLoop, &QEventLoop::quit);
|
||||
|
||||
std::cout << "Processing comics";
|
||||
|
||||
libraryCreator->start();
|
||||
eventLoop.exec();
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::addExistingLibrary(const QString & name, const QString & path)
|
||||
{
|
||||
QDir pathDir(path);
|
||||
if (!pathDir.exists())
|
||||
{
|
||||
std::cout << "Directory not found." << std::endl;
|
||||
return;
|
||||
}
|
||||
QString cleanPath = QDir::cleanPath(pathDir.absolutePath());
|
||||
|
||||
if (!QDir(cleanPath + "/.yacreaderlibrary").exists())
|
||||
{
|
||||
std::cout << "No library database found in directory." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
YACReaderLibraries yacreaderLibraries;
|
||||
yacreaderLibraries.load();
|
||||
if (yacreaderLibraries.contains(name))
|
||||
{
|
||||
std::cout << "A Library named \"" << name.toUtf8().constData() << "\" already exists in the database." << std::endl;
|
||||
return;
|
||||
}
|
||||
yacreaderLibraries.addLibrary(name, cleanPath);
|
||||
yacreaderLibraries.save();
|
||||
|
||||
std::cout << "Library added : " << name.toUtf8().constData() << " at " << cleanPath.toUtf8().constData() << std::endl;
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::removeLibrary(const QString & name)
|
||||
{
|
||||
//TODO add error handling
|
||||
YACReaderLibraries yacreaderLibraries;
|
||||
yacreaderLibraries.load();
|
||||
if (!yacreaderLibraries.contains(name))
|
||||
{
|
||||
std::cout << "No Library named \"" << name.toUtf8().constData() << "\" in database." << std::endl;
|
||||
return;
|
||||
}
|
||||
yacreaderLibraries.remove(name);
|
||||
yacreaderLibraries.save();
|
||||
|
||||
std::cout << "Library removed : " << name.toUtf8().constData() << std::endl;
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::newComic(const QString & /*relativeComicPath*/, const QString & /*coverPath*/)
|
||||
{
|
||||
numComicsProcessed++;
|
||||
std::cout << ".";
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::manageCreatingError(const QString & error)
|
||||
{
|
||||
std::cout << std::endl << "Error creating library! " << error.toUtf8().constData() << std::endl;
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::manageUpdatingError(const QString & error)
|
||||
{
|
||||
std::cout << std::endl << "Error updating library! " << error.toUtf8().constData() << std::endl;
|
||||
}
|
||||
|
||||
void ConsoleUILibraryCreator::done()
|
||||
{
|
||||
std::cout << "Done!" << std::endl;
|
||||
|
||||
if(numComicsProcessed > 0)
|
||||
std::cout << "Number of comics processed = " << numComicsProcessed << std::endl;
|
||||
}
|
||||
|
@ -1,29 +1,29 @@
|
||||
#ifndef CONSOLE_UI_LIBRARY_CREATOR_H
|
||||
#define CONSOLE_UI_LIBRARY_CREATOR_H
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class ConsoleUILibraryCreator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConsoleUILibraryCreator(QObject *parent = 0);
|
||||
void createLibrary(const QString & name, const QString & path);
|
||||
void updateLibrary(const QString & path);
|
||||
void addExistingLibrary(const QString & name, const QString & path);
|
||||
void removeLibrary(const QString & name);
|
||||
|
||||
private:
|
||||
uint numComicsProcessed;
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
protected slots:
|
||||
void newComic(const QString & relativeComicPath, const QString & coverPath);
|
||||
void manageCreatingError(const QString & error);
|
||||
void manageUpdatingError(const QString & error);
|
||||
void done();
|
||||
};
|
||||
|
||||
#endif // CONSOLE_UI_LIBRARY_CREATOR_H
|
||||
#ifndef CONSOLE_UI_LIBRARY_CREATOR_H
|
||||
#define CONSOLE_UI_LIBRARY_CREATOR_H
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class ConsoleUILibraryCreator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConsoleUILibraryCreator(QObject *parent = 0);
|
||||
void createLibrary(const QString & name, const QString & path);
|
||||
void updateLibrary(const QString & path);
|
||||
void addExistingLibrary(const QString & name, const QString & path);
|
||||
void removeLibrary(const QString & name);
|
||||
|
||||
private:
|
||||
uint numComicsProcessed;
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
protected slots:
|
||||
void newComic(const QString & relativeComicPath, const QString & coverPath);
|
||||
void manageCreatingError(const QString & error);
|
||||
void manageUpdatingError(const QString & error);
|
||||
void done();
|
||||
};
|
||||
|
||||
#endif // CONSOLE_UI_LIBRARY_CREATOR_H
|
||||
|
@ -1,257 +1,257 @@
|
||||
//#include <QtCore>
|
||||
#include <QCoreApplication>
|
||||
#include <QSysInfo>
|
||||
#include <QDir>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
#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 "libraries_updater.h"
|
||||
|
||||
#include "console_ui_library_creator.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "QsLog.h"
|
||||
#include "QsLogDest.h"
|
||||
|
||||
using namespace QsLogging;
|
||||
//Returns false in case of a parse error (unknown option or missing value); returns true otherwise.
|
||||
|
||||
|
||||
void logSystemAndConfig()
|
||||
{
|
||||
QLOG_INFO() << "---------- System & configuration ----------";
|
||||
QLOG_INFO() << "OS:" << QSysInfo::prettyProductName() << "Version: " << QSysInfo::productVersion();
|
||||
QLOG_INFO() << "Kernel:" << QSysInfo::kernelType() << QSysInfo::kernelVersion() << "Architecture:" << QSysInfo::currentCpuArchitecture();
|
||||
/* 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() << "--------------------------------------------";
|
||||
}
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
app.setApplicationName("YACReaderLibrary");
|
||||
app.setOrganizationName("YACReader");
|
||||
app.setApplicationVersion(VERSION);
|
||||
|
||||
QTextStream qout(stdout);
|
||||
|
||||
//general help
|
||||
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);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(QCoreApplication::tr("\nYACReaderLibraryServer is the headless (no gui) version of YACReaderLibrary"));
|
||||
parser.addHelpOption();
|
||||
const QCommandLineOption versionOption = parser.addVersionOption();
|
||||
parser.addPositionalArgument("command", "The command to execute. [start, create-library, update-library, add-library, remove-library, list-libraries]");
|
||||
parser.parse(app.arguments());
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
const QString command = args.isEmpty() ? QString() : args.first();
|
||||
|
||||
if(parser.isSet(versionOption))
|
||||
{
|
||||
qout << "YACReaderLibraryServer" << " " << VERSION << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(command == "start")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("start", "Start YACReaderLibraryServer");
|
||||
parser.process(app);
|
||||
|
||||
QString destLog = YACReader::getSettingsPath()+"/yacreaderlibrary.log";
|
||||
QDir().mkpath(YACReader::getSettingsPath());
|
||||
|
||||
Logger& logger = Logger::instance();
|
||||
logger.setLoggingLevel(QsLogging::InfoLevel);
|
||||
|
||||
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);
|
||||
|
||||
qRegisterMetaType<ComicDB>("ComicDB");
|
||||
|
||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/"+QCoreApplication::applicationName()+".ini",QSettings::IniFormat);
|
||||
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";
|
||||
|
||||
//Update libraries to now versions
|
||||
LibrariesUpdater updater;
|
||||
updater.updateIfNeeded();
|
||||
|
||||
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;
|
||||
}
|
||||
else if(command == "create-library")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("create-library", "Creates a library named \"name\" in the specified destination <path>");
|
||||
parser.addPositionalArgument("name", "Library name", "\"name\"");
|
||||
parser.addPositionalArgument("path", "Path to the folder where the library will be created", "<path>");
|
||||
parser.process(app);
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
if(args.length() != 3)
|
||||
{
|
||||
parser.showHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
|
||||
libraryCreatorUI->createLibrary(args.at(1), args.at(2));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(command == "update-library")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("update-library", "Updates an existing library at <path>");
|
||||
parser.addPositionalArgument("path", "Path to the library to be updated", "<path>");
|
||||
parser.process(app);
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
if(args.length() != 2)
|
||||
{
|
||||
parser.showHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
|
||||
libraryCreatorUI->updateLibrary(args.at(1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(command == "add-library")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("add-library", "Adds an exiting library named \"name\" at the specified origin <path>");
|
||||
parser.addPositionalArgument("name", "Library name", "\"name\"");
|
||||
parser.addPositionalArgument("path", "Path to the folder where the library is", "<path>");
|
||||
parser.process(app);
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
if(args.length() != 3)
|
||||
{
|
||||
parser.showHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
|
||||
libraryCreatorUI->addExistingLibrary(args.at(1), args.at(2));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(command == "remove-library")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("remove-library", "Removes a library named \"name\" from the list of libraries");
|
||||
parser.addPositionalArgument("name", "Library name", "\"name\"");
|
||||
parser.process(app);
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
if(args.length() != 2)
|
||||
{
|
||||
parser.showHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
|
||||
libraryCreatorUI->removeLibrary(args.at(1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(command == "list-libraries")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("list-libraries", "List all available libraries");
|
||||
parser.process(app);
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
for(QString libraryName : libraries.getNames())
|
||||
qout << libraryName << " : " << libraries.getPath(libraryName) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
else //error
|
||||
{
|
||||
parser.process(app);
|
||||
parser.showHelp();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
//#include <QtCore>
|
||||
#include <QCoreApplication>
|
||||
#include <QSysInfo>
|
||||
#include <QDir>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
#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 "libraries_updater.h"
|
||||
|
||||
#include "console_ui_library_creator.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "QsLog.h"
|
||||
#include "QsLogDest.h"
|
||||
|
||||
using namespace QsLogging;
|
||||
//Returns false in case of a parse error (unknown option or missing value); returns true otherwise.
|
||||
|
||||
|
||||
void logSystemAndConfig()
|
||||
{
|
||||
QLOG_INFO() << "---------- System & configuration ----------";
|
||||
QLOG_INFO() << "OS:" << QSysInfo::prettyProductName() << "Version: " << QSysInfo::productVersion();
|
||||
QLOG_INFO() << "Kernel:" << QSysInfo::kernelType() << QSysInfo::kernelVersion() << "Architecture:" << QSysInfo::currentCpuArchitecture();
|
||||
/* 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() << "--------------------------------------------";
|
||||
}
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
app.setApplicationName("YACReaderLibrary");
|
||||
app.setOrganizationName("YACReader");
|
||||
app.setApplicationVersion(VERSION);
|
||||
|
||||
QTextStream qout(stdout);
|
||||
|
||||
//general help
|
||||
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);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(QCoreApplication::tr("\nYACReaderLibraryServer is the headless (no gui) version of YACReaderLibrary"));
|
||||
parser.addHelpOption();
|
||||
const QCommandLineOption versionOption = parser.addVersionOption();
|
||||
parser.addPositionalArgument("command", "The command to execute. [start, create-library, update-library, add-library, remove-library, list-libraries]");
|
||||
parser.parse(app.arguments());
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
const QString command = args.isEmpty() ? QString() : args.first();
|
||||
|
||||
if(parser.isSet(versionOption))
|
||||
{
|
||||
qout << "YACReaderLibraryServer" << " " << VERSION << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(command == "start")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("start", "Start YACReaderLibraryServer");
|
||||
parser.process(app);
|
||||
|
||||
QString destLog = YACReader::getSettingsPath()+"/yacreaderlibrary.log";
|
||||
QDir().mkpath(YACReader::getSettingsPath());
|
||||
|
||||
Logger& logger = Logger::instance();
|
||||
logger.setLoggingLevel(QsLogging::InfoLevel);
|
||||
|
||||
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);
|
||||
|
||||
qRegisterMetaType<ComicDB>("ComicDB");
|
||||
|
||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/"+QCoreApplication::applicationName()+".ini",QSettings::IniFormat);
|
||||
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";
|
||||
|
||||
//Update libraries to now versions
|
||||
LibrariesUpdater updater;
|
||||
updater.updateIfNeeded();
|
||||
|
||||
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;
|
||||
}
|
||||
else if(command == "create-library")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("create-library", "Creates a library named \"name\" in the specified destination <path>");
|
||||
parser.addPositionalArgument("name", "Library name", "\"name\"");
|
||||
parser.addPositionalArgument("path", "Path to the folder where the library will be created", "<path>");
|
||||
parser.process(app);
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
if(args.length() != 3)
|
||||
{
|
||||
parser.showHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
|
||||
libraryCreatorUI->createLibrary(args.at(1), args.at(2));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(command == "update-library")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("update-library", "Updates an existing library at <path>");
|
||||
parser.addPositionalArgument("path", "Path to the library to be updated", "<path>");
|
||||
parser.process(app);
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
if(args.length() != 2)
|
||||
{
|
||||
parser.showHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
|
||||
libraryCreatorUI->updateLibrary(args.at(1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(command == "add-library")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("add-library", "Adds an exiting library named \"name\" at the specified origin <path>");
|
||||
parser.addPositionalArgument("name", "Library name", "\"name\"");
|
||||
parser.addPositionalArgument("path", "Path to the folder where the library is", "<path>");
|
||||
parser.process(app);
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
if(args.length() != 3)
|
||||
{
|
||||
parser.showHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
|
||||
libraryCreatorUI->addExistingLibrary(args.at(1), args.at(2));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(command == "remove-library")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("remove-library", "Removes a library named \"name\" from the list of libraries");
|
||||
parser.addPositionalArgument("name", "Library name", "\"name\"");
|
||||
parser.process(app);
|
||||
|
||||
const QStringList args = parser.positionalArguments();
|
||||
if(args.length() != 2)
|
||||
{
|
||||
parser.showHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
ConsoleUILibraryCreator * libraryCreatorUI = new ConsoleUILibraryCreator;
|
||||
libraryCreatorUI->removeLibrary(args.at(1));
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if(command == "list-libraries")
|
||||
{
|
||||
parser.clearPositionalArguments();
|
||||
parser.addPositionalArgument("list-libraries", "List all available libraries");
|
||||
parser.process(app);
|
||||
|
||||
YACReaderLibraries libraries = DBHelper::getLibraries();
|
||||
for(QString libraryName : libraries.getNames())
|
||||
qout << libraryName << " : " << libraries.getPath(libraryName) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
else //error
|
||||
{
|
||||
parser.process(app);
|
||||
parser.showHelp();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user