2010-02-28 13:51:17 +00:00
# include <iostream>
2013-12-05 13:28:39 +00:00
# include <cstdio>
2010-02-28 13:51:17 +00:00
2014-01-22 16:33:55 +00:00
# include <components/version/version.hpp>
2012-01-21 00:14:35 +00:00
# include <components/files/configurationmanager.hpp>
2011-04-28 07:39:40 +00:00
2014-06-10 02:10:34 +00:00
# include <SDL_messagebox.h>
# include <SDL_main.h>
2010-06-16 10:13:21 +00:00
# include "engine.hpp"
2010-02-28 13:51:17 +00:00
2011-01-04 00:34:55 +00:00
# include <boost/iostreams/concepts.hpp>
2010-09-19 00:01:01 +00:00
# include <boost/iostreams/stream_buffer.hpp>
2014-06-11 14:17:48 +00:00
# include <boost/filesystem/fstream.hpp>
2010-09-19 00:01:01 +00:00
2014-06-10 00:22:58 +00:00
# if defined(_WIN32)
2010-09-19 00:01:01 +00:00
// For OutputDebugString
2014-01-04 05:30:43 +00:00
# define WIN32_LEAN_AND_MEAN
2010-09-19 00:01:01 +00:00
# include <Windows.h>
// makes __argc and __argv available on windows
2012-07-17 07:44:24 +00:00
# include <cstdlib>
2010-09-19 00:01:01 +00:00
# endif
2013-11-16 14:56:15 +00:00
# if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
2013-11-16 16:00:26 +00:00
# include <csignal>
2013-11-16 14:56:15 +00:00
extern int cc_install_handlers ( int argc , char * * argv , int num_signals , int * sigs , const char * logfile , int ( * user_info ) ( char * , char * ) ) ;
extern int is_debugger_attached ( void ) ;
# endif
2011-06-25 15:29:11 +00:00
// for Ogre::macBundlePath
# if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
# include <OSX/macUtils.h>
# endif
2012-02-24 19:19:32 +00:00
# include <boost/version.hpp>
/**
* Workaround for problems with whitespaces in paths in older versions of Boost library
*/
# if (BOOST_VERSION <= 104600)
namespace boost
{
template < >
inline boost : : filesystem : : path lexical_cast < boost : : filesystem : : path , std : : string > ( const std : : string & arg )
{
return boost : : filesystem : : path ( arg ) ;
}
} /* namespace boost */
# endif /* (BOOST_VERSION <= 104600) */
2012-04-02 23:47:43 +00:00
struct FallbackMap {
std : : map < std : : string , std : : string > mMap ;
2012-04-03 00:14:39 +00:00
} ;
2012-04-02 23:47:43 +00:00
2012-04-03 00:14:39 +00:00
void validate ( boost : : any & v , std : : vector < std : : string > const & tokens , FallbackMap * , int )
{
if ( v . empty ( ) )
2012-04-02 23:47:43 +00:00
{
2012-04-03 00:14:39 +00:00
v = boost : : any ( FallbackMap ( ) ) ;
}
FallbackMap * map = boost : : any_cast < FallbackMap > ( & v ) ;
std : : map < std : : string , std : : string > : : iterator mapIt ;
2013-07-31 16:46:32 +00:00
for ( std : : vector < std : : string > : : const_iterator it = tokens . begin ( ) ; it ! = tokens . end ( ) ; + + it )
2012-04-03 00:14:39 +00:00
{
int sep = it - > find ( " , " ) ;
2012-04-04 21:51:22 +00:00
if ( sep < 1 | | sep = = ( int ) it - > length ( ) - 1 )
2012-04-04 21:52:42 +00:00
# if (BOOST_VERSION < 104200)
2012-04-04 21:51:22 +00:00
throw boost : : program_options : : validation_error ( " invalid value " ) ;
# else
2012-04-04 13:23:14 +00:00
throw boost : : program_options : : validation_error ( boost : : program_options : : validation_error : : invalid_option_value ) ;
2012-04-04 22:16:44 +00:00
# endif
2012-04-03 00:14:39 +00:00
std : : string key ( it - > substr ( 0 , sep ) ) ;
std : : string value ( it - > substr ( sep + 1 ) ) ;
if ( ( mapIt = map - > mMap . find ( key ) ) = = map - > mMap . end ( ) )
2012-04-02 23:47:43 +00:00
{
2012-10-09 15:10:25 +00:00
map - > mMap . insert ( std : : make_pair ( key , value ) ) ;
2012-04-02 23:47:43 +00:00
}
2012-04-03 00:14:39 +00:00
}
}
2012-04-02 23:47:43 +00:00
2011-08-19 19:06:09 +00:00
/**
* \ brief Parses application command line and calls \ ref Cfg : : ConfigurationManager
* to parse configuration files .
*
* Results are directly written to \ ref Engine class .
*
* \ retval true - Everything goes OK
* \ retval false - Error
*/
2012-01-21 00:14:35 +00:00
bool parseOptions ( int argc , char * * argv , OMW : : Engine & engine , Files : : ConfigurationManager & cfgMgr )
2010-02-28 13:51:17 +00:00
{
2010-06-27 23:44:15 +00:00
// Create a local alias for brevity
2010-10-05 16:23:53 +00:00
namespace bpo = boost : : program_options ;
2011-08-19 19:06:09 +00:00
typedef std : : vector < std : : string > StringsVector ;
2010-06-27 23:44:15 +00:00
2011-08-19 19:06:09 +00:00
bpo : : options_description desc ( " Syntax: openmw <options> \n Allowed options " ) ;
2010-06-10 08:31:50 +00:00
desc . add_options ( )
2011-08-19 19:06:09 +00:00
( " help " , " print help message " )
2011-07-08 14:16:20 +00:00
( " version " , " print version information and quit " )
2011-09-02 20:45:21 +00:00
( " data " , bpo : : value < Files : : PathContainer > ( ) - > default_value ( Files : : PathContainer ( ) , " data " )
2011-08-19 19:06:09 +00:00
- > multitoken ( ) , " set data directories (later directories have higher priority) " )
( " data-local " , bpo : : value < std : : string > ( ) - > default_value ( " " ) ,
2011-05-05 17:50:28 +00:00
" set local data directory (highest priority) " )
2011-08-19 19:06:09 +00:00
2013-03-09 20:08:08 +00:00
( " fallback-archive " , bpo : : value < StringsVector > ( ) - > default_value ( StringsVector ( ) , " fallback-archive " )
- > multitoken ( ) , " set fallback BSA archives (later archives have higher priority) " )
2011-08-19 19:06:09 +00:00
( " resources " , bpo : : value < std : : string > ( ) - > default_value ( " resources " ) ,
2011-01-04 00:34:55 +00:00
" set resources directory " )
2011-08-19 19:06:09 +00:00
2013-11-16 11:08:00 +00:00
( " start " , bpo : : value < std : : string > ( ) - > default_value ( " " ) ,
2010-10-05 16:23:53 +00:00
" set initial cell " )
2011-08-19 19:06:09 +00:00
2013-09-29 07:11:57 +00:00
( " content " , bpo : : value < StringsVector > ( ) - > default_value ( StringsVector ( ) , " " )
- > multitoken ( ) , " content file(s): esm/esp, or omwgame/omwaddon " )
2011-08-19 19:06:09 +00:00
2013-12-26 01:24:12 +00:00
( " no-sound " , bpo : : value < bool > ( ) - > implicit_value ( true )
2011-08-19 19:06:09 +00:00
- > default_value ( false ) , " disable all sounds " )
2012-04-02 18:47:09 +00:00
( " script-verbose " , bpo : : value < bool > ( ) - > implicit_value ( true )
2011-08-19 19:06:09 +00:00
- > default_value ( false ) , " verbose script output " )
2012-04-02 18:47:09 +00:00
( " script-all " , bpo : : value < bool > ( ) - > implicit_value ( true )
2011-08-19 19:06:09 +00:00
- > default_value ( false ) , " compile all scripts (excluding dialogue scripts) at startup " )
2012-07-30 09:43:28 +00:00
( " script-console " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " enable console-only script functionality " )
2012-07-30 10:37:46 +00:00
( " script-run " , bpo : : value < std : : string > ( ) - > default_value ( " " ) ,
2012-11-27 10:50:49 +00:00
" select a file containing a list of console commands that is executed on startup " )
2012-07-30 10:37:46 +00:00
2014-02-02 13:09:59 +00:00
( " script-warn " , bpo : : value < int > ( ) - > implicit_value ( 1 )
- > default_value ( 1 ) ,
" handling of warnings when compiling scripts \n "
" \t 0 - ignore warning \n "
" \t 1 - show warning but consider script as correctly compiled anyway \n "
" \t 2 - treat warnings as errors " )
2014-07-21 07:34:10 +00:00
( " script-blacklist " , bpo : : value < StringsVector > ( ) - > default_value ( StringsVector ( ) , " " )
- > multitoken ( ) , " ignore the specified script (if the use of the blacklist is enabled) " )
( " script-blacklist-use " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( true ) , " enable script blacklisting " )
2013-11-16 10:33:20 +00:00
( " skip-menu " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " skip main menu on game startup " )
2012-04-02 18:47:09 +00:00
( " fs-strict " , bpo : : value < bool > ( ) - > implicit_value ( true )
2011-08-19 19:06:09 +00:00
- > default_value ( false ) , " strict file system handling (no case folding) " )
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 20:16:50 +00:00
2012-04-02 18:47:09 +00:00
( " encoding " , bpo : : value < std : : string > ( ) - >
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 20:16:50 +00:00
default_value ( " win1252 " ) ,
2011-07-17 20:53:20 +00:00
" Character encoding used in OpenMW game messages: \n "
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 20:16:50 +00:00
" \n \t win1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages \n "
" \n \t win1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages \n "
" \n \t win1252 - Western European (Latin) alphabet, used by default " )
2011-10-08 08:31:23 +00:00
2012-04-04 17:59:46 +00:00
( " fallback " , bpo : : value < FallbackMap > ( ) - > default_value ( FallbackMap ( ) , " " )
2012-04-02 18:47:09 +00:00
- > multitoken ( ) - > composing ( ) , " fallback values " )
2013-11-29 19:06:54 +00:00
( " no-grab " , " Don't grab mouse cursor " )
2013-01-09 03:52:18 +00:00
( " activate-dist " , bpo : : value < int > ( ) - > default_value ( - 1 ) , " activation distance override " ) ;
2011-08-19 19:06:09 +00:00
bpo : : parsed_options valid_opts = bpo : : command_line_parser ( argc , argv )
. options ( desc ) . allow_unregistered ( ) . run ( ) ;
2011-01-04 00:34:55 +00:00
2011-08-19 19:06:09 +00:00
bpo : : variables_map variables ;
2010-06-11 17:53:00 +00:00
2011-08-19 19:06:09 +00:00
// Runtime options override settings from all configs
2010-07-04 21:16:57 +00:00
bpo : : store ( valid_opts , variables ) ;
bpo : : notify ( variables ) ;
2010-06-10 08:31:50 +00:00
2011-07-08 14:16:20 +00:00
bool run = true ;
2010-06-10 08:31:50 +00:00
if ( variables . count ( " help " ) )
{
2010-06-16 10:21:02 +00:00
std : : cout < < desc < < std : : endl ;
2011-07-08 14:16:20 +00:00
run = false ;
}
if ( variables . count ( " version " ) )
{
std : : cout < < " OpenMW version " < < OPENMW_VERSION < < std : : endl ;
run = false ;
2010-06-10 08:31:50 +00:00
}
2010-06-16 10:21:02 +00:00
2011-07-08 14:16:20 +00:00
if ( ! run )
2010-06-16 10:21:02 +00:00
return false ;
2011-07-08 14:16:20 +00:00
2013-12-23 22:55:40 +00:00
cfgMgr . readConfiguration ( variables , desc ) ;
2013-11-29 19:06:54 +00:00
engine . setGrabMouse ( ! variables . count ( " no-grab " ) ) ;
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 20:16:50 +00:00
// Font encoding settings
std : : string encoding ( variables [ " encoding " ] . as < std : : string > ( ) ) ;
2012-12-26 15:19:59 +00:00
std : : cout < < ToUTF8 : : encodingUsingMessage ( encoding ) < < std : : endl ;
engine . setEncoding ( ToUTF8 : : calculateEncoding ( encoding ) ) ;
2010-06-16 10:21:02 +00:00
2011-03-29 11:57:56 +00:00
// directory settings
2011-08-19 19:06:09 +00:00
engine . enableFSStrict ( variables [ " fs-strict " ] . as < bool > ( ) ) ;
2011-05-05 17:56:16 +00:00
2011-09-02 20:45:21 +00:00
Files : : PathContainer dataDirs ( variables [ " data " ] . as < Files : : PathContainer > ( ) ) ;
2011-05-05 17:50:28 +00:00
2011-08-19 19:06:09 +00:00
std : : string local ( variables [ " data-local " ] . as < std : : string > ( ) ) ;
2011-05-05 17:50:28 +00:00
if ( ! local . empty ( ) )
2011-08-19 19:06:09 +00:00
{
2012-08-16 10:59:28 +00:00
dataDirs . push_back ( Files : : PathContainer : : value_type ( local ) ) ;
2011-08-19 19:06:09 +00:00
}
2011-05-05 17:39:11 +00:00
2012-02-22 22:56:07 +00:00
cfgMgr . processPaths ( dataDirs ) ;
2011-08-19 19:06:09 +00:00
engine . setDataDirs ( dataDirs ) ;
2013-03-09 20:08:08 +00:00
// fallback archives
StringsVector archives = variables [ " fallback-archive " ] . as < StringsVector > ( ) ;
2013-07-31 16:46:32 +00:00
for ( StringsVector : : const_iterator it = archives . begin ( ) ; it ! = archives . end ( ) ; + + it )
2013-03-09 20:08:08 +00:00
{
engine . addArchive ( * it ) ;
}
2011-08-19 19:06:09 +00:00
engine . setResourceDir ( variables [ " resources " ] . as < std : : string > ( ) ) ;
2011-03-29 11:57:56 +00:00
2013-09-29 07:11:57 +00:00
StringsVector content = variables [ " content " ] . as < StringsVector > ( ) ;
if ( content . empty ( ) )
2011-03-29 11:57:56 +00:00
{
2013-09-29 07:11:57 +00:00
std : : cout < < " No content file given (esm/esp, nor omwgame/omwaddon). Aborting... " < < std : : endl ;
return false ;
2011-03-29 11:57:56 +00:00
}
2013-09-29 07:11:57 +00:00
StringsVector : : const_iterator it ( content . begin ( ) ) ;
StringsVector : : const_iterator end ( content . end ( ) ) ;
for ( ; it ! = end ; + + it )
2011-08-19 19:06:09 +00:00
{
2013-09-29 07:11:57 +00:00
engine . addContentFile ( * it ) ;
2011-08-19 19:06:09 +00:00
}
2011-03-29 11:57:56 +00:00
// startup-settings
2011-08-19 19:06:09 +00:00
engine . setCell ( variables [ " start " ] . as < std : : string > ( ) ) ;
2013-11-16 10:33:20 +00:00
engine . setSkipMenu ( variables [ " skip-menu " ] . as < bool > ( ) ) ;
2011-03-29 11:57:56 +00:00
2014-07-21 07:34:10 +00:00
// scripts
2011-08-19 19:06:09 +00:00
engine . setCompileAll ( variables [ " script-all " ] . as < bool > ( ) ) ;
2014-07-21 07:34:10 +00:00
engine . setScriptsVerbosity ( variables [ " script-verbose " ] . as < bool > ( ) ) ;
2012-07-30 09:43:28 +00:00
engine . setScriptConsoleMode ( variables [ " script-console " ] . as < bool > ( ) ) ;
2012-07-30 10:37:46 +00:00
engine . setStartupScript ( variables [ " script-run " ] . as < std : : string > ( ) ) ;
2014-02-02 13:09:59 +00:00
engine . setWarningsMode ( variables [ " script-warn " ] . as < int > ( ) ) ;
2014-07-21 07:34:10 +00:00
engine . setScriptBlacklist ( variables [ " script-blacklist " ] . as < StringsVector > ( ) ) ;
engine . setScriptBlacklistUse ( variables [ " script-blacklist-use " ] . as < bool > ( ) ) ;
// other settings
engine . setSoundUsage ( ! variables [ " no-sound " ] . as < bool > ( ) ) ;
engine . setFallbackValues ( variables [ " fallback " ] . as < FallbackMap > ( ) . mMap ) ;
engine . setActivationDistanceOverride ( variables [ " activate-dist " ] . as < int > ( ) ) ;
2010-10-06 12:52:53 +00:00
2010-06-23 00:52:17 +00:00
return true ;
2010-06-16 10:21:02 +00:00
}
2014-06-10 00:22:58 +00:00
# if defined(_WIN32) && defined(_DEBUG)
2010-09-19 00:01:01 +00:00
class DebugOutput : public boost : : iostreams : : sink
{
public :
std : : streamsize write ( const char * str , std : : streamsize size )
{
// Make a copy for null termination
std : : string tmp ( str , size ) ;
// Write string to Visual Studio Debug output
OutputDebugString ( tmp . c_str ( ) ) ;
return size ;
}
} ;
# else
2014-06-10 00:22:58 +00:00
class Tee : public boost : : iostreams : : sink
2010-09-19 00:01:01 +00:00
{
public :
2014-06-10 00:22:58 +00:00
Tee ( std : : ostream & stream , std : : ostream & stream2 )
: out ( stream ) , out2 ( stream2 )
2010-09-19 00:01:01 +00:00
{
}
std : : streamsize write ( const char * str , std : : streamsize size )
{
out . write ( str , size ) ;
out . flush ( ) ;
2014-06-10 00:22:58 +00:00
out2 . write ( str , size ) ;
out2 . flush ( ) ;
2010-09-19 00:01:01 +00:00
return size ;
}
private :
2014-06-10 00:22:58 +00:00
std : : ostream & out ;
std : : ostream & out2 ;
2010-09-19 00:01:01 +00:00
} ;
# endif
2014-06-10 00:22:58 +00:00
int main ( int argc , char * * argv )
2010-09-19 00:01:01 +00:00
{
2014-06-13 20:03:52 +00:00
// Some objects used to redirect cout and cerr
// Scope must be here, so this still works inside the catch block for logging exceptions
2014-06-10 00:22:58 +00:00
std : : streambuf * cout_rdbuf = std : : cout . rdbuf ( ) ;
std : : streambuf * cerr_rdbuf = std : : cerr . rdbuf ( ) ;
2010-09-19 00:01:01 +00:00
2014-06-22 02:15:41 +00:00
# if !(defined(_WIN32) && defined(_DEBUG))
2014-06-13 20:03:52 +00:00
boost : : iostreams : : stream_buffer < Tee > coutsb ;
boost : : iostreams : : stream_buffer < Tee > cerrsb ;
2014-06-22 02:15:41 +00:00
# endif
2014-06-13 20:03:52 +00:00
std : : ostream oldcout ( cout_rdbuf ) ;
std : : ostream oldcerr ( cerr_rdbuf ) ;
boost : : filesystem : : ofstream logfile ;
2014-07-26 20:29:04 +00:00
std : : auto_ptr < OMW : : Engine > engine ;
2010-09-19 00:01:01 +00:00
int ret = 0 ;
2014-06-10 00:22:58 +00:00
try
2010-09-19 00:01:01 +00:00
{
2014-06-10 00:22:58 +00:00
Files : : ConfigurationManager cfgMgr ;
# if defined(_WIN32) && defined(_DEBUG)
// Redirect cout and cerr to VS debug output when running in debug mode
2010-09-19 00:01:01 +00:00
boost : : iostreams : : stream_buffer < DebugOutput > sb ;
sb . open ( DebugOutput ( ) ) ;
2014-06-10 00:22:58 +00:00
std : : cout . rdbuf ( & sb ) ;
std : : cerr . rdbuf ( & sb ) ;
2010-09-19 00:01:01 +00:00
# else
2014-06-10 00:22:58 +00:00
// Redirect cout and cerr to openmw.log
2014-06-13 20:03:52 +00:00
logfile . open ( boost : : filesystem : : path ( cfgMgr . getLogPath ( ) / " /openmw.log " ) ) ;
2014-06-10 00:22:58 +00:00
coutsb . open ( Tee ( logfile , oldcout ) ) ;
cerrsb . open ( Tee ( logfile , oldcerr ) ) ;
2014-06-13 20:03:52 +00:00
std : : cout . rdbuf ( & coutsb ) ;
2014-06-10 00:22:58 +00:00
std : : cerr . rdbuf ( & cerrsb ) ;
2010-09-19 00:01:01 +00:00
# endif
2014-06-13 20:03:52 +00:00
2014-06-10 00:22:58 +00:00
# if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
// Unix crash catcher
if ( ( argc = = 2 & & strcmp ( argv [ 1 ] , " --cc-handle-crash " ) = = 0 ) | | ! is_debugger_attached ( ) )
{
int s [ 5 ] = { SIGSEGV , SIGILL , SIGFPE , SIGBUS , SIGABRT } ;
2014-06-18 23:10:33 +00:00
cc_install_handlers ( argc , argv , 5 , s , ( cfgMgr . getLogPath ( ) / " crash.log " ) . string ( ) . c_str ( ) , NULL ) ;
2014-06-10 00:22:58 +00:00
std : : cout < < " Installing crash catcher " < < std : : endl ;
}
else
std : : cout < < " Running in a debugger, not installing crash catcher " < < std : : endl ;
# endif
# if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
// set current dir to bundle path
boost : : filesystem : : path bundlePath = boost : : filesystem : : path ( Ogre : : macBundlePath ( ) ) . parent_path ( ) ;
boost : : filesystem : : current_path ( bundlePath ) ;
# endif
2014-07-26 20:29:04 +00:00
engine . reset ( new OMW : : Engine ( cfgMgr ) ) ;
2014-06-10 00:22:58 +00:00
2014-07-26 20:29:04 +00:00
if ( parseOptions ( argc , argv , * engine , cfgMgr ) )
2014-06-10 00:22:58 +00:00
{
2014-07-26 20:29:04 +00:00
engine - > go ( ) ;
2014-06-10 00:22:58 +00:00
}
}
catch ( std : : exception & e )
{
# if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
2014-06-11 06:51:18 +00:00
if ( isatty ( fileno ( stdin ) ) )
2014-06-10 00:22:58 +00:00
std : : cerr < < " \n ERROR: " < < e . what ( ) < < std : : endl ;
else
# endif
SDL_ShowSimpleMessageBox ( 0 , " OpenMW: Fatal error " , e . what ( ) , NULL ) ;
2010-09-19 00:01:01 +00:00
2014-06-10 00:22:58 +00:00
ret = 1 ;
2010-09-19 00:01:01 +00:00
}
2014-06-10 00:22:58 +00:00
// Restore cout and cerr
std : : cout . rdbuf ( cout_rdbuf ) ;
std : : cerr . rdbuf ( cerr_rdbuf ) ;
2010-09-19 00:01:01 +00:00
return ret ;
}
2014-06-10 00:22:58 +00:00
// Platform specific for Windows when there is no console built into the executable.
// Windows will call the WinMain function instead of main in this case, the normal
// main function is then called with the __argc and __argv parameters.
# if defined(_WIN32) && !defined(_CONSOLE)
int WINAPI WinMain ( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nShowCmd )
{
return main ( __argc , __argv ) ;
}
2010-09-19 00:01:01 +00:00
# endif