2016-04-25 22:30:11 +02:00
|
|
|
#include "../lib/alpm/manager.h"
|
|
|
|
#include "../lib/alpm/utilities.h"
|
|
|
|
#include "../lib/alpm/config.h"
|
2016-02-27 21:00:58 +01:00
|
|
|
|
2016-04-25 22:30:11 +02:00
|
|
|
#include "../lib/network/server.h"
|
2016-02-27 21:00:58 +01:00
|
|
|
|
2016-04-25 22:30:11 +02:00
|
|
|
#include "./mainwindow.h"
|
2016-02-27 21:00:58 +01:00
|
|
|
|
|
|
|
#include "resources/config.h"
|
|
|
|
|
|
|
|
#include <qtutilities/resources/qtconfigarguments.h>
|
|
|
|
#include <qtutilities/resources/resources.h>
|
|
|
|
|
|
|
|
#include <c++utilities/application/argumentparser.h>
|
|
|
|
#include <c++utilities/conversion/stringconversion.h>
|
|
|
|
#include <c++utilities/application/failure.h>
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace ApplicationUtilities;
|
|
|
|
using namespace RepoIndex;
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
// setup the argument parser
|
|
|
|
ArgumentParser parser;
|
|
|
|
SET_APPLICATION_INFO;
|
|
|
|
SET_QT_APPLICATION_INFO;
|
|
|
|
QT_CONFIG_ARGUMENTS qtConfigArgs;
|
|
|
|
ConfigArgs configArgs(parser);
|
|
|
|
parser.setIgnoreUnknownArguments(false);
|
2016-05-26 02:29:56 +02:00
|
|
|
Argument webdirArg("web-dir", '\0', "specifies the directory of the web files");
|
2016-02-27 21:00:58 +01:00
|
|
|
webdirArg.setCombinable(true);
|
|
|
|
webdirArg.setRequiredValueCount(1);
|
|
|
|
webdirArg.setValueNames({"path"});
|
|
|
|
for(Argument *arg : initializer_list<Argument *>{&configArgs.rootdirArg, &configArgs.dbpathArg, &configArgs.pacmanConfArg, &configArgs.reposFromPacmanConfEnabled, &configArgs.aurArg}) {
|
2016-05-26 02:29:56 +02:00
|
|
|
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(arg);
|
2016-02-27 21:00:58 +01:00
|
|
|
}
|
|
|
|
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &configArgs.repoindexConfArg, &configArgs.repoindexConfArg, &webdirArg, &configArgs.cacheDirArg, &configArgs.storageDirArg, &configArgs.helpArg});
|
|
|
|
// parse command line arguments
|
|
|
|
try {
|
|
|
|
parser.parseArgs(argc, argv);
|
|
|
|
} catch (const Failure &e) {
|
|
|
|
cerr << shchar << "Unable to parse arguments: " << e.what() << endl;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
// load configuration
|
|
|
|
Config config;
|
|
|
|
config.loadFromConfigFile(configArgs);
|
|
|
|
config.loadFromArgs(configArgs);
|
|
|
|
config.loadLocalOnlySetup();
|
|
|
|
config.setServerCloseable(false);
|
|
|
|
|
|
|
|
if(qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
|
|
|
|
// configure Qt
|
|
|
|
qtConfigArgs.applySettings();
|
2016-02-28 02:33:25 +01:00
|
|
|
QApplication application(argc, argv);
|
2016-02-27 21:00:58 +01:00
|
|
|
|
|
|
|
// find directory with web files
|
|
|
|
QString webdir;
|
|
|
|
if(webdirArg.isPresent()) {
|
2016-05-26 02:29:56 +02:00
|
|
|
webdir = QString::fromLocal8Bit(webdirArg.values().front());
|
2016-02-27 21:00:58 +01:00
|
|
|
} else {
|
|
|
|
webdir = QStringLiteral("/usr/share/" PROJECT_NAME "/web");
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup manager
|
|
|
|
Manager manager(config);
|
|
|
|
cerr << shchar << "Loading databases ..." << endl;
|
|
|
|
if(config.areReposFromPacmanConfEnabled()) {
|
|
|
|
manager.addDataBasesFromPacmanConfig();
|
|
|
|
}
|
|
|
|
manager.addDatabasesFromRepoIndexConfig();
|
|
|
|
manager.initAlpmDataBases();
|
|
|
|
cerr << shchar << "Restoring cache ... ";
|
|
|
|
manager.restoreCache();
|
|
|
|
cerr << shchar << "DONE" << endl;
|
|
|
|
|
|
|
|
// setup the server
|
|
|
|
Server server(manager, manager.config());
|
|
|
|
manager.setAutoCacheMaintenanceEnabled(true);
|
|
|
|
manager.setAutoUpdateEnabled(true);
|
|
|
|
|
2016-02-28 02:33:25 +01:00
|
|
|
// create app
|
|
|
|
MainWindow mainWindow(webdir, &manager);
|
|
|
|
mainWindow.show();
|
|
|
|
|
2016-02-27 21:00:58 +01:00
|
|
|
// run Qt event loop
|
|
|
|
return application.exec();
|
|
|
|
|
|
|
|
} else if(!configArgs.helpArg.isPresent()) {
|
|
|
|
if(useShSyntax) {
|
|
|
|
cerr << "export REPOINDEX_ERROR='No command line arguments specified. See --help for available commands.'" << endl;
|
|
|
|
} else {
|
|
|
|
cerr << "No command line arguments specified. See --help for available commands." << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (const exception &ex) {
|
|
|
|
Utilities::printError(ex);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|