EgtGeneral 1.4a4 : Aggiunte funzioni GetModule*. Si usano solo string.

This commit is contained in:
Dario Sassi
2013-12-11 18:29:32 +00:00
parent 4903e8f3fd
commit 07cfdd76f3
10 changed files with 130 additions and 52 deletions
+14 -7
View File
@@ -13,9 +13,9 @@
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include <iostream>
#include "/EgtDev/Include/EgnStringUtils.h"
#include "CmdParser.h"
#include "/EgtDev/Include/EgnStringUtils.h"
#include <iostream>
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 ;
}
+2 -1
View File
@@ -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 ;
} ;
+4 -5
View File
@@ -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()) ;
}
+1 -1
View File
@@ -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 ; }
+7 -35
View File
@@ -13,15 +13,15 @@
//--------------------------- Include ----------------------------------------
#include "stdafx.h"
#include <windows.h>
#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 ;
}
BIN
View File
Binary file not shown.
+4 -2
View File
@@ -59,7 +59,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>version.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\
@@ -84,7 +84,7 @@ copy $(TargetPath) \EgtProg\Dll</Command>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>version.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>version.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PostBuildEvent>
<Command>copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\
@@ -98,6 +98,7 @@ copy $(TargetPath) \EgtProg\Dll</Command>
<ItemGroup>
<ClInclude Include="..\Include\EgnCmdExecutor.h" />
<ClInclude Include="..\Include\EgnCmdParser.h" />
<ClInclude Include="..\Include\EgnGetModuleVer.h" />
<ClInclude Include="..\Include\EGnScan.h" />
<ClInclude Include="..\Include\EGnStringBase.h" />
<ClInclude Include="..\Include\EGnStringConverter.h" />
@@ -120,6 +121,7 @@ copy $(TargetPath) \EgtProg\Dll</Command>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="GetModuleVer.cpp" />
<ClCompile Include="Scan.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
+6
View File
@@ -51,6 +51,9 @@
<ClInclude Include="..\Include\EgtTrace.h">
<Filter>File di intestazione</Filter>
</ClInclude>
<ClInclude Include="..\Include\EgnGetModuleVer.h">
<Filter>File di intestazione</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
@@ -71,6 +74,9 @@
<ClCompile Include="CmdScanner.cpp">
<Filter>File di origine</Filter>
</ClCompile>
<ClCompile Include="GetModuleVer.cpp">
<Filter>File di origine</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="EgtGeneral.rc">
+91
View File
@@ -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 <Shlwapi.h>
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) ;
}
+1 -1
View File
@@ -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())