OpenFlipper.cc 19.1 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39 40
*                                                                            *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
41

Jan Möbius's avatar
Jan Möbius committed
42 43 44 45 46 47 48
/*===========================================================================*\
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
49 50 51 52 53 54



// Mainwindow

#include "OpenFlipper/Core/Core.hh"
Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
55
#include "common/glew_wrappers.hh"
Jan Möbius's avatar
 
Jan Möbius committed
56 57 58 59 60 61

// Qt
#include <qgl.h>

// stdc++
#include <csignal>
62
#include <regex>
Jan Möbius's avatar
 
Jan Möbius committed
63 64
#include <OpenFlipper/SimpleOpt/SimpleOpt.h>

Matthias Möller's avatar
Matthias Möller committed
65
#if ( defined(WIN32))
Mike Kremer's avatar
Mike Kremer committed
66 67 68 69
  #define NO_EXECINFO
#endif

#ifndef NO_EXECINFO
70
#include <execinfo.h>
Jan Möbius's avatar
 
Jan Möbius committed
71 72 73 74 75
#endif

#ifdef USE_OPENMP
#endif

76 77 78 79 80 81 82 83
/* ==========================================================
 *
 * Stackwalker code. Used to get a backtrace if OpenFlipper
 * crashes under windows
 *
 * ==========================================================*/


84 85
#ifdef WIN32
  #include "StackWalker/StackWalker.hh"
86
  #include <fstream>
87 88 89 90 91 92

  class StackWalkerToConsole : public StackWalker
  {
  protected:
	  virtual void OnOutput(LPCSTR szText)
    	{
93 94 95
			// Writes crash dump to .OpenFlipper config directory
			std::ofstream crashFile;
			QString crashName = OpenFlipper::Options::configDirStr() + QDir::separator() + "CrashDump.txt";
Jan Möbius's avatar
Jan Möbius committed
96
			crashFile.open(crashName.toLatin1(),std::ios::out | std::ios::app);
97 98
			crashFile << szText;
			crashFile.close();
99 100 101 102
	  }
  };
#endif

103 104 105 106 107 108 109 110 111

/* ==========================================================
 *
 * Console for Windows to get additional output written via
 * cerr, cout, ... that is not forwarded to log window
 *
 * ==========================================================*/

#ifdef WIN32
112

Martin Schultz's avatar
Martin Schultz committed
113
  void attachConsole()
Jan Möbius's avatar
Jan Möbius committed
114 115 116 117 118 119 120 121 122
   {
     //try to attach the console of the parent process
     if (AttachConsole(-1))
     {
       //if the console was attached change stdinput and output
       FILE* check = freopen("CONIN$", "r", stdin);
       if (check) {
         std::cerr << "Error reopening stdin" << std::endl;
       }
Jan Möbius's avatar
Typo  
Jan Möbius committed
123
       check = freopen("CONOUT$", "w", stdout);
Jan Möbius's avatar
Jan Möbius committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
       if (check) {
         std::cerr << "Error reopening stdout" << std::endl;
       }
       check = freopen("CONOUT$", "w", stderr);
       if (check) {
         std::cerr << "Error reopening stderr" << std::endl;
       }
     }
     else
     {
       //create and attach a new console if needed
 #ifndef NDEBUG
       //always open a console in debug mode
       AllocConsole();

       FILE* check = freopen("CONIN$", "r", stdin);
       if (check) {
         std::cerr << "Error reopening stdin" << std::endl;
       }
tenter's avatar
tenter committed
143
       check = freopen("CONOUT$", "w", stdout);
Jan Möbius's avatar
Jan Möbius committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
       if (check) {
         std::cerr << "Error reopening stdout" << std::endl;
       }
       check = freopen("CONOUT$", "w", stderr);
       if (check) {
         std::cerr << "Error reopening stderr" << std::endl;
       }
       return;
 #endif
       if (OpenFlipper::Options::logToConsole())
       {
         AllocConsole();

         FILE* check = freopen("CONIN$", "r", stdin);
         if (check) {
           std::cerr << "Error reopening stdin" << std::endl;
         }
Jan Möbius's avatar
Typo  
Jan Möbius committed
161
         check = freopen("CONOUT$", "w", stdout);
Jan Möbius's avatar
Jan Möbius committed
162 163 164 165 166 167 168 169 170 171
         if (check) {
           std::cerr << "Error reopening stdout" << std::endl;
         }
         check = freopen("CONOUT$", "w", stderr);
         if (check) {
           std::cerr << "Error reopening stderr" << std::endl;
         }
       }
     }
   }
