| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include "core/ConfigCmdManager.h"
- #include "core/ConfigFile.h"
- #include "core/Logger.h"
- #include "core/Utilites.h"
- void
- ConfigFile::Execute( const Ogre::String& name )
- {
- // Open the configuration file
- std::ifstream fp;
- // Always open in binary mode
- fp.open( name.c_str(), std::ios::in | std::ios::binary );
- if( !fp )
- {
- LOG_WARNING( "Config file\"" + name + "\" not found!" );
- }
- else
- {
- Ogre::String command = "";
- while( true )
- {
- char c = fp.get(); // get character from file
- if( fp.good() == false )
- {
- break;
- }
- if( c == '\r' || ( c == '\n' && command.size() == 0 ) )
- {
- }
- else if( c == '\n' && command.size() > 0 )
- {
- Ogre::StringVector params = StringTokenise( command );
- if( params.size() > 0 )
- {
- // handle command
- ConfigCmd* cmd = ConfigCmdManager::getSingleton().Find( params[ 0 ] );
- if( cmd != NULL )
- {
- cmd->GetHandler()( params );
- }
- else
- {
- LOG_ERROR( "Can't find command \"" + params[ 0 ] + "\"." );
- }
- }
- command = "";
- }
- else if( c >= 0 ) // use only ascii characters
- {
- command += c;
- }
- }
- if( command.size() > 0 )
- {
- Ogre::StringVector params = StringTokenise( command );
- if( params.size() > 0 )
- {
- ConfigCmd* cmd = ConfigCmdManager::getSingleton().Find( params[ 0 ] );
- if( cmd != NULL )
- {
- cmd->GetHandler()( params );
- }
- else
- {
- LOG_ERROR( "Can't find command \"" + params[ 0 ] + "\"." );
- }
- }
- }
- fp.close(); // close file
- }
- }
|