//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : API_General.cpp Data : 01.09.14 Versione : 1.5i1 // Contenuto : Funzioni generali per API. // // // // Modifiche : 01.09.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "LUA_Base.h" #include "DllGraphics.h" #include "DllExchange.h" #include "DllMachKernel.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EXeDllMain.h" #include "/EgtDev/Include/EGnDllMain.h" #include "/EgtDev/Include/ENkDllMain.h" #include "/EgtDev/Include/EGkDllMain.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGnPcInfo.h" #include "/EgtDev/Include/EgtLogger.h" #include "/EgtDev/Include/EgtStringConverter.h" #include using namespace std ; using namespace egtlogger ; //---------------------------------------------------------------------------- static Logger* s_pGenLog = nullptr ; static bool s_bCmdLog = false ; static Logger* s_pCmdLog = nullptr ; //----------------------------------------------------------------------------- bool ExeInit( int nDebug, const string& sLogFile, const string& sLogMsg) { // cancello eventuali vecchi contesti ClearAllGseContexts() ; // cancello eventuale vecchio logger if ( s_pGenLog != nullptr) delete s_pGenLog ; // creo il logger generale s_pGenLog = new Logger( ( nDebug > 0 ? LL_DEBUG : LL_INFO), "EgtInterface") ; if ( s_pGenLog == nullptr) return false ; // assegno il file s_pGenLog->AddOutputStream( new ofstream( stringtoW( sLogFile)), true) ; // lo passo alle DLL SetEGnLogger( s_pGenLog) ; SetENkLogger( s_pGenLog) ; SetEGkLogger( s_pGenLog) ; // carico librerie opzionali LoadGraphicsDll() ; MySetEGrLogger( s_pGenLog) ; LoadExchangeDll() ; MySetEExLogger( s_pGenLog) ; LoadMachKernelDll() ; MySetEMkLogger( s_pGenLog) ; // dichiaro inizio programma LOG_DATETIME( s_pGenLog, " Init") // eventuale messaggio dall'applicazione if ( &sLogMsg != nullptr && ! sLogMsg.empty()) LOG_INFO( s_pGenLog, sLogMsg.c_str()) // versione di interfaccia e componenti string sVer ; ExeGetVersionInfo( sVer, "\n") ; LOG_INFO( s_pGenLog, sVer.c_str()) // Info sul sistema string sTmp ; if ( GetOsInfo( sTmp)) LOG_INFO( s_pGenLog, sTmp.c_str()) if ( GetCpuInfo( sTmp)) LOG_INFO( s_pGenLog, sTmp.c_str()) if ( GetMemoryInfo( sTmp)) LOG_INFO( s_pGenLog, sTmp.c_str()) // inizializzo l'interprete LUA LuaInit() ; return true ; } //----------------------------------------------------------------------------- bool ExeExit( void) { // cancello tutti i contesti ClearAllGseContexts() ; // termino l'interprete LUA LuaExit() ; // libero le librerie opzionali FreeMachKernelDll() ; FreeExchangeDll() ; FreeGraphicsDll() ; // fine programma LOG_DATETIME( s_pGenLog, " Exit") // cancello il logger dei comandi if ( s_pCmdLog != nullptr) { delete s_pCmdLog ; s_pCmdLog = nullptr ; } // cancello il logger generale if ( s_pGenLog != nullptr) { delete s_pGenLog ; s_pGenLog = nullptr ; } return true ; } //----------------------------------------------------------------------------- bool ExeSetKey( const string& sKey) { SetEGkKey( sKey) ; MySetEGrKey( sKey) ; MySetEExKey( sKey) ; MySetEMkKey( sKey) ; return true ; } //----------------------------------------------------------------------------- bool ExeSetFont( const string& sNfeFontDir, const string& sDefaultFont) { // inizializzazioni gestore font Nfe InitFontManager( sNfeFontDir, sDefaultFont) ; return true ; } //----------------------------------------------------------------------------- bool ExeGetNfeFontDir( string& sNfeFontDir) { if ( &sNfeFontDir == nullptr) return false ; // recupero il nome del font di default sNfeFontDir = GetNfeFontDir() ; return true ; } //----------------------------------------------------------------------------- bool ExeGetDefaultFont( string& sDefaultFont) { if ( &sDefaultFont == nullptr) return false ; // recupero il nome del font di default sDefaultFont = GetDefaultFont() ; return true ; } //----------------------------------------------------------------------------- bool ExeSetLuaLibs( const string& sLuaLibsDir) { return LuaSetLuaLibsDir( sLuaLibsDir) ; } //----------------------------------------------------------------------------- bool ExeSetCommandLogger( const string& sLogFile) { // cancello eventuale vecchio logger e disabilito output if ( s_pCmdLog != nullptr) delete s_pCmdLog ; s_bCmdLog = false ; // creo il logger dei comandi s_pCmdLog = new Logger( LL_INFO, "EgtCommandLog") ; if ( s_pCmdLog == nullptr) return false ; // assegno il file ofstream* pLogFile = new ofstream( stringtoW( sLogFile)) ; if ( pLogFile == nullptr || pLogFile->bad()) return false ; s_pCmdLog->AddOutputStream( pLogFile, true) ; // scrivo intestazione string sOut = "-- " + CurrDateTime() + " EgtCommandLog" ; LOG_INFO( s_pCmdLog, sOut.c_str()) return false ; } //----------------------------------------------------------------------------- void ExeEnableCommandLogger( void) { SetCmdLog( true) ; } //----------------------------------------------------------------------------- void ExeDisableCommandLogger( void) { SetCmdLog( false) ; } //----------------------------------------------------------------------------- bool ExeGetVersionInfo( string& sVer, const char* szNewLine) { // verifico il parametro if ( &sVer == nullptr) return false ; // recupero le informazioni sulle DLL sempre presenti sVer += GetEXeVersion() ; sVer += szNewLine ; sVer += GetEGnVersion() ; sVer += szNewLine ; sVer += GetENkVersion() ; sVer += szNewLine ; sVer += GetEGkVersion() ; // recupero le informazioni sulle DLL opzionali if ( IsLoadedGraphicsDll()) { sVer += szNewLine ; sVer += MyGetEGrVersion() ; } if ( IsLoadedExchangeDll()) { sVer += szNewLine ; sVer += MyGetEExVersion() ; } if ( IsLoadedMachKernelDll()) { sVer += szNewLine ; sVer += MyGetEMkVersion() ; } return true ; } //----------------------------------------------------------------------------- bool ExeGetOsInfo( string& sOs) { // recupero le informazioni sul sistema operativo return GetOsInfo( sOs) ; } //----------------------------------------------------------------------------- bool ExeGetCpuInfo( string& sCpu) { // recupero le informazioni sulla Cpu return GetCpuInfo( sCpu) ; } //----------------------------------------------------------------------------- bool ExeGetMemoryInfo( string& sMem) { // recupero le informazioni sulla memoria presente return GetMemoryInfo( sMem) ; } //----------------------------------------------------------------------------- bool ExeOutLog( const string& sMsg) { LOG_INFO( s_pGenLog, sMsg.c_str()) return ( s_pGenLog != nullptr) ; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- ILogger* GetLogger( void) { return s_pGenLog ; } //----------------------------------------------------------------------------- ILogger* GetCmdLogger( void) { return s_pCmdLog ; } //----------------------------------------------------------------------------- bool SetCmdLog( bool bVal) { swap( bVal, s_bCmdLog) ; return bVal ; } //----------------------------------------------------------------------------- bool IsCmdLog( void) { return s_bCmdLog ; }