172

173 174 175 176 177 178 179 180
#endif

/* ==========================================================
 *
 * Linux function printing a full stack trace to the console
 *
 * ==========================================================*/
#ifndef NO_EXECINFO
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

#if defined(__GLIBCXX__) || defined(__GLIBCPP__)
// GCC: implement demangling using cxxabi
#include <cxxabi.h>
std::string demangle(const std::string& _symbol)
{
    int status;
    char* demangled = abi::__cxa_demangle(_symbol.c_str(), nullptr, nullptr, &status);
    if (demangled) {
        std::string result{demangled};
        free(demangled);
        if (status == 0) {
            return result;
        }
        else {
            return _symbol;
        }
    }
    else {
        return _symbol;
    }
}
#else
// other compiler environment: no demangling
std::string demangle(const std::string& _symbol)
206
{
207 208 209
    return _symbol;
}
#endif
210

211 212 213 214
void backtrace()
{
    void *addresses[20];
    char **strings;
Jan Möbius's avatar
Jan Möbius committed
215

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
    int size = backtrace(addresses, 20);
    strings = backtrace_symbols(addresses, size);
    std::cerr << "Stack frames: " << size << std::endl;
    // line format:
    // <path>(<mangled_name>+<offset>) [<address>]
    std::regex line_format{R"(^\s*(.+)\((([^()]+)?\+(0x[0-9a-f]+))?\)\s+\[(0x[0-9a-f]+)\]\s*$)"};
    for(int i = 0; i < size; i++) {
        std::string line{strings[i]};
        std::smatch match;
        std::regex_match(line, match, line_format);
        if (!match.empty()) {
            auto file_name = match[1].str();
            auto symbol = demangle(match[3].str());
            auto offset = match[4].str();
            auto address = match[5].str();
            std::cerr << i << ":";
            if (!file_name.empty()) std::cerr << " " << file_name << " ::";
            if (!symbol.empty()) std::cerr << " " << symbol;
            if (!offset.empty()) std::cerr << " (+" << offset << ")";
            if (!address.empty()) std::cerr << " [" << address << "]";
            std::cerr << std::endl;
        }
    }
    free(strings);
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
}
#endif

/* ==========================================================
 *
 * General segfault handler. This function is called if OpenFlipper
 * crashes
 *
 * ==========================================================*/
void segfaultHandling (int) {

  // prevent infinite recursion if segfaultHandling() causes another segfault
  std::signal(SIGSEGV, SIG_DFL);


  std::cerr << "\n" << std::endl;
  std::cerr << "\n" << std::endl;
  std::cerr << "\33[31m" << "=====================================================" << std::endl;
  std::cerr << "\33[31m" << "OpenFlipper or one of its plugins caused a Segfault." << std::endl;
  std::cerr << "\33[31m" << "This should not happen,... Sorry :-(" << std::endl;
  std::cerr << "\33[31m" << "=====================================================" << std::endl;
  std::cerr << "\n" << std::endl;

  // Linux Handler
#ifndef NO_EXECINFO
  std::cerr << "\33[0m"  << "Trying a backtrace to show what happened last: " << std::endl;
  backtrace();

  std::cerr << "\n" << std::endl;
  std::cerr << "Backtrace completed, trying to abort now ..." << std::endl;
#endif

  // Windows handler via StackWalker
#ifdef WIN32
  StackWalkerToConsole sw;
  sw.ShowCallstack();
#endif


Jan Möbius's avatar
Jan Möbius committed
279 280 281 282 283 284 285 286
  std::cerr << "Trying to get additional information (This might fail if the memory is corrupted)." << std::endl;

  if (OpenFlipper::Options::gui()) {
    for ( unsigned int i = 0 ; i <  4 ; ++i) {
      std::cerr << "DrawMode Viewer "<<  i << " " << PluginFunctions::drawMode(i).description() << std::endl;
    }
  }

287 288
  std::abort();
}
289

