Commit a9e8af33 authored by schultz's avatar schultz

moved the commandline parsing further up in main function.

initialize settings before parsing command line options.
prevent double initialization.
parent bb4e1fc4
...@@ -441,9 +441,43 @@ int main(int argc, char **argv) ...@@ -441,9 +441,43 @@ int main(int argc, char **argv)
} }
// Set organization and application names
QCoreApplication::setOrganizationName("rwth-aachen.de");
QCoreApplication::setApplicationName(TOSTRING(PRODUCT_STRING));
QCoreApplication::setApplicationVersion(OpenFlipper::Options::coreVersion());
// initialize a core application to check for commandline parameters
QCoreApplication* coreApp = new QCoreApplication(argc, argv);
OpenFlipper::Options::initializeSettings();
QCommandLineParser parser; QCommandLineParser parser;
QString errorMessage; QString errorMessage;
// parse command line options
switch (parseCommandLine(parser, &errorMessage)) {
case CommandLineOk:
break;
case CommandLineError:
fputs(qPrintable(errorMessage), stderr);
fputs("\n\n", stderr);
fputs(qPrintable(parser.helpText()), stderr);
return 1;
case CommandLineVersionRequested:
printf("%s %s\n", qPrintable(QCoreApplication::applicationName()),
qPrintable(QCoreApplication::applicationVersion()));
return 0;
case CommandLineHelpRequested:
parser.showHelp();
Q_UNREACHABLE();
}
// only one application is allowed so delete the core application
// once cmdline parsing is done
delete coreApp;
#ifdef WIN32 #ifdef WIN32
//attach a console if necessary //attach a console if necessary
attachConsole(); attachConsole();
...@@ -463,26 +497,6 @@ int main(int argc, char **argv) ...@@ -463,26 +497,6 @@ int main(int argc, char **argv)
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
#endif #endif
QApplication::setColorSpec( QApplication::CustomColor ); QApplication::setColorSpec( QApplication::CustomColor );
// initialize a core application to check for commandline parameters
QCoreApplication* coreApp = new QCoreApplication(argc,argv);
// parse command line options
switch (parseCommandLine(parser, &errorMessage)) {
case CommandLineOk:
break;
case CommandLineError:
fputs(qPrintable(errorMessage), stderr);
fputs("\n\n", stderr);
fputs(qPrintable(parser.helpText()), stderr);
return 1;
case CommandLineVersionRequested:
printf("%s %s\n", qPrintable(QCoreApplication::applicationName()),
qPrintable(QCoreApplication::applicationVersion()));
return 0;
case CommandLineHelpRequested:
parser.showHelp();
Q_UNREACHABLE();
}
#if QT_VERSION >= 0x050500 #if QT_VERSION >= 0x050500
...@@ -501,11 +515,7 @@ int main(int argc, char **argv) ...@@ -501,11 +515,7 @@ int main(int argc, char **argv)
QSurfaceFormat::setDefaultFormat(format); QSurfaceFormat::setDefaultFormat(format);
// only one application is allowed so delete the core application
// once cmdline parsing is done
delete coreApp;
QApplication app(argc, argv); QApplication app(argc, argv);
QScreen *screen = app.primaryScreen(); QScreen *screen = app.primaryScreen();
QOffscreenSurface *surface = new QOffscreenSurface(); QOffscreenSurface *surface = new QOffscreenSurface();
...@@ -518,11 +528,6 @@ int main(int argc, char **argv) ...@@ -518,11 +528,6 @@ int main(int argc, char **argv)
#endif #endif
// Set organization and application names
QCoreApplication::setOrganizationName("rwth-aachen.de");
QCoreApplication::setApplicationName(TOSTRING(PRODUCT_STRING));
QCoreApplication::setApplicationVersion(OpenFlipper::Options::coreVersion());
if ( !QGLFormat::hasOpenGL() ) { if ( !QGLFormat::hasOpenGL() ) {
std::cerr << "This system has no OpenGL support.\n"; std::cerr << "This system has no OpenGL support.\n";
return -1; return -1;
......
...@@ -752,55 +752,57 @@ QString coreVersion() { ...@@ -752,55 +752,57 @@ QString coreVersion() {
static const char * const CONFIG_DIR = "." TOSTRING(PRODUCT_STRING); static const char * const CONFIG_DIR = "." TOSTRING(PRODUCT_STRING);
bool initializeSettings() { bool initializeSettings() {
if (OpenFlipper::Options::settings_ == nullptr)
{
#if defined(__INTEL_COMPILER) #if defined(__INTEL_COMPILER)
compilerInfo_ = "Intel: " + QString( TOSTRING(__INTEL_COMPILER) ) + "." + QString( TOSTRING(__GNUC_MINOR__) ) ; compilerInfo_ = "Intel: " + QString(TOSTRING(__INTEL_COMPILER)) + "." + QString(TOSTRING(__GNUC_MINOR__));
#if defined(__INTEL_COMPILER_BUILD_DATE) #if defined(__INTEL_COMPILER_BUILD_DATE)
compilerInfo_ += " BuildDate " + QString( TOSTRING(__INTEL_COMPILER_BUILD_DATE) ); compilerInfo_ += " BuildDate " + QString(TOSTRING(__INTEL_COMPILER_BUILD_DATE));
#endif #endif
#elif defined(__GNUC__) #elif defined(__GNUC__)
compilerInfo_ = "Gnu CC: " + QString( TOSTRING(__GNUC__) ) + "." + QString( TOSTRING(__GNUC_MINOR__) ) ; compilerInfo_ = "Gnu CC: " + QString(TOSTRING(__GNUC__)) + "." + QString(TOSTRING(__GNUC_MINOR__));
#if defined(__GNUC_PATCHLEVEL__) #if defined(__GNUC_PATCHLEVEL__)
compilerInfo_ += "." + QString( TOSTRING(__GNUC_PATCHLEVEL__) ); compilerInfo_ += "." + QString(TOSTRING(__GNUC_PATCHLEVEL__));
#endif #endif
#elif defined (_MSC_FULL_VER) #elif defined (_MSC_FULL_VER)
compilerInfo_ = "MSVC: " + QString( TOSTRING(_MSC_FULL_VER) ); compilerInfo_ = "MSVC: " + QString(TOSTRING(_MSC_FULL_VER));
#else #else
compilerInfo_ = "Unknown Compiler"; compilerInfo_ = "Unknown Compiler";
#endif #endif
//================================================================================================== //==================================================================================================
// Get the Main config dir in the home directory and possibly create it // Get the Main config dir in the home directory and possibly create it
//================================================================================================== //==================================================================================================
#if defined(ARCH_DARWIN) #if defined(ARCH_DARWIN)
configDir_ = QDir::home(); configDir_ = QDir::home();
if ( ! configDir_.cd("Library") ) if (!configDir_.cd("Library"))
configDir_.mkdir("Library"); configDir_.mkdir("Library");
if ( ! configDir_.cd("Application Support") ) if (!configDir_.cd("Application Support"))
configDir_.mkdir("Application Support"); configDir_.mkdir("Application Support");
if ( ! configDir_.cd("de.rwth-aachen.graphics.openflipper") ) { if (!configDir_.cd("de.rwth-aachen.graphics.openflipper")) {
configDir_.mkdir("de.rwth-aachen.graphics.openflipper"); configDir_.mkdir("de.rwth-aachen.graphics.openflipper");
if ( ! configDir_.cd("de.rwth-aachen.graphics.openflipper") ) { if (!configDir_.cd("de.rwth-aachen.graphics.openflipper")) {
std::cerr << "Unable to create config dir ~/Library/de.rwth-aachen.graphics.openflipper" << std::endl; std::cerr << "Unable to create config dir ~/Library/de.rwth-aachen.graphics.openflipper" << std::endl;
return false; return false;
} }
} }
#else #else
configDir_ = QDir::home(); configDir_ = QDir::home();
if ( ! configDir_.cd(CONFIG_DIR) ) { if (!configDir_.cd(CONFIG_DIR)) {
std::cerr << "Creating config Dir ~/" << CONFIG_DIR << std::endl;; std::cerr << "Creating config Dir ~/" << CONFIG_DIR << std::endl;;
configDir_.mkdir(CONFIG_DIR); configDir_.mkdir(CONFIG_DIR);
if ( ! configDir_.cd(CONFIG_DIR) ) { if (!configDir_.cd(CONFIG_DIR)) {
std::cerr << "Unable to create config dir ~/" << CONFIG_DIR << std::endl; std::cerr << "Unable to create config dir ~/" << CONFIG_DIR << std::endl;
return false; return false;
} }
} }
#endif #endif
//================================================================================================== //==================================================================================================
...@@ -809,10 +811,10 @@ bool initializeSettings() { ...@@ -809,10 +811,10 @@ bool initializeSettings() {
// This has to be done as early as possible to set the program options right // This has to be done as early as possible to set the program options right
// Force ini format on all platforms // Force ini format on all platforms
QSettings::setDefaultFormat ( QSettings::IniFormat ); QSettings::setDefaultFormat(QSettings::IniFormat);
// Force settings to be stored in the OpenFlipper config directory // Force settings to be stored in the OpenFlipper config directory
QSettings::setPath( QSettings::IniFormat, QSettings::UserScope , configDir_.absolutePath() ); QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, configDir_.absolutePath());
// Finally attach the settings object. // Finally attach the settings object.
settings_ = new OpenFlipperQSettings(QSettings::IniFormat, QSettings::UserScope, "ACG", "OpenFlipper"); settings_ = new OpenFlipperQSettings(QSettings::IniFormat, QSettings::UserScope, "ACG", "OpenFlipper");
...@@ -822,7 +824,7 @@ bool initializeSettings() { ...@@ -822,7 +824,7 @@ bool initializeSettings() {
//================================================================================================== //==================================================================================================
// Create a personal Icon cache dir to save for example user added icons // Create a personal Icon cache dir to save for example user added icons
if ( ! configDir_.exists("Icons") ){ if (!configDir_.exists("Icons")) {
configDir_.mkdir("Icons"); configDir_.mkdir("Icons");
std::cerr << "Creating Icon Cache Dir ~/" << CONFIG_DIR << "/Icons" << std::endl; std::cerr << "Creating Icon Cache Dir ~/" << CONFIG_DIR << "/Icons" << std::endl;
} }
...@@ -849,11 +851,11 @@ bool initializeSettings() { ...@@ -849,11 +851,11 @@ bool initializeSettings() {
dataDir_ = OpenFlipper::Options::applicationDir(); dataDir_ = OpenFlipper::Options::applicationDir();
#ifdef OPENFLIPPER_DATADIR #ifdef OPENFLIPPER_DATADIR
dataDir_.cd(OPENFLIPPER_DATADIR); dataDir_.cd(OPENFLIPPER_DATADIR);
#else #else
dataDir_ = OpenFlipper::Options::applicationDir(); dataDir_ = OpenFlipper::Options::applicationDir();
#endif #endif
// Set the Path to the Shaders // Set the Path to the Shaders
shaderDir_ = dataDir_; shaderDir_ = dataDir_;
...@@ -894,32 +896,32 @@ bool initializeSettings() { ...@@ -894,32 +896,32 @@ bool initializeSettings() {
//================================================================================================== //==================================================================================================
// User Interface Settings // User Interface Settings
if ( ! settings_->contains("Core/Gui/glViewer/defaultBackgroundColor") ) if (!settings_->contains("Core/Gui/glViewer/defaultBackgroundColor"))
settings_->setValue("Core/Gui/glViewer/defaultBackgroundColor",QColor("black")); settings_->setValue("Core/Gui/glViewer/defaultBackgroundColor", QColor("black"));
if ( ! settings_->contains("Core/Gui/glViewer/showControlWheels") ) if (!settings_->contains("Core/Gui/glViewer/showControlWheels"))
settings_->setValue("Core/Gui/glViewer/showControlWheels",false); settings_->setValue("Core/Gui/glViewer/showControlWheels", false);
// Mouse Controls // Mouse Controls
if ( ! settings_->contains("Core/Mouse/Wheel/ZoomFactor") ) if (!settings_->contains("Core/Mouse/Wheel/ZoomFactor"))
settings_->setValue("Core/Mouse/Wheel/ZoomFactor",1.0); settings_->setValue("Core/Mouse/Wheel/ZoomFactor", 1.0);
if ( ! settings_->contains("Core/Mouse/Wheel/ZoomFactorShift") ) if (!settings_->contains("Core/Mouse/Wheel/ZoomFactorShift"))
settings_->setValue("Core/Mouse/Wheel/ZoomFactorShift",0.2); settings_->setValue("Core/Mouse/Wheel/ZoomFactorShift", 0.2);
if ( ! settings_->contains("Core/Mouse/Wheel/Invert") ) if (!settings_->contains("Core/Mouse/Wheel/Invert"))
settings_->setValue("Core/Mouse/Wheel/Invert",false); settings_->setValue("Core/Mouse/Wheel/Invert", false);
// General Stereo Settings // General Stereo Settings
if ( ! settings_->contains("Core/Stereo/FocalLength") ) if (!settings_->contains("Core/Stereo/FocalLength"))
settings_->setValue("Core/Stereo/FocalLength",0.5); settings_->setValue("Core/Stereo/FocalLength", 0.5);
if ( ! settings_->contains("Core/Stereo/EyeDistance") ) if (!settings_->contains("Core/Stereo/EyeDistance"))
settings_->setValue("Core/Stereo/EyeDistance",0.07); settings_->setValue("Core/Stereo/EyeDistance", 0.07);
return true; return true;
}
} }
void closeSettings() { void closeSettings() {
...@@ -939,7 +941,7 @@ OpenFlipperQSettings& OpenFlipperSettings() { ...@@ -939,7 +941,7 @@ OpenFlipperQSettings& OpenFlipperSettings() {
// Empty standard settings object if the right settings are not available! // Empty standard settings object if the right settings are not available!
static OpenFlipperQSettings emptySettings; static OpenFlipperQSettings emptySettings;
if ( OpenFlipper::Options::settings_ ) if ( OpenFlipper::Options::settings_ != nullptr )
return *OpenFlipper::Options::settings_; return *OpenFlipper::Options::settings_;
else else
return emptySettings; return emptySettings;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment