0424900a2b
- aggiunta funzione Exe e Lua VerifyKeyOption (nel parametro OptInd le centinaia indicano il numero di opzione, il resto indica il numero del bit).
813 lines
23 KiB
C++
813 lines
23 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2023
|
|
//----------------------------------------------------------------------------
|
|
// File : EXE_General.cpp Data : 14.11.23 Versione : 2.5k2
|
|
// Contenuto : Funzioni generali per EXE.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 01.09.14 DS Creazione modulo.
|
|
// 28.11.19 DS Aggiunto caricamento opzionale di Nesting.
|
|
// 14.11.23 DS Aggiunto caricamento opzionale di Exchange 3dm.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "EXE.h"
|
|
#include "LUA_Base.h"
|
|
#include "DllGraphics.h"
|
|
#include "DllExchange.h"
|
|
#include "DllExch3dm.h"
|
|
#include "DllMachKernel.h"
|
|
#include "DllNesting.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/EGnFileUtils.h"
|
|
#include "/EgtDev/Include/EGnGetModuleVer.h"
|
|
#include "/EgtDev/Include/EGnPcInfo.h"
|
|
#include "/EgtDev/Include/EGnGetKeyData.h"
|
|
#include "/EgtDev/Include/EgtIniFile.h"
|
|
#include "/EgtDev/Include/EgtLogger.h"
|
|
#include "/EgtDev/Include/EgtStringConverter.h"
|
|
#include "/EgtDev/Include/EgtKeyCodes.h"
|
|
#include "/EgtDev/Include/SELkLockId.h"
|
|
#include "/EgtDev/Include/SELkKeyProc.h"
|
|
#include <fstream>
|
|
|
|
using namespace std ;
|
|
using namespace egtlogger ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
static int s_nDebugLev = 0 ;
|
|
static Logger* s_pGenLog = nullptr ;
|
|
static bool s_bCmdLog = false ;
|
|
static Logger* s_pCmdLog = nullptr ;
|
|
static int s_nUserLev = 1 ;
|
|
static string s_sKey ;
|
|
static int s_nKeyType = KEY_LOCK_TYPE_ANY ;
|
|
static bool s_bNetHwKey = false ;
|
|
static int s_nKeyExpDays = 0 ;
|
|
static int s_nKeyAssExpDays = 0 ;
|
|
static int s_nKeyOptExpDays = 0 ;
|
|
static string s_sNestKey ;
|
|
static string s_sLockId ;
|
|
static string s_sIniFile ;
|
|
static bool s_bEnableUI = true ;
|
|
static pfOnTerminateProcess s_pFunOnTerminateProcess = nullptr ;
|
|
static pfProcEvents s_pFunProcEvents = nullptr ;
|
|
static pfOutText s_pFunOutText = nullptr ;
|
|
static HWND s_hMainWnd = nullptr ;
|
|
static string s_sTempDir ;
|
|
|
|
//-----------------------------------------------------------------------------
|
|
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 ;
|
|
// cancello riferimenti a funzioni installate
|
|
s_pFunOnTerminateProcess = nullptr ;
|
|
s_pFunProcEvents = nullptr ;
|
|
s_pFunOutText = nullptr ;
|
|
s_bEnableUI = true ;
|
|
|
|
// assegno il livello di debug
|
|
s_nDebugLev = max( nDebug, 0) ;
|
|
// lo passo alle DLL
|
|
SetEGkDebugLev( s_nDebugLev) ;
|
|
// creo il logger generale
|
|
s_pGenLog = new( nothrow) Logger( ( s_nDebugLev > 0 ? LL_DEBUG : LL_INFO), "EgtInterface") ;
|
|
if ( s_pGenLog == nullptr)
|
|
return false ;
|
|
// assegno il file
|
|
s_pGenLog->AddOutputStream( new( nothrow) 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) ;
|
|
SetEGkNetHwKey( s_bNetHwKey) ;
|
|
|
|
// carico libreria grafica opzionale
|
|
if ( LoadGraphicsDll( s_pGenLog, s_sKey, s_bNetHwKey))
|
|
LOG_INFO( s_pGenLog, MyGetEGrVersion())
|
|
|
|
// carico libreria exchange opzionale
|
|
if ( LoadExchangeDll( s_pGenLog, s_sKey, s_bNetHwKey))
|
|
LOG_INFO( s_pGenLog, MyGetEExVersion())
|
|
|
|
// carico libreria exchange 3dm opzionale
|
|
if ( LoadExch3dmDll( s_pGenLog, s_sKey, s_bNetHwKey))
|
|
LOG_INFO( s_pGenLog, MyGetEE3Version())
|
|
|
|
// carico libreria di lavorazione opzionale
|
|
if ( LoadMachKernelDll( s_pGenLog, s_sKey, s_bNetHwKey))
|
|
LOG_INFO( s_pGenLog, MyGetEMkVersion())
|
|
|
|
// carico libreria nesting opzionale (non può usare la chiave di rete)
|
|
if ( LoadNestingDll( s_pGenLog, s_sKey, s_sNestKey, s_bNetHwKey))
|
|
LOG_INFO( s_pGenLog, MyGetENsVersion())
|
|
|
|
// 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
|
|
if ( ExeGetDebugLevel() >= 1) {
|
|
STRVECTOR vsOuMgr ;
|
|
if ( USEROBJ_GETLIST( vsOuMgr)) {
|
|
LOG_DBG_INFO( s_pGenLog, "UserObj Managers :")
|
|
for ( size_t i = 0 ; i < vsOuMgr.size() ; ++ i)
|
|
LOG_DBG_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() ;
|
|
FreeExch3dmDll() ;
|
|
FreeGraphicsDll() ;
|
|
|
|
// cancello riferimenti a funzioni installate
|
|
s_pFunOnTerminateProcess = nullptr ;
|
|
s_pFunProcEvents = nullptr ;
|
|
s_pFunOutText = nullptr ;
|
|
s_bEnableUI = true ;
|
|
|
|
// 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 ;
|
|
}
|
|
|
|
// libero eventuale chiave di rete
|
|
if ( s_bNetHwKey)
|
|
CloseNetHwKey() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetOnTerminateProcess( pfOnTerminateProcess pFun)
|
|
{
|
|
s_pFunOnTerminateProcess = pFun ;
|
|
return ( pFun != nullptr) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeOnTerminateProcess( int nExitCode)
|
|
{
|
|
// lancio eventuale callback
|
|
bool bTerminate = true ;
|
|
if ( s_pFunOnTerminateProcess != nullptr)
|
|
bTerminate = s_pFunOnTerminateProcess( nExitCode) ;
|
|
|
|
// se confermata chiusura, libero eventuale chiave di rete
|
|
if ( bTerminate && s_bNetHwKey)
|
|
CloseNetHwKey() ;
|
|
|
|
return bTerminate ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
ExeGetDebugLevel( void)
|
|
{
|
|
return s_nDebugLev ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetUserLevel( int nUserLev)
|
|
{
|
|
s_nUserLev = max( nUserLev, 1) ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
ExeGetUserLevel( void)
|
|
{
|
|
return s_nUserLev ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetKey( const string& sKey)
|
|
{
|
|
s_sKey = sKey ;
|
|
SetEGnKey( s_sKey) ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
const string&
|
|
ExeGetKey( void)
|
|
{
|
|
return s_sKey ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetNestKey( const string& sNestKey)
|
|
{
|
|
s_sNestKey = sNestKey ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
const string&
|
|
ExeGetNestKey( void)
|
|
{
|
|
return s_sNestKey ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetLockType( int nType)
|
|
{
|
|
s_nKeyType = nType ;
|
|
SetEGnKeyType( s_nKeyType) ;
|
|
return SetLockType( nType) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetLockId( const string& sLockId)
|
|
{
|
|
int nKeyType ;
|
|
bool bNetKey ;
|
|
int nUserId ;
|
|
GetLockIdStringInfo( sLockId, nKeyType, bNetKey, nUserId) ;
|
|
bool bOk ;
|
|
switch ( nKeyType) {
|
|
default :
|
|
ExeSetNetHwKey( false) ;
|
|
bOk = false ;
|
|
break ;
|
|
case KEY_LOCK_TYPE_SW :
|
|
ExeSetNetHwKey( false) ;
|
|
bOk = ( s_nKeyType != KEY_LOCK_TYPE_HW) ;
|
|
break ;
|
|
case KEY_LOCK_TYPE_HW :
|
|
{ string sAddrPort ;
|
|
GetLockIdStringNetData( sLockId, sAddrPort) ;
|
|
ExeSetNetHwKey( bNetKey, nUserId, sAddrPort) ;
|
|
bOk = true ;
|
|
break ;
|
|
}
|
|
}
|
|
if ( bOk)
|
|
s_sLockId = sLockId ;
|
|
else
|
|
s_sLockId = "" ;
|
|
return bOk ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
const string&
|
|
ExeGetLockId( void)
|
|
{
|
|
if ( s_sLockId.empty())
|
|
GetLockId( s_sLockId) ;
|
|
return s_sLockId ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetNetHwKey( bool bNetHwKey, int nUserId, const string& sAddrPort)
|
|
{
|
|
s_bNetHwKey = bNetHwKey ;
|
|
SetEGnNetHwKey( s_bNetHwKey) ;
|
|
return SetNetHwKey( s_bNetHwKey, nUserId, sAddrPort) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetNetHwKey( void)
|
|
{
|
|
return s_bNetHwKey ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeVerifyKeyOption( int nOptInd)
|
|
{
|
|
// recupero le opzioni abilitate
|
|
unsigned int nOpt1, nOpt2 ;
|
|
int nOptExpDays ;
|
|
int nRet = GetEGnKeyOptions( KEY_BASELIB_PROD, KEY_BASELIB_VER, KEY_BASELIB_LEV,
|
|
nOpt1, nOpt2, nOptExpDays) ;
|
|
if ( ! ExeGetNetHwKey())
|
|
nRet = GetKeyOptions( ExeGetKey(), KEY_BASELIB_PROD, KEY_BASELIB_VER, KEY_BASELIB_LEV,
|
|
nOpt1, nOpt2, nOptExpDays) ;
|
|
// verifico validità chiave con licenza
|
|
if ( nRet != KEY_OK || nOptExpDays < GetCurrDay())
|
|
return false ;
|
|
// verifico le opzioni (nOptInd = 100 -> bit 0 di Opt1 ... = 200 -> bit 0 di Opt2 ... = 231 -> bit 31 di Opt2)
|
|
if ( nOptInd >= 100 && nOptInd <= 131) {
|
|
unsigned int nOptVal = ( 1 << ( nOptInd - 100)) ;
|
|
return ( ( nOpt1 & nOptVal) != 0) ;
|
|
}
|
|
else if ( nOptInd >= 200 && nOptInd <= 231) {
|
|
unsigned int nOptVal = ( 1 << ( nOptInd - 200)) ;
|
|
return ( ( nOpt2 & nOptVal) != 0) ;
|
|
}
|
|
else
|
|
return false ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
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
|
|
ExeGetIniFile( string& sIniFile)
|
|
{
|
|
if ( &sIniFile == nullptr)
|
|
return false ;
|
|
// recupero il nome del font di default
|
|
sIniFile = s_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( nothrow) Logger( LL_INFO, "EgtCommandLog") ;
|
|
if ( s_pCmdLog == nullptr)
|
|
return false ;
|
|
// assegno il file
|
|
ofstream* pLogFile = new( nothrow) 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
|
|
ExeGetExecutableVersion( string& sVer)
|
|
{
|
|
// verifico il parametro
|
|
if ( &sVer == nullptr)
|
|
return false ;
|
|
return GetModuleVersion( nullptr, sVer) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
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 ( IsLoadedExch3dmDll()) {
|
|
sVer += szNewLine ;
|
|
sVer += MyGetEE3Version() ;
|
|
}
|
|
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 ;
|
|
int nLockSN = 0 ;
|
|
if ( GetLockSN( nLockSN))
|
|
sLockId += " (" + ToString( nLockSN) + ")" ;
|
|
}
|
|
// 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 nRet = GetKeyLevelEx( s_sKey, nProd, nVer, nLev, nKLev, s_nKeyExpDays, s_nKeyAssExpDays) ;
|
|
SetEGnKeyLevel( nRet, nKLev, s_nKeyExpDays) ;
|
|
if ( nRet != KEY_OK) {
|
|
string sErr = "Error on Key (EGKL/" + ToString( nRet) + ")" ;
|
|
LOG_ERROR( s_pGenLog, sErr.c_str()) ;
|
|
nKLev = - nRet ;
|
|
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 nRet = GetKeyOptions( s_sKey, nProd, nVer, nLev, nOpt1, nOpt2, s_nKeyOptExpDays) ;
|
|
SetEGnKeyOptions( nRet, nOpt1, nOpt2, s_nKeyOptExpDays) ;
|
|
if ( nRet != KEY_OK) {
|
|
nOpt2 = 0 ;
|
|
string sErr = "Error on Key (EGKO/" + ToString( nRet) + ")" ;
|
|
LOG_ERROR( s_pGenLog, sErr.c_str()) ;
|
|
return false ;
|
|
}
|
|
if ( s_nKeyOptExpDays < GetCurrDay()) {
|
|
nOpt2 = 0 ;
|
|
string sErr = "Error on Key (EGKO/OPT)" ;
|
|
LOG_ERROR( s_pGenLog, sErr.c_str()) ;
|
|
return true ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetKeyLeftDays( int& nLeftDays)
|
|
{
|
|
if ( s_nKeyExpDays == 0)
|
|
return false ;
|
|
nLeftDays = s_nKeyExpDays - GetCurrDay() ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetKeyAssLeftDays( int& nAssLeftDays)
|
|
{
|
|
if ( s_nKeyAssExpDays == 0)
|
|
return false ;
|
|
nAssLeftDays = s_nKeyAssExpDays - GetCurrDay() ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetKeyOptLeftDays( int& nOptLeftDays)
|
|
{
|
|
if ( s_nKeyOptExpDays == 0)
|
|
return false ;
|
|
nOptLeftDays = s_nKeyOptExpDays - GetCurrDay() ;
|
|
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, int nDebugLevel)
|
|
{
|
|
if ( s_pGenLog == nullptr)
|
|
return false ;
|
|
if ( nDebugLevel == 0)
|
|
LOG_INFO( s_pGenLog, sMsg.c_str())
|
|
else if ( ExeGetDebugLevel() >= nDebugLevel)
|
|
LOG_DBG_INFO( s_pGenLog, sMsg.c_str())
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetEnableUI( bool bEnableUI)
|
|
{
|
|
s_bEnableUI = bEnableUI ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetEnableUI( void)
|
|
{
|
|
return s_bEnableUI ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
ExeMessageBox( const string& sText, const string& sTitle, int nType)
|
|
{
|
|
int nRes = 0 ;
|
|
if ( ExeGetEnableUI()) {
|
|
HWND hTopWnd = ExeGetMainWindowHandle() ;
|
|
nRes = MessageBox( hTopWnd, stringtoW( sText), stringtoW( sTitle), nType | MB_TASKMODAL) ;
|
|
}
|
|
return nRes ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetProcessEvents( pfProcEvents pFun)
|
|
{
|
|
s_pFunProcEvents = pFun ;
|
|
SetEGkProcessEvents( pFun) ;
|
|
return ( pFun != nullptr) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
int
|
|
ExeProcessEvents( int nProg, int nPause)
|
|
{
|
|
if ( s_pFunProcEvents != nullptr && s_bEnableUI)
|
|
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 && s_bEnableUI)
|
|
return s_pFunOutText( sText) ;
|
|
else
|
|
return false ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetTempDir( const string& sTempDir)
|
|
{
|
|
s_sTempDir = sTempDir ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetTempDir( string& sTempDir)
|
|
{
|
|
// ne verifico l'esistenza
|
|
if ( ! ExistsDirectory( s_sTempDir))
|
|
return false ;
|
|
// lo restituisco
|
|
sTempDir = s_sTempDir ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeGetStringUtf8FromIni( const string& sSec, const string& sKey, const string& sDef, string& sVal, const string& sIniFile)
|
|
{
|
|
sVal = GetPrivateProfileStringUtf8( sSec.c_str(), sKey.c_str(), sDef.c_str(), sIniFile.c_str()) ;
|
|
return ( ! sVal.empty()) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeWriteStringUtf8ToIni( const string& sSec, const string& sKey, const string& sVal, const string& sIniFile)
|
|
{
|
|
return WritePrivateProfileStringUtf8( sSec.c_str(), sKey.c_str(), sVal.c_str(), sIniFile.c_str()) ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
bool
|
|
ExeSetMainWindowHandle( HWND hMainWnd)
|
|
{
|
|
s_hMainWnd = hMainWnd ;
|
|
return true ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
HWND
|
|
ExeGetMainWindowHandle( void)
|
|
{
|
|
return s_hMainWnd ;
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------
|
|
//-----------------------------------------------------------------------------
|
|
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 ;
|
|
}
|