//---------------------------------------------------------------------------- // 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 "API.h" #include "LUA.h" #include "/EgtDev/Include/EInAPI.h" #include "/EgtDev/Include/EInDllMain.h" #include "/EgtDev/Include/EGkDllMain.h" #include "/EgtDev/Include/ENkDllMain.h" #include "/EgtDev/Include/EGnDllMain.h" #include "/EgtDev/Include/EExDllMain.h" #include "/EgtDev/Include/EGrDllMain.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGnStringConverter.h" #include "/EgtDev/Include/EgtLogger.h" #include using namespace std ; using namespace egtlogger ; //---------------------------------------------------------------------------- static Logger* s_pGenLog = nullptr ; static Logger* s_pCmdLog = nullptr ; static bool s_bCmdLog = false ; //----------------------------------------------------------------------------- BOOL __stdcall EgtInit( int nDebug, const wchar_t* sLogFile) { // 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( sLogFile), true) ; // lo passo alle DLL SetEGnLogger( s_pGenLog) ; SetENkLogger( s_pGenLog) ; SetEGkLogger( s_pGenLog) ; SetEExLogger( s_pGenLog) ; SetEGrLogger( s_pGenLog) ; // dichiaro inizio programma LOG_DATETIME( s_pGenLog, " Init") // versione dell'interfaccia LOG_INFO( s_pGenLog, GetEInVersion()) // versione delle librerie LOG_INFO( s_pGenLog, GetEGnVersion()) LOG_INFO( s_pGenLog, GetENkVersion()) LOG_INFO( s_pGenLog, GetEGkVersion()) LOG_INFO( s_pGenLog, GetEExVersion()) LOG_INFO( s_pGenLog, GetEGrVersion()) // inizializzo l'interprete LUA LuaInit() ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtExit( void) { // cancello tutti i contesti ClearAllGseContexts() ; // termino l'interprete LUA LuaExit() ; // 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 __stdcall EgtSetKey( const wchar_t* sKey) { SetEGkKey( LPSTR( WtoA( sKey))) ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetFont( const wchar_t* wsNfeFontDir, const wchar_t* wsDefaultFont) { // inizializzazioni gestore font Nfe InitFontManager( LPSTR( WtoA( wsNfeFontDir)), LPSTR( WtoA( wsDefaultFont))) ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetNfeFontDir( wchar_t*& wsNfeFontDir) { if ( &wsNfeFontDir == nullptr) return false ; // recupero il nome del font di default string sNfeFontDir = GetNfeFontDir() ; wsNfeFontDir = _wcsdup( stringtoW( sNfeFontDir)) ; return (( wsNfeFontDir == nullptr) ? FALSE : TRUE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetDefaultFont( wchar_t*& wsDefaultFont) { if ( &wsDefaultFont == nullptr) return false ; // recupero il nome del font di default string sDefaultFont = GetDefaultFont() ; wsDefaultFont = _wcsdup( stringtoW( sDefaultFont)) ; return (( wsDefaultFont == nullptr) ? FALSE : TRUE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetLuaLibs( const wchar_t* wsLuaLibsDir) { if ( LuaSetLuaLibsDir( LPSTR( WtoA( wsLuaLibsDir)))) return TRUE ; else return FALSE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetCommandLogger( const wchar_t* 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( 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 TRUE ; } //----------------------------------------------------------------------------- void __stdcall EgtEnableCommandLogger( void) { s_bCmdLog = true ; } //----------------------------------------------------------------------------- void __stdcall EgtDisableCommandLogger( void) { s_bCmdLog = false ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetVersionInfo( wchar_t*& wsVer) { // recupero le informazioni sulle DLL string sVer ; if ( ! EgtGetVersionInfo( sVer, "\r\n")) return FALSE ; wsVer = _wcsdup( stringtoW( sVer)) ; return (( wsVer == nullptr) ? FALSE : TRUE) ; } //----------------------------------------------------------------------------- bool EgtGetVersionInfo( string& sVer, const char* szNewLine) { // verifico il parametro if ( &sVer == nullptr) return false ; // recupero le informazioni sulle DLL sVer += GetEInVersion() ; sVer += szNewLine ; sVer += GetEGrVersion() ; sVer += szNewLine ; sVer += GetEExVersion() ; sVer += szNewLine ; sVer += GetEGkVersion() ; sVer += szNewLine ; sVer += GetENkVersion() ; sVer += szNewLine ; sVer += GetEGnVersion() ; return true ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtFreeMemory( void* pMem) { if ( pMem == nullptr) return FALSE ; free( pMem) ; return TRUE ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtOutLog( const wchar_t* sMsg) { LOG_INFO( s_pGenLog, LPSTR( WtoA( sMsg))) return ( s_pGenLog != nullptr) ; } //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- ILogger* GetLogger( void) { return s_pGenLog ; } //----------------------------------------------------------------------------- ILogger* GetCmdLogger( void) { return s_pCmdLog ; } //----------------------------------------------------------------------------- bool IsCmdLog( void) { return s_bCmdLog ; }