2019-04-06 17:16:42 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QProcessEnvironment>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QDebug>
|
2020-05-23 22:52:42 +02:00
|
|
|
#include <QSettings>
|
2019-04-06 17:16:42 +02:00
|
|
|
#include <functional>
|
2022-04-14 15:03:19 +02:00
|
|
|
#include <QTimer>
|
|
|
|
|
2019-04-06 17:16:42 +02:00
|
|
|
#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"
|
2021-08-07 18:38:23 +02:00
|
|
|
#include "sandboxedprocessor.h"
|
2020-05-23 22:52:42 +02:00
|
|
|
#include "../shared/common.h"
|
2022-04-14 15:03:19 +02:00
|
|
|
#include "../shared/filescanworker.h"
|
2020-05-23 22:52:42 +02:00
|
|
|
|
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();
|
2021-08-07 18:38:23 +02:00
|
|
|
|
2019-04-06 17:16:42 +02:00
|
|
|
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;
|
|
|
|
}
|
2021-08-07 18:38:23 +02:00
|
|
|
qRegisterMetaType<PageData>();
|
2022-04-14 15:03:19 +02:00
|
|
|
qRegisterMetaType<FileScanResult>("FileScanResult");
|
2020-08-24 21:36:45 +02:00
|
|
|
|
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();
|
2021-08-07 18:38:23 +02:00
|
|
|
if(commandName == "process")
|
|
|
|
{
|
|
|
|
if(args.length() < 1)
|
|
|
|
{
|
|
|
|
qDebug() << "Filename is required";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString file = args.at(1);
|
|
|
|
SandboxedProcessor processor(file);
|
|
|
|
return processor.process();
|
|
|
|
}
|
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
|
|
|
|
{
|
2022-04-14 15:03:19 +02:00
|
|
|
QObject::connect(cmd, &Command::finishedCmd, [](int retval) { QCoreApplication::exit(retval); });
|
|
|
|
cmd->setArguments(args);
|
|
|
|
QTimer::singleShot(0, cmd, &Command::execute);
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
2021-06-12 14:59:58 +02:00
|
|
|
catch(const LooqsGeneralException &e)
|
2019-04-06 17:16:42 +02:00
|
|
|
{
|
2022-04-24 19:40:28 +02:00
|
|
|
Logger::error() << "Exception caught, message:" << e.message << Qt::endl;
|
|
|
|
return 1;
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-24 19:40:28 +02:00
|
|
|
Logger::error() << "Unknown command:" << commandName << Qt::endl;
|
|
|
|
return 1;
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|
2022-04-14 15:03:19 +02:00
|
|
|
|
|
|
|
return app.exec();
|
2019-04-06 17:16:42 +02:00
|
|
|
}
|