KeyGenerator 1.6c6 :

- possibilità di caricare file Kge
- generazione file lic.
This commit is contained in:
Dario Sassi
2015-03-30 06:46:52 +00:00
parent 5fc9544fe3
commit b356c23a45
7 changed files with 208 additions and 56 deletions
+93 -19
View File
@@ -164,28 +164,102 @@ KeyMaker::GetKey( string& sKey)
bool
KeyMaker::SaveData( void)
{
// determino path file di salvataggio
// direttorio di salvataggio
string sDataDir = GetPrivateProfileStringUtf8( "General", "DataDir", "C:/EgtProg/KeyGenerator", AfxGetApp()->m_pszProfileName) ;
TrimRight( sDataDir, "/\\") ;
string sFile = sDataDir + "/" + m_sCustomer + ".Kge" ;
// apro il file
ofstream ofOut( stringtoW( sFile), ios_base::out | ios_base::app) ;
// path file di log
string sLogFile = sDataDir + "\\" + m_sCustomer + ".Kge" ;
// leggo indice ultimo salvataggio
int nLast = GetPrivateProfileInt( "Index", "Last", 0, sLogFile.c_str()) ;
// assegno nome sezione
string sSec = "Licence" + ToString( nLast) ;
// se cambiati i dati, aggiungo nuova versione di licenza
if ( DiffLicence( sLogFile.c_str())) {
// salvo nuovo indice salvataggio
++ nLast ;
WritePrivateProfileInt( "Index", "Last", nLast, sLogFile.c_str()) ;
// aggiorno nome sezione
sSec = "Licence" + ToString( nLast) ;
// salvo i nuovi dati
if ( ! WriteLicence( sSec.c_str(), sLogFile.c_str(), true))
return false ;
}
// path file licenza
string sLicFile = sDataDir + "\\" + m_sCustomer + "_" + sSec + ".lic" ;
// linea per evitare problemi con BOM
ofstream ofOut( stringtoW( sLicFile), ios_base::out | ios_base::trunc) ;
if ( ! ofOut.good())
return false ;
// inserisco la data
ofOut << CurrDateTime() << endl ;
ofOut << "Customer=" << m_sCustomer << endl ;
ofOut << "MachineId=" << m_sMachineId2 << endl ;
ofOut << "ClearMachineId=" << m_sMachineId << endl ;
ofOut << "Product=" << m_nProd << endl ;
ofOut << "Ver=" << m_nVer << endl ;
ofOut << "Lev=" << m_nLev << endl ;
ofOut << "ExpDays=" << m_nExpDays << endl ;
ofOut << "Opt1=" << m_nOpt1 << endl ;
ofOut << "Opt2=" << m_nOpt2 << endl ;
ofOut << "OptExpDays=" << m_nOptExpDays << endl ;
ofOut << "Key=" << m_sKey << endl ;
// chiudo il file
ofOut << "; Commento per evitare BOM con UTF-8" << endl ;
ofOut.close() ;
return true ;
// salvo i nuovi dati
return WriteLicence( "Licence", sLicFile.c_str(), false) ;
}
//----------------------------------------------------------------------------
bool
KeyMaker::DiffLicence( const char* szFile)
{
// leggo indice ultimo salvataggio
int nLast = GetPrivateProfileInt( "Index", "Last", 0, szFile) ;
// sezione ultimo salvataggio
string sSec = "Licence" + ToString( nLast) ;
// leggo i dati dell'ultimo salvataggio e li confronto con gli attuali
string sCust = GetPrivateProfileStringUtf8( sSec.c_str(), "Customer", "", szFile) ;
if ( sCust != m_sCustomer)
return true ;
string sMachId = GetPrivateProfileStringUtf8( sSec.c_str(), "MachineId", "", szFile) ;
if ( sMachId != m_sMachineId2)
return true ;
string sClearMachId = GetPrivateProfileStringUtf8( sSec.c_str(), "ClearMachineId", "", szFile) ;
if ( sClearMachId != m_sMachineId)
return true ;
int nProd = GetPrivateProfileInt( sSec.c_str(), "Product", 0, szFile) ;
if ( nProd != m_nProd)
return true ;
int nVer = GetPrivateProfileInt( sSec.c_str(), "Ver", 0, szFile) ;
if ( nVer != m_nVer)
return true ;
int nLev = GetPrivateProfileInt( sSec.c_str(), "Lev", 0, szFile) ;
if ( nLev != m_nLev)
return true ;
int nExpDays = GetPrivateProfileInt( sSec.c_str(), "ExpDays", 0, szFile) ;
if ( nExpDays != m_nExpDays)
return true ;
int nOpt1 = GetPrivateProfileInt( sSec.c_str(), "Opt1", 0, szFile) ;
if ( nOpt1 != m_nOpt1)
return true ;
int nOpt2 = GetPrivateProfileInt( sSec.c_str(), "Opt2", 0, szFile) ;
if ( nOpt2 != m_nOpt2)
return true ;
int nOptExpDays = GetPrivateProfileInt( sSec.c_str(), "OptExpDays", 0, szFile) ;
if ( nOptExpDays != m_nOptExpDays)
return true ;
string sKey = GetPrivateProfileStringUtf8( sSec.c_str(), "Key", "", szFile) ;
if ( sKey != m_sKey)
return true ;
return false ;
}
//----------------------------------------------------------------------------
bool
KeyMaker::WriteLicence( const char* szSec, const char* szFile, bool bAll)
{
if ( bAll)
WritePrivateProfileStringUtf8( szSec, "Date", CurrDateTime().c_str(), szFile) ;
WritePrivateProfileStringUtf8( szSec, "Customer", m_sCustomer.c_str(), szFile) ;
WritePrivateProfileStringUtf8( szSec, "MachineId", m_sMachineId2.c_str(), szFile) ;
if ( bAll)
WritePrivateProfileStringUtf8( szSec, "ClearMachineId", m_sMachineId.c_str(), szFile) ;
WritePrivateProfileInt( szSec, "Product", m_nProd, szFile) ;
WritePrivateProfileInt( szSec, "Ver", m_nVer, szFile) ;
WritePrivateProfileInt( szSec, "Lev", m_nLev, szFile) ;
WritePrivateProfileInt( szSec, "ExpDays", m_nExpDays, szFile) ;
WritePrivateProfileInt( szSec, "Opt1", m_nOpt1, szFile) ;
WritePrivateProfileInt( szSec, "Opt2", m_nOpt2, szFile) ;
WritePrivateProfileInt( szSec, "OptExpDays", m_nOptExpDays, szFile) ;
WritePrivateProfileStringUtf8( szSec, "Key", m_sKey.c_str(), szFile) ;
return true ;
}