Jan Möbius's avatar
 
Jan Möbius committed
290
enum {OPT_HELP , OPT_STEREO, OPT_BATCH ,OPT_CONSOLE_LOG , OPT_DEBUGGING, OPT_FULLSCREEN,
291
      OPT_HIDDDEN_LOGGER , OPT_NOSPLASH ,OPT_HIDDDEN_TOOLBOX , OPT_LOAD_POLYMESHES,
292
      OPT_REMOTE, OPT_REMOTE_PORT};
Jan Möbius's avatar
 
Jan Möbius committed
293 294

CSimpleOpt::SOption g_rgOptions[] = {
295 296 297 298
    { OPT_DEBUGGING        , (char*) "--debug"          , SO_NONE    },
    { OPT_HELP             , (char*) "-?"               , SO_NONE    },
    { OPT_HELP             , (char*) "--help"           , SO_NONE    },
    { OPT_HELP             , (char*) "-h"               , SO_NONE    },
Jan Möbius's avatar
Jan Möbius committed
299
    { OPT_STEREO           , (char*) "--disable-stereo" , SO_NONE    },
300 301 302 303 304 305 306
    { OPT_BATCH            , (char*) "-b"               , SO_NONE    },
    { OPT_CONSOLE_LOG      , (char*) "-c"               , SO_NONE    },
    { OPT_CONSOLE_LOG      , (char*) "--log-to-console" , SO_NONE    },
    { OPT_FULLSCREEN       , (char*) "-f"               , SO_NONE    },
    { OPT_HIDDDEN_LOGGER   , (char*) "-l"               , SO_NONE    },
    { OPT_NOSPLASH         , (char*) "--no-splash"      , SO_NONE    },
    { OPT_HIDDDEN_TOOLBOX  , (char*) "-t"               , SO_NONE    },
Mike Kremer's avatar
Mike Kremer committed
307
    { OPT_LOAD_POLYMESHES  , (char*) "-p"               , SO_NONE    },
308
    { OPT_REMOTE           , (char*) "--remote-control" , SO_NONE    },
309
    { OPT_REMOTE_PORT      , (char*) "--remote-port"    , SO_REQ_SEP },
Jan Möbius's avatar
 
Jan Möbius committed
310 311 312 313
    SO_END_OF_OPTIONS                       // END
};

void showHelp() {
Jan Möbius's avatar
Jan Möbius committed
314
  std::cerr << "OpenFlipper [Options] <filenames> " << std::endl << std::endl;;
Jan Möbius's avatar
 
Jan Möbius committed
315 316
  std::cerr << "Possible Options : " << std::endl;
  std::cerr << std::endl;
317 318 319 320 321 322 323 324 325 326 327

  std::cerr << "Load/Save Options:" << std::endl;
  std::cerr << " -p \t: Open files as PolyMeshes" << std::endl;
  std::cerr << std::endl;

  std::cerr << "Gui Options:" << std::endl;
  std::cerr << " -f \t\t: Start Fullscreen" << std::endl;
  std::cerr << " -l \t\t: Start with hidden logger" << std::endl;
  std::cerr << " -t \t\t: Start with hidden Toolbox" << std::endl;
  std::cerr << " --no-splash \t: Disable splash screen" << std::endl;

Jan Möbius's avatar
 
Jan Möbius committed
328
  std::cerr << " --disable-stereo \t: Disable Stereo Mode" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
329
  std::cerr << std::endl;
330 331 332

  std::cerr << "Log options:" << std::endl;
  std::cerr << " --log-to-console ( -c ) \t: Write logger window contents to console" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
333
  std::cerr << std::endl;
334 335 336 337 338

  std::cerr << "Other options:" << std::endl;
  std::cerr << " -b \t: Batch mode, you have to provide a script for execution" << std::endl;
  std::cerr << " --remote-control \t: Batch mode accepting remote connections" << std::endl;

Jan Möbius's avatar
 
Jan Möbius committed
339
  std::cerr << std::endl;
340 341 342


  std::cerr << " -h \t: This help" << std::endl;
Jan Möbius's avatar
 
Jan Möbius committed
343 344 345
}


