diff --git a/CmdParser.cpp b/CmdParser.cpp index f922d25..9eff0e1 100644 --- a/CmdParser.cpp +++ b/CmdParser.cpp @@ -13,9 +13,9 @@ //--------------------------- Include ---------------------------------------- #include "stdafx.h" -#include -#include "/EgtDev/Include/EgnStringUtils.h" #include "CmdParser.h" +#include "/EgtDev/Include/EgnStringUtils.h" +#include using namespace std ; @@ -30,6 +30,7 @@ CreateCmdParser( void) CmdParser::CmdParser( void) { m_pTheExecutor = nullptr ; + m_pLogger = nullptr ; } //---------------------------------------------------------------------------- @@ -39,10 +40,10 @@ CmdParser::~CmdParser( void) //---------------------------------------------------------------------------- bool -CmdParser::Initialize( wstring sCmdFile, ICmdExecutor* pCmdExec) +CmdParser::Init( string sCmdFile, ICmdExecutor* pCmdExec, ILogger* pLogger) { // inizializzo lo scanner - if ( ! m_TheScanner.Initialize( sCmdFile)) + if ( ! m_TheScanner.Init( sCmdFile)) return false ; // verifico la validità dell'esecutore @@ -52,6 +53,9 @@ CmdParser::Initialize( wstring sCmdFile, ICmdExecutor* pCmdExec) // salvo il riferimento al documento m_pTheExecutor = pCmdExec ; + // salvo il gestore di log + m_pLogger = pLogger ; + return true ; } @@ -60,6 +64,7 @@ bool CmdParser::Run( void) { bool bOk ; + string sOut ; string sLine ; string sCmd ; string sParams ; @@ -67,7 +72,8 @@ CmdParser::Run( void) // log di inizio file - cout << "--- Start : " << m_TheScanner.GetFilePath() << endl ; + sOut = "--- Start : " + m_TheScanner.GetFilePath() ; + LOG_INFO( m_pLogger, sOut.c_str()) ; // interpretazione dei comandi del file bOk = true ; @@ -81,13 +87,14 @@ CmdParser::Run( void) // deve esserci un comando e deve essere eseguito correttamente if ( sCmd.empty() || ! ExecCommand( sCmd, sParams)) { bOk = false ; - cout << "Error on line (" << m_TheScanner.GetCurrLineNbr() << ") : " << sLine << endl ; + sOut = "Error on line (" + ToString( m_TheScanner.GetCurrLineNbr()) + ") : " + sLine ; + LOG_INFO( m_pLogger, sOut.c_str()) ; } } // log di fine file if ( bOk) - cout << "--- End" << endl ; + LOG_INFO( m_pLogger, "--- End") ; return bOk ; } diff --git a/CmdParser.h b/CmdParser.h index a6dd131..9bc6c04 100644 --- a/CmdParser.h +++ b/CmdParser.h @@ -22,7 +22,7 @@ class CmdParser : public ICmdParser public : CmdParser( void) ; ~CmdParser( void) ; - bool Initialize( std::wstring sCmdFile, ICmdExecutor* pCmdExec) ; + bool Init( std::string sCmdFile, ICmdExecutor* pCmdExec, ILogger* pLogger) ; bool Run( void) ; private : @@ -31,4 +31,5 @@ class CmdParser : public ICmdParser private : CmdScanner m_TheScanner ; ICmdExecutor* m_pTheExecutor ; + ILogger* m_pLogger ; } ; diff --git a/CmdScanner.cpp b/CmdScanner.cpp index d977441..4123a67 100644 --- a/CmdScanner.cpp +++ b/CmdScanner.cpp @@ -14,13 +14,12 @@ //--------------------------- Include ---------------------------------------- #include "stdafx.h" +#include "CmdScanner.h" #include "/EgtDev/Include/EgnStringUtils.h" #include "/EgtDev/Include/EgnStringConverter.h" -#include "CmdScanner.h" using namespace std ; - //---------------------------------------------------------------------------- CmdScanner::CmdScanner( void) { @@ -35,19 +34,19 @@ CmdScanner::~CmdScanner( void) //---------------------------------------------------------------------------- bool -CmdScanner::Initialize( wstring sCmdFile) +CmdScanner::Init( string sCmdFile) { // se già aperto, lo chiudo Terminate() ; // apertura del file di ingresso - m_CmdFile.open( sCmdFile, ios::in) ; + m_CmdFile.open( stringtoW( sCmdFile), ios::in) ; // reset numero linea corrente m_nLineNbr = 0 ; // salvo path file - m_sFName = wstringtoA( sCmdFile) ; + m_sFName = sCmdFile ; return ( ! m_CmdFile.fail()) ; } diff --git a/CmdScanner.h b/CmdScanner.h index 3cbf454..9be06da 100644 --- a/CmdScanner.h +++ b/CmdScanner.h @@ -22,7 +22,7 @@ class CmdScanner public : CmdScanner( void) ; ~CmdScanner( void) ; - bool Initialize( std::wstring sCmdFile) ; + bool Init( std::string sCmdFile) ; bool Terminate( void) ; bool GetLine( std::string& sLine) ; int GetCurrLineNbr( void) { return m_nLineNbr ; } diff --git a/EGnDllMain.cpp b/EGnDllMain.cpp index d1f2d2f..7c09069 100644 --- a/EGnDllMain.cpp +++ b/EGnDllMain.cpp @@ -13,15 +13,15 @@ //--------------------------- Include ---------------------------------------- #include "stdafx.h" -#include -#include <\EgtDev\Include\EgtTrace.h> #include <\EgtDev\Include\EGnVersion.h> +#include <\EgtDev\Include\EgnGetModuleVer.h> +#include <\EgtDev\Include\EgtTrace.h> //--------------------------- Costanti ---------------------------------------- #if defined( _DEBUG) - const char* EGK_STR = "EgtGeneralD32.dll ver. " ; + const char* EGN_STR = "EgtGeneralD32.dll ver. " ; #else - const char* EGK_STR = "EgtGeneralR32.dll ver. " ; + const char* EGN_STR = "EgtGeneralR32.dll ver. " ; #endif const int STR_DIM = 40 ; @@ -50,38 +50,10 @@ DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved) const char* GetEGnVersion( void) { - wchar_t szFileName[_MAX_PATH] ; - DWORD dwNULL ; - DWORD dwSize ; - UINT dwUsefulSize ; - LPVOID lpData ; - LPVOID lpUsefulData ; - VS_FIXEDFILEINFO* pvsInfo ; + std::string sVer ; - - // trovo nome del file dato l'hInstance - ::GetModuleFileNameW( s_hModule, szFileName, _MAX_PATH) ; - - // mi faccio dare il buffer delle informazioni dal file - dwSize = ::GetFileVersionInfoSizeW( szFileName, &dwNULL) ; - lpData = malloc( size_t( dwSize)); - GetFileVersionInfoW( szFileName, dwNULL, dwSize, lpData) ; - - // Chiedo le info standard - if ( ::VerQueryValueW( lpData, L"\\", &lpUsefulData, &dwUsefulSize)) { - pvsInfo = (VS_FIXEDFILEINFO*) lpUsefulData ; - sprintf_s( s_szEGnNameVer, STR_DIM, "%s%d.%d%c%d", - EGK_STR, - pvsInfo->dwFileVersionMS >> 16, - pvsInfo->dwFileVersionMS % 0x10000, - (pvsInfo->dwFileVersionLS >> 16) + 96, - pvsInfo->dwFileVersionLS % 0x10000); - } - else - sprintf_s( s_szEGnNameVer, STR_DIM, "%s0.0a0", EGK_STR) ; - - // disalloco il buffer - free( lpData) ; + GetModuleVersion( s_hModule, sVer) ; + sprintf_s( s_szEGnNameVer, STR_DIM, "%s%s", EGN_STR, sVer.c_str()) ; return s_szEGnNameVer ; } diff --git a/EgtGeneral.rc b/EgtGeneral.rc index e8008d0..3e594b7 100644 Binary files a/EgtGeneral.rc and b/EgtGeneral.rc differ diff --git a/EgtGeneral.vcxproj b/EgtGeneral.vcxproj index fc98536..5007bdd 100644 --- a/EgtGeneral.vcxproj +++ b/EgtGeneral.vcxproj @@ -59,7 +59,7 @@ Windows true - version.lib;%(AdditionalDependencies) + version.lib;shlwapi.lib;%(AdditionalDependencies) copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\ @@ -84,7 +84,7 @@ copy $(TargetPath) \EgtProg\Dll true true true - version.lib;%(AdditionalDependencies) + version.lib;shlwapi.lib;%(AdditionalDependencies) copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\ @@ -98,6 +98,7 @@ copy $(TargetPath) \EgtProg\Dll + @@ -120,6 +121,7 @@ copy $(TargetPath) \EgtProg\Dll + Create diff --git a/EgtGeneral.vcxproj.filters b/EgtGeneral.vcxproj.filters index b07ce03..a765a72 100644 --- a/EgtGeneral.vcxproj.filters +++ b/EgtGeneral.vcxproj.filters @@ -51,6 +51,9 @@ File di intestazione + + File di intestazione + @@ -71,6 +74,9 @@ File di origine + + File di origine + diff --git a/GetModuleVer.cpp b/GetModuleVer.cpp new file mode 100644 index 0000000..bb1f104 --- /dev/null +++ b/GetModuleVer.cpp @@ -0,0 +1,91 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2013 +//---------------------------------------------------------------------------- +// File : GetModuleVer.cpp Data : 10.12.13 Versione : 1.4a4 +// Contenuto : Funzione che restituisce la versione del modulo richiesto. +// +// +// +// Modifiche : 10.12.13 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "\EgtDev\Include\EgnGetModuleVer.h" +#include "\EgtDev\Include\EgnStringConverter.h" +#include "\EgtDev\Include\EgnStringUtils.h" +#include + +using namespace std ; + +//----------------------------------------------------------------------------- +bool +GetModuleVersion( HINSTANCE hModule, string& sVer) +{ + bool bOk ; + wchar_t szFileName[_MAX_PATH] ; + DWORD dwNULL ; + DWORD dwSize ; + UINT dwUsefulSize ; + LPVOID lpData ; + LPVOID lpUsefulData ; + VS_FIXEDFILEINFO* pvsInfo ; + + + // trovo nome del file dato l'hInstance + ::GetModuleFileNameW( hModule, szFileName, _MAX_PATH) ; + + // mi faccio dare il buffer delle informazioni dal file + dwSize = ::GetFileVersionInfoSizeW( szFileName, &dwNULL) ; + lpData = malloc( size_t( dwSize)); + GetFileVersionInfoW( szFileName, dwNULL, dwSize, lpData) ; + + // Chiedo le info standard + if ( ::VerQueryValueW( lpData, L"\\", &lpUsefulData, &dwUsefulSize)) { + pvsInfo = (VS_FIXEDFILEINFO*) lpUsefulData ; + int nMajVer = pvsInfo->dwFileVersionMS >> 16 ; + int nMinVer = pvsInfo->dwFileVersionMS % 0x10000 ; + char cChar = (char) ( (pvsInfo->dwFileVersionLS >> 16) + 96) ; + int nSub = pvsInfo->dwFileVersionLS % 0x10000 ; + sVer = ToString( nMajVer) + "." + ToString( nMinVer) + cChar + ToString( nSub) ; + bOk = true ; + } + else { + sVer = "0.0a0" ; + bOk = false ; + } + + // disalloco il buffer + free( lpData) ; + + return bOk ; +} + +//----------------------------------------------------------------------------- +bool +GetModuleDirectory( HINSTANCE hModule, string& sDir) +{ + wchar_t szFileNameW[_MAX_PATH] ; + + + // trovo path del file dato l'hInstance + if ( ::GetModuleFileNameW( hModule, szFileNameW, _MAX_PATH) == 0) + return false ; + + // elimino nome.estensione del file + PathRemoveFileSpecW( szFileNameW) ; + + // assegno valore di ritorno + sDir = LPSTR( WtoA( szFileNameW)) ; + + return true ; +} + +//----------------------------------------------------------------------------- +bool +SetCurrentDirectory( const string& sDir) +{ + return ( SetCurrentDirectoryW( stringtoW( sDir)) != 0) ; +} \ No newline at end of file diff --git a/Scan.cpp b/Scan.cpp index 455a9f4..a9366c0 100644 --- a/Scan.cpp +++ b/Scan.cpp @@ -35,7 +35,7 @@ CScan::~CScan( void) //---------------------------------------------------------------------------- bool -CScan::Initialize( ifstream& InFile) +CScan::Init( ifstream& InFile) { // verifico che il file passato sia regolarmente aperto per lettura if ( ! InFile.is_open())