01097b15df
- aggiunta gestione messaggi da file - aggiunta gestione lettura/scrittura su file INI con UTF8 - aggiunta gestione file di log.
99 lines
3.1 KiB
C++
99 lines
3.1 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2025-2025
|
|
//----------------------------------------------------------------------------
|
|
// File : Messages.cpp Data : 24.01.25 Versione : 2.7a1
|
|
// Contenuto : Implementazione funzioni gestione messaggi da file.
|
|
//
|
|
//
|
|
// Modifiche : 24.01.25 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "EBs.h"
|
|
#include "StringUtils.h"
|
|
#include "/EgtDev/Include/EBsAPI.h"
|
|
#include "/EgtDev/Include/EgtILogger.h"
|
|
#include <fstream>
|
|
#include <unordered_map>
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
typedef unordered_map< int, string> INTSTR_UMAP ;
|
|
static INTSTR_UMAP s_IdStringMap ;
|
|
static string s_sLanguage ;
|
|
static wstring s_wsMsg ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
__stdcall EgtLoadMessages( const wchar_t* wsMsgFilePath)
|
|
{
|
|
// apro il file
|
|
string sMsgFilePath = wstrztoA( wsMsgFilePath) ;
|
|
fstream File( sMsgFilePath, ios::in) ;
|
|
if ( ! File.is_open())
|
|
return FALSE ;
|
|
// pulisco la memoria
|
|
s_IdStringMap.clear() ;
|
|
s_wsMsg.clear() ;
|
|
// riservo spazio
|
|
s_IdStringMap.rehash( 4000) ;
|
|
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 ;
|
|
int nLineNum = 0 ;
|
|
while ( getline( File, sLine)) {
|
|
++ nLineNum ;
|
|
// 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( nLineNum) + " : " + 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") ; // a capo
|
|
ReplaceString( sMsg, "?" "?" "?", "") ; // da tradurre
|
|
// inserisco il messaggio in tabella
|
|
if ( ! s_IdStringMap.emplace( nNum, sMsg).second)
|
|
return FALSE ;
|
|
// se messaggio 0 è la lingua
|
|
if ( nNum == 0)
|
|
s_sLanguage = sMsg ;
|
|
}
|
|
// chiudo
|
|
File.close() ;
|
|
return TRUE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
const wchar_t*
|
|
__stdcall EgtGetMsg( int nMsg)
|
|
{
|
|
// recupero il messaggio
|
|
auto Iter = s_IdStringMap.find( nMsg) ;
|
|
string sMsg = ( Iter != s_IdStringMap.end() ? Iter->second : "Msg" + ToString( nMsg)) ;
|
|
s_wsMsg = stringtoW( sMsg) ;
|
|
return s_wsMsg.data() ;
|
|
}
|