346 347 348



349

Dirk Wilden's avatar
Dirk Wilden committed
350 351
bool openPolyMeshes = false;
bool remoteControl  = false;
352

Dirk Wilden's avatar
Dirk Wilden committed
353
bool parseCommandLineOptions(CSimpleOpt& args){
354

355 356
  QString port;  

357 358 359
#ifndef WIN32
#ifndef __APPLE__
  //workaround for bug with stereo mode on Qt5.7.0 and Qt5.7.1 on Linux
360
  int QtVersionMajor, QtVersionMinor, QtVersionPatch;
Martin Schultz's avatar
Martin Schultz committed
361
  if(sscanf(qVersion(),"%1d.%1d.%1d",&QtVersionMajor, &QtVersionMinor, &QtVersionPatch) == 3)
362 363 364
  {
    if(QtVersionMajor == 5 && QtVersionMinor >= 7)
    {
365
      if(QtVersionPatch < 2)
366 367 368 369 370 371 372 373
      {
        std::cerr << "The used Qt Version does not support stereo mode. Disabling stereo mode." << std::endl;
        OpenFlipper::Options::stereo(false);
      }
      else
        std::cerr << "Stereo Mode has not been tested for the used Qt Version." << std::endl;
    }
  }
374 375
#endif
#endif
376

Jan Möbius's avatar
 
Jan Möbius committed
377 378
  // while there are arguments left to process
  while (args.Next()) {
Dirk Wilden's avatar
Dirk Wilden committed
379

Jan Möbius's avatar
 
Jan Möbius committed
380
    if (args.LastError() == SO_SUCCESS) {
Dirk Wilden's avatar
Dirk Wilden committed
381

Jan Möbius's avatar
 
Jan Möbius committed
382 383 384 385 386 387 388 389 390
      switch (args.OptionId() ) {
        case OPT_BATCH:
          OpenFlipper::Options::nogui(true);
        break;
        case OPT_CONSOLE_LOG:
          OpenFlipper::Options::logToConsole(true);
          break;
        case OPT_DEBUGGING:
          OpenFlipper::Options::debug(true);
391
          break;
Jan Möbius's avatar
 
Jan Möbius committed
392
        case OPT_STEREO:
393 394
          OpenFlipper::Options::stereo(false);
          break;
Jan Möbius's avatar
 
Jan Möbius committed
395
        case OPT_HIDDDEN_TOOLBOX:
396 397
          OpenFlipperSettings().setValue("Core/Gui/ToolBoxes/hidden",true);
          break;
Jan Möbius's avatar
 
Jan Möbius committed
398
        case OPT_HIDDDEN_LOGGER:
399 400
          OpenFlipper::Options::loggerState(OpenFlipper::Options::Hidden);
          break;
Jan Möbius's avatar
 
Jan Möbius committed
401
        case OPT_FULLSCREEN:
402 403
          OpenFlipperSettings().setValue("Core/Gui/fullscreen",false);
          break;
Jan Möbius's avatar
 
Jan Möbius committed
404
        case OPT_LOAD_POLYMESHES:
405 406
          openPolyMeshes = true;
          break;
Jan Möbius's avatar
 
Jan Möbius committed
407
        case OPT_NOSPLASH:
408 409
          OpenFlipperSettings().setValue("Core/Gui/splash",false);
          break;
Jan Möbius's avatar
 
Jan Möbius committed
410
        case OPT_REMOTE:
411 412 413 414 415 416 417
          OpenFlipper::Options::remoteControl(true);
          break;
        case OPT_REMOTE_PORT:
          port = args.OptionArg();
          std::cerr << "Got option : " << port.toStdString() << std::endl;
          OpenFlipper::Options::remoteControl(port.toInt());
          break;
Jan Möbius's avatar
 
Jan Möbius committed
418 419 420 421 422 423 424
        case OPT_HELP:
          showHelp();
          return 0;
      }
    } else {
      std::cerr << "Invalid argument: " << args.OptionText() << std::endl;
      showHelp();
Dirk Wilden's avatar
Dirk Wilden committed
425
      return false;
Jan Möbius's avatar
 
Jan Möbius committed
426 427
    }
  }
Dirk Wilden's avatar
Dirk Wilden committed
428 429 430 431 432
  return true;
}

