24a703ba04
- ricompilazione con cambio versione.
222 lines
8.8 KiB
C++
222 lines
8.8 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2023-2024
|
|
//----------------------------------------------------------------------------
|
|
// File : EgtEngine.cpp Data : 09.04.24 Versione : 2.6d2
|
|
// 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
|
|
// Per file INI
|
|
static char S_GENERAL[] = "General" ;
|
|
static char K_USERLEVEL[] = "UserLevel" ;
|
|
static char K_LICENCE[] = "Licence" ;
|
|
static char K_NETKEY[] = "NetKey" ;
|
|
static char K_DEBUG[] = "Debug" ;
|
|
static char K_MESSAGESDIR[] = "MessagesDir" ;
|
|
static char S_LUA[] = "Lua" ;
|
|
static char K_LIBSDIR[] = "LibsDir" ;
|
|
static char K_BASELIB[] = "BaseLib" ;
|
|
static char S_GEOMDB[] = "GeomDB" ;
|
|
static char K_NFEFONTDIR[] = "NfeFontDir" ;
|
|
static char K_DEFAULTFONT[] = "DefaultFont" ;
|
|
static char S_SCENE[] = "Scene" ;
|
|
static char K_MMUNITS[] = "MmUnits" ;
|
|
static char S_IMPORT[] = "Import" ;
|
|
static char K_BTLFLAG[] = "BtlFlag" ;
|
|
static char K_BTLAUXDIR[] = "BtlAuxDir" ;
|
|
static char S_MACH[] = "Mach" ;
|
|
static char K_MACHINESDIR[] = "MachinesDir" ;
|
|
static char K_TOOLMAKERSDIR[] = "ToolMakersDir" ;
|
|
// Per file LICENCE
|
|
static char S_LICENCE[] = "Licence" ;
|
|
static char K_KEY[] = "Key" ;
|
|
static char K_NESTKEY[] = "NestKey" ;
|
|
static char K_LOCKID[] = "LockId" ;
|
|
|
|
//------------------------- 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( S_MACH, K_MACHINESDIR, "", sFileIni.c_str()) ;
|
|
if ( sMachinesRoot.empty())
|
|
sMachinesRoot = sDataRoot + "\\Machines" ;
|
|
// Impostazione direttorio toolmakers
|
|
string sToolMakersDir = GetPrivateProfileStringUtf8( S_MACH, K_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( S_GENERAL, K_LICENCE, "", sFileIni.c_str()) ;
|
|
string sKey = GetPrivateProfileStringUtf8( S_LICENCE, K_KEY, "", sFileLic.c_str()) ;
|
|
ExeSetKey( sKey) ;
|
|
string sNestKey = GetPrivateProfileStringUtf8( S_LICENCE, K_NESTKEY, "", sFileLic.c_str()) ;
|
|
ExeSetNestKey( sNestKey) ;
|
|
// Impostazioni per chiave di rete
|
|
bool bNetHwKey = ( GetPrivateProfileInt( S_GENERAL, K_NETKEY, 0, sFileIni.c_str()) == 1) ;
|
|
ExeSetNetHwKey( bNetHwKey) ;
|
|
string sLockId = GetPrivateProfileStringUtf8( S_LICENCE, K_LOCKID, "", sFileLic.c_str()) ;
|
|
if ( ! IsEmptyOrSpaces( sLockId))
|
|
ExeSetLockId( sLockId) ;
|
|
// Recupero livello e opzioni della chiave
|
|
int nKeyLev ; unsigned int nKeyOptions ;
|
|
bool bKey = ExeGetKeyLevel( 9935, 2710, 1, nKeyLev) &&
|
|
ExeGetKeyOptions( 9935, 2710, 1, nKeyOptions) ;
|
|
// Recupero livello utente e livello di debug
|
|
int nUserLev = min( GetPrivateProfileInt( S_GENERAL, K_USERLEVEL, 1, sFileIni.c_str()), nKeyLev) ;
|
|
int nDebug = GetPrivateProfileInt( S_GENERAL, K_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( S_GENERAL, K_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( S_GEOMDB, K_NFEFONTDIR, "", sFileIni.c_str()) ;
|
|
string sDefFont = GetPrivateProfileStringUtf8( S_GEOMDB, K_DEFAULTFONT, "", sFileIni.c_str()) ;
|
|
ExeSetFont( sNfeDir, sDefFont) ;
|
|
// Imposto dir di default per libreria Lua e lancio libreria di base
|
|
string sLuaLibsDir = GetPrivateProfileStringUtf8( S_LUA, K_LIBSDIR, "", sFileIni.c_str()) ;
|
|
ExeSetLuaLibs( sLuaLibsDir) ;
|
|
string sLuaBaseLib = GetPrivateProfileStringUtf8( S_LUA, K_BASELIB, "EgtBase", sFileIni.c_str()) ;
|
|
ExeLuaRequire( sLuaBaseLib) ;
|
|
// Imposto direttorio ausiliario per import/gestione BTL (sempre dopo impostazioni lua)
|
|
string sBtlAuxDir = GetPrivateProfileStringUtf8( S_IMPORT, K_BTLAUXDIR, "", sFileIni.c_str()) ;
|
|
ExeSetBtlAuxDir( sBtlAuxDir) ;
|
|
// Imposto unità di misura di interfaccia (per generazione CN)
|
|
bool bMM = ( GetPrivateProfileInt( S_SCENE, K_MMUNITS, 1, sFileIni.c_str()) != 0) ;
|
|
ExeSetUiUnits( bMM) ;
|
|
// Imposto direttorio temporaneo a EgtInterface
|
|
ExeSetTempDir( sTempDir) ;
|
|
// Imposto IniFile a EgtInterface
|
|
ExeSetIniFile( sFileIni) ;
|
|
// Verifiche chiave e licenza
|
|
if ( ! bKey) {
|
|
if ( nKeyLev == -1 || nKeyLev == -2) {
|
|
if ( ! ExeGetNetHwKey())
|
|
ExeOutLog( "Error : Missing Protection Key") ;
|
|
else
|
|
ExeOutLog( "Error : Net Key is full") ;
|
|
}
|
|
else if ( nKeyLev == -9)
|
|
ExeOutLog( "Error : Missing Link with Net 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) ;
|
|
// Inizializzo gestore lavorazioni
|
|
ExeInitMachMgr( sMachinesRoot, sToolMakersDir) ;
|
|
// Eventuale inizializzazione gestore travi e pareti
|
|
if ( ( nKeyOptions & 64) != 0 || ( nKeyOptions & 512) != 0) {
|
|
int nFlag = GetPrivateProfileInt( S_IMPORT, K_BTLFLAG, 0, sFileIni.c_str()) ;
|
|
ExeInitBeamMgr( nFlag) ;
|
|
}
|
|
// 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 ;
|
|
}
|