//---------------------------------------------------------------------------- // EgalTech 2023-2023 //---------------------------------------------------------------------------- // File : EgtEngine.cpp Data : 30.05.23 Versione : 2.5e5 // Contenuto : Motore di calcolo geometrico-grafico con lua. // // // // Modifiche : 24.04.23 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "/EgtDev/Include/EgtIniFile.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EGnGetModuleVer.h" #include "/EgtDev/Include/EGnPcInfo.h" #include "/EgtDev/Include/SELkLockId.h" using namespace std ; //--------------------------- Costanti ---------------------------------------- #if defined( _WIN64) #if defined( _DEBUG) const string EXE_NAME = "EgtEngineD64.exe" ; #else const string EXE_NAME = "EgtEngineR64.exe" ; #endif #elif defined( _WIN32) #if defined( _DEBUG) const string EXE_NAME = "EgtEngineD32.exe" ; #else const string EXE_NAME = "EgtEngineR32.exe" ; #endif #endif //------------------------- Variabili locali --------------------------------- //---------------------------------------------------------------------------- int wmain( int argc, wchar_t* argv[]) { // Primo parametro della linea di comando : nome eseguibile // Non interessa // Secondo parametro della linea di comando : indice di istanza wstring swInstance = ( argc >= 2 ? argv[1] : L"") ; string sInstance = wstringtoA( swInstance) ; // Terzo parametro della linea di comando : script lua da eseguire wstring swLuaPath = ( argc >= 3 ? argv[2] : L"") ; string sLuaPath = wstringtoA( swLuaPath) ; // Quarto parametro opzionale della linea di comando : da passare allo script lua wstring swParam2 = ( argc >= 4 ? argv[3] : L"") ; string sParam2 = wstringtoA( swParam2) ; // Recupero il direttorio del programma e lo imposto come direttorio di lavoro string sExeDir ; GetModuleDirectory( NULL, sExeDir) ; SetCurrentDirectory( sExeDir) ; // Impostazione path radice per i dati string sDataRoot = GetPrivateProfileStringUtf8( "Data", "DataRoot", "", ( sExeDir + "\\DataRoot.ini").c_str()) ; if ( sDataRoot.empty()) sDataRoot = sExeDir ; // Impostazione direttorio di configurazione string sConfigDir = sDataRoot + "\\Config" ; // Impostazione direttorio per i file temporanei string sTempDir = sDataRoot + "\\Temp" ; // Impostazione path del file Ini string sFileIni = sConfigDir + "\\EgtEngine.ini" ; // Impostazione direttorio per le macchine string sMachinesRoot = GetPrivateProfileStringUtf8( "Mach", "MachinesDir", "", sFileIni.c_str()) ; if ( sMachinesRoot.empty()) sMachinesRoot = sDataRoot + "\\Machines" ; // Impostazione direttorio toolmakers string sToolMakersDir = GetPrivateProfileStringUtf8( "Mach", "ToolMakersDir", "", sFileIni.c_str()) ; if ( sToolMakersDir.empty()) sToolMakersDir = sDataRoot + "\\ToolMakers" ; // Imposto tipo chiave ExeSetLockType( KEY_LOCK_TYPE_HW) ; // Leggo e imposto chiave di protezione ed eventuale chiave nesting string sFileLic = sConfigDir + "\\" + GetPrivateProfileStringUtf8( "General", "Licence", "", sFileIni.c_str()) ; string sKey = GetPrivateProfileStringUtf8( "Licence", "Key", "", sFileLic.c_str()) ; ExeSetKey( sKey) ; string sNestKey = GetPrivateProfileStringUtf8( "Licence", "NestKey", "", sFileLic.c_str()) ; ExeSetNestKey( sNestKey) ; // Impostazioni per chiave di rete bool bNetHwKey = ( GetPrivateProfileInt( "General", "NetKey", 0, sFileIni.c_str()) == 1) ; ExeSetNetHwKey( bNetHwKey) ; string sLockId = GetPrivateProfileStringUtf8( "Licence", "LockId", "", sFileLic.c_str()) ; if ( ! IsEmptyOrSpaces( sLockId)) ExeSetLockId( sLockId) ; // Recupero livello e opzioni della chiave int nKeyLev ; unsigned int nKeyOptions ; bool bKey = ExeGetKeyLevel( 9935, 2511, 1, nKeyLev) && ExeGetKeyOptions( 9935, 2511, 1, nKeyOptions) ; // Recupero livello utente e livello di debug int nUserLev = min( GetPrivateProfileInt( "General", "UserLevel", 1, sFileIni.c_str()), nKeyLev) ; int nDebug = GetPrivateProfileInt( "General", "Debug", 0, sFileIni.c_str()) ; // Imposto file di log string sLogFile = sTempDir + "\\EgtEngineLog" + sInstance + ".txt" ; // Imposto messaggio iniziale di Log string sUserInfo ; GetUserInfo( sUserInfo) ; string sExeVer ; GetModuleVersion( NULL, sExeVer) ; string sLogMsg = "User " + sUserInfo + " Inst" + ToString( 1) + " Ulv" + ToString( nUserLev) + " Dbg" + ToString( nDebug) + "\n" + EXE_NAME + " ver." + sExeVer ; // Inizializzo Executor ExeInit( nDebug, sLogFile, sLogMsg) ; ExeSetUserLevel( nUserLev) ; // Leggo file messaggi string sMsgDir = GetPrivateProfileStringUtf8( "General", "MessagesDir", "", sFileIni.c_str()) ; if ( sMsgDir.empty()) sMsgDir = sConfigDir ; if ( ! ExeLoadMessages( sMsgDir + "\\EgalTechEng.txt")) ExeOutLog( "Error : ExeLoadMessages failed") ; // Imposto direttorio font Nfe e font di default string sNfeDir = GetPrivateProfileStringUtf8( "GeomDB", "NfeFontDir", "", sFileIni.c_str()) ; string sDefFont = GetPrivateProfileStringUtf8( "GeomDB", "DefaultFont", "", sFileIni.c_str()) ; ExeSetFont( sNfeDir, sDefFont) ; // Imposto dir di default per libreria Lua e lancio libreria di base string sLuaLibsDir = GetPrivateProfileStringUtf8( "Lua", "LibsDir", "", sFileIni.c_str()) ; ExeSetLuaLibs( sLuaLibsDir) ; string sLuaBaseLib = GetPrivateProfileStringUtf8( "Lua", "BaseLib", "EgtBase", sFileIni.c_str()) ; ExeLuaRequire( sLuaBaseLib) ; // Imposto direttorio temporaneo a EgtInterface ExeSetTempDir( sTempDir) ; // Imposto IniFile a EgtInterface ExeSetIniFile( sFileIni) ; // Verifiche chiave e licenza if ( ! bKey) { if ( nKeyLev == -1) ExeOutLog( "Error : Missing Protection Key") ; else ExeOutLog( "Error : Missing or Expired Licence") ; ExeExit() ; return 1 ; } // Creazione contesto con DB geometrico if ( ExeInitContext() == 0) { ExeOutLog( "Error : ExeInitContext failed") ; ExeExit() ; return 2 ; } ExeInitTscExec() ; // Disabilito utilizzo UI perchè non definita ExeSetEnableUI( false) ; // Impostazioni per macchine ExeInitMachMgr( sMachinesRoot, sToolMakersDir) ; // Verifico definizione script lua if ( sLuaPath.empty()) { ExeOutLog( "Error : Empty lua script path") ; ExeExit() ; return 3 ; } // Imposto parametri per script lua ExeLuaCreateGlobTable( "ENG") ; ExeLuaSetGlobStringVar( "ENG.IniPath", sFileIni) ; ExeLuaSetGlobStringVar( "ENG.Param2", sParam2) ; // Eseguo script lua ExeLuaExecFile( sLuaPath) ; // Recupero codicie di errore int nErr = 999 ; ExeLuaGetGlobIntVar( "ENG.ERR", &nErr) ; string sRes = "Result = " + ToString( nErr) ; ExeOutLog( sRes.c_str()) ; // Cancello tabella parametri di scambio ExeLuaResetGlobVar( "ENG") ; // Chiudo Executor ExeExit() ; return 0 ; }