void clConsole::DisplayMessage( const LString& Message, const LConsoleMessageType MSGType ) const { if ( Env ) { Env->SendSync( L_EVENT_CONSOLELOG, LEventArgs( &Message ), false ); } FTimeVisible = MESSAGE_VISIBILITY_TIME; LVector4 Color; switch ( MSGType ) { case CMSG_ENGINEMESSAGE: Color = LC_LinderdaumConsoleEM; break; case CMSG_ERRORMESSAGE: Color = LC_LinderdaumConsoleERR; break; case CMSG_INFOTIP: Color = LC_LinderdaumConsoleIT; break; default: FATAL_MSG( "Unknown message type" ); } LString Msg = Message; LMutex Lock( &FMessagesHistoryMutex ); while ( true ) { size_t Separation = Msg.find( "\n" ); if ( Separation == LString::npos ) { break; } LString NewMsg = Msg.substr( 0, Separation ); FMessagesHistory.push_back( sConsoleMessage( NewMsg, Color ) ); if ( FMessagesHistory.size() > MAX_HISTORY_SIZE ) { FMessagesHistory.pop_front(); } Msg = Msg.substr( Separation + 1, Message.length() - 1 ); } FMessagesHistory.push_back( sConsoleMessage( Msg, Color ) ); }
//------------------------------------------------------------------------------ int LArguments::parse(int argc, char* argv[]) { LString opt; int find; int ret; for(int num = 1; num < argc; num++) { opt = LString(argv[num]); if(opt.find("--") == 0) { if((find = opt.find("=")) != (int)string::npos) { if((ret = parseInternalOptionWithParamater(opt.substr(0, find), opt.substr(find + 1))) != L_OK) { return ret; } } else { if((ret = parseInternalOption(opt)) != L_OK) { return ret; } } } else if(opt.find("-") == 0) { if((find = opt.find("=")) != (int)string::npos) { if((ret = parseInternalOptionWithParamater(opt.substr(0, find), opt.substr(find + 1))) != L_OK) { return ret; } } else { if((ret = parseInternalOption(opt)) != L_OK) { return ret; } } } else { if((ret = parseInternalArgument(opt)) != L_OK) { return ret; } } } return L_OK; }
void clLocalizer::SetLocale( const LString& LocaleName ) { guard( "%s", LocaleName.c_str() ); ClearLocalization(); FLocaleName = LocaleName; const LString FileName( FLocalePath + "/Localizer-" + LocaleName + ".txt" ); if ( Env->FileSystem->FileExists( FileName ) ) { Env->Logger->LogP( L_NOTICE, "Reading locale from %s", FileName.c_str() ); iIStream* Stream = Env->FileSystem->CreateFileReader( FileName ); while ( !Stream->Eof() ) { LString Line = Stream->ReadLine(); size_t SepPos = Line.find( "~" ); FATAL( SepPos == Line.npos, "Invalid locale translation file format: missing ~" ); LString Text( Line.substr( 0, SepPos ) ); LString Translation( Line.substr( SepPos + 1, Line.length() - SepPos - 1 ) ); FTranslations[ Text ] = Translation; } delete( Stream ); } else { Env->Logger->LogP( L_NOTICE, "Locale %s not found", FileName.c_str() ); } this->SendAsync( L_EVENT_LOCALE_CHANGED, LEventArgs(), false ); unguard(); }
void clConsole::SendCommand( const LString& CMDName ) { guard( "%s", CMDName.c_str() ); FSendCommandResult.assign( "" ); if ( CMDName.size() == 0 ) { return; } bool IsScript = ( LStr::GetUpper( LStr::GetToken( CMDName, 1 ) ) == "RS" ); // split command size_t CommandsSeparator = FindCommandsSeparator( CMDName ); LString ThisCMDString = CMDName; LString RestCMDString( "" ); if ( !IsScript ) { if ( CommandsSeparator ) { ThisCMDString = CMDName.substr( 0, CommandsSeparator ); RestCMDString = CMDName.substr( CommandsSeparator, CMDName.length() - CommandsSeparator ); if ( RestCMDString.length() > 0 ) { LStr::pop_front( &RestCMDString ); } } } // extract command name and parameters LString ThisCMDName = LStr::GetToken( ThisCMDString, 1 ); LString ThisCMDParam = ThisCMDString.substr( ThisCMDName.length(), ThisCMDString.length() - ThisCMDName.length() ); if ( ThisCMDParam.length() > 0 ) { LStr::pop_front( &ThisCMDParam ); } LStr::ToUpper( &ThisCMDName ); if ( IsScript ) { // execute script and return ExecuteStatement( ThisCMDParam ); return; } if ( ThisCMDName.find( "WAIT" ) == 0 ) { // Leave the rest of the command until the next frame if ( CommandsSeparator ) { QueryCommand( RestCMDString ); } return; } else { clCommandsList::const_iterator i = FCommandsList.find( ThisCMDName ); if ( i != FCommandsList.end() ) { ( i->second ).Exec( clFileSystem::ReplaceEnvVars( ThisCMDParam ) ); } else { clAliasesList::const_iterator j = FAliasesList.find( ThisCMDName ); if ( j != FAliasesList.end() ) { QueryCommand( j->second ); } else { DisplayError( "Unknown command: " + ThisCMDName ); } } } if ( CommandsSeparator ) { SendCommand( RestCMDString ); } unguard(); }