94640720eb
- primo rilascio.
192 lines
5.4 KiB
C++
192 lines
5.4 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2013-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : KeyProcess.cpp Data : 11.09.14 Versione : 1.5i2
|
|
// Contenuto : Implementazione funzioni costruzione chiave.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 11.09.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "KeyMaker.h"
|
|
#include "/EgtDev/Include/SELkMachineId.h"
|
|
#include "/EgtDev/Include/SELkKeyProc.h"
|
|
#include "/EgtDev/Include/EGnStringUtils.h"
|
|
#include "/EgtDev/Include/EgtIniFile.h"
|
|
#include <fstream>
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//----------------------------------------------------------------------------
|
|
KeyMaker::KeyMaker( void)
|
|
{
|
|
m_sCustomer.clear() ;
|
|
m_sMachineId.clear() ;
|
|
m_sMachineId2.clear() ;
|
|
m_sScramKey.clear() ;
|
|
m_nProd = 0 ;
|
|
m_nVer = 0 ;
|
|
m_nLev = 0 ;
|
|
m_nExpDays = 0 ;
|
|
m_nOpt1 = 0 ;
|
|
m_nOpt2 = 0 ;
|
|
m_nOptExpDays = 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::SetCustomer( const string& sCustomer)
|
|
{
|
|
// verifico validità nome come nome di file
|
|
if ( ! IsValidName( sCustomer))
|
|
return false ;
|
|
m_sCustomer = sCustomer ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::SetMachineId( const string& sMachineId2)
|
|
{
|
|
// calcolo identificativo macchina in chiaro
|
|
string sMachineId ;
|
|
if ( ! ConvertMachineId2ToMachineId( sMachineId2, sMachineId))
|
|
return false ;
|
|
// calcolo chiave di scramble
|
|
string sScramKey ;
|
|
if ( ! ConvertMachineId2ToScramKey( sMachineId2, sScramKey))
|
|
return false ;
|
|
m_sMachineId2 = sMachineId2 ;
|
|
m_sMachineId = sMachineId ;
|
|
m_sScramKey = sScramKey ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::SetProduct( const std::string& sProd)
|
|
{
|
|
int nProd ;
|
|
if ( ! FromString( sProd, nProd) ||
|
|
nProd < 100 || nProd > 9999)
|
|
return false ;
|
|
m_nProd = nProd ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::SetVersion( const std::string& sVer)
|
|
{
|
|
int nVer ;
|
|
if ( ! FromString( sVer, nVer) ||
|
|
nVer < 15 || nVer > 99)
|
|
return false ;
|
|
m_nVer = nVer ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::SetLevel( const std::string& sLev)
|
|
{
|
|
int nLev ;
|
|
if ( ! FromString( sLev, nLev) ||
|
|
nLev < 1 || nLev > 99)
|
|
return false ;
|
|
m_nLev = nLev ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::SetExpirDays( int nExpDays)
|
|
{
|
|
if ( nExpDays < 0 || nExpDays > 999999)
|
|
return false ;
|
|
m_nExpDays = nExpDays ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::SetOptions( unsigned int nOpt1, unsigned int nOpt2)
|
|
{
|
|
m_nOpt1 = nOpt1 ;
|
|
m_nOpt2 = nOpt2 ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::SetOptExpirDays( int nOptExpDays)
|
|
{
|
|
if ( nOptExpDays < 0 || nOptExpDays > 999999)
|
|
return false ;
|
|
m_nOptExpDays = nOptExpDays ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::CalcKey( void)
|
|
{
|
|
string sKey ;
|
|
if ( ! MakeKey( m_nProd, m_nVer, m_nLev, m_nExpDays,
|
|
m_nOpt1, m_nOpt2, m_nOptExpDays,
|
|
m_sScramKey, sKey))
|
|
return false ;
|
|
m_sKey = sKey ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::GetKey( string& sKey)
|
|
{
|
|
if ( m_sKey.empty())
|
|
return false ;
|
|
sKey = m_sKey ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
KeyMaker::SaveData( void)
|
|
{
|
|
// determino path file 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) ;
|
|
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.close() ;
|
|
return true ;
|
|
}
|