//---------------------------------------------------------------------------- // EgalTech 2014-2015 //---------------------------------------------------------------------------- // File : EXE_General.cpp Data : 01.09.14 Versione : 1.5i1 // Contenuto : Funzioni generali per EXE. // // // // 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/EGkUserObjFactory.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGnPcInfo.h" #include "/EgtDev/Include/EgtLogger.h" #include "/EgtDev/Include/EgtStringConverter.h" #include "/EgtDev/Include/SELkLockId.h" #include "/EgtDev/Include/SELkKeyProc.h" #include using namespace std ; using namespace egtlogger ; //---------------------------------------------------------------------------- static Logger* s_pGenLog = nullptr ; static bool s_bCmdLog = false ; static Logger* s_pCmdLog = nullptr ; static string s_sKey ; static int s_nKeyType = KEY_LOCK_TYPE_ANY ; static string s_sIniFile ; static pfProcEvents s_pFunProcEvents = nullptr ; static pfOutText s_pFunOutText = 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) ; // 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()) // imposto la chiave di protezione sulle librerie di base SetEGkKeyType( s_nKeyType) ; SetEGkKey( s_sKey) ; // carico libreria grafica opzionale if ( LoadGraphicsDll( s_pGenLog, s_sKey)) LOG_INFO( s_pGenLog, MyGetEGrVersion()) // carico libreria exchange opzionale if ( LoadExchangeDll( s_pGenLog, s_sKey)) LOG_INFO( s_pGenLog, MyGetEExVersion()) // carico libreria di lavorazione opzionale if ( LoadMachKernelDll( s_pGenLog, s_sKey)) LOG_INFO( s_pGenLog, MyGetEMkVersion()) // Info sulla protezione e sul sistema string sTmp ; if ( ExeGetKeyInfo( sTmp)) LOG_INFO( s_pGenLog, sTmp.c_str()) 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()) // Info su gestori UserObj caricati STRVECTOR vsOuMgr ; if ( USEROBJ_GETLIST( vsOuMgr)) { LOG_INFO( s_pGenLog, "UserObj Managers :") for ( size_t i = 0 ; i < vsOuMgr.size() ; ++ i) LOG_INFO( s_pGenLog, vsOuMgr[i].c_str()) } // inizializzo l'interprete LUA LuaInit() ; return true ; } //----------------------------------------------------------------------------- bool ExeExit( void) { // recupero vettore dei contesti attivi INTVECTOR vOn ; GetAllGseContextOn( vOn) ; // cancello tutti i contesti ClearAllGseContexts() ; // log dei contesti cancellati string sTmp = "All Contexts deleted (" + ToString( vOn) + ")" ; LOG_INFO( s_pGenLog, sTmp.c_str()) // termino l'interprete LUA LuaExit() ; // libero le librerie opzionali FreeMachKernelDll() ; FreeExchangeDll() ; FreeGraphicsDll() ; // cancello riferimenti a funzioni installate s_pFunProcEvents = nullptr ; s_pFunOutText = nullptr ; // 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) { s_sKey = sKey ; return true ; } //----------------------------------------------------------------------------- bool ExeSetLockType( int nType) { s_nKeyType = nType ; return SetLockType( nType) ; } //----------------------------------------------------------------------------- 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 ExeSetIniFile( const string& sIniFile) { s_sIniFile = sIniFile ; return true ; } //----------------------------------------------------------------------------- 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 ; } //----------------------------------------------------------------------------- bool ExeEnableCommandLogger( void) { return SetCmdLog( true) ; } //----------------------------------------------------------------------------- bool ExeDisableCommandLogger( void) { return 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 ExeGetKeyInfo( string& sKey) { // verifico il parametro if ( &sKey == nullptr) return false ; // recupero informazioni sulla protezione string sLockId ; if ( ! GetLockId( sLockId)) return false ; // se protezione hardware if ( sLockId.find( KEY_LOCK_HW_START) != string::npos) { sLockId = sLockId.substr( 7, 6) ; if ( sLockId.empty()) return false ; } // altrimenti else { if ( ! GetLockId2( sLockId)) return false ; } // assemblo stringa da restituire sKey = "Key " + sLockId ; return true ; } //----------------------------------------------------------------------------- bool ExeGetKeyLevel( int nProd, int nVer, int nLev, int& nKLev) { // verifico la chiave e il livello int nExpDays ; int nRet = GetKeyLevel( s_sKey, nProd, nVer, nLev, nKLev, nExpDays) ; if ( nRet != KEY_OK) { string sErr = "Error on Key (EGKL/" + ToString( nRet) + ")" ; LOG_ERROR( s_pGenLog, sErr.c_str()) ; return false ; } return true ; } //----------------------------------------------------------------------------- bool ExeGetKeyOptions( int nProd, int nVer, int nLev, unsigned int& nOpt2) { // verifico la chiave e le opzioni unsigned int nOpt1 ; int nOptExpDays ; int nRet = GetKeyOptions( s_sKey, nProd, nVer, nLev, nOpt1, nOpt2, nOptExpDays) ; if ( nRet != KEY_OK) { string sErr = "Error on Key (EGKO/" + ToString( nRet) + ")" ; LOG_ERROR( s_pGenLog, sErr.c_str()) ; return false ; } if ( nOptExpDays < GetCurrDay()) { nOpt2 = 0 ; string sErr = "Error on Key (EGKO/OPT)" ; LOG_ERROR( s_pGenLog, sErr.c_str()) ; return true ; } 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) ; } //----------------------------------------------------------------------------- bool ExeSetProcessEvents( pfProcEvents pFun) { s_pFunProcEvents = pFun ; return ( pFun != nullptr) ; } //----------------------------------------------------------------------------- int ExeProcessEvents( int nProg, int nPause) { if ( s_pFunProcEvents != nullptr) return s_pFunProcEvents( nProg, nPause) ; else return 0 ; } //----------------------------------------------------------------------------- bool ExeSetOutText( pfOutText pFun) { s_pFunOutText = pFun ; return ( pFun != nullptr) ; } //----------------------------------------------------------------------------- bool ExeOutText( const string& sText) { if ( s_pFunOutText != nullptr) return s_pFunOutText( sText) ; else return false ; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- const string& ExeGetIniFile( void) { return s_sIniFile ; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- 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 ; }