mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-11 07:56:08 -06:00
* If you run a GUI-version this is likely to be checked anyway through Qt or GTK+ but not the console version.
124 lines
3.8 KiB
C++
124 lines
3.8 KiB
C++
/////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
|
//
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
//
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
// for more details.
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "RiaArgumentParser.h"
|
|
#include "RiaConsoleApplication.h"
|
|
#include "RiaGuiApplication.h"
|
|
#include "RiaLogging.h"
|
|
|
|
#include "cvfProgramOptions.h"
|
|
#include "cvfqtUtils.h"
|
|
|
|
#ifndef WIN32
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#endif
|
|
|
|
RiaApplication* createApplication(int &argc, char *argv[])
|
|
{
|
|
for (int i = 1; i < argc; ++i)
|
|
{
|
|
if (!qstrcmp(argv[i], "--console") || !qstrcmp(argv[i], "--unittest"))
|
|
{
|
|
return new RiaConsoleApplication(argc, argv);
|
|
}
|
|
}
|
|
return new RiaGuiApplication(argc, argv);
|
|
}
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
#ifndef WIN32
|
|
// From Qt 5.3 and onwards Qt has a mechanism for checking this automatically
|
|
// But it only checks user id not group id, so better to do it ourselves.
|
|
if (getuid() != geteuid() || getgid() != getegid())
|
|
{
|
|
std::cerr << "FATAL: The application binary appears to be running setuid or setgid, this is a security hole." << std::endl;
|
|
return 1;
|
|
}
|
|
#endif
|
|
RiaLogging::loggerInstance()->setLevel(RI_LL_DEBUG);
|
|
|
|
std::unique_ptr<RiaApplication> app (createApplication(argc, argv));
|
|
|
|
cvf::ProgramOptions progOpt;
|
|
bool result = RiaArgumentParser::parseArguments(&progOpt);
|
|
|
|
app->initialize();
|
|
|
|
if (!result)
|
|
{
|
|
std::vector<cvf::String> unknownOptions = progOpt.unknownOptions();
|
|
QStringList unknownOptionsText;
|
|
for (cvf::String option : unknownOptions)
|
|
{
|
|
unknownOptionsText += QString("Unknown option: %1").arg(cvfqt::Utils::toQString(option));
|
|
}
|
|
|
|
const cvf::String usageText = progOpt.usageText(110, 30);
|
|
app->showErrorMessage(RiaApplication::commandLineParameterHelp() +
|
|
cvfqt::Utils::toQString(usageText) +
|
|
unknownOptionsText.join("\n"));
|
|
if (dynamic_cast<RiaGuiApplication*>(app.get()) == nullptr)
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
|
|
setlocale(LC_NUMERIC,"C");
|
|
|
|
RiaApplication::ApplicationStatus status = app->handleArguments(&progOpt);
|
|
if (status == RiaApplication::EXIT_COMPLETED)
|
|
{
|
|
return 0;
|
|
}
|
|
else if (status == RiaApplication::EXIT_WITH_ERROR)
|
|
{
|
|
return 2;
|
|
}
|
|
else if (status == RiaApplication::KEEP_GOING)
|
|
{
|
|
int exitCode = 0;
|
|
try
|
|
{
|
|
if (app->initializeGrpcServer(progOpt))
|
|
{
|
|
app->launchGrpcServer();
|
|
}
|
|
exitCode = QCoreApplication::instance()->exec();
|
|
}
|
|
catch (std::exception& exep )
|
|
{
|
|
std::cout << "A standard c++ exception that terminated ResInsight caught in RiaMain.cpp: " << exep.what() << std::endl;
|
|
throw;
|
|
}
|
|
catch(...)
|
|
{
|
|
std::cout << "An unknown exception that terminated ResInsight caught in RiaMain.cpp. " << std::endl;
|
|
throw;
|
|
}
|
|
|
|
return exitCode;
|
|
}
|
|
|
|
CVF_ASSERT(false && "Unknown ApplicationStatus");
|
|
return -1;
|
|
}
|
|
|