2019-04-06 17:16:42 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QProcessEnvironment>
|
|
|
|
#include <QSqlDatabase>
|
|
|
|
#include <QSqlQuery>
|
|
|
|
#include <QSqlError>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QDebug>
|
2020-05-23 22:52:42 +02:00
|
|
|
#include <QSettings>
|
2019-04-06 17:16:42 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <exception>
|
|
|
|
#include "encodingdetector.h"
|
|
|
|
#include "pdfprocessor.h"
|
|
|
|
#include "defaulttextprocessor.h"
|
2019-04-10 18:57:27 +02:00
|
|
|
#include "utils.h"
|
2019-04-06 17:16:42 +02:00
|
|
|
#include "command.h"
|
|
|
|
#include "commandadd.h"
|
2019-04-07 20:22:20 +02:00
|
|
|
#include "commanddelete.h"
|
2019-04-16 08:54:49 +02:00
|
|
|
#include "commandupdate.h"
|
2019-04-20 23:31:14 +02:00
|
|
|
#include "commandsearch.h"
|
2019-04-16 08:54:49 +02:00
|
|
|
#include "databasefactory.h"
|
|
|
|
#include "logger.h"
|
2020-05-23 22:52:42 +02:00
|
|
|
#include "../shared/common.h"
|
|
|
|
|
2019-04-06 17:16:42 +02:00
|
|
|
void printUsage(QString argv0)
|
|
|
|
{
|
2020-05-24 15:36:27 +02:00
|
|
|
qInfo() << "Usage:" << argv0 << "command";
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
|
|
|
|
2019-04-16 08:54:49 +02:00
|
|
|
Command *commandFromName(QString name, SqliteDbService &dbService)
|
2019-04-06 17:16:42 +02:00
|
|
|
{
|
|
|
|
if(name == "add")
|
|
|
|
{
|
2019-04-16 08:54:49 +02:00
|
|
|
return new CommandAdd(dbService);
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
|
|
|
if(name == "delete")
|
|
|
|
{
|
2019-04-16 08:54:49 +02:00
|
|
|
return new CommandDelete(dbService);
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
|
|
|
if(name == "update")
|
|
|
|
{
|
2019-04-16 08:54:49 +02:00
|
|
|
return new CommandUpdate(dbService);
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
|
|
|
if(name == "search")
|
|
|
|
{
|
2019-04-20 23:31:14 +02:00
|
|
|
return new CommandSearch(dbService);
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
2019-04-20 23:31:14 +02:00
|
|
|
|
2019-04-06 17:16:42 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2020-05-23 22:52:42 +02:00
|
|
|
Common::setupAppInfo();
|
|
|
|
QCoreApplication app(argc, argv);
|
2019-04-06 17:16:42 +02:00
|
|
|
QStringList args = app.arguments();
|
|
|
|
QString argv0 = args.takeFirst();
|
|
|
|
if(args.length() < 1)
|
|
|
|
{
|
|
|
|
printUsage(argv0);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2020-08-24 21:36:45 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Common::ensureConfigured();
|
|
|
|
}
|
2021-06-12 14:59:58 +02:00
|
|
|
catch(LooqsGeneralException &e)
|
2020-08-24 21:36:45 +02:00
|
|
|
{
|
|
|
|
Logger::error() << "Error: " << e.message;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-05-24 15:36:27 +02:00
|
|
|
QString connectionString = Common::databasePath();
|
2019-04-16 08:54:49 +02:00
|
|
|
DatabaseFactory dbFactory(connectionString);
|
|
|
|
SqliteDbService dbService(dbFactory);
|
2020-05-24 15:36:27 +02:00
|
|
|
QString commandName = args.first();
|
2019-04-16 08:54:49 +02:00
|
|
|
Command *cmd = commandFromName(commandName, dbService);
|
2019-04-06 17:16:42 +02:00
|
|
|
if(cmd != nullptr)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return cmd->handle(args);
|
|
|
|
}
|
2021-06-12 14:59:58 +02:00
|
|
|
catch(const LooqsGeneralException &e)
|
2019-04-06 17:16:42 +02:00
|
|
|
{
|
2019-04-16 08:54:49 +02:00
|
|
|
Logger::error() << "Exception caught, message: " << e.message << endl;
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-16 08:54:49 +02:00
|
|
|
Logger::error() << "Unknown command " << commandName << endl;
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|