#include "aa_config.h"
#include <fstream>
#include <iomanip>
#include <iostream>
#include "tConfiguration.h"
#include <stdlib.h>
#include <ctype.h>
#include <string>
#include <sstream>
#include "tString.h"
#include "tToDo.h"
#include "tConsole.h"
#include "tDirectories.h"
#include "tLocale.h"
#include "tRecorder.h"
#include "tCommandLine.h"
#include "tResourceManager.h"
#include "tError.h"
#include <vector>
#include <string.h>
#include <signal.h>
Go to the source code of this file.
Functions | |
static bool | s_Veto (tString line_in, std::vector< tString > const &vetos) |
static std::vector< tString > | st_Stringify (char const *vetos[]) |
static bool | s_VetoPlayback (tString const &line) |
static bool | s_VetoRecording (tString const &line) |
static bool | Load (const tPath &path, const char *filename) |
static void | st_InstallSigHupHandler () |
void | st_LoadConfig (bool printChange) |
void | st_SaveConfig () |
void | st_LoadConfig () |
static void | st_DoHandleSigHup () |
static void | st_HandleSigHup (int signal) |
void | st_Include (tString const &file, bool reportError) |
static void | Include (std::istream &s, bool error) |
static void | Include (std::istream &s) |
static void | SInclude (std::istream &s) |
static void | st_Dummy (std::istream &s) |
Variables | |
static std::map< tString, tConfItemBase * > * | st_confMap = 0 |
bool | st_FirstUse = true |
static tConfItem< bool > | fu ("FIRST_USE", st_FirstUse) |
static char const * | recordingSection = "CONFIG" |
static bool | st_settingsFromRecording = false |
char const * | st_userConfigs [] = { "user_3_1.cfg", "user_3_0.cfg", "user.cfg", 0 } |
static tConfItemFunc | s_Include ("INCLUDE",&Include) |
static tConfItemFunc | s_SInclude ("SINCLUDE",&SInclude) |
static tConfItemFunc | st_DummyMpHack ("MOVIEPACK_HACK",&st_Dummy) |
static tConfItemFunc | st_Dummy10 ("SIMULATE_RECEIVE_PACKET_LOSS",&st_Dummy) |
static tConfItemFunc | st_Dummy11 ("SIMULATE_SEND_PACKET_LOSS",&st_Dummy) |
static void Include | ( | std::istream & | s | ) | [static] |
Definition at line 939 of file tConfiguration.cpp.
References Include().
00940 { 00941 Include( s, true ); 00942 }
static void Include | ( | std::istream & | s, | |
bool | error | |||
) | [static] |
Definition at line 931 of file tConfiguration.cpp.
References st_Include().
Referenced by Include(), SInclude(), and eWallRim::UpdateBounds().
00932 { 00933 tString file; 00934 s >> file; 00935 00936 st_Include( file, error ); 00937 }
static bool Load | ( | const tPath & | path, | |
const char * | filename | |||
) | [static] |
Definition at line 724 of file tConfiguration.cpp.
References tConfItemBase::LoadAll(), and tPath::Open().
Referenced by main(), st_Include(), and st_LoadConfig().
00725 { 00726 // read from file 00727 if ( !filename ) 00728 { 00729 return false; 00730 } 00731 00732 std::ifstream s; 00733 if ( path.Open( s, filename ) ) 00734 { 00735 tConfItemBase::LoadAll( s ); 00736 return true; 00737 } 00738 else 00739 { 00740 return false; 00741 } 00742 }
Definition at line 483 of file tConfiguration.cpp.
References con, isblank(), tRecorderBase::IsRunning(), tString::StartsWith(), and tToUpper().
Referenced by s_VetoPlayback(), and s_VetoRecording().
00484 { 00485 // make name uppercase: 00486 tToUpper( line_in ); 00487 00488 // eat whitespace at the beginning 00489 char const * test = line_in; 00490 while( isblank(*test) ) 00491 test++; 00492 00493 // skip "LAST_" 00494 tString line( test ); 00495 if ( line.StartsWith( "LAST_" ) ) 00496 line = tString( static_cast< char const * >(line) + 5 ); 00497 00498 // iterate throug vetoed config items and test each one 00499 for ( std::vector< tString >::const_iterator iter = vetos.begin(); iter != vetos.end(); ++iter ) 00500 { 00501 tString const & veto = *iter; 00502 00503 if ( line.StartsWith( veto ) ) 00504 { 00505 #ifdef DEBUG_X 00506 if ( !line.StartsWith( "INCLUDE" ) && tRecorder::IsRunning() ) 00507 { 00508 con << "Veto on config line: " << line << "\n"; 00509 } 00510 #endif 00511 00512 return true; 00513 } 00514 } 00515 00516 return false; 00517 }
static bool s_VetoPlayback | ( | tString const & | line | ) | [static] |
Definition at line 535 of file tConfiguration.cpp.
References s_Veto(), and st_Stringify().
Referenced by tConfItemBase::LoadAll(), and tConfItemBase::LoadPlayback().
00536 { 00537 static char const * vetos_char[]= 00538 { "USE_DISPLAYLISTS", "CHECK_ERRORS", "ZDEPTH", 00539 "COLORDEPTH", "FULLSCREEN ", "ARMAGETRON_LAST_WINDOWSIZE", 00540 "ARMAGETRON_WINDOWSIZE", "ARMAGETRON_LAST_SCREENMODE", 00541 "ARMAGETRON_SCREENMODE", "CUSTOM_SCREEN", "SOUND", 00542 "PASSWORD", "ADMIN_PASS", "RECORDING_DEBUGLEVEL", 00543 "ZTRICK", "MOUSE_GRAB", "PNG_SCREENSHOT", // "WHITE_SPARKS", "SPARKS", 00544 "KEEP_WINDOW_ACTIVE", "TEXTURE_MODE", "TEXTURES_HI", "LAG_O_METER", "INFINITY_PLANE", 00545 "SKY_WOBBLE", "LOWER_SKY", "UPPER_SKY", "DITHER", "HIGH_RIM", "FLOOR_DETAIL", 00546 "FLOOR_MIRROR", "SHOW_FPS", "TEXT_OUT", "SMOOTH_SHADING", "ALPHA_BLEND", 00547 "PERSP_CORRECT", "POLY_ANTIALIAS", "LINE_ANTIALIAS", "FAST_FORWARD_MAXSTEP", 00548 "DEBUG_GNUPLOT", "FLOOR_", "MOVIEPACK_", "RIM_WALL_", "INCLUDE", "SINCLUDE", 00549 0 }; 00550 00551 static std::vector< tString > vetos = st_Stringify( vetos_char ); 00552 00553 // delegate 00554 return s_Veto( line, vetos ); 00555 }
static bool s_VetoRecording | ( | tString const & | line | ) | [static] |
Definition at line 559 of file tConfiguration.cpp.
References s_Veto(), and st_Stringify().
Referenced by tConfItemBase::LoadAll().
00560 { 00561 static char const * vetos_char[]= 00562 { "#", "PASSWORD", "ADMIN_PASS", "LOCAL_USER", "LOCAL_TEAM", 00563 0 }; 00564 00565 static std::vector< tString > vetos = st_Stringify( vetos_char ); 00566 00567 // delegate 00568 return s_Veto( line, vetos ); 00569 }
static void SInclude | ( | std::istream & | s | ) | [static] |
Definition at line 944 of file tConfiguration.cpp.
References Include().
00945 { 00946 Include( s, false ); 00947 }
static void st_DoHandleSigHup | ( | ) | [static] |
Definition at line 844 of file tConfiguration.cpp.
References con, st_LoadConfig(), and st_SaveConfig().
Referenced by st_HandleSigHup().
00845 { 00846 con << tOutput("$config_sighup"); 00847 st_SaveConfig(); 00848 st_LoadConfig(); 00849 }
static void st_Dummy | ( | std::istream & | s | ) | [static] |
Definition at line 953 of file tConfiguration.cpp.
References tString::ReadLine().
static void st_HandleSigHup | ( | int | signal | ) | [static] |
Definition at line 851 of file tConfiguration.cpp.
References st_DoHandleSigHup(), and st_ToDo_Signal().
Referenced by st_InstallSigHupHandler().
00852 { 00853 st_ToDo_Signal( st_DoHandleSigHup ); 00854 }
void st_Include | ( | tString const & | file, | |
bool | reportError | |||
) |
Definition at line 916 of file tConfiguration.cpp.
References con, tDirectories::Config(), tPath::IsValidPath(), Load(), and tDirectories::Var().
Referenced by Include().
00917 { 00918 // refuse to load illegal paths 00919 if( !tPath::IsValidPath( file ) ) 00920 return; 00921 00922 if ( !Load( tDirectories::Var(), file ) ) 00923 { 00924 if (!Load( tDirectories::Config(), file ) && reportError ) 00925 { 00926 con << tOutput( "$config_include_not_found", file ); 00927 } 00928 } 00929 }
static void st_InstallSigHupHandler | ( | ) | [static] |
Definition at line 856 of file tConfiguration.cpp.
References st_HandleSigHup().
Referenced by st_LoadConfig().
00857 { 00858 #ifndef WIN32 00859 static bool installed = false; 00860 if ( !installed ) 00861 { 00862 signal( SIGHUP, &st_HandleSigHup ); 00863 installed = true; 00864 } 00865 #endif 00866 }
void st_LoadConfig | ( | ) |
Definition at line 839 of file tConfiguration.cpp.
References st_LoadConfig().
00840 { 00841 st_LoadConfig( false ); 00842 }
void st_LoadConfig | ( | bool | printChange | ) |
Definition at line 775 of file tConfiguration.cpp.
References tDirectories::Config(), tDirectories::Data(), tRecorderBase::IsPlayingBack(), Load(), tConfItemBase::LoadPlayback(), tConfItemBase::printChange, tConfItemBase::printErrors, st_InstallSigHupHandler(), and tDirectories::Var().
Referenced by main(), st_DoHandleSigHup(), and st_LoadConfig().
00776 { 00777 st_InstallSigHupHandler(); 00778 00779 const tPath& var = tDirectories::Var(); 00780 const tPath& config = tDirectories::Config(); 00781 const tPath& data = tDirectories::Data(); 00782 00783 tConfItemBase::printChange=printChange; 00784 #ifdef DEDICATED 00785 tConfItemBase::printErrors=false; 00786 #endif 00787 { 00788 // load the first available user configuration file 00789 char const * const * userConfig = st_userConfigs; 00790 while ( *userConfig && !Load( var, *userConfig ) ) 00791 userConfig++; 00792 } 00793 tConfItemBase::printErrors=true; 00794 00795 Load( config, "settings.cfg" ); 00796 #ifdef DEDICATED 00797 Load( config, "settings_dedicated.cfg" ); 00798 if( extraConfig != "NONE" ) Load( config, extraConfig ); 00799 #else 00800 if (st_FirstUse) 00801 { 00802 Load( config, "default.cfg" ); 00803 } 00804 #endif 00805 00806 Load( data, "moviepack/settings.cfg" ); 00807 00808 Load( config, "autoexec.cfg" ); 00809 Load( var, "autoexec.cfg" ); 00810 00811 // load configuration from playback 00812 tConfItemBase::LoadPlayback(); 00813 st_settingsFromRecording = tRecorder::IsPlayingBack(); 00814 00815 tConfItemBase::printChange=true; 00816 }
void st_SaveConfig | ( | ) |
Definition at line 818 of file tConfiguration.cpp.
References con, tConfItemBase::SaveAll(), and tDirectories::Var().
Referenced by filter(), main(), SDLMain::quit:, se_DeletePasswords(), se_SoundInit(), sr_ExitDisplay(), sr_InitDisplay(), st_DoHandleSigHup(), and SDLApplication::terminate:.
00819 { 00820 // don't save while playing back 00821 if ( st_settingsFromRecording ) 00822 { 00823 return; 00824 } 00825 00826 std::ofstream s; 00827 if ( tDirectories::Var().Open( s, st_userConfigs[0], std::ios::out, true ) ) 00828 { 00829 tConfItemBase::SaveAll(s); 00830 } 00831 else 00832 { 00833 tOutput o("$config_file_write_error"); 00834 con << o; 00835 std::cerr << o; 00836 } 00837 }
static std::vector< tString > st_Stringify | ( | char const * | vetos[] | ) | [static] |
Definition at line 521 of file tConfiguration.cpp.
Referenced by s_VetoPlayback(), and s_VetoRecording().
00522 { 00523 std::vector< tString > ret; 00524 00525 char const * * v = vetos; 00526 while ( *v ) 00527 { 00528 ret.push_back( tString( *v ) ); 00529 ++v; 00530 } 00531 00532 return ret; 00533 }
char const* recordingSection = "CONFIG" [static] |
Definition at line 451 of file tConfiguration.cpp.
tConfItemFunc s_Include("INCLUDE",&Include) [static] |
tConfItemFunc s_SInclude("SINCLUDE",&SInclude) [static] |
std::map< tString, tConfItemBase * >* st_confMap = 0 [static] |
Definition at line 106 of file tConfiguration.cpp.
Referenced by tConfItemBase::ConfItemMap(), and tConfItemBase::~tConfItemBase().
tConfItemFunc st_Dummy10("SIMULATE_RECEIVE_PACKET_LOSS",&st_Dummy) [static] |
tConfItemFunc st_Dummy11("SIMULATE_SEND_PACKET_LOSS",&st_Dummy) [static] |
tConfItemFunc st_DummyMpHack("MOVIEPACK_HACK",&st_Dummy) [static] |
bool st_FirstUse = true |
bool st_settingsFromRecording = false [static] |
Definition at line 745 of file tConfiguration.cpp.
char const* st_userConfigs[] = { "user_3_1.cfg", "user_3_0.cfg", "user.cfg", 0 } |
Definition at line 771 of file tConfiguration.cpp.