int main(int argc, char **argv)
{
433

434 435
  // Remove -psn_0_xxxxx argument which is automatically
  // attached by MacOSX
Mike Kremer's avatar
 
Mike Kremer committed
436
  for (int i = 0; i < argc; i++) {
437 438 439 440 441
    if(strlen(argv[i]) > 4) {
      if( ( (argv[i])[0] == '-' ) &&
        ( (argv[i])[1] == 'p' ) &&
        ( (argv[i])[2] == 's' ) &&
        ( (argv[i])[3] == 'n' ) ) {
Jan Möbius's avatar
Jan Möbius committed
442 443
        argc--;
        argv[i] = (char *)"";
444 445 446
      }
    }
  }
Jan Möbius's avatar
Jan Möbius committed
447

Dirk Wilden's avatar
Dirk Wilden committed
448 449 450
  OpenFlipper::Options::argc(&argc);
  OpenFlipper::Options::argv(&argv);

Dirk Wilden's avatar
Dirk Wilden committed
451
  CSimpleOpt argBatch(argc, argv, g_rgOptions);
Dirk Wilden's avatar
Dirk Wilden committed
452

Dirk Wilden's avatar
Dirk Wilden committed
453
  //check only batchMode before the core is created
Dirk Wilden's avatar
Dirk Wilden committed
454 455
  while (argBatch.Next())
    if (argBatch.OptionId() == OPT_BATCH ){
Dirk Wilden's avatar
Dirk Wilden committed
456 457 458 459
      OpenFlipper::Options::nogui(true);
      break;
    }

Dirk Wilden's avatar
Dirk Wilden committed
460 461
  CSimpleOpt args(argc, argv, g_rgOptions);

462
#ifndef NO_CATCH_SIGSEGV
Dirk Wilden's avatar
Dirk Wilden committed
463 464
  // Set a handler for segfaults
  std::signal(SIGSEGV, segfaultHandling);
465
#endif
Dirk Wilden's avatar
Dirk Wilden committed
466

Jan Möbius's avatar
Jan Möbius committed
467
  OpenFlipper::Options::windowTitle(TOSTRING(PRODUCT_STRING)" v" + OpenFlipper::Options::coreVersion());
468

Jan Möbius's avatar
 
Jan Möbius committed
469
  if ( !OpenFlipper::Options::nogui() ) {
470

Jan Möbius's avatar
 
Jan Möbius committed
471 472 473
    // OpenGL check
    QApplication::setColorSpec( QApplication::CustomColor );
    QApplication app(argc,argv);
474

475
#ifdef __APPLE__
Mike Kremer's avatar
Mike Kremer committed
476
    // Set organization and application names
477 478 479 480
    QCoreApplication::setOrganizationName("rwth-aachen.de");
    QCoreApplication::setApplicationName("graphics.openflipper");
#endif

Jan Möbius's avatar
 
Jan Möbius committed
481 482 483 484
    if ( !QGLFormat::hasOpenGL() ) {
      std::cerr << "This system has no OpenGL support.\n";
      return -1;
    }
485

486
#ifndef __APPLE__
Jan Möbius's avatar
 
Jan Möbius committed
487
    glutInit(&argc,argv);
488
#endif
489

Jan Möbius's avatar
 
Jan Möbius committed
490 491
    // create core ( this also reads the ini files )
    Core * w = new Core( );
492

Jan Möbius's avatar
Jan Möbius committed
493 494
    if ( !parseCommandLineOptions(args) ) {
      delete w;
Dirk Wilden's avatar
Dirk Wilden committed
495
      return 1;
Jan Möbius's avatar
Jan Möbius committed
496
    }
497

Marti's avatar
Marti committed
498
#ifdef WIN32
499
	//attach a console if necessary
Martin Schultz's avatar
Martin Schultz committed
500
	attachConsole();
Marti's avatar
Marti committed
501
#endif
Dirk Wilden's avatar
Dirk Wilden committed
502

503
    QString tLang = OpenFlipperSettings().value("Core/Language/Translation","en_US").toString();
504 505 506 507

    if (tLang == "locale")
      tLang = QLocale::system().name();

508 509
    // Install translator for qt internals
    QTranslator qtTranslator;
Jan Möbius's avatar
Jan Möbius committed
510 511 512 513 514 515 516
//     std::cerr << "Loading qt translations from: " << QLibraryInfo::location(QLibraryInfo::TranslationsPath).toStdString() << std::endl;
//     if ( qtTranslator.load("qt_" + tLang, QLibraryInfo::location(QLibraryInfo::TranslationsPath)) )
//       std::cerr << "Loaded" << std::endl;
//     std::cerr << "Loading qt translations from: " << QLibraryInfo::location(QLibraryInfo::TranslationsPath).toStdString() << std::endl;
    qtTranslator.load("qt_" + tLang, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
//       std::cerr << "Loaded" << std::endl;

517 518 519
    app.installTranslator(&qtTranslator);
    
    // install translator for Core Application
Dirk Wilden's avatar
Dirk Wilden committed
520
    QString translationDir = OpenFlipper::Options::translationsDirStr() + QDir::separator();
521

Jan Möbius's avatar
Jan Möbius committed
522
//     std::cerr << "Loading own translations from: " << QString(translationDir + " (" + tLang + ")").toStdString() << std::endl;
Dirk Wilden's avatar
Dirk Wilden committed
523 524 525 526 527 528 529 530 531 532 533 534 535

    QDir dir(translationDir);
    dir.setFilter(QDir::Files);

    QFileInfoList list = dir.entryInfoList();

    for (int i = 0; i < list.size(); ++i) {
      QFileInfo fileInfo = list.at(i);

      if ( fileInfo.baseName().contains(tLang) ){
        QTranslator* myAppTranslator = new QTranslator();

        if ( myAppTranslator->load( fileInfo.filePath() ) ){
Jan Möbius's avatar
Jan Möbius committed
536
//           std::cerr << "Loaded " << fileInfo.fileName().toStdString() << std::endl;
537
    
Dirk Wilden's avatar
Dirk Wilden committed
538
          app.installTranslator(myAppTranslator);
Jan Möbius's avatar
Jan Möbius committed
539 540
        } else {
  	  delete myAppTranslator;
Dirk Wilden's avatar
Dirk Wilden committed
541 542 543
        }
      }
     }
Jan's avatar
Jan committed
544
    
545
    // After setting all Options from command line, build the real gui
Jan's avatar
Jan committed
546 547 548 549 550
    w->init();

    #ifndef __APPLE__
    initGlew();
    #endif
Jan Möbius's avatar
Jan Möbius committed
551
 
552
    for ( int i = 0 ; i < args.FileCount(); ++i )
553
      w->commandLineOpen(args.File(i), openPolyMeshes);    
554

Jan Möbius's avatar
 
Jan Möbius committed
555
    return app.exec();
556

Jan Möbius's avatar
 
Jan Möbius committed
557
  } else {
558

Jan Möbius's avatar
 
Jan Möbius committed
559
    QCoreApplication app(argc,argv);
560

561
#ifdef __APPLE__
Mike Kremer's avatar
Mike Kremer committed
562
    // Set organization and application names
563 564 565 566
    QCoreApplication::setOrganizationName("rwth-aachen.de");
    QCoreApplication::setApplicationName("graphics.openflipper");
#endif

Jan Möbius's avatar
 
Jan Möbius committed
567 568
    // create widget ( this also reads the ini files )
    Core * w = new Core( );
569

Jan Möbius's avatar
Jan Möbius committed
570 571
    if ( !parseCommandLineOptions(args) ) {
      delete w;
Dirk Wilden's avatar
Dirk Wilden committed
572
      return 1;
Jan Möbius's avatar
Jan Möbius committed
573
    }
Dirk Wilden's avatar
Dirk Wilden committed
574

Jan Möbius's avatar
 
Jan Möbius committed
575 576
    // After setting all Options from command line, build the real gui
    w->init();
577 578 579 580

    for ( int i = 0 ; i < args.FileCount(); ++i )
      w->commandLineScript(args.File(i));

Dirk Wilden's avatar
Dirk Wilden committed
581
    return app.exec();
Jan Möbius's avatar
 
Jan Möbius committed
582 583 584 585
  }

  return 0;
}