9d3dc5e537
- costanti stringa sostituite con costanti numeriche - modificate funzioni API e LUA per scansione pezzi e layer - aggiunta pulizia memoria al caricamento messaggi (necessario al cambio lingua) - migliorie varie a funzioni Lua.
95 lines
3.0 KiB
C++
95 lines
3.0 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2015-2015
|
|
//----------------------------------------------------------------------------
|
|
// File : API_Messages.cpp Data : 12.02.15 Versione : 1.6b3
|
|
// Contenuto : Funzioni per gestione messaggi.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 12.02.15 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "API.h"
|
|
#include "/EgtDev/Include/EInAPI.h"
|
|
#include "/EgtDEv/Include/EGnScan.h"
|
|
#include "/EgtDev/Include/EGnStringUtils.h"
|
|
#include "/EgtDev/Include/EGnStringConverter.h"
|
|
#include "/EgtDev/Include/EgtLogger.h"
|
|
#include <unordered_map>
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
typedef unordered_map< int, string> INTSTR_UMAP ;
|
|
INTSTR_UMAP s_IdStringMap ;
|
|
wstring s_wsMsg ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtLoadMessages( const wchar_t* wsMsgFilePath)
|
|
{
|
|
// inizializzo lo scanner
|
|
string sMsgFilePath = wstrztoA( wsMsgFilePath) ;
|
|
Scanner scan ;
|
|
if ( ! scan.Init( sMsgFilePath))
|
|
return FALSE ;
|
|
// pulisco la memoria
|
|
s_IdStringMap.clear() ;
|
|
s_wsMsg.clear() ;
|
|
// riservo spazio
|
|
s_IdStringMap.rehash( 1000) ;
|
|
s_wsMsg.reserve( 128) ;
|
|
// leggo le linee
|
|
string sLine ;
|
|
sLine.reserve( 128) ;
|
|
string sNum ;
|
|
sNum.reserve( 16) ;
|
|
string sMsg ;
|
|
sMsg.reserve( 128) ;
|
|
int nNum ;
|
|
int nCurrNum = - 1 ;
|
|
while ( scan.GetLine( sLine)) {
|
|
// divido la linea in due parti sul token '='
|
|
Split( sLine, "=", true, sNum, sMsg) ;
|
|
// la prima parte deve essere numerica
|
|
if ( sNum.empty() || ! FromString( sNum, nNum)) {
|
|
string sOut ;
|
|
sOut = "Problem in " + sMsgFilePath + " at line " + ToString( scan.GetCurrLineNbr()) + " : " + sLine ;
|
|
LOG_WARN( GetLogger(), sOut.c_str())
|
|
continue ;
|
|
}
|
|
// la numerazione deve essere crescente
|
|
if ( nNum <= nCurrNum) {
|
|
string sOut ;
|
|
sOut = "Error in " + sMsgFilePath + " at message " + sNum + " : " + sLine ;
|
|
LOG_ERROR( GetLogger(), sOut.c_str())
|
|
return FALSE ;
|
|
}
|
|
nCurrNum = nNum ;
|
|
// converto i caratteri speciali
|
|
ReplaceString( sMsg, "<br/>", "\n") ;
|
|
// inserisco il messaggio in tabella
|
|
if ( ! s_IdStringMap.emplace( nNum, sMsg).second)
|
|
return FALSE ;
|
|
}
|
|
|
|
// termino lo scanner
|
|
return ( scan.Terminate() ? TRUE :FALSE) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
const wchar_t*
|
|
__stdcall EgtGetMsg( int nMsg)
|
|
{
|
|
// recupero il messaggio
|
|
INTSTR_UMAP::iterator Iter = s_IdStringMap.find( nMsg) ;
|
|
if ( Iter != s_IdStringMap.end())
|
|
s_wsMsg = stringtoW( Iter->second) ;
|
|
else
|
|
s_wsMsg = stringtoW( ( "Msg" + ToString( nMsg))) ;
|
|
return s_wsMsg.c_str() ;
|
|
} |