2010-03-14 01:49:19 +01:00
// ==============================================================
// This file is part of Glest (www.glest.org)
//
2011-06-07 04:37:58 +02:00
// Copyright (C) 2001-2008 Martiño Figueroa
2010-03-14 01:49:19 +01: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
// ==============================================================
# include "game_util.h"
# include "util.h"
# include "lang.h"
# include "game_constants.h"
# include "config.h"
2010-03-22 00:40:35 +01:00
# include <stdlib.h>
# include "platform_util.h"
2010-04-30 04:20:27 +02:00
# include "conversion.h"
2010-12-09 21:41:11 +01:00
# include "cache_manager.h"
2010-03-14 01:49:19 +01:00
# include "leak_dumper.h"
using namespace Shared : : Util ;
2010-03-22 00:40:35 +01:00
using namespace Shared : : Platform ;
2010-03-14 01:49:19 +01:00
2010-09-16 09:00:50 +02:00
namespace Glest { namespace Game {
2010-03-14 01:49:19 +01:00
2011-10-18 03:40:49 +02:00
const char * mailString = " http://bugs.megaglest.org " ;
2012-10-10 01:18:07 +02:00
const string glestVersionString = " v3.7.0-dev " ;
2010-12-10 02:53:51 +01:00
# if defined(SVNVERSION)
const string SVN_Rev = string ( " Rev: " ) + string ( SVNVERSION ) ;
2010-12-24 00:17:15 +01:00
# elif defined(SVNVERSIONHEADER)
# include "svnversion.h"
const string SVN_Rev = string ( " Rev: " ) + string ( SVNVERSION ) ;
2010-12-10 02:53:51 +01:00
# else
2010-10-08 04:05:42 +02:00
const string SVN_Rev = " $Rev$ " ;
2010-12-10 02:53:51 +01:00
# endif
2010-03-14 01:49:19 +01:00
string getCrashDumpFileName ( ) {
2010-12-13 01:32:59 +01:00
return " megaglest " + glestVersionString + " .dmp " ;
2010-03-14 01:49:19 +01:00
}
2010-05-13 00:54:42 +02:00
string getPlatformNameString ( ) {
2012-10-06 09:06:40 +02:00
static string platform ;
2011-11-23 09:00:09 +01:00
if ( platform = = " " ) {
2010-05-13 00:54:42 +02:00
# if defined(WIN32)
2012-10-06 09:06:40 +02:00
2010-12-08 08:01:24 +01:00
# if defined(__MINGW32__)
platform = " W-MINGW " ;
2012-10-06 09:06:40 +02:00
# else
platform = " Windows " ;
2010-12-08 08:01:24 +01:00
# endif
2010-09-25 01:28:54 +02:00
# elif defined(__FreeBSD__)
platform = " FreeBSD " ;
2010-09-27 22:28:08 +02:00
# elif defined(__APPLE__)
platform = " MacOSX " ;
2010-04-30 04:20:27 +02:00
# elif defined(__GNUC__)
2012-10-06 09:06:40 +02:00
2010-12-08 08:01:24 +01:00
# if defined(__MINGW32__)
platform = " L-MINGW " ;
2012-10-06 09:06:40 +02:00
# else
platform = " GNU " ;
2010-12-08 08:01:24 +01:00
# endif
2010-05-13 00:54:42 +02:00
# else
platform = " ??? " ;
# endif
2010-06-27 00:49:59 +02:00
2010-06-27 07:10:41 +02:00
# if defined(_M_X64) || defined(_M_IA64) || defined(_M_AMD64) || defined(__x86_64__) || defined(_WIN64)
2010-06-27 00:49:59 +02:00
platform + = " _64bit " ;
# endif
2011-11-23 09:00:09 +01:00
}
2010-05-13 00:54:42 +02:00
return platform ;
}
2010-04-30 04:20:27 +02:00
2010-10-08 04:05:42 +02:00
string getSVNRevisionString ( ) {
return SVN_Rev ;
}
2010-05-13 00:54:42 +02:00
string getCompilerNameString ( ) {
2011-11-23 09:00:09 +01:00
static string version = " " ;
if ( version = = " " ) {
2010-05-13 00:54:42 +02:00
# if defined(WIN32) && defined(_MSC_VER)
version = " VC++: " + intToStr ( _MSC_VER ) ;
2010-06-22 01:45:49 +02:00
2010-05-13 00:54:42 +02:00
# elif defined(__GNUC__)
2010-04-30 04:20:27 +02:00
# if defined(__GNUC__)
# if defined(__GNUC_PATCHLEVEL__)
# define __GNUC_VERSION__ (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__ )
# else
# define __GNUC_VERSION__ (__GNUC__ * 10000 \
+ __GNUC_MINOR__ * 100 )
# endif
# endif
2010-12-08 08:01:24 +01:00
version = " GNUC " ;
# if defined(__MINGW32__)
version + = " -MINGW " ;
# endif
version + = " : " + intToStr ( __GNUC_VERSION__ ) ;
2010-06-22 01:45:49 +02:00
2010-05-13 00:54:42 +02:00
# else
version = " ??? " ;
2010-04-30 04:20:27 +02:00
# endif
2010-06-27 00:49:59 +02:00
# if defined(DEBUG) || defined(_DEBUG)
version + = " [DEBUG] " ;
# endif
2010-06-27 07:10:41 +02:00
# if defined(_M_X64) || defined(_M_IA64) || defined(_M_AMD64) || defined(__x86_64__) || defined(_WIN64)
2010-06-27 00:49:59 +02:00
version + = " [64bit] " ;
# endif
2011-11-23 09:00:09 +01:00
}
2010-04-30 04:20:27 +02:00
return version ;
2010-04-30 03:32:37 +02:00
}
2010-05-13 00:54:42 +02:00
string getNetworkVersionString ( ) {
2011-11-23 09:00:09 +01:00
static string version = " " ;
if ( version = = " " ) {
version = glestVersionString + " - " + getCompilerNameString ( ) + " - " + getCompileDateTime ( ) ;
}
2010-05-13 00:54:42 +02:00
return version ;
}
2011-04-30 03:05:53 +02:00
string getNetworkVersionSVNString ( ) {
2011-11-23 09:00:09 +01:00
static string version = " " ;
if ( version = = " " ) {
version = glestVersionString + " - " + getCompilerNameString ( ) + " - " + getSVNRevisionString ( ) ;
}
2011-04-30 03:05:53 +02:00
return version ;
}
2010-05-13 00:44:41 +02:00
string getCompileDateTime ( ) {
2011-11-23 09:00:09 +01:00
static string result = " " ;
if ( result = = " " ) {
result = string ( __DATE__ ) + " " + string ( __TIME__ ) ;
}
return result ;
2010-05-13 00:44:41 +02:00
}
2010-04-30 03:32:37 +02:00
string getNetworkPlatformFreeVersionString ( ) {
return glestVersionString ;
2010-03-14 01:49:19 +01:00
}
2010-10-08 04:05:42 +02:00
string getAboutString1 ( int i ) {
2011-11-23 09:00:09 +01:00
switch ( i ) {
2010-12-13 01:32:59 +01:00
case 0 : return " MegaGlest " + glestVersionString + " ( " + " Shared Library " + sharedLibVersionString + " ) " ;
2010-08-23 19:13:19 +02:00
case 1 : return " Built: " + string ( __DATE__ ) + " " + SVN_Rev ;
2011-04-05 23:46:02 +02:00
case 2 : return " Copyright 2001-2011 The MegaGlest Team " ;
2010-03-14 01:49:19 +01:00
}
return " " ;
}
2011-11-23 09:00:09 +01:00
string getAboutString2 ( int i ) {
switch ( i ) {
2010-12-13 01:32:59 +01:00
case 0 : return " Web: http://www.megaglest.org http://glest.org " ;
2011-10-18 03:40:49 +02:00
case 1 : return " Bug reports: " + string ( mailString ) ;
2010-03-14 01:49:19 +01:00
case 2 : return " Irc: irc://irc.freenode.net/glest " ;
}
return " " ;
}
2010-09-16 09:03:38 +02:00
string getTeammateName ( int i ) {
switch ( i ) {
2011-06-28 17:39:19 +02:00
case 0 : return " Martiño Figueroa " ;
//case 0: return "Martino Figueroa";
case 1 : return " José Luis González " ;
//case 1: return "Jose Luis Gonzalez";
case 2 : return " Tucho Fernández " ;
//case 2: return "Tucho Fernandez";
case 3 : return " José Zanni " ;
//case 3: return "Jose Zanni";
case 4 : return " Félix Menéndez " ;
//case 4: return "Felix Menendez";
2010-03-14 01:49:19 +01:00
case 5 : return " Marcos Caruncho " ;
case 6 : return " Matthias Braun " ;
case 7 : return " Titus Tscharntke " ;
2010-09-16 09:03:38 +02:00
case 8 : return " Mark Vejvoda " ;
}
2010-03-14 01:49:19 +01:00
return " " ;
}
2010-09-16 09:03:38 +02:00
string getTeammateRole ( int i ) {
2010-03-14 01:49:19 +01:00
Lang & l = Lang : : getInstance ( ) ;
switch ( i ) {
case 0 : return l . get ( " Programming " ) ;
case 1 : return l . get ( " SoundAndMusic " ) ;
case 2 : return l . get ( " 3dAnd2dArt " ) ;
case 3 : return l . get ( " 2dArtAndWeb " ) ;
case 4 : return l . get ( " Animation " ) ;
case 5 : return l . get ( " 3dArt " ) ;
case 6 : return l . get ( " LinuxPort " ) ;
case 7 : return l . get ( " Megaglest3d2dProgramming " ) ;
case 8 : return l . get ( " MegaglestProgramming " ) ;
}
return " " ;
}
2011-11-23 09:00:09 +01:00
string formatString ( string str ) {
2010-03-14 01:49:19 +01:00
string outStr = str ;
if ( ! outStr . empty ( ) ) {
outStr [ 0 ] = toupper ( outStr [ 0 ] ) ;
}
bool afterSeparator = false ;
for ( int i = 0 ; i < str . size ( ) ; + + i ) {
if ( outStr [ i ] = = ' _ ' ) {
outStr [ i ] = ' ' ;
}
else if ( afterSeparator ) {
outStr [ i ] = toupper ( outStr [ i ] ) ;
afterSeparator = false ;
}
if ( outStr [ i ] = = ' \n ' | | outStr [ i ] = = ' ( ' | | outStr [ i ] = = ' ' ) {
afterSeparator = true ;
}
}
return outStr ;
}
2011-11-02 18:17:28 +01:00
string getGameCustomCoreDataPath ( string originalBasePath , string uniqueFilePath ) {
2011-11-23 19:02:00 +01:00
// original file path setup
2011-11-02 18:17:28 +01:00
if ( originalBasePath ! = " " ) {
endPathWithSlash ( originalBasePath ) ;
}
2011-11-23 19:02:00 +01:00
//
2011-11-02 18:17:28 +01:00
2011-11-23 19:02:00 +01:00
// mydata user data override
2011-11-02 18:17:28 +01:00
Config & config = Config : : getInstance ( ) ;
string data_path = config . getString ( " UserData_Root " , " " ) ;
if ( data_path ! = " " ) {
endPathWithSlash ( data_path ) ;
}
2011-11-23 19:02:00 +01:00
//
2011-11-02 18:17:28 +01:00
2011-11-23 19:02:00 +01:00
// if set this is the current active mod
string custom_mod_path = config . getCustomRuntimeProperty ( Config : : ACTIVE_MOD_PROPERTY_NAME ) ;
if ( custom_mod_path ! = " " ) {
endPathWithSlash ( custom_mod_path ) ;
}
//
// decide which file to use
string result = " " ;
if ( custom_mod_path ! = " " & &
( uniqueFilePath = = " " | | fileExists ( custom_mod_path + uniqueFilePath ) = = true ) ) {
result = custom_mod_path + uniqueFilePath ;
}
else if ( data_path ! = " " & &
( uniqueFilePath = = " " | | fileExists ( data_path + uniqueFilePath ) = = true ) ) {
2011-11-02 18:17:28 +01:00
result = data_path + uniqueFilePath ;
}
2011-11-23 19:02:00 +01:00
else {
result = originalBasePath + uniqueFilePath ;
}
2011-11-02 18:17:28 +01:00
//printf("data_path [%s] result [%s]\n",data_path.c_str(),result.c_str());
return result ;
}
2010-12-09 21:41:11 +01:00
string getGameReadWritePath ( string lookupKey ) {
string path = " " ;
if ( lookupKey ! = " " ) {
2011-01-20 16:56:30 +01:00
std : : map < string , string > & pathCache = CacheManager : : getCachedItem < std : : map < string , string > > ( GameConstants : : pathCacheLookupKey ) ;
2010-12-09 21:41:11 +01:00
std : : map < string , string > : : const_iterator iterFind = pathCache . find ( lookupKey ) ;
if ( iterFind ! = pathCache . end ( ) ) {
path = iterFind - > second ;
if ( path ! = " " & & EndsWith ( path , " / " ) = = false & & EndsWith ( path , " \\ " ) = = false ) {
path + = " / " ;
}
2010-12-21 06:07:10 +01:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path to be used for [%s] files [%s]\n",__FILE__,__FUNCTION__,__LINE__,lookupKey.c_str(),path.c_str());
2011-01-20 16:56:30 +01:00
}
2010-12-09 21:41:11 +01:00
}
if ( path = = " " & & getenv ( " GLESTHOME " ) ! = NULL ) {
2010-03-22 00:40:35 +01:00
path = getenv ( " GLESTHOME " ) ;
if ( path ! = " " & & EndsWith ( path , " / " ) = = false & & EndsWith ( path , " \\ " ) = = false ) {
path + = " / " ;
}
2010-12-21 06:07:10 +01:00
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path to be used for read/write files [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
2010-03-22 00:40:35 +01:00
}
return path ;
}
2011-11-23 09:00:09 +01:00
void initSpecialStrings ( ) {
getCrashDumpFileName ( ) ;
getPlatformNameString ( ) ;
getSVNRevisionString ( ) ;
getCompilerNameString ( ) ;
getNetworkVersionString ( ) ;
getNetworkVersionSVNString ( ) ;
getNetworkPlatformFreeVersionString ( ) ;
getCompileDateTime ( ) ;
}
2010-03-14 01:49:19 +01:00
} } //end namespace