2011-05-19 00:04:45 +02:00
// This file is part of Glest (www.glest.org)
//
2012-10-30 07:48:12 +01:00
// Copyright (C) 2001-2008 Martiño Figueroa
2011-05-19 00:04:45 +02:00
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
2012-04-20 03:04:05 +02:00
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
2012-05-14 05:36:43 +02:00
# include <process.h>
2012-05-14 09:28:34 +02:00
# include <io.h>
2012-04-20 03:04:05 +02:00
# endif
2013-01-31 21:17:52 +01:00
# ifdef HAVE_GOOGLE_BREAKPAD
2013-02-01 03:27:01 +01:00
# include "handler/exception_handler.h"
2013-01-31 21:17:52 +01:00
# endif
2011-05-19 00:04:45 +02:00
# include "math_wrapper.h"
# include "main.h"
# include <string>
# include <cstdlib>
# include "game.h"
# include "main_menu.h"
# include "program.h"
# include "config.h"
# include "metrics.h"
# include "game_util.h"
# include "platform_util.h"
# include "platform_main.h"
# include "network_interface.h"
# include "ImageReaders.h"
# include "renderer.h"
# include "simple_threads.h"
# include <memory>
# include "font.h"
# include <curl/curl.h>
# include "menu_state_masterserver.h"
# include "checksum.h"
# include <algorithm>
# include "sound_renderer.h"
# include "font_gl.h"
# include "FileReader.h"
# include "cache_manager.h"
# include <iterator>
# include "core_data.h"
2011-06-07 04:37:58 +02:00
# include "font_text.h"
2011-12-01 03:31:00 +01:00
# include <locale.h>
2011-12-01 09:05:36 +01:00
# include "string_utils.h"
2012-03-17 09:20:17 +01:00
# include "auto_test.h"
2012-10-11 07:17:37 +02:00
# include "lua_script.h"
2011-05-19 00:04:45 +02:00
2012-04-14 23:21:09 +02:00
// To handle signal catching
2011-05-19 00:04:45 +02:00
# if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
# include <signal.h>
# endif
2013-01-31 21:17:52 +01:00
# if defined WIN32 && !defined(HAVE_GOOGLE_BREAKPAD)
2011-05-19 00:04:45 +02:00
# if defined(__WIN32__) && !defined(__GNUC__)
# include <eh.h>
# endif
# include <dbghelp.h>
# endif
# ifndef WIN32
2011-09-27 12:16:09 +02:00
# include <poll.h>
2011-05-19 00:04:45 +02:00
# define stricmp strcasecmp
# define strnicmp strncasecmp
# define _strnicmp strncasecmp
# endif
2012-04-14 23:21:09 +02:00
# include <stdlib.h>
2012-11-02 20:08:55 +01:00
2012-11-03 02:23:48 +01:00
# include "network_message.h"
# include "network_protocol.h"
2013-01-11 23:51:47 +01:00
# include "conversion.h"
2013-06-01 04:31:12 +02:00
# include "gen_uuid.h"
2012-04-14 23:21:09 +02:00
# include "leak_dumper.h"
2013-02-04 09:30:43 +01:00
//#if defined(WIN32) && !defined(HAVE_GOOGLE_BREAKPAD)
# if defined(WIN32)
2011-05-19 00:04:45 +02:00
# ifndef _DEBUG
# ifndef __GNUC__
# define WIN32_STACK_TRACE
# endif
# endif
# endif
using namespace std ;
using namespace Shared : : Platform ;
using namespace Shared : : Util ;
using namespace Shared : : Graphics ;
using namespace Shared : : Graphics : : Gl ;
2012-04-14 23:21:09 +02:00
using namespace Shared : : Xml ;
2011-10-01 01:55:07 +02:00
using namespace Shared ;
2011-05-19 00:04:45 +02:00
2012-04-14 23:21:09 +02:00
namespace Glest { namespace Game {
2011-05-19 00:04:45 +02:00
2012-04-14 23:21:09 +02:00
static string mg_app_name = " " ;
static string mailStringSupport = " " ;
static bool sdl_quitCalled = false ;
2011-05-19 00:04:45 +02:00
2012-04-17 09:12:07 +02:00
static bool disableheadless_console = false ;
static bool disableBacktrace = false ;
static bool gameInitialized = false ;
2012-04-14 23:21:09 +02:00
2012-04-17 09:12:07 +02:00
static Program * mainProgram = NULL ;
static FileCRCPreCacheThread * preCacheThread = NULL ;
2012-09-22 23:00:31 +02:00
# ifdef WIN32
static string runtimeErrorMsg = " " ;
# endif
2011-05-19 00:04:45 +02:00
2013-01-31 21:17:52 +01:00
# ifdef HAVE_GOOGLE_BREAKPAD
std : : auto_ptr < google_breakpad : : ExceptionHandler > errorHandlerPtr ;
# endif
2012-12-28 02:02:09 +01:00
class NavtiveLanguageNameListCacheGenerator : public SimpleTaskCallbackInterface {
virtual void simpleTask ( BaseThread * callingThread ) {
Lang & lang = Lang : : getInstance ( ) ;
lang . getDiscoveredLanguageList ( true ) ;
}
} ;
2013-01-11 23:51:47 +01:00
// =====================================================
// class ExceptionHandler
// =====================================================
class ExceptionHandler : public PlatformExceptionHandler {
public :
# if defined(__WIN32__) && !defined(__GNUC__)
virtual void handle ( LPEXCEPTION_POINTERS pointers ) ;
# endif
virtual void handle ( ) ;
static void logError ( const char * msg , bool confirmToConsole ) ;
static void handleRuntimeError ( const megaglest_runtime_error & ex ) ;
static void handleRuntimeError ( const char * msg , bool getStackTraceString ) ;
static int DisplayMessage ( const char * msg , bool exitApp ) ;
} ;
2011-05-19 00:04:45 +02:00
void cleanupCRCThread ( ) {
if ( preCacheThread ! = NULL ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2012-04-17 09:12:07 +02:00
const double MAX_THREAD_WAIT = 60 ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " START - shutting down crc threads \n " ) ;
2011-05-19 00:04:45 +02:00
time_t elapsed = time ( NULL ) ;
preCacheThread - > signalQuit ( ) ;
for ( ; preCacheThread - > canShutdown ( false ) = = false & &
2012-09-22 22:13:57 +02:00
difftime ( ( long int ) time ( NULL ) , elapsed ) < = MAX_THREAD_WAIT ; ) {
2011-05-19 00:04:45 +02:00
//sleep(150);
}
2012-09-22 22:13:57 +02:00
if ( difftime ( ( long int ) time ( NULL ) , elapsed ) < = MAX_THREAD_WAIT ) {
2012-04-17 09:12:07 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " B - shutting down crc threads \n " ) ;
for ( ; preCacheThread - > shutdownAndWait ( ) = = false & &
2012-09-22 22:13:57 +02:00
difftime ( ( long int ) time ( NULL ) , elapsed ) < = MAX_THREAD_WAIT ; ) {
2012-04-17 09:12:07 +02:00
}
if ( preCacheThread - > getRunningStatus ( ) = = false ) {
2011-09-27 22:35:45 +02:00
delete preCacheThread ;
2013-02-01 18:25:49 +01:00
preCacheThread = NULL ;
2012-04-17 09:12:07 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " C - shutting down crc threads \n " ) ;
2011-09-27 22:35:45 +02:00
}
2011-05-19 00:04:45 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2011-09-27 22:35:45 +02:00
else {
2012-04-17 09:12:07 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " D - shutting down crc threads \n " ) ;
if ( preCacheThread - > canShutdown ( false ) = = true ) {
2012-11-03 02:23:48 +01:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-09-27 22:35:45 +02:00
delete preCacheThread ;
2013-02-01 18:25:49 +01:00
preCacheThread = NULL ;
2011-09-27 22:35:45 +02:00
2012-04-17 09:12:07 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " E - shutting down crc threads \n " ) ;
2011-09-27 22:35:45 +02:00
//printf("Stopping broadcast thread [%p] - C\n",broadCastThread);
}
}
2012-04-17 09:12:07 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " F - shutting down crc threads \n " ) ;
2011-05-19 00:04:45 +02:00
preCacheThread = NULL ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
static void cleanupProcessObjects ( ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-09-27 07:29:57 +02:00
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-09-27 07:29:57 +02:00
showCursor ( true ) ;
restoreVideoMode ( true ) ;
}
2011-05-19 00:04:45 +02:00
2012-11-10 10:22:28 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " #1 IRCCLient Cache SHUTDOWN \n " ) ;
2012-11-15 09:16:08 +01:00
IRCThread * & ircClient = CacheManager : : getCachedItem < IRCThread * > ( GameConstants : : ircClientCacheLookupKey ) ;
2013-01-08 07:59:53 +01:00
//printf("In main IRCThreadcheck [%p]...\n",ircClient);
2012-11-10 10:22:28 +01:00
if ( ircClient ! = NULL ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " #2 IRCCLient Cache SHUTDOWN \n " ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
ircClient - > disconnect ( ) ;
2013-05-17 02:08:26 +02:00
ircClient - > signalQuit ( ) ;
2013-05-04 01:11:57 +02:00
ircClient = NULL ;
2013-05-17 02:40:54 +02:00
sleep ( 0 ) ;
2013-05-04 01:11:57 +02:00
/*
2012-11-10 10:22:28 +01:00
ircClient - > setCallbackObj ( NULL ) ;
2013-01-08 07:59:53 +01:00
//printf("In main IRCThreadcheck [%p] signalled quit...\n",ircClient);
2013-05-04 01:11:57 +02:00
printf ( " Closing IRC CLient %d \n " , __LINE__ ) ;
2012-11-10 10:22:28 +01:00
ircClient - > signalQuit ( ) ;
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ) SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) , __FUNCTION__ , __LINE__ ) ;
2013-05-04 01:11:57 +02:00
ircClient - > disconnect ( ) ;
2012-11-10 10:22:28 +01:00
ircClient = NULL ;
2013-05-04 01:11:57 +02:00
printf ( " Closing IRC CLient %d \n " , __LINE__ ) ;
2012-11-10 10:22:28 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " #3 IRCCLient Cache SHUTDOWN \n " ) ;
2013-05-04 01:11:57 +02:00
*/
2012-11-10 10:22:28 +01:00
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " #4 IRCCLient Cache SHUTDOWN \n " ) ;
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
2011-05-19 00:04:45 +02:00
cleanupCRCThread ( ) ;
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
2011-12-02 17:07:59 +01:00
if ( Renderer : : isEnded ( ) = = false ) {
Renderer : : getInstance ( ) . end ( ) ;
CoreData & coreData = CoreData : : getInstance ( ) ;
coreData . cleanup ( ) ;
}
2011-05-19 00:04:45 +02:00
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
2011-05-19 00:04:45 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
SystemFlags : : Close ( ) ;
2011-10-18 03:29:08 +02:00
SystemFlags : : SHUTDOWN_PROGRAM_MODE = true ;
2011-10-15 03:03:24 +02:00
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
2013-05-17 02:08:26 +02:00
Thread : : shutdownThreads ( ) ;
2012-11-10 07:37:23 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " start running threads = " MG_SIZE_T_SPECIFIER " \n " , Thread : : getThreadList ( ) . size ( ) ) ;
2011-10-15 03:03:24 +02:00
time_t elapsed = time ( NULL ) ;
2013-05-04 01:11:57 +02:00
int lastLazyThreadDump = 0 ;
2011-10-15 03:03:24 +02:00
for ( ; Thread : : getThreadList ( ) . size ( ) > 0 & &
2012-09-22 22:13:57 +02:00
difftime ( ( long int ) time ( NULL ) , elapsed ) < = 10 ; ) {
2011-10-15 03:03:24 +02:00
//sleep(0);
2013-05-17 02:08:26 +02:00
2013-05-04 01:11:57 +02:00
if ( difftime ( ( long int ) time ( NULL ) , elapsed ) > 1 ) {
if ( lastLazyThreadDump ! = ( int ) difftime ( ( long int ) time ( NULL ) , elapsed ) ) {
lastLazyThreadDump = difftime ( ( long int ) time ( NULL ) , elapsed ) ;
2013-05-05 08:14:22 +02:00
printf ( " Waiting for the following threads to exit [ " MG_SIZE_T_SPECIFIER " ]: \n " , Thread : : getThreadList ( ) . size ( ) ) ;
2013-05-04 01:11:57 +02:00
2013-05-05 08:14:22 +02:00
for ( int i = 0 ; i < Thread : : getThreadList ( ) . size ( ) ; + + i ) {
BaseThread * baseThread = dynamic_cast < BaseThread * > ( Thread : : getThreadList ( ) [ i ] ) ;
2013-05-17 02:08:26 +02:00
printf ( " Thread index: %d ptr [%p] isBaseThread: %d, Name: [%s] \n " , i , baseThread , ( baseThread ! = NULL ) , ( baseThread ! = NULL ? baseThread - > getUniqueID ( ) . c_str ( ) : " <na> " ) ) ;
2013-05-04 01:11:57 +02:00
}
}
}
2011-10-15 03:03:24 +02:00
}
2012-11-10 07:37:23 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " end running threads = " MG_SIZE_T_SPECIFIER " \n " , Thread : : getThreadList ( ) . size ( ) ) ;
2011-09-28 08:57:42 +02:00
2013-05-17 02:40:54 +02:00
Thread : : shutdownThreads ( ) ;
2011-09-28 08:57:42 +02:00
std : : map < int , Texture2D * > & crcPlayerTextureCache = CacheManager : : getCachedItem < std : : map < int , Texture2D * > > ( GameConstants : : playerTextureCacheLookupKey ) ;
//deleteMapValues(crcPlayerTextureCache.begin(),crcPlayerTextureCache.end());
crcPlayerTextureCache . clear ( ) ;
std : : map < string , Texture2D * > & crcFactionPreviewTextureCache = CacheManager : : getCachedItem < std : : map < string , Texture2D * > > ( GameConstants : : factionPreviewTextureCacheLookupKey ) ;
//deleteMapValues(crcFactionPreviewTextureCache.begin(),crcFactionPreviewTextureCache.end());
crcFactionPreviewTextureCache . clear ( ) ;
2011-10-01 01:55:07 +02:00
std : : map < string , vector < FileReader < Pixmap2D > const * > * > & list2d = FileReader < Pixmap2D > : : getFileReadersMap ( ) ;
2012-11-10 07:37:23 +01:00
//printf("list2d = " MG_SIZE_T_SPECIFIER "\n",list2d.size());
2011-10-01 01:55:07 +02:00
deleteMapValues ( list2d . begin ( ) , list2d . end ( ) ) ;
std : : map < string , vector < FileReader < Pixmap3D > const * > * > & list3d = FileReader < Pixmap3D > : : getFileReadersMap ( ) ;
2012-11-10 07:37:23 +01:00
//printf("list3d = " MG_SIZE_T_SPECIFIER "\n",list3d.size());
2011-10-01 01:55:07 +02:00
deleteMapValues ( list3d . begin ( ) , list3d . end ( ) ) ;
2011-05-19 00:04:45 +02:00
2011-10-15 03:03:24 +02:00
XmlIo : : getInstance ( ) . cleanup ( ) ;
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
2011-05-19 00:04:45 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-10-18 03:29:08 +02:00
2011-10-01 01:55:07 +02:00
SystemFlags : : globalCleanupHTTP ( ) ;
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
2011-10-01 01:55:07 +02:00
CacheManager : : cleanupMutexes ( ) ;
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
2011-05-19 00:04:45 +02:00
}
# if defined(WIN32) && !defined(_DEBUG) && !defined(__GNUC__)
void fatal ( const char * s , . . . ) // failure exit
{
static int errors = 0 ;
errors + + ;
if ( errors < = 5 ) { // print up to two extra recursive errors
defvformatstring ( msg , s , s ) ;
string errText = string ( msg ) + " [ " + runtimeErrorMsg + " ] " ;
//puts(msg);
string sErr = string ( mg_app_name ) + " fatal error " ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " %s \n " , errText . c_str ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , errText . c_str ( ) ) ;
if ( errors < = 1 ) { // avoid recursion
if ( SDL_WasInit ( SDL_INIT_VIDEO ) ) {
SDL_ShowCursor ( 1 ) ;
SDL_WM_GrabInput ( SDL_GRAB_OFF ) ;
2011-12-23 09:20:54 +01:00
//SDL_SetGamma(1, 1, 1);
2011-05-19 00:04:45 +02:00
}
# ifdef WIN32
LPWSTR wstr = Ansi2WideString ( errText . c_str ( ) ) ;
LPWSTR wstr1 = Ansi2WideString ( sErr . c_str ( ) ) ;
2013-02-01 06:52:00 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
MessageBox ( NULL , wstr , wstr1 , MB_OK | MB_SYSTEMMODAL ) ;
}
2011-05-19 00:04:45 +02:00
2013-02-01 18:25:49 +01:00
if ( wstr ) delete [ ] wstr ;
if ( wstr1 ) delete [ ] wstr1 ;
2011-05-19 00:04:45 +02:00
# endif
//SDL_Quit();
}
}
// Now try to shutdown threads if possible
2012-03-28 00:44:16 +02:00
delete mainProgram ;
mainProgram = NULL ;
2011-05-19 00:04:45 +02:00
// END
if ( sdl_quitCalled = = false ) {
sdl_quitCalled = true ;
SDL_Quit ( ) ;
}
exit ( EXIT_FAILURE ) ;
}
2013-01-11 23:51:47 +01:00
std : : string get_module_path ( HMODULE module = 0 ) {
char path_name [ MAX_PATH ] = { } ;
DWORD size = GetModuleFileNameA ( module , path_name , MAX_PATH ) ;
return std : : string ( path_name , size ) ;
}
2013-01-11 21:34:24 +01:00
void write_module_name ( string & out , HANDLE process , DWORD64 program_counter ) {
DWORD64 module_base = SymGetModuleBase64 ( process , program_counter ) ;
if ( module_base ) {
std : : string module_name = get_module_path ( reinterpret_cast < HMODULE > ( module_base ) ) ;
if ( ! module_name . empty ( ) )
out + = module_name + " | " ;
else
2013-01-11 23:51:47 +01:00
out + = " Unknown module| " ;
2013-01-11 21:34:24 +01:00
} else {
2013-01-11 23:51:47 +01:00
out + = " Unknown module| " ;
2013-01-11 21:34:24 +01:00
}
}
void write_function_name ( string & out , HANDLE process , DWORD64 program_counter ) {
SYMBOL_INFO_PACKAGE sym = { sizeof ( sym ) } ;
sym . si . MaxNameLen = MAX_SYM_NAME ;
if ( SymFromAddr ( process , program_counter , 0 , & sym . si ) ) {
2013-01-11 23:51:47 +01:00
out + = string ( sym . si . Name ) + " () " ;
2013-01-11 21:34:24 +01:00
} else {
2013-01-11 23:51:47 +01:00
out + = " Unknown function " ;
2013-01-11 21:34:24 +01:00
}
}
2013-01-11 23:51:47 +01:00
void write_file_and_line ( string & out , HANDLE process , DWORD64 program_counter ) {
2013-01-11 21:34:24 +01:00
IMAGEHLP_LINE64 ih_line = { sizeof ( IMAGEHLP_LINE64 ) } ;
DWORD dummy = 0 ;
if ( SymGetLineFromAddr64 ( process , program_counter , & dummy , & ih_line ) ) {
2013-01-11 23:51:47 +01:00
out + = string ( " | " ) + string ( ih_line . FileName ) + " : " + intToStr ( ih_line . LineNumber ) ;
2013-01-11 21:34:24 +01:00
}
}
void generate_stack_trace ( string & out , CONTEXT ctx , int skip ) {
STACKFRAME64 sf = { } ;
sf . AddrPC . Offset = ctx . Eip ;
sf . AddrPC . Mode = AddrModeFlat ;
sf . AddrStack . Offset = ctx . Esp ;
sf . AddrStack . Mode = AddrModeFlat ;
sf . AddrFrame . Offset = ctx . Ebp ;
sf . AddrFrame . Mode = AddrModeFlat ;
HANDLE process = GetCurrentProcess ( ) ;
HANDLE thread = GetCurrentThread ( ) ;
2013-01-11 23:51:47 +01:00
bool tryThreadContext = true ;
CONTEXT threadContext ;
memset ( & threadContext , 0 , sizeof ( CONTEXT ) ) ;
threadContext . ContextFlags = CONTEXT_FULL ;
2013-01-11 21:34:24 +01:00
for ( ; ; ) {
SetLastError ( 0 ) ;
BOOL stack_walk_ok = StackWalk64 ( IMAGE_FILE_MACHINE_I386 , process , thread , & sf ,
2013-01-11 23:51:47 +01:00
( tryThreadContext = = false ? & threadContext : & ctx ) , 0 , & SymFunctionTableAccess64 ,
2013-01-11 21:34:24 +01:00
& SymGetModuleBase64 , 0 ) ;
2013-01-11 23:51:47 +01:00
if ( ! stack_walk_ok | | ! sf . AddrFrame . Offset ) {
if ( tryThreadContext = = true ) {
tryThreadContext = false ;
if ( GetThreadContext ( thread , & threadContext ) ! = 0 ) {
sf . AddrPC . Offset = threadContext . Eip ;
sf . AddrPC . Mode = AddrModeFlat ;
sf . AddrStack . Offset = threadContext . Esp ;
sf . AddrStack . Mode = AddrModeFlat ;
sf . AddrFrame . Offset = threadContext . Ebp ;
sf . AddrFrame . Mode = AddrModeFlat ;
}
else {
return ;
}
}
else {
return ;
}
}
2013-01-11 21:34:24 +01:00
if ( skip ) {
2013-01-11 23:51:47 +01:00
- - skip ;
}
else {
2013-01-11 21:34:24 +01:00
// write the address
2013-01-11 23:51:47 +01:00
//out += reinterpret_cast<void *>(sf.AddrPC.Offset) + "|";
out + = intToStr ( sf . AddrPC . Offset ) + " | " ;
2013-01-11 21:34:24 +01:00
2013-01-11 23:51:47 +01:00
write_module_name ( out , process , sf . AddrPC . Offset ) ;
write_function_name ( out , process , sf . AddrPC . Offset ) ;
write_file_and_line ( out , process , sf . AddrPC . Offset ) ;
2013-01-11 21:34:24 +01:00
2013-01-11 23:51:47 +01:00
out + = " \n " ;
2013-01-11 21:34:24 +01:00
}
}
}
2013-01-11 23:51:47 +01:00
struct UntypedException {
UntypedException ( const EXCEPTION_RECORD & er )
: exception_object ( reinterpret_cast < void * > ( er . ExceptionInformation [ 1 ] ) ) ,
type_array ( reinterpret_cast < _ThrowInfo * > ( er . ExceptionInformation [ 2 ] ) - > pCatchableTypeArray )
{ }
void * exception_object ;
_CatchableTypeArray * type_array ;
} ;
void * exception_cast_worker ( const UntypedException & e , const type_info & ti ) {
for ( int i = 0 ; i < e . type_array - > nCatchableTypes ; + + i ) {
_CatchableType & type_i = * e . type_array - > arrayOfCatchableTypes [ i ] ;
const std : : type_info & ti_i = * reinterpret_cast < std : : type_info * > ( type_i . pType ) ;
if ( ti_i = = ti ) {
char * base_address = reinterpret_cast < char * > ( e . exception_object ) ;
base_address + = type_i . thisDisplacement . mdisp ;
return base_address ;
}
}
return 0 ;
}
template < typename T >
T * exception_cast ( const UntypedException & e ) {
const std : : type_info & ti = typeid ( T ) ;
return reinterpret_cast < T * > ( exception_cast_worker ( e , ti ) ) ;
}
void stackdumper ( unsigned int type , EXCEPTION_POINTERS * ep , bool fatalExit ) {
2013-02-04 09:30:43 +01:00
# ifdef HAVE_GOOGLE_BREAKPAD
if ( errorHandlerPtr . get ( ) ! = NULL ) {
errorHandlerPtr - > WriteMinidump ( ) ;
}
# endif
if ( ! ep ) {
2013-01-11 23:51:47 +01:00
fatal ( " unknown type " ) ;
2013-02-04 09:30:43 +01:00
return ;
2013-01-11 23:51:47 +01:00
}
2011-05-19 00:04:45 +02:00
EXCEPTION_RECORD * er = ep - > ExceptionRecord ;
CONTEXT * context = ep - > ContextRecord ;
2013-01-11 21:34:24 +01:00
string out = " " ;
int skip = 0 ;
2013-01-11 23:51:47 +01:00
2013-01-11 21:34:24 +01:00
switch ( er - > ExceptionCode ) {
case 0xE06D7363 : { // C++ exception
2013-01-11 23:51:47 +01:00
UntypedException ue ( * er ) ;
2013-01-11 21:34:24 +01:00
if ( std : : exception * e = exception_cast < std : : exception > ( ue ) ) {
2013-01-11 23:51:47 +01:00
const std : : type_info & ti = typeid ( * e ) ;
out + = string ( ti . name ( ) ) + " : " + string ( e - > what ( ) ) ;
}
else {
out + = " Unknown C++ exception thrown. " ;
2013-01-11 21:34:24 +01:00
}
skip = 2 ; // skip RaiseException and _CxxThrowException
} break ;
case EXCEPTION_ACCESS_VIOLATION : {
2013-01-11 23:51:47 +01:00
out + = string ( " Access violation. Illegal " )
+ ( er - > ExceptionInformation [ 0 ] ? " write " : " read " )
+ string ( " by " )
+ intToStr ( ( int ) er - > ExceptionAddress )
+ string ( " at " )
//+ reinterpret_cast<void *>(er->ExceptionInformation[1]);
+ intToStr ( er - > ExceptionInformation [ 1 ] ) ;
2013-01-11 21:34:24 +01:00
} break ;
default : {
out + = " SEH exception thrown. Exception code: "
2013-01-11 23:51:47 +01:00
+ er - > ExceptionCode
+ string ( " at " )
+ intToStr ( ( int ) er - > ExceptionAddress ) ;
2013-01-11 21:34:24 +01:00
}
2011-05-19 00:04:45 +02:00
}
2013-01-11 21:34:24 +01:00
2013-01-11 23:51:47 +01:00
generate_stack_trace ( out , * context , skip ) ;
if ( fatalExit = = true ) {
fatal ( out . c_str ( ) ) ;
}
else {
ExceptionHandler : : logError ( out . c_str ( ) , true ) ;
}
2011-05-19 00:04:45 +02:00
}
# endif
// =====================================================
// class ExceptionHandler
// =====================================================
2013-01-31 21:17:52 +01:00
# if defined(WIN32) && !defined(__GNUC__)
2013-01-11 23:51:47 +01:00
void ExceptionHandler : : handle ( LPEXCEPTION_POINTERS pointers ) {
string msg = " #1 An error occurred and " + string ( mg_app_name ) + " will close. \n Please report this bug to: " + string ( mailString ) ;
msg + = " , attaching the generated " + getCrashDumpFileName ( ) + " file. " ;
2011-05-19 00:04:45 +02:00
2013-01-11 23:51:47 +01:00
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " %s \n " , msg . c_str ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , msg . c_str ( ) ) ;
stackdumper ( 0 , pointers , false ) ;
if ( mainProgram & & gameInitialized = = true ) {
mainProgram - > showMessage ( msg . c_str ( ) ) ;
}
message ( msg . c_str ( ) ) ;
}
# endif
void ExceptionHandler : : handle ( ) {
2011-10-18 03:40:49 +02:00
string msg = " #1 An error occurred and " + string ( mg_app_name ) + " will close. \n Please report this bug to: " + string ( mailString ) ;
2011-05-19 00:04:45 +02:00
# ifdef WIN32
msg + = " , attaching the generated " + getCrashDumpFileName ( ) + " file. " ;
# endif
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " %s \n " , msg . c_str ( ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , msg . c_str ( ) ) ;
2012-03-28 00:44:16 +02:00
if ( mainProgram & & gameInitialized = = true ) {
mainProgram - > showMessage ( msg . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
}
message ( msg . c_str ( ) ) ;
}
2013-01-11 23:51:47 +01:00
void ExceptionHandler : : logError ( const char * msg , bool confirmToConsole ) {
2011-10-03 20:34:59 +02:00
string errorLogFile = " error.log " ;
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
errorLogFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + errorLogFile ;
}
else {
string userData = Config : : getInstance ( ) . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
errorLogFile = userData + errorLogFile ;
}
2011-10-18 04:02:37 +02:00
2011-10-18 04:11:55 +02:00
//printf("Attempting to write error to file [%s]\n",errorLogFile.c_str());
2011-10-18 04:02:37 +02:00
2011-10-03 20:34:59 +02:00
# if defined(WIN32) && !defined(__MINGW32__)
FILE * fp = _wfopen ( utf8_decode ( errorLogFile ) . c_str ( ) , L " w " ) ;
std : : ofstream logFile ( fp ) ;
# else
std : : ofstream logFile ;
logFile . open ( errorLogFile . c_str ( ) , ios_base : : out | ios_base : : trunc ) ;
# endif
if ( logFile . is_open ( ) = = true ) {
time_t curtime = time ( NULL ) ;
struct tm * loctime = localtime ( & curtime ) ;
char szBuf2 [ 100 ] = " " ;
strftime ( szBuf2 , 100 , " %Y-%m-%d %H:%M:%S " , loctime ) ;
logFile < < " [ " < < szBuf2 < < " ] Runtime Error information: " < < std : : endl ;
logFile < < " ====================================================== " < < std : : endl ;
logFile < < ( msg ! = NULL ? msg : " null " ) < < std : : endl ;
logFile . close ( ) ;
# if defined(WIN32) && !defined(__MINGW32__)
if ( fp ) {
fclose ( fp ) ;
}
# endif
2011-10-03 20:39:21 +02:00
if ( confirmToConsole = = true ) {
printf ( " Error saved to logfile [%s] \n " , errorLogFile . c_str ( ) ) ;
fflush ( stdout ) ;
}
2011-10-03 20:34:59 +02:00
}
2011-10-18 04:11:55 +02:00
else {
if ( confirmToConsole = = true ) {
printf ( " COULD NOT SAVE TO ERROR logfile [%s] \n " , errorLogFile . c_str ( ) ) ;
fflush ( stdout ) ;
}
}
2011-10-03 20:39:21 +02:00
}
2013-01-11 23:51:47 +01:00
void ExceptionHandler : : handleRuntimeError ( const megaglest_runtime_error & ex ) {
2012-04-14 23:21:09 +02:00
const char * msg = ex . what ( ) ;
handleRuntimeError ( msg , false ) ;
}
2013-01-11 23:51:47 +01:00
void ExceptionHandler : : handleRuntimeError ( const char * msg , bool getStackTraceString ) {
2011-10-03 20:39:21 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-10-05 23:46:41 +02:00
static bool inErrorNow = false ;
if ( inErrorNow = = true ) {
2013-05-28 17:42:54 +02:00
printf ( " \n ===================================== \n " ) ;
printf ( " \n ** Already in error handler aborting, msg [%s] \n " , msg ) ;
2011-10-05 23:46:41 +02:00
fflush ( stdout ) ;
abort ( ) ;
return ;
}
inErrorNow = true ;
2011-10-03 20:39:21 +02:00
logError ( msg , true ) ;
2011-10-03 20:34:59 +02:00
2012-03-28 00:44:16 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] program = %p gameInitialized = %d msg [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , mainProgram , gameInitialized , msg ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] [%s] gameInitialized = %d, program = %p \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , gameInitialized , mainProgram ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] [%s] gameInitialized = %d, program = %p \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , gameInitialized , mainProgram ) ;
2011-05-19 00:04:45 +02:00
string errMsg = ( msg ! = NULL ? msg : " null " ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2012-04-14 23:21:09 +02:00
bool gotStackTrace = false ;
if ( getStackTraceString = = true & & disableBacktrace = = false & & sdl_quitCalled = = false ) {
string stackTrace = getStackTrace ( ) ;
errMsg + = stackTrace ;
gotStackTrace = true ;
2011-05-19 00:04:45 +02:00
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-10-03 20:39:21 +02:00
logError ( errMsg . c_str ( ) , false ) ;
2012-04-14 23:21:09 +02:00
if ( gotStackTrace = = true ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugError , " In [%s::%s Line: %d] [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , errMsg . c_str ( ) ) ;
}
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] [%s] \n " , __FILE__ , __FUNCTION__ , __LINE__ , errMsg . c_str ( ) ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//abort();
2012-03-28 00:44:16 +02:00
if ( mainProgram & & gameInitialized = = true ) {
2011-05-19 00:04:45 +02:00
//printf("\nprogram->getState() [%p]\n",program->getState());
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2012-03-28 00:44:16 +02:00
if ( mainProgram - > getState ( ) ! = NULL ) {
2011-05-19 00:04:45 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2012-03-28 00:44:16 +02:00
mainProgram - > showMessage ( errMsg . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-10-05 23:46:41 +02:00
2012-08-10 08:19:35 +02:00
if ( glActiveTexture ! = NULL ) {
for ( ; GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false & & mainProgram - > isMessageShowing ( ) ; ) {
//program->getState()->render();
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2013-05-28 17:42:54 +02:00
try {
mainProgram - > loop ( ) ;
}
catch ( const exception & e ) {
printf ( " \n ===================================== \n " ) ;
printf ( " \n ** Already in error handler exiting errror rendering, msg [%s] \n " , e . what ( ) ) ;
fflush ( stdout ) ;
//abort();
break ;
}
2012-08-10 08:19:35 +02:00
}
}
2011-05-19 00:04:45 +02:00
}
else {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2012-03-28 00:44:16 +02:00
mainProgram - > showMessage ( errMsg . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-10-05 23:46:41 +02:00
2012-08-10 08:19:35 +02:00
if ( glActiveTexture ! = NULL ) {
for ( ; GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false & & mainProgram - > isMessageShowing ( ) ; ) {
//program->renderProgramMsgBox();
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2013-05-28 17:42:54 +02:00
try {
mainProgram - > loop ( ) ;
}
catch ( const exception & e ) {
printf ( " \n ===================================== \n " ) ;
printf ( " \n ** Already in error handler exiting errror rendering, msg [%s] \n " , e . what ( ) ) ;
fflush ( stdout ) ;
//abort();
break ;
}
2012-08-10 08:19:35 +02:00
}
}
2011-05-19 00:04:45 +02:00
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
else {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
string err = " #2 An error occurred and " ;
if ( sdl_quitCalled = = false ) {
err + = mg_app_name ;
}
err + = " will close. \n Error msg = [ " + errMsg + " ] \n \n Please report this bug to " ;
if ( sdl_quitCalled = = false ) {
err + = mailStringSupport ;
}
# ifdef WIN32
err + = string ( " , attaching the generated " ) + getCrashDumpFileName ( ) + string ( " file. " ) ;
# endif
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
message ( err ) ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
// Now try to shutdown threads if possible
2012-03-28 00:44:16 +02:00
delete mainProgram ;
mainProgram = NULL ;
2011-05-19 00:04:45 +02:00
// END
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
# ifdef WIN32
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-09-27 07:29:57 +02:00
showCursor ( true ) ;
restoreVideoMode ( true ) ;
}
2011-05-19 00:04:45 +02:00
runtimeErrorMsg = errMsg ;
2011-10-05 23:46:41 +02:00
inErrorNow = false ;
2011-05-19 00:04:45 +02:00
throw runtimeErrorMsg ;
# endif
//printf("In [%s::%s Line: %d] [%s] gameInitialized = %d\n",__FILE__,__FUNCTION__,__LINE__,msg,gameInitialized);
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
cleanupProcessObjects ( ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( sdl_quitCalled = = false ) {
sdl_quitCalled = true ;
SDL_Quit ( ) ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-10-05 23:46:41 +02:00
inErrorNow = false ;
2011-05-19 00:04:45 +02:00
abort ( ) ;
}
2013-01-11 23:51:47 +01:00
int ExceptionHandler : : DisplayMessage ( const char * msg , bool exitApp ) {
2011-12-05 06:26:48 +01:00
//printf("In [%s::%s Line: %d] msg [%s] exitApp = %d\n",__FILE__,__FUNCTION__,__LINE__,msg,exitApp);
2011-05-19 00:04:45 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] msg [%s] exitApp = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , exitApp ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] msg [%s] exitApp = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , exitApp ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] msg [%s] exitApp = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , exitApp ) ;
2012-03-28 00:44:16 +02:00
if ( mainProgram & & gameInitialized = = true ) {
2011-05-19 00:04:45 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] msg [%s] exitApp = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , exitApp ) ;
2012-03-28 00:44:16 +02:00
mainProgram - > showMessage ( msg ) ;
2011-05-19 00:04:45 +02:00
}
else {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] msg [%s] exitApp = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , exitApp ) ;
message ( msg ) ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] msg [%s] exitApp = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , exitApp ) ;
if ( exitApp = = true ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s \n " , msg ) ;
// Now try to shutdown threads if possible
2012-03-28 00:44:16 +02:00
delete mainProgram ;
mainProgram = NULL ;
2011-05-19 00:04:45 +02:00
// END
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] msg [%s] exitApp = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , exitApp ) ;
cleanupProcessObjects ( ) ;
if ( sdl_quitCalled = = false ) {
sdl_quitCalled = true ;
SDL_Quit ( ) ;
}
exit ( - 1 ) ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] msg [%s] exitApp = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , msg , exitApp ) ;
return 0 ;
}
// =====================================================
// class MainWindow
// =====================================================
2011-09-27 12:16:09 +02:00
MainWindow : : MainWindow ( Program * program ) : WindowGl ( ) {
2011-05-19 00:04:45 +02:00
this - > program = program ;
2011-10-25 20:39:11 +02:00
this - > popupMenu . setEnabled ( false ) ;
this - > popupMenu . setVisible ( false ) ;
2011-10-26 00:40:28 +02:00
this - > triggerLanguageToggle = false ;
this - > triggerLanguage = " " ;
2011-12-02 17:07:59 +01:00
this - > cancelLanguageSelection = - 1 ;
2011-05-19 00:04:45 +02:00
}
2011-10-26 00:40:28 +02:00
2011-05-19 00:04:45 +02:00
MainWindow : : ~ MainWindow ( ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
delete program ;
program = NULL ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
void MainWindow : : eventMouseDown ( int x , int y , MouseButton mouseButton ) {
const Metrics & metrics = Metrics : : getInstance ( ) ;
int vx = metrics . toVirtualX ( x ) ;
int vy = metrics . toVirtualY ( getH ( ) - y ) ;
if ( program = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " In [MainWindow::eventMouseDown] ERROR, program == NULL! " ) ;
2011-05-19 00:04:45 +02:00
}
2011-10-25 20:39:11 +02:00
//printf("eventMouseDown popupMenu.getVisible() = %d\n",popupMenu.getVisible());
if ( popupMenu . getVisible ( ) = = true & & popupMenu . mouseClick ( vx , vy ) ) {
std : : pair < int , string > result = popupMenu . mouseClickedMenuItem ( vx , vy ) ;
//printf("In popup callback menuItemSelected [%s] menuIndexSelected = %d\n",result.second.c_str(),result.first);
popupMenu . setEnabled ( false ) ;
popupMenu . setVisible ( false ) ;
//printf("result.first = %d [%s] cancelLanguageSelection = %d\n",result.first,result.second.c_str(),cancelLanguageSelection);
// Exit game
if ( result . first ! = cancelLanguageSelection ) {
2011-10-26 00:40:28 +02:00
//toggleLanguage(result.second);
this - > triggerLanguageToggle = true ;
this - > triggerLanguage = result . second ;
2011-10-25 20:39:11 +02:00
}
return ;
}
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
switch ( mouseButton ) {
case mbLeft :
program - > mouseDownLeft ( vx , vy ) ;
break ;
case mbRight :
//program->mouseDownRight(vx, vy);
break ;
case mbCenter :
//program->mouseDownCenter(vx, vy);
break ;
default :
break ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
ProgramState * programState = program - > getState ( ) ;
if ( programState ! = NULL ) {
switch ( mouseButton ) {
case mbLeft :
programState - > mouseDownLeft ( vx , vy ) ;
break ;
case mbRight :
programState - > mouseDownRight ( vx , vy ) ;
break ;
case mbCenter :
programState - > mouseDownCenter ( vx , vy ) ;
break ;
default :
break ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
void MainWindow : : eventMouseUp ( int x , int y , MouseButton mouseButton ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
int vx = metrics . toVirtualX ( x ) ;
int vy = metrics . toVirtualY ( getH ( ) - y ) ;
if ( program = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " In [MainWindow::eventMouseUp] ERROR, program == NULL! " ) ;
2011-05-19 00:04:45 +02:00
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
ProgramState * programState = program - > getState ( ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( programState ! = NULL ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
switch ( mouseButton ) {
case mbLeft :
programState - > mouseUpLeft ( vx , vy ) ;
break ;
case mbRight :
programState - > mouseUpRight ( vx , vy ) ;
break ;
case mbCenter :
programState - > mouseUpCenter ( vx , vy ) ;
break ;
default :
break ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
void MainWindow : : eventMouseDoubleClick ( int x , int y , MouseButton mouseButton ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
int vx = metrics . toVirtualX ( x ) ;
int vy = metrics . toVirtualY ( getH ( ) - y ) ;
if ( program = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " In [MainWindow::eventMouseDoubleClick] ERROR, program == NULL! " ) ;
2011-05-19 00:04:45 +02:00
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
ProgramState * programState = program - > getState ( ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( programState ! = NULL ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
switch ( mouseButton ) {
case mbLeft :
programState - > mouseDoubleClickLeft ( vx , vy ) ;
break ;
case mbRight :
programState - > mouseDoubleClickRight ( vx , vy ) ;
break ;
case mbCenter :
programState - > mouseDoubleClickCenter ( vx , vy ) ;
break ;
default :
break ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
void MainWindow : : eventMouseMove ( int x , int y , const MouseState * ms ) {
const Metrics & metrics = Metrics : : getInstance ( ) ;
int vx = metrics . toVirtualX ( x ) ;
int vy = metrics . toVirtualY ( getH ( ) - y ) ;
if ( program = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " In [MainWindow::eventMouseMove] ERROR, program == NULL! " ) ;
2011-05-19 00:04:45 +02:00
}
program - > eventMouseMove ( vx , vy , ms ) ;
ProgramState * programState = program - > getState ( ) ;
if ( programState ! = NULL ) {
programState - > mouseMove ( vx , vy , ms ) ;
}
}
void MainWindow : : eventMouseWheel ( int x , int y , int zDelta ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
int vx = metrics . toVirtualX ( x ) ;
int vy = metrics . toVirtualY ( getH ( ) - y ) ;
if ( program = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " In [MainWindow::eventMouseMove] ERROR, program == NULL! " ) ;
2011-05-19 00:04:45 +02:00
}
ProgramState * programState = program - > getState ( ) ;
if ( programState ! = NULL ) {
programState - > eventMouseWheel ( vx , vy , zDelta ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2011-10-25 20:39:11 +02:00
void MainWindow : : render ( ) {
if ( popupMenu . getVisible ( ) = = true ) {
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . renderPopupMenu ( & popupMenu ) ;
//printf("Render lang popup\n");
}
}
void MainWindow : : showLanguages ( ) {
Lang & lang = Lang : : getInstance ( ) ;
//PopupMenu popupMenu;
std : : vector < string > menuItems ;
vector < string > langResults ;
string data_path = getGameReadWritePath ( GameConstants : : path_data_CacheLookupKey ) ;
2011-11-02 18:17:28 +01:00
string userDataPath = getGameCustomCoreDataPath ( data_path , " " ) ;
findAll ( userDataPath + " data/lang/*.lng " , langResults , true , false ) ;
2011-10-25 20:39:11 +02:00
for ( unsigned int i = 0 ; i < langResults . size ( ) ; + + i ) {
string testLanguage = langResults [ i ] ;
menuItems . push_back ( testLanguage ) ;
}
2011-11-02 18:17:28 +01:00
vector < string > langResults2 ;
findAll ( data_path + " data/lang/*.lng " , langResults2 , true ) ;
if ( langResults2 . empty ( ) & & langResults . empty ( ) ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " There are no lang files " ) ;
2011-11-02 18:17:28 +01:00
}
for ( unsigned int i = 0 ; i < langResults2 . size ( ) ; + + i ) {
string testLanguage = langResults2 [ i ] ;
if ( std : : find ( menuItems . begin ( ) , menuItems . end ( ) , testLanguage ) = = menuItems . end ( ) ) {
menuItems . push_back ( testLanguage ) ;
}
}
2011-12-01 00:35:54 +01:00
menuItems . push_back ( lang . get ( " Exit " ) ) ;
2011-10-25 20:39:11 +02:00
cancelLanguageSelection = menuItems . size ( ) - 1 ;
popupMenu . setW ( 100 ) ;
popupMenu . setH ( 100 ) ;
popupMenu . init ( lang . get ( " GameMenuTitle " ) , menuItems ) ;
popupMenu . setEnabled ( true ) ;
popupMenu . setVisible ( true ) ;
}
void MainWindow : : toggleLanguage ( string language ) {
popupMenu . setEnabled ( false ) ;
popupMenu . setVisible ( false ) ;
2011-10-26 00:40:28 +02:00
this - > triggerLanguageToggle = false ;
this - > triggerLanguage = " " ;
2011-10-25 20:39:11 +02:00
Lang & lang = Lang : : getInstance ( ) ;
string currentLanguage = lang . getLanguage ( ) ;
string newLanguageSelected = language ;
if ( language = = " " ) {
newLanguageSelected = currentLanguage ;
vector < string > langResults ;
string data_path = getGameReadWritePath ( GameConstants : : path_data_CacheLookupKey ) ;
2011-11-02 18:17:28 +01:00
string userDataPath = getGameCustomCoreDataPath ( data_path , " " ) ;
findAll ( userDataPath + " data/lang/*.lng " , langResults , true , false ) ;
vector < string > langResults2 ;
findAll ( data_path + " data/lang/*.lng " , langResults2 , true ) ;
if ( langResults2 . empty ( ) & & langResults . empty ( ) ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " There are no lang files " ) ;
2011-11-02 18:17:28 +01:00
}
for ( unsigned int i = 0 ; i < langResults2 . size ( ) ; + + i ) {
string testLanguage = langResults2 [ i ] ;
if ( std : : find ( langResults . begin ( ) , langResults . end ( ) , testLanguage ) = = langResults . end ( ) ) {
langResults . push_back ( testLanguage ) ;
}
2011-10-25 20:39:11 +02:00
}
for ( unsigned int i = 0 ; i < langResults . size ( ) ; + + i ) {
string testLanguage = langResults [ i ] ;
if ( testLanguage = = currentLanguage ) {
if ( i + 1 < langResults . size ( ) ) {
newLanguageSelected = langResults [ i + 1 ] ;
}
else {
newLanguageSelected = langResults [ 0 ] ;
}
break ;
}
}
}
if ( newLanguageSelected ! = currentLanguage ) {
lang . loadStrings ( newLanguageSelected ) ;
program - > reloadUI ( ) ;
program - > consoleAddLine ( lang . get ( " Language " ) + " " + newLanguageSelected ) ;
}
}
2011-06-26 03:55:08 +02:00
void MainWindow : : eventKeyDown ( SDL_KeyboardEvent key ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] [%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , key . keysym . sym ) ;
2011-05-19 00:04:45 +02:00
2011-06-28 03:25:14 +02:00
//SDL_keysym keystate = Window::getKeystate();
SDL_keysym keystate = key . keysym ;
2011-12-03 05:58:36 +01:00
//printf("keystate.mod = %d key = %d lalt [%d] ralt [%d] alt [%d]\n",keystate.mod,key.keysym.unicode,(keystate.mod & KMOD_LALT),(keystate.mod & KMOD_RALT),(keystate.mod & KMOD_ALT));
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] key = [%c][%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , key , key ) ;
if ( program = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " In [MainWindow::eventKeyDown] ERROR, program == NULL! " ) ;
2011-05-19 00:04:45 +02:00
}
2011-10-25 20:39:11 +02:00
if ( popupMenu . getVisible ( ) = = true & & isKeyPressed ( SDLK_ESCAPE , key ) = = true ) {
this - > popupMenu . setEnabled ( false ) ;
this - > popupMenu . setVisible ( false ) ;
return ;
}
2011-05-19 00:04:45 +02:00
//{
//Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
//printf("----------------------- key [%d] CameraModeLeft [%d]\n",key,configKeys.getCharKey("CameraModeLeft"));
//}
program - > keyDown ( key ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( keystate . mod & ( KMOD_LALT | KMOD_RALT ) ) {
2011-06-26 03:55:08 +02:00
//if(key == vkReturn) {
if ( isKeyPressed ( SDLK_RETURN , key ) = = true ) {
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] ALT-ENTER pressed \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
// This stupidity only required in win32.
// We reload the textures so that the canvas paints textures properly
# ifdef WIN32
if ( Window : : getAllowAltEnterFullscreenToggle ( ) = = true ) {
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . reinitAll ( ) ;
}
# endif
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
}
if ( program ! = NULL & & program - > isInSpecialKeyCaptureEvent ( ) = = false ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2012-11-21 19:54:50 +01:00
vector < int > modifiersToCheck ;
modifiersToCheck . push_back ( KMOD_LCTRL ) ;
modifiersToCheck . push_back ( KMOD_RCTRL ) ;
modifiersToCheck . push_back ( KMOD_LALT ) ;
modifiersToCheck . push_back ( KMOD_RALT ) ;
modifiersToCheck . push_back ( KMOD_LSHIFT ) ;
modifiersToCheck . push_back ( KMOD_RSHIFT ) ;
2011-05-19 00:04:45 +02:00
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2011-06-26 03:55:08 +02:00
//if(key == configKeys.getCharKey("HotKeyShowDebug")) {
if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeyShowDebug " ) , key ) = = true ) {
2011-11-15 05:48:57 +01:00
//printf("debug key pressed keystate.mod = %d [%d]\n",keystate.mod,keystate.mod & (KMOD_LALT | KMOD_RALT));
2011-05-19 00:04:45 +02:00
Renderer & renderer = Renderer : : getInstance ( ) ;
//if(keystate.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
if ( keystate . mod & ( KMOD_LALT | KMOD_RALT ) ) {
renderer . cycleShowDebugUILevel ( ) ;
}
else {
bool showDebugUI = renderer . getShowDebugUI ( ) ;
renderer . setShowDebugUI ( ! showDebugUI ) ;
}
}
2012-09-22 22:13:57 +02:00
else if ( ( keystate . mod & ( KMOD_LCTRL | KMOD_RCTRL ) ) & &
2011-10-25 20:39:11 +02:00
isKeyPressed ( configKeys . getSDLKey ( " SwitchLanguage " ) , key ) = = true ) {
2012-09-22 22:13:57 +02:00
if ( ( keystate . mod & ( KMOD_LSHIFT | KMOD_RSHIFT ) ) ) {
2011-10-26 00:40:28 +02:00
//toggleLanguage("");
this - > triggerLanguageToggle = true ;
this - > triggerLanguage = " " ;
2011-10-25 20:39:11 +02:00
}
else {
showLanguages ( ) ;
}
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("ReloadINI")) {
2012-11-21 19:54:50 +01:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " ReloadINI " ) , key , modifiersToCheck ) = = true ) {
2011-05-19 00:04:45 +02:00
Config & config = Config : : getInstance ( ) ;
config . reload ( ) ;
}
2011-06-26 03:55:08 +02:00
//else if(key == configKeys.getCharKey("Screenshot")) {
2012-11-21 19:54:50 +01:00
else if ( isKeyPressed ( configKeys . getSDLKey ( " Screenshot " ) , key , modifiersToCheck ) = = true ) {
2012-11-20 02:12:07 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Screenshot key pressed \n " ) ;
2011-05-19 00:04:45 +02:00
string userData = Config : : getInstance ( ) . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
string path = userData + GameConstants : : folder_path_screenshots ;
2012-11-20 02:12:07 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Screenshot checking path [%s] \n " , path . c_str ( ) ) ;
if ( isdir ( path . c_str ( ) ) = = false ) {
createDirectoryPaths ( path ) ;
}
2011-05-19 00:04:45 +02:00
if ( isdir ( path . c_str ( ) ) = = true ) {
2012-11-20 02:12:07 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Screenshot path [%s] \n " , path . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
Config & config = Config : : getInstance ( ) ;
string fileFormat = config . getString ( " ScreenShotFileType " , " jpg " ) ;
unsigned int queueSize = Renderer : : getInstance ( ) . getSaveScreenQueueSize ( ) ;
for ( int i = 0 ; i < 5000 ; + + i ) {
path = userData + GameConstants : : folder_path_screenshots ;
path + = string ( " screen " ) + intToStr ( i + queueSize ) + string ( " . " ) + fileFormat ;
# ifdef WIN32
FILE * f = _wfopen ( utf8_decode ( path ) . c_str ( ) , L " rb " ) ;
# else
FILE * f = fopen ( path . c_str ( ) , " rb " ) ;
# endif
if ( f = = NULL ) {
Lang & lang = Lang : : getInstance ( ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2011-05-19 00:04:45 +02:00
if ( lang . get ( " ScreenshotSavedTo " ) . length ( ) > 0 & & lang . get ( " ScreenshotSavedTo " ) [ 0 ] ! = ' ? ' ) {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , lang . get ( " ScreenshotSavedTo " ) . c_str ( ) , path . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Screenshot will be saved to: %s " , path . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , szBuf ) ;
2012-11-20 02:12:07 +01:00
bool showScreenshotSavedMsg = Config : : getInstance ( ) . getBool ( " DisableScreenshotConsoleText " , " false " ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Screenshot console showScreenshotSavedMsg = %d \n " , showScreenshotSavedMsg ) ;
if ( showScreenshotSavedMsg = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Screenshot console [%s] \n " , szBuf ) ;
2011-05-19 00:04:45 +02:00
program - > consoleAddLine ( szBuf ) ;
}
2012-11-20 02:12:07 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Screenshot save to [%s] \n " , path . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
Renderer : : getInstance ( ) . saveScreen ( path ) ;
break ;
}
else {
2012-11-20 02:12:07 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " CANNOT save Screenshot [%s] \n " , path . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
fclose ( f ) ;
}
}
}
}
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2011-06-26 03:55:08 +02:00
void MainWindow : : eventKeyUp ( SDL_KeyboardEvent key ) {
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] [%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , key ) ;
if ( program = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " In [MainWindow::eventKeyUp] ERROR, program == NULL! " ) ;
2011-05-19 00:04:45 +02:00
}
program - > keyUp ( key ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] [%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , key ) ;
}
2011-06-26 03:55:08 +02:00
void MainWindow : : eventKeyPress ( SDL_KeyboardEvent c ) {
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] [%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , c ) ;
if ( program = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " In [MainWindow::eventKeyPress] ERROR, program == NULL! " ) ;
2011-05-19 00:04:45 +02:00
}
program - > keyPress ( c ) ;
if ( program ! = NULL & & program - > isInSpecialKeyCaptureEvent ( ) = = false ) {
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
Config & configKeys = Config : : getInstance ( std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ) ;
2011-06-26 03:55:08 +02:00
//if(c == configKeys.getCharKey("HotKeyToggleOSMouseEnabled")) {
if ( isKeyPressed ( configKeys . getSDLKey ( " HotKeyToggleOSMouseEnabled " ) , c ) = = true ) {
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
bool showCursorState = false ;
int state = SDL_ShowCursor ( SDL_QUERY ) ;
if ( state = = SDL_DISABLE ) {
showCursorState = true ;
}
showCursor ( showCursorState ) ;
Renderer & renderer = Renderer : : getInstance ( ) ;
renderer . setNo2DMouseRendering ( showCursorState ) ;
Window : : lastShowMouseState = SDL_ShowCursor ( SDL_QUERY ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Window::lastShowMouseState = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , Window : : lastShowMouseState ) ;
}
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] [%d] \n " , __FILE__ , __FUNCTION__ , __LINE__ , c ) ;
}
2011-06-26 03:55:08 +02:00
void MainWindow : : eventActivate ( bool active ) {
2011-05-19 00:04:45 +02:00
if ( ! active ) {
//minimize();
}
}
2011-06-26 03:55:08 +02:00
void MainWindow : : eventResize ( SizeState sizeState ) {
2011-05-19 00:04:45 +02:00
if ( program = = NULL ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " In [MainWindow::eventResize] ERROR, program == NULL! " ) ;
2011-05-19 00:04:45 +02:00
}
program - > resize ( sizeState ) ;
}
void MainWindow : : eventClose ( ) {
delete program ;
program = NULL ;
}
void MainWindow : : setProgram ( Program * program ) {
this - > program = program ;
}
// =====================================================
// Main
// =====================================================
SystemFlags debugger ;
void print_SDL_version ( const char * preamble , SDL_version * v ) {
printf ( " %s %u.%u.%u \n " , preamble , v - > major , v - > minor , v - > patch ) ;
}
int setupGameItemPaths ( int argc , char * * argv , Config * config ) {
// Setup path cache for files and folders used in the game
std : : map < string , string > & pathCache = CacheManager : : getCachedItem < std : : map < string , string > > ( GameConstants : : pathCacheLookupKey ) ;
//GAME_ARG_DATA_PATH
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_DATA_PATH ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_DATA_PATH ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_DATA_PATH ] ) , & foundParamIndIndex ) ;
}
string customPath = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( customPath , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string customPathValue = paramPartTokens [ 1 ] ;
2011-06-12 05:44:50 +02:00
Properties : : applyTagsToValue ( customPathValue ) ;
2011-06-10 23:18:22 +02:00
if ( customPathValue ! = " " ) {
endPathWithSlash ( customPathValue ) ;
}
2011-05-19 00:04:45 +02:00
pathCache [ GameConstants : : path_data_CacheLookupKey ] = customPathValue ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Using custom data path [%s] \n " , customPathValue . c_str ( ) ) ;
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( argv [ 0 ] , false ) ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
}
else if ( config ! = NULL ) {
if ( config - > getString ( " DataPath " , " " ) ! = " " ) {
2011-06-10 23:18:22 +02:00
string customPathValue = config - > getString ( " DataPath " , " " ) ;
if ( customPathValue ! = " " ) {
endPathWithSlash ( customPathValue ) ;
}
2011-05-19 00:04:45 +02:00
pathCache [ GameConstants : : path_data_CacheLookupKey ] = config - > getString ( " DataPath " , " " ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Using ini specified data path [%s] \n " , config - > getString ( " DataPath " , " " ) . c_str ( ) ) ;
}
}
//GAME_ARG_INI_PATH
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_INI_PATH ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_INI_PATH ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_INI_PATH ] ) , & foundParamIndIndex ) ;
}
string customPath = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( customPath , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string customPathValue = paramPartTokens [ 1 ] ;
2011-06-12 05:44:50 +02:00
Properties : : applyTagsToValue ( customPathValue ) ;
2011-05-19 00:04:45 +02:00
pathCache [ GameConstants : : path_ini_CacheLookupKey ] = customPathValue ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Using custom ini path [%s] \n " , customPathValue . c_str ( ) ) ;
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( argv [ 0 ] , false ) ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
}
//GAME_ARG_LOG_PATH
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LOG_PATH ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LOG_PATH ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LOG_PATH ] ) , & foundParamIndIndex ) ;
}
string customPath = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( customPath , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string customPathValue = paramPartTokens [ 1 ] ;
2011-06-12 05:44:50 +02:00
Properties : : applyTagsToValue ( customPathValue ) ;
2011-05-19 00:04:45 +02:00
pathCache [ GameConstants : : path_logs_CacheLookupKey ] = customPathValue ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Using custom logs path [%s] \n " , customPathValue . c_str ( ) ) ;
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( argv [ 0 ] , false ) ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
}
else if ( config ! = NULL ) {
if ( config - > getString ( " LogPath " , " " ) ! = " " ) {
pathCache [ GameConstants : : path_logs_CacheLookupKey ] = config - > getString ( " LogPath " , " " ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Using ini specified logs path [%s] \n " , config - > getString ( " LogPath " , " " ) . c_str ( ) ) ;
}
}
2011-06-07 04:37:58 +02:00
Text : : DEFAULT_FONT_PATH = pathCache [ GameConstants : : path_data_CacheLookupKey ] ;
2012-11-14 20:20:08 +01:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_FONT_PATH ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_FONT_PATH ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_FONT_PATH ] ) , & foundParamIndIndex ) ;
}
string customPath = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( customPath , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string customPathValue = paramPartTokens [ 1 ] ;
Properties : : applyTagsToValue ( customPathValue ) ;
Text : : DEFAULT_FONT_PATH_ABSOLUTE = customPathValue ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Using custom fonts path [%s] \n " , customPathValue . c_str ( ) ) ;
}
else {
printf ( " \n Invalid path specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( argv [ 0 ] , false ) ;
return 1 ;
}
}
2011-05-19 00:04:45 +02:00
return 0 ;
}
void setupLogging ( Config & config , bool haveSpecialOutputCommandLineOption ) {
SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled = config . getBool ( " DebugMode " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugNetwork ) . enabled = config . getBool ( " DebugNetwork " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled = config . getBool ( " DebugPerformance " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled = config . getBool ( " DebugWorldSynch " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugUnitCommands ) . enabled = config . getBool ( " DebugUnitCommands " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled = config . getBool ( " DebugPathFinder " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled = config . getBool ( " DebugLUA " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugSound ) . enabled = config . getBool ( " DebugSound " , " false " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugError ) . enabled = config . getBool ( " DebugError " , " true " ) ;
string userData = config . getString ( " UserData_Root " , " " ) ;
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
2013-01-31 21:17:52 +01:00
# ifdef HAVE_GOOGLE_BREAKPAD
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " #1 In setting up errorHandlerPtr->set_dump_path [%p]... \n " , errorHandlerPtr . get ( ) ) ;
if ( errorHandlerPtr . get ( ) ! = NULL ) {
string dumpFilePath ;
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
dumpFilePath = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ;
}
else {
dumpFilePath = userData ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " #2 In setting up errorHandlerPtr->set_dump_path... \n " ) ;
2013-02-01 03:27:01 +01:00
# if defined(WIN32)
2013-01-31 21:17:52 +01:00
wstring dumpfilepath = utf8_decode ( dumpFilePath ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) wprintf ( L " Hooking up google_breakpad::ExceptionHandler to save dmp files to [%s]... \n " , dumpfilepath . c_str ( ) ) ;
errorHandlerPtr - > set_dump_path ( dumpfilepath ) ;
2013-02-01 03:27:01 +01:00
# else
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Hooking up google_breakpad::ExceptionHandler to save dmp files to [%s]... \n " , dumpFilePath . c_str ( ) ) ;
//errorHandlerPtr->set_dump_path(dumpfilepath);
google_breakpad : : MinidumpDescriptor descriptor ( dumpFilePath ) ;
errorHandlerPtr - > set_minidump_descriptor ( descriptor ) ;
# endif
2013-01-31 21:17:52 +01:00
}
# endif
2011-05-19 00:04:45 +02:00
string debugLogFile = config . getString ( " DebugLogFile " , " " ) ;
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
debugLogFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + debugLogFile ;
}
else {
debugLogFile = userData + debugLogFile ;
}
//printf("debugLogFile [%s]\n",debugLogFile.c_str());
string debugWorldSynchLogFile = config . getString ( " DebugLogFileWorldSynch " , " " ) ;
if ( debugWorldSynchLogFile = = " " ) {
debugWorldSynchLogFile = debugLogFile ;
}
else if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
debugWorldSynchLogFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + debugWorldSynchLogFile ;
}
else {
debugWorldSynchLogFile = userData + debugWorldSynchLogFile ;
}
string debugPerformanceLogFile = config . getString ( " DebugLogFilePerformance " , " " ) ;
if ( debugPerformanceLogFile = = " " ) {
debugPerformanceLogFile = debugLogFile ;
}
else if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
debugPerformanceLogFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + debugPerformanceLogFile ;
}
else {
debugPerformanceLogFile = userData + debugPerformanceLogFile ;
}
string debugNetworkLogFile = config . getString ( " DebugLogFileNetwork " , " " ) ;
if ( debugNetworkLogFile = = " " ) {
debugNetworkLogFile = debugLogFile ;
}
else if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
debugNetworkLogFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + debugNetworkLogFile ;
}
else {
debugNetworkLogFile = userData + debugNetworkLogFile ;
}
string debugUnitCommandsLogFile = config . getString ( " DebugLogFileUnitCommands " , " " ) ;
if ( debugUnitCommandsLogFile = = " " ) {
debugUnitCommandsLogFile = debugLogFile ;
}
else if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
debugUnitCommandsLogFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + debugUnitCommandsLogFile ;
}
else {
debugUnitCommandsLogFile = userData + debugUnitCommandsLogFile ;
}
string debugPathFinderLogFile = config . getString ( " DebugLogFilePathFinder " , " " ) ;
if ( debugPathFinderLogFile = = " " ) {
debugPathFinderLogFile = debugLogFile ;
}
else if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
debugPathFinderLogFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + debugPathFinderLogFile ;
}
else {
debugPathFinderLogFile = userData + debugPathFinderLogFile ;
}
string debugLUALogFile = config . getString ( " DebugLogFileLUA " , " " ) ;
if ( debugLUALogFile = = " " ) {
debugLUALogFile = debugLogFile ;
}
else if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
debugLUALogFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + debugLUALogFile ;
}
else {
debugLUALogFile = userData + debugLUALogFile ;
}
string debugSoundLogFile = config . getString ( " DebugLogFileSound " , " " ) ;
if ( debugSoundLogFile = = " " ) {
debugSoundLogFile = debugLogFile ;
}
else if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
debugSoundLogFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + debugSoundLogFile ;
}
else {
debugSoundLogFile = userData + debugSoundLogFile ;
}
string debugErrorLogFile = config . getString ( " DebugLogFileError " , " " ) ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . debugLogFileName = debugLogFile ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugNetwork ) . debugLogFileName = debugNetworkLogFile ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . debugLogFileName = debugPerformanceLogFile ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . debugLogFileName = debugWorldSynchLogFile ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugUnitCommands ) . debugLogFileName = debugUnitCommandsLogFile ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . debugLogFileName = debugPathFinderLogFile ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . debugLogFileName = debugLUALogFile ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugSound ) . debugLogFileName = debugSoundLogFile ;
SystemFlags : : getSystemSettingType ( SystemFlags : : debugError ) . debugLogFileName = debugErrorLogFile ;
if ( haveSpecialOutputCommandLineOption = = false ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " --- Startup log settings are --- \n debugSystem [%d][%s] \n debugNetwork [%d][%s] \n debugPerformance [%d][%s] \n debugWorldSynch [%d][%s] \n debugUnitCommands[%d][%s] \n debugPathFinder[%d][%s] \n debugLUA [%d][%s] \n debugSound [%d][%s] \n debugError [%d][%s] \n " ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugSystem ) . enabled ,
debugLogFile . c_str ( ) ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugNetwork ) . enabled ,
debugNetworkLogFile . c_str ( ) ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPerformance ) . enabled ,
debugPerformanceLogFile . c_str ( ) ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugWorldSynch ) . enabled ,
debugWorldSynchLogFile . c_str ( ) ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugUnitCommands ) . enabled ,
debugUnitCommandsLogFile . c_str ( ) ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled ,
debugPathFinderLogFile . c_str ( ) ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugLUA ) . enabled ,
debugLUALogFile . c_str ( ) ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugSound ) . enabled ,
debugSoundLogFile . c_str ( ) ,
SystemFlags : : getSystemSettingType ( SystemFlags : : debugError ) . enabled ,
debugErrorLogFile . c_str ( ) ) ;
}
}
2012-04-03 21:35:22 +02:00
void runTilesetValidationForPath ( string tilesetPath , string tilesetName ,
World & world , bool purgeUnusedFiles , bool purgeDuplicateFiles ,
bool showDuplicateFiles , bool svnPurgeFiles , double & purgedMegaBytes ) {
2012-10-06 09:06:40 +02:00
//string file = tilesetPath + tilesetName + "/" + tilesetName + ".xml";
2012-04-03 21:35:22 +02:00
Checksum checksum ;
bool techtree_errors = false ;
std : : map < string , vector < pair < string , string > > > loadedFileList ;
vector < string > pathList ;
pathList . push_back ( tilesetPath ) ;
world . loadTileset ( pathList , tilesetName , & checksum , loadedFileList ) ;
// Fixup paths with ..
{
std : : map < string , vector < pair < string , string > > > newLoadedFileList ;
for ( std : : map < string , vector < pair < string , string > > > : : iterator iterMap = loadedFileList . begin ( ) ;
iterMap ! = loadedFileList . end ( ) ; + + iterMap ) {
string loadedFile = iterMap - > first ;
replaceAll ( loadedFile , " // " , " / " ) ;
replaceAll ( loadedFile , " \\ \\ " , " \\ " ) ;
updatePathClimbingParts ( loadedFile ) ;
if ( newLoadedFileList . find ( loadedFile ) ! = newLoadedFileList . end ( ) ) {
for ( unsigned int xx1 = 0 ; xx1 < iterMap - > second . size ( ) ; + + xx1 ) {
pair < string , string > & newVal = iterMap - > second [ xx1 ] ;
replaceAll ( newVal . first , " // " , " / " ) ;
replaceAll ( newVal . first , " \\ \\ " , " \\ " ) ;
updatePathClimbingParts ( newVal . first ) ;
replaceAll ( newVal . second , " // " , " / " ) ;
replaceAll ( newVal . second , " \\ \\ " , " \\ " ) ;
updatePathClimbingParts ( newVal . second ) ;
newLoadedFileList [ loadedFile ] . push_back ( newVal ) ;
}
}
else {
for ( unsigned int xx1 = 0 ; xx1 < iterMap - > second . size ( ) ; + + xx1 ) {
pair < string , string > & newVal = iterMap - > second [ xx1 ] ;
replaceAll ( newVal . first , " // " , " / " ) ;
replaceAll ( newVal . first , " \\ \\ " , " \\ " ) ;
updatePathClimbingParts ( newVal . first ) ;
replaceAll ( newVal . second , " // " , " / " ) ;
replaceAll ( newVal . second , " \\ \\ " , " \\ " ) ;
updatePathClimbingParts ( newVal . second ) ;
}
newLoadedFileList [ loadedFile ] = iterMap - > second ;
}
}
loadedFileList = newLoadedFileList ;
}
// Validate the faction setup to ensure we don't have any bad associations
// std::vector<std::string> resultErrors = world.validateFactionTypes();
// Now check for unused files in the techtree
std : : map < string , vector < pair < string , string > > > foundFileList ;
for ( unsigned int i = 0 ; i < pathList . size ( ) ; + + i ) {
string path = pathList [ i ] ;
endPathWithSlash ( path ) ;
path = path + tilesetName + " / " ;
replaceAll ( path , " // " , " / " ) ;
replaceAll ( path , " \\ \\ " , " \\ " ) ;
vector < string > foundFiles = getFolderTreeContentsListRecursively ( path + " *. " , " " ) ;
for ( unsigned int j = 0 ; j < foundFiles . size ( ) ; + + j ) {
string file = foundFiles [ j ] ;
replaceAll ( file , " // " , " / " ) ;
replaceAll ( file , " \\ \\ " , " \\ " ) ;
replaceAll ( file , " // " , " / " ) ;
replaceAll ( file , " \\ \\ " , " \\ " ) ;
foundFileList [ file ] . push_back ( make_pair ( path , path ) ) ;
}
}
2012-11-10 07:37:23 +01:00
printf ( " Found tileset filecount = " MG_SIZE_T_SPECIFIER " , used = " MG_SIZE_T_SPECIFIER " \n " , foundFileList . size ( ) , loadedFileList . size ( ) ) ;
2012-04-03 21:35:22 +02:00
int purgeCount = 0 ;
bool foundUnusedFile = false ;
for ( std : : map < string , vector < pair < string , string > > > : : iterator iterMap = foundFileList . begin ( ) ;
iterMap ! = foundFileList . end ( ) ; + + iterMap ) {
string foundFile = iterMap - > first ;
replaceAll ( foundFile , " // " , " / " ) ;
replaceAll ( foundFile , " \\ \\ " , " \\ " ) ;
2013-04-29 07:51:41 +02:00
if ( loadedFileList . find ( foundFile ) = = loadedFileList . end ( ) & &
foundFile . find ( " lang/ " ) = = foundFile . npos ) {
2012-04-03 21:35:22 +02:00
if ( foundUnusedFile = = false ) {
2012-10-14 23:59:35 +02:00
printf ( " \n Line ref: %d, Warning, unused files were detected - START: \n ===================== \n " , __LINE__ ) ;
2012-04-03 21:35:22 +02:00
}
foundUnusedFile = true ;
printf ( " [%s] \n " , foundFile . c_str ( ) ) ;
string fileName = extractFileFromDirectoryPath ( foundFile ) ;
if ( loadedFileList . find ( fileName ) ! = loadedFileList . end ( ) ) {
printf ( " possible match on [%s] ? \n " , loadedFileList . find ( fileName ) - > first . c_str ( ) ) ;
}
else if ( purgeUnusedFiles = = true ) {
off_t fileSize = getFileSize ( foundFile ) ;
// convert to MB
purgedMegaBytes + = ( ( double ) fileSize / 1048576.0 ) ;
purgeCount + + ;
if ( svnPurgeFiles = = true ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " svn delete \" %s \" " , foundFile . c_str ( ) ) ;
2012-04-03 21:35:22 +02:00
bool svnOk = executeShellCommand ( szBuf , 0 ) ;
if ( svnOk = = false ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Call to command failed [ " + string ( szBuf ) + " ] " ) ;
2012-04-03 21:35:22 +02:00
}
}
else {
removeFile ( foundFile ) ;
}
}
}
}
if ( foundUnusedFile = = true ) {
if ( purgedMegaBytes > 0 ) {
printf ( " Purged %.2f MB (%d) in files \n " , purgedMegaBytes , purgeCount ) ;
}
2012-10-14 23:59:35 +02:00
printf ( " \n Line ref: %d, Warning, unused files were detected - END: \n " , __LINE__ ) ;
2012-04-03 21:35:22 +02:00
}
if ( showDuplicateFiles = = true ) {
2012-07-07 04:46:57 +02:00
std : : map < uint32 , vector < string > > mapDuplicateFiles ;
2012-04-03 21:35:22 +02:00
// Now check for duplicate data content
for ( std : : map < string , vector < pair < string , string > > > : : iterator iterMap = loadedFileList . begin ( ) ;
iterMap ! = loadedFileList . end ( ) ; + + iterMap ) {
string fileName = iterMap - > first ;
Checksum checksum ;
checksum . addFile ( fileName ) ;
2012-07-07 04:46:57 +02:00
uint32 crcValue = checksum . getSum ( ) ;
2012-04-03 21:35:22 +02:00
mapDuplicateFiles [ crcValue ] . push_back ( fileName ) ;
}
double duplicateMegaBytesPurged = 0 ;
int duplicateCountPurged = 0 ;
double duplicateMegaBytes = 0 ;
int duplicateCount = 0 ;
bool foundDuplicates = false ;
2012-07-07 04:46:57 +02:00
for ( std : : map < uint32 , vector < string > > : : iterator iterMap = mapDuplicateFiles . begin ( ) ;
2012-04-03 21:35:22 +02:00
iterMap ! = mapDuplicateFiles . end ( ) ; + + iterMap ) {
vector < string > & fileList = iterMap - > second ;
if ( fileList . size ( ) > 1 ) {
if ( foundDuplicates = = false ) {
foundDuplicates = true ;
printf ( " \n Warning, duplicate files were detected - START: \n ===================== \n " ) ;
}
map < string , int > parentList ;
for ( unsigned int idx = 0 ; idx < fileList . size ( ) ; + + idx ) {
string duplicateFile = fileList [ idx ] ;
if ( idx > 0 ) {
off_t fileSize = getFileSize ( duplicateFile ) ;
// convert to MB
duplicateMegaBytes + = ( ( double ) fileSize / 1048576.0 ) ;
duplicateCount + + ;
}
else {
printf ( " \n " ) ;
}
printf ( " [%s] \n " , duplicateFile . c_str ( ) ) ;
std : : map < string , vector < pair < string , string > > > : : iterator iterFind = loadedFileList . find ( duplicateFile ) ;
if ( iterFind ! = loadedFileList . end ( ) ) {
for ( unsigned int jdx = 0 ; jdx < iterFind - > second . size ( ) ; jdx + + ) {
parentList [ iterFind - > second [ jdx ] . first ] + + ;
}
}
}
for ( map < string , int > : : iterator iterMap1 = parentList . begin ( ) ;
iterMap1 ! = parentList . end ( ) ; + + iterMap1 ) {
if ( iterMap1 = = parentList . begin ( ) ) {
printf ( " \t Parents: \n " ) ;
}
printf ( " \t [%s] \n " , iterMap1 - > first . c_str ( ) ) ;
}
if ( purgeDuplicateFiles = = true ) {
//printf("\nPurge Duplicate Files detected - START:\n=====================\n");
string newCommonFileName = " " ;
for ( unsigned int idx = 0 ; idx < fileList . size ( ) ; + + idx ) {
string duplicateFile = fileList [ idx ] ;
string fileExt = extractExtension ( duplicateFile ) ;
if ( fileExt = = " wav " | | fileExt = = " ogg " ) {
off_t fileSize = getFileSize ( duplicateFile ) ;
if ( idx = = 0 ) {
newCommonFileName = " $COMMONDATAPATH/sounds/ " + extractFileFromDirectoryPath ( duplicateFile ) ;
string expandedNewCommonFileName = newCommonFileName ;
std : : map < string , string > mapExtraTagReplacementValues ;
mapExtraTagReplacementValues = Properties : : getTagReplacementValues ( & mapExtraTagReplacementValues ) ;
Properties : : applyTagsToValue ( expandedNewCommonFileName , & mapExtraTagReplacementValues ) ;
2012-06-04 06:00:37 +02:00
replaceAll ( expandedNewCommonFileName , " // " , " / " ) ;
2012-04-03 21:35:22 +02:00
createDirectoryPaths ( extractDirectoryPathFromFile ( expandedNewCommonFileName ) ) ;
if ( svnPurgeFiles = = true ) {
copyFileTo ( duplicateFile , expandedNewCommonFileName ) ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " svn delete \" %s \" " , duplicateFile . c_str ( ) ) ;
2012-04-03 21:35:22 +02:00
bool svnOk = executeShellCommand ( szBuf , 0 ) ;
if ( svnOk = = false ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Call to command failed [ " + string ( szBuf ) + " ] " ) ;
2012-04-03 21:35:22 +02:00
}
printf ( " *** Duplicate file: \n [%s] \n was svn deleted and copied to: \n [%s] \n " , duplicateFile . c_str ( ) , expandedNewCommonFileName . c_str ( ) ) ;
}
else {
//int result = 0;
int result = rename ( duplicateFile . c_str ( ) , expandedNewCommonFileName . c_str ( ) ) ;
if ( result ! = 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2012-04-03 21:35:22 +02:00
char * errmsg = strerror ( errno ) ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " !!! Error [%s] Could not rename [%s] to [%s]! " , errmsg , duplicateFile . c_str ( ) , expandedNewCommonFileName . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2012-04-03 21:35:22 +02:00
}
else {
printf ( " *** Duplicate file: \n [%s] \n was renamed to: \n [%s] \n " , duplicateFile . c_str ( ) , expandedNewCommonFileName . c_str ( ) ) ;
}
}
}
else {
if ( svnPurgeFiles = = true ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " svn delete \" %s \" " , duplicateFile . c_str ( ) ) ;
2012-04-03 21:35:22 +02:00
bool svnOk = executeShellCommand ( szBuf , 0 ) ;
if ( svnOk = = false ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Call to command failed [ " + string ( szBuf ) + " ] " ) ;
2012-04-03 21:35:22 +02:00
}
printf ( " *** Duplicate file: \n [%s] \n was svn deleted \n " , duplicateFile . c_str ( ) ) ;
}
else {
removeFile ( duplicateFile ) ;
}
printf ( " *** Duplicate file: \n [%s] \n was removed \n " , duplicateFile . c_str ( ) ) ;
// convert to MB
duplicateMegaBytesPurged + = ( ( double ) fileSize / 1048576.0 ) ;
duplicateCountPurged + + ;
}
}
}
std : : map < string , int > mapUniqueParentList ;
for ( unsigned int idx = 0 ; idx < fileList . size ( ) ; + + idx ) {
string duplicateFile = fileList [ idx ] ;
string fileExt = extractExtension ( duplicateFile ) ;
if ( fileExt = = " wav " | | fileExt = = " ogg " ) {
std : : map < string , vector < pair < string , string > > > : : iterator iterFind2 = loadedFileList . find ( duplicateFile ) ;
if ( iterFind2 ! = loadedFileList . end ( ) ) {
for ( unsigned int jdx1 = 0 ; jdx1 < iterFind2 - > second . size ( ) ; jdx1 + + ) {
string parentFile = iterFind2 - > second [ jdx1 ] . first ;
string searchText = iterFind2 - > second [ jdx1 ] . second ;
if ( mapUniqueParentList . find ( parentFile ) = = mapUniqueParentList . end ( ) ) {
printf ( " *** Searching parent file: \n [%s] \n for duplicate file reference: \n [%s] \n to replace with newname: \n [%s] \n " , parentFile . c_str ( ) , searchText . c_str ( ) , newCommonFileName . c_str ( ) ) ;
bool foundText = searchAndReplaceTextInFile ( parentFile , searchText , newCommonFileName , false ) ;
printf ( " foundText = %d \n " , foundText ) ;
if ( foundText = = false ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Line ref = %d, Error finding text [%s] in file [%s] " , __LINE__ , searchText . c_str ( ) , parentFile . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2012-04-03 21:35:22 +02:00
}
mapUniqueParentList [ parentFile ] + + ;
}
}
}
}
}
//printf("\nPurge Duplicate Files detected - END:\n=====================\n");
}
else {
//printf("\nPurge Duplicate Files DISABLED - START:\n=====================\n");
string newCommonFileName = " " ;
for ( unsigned int idx = 0 ; idx < fileList . size ( ) ; + + idx ) {
string duplicateFile = fileList [ idx ] ;
string fileExt = extractExtension ( duplicateFile ) ;
if ( fileExt = = " wav " | | fileExt = = " ogg " ) {
off_t fileSize = getFileSize ( duplicateFile ) ;
if ( idx = = 0 ) {
newCommonFileName = " $COMMONDATAPATH/sounds/ " + extractFileFromDirectoryPath ( duplicateFile ) ;
break ;
}
}
}
2012-11-10 07:37:23 +01:00
//printf("\nPurge Duplicate Files #2 DISABLED [" MG_SIZE_T_SPECIFIER "] - START:\n=====================\n",fileList.size());
2012-04-03 21:35:22 +02:00
for ( unsigned int idx = 0 ; idx < fileList . size ( ) ; + + idx ) {
string duplicateFile = fileList [ idx ] ;
string fileExt = extractExtension ( duplicateFile ) ;
if ( fileExt = = " wav " | | fileExt = = " ogg " ) {
std : : map < string , vector < pair < string , string > > > : : iterator iterFind4 = loadedFileList . find ( duplicateFile ) ;
if ( iterFind4 ! = loadedFileList . end ( ) ) {
for ( unsigned int jdx = 0 ; jdx < iterFind4 - > second . size ( ) ; jdx + + ) {
string parentFile = iterFind4 - > second [ jdx ] . first ;
string searchText = iterFind4 - > second [ jdx ] . second ;
//printf("*** Searching parent file:\n[%s]\nfor duplicate file reference:\n[%s]\nto replace with newname:\n[%s]\n",parentFile.c_str(),searchText.c_str(),newCommonFileName.c_str());
bool foundText = searchAndReplaceTextInFile ( parentFile , searchText , newCommonFileName , true ) ;
//printf("foundText = %d\n",foundText);
if ( foundText = = false ) {
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Line ref = %d, Error finding text \n [%s] \n in file \n [%s] \n new Common File [%s] \n " , __LINE__ , searchText . c_str ( ) , parentFile . c_str ( ) , newCommonFileName . c_str ( ) ) ;
2012-04-03 21:35:22 +02:00
printf ( " \n \n ================================================= \n %s " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2012-04-03 21:35:22 +02:00
}
}
}
}
}
//printf("\nPurge Duplicate Files DISABLED - END:\n=====================\n");
}
}
}
if ( foundDuplicates = = true ) {
printf ( " Duplicates %.2f MB (%d) in files \n " , duplicateMegaBytes , duplicateCount ) ;
printf ( " Duplicates purged %.2f MB (%d) in files \n " , duplicateMegaBytesPurged , duplicateCountPurged ) ;
printf ( " \n Warning, duplicate files were detected - END: \n " ) ;
}
}
if ( techtree_errors = = false ) {
printf ( " \n Validation found NO ERRORS for tilesetPath [%s] tilesetName [%s]: \n " , tilesetPath . c_str ( ) , tilesetName . c_str ( ) ) ;
}
printf ( " ---------------------------------------------------------------- " ) ;
}
2011-05-19 00:04:45 +02:00
void runTechValidationForPath ( string techPath , string techName ,
2011-09-01 01:10:43 +02:00
const std : : vector < string > & filteredFactionList , World & world ,
2011-07-09 21:28:01 +02:00
bool purgeUnusedFiles , bool purgeDuplicateFiles , bool showDuplicateFiles ,
bool svnPurgeFiles , double & purgedMegaBytes ) {
2011-09-01 01:10:43 +02:00
//Config &config = Config::getInstance();
2011-05-19 00:04:45 +02:00
vector < string > factionsList ;
findDirs ( techPath + techName + " /factions/ " , factionsList , false , false ) ;
2011-09-01 01:10:43 +02:00
if ( factionsList . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
Checksum checksum ;
set < string > factions ;
for ( int j = 0 ; j < factionsList . size ( ) ; + + j ) {
2011-09-01 20:08:56 +02:00
if ( filteredFactionList . empty ( ) = = true | |
2011-05-19 00:04:45 +02:00
std : : find ( filteredFactionList . begin ( ) , filteredFactionList . end ( ) , factionsList [ j ] ) ! = filteredFactionList . end ( ) ) {
factions . insert ( factionsList [ j ] ) ;
}
}
printf ( " \n ---------------------------------------------------------------- " ) ;
printf ( " \n Checking techPath [%s] techName [%s] total faction count = %d \n " , techPath . c_str ( ) , techName . c_str ( ) , ( int ) factionsList . size ( ) ) ;
for ( int j = 0 ; j < factionsList . size ( ) ; + + j ) {
2011-09-01 20:08:56 +02:00
if ( filteredFactionList . empty ( ) = = true | |
2011-05-19 00:04:45 +02:00
std : : find ( filteredFactionList . begin ( ) , filteredFactionList . end ( ) , factionsList [ j ] ) ! = filteredFactionList . end ( ) ) {
printf ( " Using faction [%s] \n " , factionsList [ j ] . c_str ( ) ) ;
}
}
2011-09-01 01:10:43 +02:00
if ( factions . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
bool techtree_errors = false ;
std : : map < string , vector < pair < string , string > > > loadedFileList ;
//vector<string> pathList = config.getPathListForType(ptTechs,"");
vector < string > pathList ;
pathList . push_back ( techPath ) ;
2012-10-14 23:40:35 +02:00
Config & config = Config : : getInstance ( ) ;
vector < string > otherTechPaths = config . getPathListForType ( ptTechs , " " ) ;
pathList . insert ( pathList . end ( ) , otherTechPaths . begin ( ) , otherTechPaths . end ( ) ) ;
2011-05-19 00:04:45 +02:00
world . loadTech ( pathList , techName , factions , & checksum , loadedFileList ) ;
// Fixup paths with ..
{
std : : map < string , vector < pair < string , string > > > newLoadedFileList ;
for ( std : : map < string , vector < pair < string , string > > > : : iterator iterMap = loadedFileList . begin ( ) ;
iterMap ! = loadedFileList . end ( ) ; + + iterMap ) {
string loadedFile = iterMap - > first ;
replaceAll ( loadedFile , " // " , " / " ) ;
replaceAll ( loadedFile , " \\ \\ " , " \\ " ) ;
updatePathClimbingParts ( loadedFile ) ;
if ( newLoadedFileList . find ( loadedFile ) ! = newLoadedFileList . end ( ) ) {
for ( unsigned int xx1 = 0 ; xx1 < iterMap - > second . size ( ) ; + + xx1 ) {
2012-03-10 18:46:10 +01:00
pair < string , string > & newVal = iterMap - > second [ xx1 ] ;
replaceAll ( newVal . first , " // " , " / " ) ;
replaceAll ( newVal . first , " \\ \\ " , " \\ " ) ;
updatePathClimbingParts ( newVal . first ) ;
replaceAll ( newVal . second , " // " , " / " ) ;
replaceAll ( newVal . second , " \\ \\ " , " \\ " ) ;
updatePathClimbingParts ( newVal . second ) ;
newLoadedFileList [ loadedFile ] . push_back ( newVal ) ;
2011-05-19 00:04:45 +02:00
}
}
else {
2012-03-10 18:46:10 +01:00
for ( unsigned int xx1 = 0 ; xx1 < iterMap - > second . size ( ) ; + + xx1 ) {
pair < string , string > & newVal = iterMap - > second [ xx1 ] ;
replaceAll ( newVal . first , " // " , " / " ) ;
replaceAll ( newVal . first , " \\ \\ " , " \\ " ) ;
updatePathClimbingParts ( newVal . first ) ;
replaceAll ( newVal . second , " // " , " / " ) ;
replaceAll ( newVal . second , " \\ \\ " , " \\ " ) ;
updatePathClimbingParts ( newVal . second ) ;
}
2011-05-19 00:04:45 +02:00
newLoadedFileList [ loadedFile ] = iterMap - > second ;
}
}
loadedFileList = newLoadedFileList ;
}
// Validate the faction setup to ensure we don't have any bad associations
std : : vector < std : : string > resultErrors = world . validateFactionTypes ( ) ;
2011-09-01 01:10:43 +02:00
if ( resultErrors . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
techtree_errors = true ;
// Display the validation errors
string errorText = " \n Errors were detected: \n ===================== \n " ;
for ( int i = 0 ; i < resultErrors . size ( ) ; + + i ) {
if ( i > 0 ) {
errorText + = " \n " ;
}
errorText = errorText + resultErrors [ i ] ;
}
errorText + = " \n ===================== \n " ;
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error(errorText);
2011-05-19 00:04:45 +02:00
printf ( " %s " , errorText . c_str ( ) ) ;
}
// Validate the faction resource setup to ensure we don't have any bad associations
printf ( " \n Checking resources, count = %d \n " , world . getTechTree ( ) - > getResourceTypeCount ( ) ) ;
for ( int i = 0 ; i < world . getTechTree ( ) - > getResourceTypeCount ( ) ; + + i ) {
printf ( " Found techtree resource [%s] \n " , world . getTechTree ( ) - > getResourceType ( i ) - > getName ( ) . c_str ( ) ) ;
}
resultErrors = world . validateResourceTypes ( ) ;
2011-09-01 01:10:43 +02:00
if ( resultErrors . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
techtree_errors = true ;
// Display the validation errors
string errorText = " \n Errors were detected: \n ===================== \n " ;
for ( int i = 0 ; i < resultErrors . size ( ) ; + + i ) {
if ( i > 0 ) {
errorText + = " \n " ;
}
errorText = errorText + resultErrors [ i ] ;
}
errorText + = " \n ===================== \n " ;
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error(errorText);
2011-05-19 00:04:45 +02:00
printf ( " %s " , errorText . c_str ( ) ) ;
}
// Now check for unused files in the techtree
std : : map < string , vector < pair < string , string > > > foundFileList ;
for ( unsigned int i = 0 ; i < pathList . size ( ) ; + + i ) {
string path = pathList [ i ] ;
endPathWithSlash ( path ) ;
path = path + techName + " / " ;
2012-03-10 18:46:10 +01:00
replaceAll ( path , " // " , " / " ) ;
replaceAll ( path , " \\ \\ " , " \\ " ) ;
2011-05-19 00:04:45 +02:00
vector < string > foundFiles = getFolderTreeContentsListRecursively ( path + " *. " , " " ) ;
for ( unsigned int j = 0 ; j < foundFiles . size ( ) ; + + j ) {
string file = foundFiles [ j ] ;
2012-03-10 18:46:10 +01:00
replaceAll ( file , " // " , " / " ) ;
replaceAll ( file , " \\ \\ " , " \\ " ) ;
2013-02-12 00:43:30 +01:00
if ( file . find ( GameConstants : : LOADING_SCREEN_FILE ) ! = string : : npos | |
file . find ( GameConstants : : PREVIEW_SCREEN_FILE ) ! = string : : npos | |
file . find ( GameConstants : : HUD_SCREEN_FILE ) ! = string : : npos ) {
2011-05-19 00:04:45 +02:00
continue ;
}
if ( file . find ( " /factions/ " ) ! = string : : npos ) {
bool includeFaction = false ;
for ( set < string > : : iterator it = factions . begin ( ) ; it ! = factions . end ( ) ; + + it ) {
string currentFaction = * it ;
if ( file . find ( " /factions/ " + currentFaction ) ! = string : : npos ) {
includeFaction = true ;
break ;
}
}
if ( includeFaction = = false ) {
continue ;
}
}
replaceAll ( file , " // " , " / " ) ;
replaceAll ( file , " \\ \\ " , " \\ " ) ;
foundFileList [ file ] . push_back ( make_pair ( path , path ) ) ;
}
}
2012-11-10 07:37:23 +01:00
printf ( " Found techtree filecount = " MG_SIZE_T_SPECIFIER " , used = " MG_SIZE_T_SPECIFIER " \n " , foundFileList . size ( ) , loadedFileList . size ( ) ) ;
2011-05-19 00:04:45 +02:00
// for( std::map<string,vector<string> >::iterator iterMap = loadedFileList.begin();
// iterMap != loadedFileList.end(); ++iterMap) {
// string foundFile = iterMap->first;
//
// if(foundFile.find("golem_ack1.wav") != string::npos) {
// printf("FOUND file [%s]\n",foundFile.c_str());
// }
// }
int purgeCount = 0 ;
bool foundUnusedFile = false ;
for ( std : : map < string , vector < pair < string , string > > > : : iterator iterMap = foundFileList . begin ( ) ;
iterMap ! = foundFileList . end ( ) ; + + iterMap ) {
string foundFile = iterMap - > first ;
2012-03-10 18:46:10 +01:00
replaceAll ( foundFile , " // " , " / " ) ;
replaceAll ( foundFile , " \\ \\ " , " \\ " ) ;
2011-05-19 00:04:45 +02:00
2013-04-29 07:51:41 +02:00
if ( loadedFileList . find ( foundFile ) = = loadedFileList . end ( ) & &
foundFile . find ( " lang/ " ) = = foundFile . npos ) {
2011-05-19 00:04:45 +02:00
if ( foundUnusedFile = = false ) {
2012-10-14 23:59:35 +02:00
printf ( " \n Line ref: %d, Warning, unused files were detected - START: \n ===================== \n " , __LINE__ ) ;
2011-05-19 00:04:45 +02:00
}
foundUnusedFile = true ;
printf ( " [%s] \n " , foundFile . c_str ( ) ) ;
string fileName = extractFileFromDirectoryPath ( foundFile ) ;
if ( loadedFileList . find ( fileName ) ! = loadedFileList . end ( ) ) {
printf ( " possible match on [%s] ? \n " , loadedFileList . find ( fileName ) - > first . c_str ( ) ) ;
}
else if ( purgeUnusedFiles = = true ) {
off_t fileSize = getFileSize ( foundFile ) ;
// convert to MB
purgedMegaBytes + = ( ( double ) fileSize / 1048576.0 ) ;
purgeCount + + ;
if ( svnPurgeFiles = = true ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " svn delete \" %s \" " , foundFile . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
bool svnOk = executeShellCommand ( szBuf , 0 ) ;
if ( svnOk = = false ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Call to command failed [ " + string ( szBuf ) + " ] " ) ;
2011-05-19 00:04:45 +02:00
}
}
else {
removeFile ( foundFile ) ;
}
}
}
}
if ( foundUnusedFile = = true ) {
if ( purgedMegaBytes > 0 ) {
printf ( " Purged %.2f MB (%d) in files \n " , purgedMegaBytes , purgeCount ) ;
}
2012-10-14 23:59:35 +02:00
printf ( " \n Line ref: %d, Warning, unused files were detected - END: \n " , __LINE__ ) ;
2011-05-19 00:04:45 +02:00
}
2011-07-09 21:28:01 +02:00
if ( showDuplicateFiles = = true ) {
2012-07-07 04:46:57 +02:00
std : : map < uint32 , vector < string > > mapDuplicateFiles ;
2011-07-09 21:28:01 +02:00
// Now check for duplicate data content
for ( std : : map < string , vector < pair < string , string > > > : : iterator iterMap = loadedFileList . begin ( ) ;
2011-09-01 01:10:43 +02:00
iterMap ! = loadedFileList . end ( ) ; + + iterMap ) {
2011-07-09 21:28:01 +02:00
string fileName = iterMap - > first ;
Checksum checksum ;
checksum . addFile ( fileName ) ;
2012-07-07 04:46:57 +02:00
uint32 crcValue = checksum . getSum ( ) ;
2012-06-04 06:00:37 +02:00
if ( crcValue = = 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " Error calculating CRC for file [%s] " , fileName . c_str ( ) ) ;
2012-06-04 06:00:37 +02:00
throw megaglest_runtime_error ( szBuf ) ;
}
2011-07-09 21:28:01 +02:00
// else {
// printf("** CRC for file [%s] is [%d] and has %d parents\n",fileName.c_str(),crcValue,(int)iterMap->second.size());
// }
mapDuplicateFiles [ crcValue ] . push_back ( fileName ) ;
}
2011-05-19 00:04:45 +02:00
2011-07-09 21:28:01 +02:00
double duplicateMegaBytesPurged = 0 ;
int duplicateCountPurged = 0 ;
2011-05-19 00:04:45 +02:00
2011-07-09 21:28:01 +02:00
double duplicateMegaBytes = 0 ;
int duplicateCount = 0 ;
2011-05-19 00:04:45 +02:00
2011-07-09 21:28:01 +02:00
bool foundDuplicates = false ;
2012-07-07 04:46:57 +02:00
for ( std : : map < uint32 , vector < string > > : : iterator iterMap = mapDuplicateFiles . begin ( ) ;
2011-09-01 01:10:43 +02:00
iterMap ! = mapDuplicateFiles . end ( ) ; + + iterMap ) {
2011-07-09 21:28:01 +02:00
vector < string > & fileList = iterMap - > second ;
if ( fileList . size ( ) > 1 ) {
if ( foundDuplicates = = false ) {
foundDuplicates = true ;
printf ( " \n Warning, duplicate files were detected - START: \n ===================== \n " ) ;
2011-05-19 00:04:45 +02:00
}
2012-11-10 07:37:23 +01:00
printf ( " ----- START duplicate files for CRC [%u] count [ " MG_SIZE_T_SPECIFIER " ] first file is [%s] \n " , iterMap - > first , fileList . size ( ) , fileList [ 0 ] . c_str ( ) ) ;
2012-06-04 06:00:37 +02:00
2011-07-09 21:28:01 +02:00
map < string , int > parentList ;
for ( unsigned int idx = 0 ; idx < fileList . size ( ) ; + + idx ) {
string duplicateFile = fileList [ idx ] ;
if ( idx > 0 ) {
off_t fileSize = getFileSize ( duplicateFile ) ;
// convert to MB
duplicateMegaBytes + = ( ( double ) fileSize / 1048576.0 ) ;
duplicateCount + + ;
}
else {
printf ( " \n " ) ;
}
printf ( " [%s] \n " , duplicateFile . c_str ( ) ) ;
std : : map < string , vector < pair < string , string > > > : : iterator iterFind = loadedFileList . find ( duplicateFile ) ;
if ( iterFind ! = loadedFileList . end ( ) ) {
for ( unsigned int jdx = 0 ; jdx < iterFind - > second . size ( ) ; jdx + + ) {
parentList [ iterFind - > second [ jdx ] . first ] + + ;
}
2011-05-19 00:04:45 +02:00
}
2012-06-04 06:00:37 +02:00
//!!!
string newCommonFileName = " $COMMONDATAPATH/sounds/ " + extractFileFromDirectoryPath ( duplicateFile ) ;
string expandedNewCommonFileName = newCommonFileName ;
std : : map < string , string > mapExtraTagReplacementValues ;
string techCommonData = techPath + techName + " /commondata/ " ;
replaceAll ( techCommonData , " // " , " / " ) ;
mapExtraTagReplacementValues [ " $COMMONDATAPATH " ] = techCommonData ;
mapExtraTagReplacementValues = Properties : : getTagReplacementValues ( & mapExtraTagReplacementValues ) ;
Properties : : applyTagsToValue ( expandedNewCommonFileName , & mapExtraTagReplacementValues ) ;
replaceAll ( expandedNewCommonFileName , " // " , " / " ) ;
//printf("**** Checking for partial commondata scenario [%s] [%s]\n",duplicateFile.c_str(),expandedNewCommonFileName.c_str());
//if(StartsWith(duplicateFile, expandedNewCommonFileName) == true) {
// throw megaglest_runtime_error("ERROR, this configuration has partial common data and duplicates, aborting..");
//}
2011-05-19 00:04:45 +02:00
}
2012-11-10 07:37:23 +01:00
printf ( " ----- Finding parents for duplicate files [ " MG_SIZE_T_SPECIFIER " ] first file is [%s] \n " , fileList . size ( ) , fileList [ 0 ] . c_str ( ) ) ;
2012-06-04 06:00:37 +02:00
2011-07-09 21:28:01 +02:00
for ( map < string , int > : : iterator iterMap1 = parentList . begin ( ) ;
2011-09-01 01:10:43 +02:00
iterMap1 ! = parentList . end ( ) ; + + iterMap1 ) {
2011-05-19 00:04:45 +02:00
2011-07-09 21:28:01 +02:00
if ( iterMap1 = = parentList . begin ( ) ) {
printf ( " \t Parents: \n " ) ;
}
printf ( " \t [%s] \n " , iterMap1 - > first . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
}
2011-07-09 21:28:01 +02:00
if ( purgeDuplicateFiles = = true ) {
2012-03-10 07:44:57 +01:00
//printf("\nPurge Duplicate Files detected - START:\n=====================\n");
2012-11-10 07:37:23 +01:00
printf ( " ----- move / remove duplicate files [ " MG_SIZE_T_SPECIFIER " ] first file is [%s] \n " , fileList . size ( ) , fileList [ 0 ] . c_str ( ) ) ;
2012-06-04 06:00:37 +02:00
// First move first duplicate to commondata and delete all other copies
2011-07-09 21:28:01 +02:00
string newCommonFileName = " " ;
for ( unsigned int idx = 0 ; idx < fileList . size ( ) ; + + idx ) {
string duplicateFile = fileList [ idx ] ;
string fileExt = extractExtension ( duplicateFile ) ;
if ( fileExt = = " wav " | | fileExt = = " ogg " ) {
off_t fileSize = getFileSize ( duplicateFile ) ;
2012-06-04 06:00:37 +02:00
2012-11-10 07:37:23 +01:00
printf ( " #1 [%u / " MG_SIZE_T_SPECIFIER " ] removing duplicate [%s] \n " , idx , fileList . size ( ) , duplicateFile . c_str ( ) ) ;
2012-06-04 06:00:37 +02:00
2011-07-09 21:28:01 +02:00
if ( idx = = 0 ) {
newCommonFileName = " $COMMONDATAPATH/sounds/ " + extractFileFromDirectoryPath ( duplicateFile ) ;
2011-05-19 00:04:45 +02:00
2011-07-09 21:28:01 +02:00
string expandedNewCommonFileName = newCommonFileName ;
2011-05-19 00:04:45 +02:00
2011-07-09 21:28:01 +02:00
std : : map < string , string > mapExtraTagReplacementValues ;
2012-03-10 18:46:10 +01:00
string techCommonData = techPath + techName + " /commondata/ " ;
replaceAll ( techCommonData , " // " , " / " ) ;
mapExtraTagReplacementValues [ " $COMMONDATAPATH " ] = techCommonData ;
2011-07-09 21:28:01 +02:00
mapExtraTagReplacementValues = Properties : : getTagReplacementValues ( & mapExtraTagReplacementValues ) ;
Properties : : applyTagsToValue ( expandedNewCommonFileName , & mapExtraTagReplacementValues ) ;
2012-06-04 06:00:37 +02:00
replaceAll ( expandedNewCommonFileName , " // " , " / " ) ;
2011-07-09 21:28:01 +02:00
createDirectoryPaths ( extractDirectoryPathFromFile ( expandedNewCommonFileName ) ) ;
2011-05-19 00:04:45 +02:00
2011-07-09 21:28:01 +02:00
if ( svnPurgeFiles = = true ) {
copyFileTo ( duplicateFile , expandedNewCommonFileName ) ;
2011-05-19 00:04:45 +02:00
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " svn delete \" %s \" " , duplicateFile . c_str ( ) ) ;
2011-07-09 21:28:01 +02:00
bool svnOk = executeShellCommand ( szBuf , 0 ) ;
if ( svnOk = = false ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Call to command failed [ " + string ( szBuf ) + " ] " ) ;
2011-07-09 21:28:01 +02:00
}
printf ( " *** Duplicate file: \n [%s] \n was svn deleted and copied to: \n [%s] \n " , duplicateFile . c_str ( ) , expandedNewCommonFileName . c_str ( ) ) ;
}
else {
//int result = 0;
2012-06-04 06:00:37 +02:00
printf ( " moving duplicate [%s] to common data [%s] expanded to [%s] \n " , duplicateFile . c_str ( ) , newCommonFileName . c_str ( ) , expandedNewCommonFileName . c_str ( ) ) ;
2011-07-09 21:28:01 +02:00
int result = rename ( duplicateFile . c_str ( ) , expandedNewCommonFileName . c_str ( ) ) ;
if ( result ! = 0 ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2011-07-09 21:28:01 +02:00
char * errmsg = strerror ( errno ) ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " !!! Error [%s] Could not rename [%s] to [%s]! " , errmsg , duplicateFile . c_str ( ) , expandedNewCommonFileName . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-07-09 21:28:01 +02:00
}
else {
printf ( " *** Duplicate file: \n [%s] \n was renamed to: \n [%s] \n " , duplicateFile . c_str ( ) , expandedNewCommonFileName . c_str ( ) ) ;
}
2011-05-19 00:04:45 +02:00
}
}
else {
2011-07-09 21:28:01 +02:00
if ( svnPurgeFiles = = true ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " svn delete \" %s \" " , duplicateFile . c_str ( ) ) ;
2011-07-09 21:28:01 +02:00
bool svnOk = executeShellCommand ( szBuf , 0 ) ;
if ( svnOk = = false ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " Call to command failed [ " + string ( szBuf ) + " ] " ) ;
2011-07-09 21:28:01 +02:00
}
printf ( " *** Duplicate file: \n [%s] \n was svn deleted \n " , duplicateFile . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
}
else {
2012-06-04 06:00:37 +02:00
printf ( " removing duplicate [%s] \n " , duplicateFile . c_str ( ) ) ;
2011-07-09 21:28:01 +02:00
removeFile ( duplicateFile ) ;
2011-05-19 00:04:45 +02:00
}
2011-07-09 21:28:01 +02:00
printf ( " *** Duplicate file: \n [%s] \n was removed \n " , duplicateFile . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
2011-07-09 21:28:01 +02:00
// convert to MB
duplicateMegaBytesPurged + = ( ( double ) fileSize / 1048576.0 ) ;
duplicateCountPurged + + ;
}
2011-05-19 00:04:45 +02:00
}
}
2012-11-10 07:37:23 +01:00
printf ( " ----- update XML files for duplicate files [ " MG_SIZE_T_SPECIFIER " ] first file is [%s] \n " , fileList . size ( ) , fileList [ 0 ] . c_str ( ) ) ;
2011-07-09 21:28:01 +02:00
std : : map < string , int > mapUniqueParentList ;
2012-06-04 06:00:37 +02:00
// Update the XML files to point to the new single copy in commondata
2011-07-09 21:28:01 +02:00
for ( unsigned int idx = 0 ; idx < fileList . size ( ) ; + + idx ) {
string duplicateFile = fileList [ idx ] ;
string fileExt = extractExtension ( duplicateFile ) ;
if ( fileExt = = " wav " | | fileExt = = " ogg " ) {
std : : map < string , vector < pair < string , string > > > : : iterator iterFind2 = loadedFileList . find ( duplicateFile ) ;
if ( iterFind2 ! = loadedFileList . end ( ) ) {
for ( unsigned int jdx1 = 0 ; jdx1 < iterFind2 - > second . size ( ) ; jdx1 + + ) {
string parentFile = iterFind2 - > second [ jdx1 ] . first ;
string searchText = iterFind2 - > second [ jdx1 ] . second ;
if ( mapUniqueParentList . find ( parentFile ) = = mapUniqueParentList . end ( ) ) {
printf ( " *** Searching parent file: \n [%s] \n for duplicate file reference: \n [%s] \n to replace with newname: \n [%s] \n " , parentFile . c_str ( ) , searchText . c_str ( ) , newCommonFileName . c_str ( ) ) ;
bool foundText = searchAndReplaceTextInFile ( parentFile , searchText , newCommonFileName , false ) ;
printf ( " foundText = %d \n " , foundText ) ;
if ( foundText = = false ) {
2012-06-04 06:00:37 +02:00
string techCommonData = techPath + techName + " /commondata/ " ;
replaceAll ( techCommonData , " // " , " / " ) ;
//printf("WARNING #1 techCommonData check\n[%s]\n[%s]\n",techCommonData.c_str(),searchText.c_str());
if ( StartsWith ( searchText , techCommonData ) = = true ) {
printf ( " WARNING #1 [%d] techCommonData check \n [%s] \n [%s] \n [%s] \n [%s] \n " ,
foundText , parentFile . c_str ( ) , techCommonData . c_str ( ) , searchText . c_str ( ) , newCommonFileName . c_str ( ) ) ;
replaceAll ( searchText , techCommonData , " $COMMONDATAPATH/ " ) ;
foundText = searchAndReplaceTextInFile ( parentFile , searchText , newCommonFileName , false ) ;
printf ( " WARNING #2 [%d] techCommonData check \n [%s] \n [%s] \n [%s] \n [%s] \n " ,
foundText , parentFile . c_str ( ) , techCommonData . c_str ( ) , searchText . c_str ( ) , newCommonFileName . c_str ( ) ) ;
}
if ( foundText = = false ) {
//printf("Error finding text [%s] in file [%s]",searchText.c_str(),parentFile.c_str());
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Line ref = %d, Error finding text \n [%s] \n in file \n [%s] \n new Common File [%s] \n " , __LINE__ , searchText . c_str ( ) , parentFile . c_str ( ) , newCommonFileName . c_str ( ) ) ;
2012-06-04 06:00:37 +02:00
printf ( " \n \n ================================================= \n %s " , szBuf ) ;
throw megaglest_runtime_error ( szBuf ) ;
}
2011-07-09 21:28:01 +02:00
}
mapUniqueParentList [ parentFile ] + + ;
2011-05-19 00:04:45 +02:00
}
}
}
}
}
2012-03-10 07:44:57 +01:00
//printf("\nPurge Duplicate Files detected - END:\n=====================\n");
2011-05-19 00:04:45 +02:00
}
2011-07-09 21:28:01 +02:00
else {
2012-03-10 07:44:57 +01:00
//printf("\nPurge Duplicate Files DISABLED - START:\n=====================\n");
2011-07-09 21:28:01 +02:00
string newCommonFileName = " " ;
for ( unsigned int idx = 0 ; idx < fileList . size ( ) ; + + idx ) {
string duplicateFile = fileList [ idx ] ;
string fileExt = extractExtension ( duplicateFile ) ;
if ( fileExt = = " wav " | | fileExt = = " ogg " ) {
off_t fileSize = getFileSize ( duplicateFile ) ;
if ( idx = = 0 ) {
newCommonFileName = " $COMMONDATAPATH/sounds/ " + extractFileFromDirectoryPath ( duplicateFile ) ;
break ;
}
2011-05-19 00:04:45 +02:00
}
}
2012-03-10 07:44:57 +01:00
2012-11-10 07:37:23 +01:00
//printf("\nPurge Duplicate Files #2 DISABLED [" MG_SIZE_T_SPECIFIER "] - START:\n=====================\n",fileList.size());
2012-03-10 07:44:57 +01:00
2011-07-09 21:28:01 +02:00
for ( unsigned int idx = 0 ; idx < fileList . size ( ) ; + + idx ) {
string duplicateFile = fileList [ idx ] ;
string fileExt = extractExtension ( duplicateFile ) ;
if ( fileExt = = " wav " | | fileExt = = " ogg " ) {
std : : map < string , vector < pair < string , string > > > : : iterator iterFind4 = loadedFileList . find ( duplicateFile ) ;
if ( iterFind4 ! = loadedFileList . end ( ) ) {
for ( unsigned int jdx = 0 ; jdx < iterFind4 - > second . size ( ) ; jdx + + ) {
string parentFile = iterFind4 - > second [ jdx ] . first ;
string searchText = iterFind4 - > second [ jdx ] . second ;
2012-03-10 18:46:10 +01:00
//replaceAll(parentFile, "//", "/");
//replaceAll(parentFile, "\\\\", "\\");
2011-07-09 21:28:01 +02:00
//printf("*** Searching parent file:\n[%s]\nfor duplicate file reference:\n[%s]\nto replace with newname:\n[%s]\n",parentFile.c_str(),searchText.c_str(),newCommonFileName.c_str());
bool foundText = searchAndReplaceTextInFile ( parentFile , searchText , newCommonFileName , true ) ;
//printf("foundText = %d\n",foundText);
if ( foundText = = false ) {
2012-03-10 07:44:57 +01:00
string techCommonData = techPath + techName + " /commondata/ " ;
replaceAll ( techCommonData , " // " , " / " ) ;
2012-06-04 06:00:37 +02:00
//printf("WARNING #1 techCommonData check\n[%s]\n[%s]\n",techCommonData.c_str(),searchText.c_str());
2012-03-10 07:44:57 +01:00
if ( StartsWith ( searchText , techCommonData ) = = true ) {
replaceAll ( searchText , techCommonData , " $COMMONDATAPATH/ " ) ;
foundText = searchAndReplaceTextInFile ( parentFile , searchText , newCommonFileName , true ) ;
2012-06-04 06:00:37 +02:00
//printf("WARNING #2 techCommonData check\n[%s]\n[%s]\n[%s]\n",techCommonData.c_str(),searchText.c_str(),newCommonFileName.c_str());
2012-03-10 07:44:57 +01:00
}
if ( foundText = = false ) {
//printf("Error finding text [%s] in file [%s]",searchText.c_str(),parentFile.c_str());
2012-10-14 23:40:35 +02:00
// Check if the sound file already references commandata
foundText = searchAndReplaceTextInFile ( parentFile , newCommonFileName , newCommonFileName , true ) ;
if ( foundText = = false ) {
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Line ref = %d, Error finding text \n [%s] \n in file \n [%s] \n new Common File [%s] \n " , __LINE__ , searchText . c_str ( ) , parentFile . c_str ( ) , newCommonFileName . c_str ( ) ) ;
2012-10-14 23:40:35 +02:00
printf ( " \n \n ================================================= \n %s " , szBuf ) ;
2012-03-10 07:44:57 +01:00
2012-10-14 23:40:35 +02:00
throw megaglest_runtime_error ( szBuf ) ;
}
2012-03-10 07:44:57 +01:00
}
2011-07-09 21:28:01 +02:00
}
2011-05-19 00:04:45 +02:00
}
}
}
}
2012-03-10 07:44:57 +01:00
//printf("\nPurge Duplicate Files DISABLED - END:\n=====================\n");
2011-05-19 00:04:45 +02:00
}
2012-06-04 06:00:37 +02:00
2012-11-10 07:37:23 +01:00
printf ( " ----- END duplicate files [ " MG_SIZE_T_SPECIFIER " ] first file is [%s] \n " , fileList . size ( ) , fileList [ 0 ] . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
}
}
2011-07-09 21:28:01 +02:00
if ( foundDuplicates = = true ) {
printf ( " Duplicates %.2f MB (%d) in files \n " , duplicateMegaBytes , duplicateCount ) ;
printf ( " Duplicates purged %.2f MB (%d) in files \n " , duplicateMegaBytesPurged , duplicateCountPurged ) ;
2011-05-19 00:04:45 +02:00
2011-07-09 21:28:01 +02:00
printf ( " \n Warning, duplicate files were detected - END: \n " ) ;
}
2011-05-19 00:04:45 +02:00
}
if ( techtree_errors = = false ) {
printf ( " \n Validation found NO ERRORS for techPath [%s] techName [%s] factions checked (count = %d): \n " , techPath . c_str ( ) , techName . c_str ( ) , ( int ) factions . size ( ) ) ;
for ( set < string > : : iterator it = factions . begin ( ) ; it ! = factions . end ( ) ; + + it ) {
printf ( " Faction [%s] \n " , ( * it ) . c_str ( ) ) ;
}
}
}
printf ( " ---------------------------------------------------------------- " ) ;
}
}
2013-06-13 00:49:47 +02:00
void runTechTranslationExtractionForPath ( string techPath , string techName ,
const std : : vector < string > & filteredFactionList , World & world ) {
//Config &config = Config::getInstance();
vector < string > factionsList ;
findDirs ( techPath + techName + " /factions/ " , factionsList , false , false ) ;
if ( factionsList . empty ( ) = = false ) {
Checksum checksum ;
set < string > factions ;
for ( int j = 0 ; j < factionsList . size ( ) ; + + j ) {
if ( filteredFactionList . empty ( ) = = true | |
std : : find ( filteredFactionList . begin ( ) , filteredFactionList . end ( ) , factionsList [ j ] ) ! = filteredFactionList . end ( ) ) {
factions . insert ( factionsList [ j ] ) ;
}
}
printf ( " \n ---------------------------------------------------------------- " ) ;
printf ( " \n Checking techPath [%s] techName [%s] total faction count = %d \n " , techPath . c_str ( ) , techName . c_str ( ) , ( int ) factionsList . size ( ) ) ;
for ( int j = 0 ; j < factionsList . size ( ) ; + + j ) {
if ( filteredFactionList . empty ( ) = = true | |
std : : find ( filteredFactionList . begin ( ) , filteredFactionList . end ( ) , factionsList [ j ] ) ! = filteredFactionList . end ( ) ) {
printf ( " Using faction [%s] \n " , factionsList [ j ] . c_str ( ) ) ;
}
}
if ( factions . empty ( ) = = false ) {
bool techtree_errors = false ;
std : : map < string , vector < pair < string , string > > > loadedFileList ;
//vector<string> pathList = config.getPathListForType(ptTechs,"");
vector < string > pathList ;
pathList . push_back ( techPath ) ;
Config & config = Config : : getInstance ( ) ;
vector < string > otherTechPaths = config . getPathListForType ( ptTechs , " " ) ;
pathList . insert ( pathList . end ( ) , otherTechPaths . begin ( ) , otherTechPaths . end ( ) ) ;
world . loadTech ( pathList , techName , factions , & checksum , loadedFileList ) ;
const TechTree * techtree = world . getTechTree ( ) ;
string translationFile = techtree - > getPath ( ) ;
endPathWithSlash ( translationFile ) ;
translationFile + = " lang/ " + techName + " _default.lng " ;
if ( fileExists ( translationFile ) = = false ) {
string txFilePath = extractDirectoryPathFromFile ( translationFile ) ;
createDirectoryPaths ( txFilePath ) ;
# if defined(WIN32) && !defined(__MINGW32__)
FILE * fp = _wfopen ( utf8_decode ( translationFile ) . c_str ( ) , L " w " ) ;
std : : ofstream txFile ( fp ) ;
# else
std : : ofstream txFile ;
txFile . open ( translationFile . c_str ( ) , ios_base : : out | ios_base : : trunc ) ;
# endif
if ( txFile . is_open ( ) = = true ) {
txFile < < " TechTreeName= " < < techName < < std : : endl ;
txFile < < " ; -------------- " < < std : : endl ;
txFile < < " ; Types of Armor " < < std : : endl ;
for ( unsigned int index = 0 ; index < techtree - > getArmorTypeCount ( ) ; + + index ) {
const ArmorType * at = techtree - > getArmorTypeByIndex ( index ) ;
txFile < < " ArmorTypeName_ " < < at - > getName ( false ) < < " = " < < at - > getName ( false ) < < std : : endl ;
}
txFile < < " ; -------------- " < < std : : endl ;
txFile < < " ; Types of Attack " < < std : : endl ;
for ( unsigned int index = 0 ; index < techtree - > getAttackTypeCount ( ) ; + + index ) {
const AttackType * at = techtree - > getAttackTypeByIndex ( index ) ;
txFile < < " AttackTypeName_ " < < at - > getName ( false ) < < " = " < < at - > getName ( false ) < < std : : endl ;
}
txFile < < " ; ------------------ " < < std : : endl ;
txFile < < " ; Types of Resources " < < std : : endl ;
for ( unsigned int index = 0 ; index < techtree - > getResourceTypeCount ( ) ; + + index ) {
const ResourceType * rt = techtree - > getResourceType ( index ) ;
txFile < < " ResourceTypeName_ " < < rt - > getName ( false ) < < " = " < < rt - > getName ( false ) < < std : : endl ;
}
txFile < < " ; ----------------- " < < std : : endl ;
txFile < < " ; Types of Factions " < < std : : endl ;
for ( unsigned int index = 0 ; index < techtree - > getTypeCount ( ) ; + + index ) {
const FactionType * ft = techtree - > getType ( index ) ;
txFile < < " FactionName_ " < < ft - > getName ( false ) < < " = " < < ft - > getName ( false ) < < std : : endl ;
txFile < < " ; ---------------------------------- " < < std : : endl ;
txFile < < " ; Types of Upgrades for this Faction " < < std : : endl ;
for ( unsigned int upgradeIndex = 0 ; upgradeIndex < ft - > getUpgradeTypeCount ( ) ; + + upgradeIndex ) {
const UpgradeType * upt = ft - > getUpgradeType ( upgradeIndex ) ;
txFile < < " UpgradeTypeName_ " < < upt - > getName ( false ) < < " = " < < upt - > getName ( false ) < < std : : endl ;
}
txFile < < " ; ------------------------------- " < < std : : endl ;
txFile < < " ; Types of Units for this Faction " < < std : : endl ;
for ( unsigned int unitIndex = 0 ; unitIndex < ft - > getUnitTypeCount ( ) ; + + unitIndex ) {
const UnitType * ut = ft - > getUnitType ( unitIndex ) ;
txFile < < " UnitTypeName_ " < < ut - > getName ( false ) < < " = " < < ut - > getName ( false ) < < std : : endl ;
txFile < < " ; -------------------- " < < std : : endl ;
txFile < < " ; Levels for this Unit " < < std : : endl ;
for ( unsigned int levelIndex = 0 ; levelIndex < ut - > getLevelCount ( ) ; + + levelIndex ) {
const Level * level = ut - > getLevel ( levelIndex ) ;
txFile < < " LevelName_ " < < level - > getName ( false ) < < " = " < < level - > getName ( false ) < < std : : endl ;
}
txFile < < " ; ------------------------------- " < < std : : endl ;
txFile < < " ; Types of Commands for this Unit " < < std : : endl ;
for ( unsigned int commandIndex = 0 ; commandIndex < ut - > getCommandTypeCount ( ) ; + + commandIndex ) {
const CommandType * ct = ut - > getCommandType ( commandIndex ) ;
txFile < < " CommandName_ " < < ct - > getName ( false ) < < " = " < < ct - > getName ( false ) < < std : : endl ;
}
}
}
}
txFile . close ( ) ;
# if defined(WIN32) && !defined(__MINGW32__)
if ( fp ) {
fclose ( fp ) ;
}
# endif
}
else {
printf ( " \n ** Cannot product techtree translation file [%s] for techPath [%s] techName [%s] because the file already exists! \n " , translationFile . c_str ( ) , techPath . c_str ( ) , techName . c_str ( ) ) ;
}
}
printf ( " ---------------------------------------------------------------- " ) ;
}
}
void runTechTranslationExtraction ( int argc , char * * argv ) {
//disableBacktrace=true;
printf ( " ====== Started Translation Extraction ====== \n " ) ;
bool purgeDuplicateFiles = false ;
bool showDuplicateFiles = true ;
bool purgeUnusedFiles = false ;
bool svnPurgeFiles = false ;
double purgedMegaBytes = 0 ;
Config & config = Config : : getInstance ( ) ;
// Did the user pass a specific list of factions to validate?
std : : vector < string > filteredFactionList ;
vector < string > results ;
findDirs ( config . getPathListForType ( ptTechs ) , results ) ;
vector < string > techTreeFiles = results ;
// Did the user pass a specific list of techtrees to validate?
std : : vector < string > filteredTechTreeList ;
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_TRANSLATE_TECHTREES ] ) + string ( " = " ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_TRANSLATE_TECHTREES ] ) + string ( " = " ) , & foundParamIndIndex ) ;
string filterList = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( filterList , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 ) {
string techtreeList = paramPartTokens [ 1 ] ;
Tokenize ( techtreeList , filteredTechTreeList , " , " ) ;
if ( filteredTechTreeList . empty ( ) = = false ) {
printf ( " Filtering techtrees and only looking for the following: \n " ) ;
for ( int idx = 0 ; idx < filteredTechTreeList . size ( ) ; + + idx ) {
filteredTechTreeList [ idx ] = trim ( filteredTechTreeList [ idx ] ) ;
printf ( " %s \n " , filteredTechTreeList [ idx ] . c_str ( ) ) ;
}
}
// if(paramPartTokens.size() >= 3) {
// if(paramPartTokens[2] == "purgeunused") {
// purgeUnusedFiles = true;
// printf("*NOTE All unused techtree files will be deleted!\n");
// }
// else if(paramPartTokens[2] == "purgeduplicates") {
// purgeDuplicateFiles = true;
// printf("*NOTE All duplicate techtree files will be merged!\n");
// }
// else if(paramPartTokens[2] == "svndelete") {
// svnPurgeFiles = true;
// printf("*NOTE All unused / duplicate techtree files will be removed from svn!\n");
// }
// else if(paramPartTokens[2] == "hideduplicates") {
// showDuplicateFiles = false;
// printf("*NOTE All duplicate techtree files will NOT be shown!\n");
// }
// }
// if(paramPartTokens.size() >= 4) {
// if(paramPartTokens[3] == "purgeunused") {
// purgeUnusedFiles = true;
// printf("*NOTE All unused techtree files will be deleted!\n");
// }
// else if(paramPartTokens[3] == "purgeduplicates") {
// purgeDuplicateFiles = true;
// printf("*NOTE All duplicate techtree files will be merged!\n");
// }
// else if(paramPartTokens[3] == "svndelete") {
// svnPurgeFiles = true;
// printf("*NOTE All unused / duplicate techtree files will be removed from svn!\n");
// }
// else if(paramPartTokens[3] == "hideduplicates") {
// showDuplicateFiles = false;
// printf("*NOTE All duplicate techtree files will NOT be shown!\n");
// }
// }
// if(paramPartTokens.size() >= 5) {
// if(paramPartTokens[4] == "purgeunused") {
// purgeUnusedFiles = true;
// printf("*NOTE All unused techtree files will be deleted!\n");
// }
// else if(paramPartTokens[4] == "purgeduplicates") {
// purgeDuplicateFiles = true;
// printf("*NOTE All duplicate techtree files will be merged!\n");
// }
// else if(paramPartTokens[4] == "svndelete") {
// svnPurgeFiles = true;
// printf("*NOTE All unused / duplicate techtree files will be removed from svn!\n");
// }
// else if(paramPartTokens[4] == "hideduplicates") {
// showDuplicateFiles = false;
// printf("*NOTE All duplicate techtree files will NOT be shown!\n");
// }
// }
}
}
{
printf ( " \n ---------------- Loading factions inside world ---------------- " ) ;
World world ;
vector < string > techPaths = config . getPathListForType ( ptTechs ) ;
for ( int idx = 0 ; idx < techPaths . size ( ) ; idx + + ) {
string & techPath = techPaths [ idx ] ;
endPathWithSlash ( techPath ) ;
//printf("techPath [%s]\n",techPath.c_str());
for ( int idx2 = 0 ; idx2 < techTreeFiles . size ( ) ; idx2 + + ) {
string & techName = techTreeFiles [ idx2 ] ;
if ( filteredTechTreeList . empty ( ) = = true | |
std : : find ( filteredTechTreeList . begin ( ) , filteredTechTreeList . end ( ) , techName ) ! = filteredTechTreeList . end ( ) ) {
runTechTranslationExtractionForPath ( techPath , techName ,
filteredFactionList , world ) ;
}
}
}
printf ( " \n ====== Finished Translation ====== \n " ) ;
}
}
2011-05-19 00:04:45 +02:00
void runTechValidationReport ( int argc , char * * argv ) {
//disableBacktrace=true;
printf ( " ====== Started Validation ====== \n " ) ;
bool purgeDuplicateFiles = false ;
2011-07-09 21:28:01 +02:00
bool showDuplicateFiles = true ;
2011-05-19 00:04:45 +02:00
bool purgeUnusedFiles = false ;
bool svnPurgeFiles = false ;
double purgedMegaBytes = 0 ;
Config & config = Config : : getInstance ( ) ;
// Did the user pass a specific scenario to validate?
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_SCENARIO ] ) + string ( " = " ) ) = = true ) {
2012-10-06 09:06:40 +02:00
2011-05-19 00:04:45 +02:00
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_SCENARIO ] ) + string ( " = " ) , & foundParamIndIndex ) ;
string filterList = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( filterList , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 ) {
2012-10-06 09:06:40 +02:00
//vector<string> optionList;
2011-05-19 00:04:45 +02:00
string validateScenarioName = paramPartTokens [ 1 ] ;
printf ( " Filtering scenario: %s \n " , validateScenarioName . c_str ( ) ) ;
if ( paramPartTokens . size ( ) > = 3 ) {
if ( paramPartTokens [ 2 ] = = " purgeunused " ) {
purgeUnusedFiles = true ;
printf ( " *NOTE All unused scenario files will be deleted! \n " ) ;
}
}
{
printf ( " \n ---------------- Loading scenario inside world ---------------- \n " ) ;
2012-06-22 03:48:31 +02:00
bool scenarioFound = false ;
2011-05-19 00:04:45 +02:00
World world ;
2012-10-06 09:06:40 +02:00
//double purgedMegaBytes=0;
2011-05-19 00:04:45 +02:00
std : : vector < string > filteredFactionList ;
vector < string > scenarioPaths = config . getPathListForType ( ptScenarios ) ;
for ( int idx = 0 ; idx < scenarioPaths . size ( ) ; idx + + ) {
string & scenarioPath = scenarioPaths [ idx ] ;
endPathWithSlash ( scenarioPath ) ;
//printf("techPath [%s]\n",techPath.c_str());
vector < string > scenarioList ;
findDirs ( scenarioPath , scenarioList , false , false ) ;
for ( int idx2 = 0 ; idx2 < scenarioList . size ( ) ; idx2 + + ) {
string & scenarioName = scenarioList [ idx2 ] ;
2012-06-22 03:48:31 +02:00
//printf("Comparing Scenario [%s] looking for [%s]\n",scenarioName.c_str(),validateScenarioName.c_str());
2011-05-19 00:04:45 +02:00
if ( scenarioName = = validateScenarioName ) {
2012-06-22 03:48:31 +02:00
scenarioFound = true ;
2011-05-19 00:04:45 +02:00
string file = scenarioPath + scenarioName + " / " + scenarioName + " .xml " ;
XmlTree xmlTree ;
xmlTree . load ( file , Properties : : getTagReplacementValues ( ) ) ;
const XmlNode * scenarioNode = xmlTree . getRootNode ( ) ;
string techName = scenarioNode - > getChild ( " tech-tree " ) - > getAttribute ( " value " ) - > getValue ( ) ;
// Self Contained techtree?
string scenarioTechtree = scenarioPath + scenarioName + " / " + techName + " / " + techName + " .xml " ;
2012-06-22 03:48:31 +02:00
printf ( " \n Found Scenario [%s] looking for techtree [%s]... \n " , scenarioName . c_str ( ) , scenarioTechtree . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
if ( fileExists ( scenarioTechtree ) = = true ) {
string techPath = scenarioPath + scenarioName + " / " ;
2012-06-22 03:48:31 +02:00
printf ( " \n Found Scenario [%s] with custom techtree [%s] validating... \n " , scenarioName . c_str ( ) , techName . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
runTechValidationForPath ( techPath , techName , filteredFactionList ,
2011-07-09 21:28:01 +02:00
world , purgeUnusedFiles , showDuplicateFiles , false , false , purgedMegaBytes ) ;
2011-05-19 00:04:45 +02:00
}
2012-06-22 03:48:31 +02:00
else {
vector < string > techPaths = config . getPathListForType ( ptTechs ) ;
for ( int idx = 0 ; idx < techPaths . size ( ) ; idx + + ) {
string & techPath = techPaths [ idx ] ;
endPathWithSlash ( techPath ) ;
//printf("techPath [%s]\n",techPath.c_str());
//string techPath = scenarioPath + scenarioName + "/";
scenarioTechtree = techPath + " / " + techName + " / " + techName + " .xml " ;
if ( fileExists ( scenarioTechtree ) = = true ) {
printf ( " \n Found Scenario [%s] with techtree [%s] validating... \n " , scenarioName . c_str ( ) , techName . c_str ( ) ) ;
runTechValidationForPath ( techPath , techName , filteredFactionList ,
world , purgeUnusedFiles , showDuplicateFiles , false , false , purgedMegaBytes ) ;
break ;
}
}
}
2011-05-19 00:04:45 +02:00
//
//
// runTechValidationForPath(techPath, techName, filteredFactionList,
// world, purgeUnusedFiles,purgedMegaBytes);
}
}
}
2012-06-22 03:48:31 +02:00
if ( scenarioFound = = false ) {
printf ( " \n WARNING, the scenario [%s] was NOT FOUND! \n " , validateScenarioName . c_str ( ) ) ;
}
2011-05-19 00:04:45 +02:00
printf ( " \n ====== Finished Validation ====== \n " ) ;
}
return ;
}
else {
printf ( " \n Invalid missing scenario specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
return ;
}
}
// Did the user pass a specific list of factions to validate?
std : : vector < string > filteredFactionList ;
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) + string ( " = " ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
string filterList = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( filterList , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 ) {
string factionList = paramPartTokens [ 1 ] ;
Tokenize ( factionList , filteredFactionList , " , " ) ;
2011-09-01 01:10:43 +02:00
if ( filteredFactionList . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
printf ( " Filtering factions and only looking for the following: \n " ) ;
for ( int idx = 0 ; idx < filteredFactionList . size ( ) ; + + idx ) {
filteredFactionList [ idx ] = trim ( filteredFactionList [ idx ] ) ;
printf ( " %s \n " , filteredFactionList [ idx ] . c_str ( ) ) ;
}
}
if ( paramPartTokens . size ( ) > = 3 ) {
if ( paramPartTokens [ 2 ] = = " purgeunused " ) {
purgeUnusedFiles = true ;
printf ( " *NOTE All unused faction files will be deleted! \n " ) ;
}
}
}
}
vector < string > results ;
findDirs ( config . getPathListForType ( ptTechs ) , results ) ;
vector < string > techTreeFiles = results ;
// Did the user pass a specific list of techtrees to validate?
std : : vector < string > filteredTechTreeList ;
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) + string ( " = " ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) + string ( " = " ) , & foundParamIndIndex ) ;
string filterList = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( filterList , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 ) {
string techtreeList = paramPartTokens [ 1 ] ;
Tokenize ( techtreeList , filteredTechTreeList , " , " ) ;
2011-09-01 01:10:43 +02:00
if ( filteredTechTreeList . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
printf ( " Filtering techtrees and only looking for the following: \n " ) ;
for ( int idx = 0 ; idx < filteredTechTreeList . size ( ) ; + + idx ) {
filteredTechTreeList [ idx ] = trim ( filteredTechTreeList [ idx ] ) ;
printf ( " %s \n " , filteredTechTreeList [ idx ] . c_str ( ) ) ;
}
}
if ( paramPartTokens . size ( ) > = 3 ) {
if ( paramPartTokens [ 2 ] = = " purgeunused " ) {
purgeUnusedFiles = true ;
printf ( " *NOTE All unused techtree files will be deleted! \n " ) ;
}
else if ( paramPartTokens [ 2 ] = = " purgeduplicates " ) {
purgeDuplicateFiles = true ;
printf ( " *NOTE All duplicate techtree files will be merged! \n " ) ;
}
else if ( paramPartTokens [ 2 ] = = " svndelete " ) {
svnPurgeFiles = true ;
printf ( " *NOTE All unused / duplicate techtree files will be removed from svn! \n " ) ;
}
2011-07-09 21:28:01 +02:00
else if ( paramPartTokens [ 2 ] = = " hideduplicates " ) {
showDuplicateFiles = false ;
printf ( " *NOTE All duplicate techtree files will NOT be shown! \n " ) ;
}
2011-05-19 00:04:45 +02:00
}
if ( paramPartTokens . size ( ) > = 4 ) {
if ( paramPartTokens [ 3 ] = = " purgeunused " ) {
purgeUnusedFiles = true ;
printf ( " *NOTE All unused techtree files will be deleted! \n " ) ;
}
else if ( paramPartTokens [ 3 ] = = " purgeduplicates " ) {
purgeDuplicateFiles = true ;
printf ( " *NOTE All duplicate techtree files will be merged! \n " ) ;
}
else if ( paramPartTokens [ 3 ] = = " svndelete " ) {
svnPurgeFiles = true ;
printf ( " *NOTE All unused / duplicate techtree files will be removed from svn! \n " ) ;
}
2011-07-09 21:28:01 +02:00
else if ( paramPartTokens [ 3 ] = = " hideduplicates " ) {
showDuplicateFiles = false ;
printf ( " *NOTE All duplicate techtree files will NOT be shown! \n " ) ;
}
2011-05-19 00:04:45 +02:00
}
if ( paramPartTokens . size ( ) > = 5 ) {
if ( paramPartTokens [ 4 ] = = " purgeunused " ) {
purgeUnusedFiles = true ;
printf ( " *NOTE All unused techtree files will be deleted! \n " ) ;
}
else if ( paramPartTokens [ 4 ] = = " purgeduplicates " ) {
purgeDuplicateFiles = true ;
printf ( " *NOTE All duplicate techtree files will be merged! \n " ) ;
}
else if ( paramPartTokens [ 4 ] = = " svndelete " ) {
svnPurgeFiles = true ;
printf ( " *NOTE All unused / duplicate techtree files will be removed from svn! \n " ) ;
}
2011-07-09 21:28:01 +02:00
else if ( paramPartTokens [ 4 ] = = " hideduplicates " ) {
showDuplicateFiles = false ;
printf ( " *NOTE All duplicate techtree files will NOT be shown! \n " ) ;
}
2011-05-19 00:04:45 +02:00
}
}
}
{
printf ( " \n ---------------- Loading factions inside world ---------------- " ) ;
World world ;
vector < string > techPaths = config . getPathListForType ( ptTechs ) ;
for ( int idx = 0 ; idx < techPaths . size ( ) ; idx + + ) {
string & techPath = techPaths [ idx ] ;
endPathWithSlash ( techPath ) ;
//printf("techPath [%s]\n",techPath.c_str());
for ( int idx2 = 0 ; idx2 < techTreeFiles . size ( ) ; idx2 + + ) {
string & techName = techTreeFiles [ idx2 ] ;
2011-09-01 20:08:56 +02:00
if ( filteredTechTreeList . empty ( ) = = true | |
2011-05-19 00:04:45 +02:00
std : : find ( filteredTechTreeList . begin ( ) , filteredTechTreeList . end ( ) , techName ) ! = filteredTechTreeList . end ( ) ) {
runTechValidationForPath ( techPath , techName , filteredFactionList ,
2011-07-09 21:28:01 +02:00
world , purgeUnusedFiles , purgeDuplicateFiles ,
showDuplicateFiles , svnPurgeFiles , purgedMegaBytes ) ;
2011-05-19 00:04:45 +02:00
}
}
}
printf ( " \n ====== Finished Validation ====== \n " ) ;
}
}
2012-04-03 21:35:22 +02:00
void runTilesetValidationReport ( int argc , char * * argv ) {
//disableBacktrace=true;
printf ( " ====== Started Validation ====== \n " ) ;
2012-04-16 21:29:37 +02:00
//double purgedMegaBytes=0;
2012-04-03 21:35:22 +02:00
Config & config = Config : : getInstance ( ) ;
// Did the user pass a specific tileset to validate?
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_TILESET ] ) + string ( " = " ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_VALIDATE_TILESET ] ) + string ( " = " ) , & foundParamIndIndex ) ;
string filterList = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( filterList , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 ) {
2012-10-06 09:06:40 +02:00
//vector<string> optionList;
2012-04-03 21:35:22 +02:00
string validateTilesetName = paramPartTokens [ 1 ] ;
printf ( " Filtering tileset: %s \n " , validateTilesetName . c_str ( ) ) ;
2012-10-06 09:06:40 +02:00
bool purgeUnusedFiles = false ;
2012-04-03 21:35:22 +02:00
if ( paramPartTokens . size ( ) > = 3 ) {
if ( paramPartTokens [ 2 ] = = " purgeunused " ) {
purgeUnusedFiles = true ;
printf ( " *NOTE All unused tileset files will be deleted! \n " ) ;
}
}
{
printf ( " \n ---------------- Loading tileset inside world ---------------- \n " ) ;
World world ;
double purgedMegaBytes = 0 ;
2012-10-06 09:06:40 +02:00
bool showDuplicateFiles = true ;
//std::vector<string> filteredFactionList;
2012-04-03 21:35:22 +02:00
vector < string > tilesetPaths = config . getPathListForType ( ptTilesets ) ;
for ( int idx = 0 ; idx < tilesetPaths . size ( ) ; idx + + ) {
string & tilesetPath = tilesetPaths [ idx ] ;
endPathWithSlash ( tilesetPath ) ;
vector < string > tilesetList ;
findDirs ( tilesetPath , tilesetList , false , false ) ;
for ( int idx2 = 0 ; idx2 < tilesetList . size ( ) ; idx2 + + ) {
string & tilesetName = tilesetList [ idx2 ] ;
if ( tilesetName = = validateTilesetName ) {
runTilesetValidationForPath ( tilesetPath , tilesetName ,
world , purgeUnusedFiles , showDuplicateFiles ,
false , false , purgedMegaBytes ) ;
}
}
}
printf ( " \n ====== Finished Validation ====== \n " ) ;
}
return ;
}
else {
printf ( " \n Invalid missing tileset specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
return ;
}
}
else {
printf ( " \n Invalid missing tileset specified on commandline \n \n " ) ;
return ;
}
}
2011-05-19 00:04:45 +02:00
void ShowINISettings ( int argc , char * * argv , Config & config , Config & configKeys ) {
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SHOW_INI_SETTINGS ] ) = = true ) {
vector < string > filteredPropertyList ;
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_INI_SETTINGS ] ) + string ( " = " ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_INI_SETTINGS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
string filterList = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( filterList , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 ) {
string tokenList = paramPartTokens [ 1 ] ;
Tokenize ( tokenList , filteredPropertyList , " , " ) ;
2011-09-01 01:10:43 +02:00
if ( filteredPropertyList . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
printf ( " Filtering properties and only looking for the following: \n " ) ;
for ( int idx = 0 ; idx < filteredPropertyList . size ( ) ; + + idx ) {
filteredPropertyList [ idx ] = trim ( filteredPropertyList [ idx ] ) ;
printf ( " %s \n " , filteredPropertyList [ idx ] . c_str ( ) ) ;
}
}
}
}
printf ( " \n Main settings report \n " ) ;
printf ( " ==================== \n " ) ;
vector < pair < string , string > > mergedMainSettings = config . getMergedProperties ( ) ;
vector < pair < string , string > > mergedKeySettings = configKeys . getMergedProperties ( ) ;
// Figure out the max # of tabs we need to format display nicely
int tabCount = 1 ;
for ( int i = 0 ; i < mergedMainSettings . size ( ) ; + + i ) {
const pair < string , string > & nameValue = mergedMainSettings [ i ] ;
bool displayProperty = false ;
2011-09-01 01:10:43 +02:00
if ( filteredPropertyList . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
if ( find ( filteredPropertyList . begin ( ) , filteredPropertyList . end ( ) , nameValue . first ) ! = filteredPropertyList . end ( ) ) {
displayProperty = true ;
}
}
else {
displayProperty = true ;
}
if ( displayProperty = = true ) {
int requredTabs = ( nameValue . first . length ( ) / 8 ) + 1 ;
if ( nameValue . first . length ( ) % 8 ) {
requredTabs + + ;
}
if ( requredTabs > tabCount ) {
tabCount = requredTabs ;
}
}
}
for ( int i = 0 ; i < mergedKeySettings . size ( ) ; + + i ) {
const pair < string , string > & nameValue = mergedKeySettings [ i ] ;
bool displayProperty = false ;
2011-09-01 01:10:43 +02:00
if ( filteredPropertyList . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
if ( find ( filteredPropertyList . begin ( ) , filteredPropertyList . end ( ) , nameValue . first ) ! = filteredPropertyList . end ( ) ) {
displayProperty = true ;
}
}
else {
displayProperty = true ;
}
if ( displayProperty = = true ) {
int requredTabs = ( nameValue . first . length ( ) / 8 ) + 1 ;
if ( nameValue . first . length ( ) % 8 ) {
requredTabs + + ;
}
if ( requredTabs > tabCount ) {
tabCount = requredTabs ;
}
}
}
// Output the properties
for ( int i = 0 ; i < mergedMainSettings . size ( ) ; + + i ) {
const pair < string , string > & nameValue = mergedMainSettings [ i ] ;
bool displayProperty = false ;
2011-09-01 01:10:43 +02:00
if ( filteredPropertyList . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
if ( find ( filteredPropertyList . begin ( ) , filteredPropertyList . end ( ) , nameValue . first ) ! = filteredPropertyList . end ( ) ) {
displayProperty = true ;
}
}
else {
displayProperty = true ;
}
if ( displayProperty = = true ) {
printf ( " Property Name [%s] " , nameValue . first . c_str ( ) ) ;
int tabs = ( nameValue . first . length ( ) / 8 ) + 1 ;
for ( int j = 0 ; j < ( tabCount - tabs ) ; + + j ) {
printf ( " \t " ) ;
}
2012-10-22 22:05:42 +02:00
string displayValue = nameValue . second ;
if ( nameValue . first = = " TranslationGetURLPassword " ) {
displayValue = " ***** " ;
}
printf ( " Value [%s] \n " , displayValue . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
}
}
printf ( " \n \n Main key binding settings report \n " ) ;
printf ( " ==================================== \n " ) ;
for ( int i = 0 ; i < mergedKeySettings . size ( ) ; + + i ) {
const pair < string , string > & nameValue = mergedKeySettings [ i ] ;
bool displayProperty = false ;
2011-09-01 01:10:43 +02:00
if ( filteredPropertyList . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
if ( find ( filteredPropertyList . begin ( ) , filteredPropertyList . end ( ) , nameValue . first ) ! = filteredPropertyList . end ( ) ) {
displayProperty = true ;
}
}
else {
displayProperty = true ;
}
if ( displayProperty = = true ) {
printf ( " Property Name [%s] " , nameValue . first . c_str ( ) ) ;
int tabs = ( nameValue . first . length ( ) / 8 ) + 1 ;
for ( int j = 0 ; j < ( tabCount - tabs ) ; + + j ) {
printf ( " \t " ) ;
}
printf ( " Value [%s] \n " , nameValue . second . c_str ( ) ) ;
}
}
}
}
void CheckForDuplicateData ( ) {
Config & config = Config : : getInstance ( ) ;
string duplicateWarnings = " " ;
{
2012-10-06 09:06:40 +02:00
//vector<string> results;
2011-12-05 06:26:48 +01:00
string scenarioDir = " " ;
vector < string > pathList = config . getPathListForType ( ptMaps , scenarioDir ) ;
vector < string > invalidMapList ;
vector < string > maps = MapPreview : : findAllValidMaps ( pathList , scenarioDir , false , true , & invalidMapList ) ;
std : : sort ( maps . begin ( ) , maps . end ( ) ) ;
if ( maps . empty ( ) = = true ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " No maps were found! " ) ;
2011-12-05 06:26:48 +01:00
}
2012-03-28 08:25:57 +02:00
else if ( invalidMapList . empty ( ) = = false ) {
2011-12-05 06:26:48 +01:00
string errorMsg = " Warning invalid maps were detected (will be ignored): \n " ;
for ( int i = 0 ; i < invalidMapList . size ( ) ; + + i ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " map [%s] \n " , invalidMapList [ i ] . c_str ( ) ) ;
2011-12-05 06:26:48 +01:00
errorMsg + = szBuf ;
}
duplicateWarnings + = errorMsg ;
}
2011-05-19 00:04:45 +02:00
vector < string > duplicateMapsToRename ;
for ( int i = 0 ; i < maps . size ( ) ; + + i ) {
string map1 = maps [ i ] ;
for ( int j = 0 ; j < maps . size ( ) ; + + j ) {
if ( i ! = j ) {
string map2 = maps [ j ] ;
//printf("i = %d map1 [%s] j = %d map2 [%s]\n",i,map1.c_str(),j,map2.c_str());
if ( map1 = = map2 ) {
if ( std : : find ( duplicateMapsToRename . begin ( ) , duplicateMapsToRename . end ( ) , map1 ) = = duplicateMapsToRename . end ( ) ) {
duplicateMapsToRename . push_back ( map1 ) ;
}
}
}
}
}
2011-09-01 01:10:43 +02:00
if ( duplicateMapsToRename . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
string errorMsg = " Warning duplicate maps were detected and renamed: \n " ;
for ( int i = 0 ; i < duplicateMapsToRename . size ( ) ; + + i ) {
2011-12-05 06:26:48 +01:00
string currentPath = pathList [ 1 ] ;
2011-05-19 00:04:45 +02:00
endPathWithSlash ( currentPath ) ;
string oldFile = currentPath + duplicateMapsToRename [ i ] ;
string newFile = currentPath + duplicateMapsToRename [ i ] ;
string ext = extractExtension ( newFile ) ;
newFile = newFile . substr ( 0 , newFile . length ( ) - ext . length ( ) - 1 ) ;
newFile = newFile + " _custom. " + ext ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2011-05-19 00:04:45 +02:00
int result = rename ( oldFile . c_str ( ) , newFile . c_str ( ) ) ;
if ( result ! = 0 ) {
char * errmsg = strerror ( errno ) ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Error [%s] \n Could not rename [%s] to [%s]! " , errmsg , oldFile . c_str ( ) , newFile . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-05-19 00:04:45 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " map [%s] in [%s] \n was renamed to [%s] " , duplicateMapsToRename [ i ] . c_str ( ) , oldFile . c_str ( ) , newFile . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
}
errorMsg + = szBuf ;
}
duplicateWarnings + = errorMsg ;
}
}
{
//tilesets
std : : vector < std : : string > tileSets ;
vector < string > tilesetPaths = config . getPathListForType ( ptTilesets ) ;
findDirs ( tilesetPaths , tileSets , false , true ) ;
if ( tileSets . empty ( ) ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " No tilesets were found! " ) ;
2011-05-19 00:04:45 +02:00
}
vector < string > duplicateTilesetsToRename ;
for ( int i = 0 ; i < tileSets . size ( ) ; + + i ) {
string tileSet1 = tileSets [ i ] ;
for ( int j = 0 ; j < tileSets . size ( ) ; + + j ) {
if ( i ! = j ) {
string tileSet2 = tileSets [ j ] ;
if ( tileSet1 = = tileSet2 ) {
if ( std : : find ( duplicateTilesetsToRename . begin ( ) , duplicateTilesetsToRename . end ( ) , tileSet1 ) = = duplicateTilesetsToRename . end ( ) ) {
duplicateTilesetsToRename . push_back ( tileSet1 ) ;
}
}
}
}
}
2011-09-01 01:10:43 +02:00
if ( duplicateTilesetsToRename . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
string errorMsg = " Warning duplicate tilesets were detected and renamed: \n " ;
for ( int i = 0 ; i < duplicateTilesetsToRename . size ( ) ; + + i ) {
string currentPath = tilesetPaths [ 1 ] ;
endPathWithSlash ( currentPath ) ;
string oldFile = currentPath + duplicateTilesetsToRename [ i ] ;
string newFile = currentPath + duplicateTilesetsToRename [ i ] ;
newFile = newFile + " _custom " ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2011-05-19 00:04:45 +02:00
int result = rename ( oldFile . c_str ( ) , newFile . c_str ( ) ) ;
if ( result ! = 0 ) {
char * errmsg = strerror ( errno ) ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Error [%s] \n Could not rename [%s] to [%s]! " , errmsg , oldFile . c_str ( ) , newFile . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-05-19 00:04:45 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " tileset [%s] in [%s] \n was renamed to [%s] " , duplicateTilesetsToRename [ i ] . c_str ( ) , oldFile . c_str ( ) , newFile . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
string tilesetName = extractFileFromDirectoryPath ( oldFile ) ;
oldFile = newFile + " / " + tilesetName + " .xml " ;
newFile = newFile + " / " + tilesetName + " _custom.xml " ;
//printf("\n\n\n###### RENAME [%s] to [%s]\n\n",oldFile.c_str(),newFile.c_str());
2011-09-01 01:10:43 +02:00
rename ( oldFile . c_str ( ) , newFile . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
}
errorMsg + = szBuf ;
}
duplicateWarnings + = errorMsg ;
}
}
{
vector < string > techPaths = config . getPathListForType ( ptTechs ) ;
vector < string > techTrees ;
findDirs ( techPaths , techTrees , false , true ) ;
if ( techTrees . empty ( ) ) {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " No tech-trees were found! " ) ;
2011-05-19 00:04:45 +02:00
}
vector < string > duplicateTechtreesToRename ;
for ( int i = 0 ; i < techTrees . size ( ) ; + + i ) {
string techtree1 = techTrees [ i ] ;
for ( int j = 0 ; j < techTrees . size ( ) ; + + j ) {
if ( i ! = j ) {
string techtree2 = techTrees [ j ] ;
if ( techtree1 = = techtree2 ) {
if ( std : : find ( duplicateTechtreesToRename . begin ( ) , duplicateTechtreesToRename . end ( ) , techtree1 ) = = duplicateTechtreesToRename . end ( ) ) {
duplicateTechtreesToRename . push_back ( techtree1 ) ;
}
}
}
}
}
2011-09-01 01:10:43 +02:00
if ( duplicateTechtreesToRename . empty ( ) = = false ) {
2011-05-19 00:04:45 +02:00
string errorMsg = " Warning duplicate techtrees were detected and renamed: \n " ;
for ( int i = 0 ; i < duplicateTechtreesToRename . size ( ) ; + + i ) {
string currentPath = techPaths [ 1 ] ;
endPathWithSlash ( currentPath ) ;
string oldFile = currentPath + duplicateTechtreesToRename [ i ] ;
string newFile = currentPath + duplicateTechtreesToRename [ i ] ;
newFile = newFile + " _custom " ;
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
2011-05-19 00:04:45 +02:00
int result = rename ( oldFile . c_str ( ) , newFile . c_str ( ) ) ;
if ( result ! = 0 ) {
char * errmsg = strerror ( errno ) ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " Error [%s] \n Could not rename [%s] to [%s]! " , errmsg , oldFile . c_str ( ) , newFile . c_str ( ) ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2011-05-19 00:04:45 +02:00
}
else {
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " techtree [%s] in [%s] \n was renamed to [%s] " , duplicateTechtreesToRename [ i ] . c_str ( ) , oldFile . c_str ( ) , newFile . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
string tilesetName = extractFileFromDirectoryPath ( oldFile ) ;
oldFile = newFile + " / " + tilesetName + " .xml " ;
newFile = newFile + " / " + tilesetName + " _custom.xml " ;
//printf("\n\n\n###### RENAME [%s] to [%s]\n\n",oldFile.c_str(),newFile.c_str());
2011-09-01 01:10:43 +02:00
rename ( oldFile . c_str ( ) , newFile . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
}
errorMsg + = szBuf ;
}
duplicateWarnings + = errorMsg ;
}
}
if ( duplicateWarnings ! = " " ) {
2012-03-28 00:44:16 +02:00
if ( mainProgram ) {
mainProgram - > getState ( ) - > setForceMouseRender ( true ) ;
2011-05-19 00:04:45 +02:00
}
ExceptionHandler : : DisplayMessage ( duplicateWarnings . c_str ( ) , false ) ;
}
}
int glestMain ( int argc , char * * argv ) {
# ifdef SL_LEAK_DUMP
2012-04-14 23:21:09 +02:00
//AllocInfo::set_application_binary(executable_path(argv[0],true));
string & app = AllocInfo : : get_application_binary ( ) ;
app = executable_path ( argv [ 0 ] , true ) ;
//want_full_leak_stacktrace = true;
//want_full_leak_stacktrace_line_numbers = true;
2011-05-19 00:04:45 +02:00
# endif
2012-04-14 23:21:09 +02:00
// printf("START ALLOC char 200\n");
//char *ptr = new char[200];
// printf("END ALLOC char 200\n");
// return -1;
2012-05-14 09:28:34 +02:00
SystemFlags : : VERBOSE_MODE_ENABLED = false ;
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VERBOSE_MODE ] ) = = true ) {
SystemFlags : : VERBOSE_MODE_ENABLED = true ;
}
2012-04-14 23:21:09 +02:00
2012-05-14 09:28:34 +02:00
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_MASTERSERVER_MODE ] ) ) = = true ) {
//isMasterServerModeEnabled = true;
//Window::setMasterserverMode(isMasterServerModeEnabled);
GlobalStaticFlags : : setIsNonGraphicalModeEnabled ( true ) ;
2012-05-14 05:36:43 +02:00
2012-05-14 09:28:34 +02:00
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_MASTERSERVER_MODE ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_MASTERSERVER_MODE ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string headless_command_list = paramPartTokens [ 1 ] ;
vector < string > paramHeadlessCommandList ;
Tokenize ( headless_command_list , paramHeadlessCommandList , " , " ) ;
for ( unsigned int i = 0 ; i < paramHeadlessCommandList . size ( ) ; + + i ) {
string headless_command = paramHeadlessCommandList [ i ] ;
if ( headless_command = = " exit " ) {
printf ( " Forcing quit after game has completed [%s] \n " , headless_command . c_str ( ) ) ;
Program : : setWantShutdownApplicationAfterGame ( true ) ;
2012-05-14 05:36:43 +02:00
}
2012-05-14 09:28:34 +02:00
else if ( headless_command = = " vps " ) {
printf ( " Disabled reading from console [%s] \n " , headless_command . c_str ( ) ) ;
disableheadless_console = true ;
2012-05-14 05:36:43 +02:00
}
2012-11-09 22:50:01 +01:00
else if ( headless_command = = " lan " ) {
printf ( " Forcing local LAN mode [%s] \n " , headless_command . c_str ( ) ) ;
GlobalStaticFlags : : setFlag ( gsft_lan_mode ) ;
}
2012-05-14 05:36:43 +02:00
}
}
2012-05-14 09:28:34 +02:00
}
2012-05-14 05:36:43 +02:00
2012-04-14 23:21:09 +02:00
PlatformExceptionHandler : : application_binary = executable_path ( argv [ 0 ] , true ) ;
2011-05-19 00:04:45 +02:00
mg_app_name = GameConstants : : application_name ;
mailStringSupport = mailString ;
SystemFlags : : ENABLE_THREADED_LOGGING = false ;
disableBacktrace = false ;
bool foundInvalidArgs = false ;
preCacheThread = NULL ;
Properties : : setApplicationPath ( executable_path ( argv [ 0 ] ) ) ;
2011-11-02 18:17:28 +01:00
Properties : : setGameVersion ( glestVersionString ) ;
2011-05-19 00:04:45 +02:00
ServerSocket : : setMaxPlayerCount ( GameConstants : : maxPlayers ) ;
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_DISABLE_BACKTRACE ] ) = = true ) {
disableBacktrace = true ;
}
2012-07-03 02:19:23 +02:00
PlatformExceptionHandler : : disableBacktrace = disableBacktrace ;
2011-05-19 00:04:45 +02:00
# if defined(CUSTOM_DATA_INSTALL_PATH)
2012-01-24 08:39:16 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " \n \n CUSTOM_DATA_INSTALL_PATH = [%s] \n \n " , formatPath ( TOSTRING ( CUSTOM_DATA_INSTALL_PATH ) ) . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
# endif
const int knownArgCount = sizeof ( GAME_ARGS ) / sizeof ( GAME_ARGS [ 0 ] ) ;
for ( int idx = 1 ; idx < argc ; + + idx ) {
if ( hasCommandArgument ( knownArgCount , ( char * * ) & GAME_ARGS [ 0 ] , argv [ idx ] , NULL , 0 , true ) = = false ) {
foundInvalidArgs = true ;
printf ( " \n Invalid argument: %s " , argv [ idx ] ) ;
}
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_HELP ] ) = = true | |
foundInvalidArgs = = true ) {
printParameterHelp ( argv [ 0 ] , foundInvalidArgs ) ;
2012-07-18 01:04:30 +02:00
return 2 ;
2011-05-19 00:04:45 +02:00
}
# ifdef WIN32
SocketManager winSockManager ;
# endif
bool haveSpecialOutputCommandLineOption = false ;
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_OPENGL_INFO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SDL_INFO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LUA_INFO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_CURL_INFO ] ) = = true | |
2012-03-14 01:21:59 +01:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_XERCES_INFO ] ) = = true | |
2011-05-19 00:04:45 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VERSION ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SHOW_INI_SETTINGS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) = = true | |
2012-04-02 08:07:32 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_SCENARIO ] ) = = true | |
2012-04-03 21:35:22 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TILESET ] ) = = true | |
2013-06-13 00:49:47 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_TRANSLATE_TECHTREES ] ) = = true | |
2012-04-02 08:07:32 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_MAPS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TECHTRESS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_SCENARIOS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TILESETS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TUTORIALS ] ) = = true ) {
2011-05-19 00:04:45 +02:00
haveSpecialOutputCommandLineOption = true ;
}
if ( haveSpecialOutputCommandLineOption = = false | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VERSION ] ) = = true ) {
2011-12-20 08:00:23 +01:00
printf ( " %s %s " , extractFileFromDirectoryPath ( argv [ 0 ] ) . c_str ( ) , getNetworkPlatformFreeVersionString ( ) . c_str ( ) ) ;
2012-11-01 07:21:35 +01:00
printf ( " \n Compiled using: %s on: %s platform: %s endianness: %s " , getCompilerNameString ( ) . c_str ( ) , getCompileDateTime ( ) . c_str ( ) , getPlatformNameString ( ) . c_str ( ) , ( Shared : : PlatformByteOrder : : isBigEndian ( ) = = true ? " big " : " little " ) ) ;
2012-11-01 19:22:25 +01:00
2012-11-10 07:37:23 +01:00
// printf("\n\nData type sizes int8 = " MG_SIZE_T_SPECIFIER " int16 = " MG_SIZE_T_SPECIFIER " int32 = " MG_SIZE_T_SPECIFIER " int64 = " MG_SIZE_T_SPECIFIER "\n\n",sizeof(int8),sizeof(int16),sizeof(int32),sizeof(int64));
2012-11-03 08:49:09 +01:00
//
// Config::getInstance().setBool("DebugNetworkPackets",true,true);
// NetworkMessageIntro data(424336, "mg_version_x","player_x", 3, nmgstOk,444444, 555555, "english");
// unsigned char *buf = data.packMessage();
// printf("\nSend packet size = %u\n%s\n",data.getPackedSize(),data.toString().c_str());
// data.dump_packet("Send data", buf, data.getPackedSize());
// //delete [] buf;
//
// NetworkMessageIntro data2;
// data2.unpackMessage(buf);
// printf("\nReceive packet size = %u\n%s\n",data2.getPackedSize(),data2.toString().c_str());
// data2.dump_packet("nReceive data", buf, data2.getPackedSize());
// delete [] buf;
2012-11-03 02:23:48 +01:00
2012-11-02 20:08:55 +01:00
// SwitchSetupRequest data("factionname", 3,-1,2,"softcoder",10, 11,"eng");
//
// unsigned char *buf = data.packMessage();
// printf("\nSend packet size = %u\n%s\nTeam = %d faction [%s] currentFactionIndex = %d toFactionIndex = %d [%s] [%s] %d %d\n",data.getPackedSize(),buf,data.getToTeam(),data.getSelectedFactionName().c_str(),data.getCurrentFactionIndex(),data.getToFactionIndex(),data.getNetworkPlayerLanguage().c_str(),data.getNetworkPlayerName().c_str(),data.getNetworkPlayerStatus(),data.getSwitchFlags());
// //delete [] buf;
//
// data.unpackMessage(buf);
// printf("\nGot packet size = %u\n%s\nTeam = %d faction [%s] currentFactionIndex = %d toFactionIndex = %d [%s] [%s] %d %d\n",data.getPackedSize(),buf,data.getToTeam(),data.getSelectedFactionName().c_str(),data.getCurrentFactionIndex(),data.getToFactionIndex(),data.getNetworkPlayerLanguage().c_str(),data.getNetworkPlayerName().c_str(),data.getNetworkPlayerStatus(),data.getSwitchFlags());
// delete [] buf;
// int8 a = 1;
// uint8 b = 2;
// int16 c = 3;
// uint16 d = 4;
// int32 e = 5;
// uint32 f = 6;
//
// printf("\nPack test #1: [%d][%u][%d][%u][%d][%u]\n,",a,b,c,d,e,f);
//
// unsigned char *buf = new unsigned char[100];
// unsigned int packedsize = pack(buf, "cChHlL",
// a,
// b,
// c,
// d,
// e,
// f);
//
// printf("Pack test #2: [%u][%s]\n,",packedsize,buf);
//
// int8 a1 = 0;
// uint8 b1 = 0;
// int16 c1 = 0;
// uint16 d1 = 0;
// int32 e1 = 0;
// uint32 f1 = 0;
//
// unpack(buf, "cChHlL",
// &a1,
// &b1,
// &c1,
// &d1,
// &e1,
// &f1);
//
// printf("UnPack test #3: [%d][%u][%d][%u][%d][%u]\n,",a1,b1,c1,d1,e1,f1);
if ( SystemFlags : : VERBOSE_MODE_ENABLED = = true ) {
int8 testVar = 111 ;
printf ( " \n Endian value = %d " , testVar ) ;
testVar = Shared : : PlatformByteOrder : : toCommonEndian ( testVar ) ;
printf ( " \n Endian to common value = %d " , testVar ) ;
testVar = Shared : : PlatformByteOrder : : fromCommonEndian ( testVar ) ;
printf ( " \n Endian from common value = %d " , testVar ) ;
2012-11-10 07:37:23 +01:00
printf ( " \n int8 sizeof = " MG_SIZE_T_SPECIFIER " " , sizeof ( int8 ) ) ;
printf ( " \n SwitchSetupRequest sizeof = " MG_SIZE_T_SPECIFIER " " , SwitchSetupRequest ( ) . getDataSize ( ) ) ;
2012-11-02 20:08:55 +01:00
}
2012-11-01 19:48:24 +01:00
2011-12-20 08:00:23 +01:00
printf ( " \n SVN: [%s] " , getSVNRevisionString ( ) . c_str ( ) ) ;
2012-11-01 19:22:25 +01:00
2011-05-19 00:04:45 +02:00
# ifdef USE_STREFLOP
2011-11-01 21:07:18 +01:00
//# define STREFLOP_NO_DENORMALS
// streflop_init<streflop::Simple>();
2012-02-11 16:20:40 +01:00
# if defined(STREFLOP_SSE)
2012-10-06 09:06:40 +02:00
const char * instruction_set = " [SSE] " ;
2012-02-11 16:20:40 +01:00
# elif defined(STREFLOP_X87)
2012-10-06 09:06:40 +02:00
const char * instruction_set = " [X87] " ;
2012-02-11 16:20:40 +01:00
# elif defined(STREFLOP_SOFT)
2012-10-06 09:06:40 +02:00
const char * instruction_set = " [SOFTFLOAT] " ;
# else
const char * instruction_set = " [none] " ;
2012-02-11 16:20:40 +01:00
# endif
# if defined(STREFLOP_NO_DENORMALS)
2012-10-06 09:06:40 +02:00
const char * denormals = " [no-denormals] " ;
# else
const char * denormals = " [denormals] " ;
2012-02-11 16:20:40 +01:00
# endif
printf ( " - using STREFLOP %s - %s \n " , instruction_set , denormals ) ;
2011-05-19 00:04:45 +02:00
# endif
}
2012-06-04 02:11:29 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_OPENGL_INFO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SDL_INFO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LUA_INFO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_CURL_INFO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_XERCES_INFO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VERSION ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SHOW_INI_SETTINGS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_SCENARIO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TILESET ] ) = = true | |
2013-06-13 00:49:47 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_TRANSLATE_TECHTREES ] ) = = true | |
2012-06-04 02:11:29 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_MAPS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TECHTRESS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_SCENARIOS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TILESETS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TUTORIALS ] ) = = true ) {
VideoPlayer : : setDisabled ( true ) ;
}
2012-04-15 00:48:49 +02:00
//throw megaglest_runtime_error("Test!");
2011-05-19 00:04:45 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SDL_INFO ] ) = = true ) {
SDL_version ver ;
// Prints the compile time version
SDL_VERSION ( & ver ) ;
print_SDL_version ( " SDL compile-time version " , & ver ) ;
// Prints the run-time version
ver = * SDL_Linked_Version ( ) ;
print_SDL_version ( " SDL runtime version " , & ver ) ;
2012-10-30 07:48:12 +01:00
//const SDL_VideoInfo *vidInfo = SDL_GetVideoInfo();
//printf("Video card Memory: %u\n",vidInfo->video_mem);
2011-05-19 00:04:45 +02:00
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LUA_INFO ] ) = = true ) {
printf ( " LUA version: %s \n " , LUA_RELEASE ) ;
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_CURL_INFO ] ) = = true ) {
curl_version_info_data * curlVersion = curl_version_info ( CURLVERSION_NOW ) ;
2012-10-28 00:38:14 +02:00
printf ( " CURL version: %s [%s] SSL enabled: %d \n " , curlVersion - > version , ( curlVersion - > ssl_version ! = NULL ? curlVersion - > ssl_version : " " ) , ( ( curlVersion - > features & CURL_VERSION_SSL ) = = CURL_VERSION_SSL ? true : false ) ) ;
2012-10-26 20:17:02 +02:00
if ( curlVersion - > protocols ! = NULL & & curlVersion - > protocols [ 0 ] ! = NULL ) {
printf ( " protocols: " ) ;
for ( unsigned int i = 0 ; curlVersion - > protocols ! = NULL & & curlVersion - > protocols [ i ] ! = NULL ; + + i ) {
printf ( " %s " , curlVersion - > protocols [ i ] ) ;
if ( i > 0 & & i % 10 = = 0 ) {
printf ( " \n " ) ;
}
}
printf ( " \n " ) ;
}
2011-05-19 00:04:45 +02:00
}
2012-03-14 01:21:59 +01:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_XERCES_INFO ] ) = = true ) {
printf ( " XERCES version: %s \n " , XERCES_FULLVERSIONDOT ) ;
}
2011-05-19 00:04:45 +02:00
if ( ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VERSION ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SDL_INFO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LUA_INFO ] ) = = true | |
2012-03-14 01:21:59 +01:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_CURL_INFO ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_XERCES_INFO ] ) = = true ) & &
2011-05-19 00:04:45 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_OPENGL_INFO ] ) = = false & &
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) = = false & &
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) = = false & &
2012-04-02 08:07:32 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_SCENARIO ] ) = = false & &
2012-04-03 21:35:22 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TILESET ] ) = = false & &
2013-06-13 00:49:47 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_TRANSLATE_TECHTREES ] ) = = false & &
2012-04-02 08:07:32 +02:00
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_MAPS ] ) = = false & &
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TECHTRESS ] ) = = false & &
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_SCENARIOS ] ) = = false & &
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TILESETS ] ) = = false & &
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TUTORIALS ] ) = = false ) {
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
2011-11-23 19:02:00 +01:00
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_MOD ] ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_MOD ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_MOD ] ) , & foundParamIndIndex ) ;
}
string scenarioName = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( scenarioName , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string autoloadModName = paramPartTokens [ 1 ] ;
if ( Properties : : applyTagsToValue ( autoloadModName ) = = true ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Property key [%s] now has value [%s] \n " , Config : : ACTIVE_MOD_PROPERTY_NAME , autoloadModName . c_str ( ) ) ;
}
Config : : setCustomRuntimeProperty ( Config : : ACTIVE_MOD_PROPERTY_NAME , autoloadModName ) ;
printf ( " Setting mod active [%s] \n " , autoloadModName . c_str ( ) ) ;
}
else {
printf ( " \n Invalid mod pathname specified on commandline [%s] mod [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( argv [ 0 ] , foundInvalidArgs ) ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-11-23 19:02:00 +01:00
}
}
2011-05-19 00:04:45 +02:00
SystemFlags : : init ( haveSpecialOutputCommandLineOption ) ;
//SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled = true;
//SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled = true;
MainWindow * mainWindow = NULL ;
Program * program = NULL ;
ExceptionHandler exceptionHandler ;
exceptionHandler . install ( getCrashDumpFileName ( ) ) ;
2011-11-11 19:15:46 +01:00
int shutdownFadeSoundMilliseconds = 1000 ;
2011-10-22 00:07:34 +02:00
Chrono chronoshutdownFadeSound ;
SimpleTaskThread * soundThreadManager = NULL ;
2011-05-19 00:04:45 +02:00
try {
// Setup paths to game items (like data, logs, ini etc)
int setupResult = setupGameItemPaths ( argc , argv , NULL ) ;
if ( setupResult ! = 0 ) {
return setupResult ;
}
// Attempt to read ini files
Config & config = Config : : getInstance ( ) ;
setupGameItemPaths ( argc , argv , & config ) ;
2013-06-01 04:31:12 +02:00
if ( config . getString ( " PlayerId " , " " ) = = " " ) {
char uuid_str [ 38 ] ;
get_uuid_string ( uuid_str , sizeof ( uuid_str ) ) ;
config . setString ( " PlayerId " , uuid_str ) ;
config . save ( ) ;
}
//printf("Players UUID: [%s]\n",config.getString("PlayerId","").c_str());
2012-10-11 07:17:37 +02:00
if ( config . getBool ( " DisableLuaSandbox " , " false " ) = = true ) {
LuaScript : : setDisableSandbox ( true ) ;
}
2012-11-01 23:00:55 +01:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_DEBUG_NETWORK_PACKETS ] ) = = true ) {
printf ( " *NOTE: debugging network packets. \n " ) ;
config . setBool ( " DebugNetworkPackets " , true , true ) ;
}
2012-11-02 20:08:55 +01:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_ENABLE_NEW_PROTOCOL ] ) = = true ) {
printf ( " *NOTE: enabling new newtork protocol. \n " ) ;
NetworkMessage : : useOldProtocol = false ;
}
2012-10-06 02:37:21 +02:00
Socket : : setBroadCastPort ( config . getInt ( " BroadcastPort " , intToStr ( Socket : : getBroadCastPort ( ) ) . c_str ( ) ) ) ;
2012-10-06 02:34:08 +02:00
2011-11-27 01:07:55 +01:00
Socket : : disableNagle = config . getBool ( " DisableNagle " , " false " ) ;
if ( Socket : : disableNagle ) {
printf ( " *WARNING users wants to disable the socket nagle algorithm. \n " ) ;
}
Socket : : DEFAULT_SOCKET_SENDBUF_SIZE = config . getInt ( " DefaultSocketSendBufferSize " , intToStr ( Socket : : DEFAULT_SOCKET_SENDBUF_SIZE ) . c_str ( ) ) ;
if ( Socket : : DEFAULT_SOCKET_SENDBUF_SIZE > = 0 ) {
printf ( " *WARNING users wants to set default socket send buffer size to: %d \n " , Socket : : DEFAULT_SOCKET_SENDBUF_SIZE ) ;
}
Socket : : DEFAULT_SOCKET_RECVBUF_SIZE = config . getInt ( " DefaultSocketReceiveBufferSize " , intToStr ( Socket : : DEFAULT_SOCKET_RECVBUF_SIZE ) . c_str ( ) ) ;
if ( Socket : : DEFAULT_SOCKET_RECVBUF_SIZE > = 0 ) {
printf ( " *WARNING users wants to set default socket receive buffer size to: %d \n " , Socket : : DEFAULT_SOCKET_RECVBUF_SIZE ) ;
}
2011-10-22 00:36:36 +02:00
shutdownFadeSoundMilliseconds = config . getInt ( " ShutdownFadeSoundMilliseconds " , intToStr ( shutdownFadeSoundMilliseconds ) . c_str ( ) ) ;
2011-05-19 00:04:45 +02:00
string userData = config . getString ( " UserData_Root " , " " ) ;
2012-03-15 23:09:11 +01:00
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
userData = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ;
}
if ( userData ! = " " ) {
endPathWithSlash ( userData ) ;
}
2011-05-19 00:04:45 +02:00
2012-03-15 23:09:11 +01:00
if ( userData ! = " " ) {
2011-05-19 00:04:45 +02:00
if ( isdir ( userData . c_str ( ) ) = = false ) {
createDirectoryPaths ( userData ) ;
}
}
string crcCachePath = userData + " cache/ " ;
if ( isdir ( crcCachePath . c_str ( ) ) = = false ) {
createDirectoryPaths ( crcCachePath ) ;
}
setCRCCacheFilePath ( crcCachePath ) ;
2012-03-15 23:09:11 +01:00
string savedGamePath = userData + " saved/ " ;
if ( isdir ( savedGamePath . c_str ( ) ) = = false ) {
createDirectoryPaths ( savedGamePath ) ;
//printf("savedGamePath = [%s]\n",savedGamePath.c_str());
}
2011-05-19 00:04:45 +02:00
string tempDataPath = userData + " temp/ " ;
if ( isdir ( tempDataPath . c_str ( ) ) = = true ) {
removeFolder ( tempDataPath ) ;
}
createDirectoryPaths ( tempDataPath ) ;
2012-03-26 09:02:54 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_USE_PORTS ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_PORTS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_PORTS ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string portsToUse = paramPartTokens [ 1 ] ;
vector < string > paramPartPortsTokens ;
Tokenize ( portsToUse , paramPartPortsTokens , " , " ) ;
if ( paramPartPortsTokens . size ( ) > = 2 & & paramPartPortsTokens [ 1 ] . length ( ) > 0 ) {
int internalPort = strToInt ( paramPartPortsTokens [ 0 ] ) ;
int externalPort = strToInt ( paramPartPortsTokens [ 1 ] ) ;
printf ( " Forcing internal port# %d, external port# %d \n " , internalPort , externalPort ) ;
2012-10-06 14:56:53 +02:00
config . setInt ( " PortServer " , internalPort , true ) ;
config . setInt ( " PortExternal " , externalPort , true ) ;
2012-07-06 18:29:49 +02:00
config . setInt ( " FTPServerPort " , internalPort + 1 , true ) ;
2012-03-26 09:02:54 +02:00
if ( paramPartPortsTokens . size ( ) > = 3 & & paramPartPortsTokens [ 2 ] . length ( ) > 0 ) {
int statusPort = strToInt ( paramPartPortsTokens [ 2 ] ) ;
printf ( " Forcing status port# %d \n " , statusPort ) ;
2012-07-06 18:29:49 +02:00
config . setInt ( " ServerAdminPort " , statusPort , true ) ;
2012-03-26 09:02:54 +02:00
}
}
else {
printf ( " \n Invalid ports specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2012-07-18 01:04:30 +02:00
return 1 ;
2012-03-26 09:02:54 +02:00
}
}
else {
printf ( " \n Invalid missing ports specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2012-07-18 01:04:30 +02:00
return 1 ;
2012-03-26 09:02:54 +02:00
}
}
2012-03-25 08:55:43 +02:00
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_MASTERSERVER_STATUS ] ) ) = = true ) {
Ip ip ( " localhost " ) ;
int port = Config : : getInstance ( ) . getInt ( " ServerAdminPort " , intToStr ( GameConstants : : serverAdminPort ) . c_str ( ) ) ;
ClientSocket clientSocket ;
clientSocket . setBlock ( false ) ;
clientSocket . connect ( ip , port ) ;
if ( clientSocket . isConnected ( ) = = true ) {
clientSocket . setBlock ( true ) ;
char szBuf [ 8096 ] = " " ;
clientSocket . receive ( & szBuf [ 0 ] , 8095 , false ) ;
std : : cout < < szBuf < < std : : endl ;
}
2012-10-17 00:34:18 +02:00
else {
std : : cout < < " Could not connect (possibly no clients connected) to host: " < < ip . getString ( ) < < " port: " < < port < < std : : endl ;
}
2012-03-25 08:55:43 +02:00
return 0 ;
}
2011-09-26 01:57:42 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_DISABLE_SOUND ] ) = = true | |
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_MASTERSERVER_MODE ] ) ) = = true ) {
2012-07-06 18:29:49 +02:00
config . setString ( " FactorySound " , " None " , true ) ;
2011-09-26 01:57:42 +02:00
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_MASTERSERVER_MODE ] ) ) = = true ) {
2011-12-02 23:04:02 +01:00
//Logger::getInstance().setMasterserverMode(true);
//Model::setMasterserverMode(true);
//Shared::Sound::Sound::setMasterserverMode(true);
2011-09-26 01:57:42 +02:00
}
2011-05-19 00:04:45 +02:00
}
2012-08-17 00:36:04 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_DISABLE_OPENGL_CAPS_CHECK ] ) = = true | |
config . getBool ( " CheckGlCaps " ) = = false ) {
printf ( " **WARNING** disabling opengl capability checking... \n " ) ;
config . setBool ( " CheckGlCaps " , false , true ) ;
}
2011-05-19 00:04:45 +02:00
bool enableATIHacks = config . getBool ( " EnableATIHacks " , " false " ) ;
if ( enableATIHacks = = true ) {
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " **WARNING** Enabling ATI video card hacks \n " ) ;
TextureGl : : setEnableATIHacks ( enableATIHacks ) ;
}
2011-11-18 20:53:56 +01:00
if ( config . getBool ( " ForceFTGLFonts " , " false " ) = = true | | hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_FORCE_FTGLFONTS ] ) = = true ) {
2012-09-22 22:13:57 +02:00
Shared : : Graphics : : Font : : forceFTGLFonts = true ;
2011-11-18 20:53:56 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**WARNING** Forcing Legacy Fonts Enabled\n");
printf ( " **WARNING** Forcing use of FTGL Fonts \n " ) ;
}
else {
Renderer : : renderText3DEnabled = config . getBool ( " Enable3DFontRendering " , intToStr ( Renderer : : renderText3DEnabled ) . c_str ( ) ) ;
}
2011-06-08 09:18:06 +02:00
if ( config . getBool ( " EnableLegacyFonts " , " false " ) = = true | | hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_ENABLE_LEGACYFONTS ] ) = = true ) {
2012-09-22 22:13:57 +02:00
Shared : : Graphics : : Font : : forceLegacyFonts = true ;
2011-06-11 12:31:24 +02:00
Renderer : : renderText3DEnabled = false ;
2011-11-02 00:51:28 +01:00
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**WARNING** Forcing Legacy Fonts Enabled\n");
printf ( " **WARNING** Forcing Legacy Fonts Enabled \n " ) ;
2011-06-08 09:18:06 +02:00
}
2011-06-11 12:31:24 +02:00
else {
Renderer : : renderText3DEnabled = config . getBool ( " Enable3DFontRendering " , intToStr ( Renderer : : renderText3DEnabled ) . c_str ( ) ) ;
}
2011-06-10 05:09:19 +02:00
2011-07-09 01:14:26 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_USE_RESOLUTION ] ) = = true ) {
2011-06-11 10:52:49 +02:00
int foundParamIndIndex = - 1 ;
2011-07-09 01:14:26 +02:00
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_RESOLUTION ] ) + string ( " = " ) , & foundParamIndIndex ) ;
2011-06-11 10:52:49 +02:00
if ( foundParamIndIndex < 0 ) {
2011-07-09 01:14:26 +02:00
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_RESOLUTION ] ) , & foundParamIndIndex ) ;
2011-06-11 10:52:49 +02:00
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string settings = paramPartTokens [ 1 ] ;
2011-07-09 01:14:26 +02:00
printf ( " Forcing resolution [%s] \n " , settings . c_str ( ) ) ;
2011-06-11 10:52:49 +02:00
paramPartTokens . clear ( ) ;
Tokenize ( settings , paramPartTokens , " x " ) ;
if ( paramPartTokens . size ( ) > = 2 ) {
int newScreenWidth = strToInt ( paramPartTokens [ 0 ] ) ;
2012-07-06 18:29:49 +02:00
config . setInt ( " ScreenWidth " , newScreenWidth , true ) ;
2011-06-11 10:52:49 +02:00
int newScreenHeight = strToInt ( paramPartTokens [ 1 ] ) ;
2012-07-06 18:29:49 +02:00
config . setInt ( " ScreenHeight " , newScreenHeight , true ) ;
2011-06-11 10:52:49 +02:00
}
else {
2011-07-09 01:14:26 +02:00
printf ( " \n Invalid missing resolution settings specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
2011-06-11 10:52:49 +02:00
//printParameterHelp(argv[0],false);
2012-07-18 01:04:30 +02:00
return 1 ;
2011-06-11 10:52:49 +02:00
}
}
else {
2011-07-09 01:14:26 +02:00
printf ( " \n Invalid missing resolution setting specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
2011-06-11 10:52:49 +02:00
//printParameterHelp(argv[0],false);
2012-07-18 01:04:30 +02:00
return 1 ;
2011-06-11 10:52:49 +02:00
}
}
2011-07-09 01:14:26 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_USE_COLORBITS ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_COLORBITS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_COLORBITS ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string settings = paramPartTokens [ 1 ] ;
printf ( " Forcing colorbits [%s] \n " , settings . c_str ( ) ) ;
int newColorBits = strToInt ( settings ) ;
2012-07-06 18:29:49 +02:00
config . setInt ( " ColorBits " , newColorBits , true ) ;
2011-07-09 01:14:26 +02:00
}
else {
printf ( " \n Invalid missing colorbits settings specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2012-07-18 01:04:30 +02:00
return 1 ;
2011-07-09 01:14:26 +02:00
}
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_USE_DEPTHBITS ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_DEPTHBITS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_DEPTHBITS ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string settings = paramPartTokens [ 1 ] ;
printf ( " Forcing depthbits [%s] \n " , settings . c_str ( ) ) ;
int newDepthBits = strToInt ( settings ) ;
2012-07-06 18:29:49 +02:00
config . setInt ( " DepthBits " , newDepthBits , true ) ;
2011-07-09 01:14:26 +02:00
}
else {
printf ( " \n Invalid missing depthbits setting specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2012-07-18 01:04:30 +02:00
return 1 ;
2011-07-09 01:14:26 +02:00
}
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_USE_FULLSCREEN ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_FULLSCREEN ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_FULLSCREEN ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string settings = paramPartTokens [ 1 ] ;
printf ( " Forcing fullscreen [%s] \n " , settings . c_str ( ) ) ;
bool newFullScreenMode = strToBool ( settings ) ;
2012-07-06 18:29:49 +02:00
config . setBool ( " Windowed " , ! newFullScreenMode , true ) ;
2011-07-09 01:14:26 +02:00
}
else {
printf ( " \n Invalid missing fullscreen setting specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2012-07-18 01:04:30 +02:00
return 1 ;
2011-07-09 01:14:26 +02:00
}
}
2011-12-23 09:20:54 +01:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SET_GAMMA ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SET_GAMMA ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SET_GAMMA ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string settings = paramPartTokens [ 1 ] ;
printf ( " Forcing gamma [%s] \n " , settings . c_str ( ) ) ;
float newGammaValue = strToFloat ( settings ) ;
2012-07-06 18:29:49 +02:00
config . setFloat ( " GammaValue " , newGammaValue , true ) ;
2011-12-23 09:20:54 +01:00
}
else {
printf ( " \n Invalid missing gamma setting specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2012-07-18 01:04:30 +02:00
return 1 ;
2011-12-23 09:20:54 +01:00
}
}
2012-06-09 07:02:01 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_DISABLE_VIDEOS ] ) = = true ) {
VideoPlayer : : setDisabled ( true ) ;
}
else if ( config . getBool ( " EnableVideos " , " true " ) = = false ) {
VideoPlayer : : setDisabled ( true ) ;
}
2011-05-19 00:04:45 +02:00
// Set some statics based on ini entries
SystemFlags : : ENABLE_THREADED_LOGGING = config . getBool ( " ThreadedLogging " , " true " ) ;
FontGl : : setDefault_fontType ( config . getString ( " DefaultFont " , FontGl : : getDefault_fontType ( ) . c_str ( ) ) ) ;
UPNP_Tools : : isUPNP = ! config . getBool ( " DisableUPNP " , " false " ) ;
Texture : : useTextureCompression = config . getBool ( " EnableTextureCompression " , " false " ) ;
2011-06-07 04:37:58 +02:00
2011-05-19 00:04:45 +02:00
// 256 for English
// 30000 for Chinese
2012-09-22 22:13:57 +02:00
Shared : : Graphics : : Font : : charCount = config . getInt ( " FONT_CHARCOUNT " , intToStr ( Shared : : Graphics : : Font : : charCount ) . c_str ( ) ) ;
Shared : : Graphics : : Font : : fontTypeName = config . getString ( " FONT_TYPENAME " , Shared : : Graphics : : Font : : fontTypeName . c_str ( ) ) ;
Shared : : Graphics : : Font : : fontIsMultibyte = config . getBool ( " FONT_MULTIBYTE " , intToStr ( Shared : : Graphics : : Font : : fontIsMultibyte ) . c_str ( ) ) ;
Shared : : Graphics : : Font : : fontIsRightToLeft = config . getBool ( " FONT_RIGHTTOLEFT " , intToStr ( Shared : : Graphics : : Font : : fontIsRightToLeft ) . c_str ( ) ) ;
Shared : : Graphics : : Font : : baseSize = config . getInt ( " FONT_BASE_SIZE " , intToStr ( Shared : : Graphics : : Font : : baseSize ) . c_str ( ) ) ;
Shared : : Graphics : : Font : : scaleFontValue = config . getFloat ( " FONT_SCALE_SIZE " , floatToStr ( Shared : : Graphics : : Font : : scaleFontValue ) . c_str ( ) ) ;
Shared : : Graphics : : Font : : scaleFontValueCenterHFactor = config . getFloat ( " FONT_SCALE_CENTERH_FACTOR " , floatToStr ( Shared : : Graphics : : Font : : scaleFontValueCenterHFactor ) . c_str ( ) ) ;
Shared : : Graphics : : Font : : langHeightText = config . getString ( " FONT_HEIGHT_TEXT " , Shared : : Graphics : : Font : : langHeightText . c_str ( ) ) ;
2011-06-09 07:54:04 +02:00
2011-05-19 00:04:45 +02:00
// Example values:
// DEFAULT_CHARSET (English) = 1
// GB2312_CHARSET (Chinese) = 134
Shared : : Platform : : charSet = config . getInt ( " FONT_CHARSET " , intToStr ( Shared : : Platform : : charSet ) . c_str ( ) ) ;
if ( config . getBool ( " No2DMouseRendering " , " false " ) = = false ) {
showCursor ( false ) ;
}
if ( config . getInt ( " DEFAULT_HTTP_TIMEOUT " , intToStr ( SystemFlags : : DEFAULT_HTTP_TIMEOUT ) . c_str ( ) ) > = 0 ) {
SystemFlags : : DEFAULT_HTTP_TIMEOUT = config . getInt ( " DEFAULT_HTTP_TIMEOUT " , intToStr ( SystemFlags : : DEFAULT_HTTP_TIMEOUT ) . c_str ( ) ) ;
}
2012-09-22 22:13:57 +02:00
bool allowAltEnterFullscreenToggle = config . getBool ( " AllowAltEnterFullscreenToggle " , boolToStr ( Shared : : Platform : : Window : : getAllowAltEnterFullscreenToggle ( ) ) . c_str ( ) ) ;
Shared : : Platform : : Window : : setAllowAltEnterFullscreenToggle ( allowAltEnterFullscreenToggle ) ;
2011-05-19 00:04:45 +02:00
if ( config . getBool ( " noTeamColors " , " false " ) = = true ) {
MeshCallbackTeamColor : : noTeamColors = true ;
}
// Setup debug logging etc
setupLogging ( config , haveSpecialOutputCommandLineOption ) ;
2012-09-22 22:13:57 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d, Font::fontIsMultibyte = %d, fontIsRightToLeft = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , Shared : : Graphics : : Font : : charCount , Shared : : Graphics : : Font : : fontTypeName . c_str ( ) , Shared : : Platform : : charSet , Shared : : Graphics : : Font : : fontIsMultibyte , Shared : : Graphics : : Font : : fontIsRightToLeft ) ;
2011-05-19 00:04:45 +02:00
NetworkInterface : : setDisplayMessageFunction ( ExceptionHandler : : DisplayMessage ) ;
MenuStateMasterserver : : setDisplayMessageFunction ( ExceptionHandler : : DisplayMessage ) ;
# ifdef USE_STREFLOP
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s, STREFLOP enabled. \n " , getNetworkVersionString ( ) . c_str ( ) ) ;
# else
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " %s, STREFLOP NOT enabled. \n " , getNetworkVersionString ( ) . c_str ( ) ) ;
# endif
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugUnitCommands , " START \n " ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugPathFinder , " START \n " ) ;
// Setup hotkeys from key ini files
Config & configKeys = Config : : getInstance (
std : : pair < ConfigType , ConfigType > ( cfgMainKeys , cfgUserKeys ) ,
std : : pair < string , string > ( Config : : glestkeys_ini_filename , Config : : glestuserkeys_ini_filename ) ,
std : : pair < bool , bool > ( true , false ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SHOW_INI_SETTINGS ] ) = = true ) {
ShowINISettings ( argc , argv , config , configKeys ) ;
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
//setVBOSupported(false);
// Explicitly disable VBO's
if ( config . getBool ( " DisableVBO " , " false " ) = = true | | hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_DISABLE_VBO ] ) = = true ) {
setVBOSupported ( false ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " **WARNING** Disabling VBO's \n " ) ;
}
if ( config . getBool ( " EnableVSynch " , " false " ) = = true ) {
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : setTryVSynch ( true ) ;
2011-05-19 00:04:45 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " **ENABLED OPENGL VSYNCH** \n " ) ;
}
//float pingTime = Socket::getAveragePingMS("soft-haus.com");
//printf("Ping time = %f\n",pingTime);
// Load the language strings
Lang & lang = Lang : : getInstance ( ) ;
string language = config . getString ( " Lang " ) ;
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_USE_LANGUAGE ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_LANGUAGE ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_LANGUAGE ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
language = paramPartTokens [ 1 ] ;
printf ( " Forcing language [%s] \n " , language . c_str ( ) ) ;
}
else {
printf ( " \n Invalid missing language specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
}
2011-12-01 03:31:00 +01:00
else {
2011-12-01 09:05:36 +01:00
# ifdef _WIN32
2012-01-20 05:15:13 +01:00
int localeBufferSize = GetLocaleInfo ( LOCALE_SYSTEM_DEFAULT , LOCALE_SISO639LANGNAME , NULL , 0 ) ;
wchar_t * sysLocale = new wchar_t [ localeBufferSize ] ;
2011-12-01 09:05:36 +01:00
GetLocaleInfo ( LOCALE_SYSTEM_DEFAULT , LOCALE_SISO639LANGNAME , sysLocale , localeBufferSize ) ;
//String langValue(sysLocale);
//const char *lang_locale = langValue.c_str();
2012-01-20 05:15:13 +01:00
char langValue [ 1024 ] = " " ;
2011-12-01 09:05:36 +01:00
wcstombs ( langValue , sysLocale , 1023 ) ;
const char * lang_locale = & langValue [ 0 ] ;
2012-04-20 03:04:05 +02:00
delete [ ] sysLocale ;
2011-12-01 09:05:36 +01:00
# else
const char * lang_locale = setlocale ( LC_ALL , " " ) ;
# endif
2011-12-01 03:31:00 +01:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Locale is: [%s] \n " , lang_locale ) ;
if ( lang_locale ! = NULL & & strlen ( lang_locale ) > = 2 ) {
if ( config . getBool ( " AutoLocaleLanguageDetect " , " true " ) = = true ) {
language = lang_locale ;
language = language . substr ( 0 , 2 ) ;
printf ( " Auto setting language [%s] \n " , language . c_str ( ) ) ;
2011-12-01 09:05:36 +01:00
config . setString ( " AutoLocaleLanguageDetect " , " false " ) ;
config . save ( ) ;
2011-12-01 03:31:00 +01:00
}
}
}
2011-05-19 00:04:45 +02:00
2012-03-17 09:20:17 +01:00
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_AUTO_TEST ] ) ) = = true | |
Config : : getInstance ( ) . getBool ( " AutoTest " , " false " ) = = true ) {
printf ( " Running in auto test mode \n " ) ;
}
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_AUTO_TEST ] ) ) = = true ) {
2012-07-06 18:29:49 +02:00
Config : : getInstance ( ) . setBool ( " AutoTest " , " true " , true ) ;
2012-03-17 09:20:17 +01:00
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_AUTO_TEST ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_AUTO_TEST ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
vector < string > paramPartTokens2 ;
Tokenize ( paramPartTokens [ 1 ] , paramPartTokens2 , " , " ) ;
2013-05-17 05:59:34 +02:00
if ( paramPartTokens2 . empty ( ) = = false & & paramPartTokens2 [ 0 ] . length ( ) > 0 ) {
2012-03-17 09:20:17 +01:00
string newMaxSeconds = paramPartTokens2 [ 0 ] ;
time_t newTimeMaxSeconds = strToInt ( newMaxSeconds ) ;
AutoTest : : setMaxGameTime ( newTimeMaxSeconds ) ;
//printf("#1 Forcing font [%s] paramPartTokens.size() = %d, paramValue [%s]\n",newfont.c_str(),paramPartTokens.size(),paramValue.c_str());
printf ( " Forcing maximum game time to [%ld] seconds (%.2f minutes) \n " , newTimeMaxSeconds , ( ( double ) newTimeMaxSeconds / 60.0 ) ) ;
}
if ( paramPartTokens2 . size ( ) > = 3 & & paramPartTokens2 [ 2 ] . length ( ) > 0 ) {
string autoTestCmd = paramPartTokens2 [ 2 ] ;
if ( autoTestCmd = = " exit " ) {
printf ( " Detected auto test command [%s], will exit after game. \n " , autoTestCmd . c_str ( ) ) ;
AutoTest : : setWantExitGameWhenDone ( true ) ;
}
else {
printf ( " WARNING: Detected and UNKNOWN auto test command [%s]. \n " , autoTestCmd . c_str ( ) ) ;
}
}
if ( paramPartTokens2 . size ( ) > = 2 & & paramPartTokens2 [ 1 ] . length ( ) > 0 ) {
string newGameSettingsFileToLoad = paramPartTokens2 [ 1 ] ;
printf ( " About to auto test using game settings file [%s] \n " , newGameSettingsFileToLoad . c_str ( ) ) ;
AutoTest : : setLoadGameSettingsFile ( newGameSettingsFileToLoad ) ;
}
}
}
2011-11-01 18:38:51 +01:00
Renderer & renderer = Renderer : : getInstance ( ) ;
2011-11-15 19:38:13 +01:00
lang . loadStrings ( language , false , true ) ;
2011-07-02 03:56:06 +02:00
2011-07-02 20:33:59 +02:00
if ( lang . hasString ( " FONT_HEIGHT_TEXT " ) ) {
2012-09-22 22:13:57 +02:00
Shared : : Graphics : : Font : : langHeightText = config . getString ( " FONT_HEIGHT_TEXT " , Shared : : Graphics : : Font : : langHeightText . c_str ( ) ) ;
2011-07-02 20:33:59 +02:00
}
2011-10-03 04:45:43 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_FONT_BASESIZE ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_FONT_BASESIZE ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_FONT_BASESIZE ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string newfontBaseSize = paramPartTokens [ 1 ] ;
//printf("#1 Forcing font [%s] paramPartTokens.size() = %d, paramValue [%s]\n",newfont.c_str(),paramPartTokens.size(),paramValue.c_str());
printf ( " Forcing font base size[%s] \n " , newfontBaseSize . c_str ( ) ) ;
2012-09-22 22:13:57 +02:00
Shared : : Graphics : : Font : : baseSize = strToInt ( newfontBaseSize ) ;
2011-10-03 04:45:43 +02:00
}
else {
printf ( " \n Invalid missing font base size specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2011-11-01 22:47:34 +01:00
2012-07-18 01:04:30 +02:00
return 1 ;
2011-10-03 04:45:43 +02:00
}
}
2012-09-22 22:13:57 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d, Font::fontIsMultibyte = %d, Font::fontIsRightToLeft = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , Shared : : Graphics : : Font : : charCount , Shared : : Graphics : : Font : : fontTypeName . c_str ( ) , Shared : : Platform : : charSet , Shared : : Graphics : : Font : : fontIsMultibyte , Shared : : Graphics : : Font : : fontIsRightToLeft ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " Using Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d, Font::fontIsMultibyte = %d, Font::fontIsRightToLeft = %d \n " , Shared : : Graphics : : Font : : charCount , Shared : : Graphics : : Font : : fontTypeName . c_str ( ) , Shared : : Platform : : charSet , Shared : : Graphics : : Font : : fontIsMultibyte , Shared : : Graphics : : Font : : fontIsRightToLeft ) ;
2011-05-23 21:50:17 +02:00
2011-06-12 05:44:50 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_USE_FONT ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_FONT ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_USE_FONT ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string newfont = paramPartTokens [ 1 ] ;
//printf("#1 Forcing font [%s] paramPartTokens.size() = %d, paramValue [%s]\n",newfont.c_str(),paramPartTokens.size(),paramValue.c_str());
Properties : : applyTagsToValue ( newfont ) ;
printf ( " Forcing font [%s] \n " , newfont . c_str ( ) ) ;
# if defined(WIN32)
string newEnvValue = " MEGAGLEST_FONT= " + newfont ;
_putenv ( newEnvValue . c_str ( ) ) ;
# else
setenv ( " MEGAGLEST_FONT " , newfont . c_str ( ) , 1 ) ;
# endif
}
else {
printf ( " \n Invalid missing font specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2012-07-18 01:04:30 +02:00
return 1 ;
2011-06-12 05:44:50 +02:00
}
}
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SHOW_MAP_CRC ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_MAP_CRC ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_MAP_CRC ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string itemName = paramPartTokens [ 1 ] ;
string file = Map : : getMapPath ( itemName , " " , false ) ;
if ( file ! = " " ) {
Checksum checksum ;
checksum . addFile ( file ) ;
2012-07-07 04:46:57 +02:00
uint32 crcValue = checksum . getSum ( ) ;
2011-05-19 00:04:45 +02:00
2012-07-07 04:46:57 +02:00
printf ( " CRC value for map [%s] file [%s] is [%u] \n " , itemName . c_str ( ) , file . c_str ( ) , crcValue ) ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " Map [%s] was NOT FOUND \n " , itemName . c_str ( ) ) ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
2011-11-01 22:47:34 +01:00
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " \n Invalid missing map specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2011-11-01 22:47:34 +01:00
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SHOW_TILESET_CRC ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_TILESET_CRC ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_TILESET_CRC ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string itemName = paramPartTokens [ 1 ] ;
2012-07-07 04:46:57 +02:00
uint32 crcValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTilesets , " " ) , string ( " / " ) + itemName + string ( " /* " ) , " .xml " , NULL , true ) ;
2011-05-19 00:04:45 +02:00
if ( crcValue ! = 0 ) {
2012-07-07 04:46:57 +02:00
printf ( " CRC value for tileset [%s] is [%u] \n " , itemName . c_str ( ) , crcValue ) ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " Tileset [%s] was NOT FOUND \n " , itemName . c_str ( ) ) ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
2011-11-01 22:47:34 +01:00
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " \n Invalid missing tileset specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2011-11-01 22:47:34 +01:00
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SHOW_TECHTREE_CRC ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_TECHTREE_CRC ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_TECHTREE_CRC ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string itemName = paramPartTokens [ 1 ] ;
2012-07-07 04:46:57 +02:00
uint32 crcValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptTechs , " " ) , " / " + itemName + " /* " , " .xml " , NULL , true ) ;
2011-05-19 00:04:45 +02:00
if ( crcValue ! = 0 ) {
2012-07-07 04:46:57 +02:00
printf ( " CRC value for techtree [%s] is [%u] \n " , itemName . c_str ( ) , crcValue ) ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " Techtree [%s] was NOT FOUND \n " , itemName . c_str ( ) ) ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " \n Invalid missing techtree specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2011-11-01 22:47:34 +01:00
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SHOW_SCENARIO_CRC ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_SCENARIO_CRC ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_SCENARIO_CRC ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string itemName = paramPartTokens [ 1 ] ;
2012-07-07 04:46:57 +02:00
uint32 crcValue = getFolderTreeContentsCheckSumRecursively ( config . getPathListForType ( ptScenarios , " " ) , " / " + itemName + " /* " , " .xml " , NULL , true ) ;
2011-05-19 00:04:45 +02:00
if ( crcValue ! = 0 ) {
2012-07-07 04:46:57 +02:00
printf ( " CRC value for scenario [%s] is [%u] \n " , itemName . c_str ( ) , crcValue ) ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " Scenario [%s] was NOT FOUND \n " , itemName . c_str ( ) ) ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " \n Invalid missing scenario specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
//printParameterHelp(argv[0],false);
2011-11-01 22:47:34 +01:00
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SHOW_PATH_CRC ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_PATH_CRC ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_SHOW_PATH_CRC ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 3 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string itemName = paramPartTokens [ 1 ] ;
string itemNameFilter = paramPartTokens [ 2 ] ;
//printf("\n\nitemName [%s] itemNameFilter [%s]\n",itemName.c_str(),itemNameFilter.c_str());
2012-07-07 04:46:57 +02:00
uint32 crcValue = getFolderTreeContentsCheckSumRecursively ( itemName , itemNameFilter , NULL , true ) ;
2011-05-19 00:04:45 +02:00
2012-07-07 04:46:57 +02:00
printf ( " CRC value for path [%s] filter [%s] is [%u] \n " , itemName . c_str ( ) , itemNameFilter . c_str ( ) , crcValue ) ;
2011-11-01 22:47:34 +01:00
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
else {
if ( paramPartTokens . size ( ) < 2 ) {
printf ( " \n Invalid missing path and filter specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
}
if ( paramPartTokens . size ( ) < 3 ) {
printf ( " \n Invalid missing filter specified on commandline [%s] value [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 3 ? paramPartTokens [ 2 ] . c_str ( ) : NULL ) ) ;
}
//printParameterHelp(argv[0],false);
2011-11-01 22:47:34 +01:00
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
}
2012-04-02 08:07:32 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_MAPS ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LIST_MAPS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LIST_MAPS ] ) , & foundParamIndIndex ) ;
}
vector < string > pathList = config . getPathListForType ( ptMaps , " " ) ;
vector < string > maps = MapPreview : : findAllValidMaps ( pathList , " " , false , true ) ;
std : : sort ( maps . begin ( ) , maps . end ( ) ) ;
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string itemNameFilter = paramPartTokens [ 1 ] ;
printf ( " Using filter for maps list [%s] \n " , itemNameFilter . c_str ( ) ) ;
vector < string > filteredMaps ;
for ( unsigned int i = 0 ; i < maps . size ( ) ; + + i ) {
string mapName = maps [ i ] ;
if ( itemNameFilter . find ( " * " ) ! = itemNameFilter . npos ) {
if ( StartsWith ( mapName , itemNameFilter . substr ( 0 , itemNameFilter . find ( " * " ) ) ) = = true ) {
filteredMaps . push_back ( mapName ) ;
}
}
else if ( mapName = = itemNameFilter ) {
filteredMaps . push_back ( mapName ) ;
}
}
maps = filteredMaps ;
}
printf ( " Maps found: \n =========================================== \n " ) ;
for ( unsigned int i = 0 ; i < maps . size ( ) ; + + i ) {
string mapName = maps [ i ] ;
printf ( " %s \n " , mapName . c_str ( ) ) ;
}
2012-11-10 07:37:23 +01:00
printf ( " =========================================== \n Total: " MG_SIZE_T_SPECIFIER " \n " , maps . size ( ) ) ;
2012-04-02 08:07:32 +02:00
2012-07-18 01:04:30 +02:00
return 0 ;
2012-04-02 08:07:32 +02:00
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TECHTRESS ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LIST_TECHTRESS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LIST_TECHTRESS ] ) , & foundParamIndIndex ) ;
}
vector < string > pathList = config . getPathListForType ( ptTechs , " " ) ;
vector < string > results ;
findDirs ( pathList , results ) ;
bool showfactions = false ;
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string cmd = paramPartTokens [ 1 ] ;
if ( cmd = = " showfactions " ) {
showfactions = true ;
}
else {
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( " unknown command for techtreelist [ " + cmd + " ] " ) ;
2012-04-02 08:07:32 +02:00
}
printf ( " Using special command for techtree list [%s] \n " , cmd . c_str ( ) ) ;
}
printf ( " Techtrees found: \n =========================================== \n " ) ;
for ( unsigned int i = 0 ; i < results . size ( ) ; + + i ) {
string name = results [ i ] ;
for ( unsigned int j = 0 ; j < pathList . size ( ) ; + + j ) {
string techPath = pathList [ j ] ;
if ( techPath ! = " " ) {
endPathWithSlash ( techPath ) ;
}
vector < string > results2 ;
findDirs ( techPath + name + " /factions " , results2 , false , true ) ;
if ( results2 . empty ( ) = = false ) {
string downloadArchive = techPath + name + " .7z " ;
//printf("dl [%s] [%s]\n",name.c_str(),downloadArchive.c_str());
if ( fileExists ( downloadArchive ) = = true ) {
off_t fileSize = getFileSize ( downloadArchive ) ;
// convert to MB
double megaBytes = ( ( double ) fileSize / 1048576.0 ) ;
printf ( " %s [download archive %.2fMB] \n " , name . c_str ( ) , megaBytes ) ;
}
else {
printf ( " %s \n " , name . c_str ( ) ) ;
}
if ( showfactions = = true ) {
printf ( " --> Factions: \n " ) ;
for ( unsigned int k = 0 ; k < results2 . size ( ) ; + + k ) {
string name2 = results2 [ k ] ;
printf ( " --> %s \n " , name2 . c_str ( ) ) ;
}
2012-11-10 07:37:23 +01:00
printf ( " --> Total Factions: " MG_SIZE_T_SPECIFIER " \n " , results2 . size ( ) ) ;
2012-04-02 08:07:32 +02:00
break ;
}
}
}
}
2012-11-10 07:37:23 +01:00
printf ( " =========================================== \n Total Techtrees: " MG_SIZE_T_SPECIFIER " \n " , results . size ( ) ) ;
2012-04-02 08:07:32 +02:00
2012-07-18 01:04:30 +02:00
return 0 ;
2012-04-02 08:07:32 +02:00
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_SCENARIOS ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LIST_SCENARIOS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LIST_SCENARIOS ] ) , & foundParamIndIndex ) ;
}
vector < string > pathList = config . getPathListForType ( ptScenarios , " " ) ;
vector < string > results ;
findDirs ( pathList , results ) ;
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string itemNameFilter = paramPartTokens [ 1 ] ;
printf ( " Using filter for scenarios list [%s] \n " , itemNameFilter . c_str ( ) ) ;
vector < string > filtered ;
for ( unsigned int i = 0 ; i < results . size ( ) ; + + i ) {
string name = results [ i ] ;
if ( itemNameFilter . find ( " * " ) ! = itemNameFilter . npos ) {
if ( StartsWith ( name , itemNameFilter . substr ( 0 , itemNameFilter . find ( " * " ) ) ) = = true ) {
filtered . push_back ( name ) ;
}
}
else if ( name = = itemNameFilter ) {
filtered . push_back ( name ) ;
}
}
results = filtered ;
}
printf ( " Scenarios found: \n =========================================== \n " ) ;
for ( unsigned int i = 0 ; i < results . size ( ) ; + + i ) {
string name = results [ i ] ;
printf ( " %s \n " , name . c_str ( ) ) ;
}
2012-11-10 07:37:23 +01:00
printf ( " =========================================== \n Total: " MG_SIZE_T_SPECIFIER " \n " , results . size ( ) ) ;
2012-04-02 08:07:32 +02:00
2012-07-18 01:04:30 +02:00
return 0 ;
2012-04-02 08:07:32 +02:00
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TILESETS ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LIST_TILESETS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LIST_TILESETS ] ) , & foundParamIndIndex ) ;
}
vector < string > pathList = config . getPathListForType ( ptTilesets , " " ) ;
vector < string > results ;
findDirs ( pathList , results ) ;
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string itemNameFilter = paramPartTokens [ 1 ] ;
printf ( " Using filter for tilesets list [%s] \n " , itemNameFilter . c_str ( ) ) ;
vector < string > filtered ;
for ( unsigned int i = 0 ; i < results . size ( ) ; + + i ) {
string name = results [ i ] ;
if ( itemNameFilter . find ( " * " ) ! = itemNameFilter . npos ) {
if ( StartsWith ( name , itemNameFilter . substr ( 0 , itemNameFilter . find ( " * " ) ) ) = = true ) {
filtered . push_back ( name ) ;
}
}
else if ( name = = itemNameFilter ) {
filtered . push_back ( name ) ;
}
}
results = filtered ;
}
printf ( " Tilesets found: \n =========================================== \n " ) ;
for ( unsigned int i = 0 ; i < results . size ( ) ; + + i ) {
string name = results [ i ] ;
for ( unsigned int j = 0 ; j < pathList . size ( ) ; + + j ) {
string tilesetPath = pathList [ j ] ;
if ( tilesetPath ! = " " ) {
endPathWithSlash ( tilesetPath ) ;
}
if ( fileExists ( tilesetPath + name + " / " + name + " .xml " ) = = true ) {
string downloadArchive = tilesetPath + name + " .7z " ;
//printf("dl [%s] [%s]\n",name.c_str(),downloadArchive.c_str());
if ( fileExists ( downloadArchive ) = = true ) {
off_t fileSize = getFileSize ( downloadArchive ) ;
// convert to MB
double megaBytes = ( ( double ) fileSize / 1048576.0 ) ;
printf ( " %s [download archive %.2fMB] \n " , name . c_str ( ) , megaBytes ) ;
}
else {
printf ( " %s \n " , name . c_str ( ) ) ;
}
break ;
}
}
}
2012-11-10 07:37:23 +01:00
printf ( " =========================================== \n Total: " MG_SIZE_T_SPECIFIER " \n " , results . size ( ) ) ;
2012-04-02 08:07:32 +02:00
2012-07-18 01:04:30 +02:00
return 0 ;
2012-04-02 08:07:32 +02:00
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_LIST_TUTORIALS ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LIST_TUTORIALS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LIST_TUTORIALS ] ) , & foundParamIndIndex ) ;
}
vector < string > pathList = config . getPathListForType ( ptTutorials , " " ) ;
vector < string > results ;
findDirs ( pathList , results ) ;
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string itemNameFilter = paramPartTokens [ 1 ] ;
printf ( " Using filter for tutorials list [%s] \n " , itemNameFilter . c_str ( ) ) ;
vector < string > filtered ;
for ( unsigned int i = 0 ; i < results . size ( ) ; + + i ) {
string name = results [ i ] ;
if ( itemNameFilter . find ( " * " ) ! = itemNameFilter . npos ) {
if ( StartsWith ( name , itemNameFilter . substr ( 0 , itemNameFilter . find ( " * " ) ) ) = = true ) {
filtered . push_back ( name ) ;
}
}
else if ( name = = itemNameFilter ) {
filtered . push_back ( name ) ;
}
}
results = filtered ;
}
printf ( " Tutorials found: \n =========================================== \n " ) ;
for ( unsigned int i = 0 ; i < results . size ( ) ; + + i ) {
string name = results [ i ] ;
for ( unsigned int j = 0 ; j < pathList . size ( ) ; + + j ) {
string tutorialsPath = pathList [ j ] ;
if ( tutorialsPath ! = " " ) {
endPathWithSlash ( tutorialsPath ) ;
}
if ( fileExists ( tutorialsPath + name + " / " + name + " .xml " ) = = true ) {
string downloadArchive = tutorialsPath + name + " .7z " ;
//printf("dl [%s] [%s]\n",name.c_str(),downloadArchive.c_str());
if ( fileExists ( downloadArchive ) = = true ) {
off_t fileSize = getFileSize ( downloadArchive ) ;
// convert to MB
double megaBytes = ( ( double ) fileSize / 1048576.0 ) ;
printf ( " %s [download archive %.2fMB] \n " , name . c_str ( ) , megaBytes ) ;
}
else {
printf ( " %s \n " , name . c_str ( ) ) ;
}
break ;
}
}
}
2012-11-10 07:37:23 +01:00
printf ( " =========================================== \n Total: " MG_SIZE_T_SPECIFIER " \n " , results . size ( ) ) ;
2012-04-02 08:07:32 +02:00
2012-07-18 01:04:30 +02:00
return 0 ;
2012-04-02 08:07:32 +02:00
}
2011-11-01 22:47:34 +01:00
program = new Program ( ) ;
2012-03-28 00:44:16 +02:00
mainProgram = program ;
2012-03-13 02:34:14 +01:00
renderer . setProgram ( program ) ;
2011-05-19 00:04:45 +02:00
2012-03-28 00:44:16 +02:00
if ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled = = true ) {
renderer . setAllowRenderUnitTitles ( SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugPathFinder , " In [%s::%s Line: %d] renderer.setAllowRenderUnitTitles = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , SystemFlags : : getSystemSettingType ( SystemFlags : : debugPathFinder ) . enabled ) ;
}
renderer . setAllowRenderUnitTitles ( true ) ;
string screenShotsPath = userData + GameConstants : : folder_path_screenshots ;
if ( isdir ( screenShotsPath . c_str ( ) ) = = false ) {
createDirectoryPaths ( screenShotsPath ) ;
}
// Cache Player textures - START
string data_path = getGameReadWritePath ( GameConstants : : path_data_CacheLookupKey ) ;
std : : map < int , Texture2D * > & crcPlayerTextureCache = CacheManager : : getCachedItem < std : : map < int , Texture2D * > > ( GameConstants : : playerTextureCacheLookupKey ) ;
for ( int index = 0 ; index < GameConstants : : maxPlayers ; + + index ) {
//string playerTexture = data_path + "data/core/faction_textures/faction" + intToStr(index) + ".tga";
string playerTexture = getGameCustomCoreDataPath ( data_path , " data/core/faction_textures/faction " + intToStr ( index ) + " .tga " ) ;
if ( fileExists ( playerTexture ) = = true ) {
Texture2D * texture = Renderer : : getInstance ( ) . newTexture2D ( rsGlobal ) ;
if ( texture ) {
texture - > load ( playerTexture ) ;
}
crcPlayerTextureCache [ index ] = texture ;
}
else {
crcPlayerTextureCache [ index ] = NULL ;
}
}
// Cache Player textures - END
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-11-01 22:47:34 +01:00
mainWindow = new MainWindow ( program ) ;
2011-05-19 00:04:45 +02:00
mainWindow - > setUseDefaultCursorOnly ( config . getBool ( " No2DMouseRendering " , " false " ) ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-09-16 02:34:14 +02:00
GameSettings startupGameSettings ;
2011-05-19 00:04:45 +02:00
//parse command line
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_SERVER ] ) = = true ) {
program - > initServer ( mainWindow , false , true ) ;
2012-03-29 02:43:03 +02:00
gameInitialized = true ;
2011-05-19 00:04:45 +02:00
}
2011-09-24 09:46:56 +02:00
else if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_MASTERSERVER_MODE ] ) ) = = true ) {
program - > initServer ( mainWindow , false , true , true ) ;
2012-03-29 02:43:03 +02:00
gameInitialized = true ;
2011-09-24 09:46:56 +02:00
}
2011-05-19 00:04:45 +02:00
else if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_AUTOSTART_LASTGAME ] ) ) = = true ) {
program - > initServer ( mainWindow , true , false ) ;
2012-03-29 02:43:03 +02:00
gameInitialized = true ;
2011-05-19 00:04:45 +02:00
}
2012-03-13 00:08:22 +01:00
else if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_AUTOSTART_LAST_SAVED_GAME ] ) ) = = true ) {
2012-03-15 16:57:21 +01:00
string fileName = " " ;
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_AUTOSTART_LAST_SAVED_GAME ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex > = 0 ) {
string loadfileName = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( loadfileName , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
fileName = paramPartTokens [ 1 ] ;
2012-03-19 22:35:54 +01:00
if ( fileExists ( fileName ) = = false ) {
// Save the file now
string saveGameFile = " saved/ " + fileName ;
if ( getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) ! = " " ) {
saveGameFile = getGameReadWritePath ( GameConstants : : path_logs_CacheLookupKey ) + saveGameFile ;
}
else {
2012-03-28 00:44:16 +02:00
// string userData = config.getString("UserData_Root","");
// if(userData != "") {
// endPathWithSlash(userData);
// }
2012-03-19 22:35:54 +01:00
saveGameFile = userData + saveGameFile ;
}
if ( fileExists ( saveGameFile ) = = true ) {
fileName = saveGameFile ;
}
}
2012-03-15 16:57:21 +01:00
if ( fileExists ( fileName ) = = false ) {
char szBuf [ 8096 ] = " " ;
2012-10-19 03:31:20 +02:00
snprintf ( szBuf , 8096 , " File specified for loading a saved game cannot be found: [%s] " , fileName . c_str ( ) ) ;
2012-03-15 16:57:21 +01:00
printf ( " \n \n ====================================================================================== \n %s \n ====================================================================================== \n \n \n " , szBuf ) ;
2012-04-14 23:21:09 +02:00
throw megaglest_runtime_error ( szBuf ) ;
2012-03-15 16:57:21 +01:00
}
}
}
program - > initSavedGame ( mainWindow , false , fileName ) ;
2012-03-29 02:43:03 +02:00
gameInitialized = true ;
2012-03-13 00:08:22 +01:00
}
2011-09-16 02:34:14 +02:00
else if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_PREVIEW_MAP ] ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_PREVIEW_MAP ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_PREVIEW_MAP ] ) , & foundParamIndIndex ) ;
}
string mapName = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( mapName , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string autoloadMapName = paramPartTokens [ 1 ] ;
GameSettings * gameSettings = & startupGameSettings ;
2011-12-02 17:07:59 +01:00
//int factionCount= 0;
2011-09-16 02:34:14 +02:00
gameSettings - > setMap ( autoloadMapName ) ;
gameSettings - > setTileset ( " forest " ) ;
gameSettings - > setTech ( " megapack " ) ;
gameSettings - > setDefaultUnits ( false ) ;
gameSettings - > setDefaultResources ( false ) ;
gameSettings - > setDefaultVictoryConditions ( true ) ;
gameSettings - > setFogOfWar ( false ) ;
gameSettings - > setAllowObservers ( true ) ;
gameSettings - > setPathFinderType ( pfBasic ) ;
for ( int i = 0 ; i < GameConstants : : maxPlayers ; + + i ) {
ControlType ct = ctClosed ;
2012-09-21 17:03:13 +02:00
gameSettings - > setNetworkPlayerStatuses ( i , npst_None ) ;
2011-09-16 02:34:14 +02:00
gameSettings - > setFactionControl ( i , ct ) ;
gameSettings - > setStartLocationIndex ( i , i ) ;
gameSettings - > setResourceMultiplierIndex ( i , 10 ) ;
gameSettings - > setNetworkPlayerName ( i , " Closed " ) ;
}
ControlType ct = ctHuman ;
2012-09-21 17:03:13 +02:00
gameSettings - > setNetworkPlayerStatuses ( 0 , npst_None ) ;
2011-09-16 02:34:14 +02:00
gameSettings - > setFactionControl ( 0 , ct ) ;
gameSettings - > setFactionTypeName ( 0 , formatString ( GameConstants : : OBSERVER_SLOTNAME ) ) ;
gameSettings - > setTeam ( 0 , GameConstants : : maxPlayers + fpt_Observer - 1 ) ;
gameSettings - > setStartLocationIndex ( 0 , 0 ) ;
gameSettings - > setNetworkPlayerName ( 0 , GameConstants : : OBSERVER_SLOTNAME ) ;
gameSettings - > setFactionCount ( 1 ) ;
Config & config = Config : : getInstance ( ) ;
gameSettings - > setEnableServerControlledAI ( config . getBool ( " ServerControlledAI " , " true " ) ) ;
gameSettings - > setNetworkFramePeriod ( config . getInt ( " NetworkSendFrameCount " , " 20 " ) ) ;
program - > initServer ( mainWindow , gameSettings ) ;
2012-03-29 02:43:03 +02:00
gameInitialized = true ;
2011-09-16 02:34:14 +02:00
}
else {
printf ( " \n Invalid map name specified on commandline [%s] map [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( argv [ 0 ] , foundInvalidArgs ) ;
delete mainWindow ;
2013-02-01 18:25:49 +01:00
mainWindow = NULL ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-09-16 02:34:14 +02:00
}
}
2012-09-25 23:52:23 +02:00
else if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_CONNECT ] ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_CONNECT ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_CONNECT ] ) , & foundParamIndIndex ) ;
}
string serverToConnectTo = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( serverToConnectTo , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string autoConnectServer = paramPartTokens [ 1 ] ;
2012-10-06 02:25:13 +02:00
2012-10-06 14:56:53 +02:00
int port = config . getInt ( " PortServer " , intToStr ( GameConstants : : serverPort ) . c_str ( ) ) ;
2012-09-25 23:52:23 +02:00
vector < string > paramPartTokens2 ;
Tokenize ( autoConnectServer , paramPartTokens2 , " : " ) ;
autoConnectServer = paramPartTokens2 [ 0 ] ;
if ( paramPartTokens2 . size ( ) > = 2 & & paramPartTokens2 [ 1 ] . length ( ) > 0 ) {
port = strToInt ( paramPartTokens2 [ 1 ] ) ;
}
printf ( " Connecting to host [%s] using port: %d \n " , autoConnectServer . c_str ( ) , port ) ;
2012-10-06 02:25:13 +02:00
if ( autoConnectServer = = " auto-connect " ) {
program - > initClientAutoFindHost ( mainWindow ) ;
}
else {
program - > initClient ( mainWindow , autoConnectServer , port ) ;
}
2012-09-25 23:52:23 +02:00
gameInitialized = true ;
}
else {
printf ( " \n Invalid host specified on commandline [%s] host [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( argv [ 0 ] , foundInvalidArgs ) ;
delete mainWindow ;
2013-02-01 18:25:49 +01:00
mainWindow = NULL ;
2012-09-25 23:52:23 +02:00
return 1 ;
}
}
2011-05-19 00:04:45 +02:00
else if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_CLIENT ] ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_CLIENT ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_CLIENT ] ) , & foundParamIndIndex ) ;
}
string serverToConnectTo = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( serverToConnectTo , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string autoConnectServer = paramPartTokens [ 1 ] ;
2012-03-28 00:44:16 +02:00
2012-10-06 02:25:13 +02:00
if ( autoConnectServer = = " auto-connect " ) {
program - > initClientAutoFindHost ( mainWindow ) ;
}
else {
program - > initClient ( mainWindow , autoConnectServer ) ;
}
2012-03-29 02:43:03 +02:00
gameInitialized = true ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " \n Invalid host specified on commandline [%s] host [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( argv [ 0 ] , foundInvalidArgs ) ;
delete mainWindow ;
2013-02-01 18:25:49 +01:00
mainWindow = NULL ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
}
else if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LOADSCENARIO ] ) ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LOADSCENARIO ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_LOADSCENARIO ] ) , & foundParamIndIndex ) ;
}
string scenarioName = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( scenarioName , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string autoloadScenarioName = paramPartTokens [ 1 ] ;
2012-03-28 00:44:16 +02:00
2011-05-19 00:04:45 +02:00
program - > initScenario ( mainWindow , autoloadScenarioName ) ;
2012-03-29 02:43:03 +02:00
gameInitialized = true ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " \n Invalid scenario name specified on commandline [%s] scenario [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( argv [ 0 ] , foundInvalidArgs ) ;
delete mainWindow ;
2013-02-01 18:25:49 +01:00
mainWindow = NULL ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
}
else {
program - > initNormal ( mainWindow ) ;
}
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
// Initialize Renderer
2011-11-01 18:38:51 +01:00
//Renderer &renderer= Renderer::getInstance();
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] OpenGL Info: \n %s \n " , __FILE__ , __FUNCTION__ , __LINE__ , renderer . getGlInfo ( ) . c_str ( ) ) ;
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_OPENGL_INFO ] ) = = true ) {
//Renderer &renderer= Renderer::getInstance();
printf ( " %s " , renderer . getGlInfo ( ) . c_str ( ) ) ;
printf ( " %s " , renderer . getGlMoreInfo ( ) . c_str ( ) ) ;
delete mainWindow ;
2013-02-01 18:25:49 +01:00
mainWindow = NULL ;
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_CONVERT_MODELS ] ) = = true ) {
int foundParamIndIndex = - 1 ;
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_CONVERT_MODELS ] ) + string ( " = " ) , & foundParamIndIndex ) ;
if ( foundParamIndIndex < 0 ) {
hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_CONVERT_MODELS ] ) , & foundParamIndIndex ) ;
}
string paramValue = argv [ foundParamIndIndex ] ;
vector < string > paramPartTokens ;
Tokenize ( paramValue , paramPartTokens , " = " ) ;
if ( paramPartTokens . size ( ) > = 2 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
string modelFile = paramPartTokens [ 1 ] ;
printf ( " About to convert model(s) [%s] \n " , modelFile . c_str ( ) ) ;
string textureFormat = " " ;
if ( paramPartTokens . size ( ) > = 3 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
textureFormat = paramPartTokens [ 2 ] ;
printf ( " About to convert using texture format [%s] \n " , textureFormat . c_str ( ) ) ;
}
bool keepsmallest = false ;
if ( paramPartTokens . size ( ) > = 4 & & paramPartTokens [ 1 ] . length ( ) > 0 ) {
keepsmallest = ( paramPartTokens [ 3 ] = = " keepsmallest " ) ;
printf ( " About to convert using keepsmallest = %d \n " , keepsmallest ) ;
}
2012-03-03 19:40:18 +01:00
//CoreData::getInstance().load();
2011-05-19 00:04:45 +02:00
showCursor ( true ) ;
mainWindow - > setUseDefaultCursorOnly ( true ) ;
const Metrics & metrics = Metrics : : getInstance ( ) ;
renderer . clearBuffers ( ) ;
renderer . clearZBuffer ( ) ;
renderer . reset2d ( ) ;
2012-03-03 19:40:18 +01:00
if ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ! = NULL ) {
renderer . renderText3D (
" Please wait, converting models... " ,
CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ,
Vec3f ( 1.f , 1.f , 0.f ) , ( metrics . getScreenW ( ) / 2 ) - 400 ,
( metrics . getScreenH ( ) / 2 ) , true ) ;
}
else {
renderer . renderText (
" Please wait, converting models... " ,
CoreData : : getInstance ( ) . getMenuFontBig ( ) ,
Vec3f ( 1.f , 1.f , 0.f ) , ( metrics . getScreenW ( ) / 2 ) - 400 ,
( metrics . getScreenH ( ) / 2 ) , true ) ;
}
2011-05-19 00:04:45 +02:00
renderer . swapBuffers ( ) ;
std : : vector < string > models ;
if ( isdir ( modelFile . c_str ( ) ) = = true ) {
models = getFolderTreeContentsListRecursively ( modelFile , " .g3d " ) ;
}
else {
models . push_back ( modelFile ) ;
}
sleep ( 0 ) ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2011-05-19 00:04:45 +02:00
SDL_PumpEvents ( ) ;
2012-07-18 01:04:30 +02:00
int result = 0 ;
2012-10-19 03:31:20 +02:00
char szTextBuf [ 8096 ] = " " ;
2011-05-19 00:04:45 +02:00
for ( unsigned int i = 0 ; i < models . size ( ) ; + + i ) {
string & file = models [ i ] ;
bool modelLoadedOk = false ;
renderer . clearBuffers ( ) ;
renderer . clearZBuffer ( ) ;
renderer . reset2d ( ) ;
2012-11-10 07:37:23 +01:00
snprintf ( szTextBuf , 8096 , " Please wait, converting models [%u of " MG_SIZE_T_SPECIFIER " ] ... " , i , models . size ( ) ) ;
2012-03-03 19:40:18 +01:00
if ( CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ! = NULL ) {
renderer . renderText3D (
szTextBuf ,
CoreData : : getInstance ( ) . getMenuFontBig3D ( ) ,
Vec3f ( 1.f , 1.f , 0.f ) , ( metrics . getScreenW ( ) / 2 ) - 400 ,
( metrics . getScreenH ( ) / 2 ) , true ) ;
}
else {
renderer . renderText (
szTextBuf ,
CoreData : : getInstance ( ) . getMenuFontBig ( ) ,
Vec3f ( 1.f , 1.f , 0.f ) , ( metrics . getScreenW ( ) / 2 ) - 400 ,
( metrics . getScreenH ( ) / 2 ) , true ) ;
}
2011-05-19 00:04:45 +02:00
renderer . swapBuffers ( ) ;
sleep ( 0 ) ;
2012-09-22 22:13:57 +02:00
Shared : : Platform : : Window : : handleEvent ( ) ;
2011-05-19 00:04:45 +02:00
SDL_PumpEvents ( ) ;
Model * model = renderer . newModel ( rsGlobal ) ;
try {
2012-11-10 07:37:23 +01:00
printf ( " About to load model [%s] [%u of " MG_SIZE_T_SPECIFIER " ] \n " , file . c_str ( ) , i , models . size ( ) ) ;
2011-05-19 00:04:45 +02:00
model - > load ( file ) ;
modelLoadedOk = true ;
}
catch ( const exception & ex ) {
2012-07-18 01:04:30 +02:00
result = 1 ;
2011-05-19 00:04:45 +02:00
printf ( " ERROR loading model [%s] message [%s] \n " , file . c_str ( ) , ex . what ( ) ) ;
}
if ( modelLoadedOk = = true ) {
printf ( " About to save converted model [%s] \n " , file . c_str ( ) ) ;
model - > save ( file , textureFormat , keepsmallest ) ;
}
Renderer : : getInstance ( ) . endModel ( rsGlobal , model ) ;
}
delete mainWindow ;
2013-02-01 18:25:49 +01:00
mainWindow = NULL ;
2012-07-18 01:04:30 +02:00
return result ;
2011-05-19 00:04:45 +02:00
}
else {
printf ( " \n Invalid model specified on commandline [%s] texture [%s] \n \n " , argv [ foundParamIndIndex ] , ( paramPartTokens . size ( ) > = 2 ? paramPartTokens [ 1 ] . c_str ( ) : NULL ) ) ;
printParameterHelp ( argv [ 0 ] , foundInvalidArgs ) ;
delete mainWindow ;
2013-02-01 18:25:49 +01:00
mainWindow = NULL ;
2012-07-18 01:04:30 +02:00
return 1 ;
2011-05-19 00:04:45 +02:00
}
}
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TECHTREES ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_FACTIONS ] ) = = true | |
hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_SCENARIO ] ) = = true ) {
runTechValidationReport ( argc , argv ) ;
delete mainWindow ;
2013-02-01 18:25:49 +01:00
mainWindow = NULL ;
2012-07-18 01:04:30 +02:00
return 0 ;
2011-05-19 00:04:45 +02:00
}
2013-06-13 00:49:47 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_TRANSLATE_TECHTREES ] ) = = true ) {
runTechTranslationExtraction ( argc , argv ) ;
delete mainWindow ;
mainWindow = NULL ;
return 0 ;
}
2012-04-03 21:35:22 +02:00
if ( hasCommandArgument ( argc , argv , GAME_ARGS [ GAME_ARG_VALIDATE_TILESET ] ) = = true ) {
runTilesetValidationReport ( argc , argv ) ;
delete mainWindow ;
2013-02-01 18:25:49 +01:00
mainWindow = NULL ;
2012-07-18 01:04:30 +02:00
return 0 ;
2012-04-03 21:35:22 +02:00
}
2011-05-19 00:04:45 +02:00
gameInitialized = true ;
// Setup the screenshots folder
2012-03-28 00:44:16 +02:00
// if(userData != "") {
// endPathWithSlash(userData);
// }
2011-05-19 00:04:45 +02:00
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
CheckForDuplicateData ( ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//throw "BLAH!";
// START Test out SIGSEGV error handling
//int *foo = (int*)-1; // make a bad pointer
//printf("%d\n", *foo); // causes segfault
// END
bool startCRCPrecacheThread = config . getBool ( " PreCacheCRCThread " , " true " ) ;
//printf("### In [%s::%s Line: %d] precache thread enabled = %d SystemFlags::VERBOSE_MODE_ENABLED = %d\n",__FILE__,__FUNCTION__,__LINE__,startCRCPrecacheThread,SystemFlags::VERBOSE_MODE_ENABLED);
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] precache thread enabled = %d \n " , __FILE__ , __FUNCTION__ , __LINE__ , startCRCPrecacheThread ) ;
if ( startCRCPrecacheThread = = true ) {
vector < string > techDataPaths = config . getPathListForType ( ptTechs ) ;
2013-01-23 15:51:28 +01:00
static string mutexOwnerId = string ( extractFileFromDirectoryPath ( __FILE__ ) . c_str ( ) ) + string ( " _ " ) + intToStr ( __LINE__ ) ;
2011-05-19 00:04:45 +02:00
preCacheThread = new FileCRCPreCacheThread ( ) ;
2013-01-23 15:51:28 +01:00
preCacheThread - > setUniqueID ( mutexOwnerId ) ;
2011-05-19 00:04:45 +02:00
preCacheThread - > setTechDataPaths ( techDataPaths ) ;
//preCacheThread->setFileCRCPreCacheThreadCallbackInterface(&preCacheThreadGame);
preCacheThread - > start ( ) ;
}
2012-12-28 02:02:09 +01:00
std : : auto_ptr < NavtiveLanguageNameListCacheGenerator > lngCacheGen ;
std : : auto_ptr < SimpleTaskThread > languageCacheGen ;
bool startNativeLanguageNamesPrecacheThread = config . getBool ( " PreCacheNativeLanguageNamesThread " , " true " ) ;
if ( startNativeLanguageNamesPrecacheThread = = true & &
GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
lngCacheGen . reset ( new NavtiveLanguageNameListCacheGenerator ( ) ) ;
languageCacheGen . reset ( new SimpleTaskThread ( lngCacheGen . get ( ) , 1 ) ) ;
languageCacheGen - > start ( ) ;
}
2011-05-19 00:04:45 +02:00
// test
//Shared::Platform::MessageBox(NULL,"Mark's test.","Test",0);
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error("test!");
2011-05-19 00:04:45 +02:00
//ExceptionHandler::DisplayMessage("test!", false);
//Lang &lang= Lang::getInstance();
//string test = lang.get("ExitGameServer?");
//printf("[%s]",test.c_str());
//time_t lastTextureLoadEvent = time(NULL);
2011-09-27 12:16:09 +02:00
// Check for commands being input from stdin
string command = " " ;
2011-11-16 06:20:35 +01:00
# ifndef WIN32
2011-09-27 12:16:09 +02:00
pollfd cinfd [ 1 ] ;
2011-11-16 06:20:35 +01:00
# else
HANDLE h = 0 ;
# endif
if ( disableheadless_console = = false ) {
# ifndef WIN32
// Theoretically this should always be 0, but one fileno call isn't going to hurt, and if
// we try to run somewhere that stdin isn't fd 0 then it will still just work
cinfd [ 0 ] . fd = fileno ( stdin ) ;
cinfd [ 0 ] . events = POLLIN ;
# else
h = GetStdHandle ( STD_INPUT_HANDLE ) ;
2012-01-20 05:15:13 +01:00
//DWORD dwMode;
//GetConsoleMode(h, &dwMode);
//SetConsoleMode(h, dwMode & ~ENABLE_MOUSE_INPUT);
FlushConsoleInputBuffer ( h ) ;
2011-11-16 06:20:35 +01:00
# endif
}
2011-09-27 12:16:09 +02:00
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 12:16:09 +02:00
printf ( " Headless server is now running... \n " ) ;
}
2012-04-14 23:21:09 +02:00
//throw megaglest_runtime_error("Test!");
2013-01-31 21:17:52 +01:00
//printf("About to throw an exception...\n");
//throw 123;
2011-10-03 20:34:59 +02:00
2011-05-19 00:04:45 +02:00
//main loop
2012-09-22 22:13:57 +02:00
while ( program - > isShutdownApplicationEnabled ( ) = = false & & Shared : : Platform : : Window : : handleEvent ( ) ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-11-16 06:20:35 +01:00
if ( disableheadless_console = = false ) {
2011-09-27 12:16:09 +02:00
# ifndef WIN32
2011-11-16 06:20:35 +01:00
int pollresult = poll ( cinfd , 1 , 0 ) ;
int pollerror = errno ;
if ( pollresult )
2011-09-27 12:16:09 +02:00
# else
2011-11-16 06:20:35 +01:00
// This is problematic because input on Windows is not line-buffered so this will return
// even if getline may block. I haven't found a good way to fix it, so for the moment
// I just strongly suggest only running the server from the Python frontend, which does
// line buffer input. This does work okay as long as the user doesn't enter characters
// without pressing enter, and then try to end the server another way (say a remote
// console command), in which case we'll still be waiting for the stdin EOL and hang.
2012-01-20 05:15:13 +01:00
DWORD saveMode ;
GetConsoleMode ( h , & saveMode ) ;
DWORD dwMode = saveMode ;
dwMode & = ~ ENABLE_MOUSE_INPUT ;
dwMode & = ~ ENABLE_WINDOW_INPUT ;
SetConsoleMode ( h , dwMode ) ;
bool gotData = ( WaitForSingleObject ( h , 0 ) = = WAIT_OBJECT_0 ) ;
SetConsoleMode ( h , saveMode ) ;
if ( gotData = = true )
2011-09-27 12:16:09 +02:00
# endif
2011-11-16 06:20:35 +01:00
{
2011-11-16 05:03:17 +01:00
2012-10-06 09:06:40 +02:00
2012-01-20 05:15:13 +01:00
# ifdef WIN32
2012-10-06 09:06:40 +02:00
bool skip = true ;
2012-01-20 05:15:13 +01:00
DWORD nNumberOfCharsToRead = 1024 ;
DWORD nRead = 0 ;
INPUT_RECORD irInRec [ 1025 ] ;
PeekConsoleInput ( h , & irInRec [ 0 ] , nNumberOfCharsToRead , & nRead ) ;
for ( int i = 0 ; i < nRead ; + + i ) {
INPUT_RECORD & inr = irInRec [ i ] ;
//printf("inr.EventType = %d\n",inr.EventType);
if ( inr . EventType = = KEY_EVENT ) {
if ( inr . Event . KeyEvent . bKeyDown ) {
char cHoldKey = inr . Event . KeyEvent . uChar . AsciiChar ;
if ( cHoldKey = = ' \r ' ) {
skip = false ;
break ;
}
}
}
2011-11-16 06:20:35 +01:00
}
2012-01-20 05:15:13 +01:00
# else
2012-10-06 09:06:40 +02:00
bool skip = false ;
2012-01-20 05:15:13 +01:00
# endif
if ( skip = = false ) {
getline ( cin , command ) ;
cin . clear ( ) ;
printf ( " server command [%s] \n " , command . c_str ( ) ) ;
if ( command = = " quit " ) {
break ;
}
2011-11-16 05:03:17 +01:00
# ifndef WIN32
2012-01-20 05:15:13 +01:00
if ( cinfd [ 0 ] . revents & POLLNVAL ) {
printf ( " invalid file descriptor \n " ) ;
}
if ( cinfd [ 0 ] . revents & POLLERR ) {
printf ( " error in file descriptor \n " ) ;
}
if ( cinfd [ 0 ] . revents & POLLHUP ) {
printf ( " hang up in file descriptor \n " ) ;
}
2011-12-01 20:45:46 +01:00
2012-01-20 05:15:13 +01:00
if ( pollresult < 0 ) {
printf ( " pollresult = %d errno = %d [%s] \n " , pollresult , pollerror , strerror ( pollerror ) ) ;
2011-11-16 05:03:17 +01:00
2012-01-20 05:15:13 +01:00
cinfd [ 0 ] . fd = fileno ( stdin ) ;
cinfd [ 0 ] . events = POLLIN ;
}
2011-11-16 05:03:17 +01:00
# endif
2012-01-20 05:15:13 +01:00
}
2011-11-16 06:20:35 +01:00
}
2011-09-27 12:16:09 +02:00
}
//printf("looping\n");
}
2011-05-19 00:04:45 +02:00
program - > loop ( ) ;
2011-10-25 20:39:11 +02:00
2011-05-19 00:04:45 +02:00
// Because OpenGL really doesn't do multi-threading well
// if(difftime(time(NULL),lastTextureLoadEvent) >= 3) {
// lastTextureLoadEvent = time(NULL);
// vector<Texture2D *> textureList = preCacheThread->getPendingTextureList(1);
// for(unsigned int i = 0; i < textureList.size(); ++i) {
// Texture2D * factionLogo = textureList[i];
// if(factionLogo != NULL) {
// printf("\n\n\n\n|||||||||||||||||||||||||| Load texture [%s]\n",factionLogo->getPath().c_str());
2012-09-25 09:05:52 +02:00
// //Renderer::findTexture(factionLogo);
2011-05-19 00:04:45 +02:00
// renderer.initTexture(rsGlobal,factionLogo);
// }
// }
// }
}
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = true ) {
2011-09-27 12:16:09 +02:00
printf ( " \n Headless server is about to quit... \n " ) ;
}
2011-05-19 00:04:45 +02:00
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] starting normal application shutdown \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-10-22 00:07:34 +02:00
soundThreadManager = program - > getSoundThreadManager ( true ) ;
if ( soundThreadManager ) {
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . stopAllSounds ( shutdownFadeSoundMilliseconds ) ;
chronoshutdownFadeSound . start ( ) ;
}
}
2011-05-19 00:04:45 +02:00
cleanupCRCThread ( ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
showCursor ( true ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
}
2012-04-14 23:21:09 +02:00
catch ( const megaglest_runtime_error & e ) {
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
soundThreadManager = ( program ! = NULL ? program - > getSoundThreadManager ( true ) : NULL ) ;
if ( soundThreadManager ) {
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . stopAllSounds ( shutdownFadeSoundMilliseconds ) ;
chronoshutdownFadeSound . start ( ) ;
}
}
ExceptionHandler : : handleRuntimeError ( e ) ;
}
2011-10-22 00:07:34 +02:00
catch ( const exception & e ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-11-02 18:17:28 +01:00
soundThreadManager = ( program ! = NULL ? program - > getSoundThreadManager ( true ) : NULL ) ;
2011-10-22 00:07:34 +02:00
if ( soundThreadManager ) {
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . stopAllSounds ( shutdownFadeSoundMilliseconds ) ;
chronoshutdownFadeSound . start ( ) ;
}
}
2012-04-14 23:21:09 +02:00
ExceptionHandler : : handleRuntimeError ( e . what ( ) , true ) ;
2011-05-19 00:04:45 +02:00
}
2011-10-22 00:07:34 +02:00
catch ( const char * e ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-11-02 18:17:28 +01:00
soundThreadManager = ( program ! = NULL ? program - > getSoundThreadManager ( true ) : NULL ) ;
2011-10-22 00:07:34 +02:00
if ( soundThreadManager ) {
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . stopAllSounds ( shutdownFadeSoundMilliseconds ) ;
chronoshutdownFadeSound . start ( ) ;
}
}
2012-04-14 23:21:09 +02:00
ExceptionHandler : : handleRuntimeError ( e , true ) ;
2011-05-19 00:04:45 +02:00
}
2011-10-22 00:07:34 +02:00
catch ( const string & ex ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-11-02 18:17:28 +01:00
soundThreadManager = ( program ! = NULL ? program - > getSoundThreadManager ( true ) : NULL ) ;
2011-10-22 00:07:34 +02:00
if ( soundThreadManager ) {
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . stopAllSounds ( shutdownFadeSoundMilliseconds ) ;
chronoshutdownFadeSound . start ( ) ;
}
}
2012-04-14 23:21:09 +02:00
ExceptionHandler : : handleRuntimeError ( ex . c_str ( ) , true ) ;
2011-05-19 00:04:45 +02:00
}
2013-01-31 21:17:52 +01:00
# if !defined(HAVE_GOOGLE_BREAKPAD)
2011-10-22 00:07:34 +02:00
catch ( . . . ) {
2011-12-02 23:04:02 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
2011-11-02 18:17:28 +01:00
soundThreadManager = ( program ! = NULL ? program - > getSoundThreadManager ( true ) : NULL ) ;
2011-10-22 00:07:34 +02:00
if ( soundThreadManager ) {
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
soundRenderer . stopAllSounds ( shutdownFadeSoundMilliseconds ) ;
chronoshutdownFadeSound . start ( ) ;
}
}
2013-01-18 02:12:32 +01:00
ExceptionHandler : : handleRuntimeError ( " Unknown error [main]! " , true ) ;
2011-05-19 00:04:45 +02:00
}
2013-01-31 21:17:52 +01:00
# endif
2013-01-18 05:01:43 +01:00
2011-05-19 00:04:45 +02:00
cleanupCRCThread ( ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
2011-05-19 00:04:45 +02:00
delete mainWindow ;
mainWindow = NULL ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
//showCursor(true);
//restoreVideoMode(true);
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
GraphicComponent : : clearRegisteredComponents ( ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
SystemFlags : : OutputDebug ( SystemFlags : : debugSystem , " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
2011-10-22 00:07:34 +02:00
if ( soundThreadManager ) {
2011-11-11 19:15:46 +01:00
SoundRenderer & soundRenderer = SoundRenderer : : getInstance ( ) ;
if ( Config : : getInstance ( ) . getString ( " FactorySound " , " " ) ! = " None " & &
soundRenderer . isVolumeTurnedOff ( ) = = false ) {
//printf("chronoshutdownFadeSound.getMillis() = %llu\n",chronoshutdownFadeSound.getMillis());
for ( ; chronoshutdownFadeSound . getMillis ( ) < = shutdownFadeSoundMilliseconds ; ) {
sleep ( 10 ) ;
}
2011-10-22 00:07:34 +02:00
}
BaseThread : : shutdownAndWait ( soundThreadManager ) ;
delete soundThreadManager ;
soundThreadManager = NULL ;
}
2013-05-04 01:11:57 +02:00
//printf("Closing IRC CLient %d\n",__LINE__);
2011-05-19 00:04:45 +02:00
return 0 ;
}
2012-04-14 23:21:09 +02:00
# if defined(__GNUC__) && !defined(__FreeBSD__) && !defined(BSD)
void handleSIGSEGV ( int sig ) {
2012-10-19 03:31:20 +02:00
char szBuf [ 8096 ] = " " ;
snprintf ( szBuf , 8096 , " In [%s::%s Line: %d] Error detected: signal %d: \n " , __FILE__ , __FUNCTION__ , __LINE__ , sig ) ;
2012-04-14 23:21:09 +02:00
printf ( " %s " , szBuf ) ;
//abort();
2011-12-01 03:31:00 +01:00
2012-04-14 23:21:09 +02:00
ExceptionHandler : : handleRuntimeError ( szBuf , true ) ;
}
# endif
2013-01-31 21:17:52 +01:00
# if defined(HAVE_GOOGLE_BREAKPAD)
2013-02-01 03:27:01 +01:00
# if defined(WIN32)
2013-01-31 21:17:52 +01:00
// Callback when minidump written.
static bool MinidumpCallback ( const wchar_t * dump_path ,
const wchar_t * minidump_id ,
void * context ,
EXCEPTION_POINTERS * exinfo ,
MDRawAssertionInfo * assertion ,
bool succeeded ) {
printf ( " \n ======= In MinidumpCallback... \n " ) ;
wprintf ( L " \n ***ERROR details captured: \n Crash minidump folder: %s \n file: %s.dmp \n Succeeded: %d \n " , ( dump_path ! = NULL ? dump_path : L " (null) " ) , ( minidump_id ! = NULL ? minidump_id : L " (null) " ) , succeeded ) ;
2013-02-01 06:52:00 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
wchar_t szBuf [ 8096 ] ;
2013-02-04 09:30:43 +01:00
int bufBytes = _snwprintf ( szBuf , 8096 , L " An unhandled error was detected. \n \n A crash dump file has been created in the folder: \n %s \n Crash dump filename is: %s.dmp " , dump_path , minidump_id ) ;
szBuf [ bufBytes ] = ' \0 ' ;
2013-02-01 06:52:00 +01:00
MessageBox ( NULL , szBuf , L " Unhandled error " , MB_OK | MB_SYSTEMMODAL ) ;
}
2013-02-01 03:27:01 +01:00
return succeeded ;
}
# else
// Callback when minidump written.
static bool MinidumpCallback ( const google_breakpad : : MinidumpDescriptor & descriptor ,
void * context ,
bool succeeded ) {
printf ( " \n ======= In MinidumpCallback... \n " ) ;
printf ( " \n ***ERROR details captured: \n Crash minidump folder: %s \n file: %s \n Succeeded: %d \n " , descriptor . directory ( ) . c_str ( ) , descriptor . path ( ) , succeeded ) ;
2013-02-01 06:52:00 +01:00
if ( GlobalStaticFlags : : getIsNonGraphicalModeEnabled ( ) = = false ) {
char szBuf [ 8096 ] ;
2013-03-06 15:29:49 +01:00
snprintf ( szBuf , 8096 , " An unhandled error was detected. \n \n A crash dump file has been created in the folder: \n %s \n Crash dump filename is: %s " , descriptor . directory ( ) . c_str ( ) , descriptor . path ( ) ) ;
2013-02-01 06:52:00 +01:00
//MessageBox(NULL, szBuf, "Unhandled error", MB_OK|MB_SYSTEMMODAL);
message ( szBuf ) ;
}
2013-02-01 03:27:01 +01:00
return succeeded ;
}
2013-01-31 21:17:52 +01:00
# endif
# endif
# ifdef WIN32
void EnableCrashingOnCrashes ( ) {
typedef BOOL ( WINAPI * tGetPolicy ) ( LPDWORD lpFlags ) ;
typedef BOOL ( WINAPI * tSetPolicy ) ( DWORD dwFlags ) ;
const DWORD EXCEPTION_SWALLOWING = 0x1 ;
2013-02-04 09:30:43 +01:00
HMODULE kernel32 = LoadLibraryA ( " kernel32.dll " ) ;
if ( kernel32 ! = 0 ) {
tGetPolicy pGetPolicy = ( tGetPolicy ) GetProcAddress ( kernel32 , " GetProcessUserModeExceptionPolicy " ) ;
tSetPolicy pSetPolicy = ( tSetPolicy ) GetProcAddress ( kernel32 , " SetProcessUserModeExceptionPolicy " ) ;
if ( pGetPolicy & & pSetPolicy ) {
DWORD dwFlags ;
if ( pGetPolicy ( & dwFlags ) ) {
// Turn off the filter
pSetPolicy ( dwFlags & ~ EXCEPTION_SWALLOWING ) ;
}
}
}
2013-01-31 21:17:52 +01:00
}
# endif
2013-02-04 09:30:43 +01:00
int glestMainSEHWrapper ( int argc , char * * argv ) {
# ifdef WIN32_STACK_TRACE
2013-02-09 09:01:06 +01:00
//printf("Hooking up WIN32_STACK_TRACE...\n");
2013-02-04 09:30:43 +01:00
__try {
# endif
//application_binary= executable_path(argv[0],true);
//printf("\n\nargv0 [%s] application_binary [%s]\n\n",argv[0],application_binary.c_str());
# if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
if ( hasCommandArgument ( argc , argv , string ( GAME_ARGS [ GAME_ARG_DISABLE_SIGSEGV_HANDLER ] ) ) = = false ) {
signal ( SIGSEGV , handleSIGSEGV ) ;
}
// http://developerweb.net/viewtopic.php?id=3013
//signal(SIGPIPE, SIG_IGN);
# endif
initSpecialStrings ( ) ;
IRCThread : : setGlobalCacheContainerName ( GameConstants : : ircClientCacheLookupKey ) ;
int result = glestMain ( argc , argv ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
cleanupProcessObjects ( ) ;
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
if ( sdl_quitCalled = = false ) {
sdl_quitCalled = true ;
SDL_Quit ( ) ;
}
if ( SystemFlags : : VERBOSE_MODE_ENABLED ) printf ( " In [%s::%s Line: %d] \n " , __FILE__ , __FUNCTION__ , __LINE__ ) ;
return result ;
# ifdef WIN32_STACK_TRACE
} __except ( stackdumper ( 0 , GetExceptionInformation ( ) , true ) , EXCEPTION_CONTINUE_SEARCH ) { return 0 ; }
# endif
}
2012-04-14 23:21:09 +02:00
int glestMainWrapper ( int argc , char * * argv ) {
2011-06-06 23:38:25 +02:00
//setlocale(LC_ALL, "zh_TW.UTF-8");
//setlocale(LC_ALL, "");
2013-01-31 21:17:52 +01:00
# ifdef WIN32
EnableCrashingOnCrashes ( ) ;
# endif
# if defined(HAVE_GOOGLE_BREAKPAD)
/*
handler = new ExceptionHandler ( const wstring & dump_path ,
FilterCallback filter ,
MinidumpCallback callback ,
void * callback_context ,
int handler_types ,
MINIDUMP_TYPE dump_type ,
const wchar_t * pipe_name ,
const CustomClientInfo * custom_info ) ;
*/
// See this link about swallowed exceptions in Win 7: http://blog.paulbetts.org/index.php/2010/07/20/the-case-of-the-disappearing-onload-exception-user-mode-callback-exceptions-in-x64/
//DWORD dwFlags;
//if (GetProcessUserModeExceptionPolicy(&dwFlags)) {
// SetProcessUserModeExceptionPolicy(dwFlags & ~PROCESS_CALLBACK_FILTER_ENABLED); // turn off bit 1
//}
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Hooking up google_breakpad::ExceptionHandler...\n");
2013-02-01 03:27:01 +01:00
# if defined(WIN32)
2013-01-31 21:17:52 +01:00
wstring dumpfilepath = utf8_decode ( " . " ) ;
//google_breakpad::ExceptionHandler handler(dumpfilepath, NULL, MinidumpCallback, NULL, true);
2013-02-04 09:30:43 +01:00
errorHandlerPtr . reset ( new google_breakpad : : ExceptionHandler ( dumpfilepath , NULL , MinidumpCallback ,
NULL , google_breakpad : : ExceptionHandler : : HANDLER_ALL ) ) ;
2013-02-01 03:27:01 +01:00
# else
google_breakpad : : MinidumpDescriptor descriptor ( " . " ) ;
errorHandlerPtr . reset ( new google_breakpad : : ExceptionHandler ( descriptor , NULL , MinidumpCallback , NULL , true , - 1 ) ) ;
# endif
2013-02-04 09:30:43 +01:00
2013-01-31 21:17:52 +01:00
// ExceptionHandler(const wstring& dump_path,
// FilterCallback filter,
// MinidumpCallback callback,
// void* callback_context,
// int handler_types);
# endif
2011-05-19 00:04:45 +02:00
# if defined(__GNUC__) && !defined(__MINGW32__) && !defined(__FreeBSD__) && !defined(BSD)
//#ifdef DEBUG
//printf("MTRACE will be called...\n");
//mtrace ();
//#endif
# endif
2013-02-04 09:30:43 +01:00
int result = glestMainSEHWrapper ( argc , argv ) ;
2011-05-19 00:04:45 +02:00
return result ;
}
} } //end namespace
MAIN_FUNCTION ( Glest : : Game : : glestMainWrapper )