diff --git a/KeyGenerator.rc b/KeyGenerator.rc index df972df..847f315 100644 Binary files a/KeyGenerator.rc and b/KeyGenerator.rc differ diff --git a/KeyGeneratorDlg.cpp b/KeyGeneratorDlg.cpp index 1f71c79..479db4b 100644 --- a/KeyGeneratorDlg.cpp +++ b/KeyGeneratorDlg.cpp @@ -115,7 +115,7 @@ CKeyGeneratorDlg::CKeyGeneratorDlg( const string& sFileToOpen, int nFlag, CWnd* m_hIcon = AfxGetApp()->LoadIcon( IDR_MAINFRAME) ; // eventuale file da caricare all'avvio m_sFileToOpen = sFileToOpen ; - m_nFlag = nFlag ; + m_bSpecial = ( ! m_sFileToOpen.empty() && nFlag == 1) ; } //---------------------------------------------------------------------------- @@ -161,7 +161,7 @@ CKeyGeneratorDlg::OnInitDialog( void) if ( ! m_sFileToOpen.empty()) { // leggo il file e genero if ( LoadFile( m_sFileToOpen.c_str())) { - if ( m_nFlag == 1) + if ( m_bSpecial) PostMessage( WM_COMMAND, IDC_GENER, 0) ; return TRUE ; } @@ -417,14 +417,14 @@ CKeyGeneratorDlg::OnGenerate( void) mKey.GetKey( sKey) ; // salvo i dati - if ( ! mKey.SaveData()) + if ( ! mKey.SaveData( m_bSpecial)) AfxMessageBox( L"Errore nel salvataggio dei dati") ; // visualizzo i risultanti CKeyDlg dlgKey( sKey) ; dlgKey.DoModal() ; - // se lanciato con file, esco dal programma - if ( ! m_sFileToOpen.empty() && m_nFlag == 1) + // se lanciato con file e flag 1, esco dal programma + if ( m_bSpecial) PostMessage( WM_CLOSE, 0, 0) ; } diff --git a/KeyGeneratorDlg.h b/KeyGeneratorDlg.h index 88c2775..4730263 100644 --- a/KeyGeneratorDlg.h +++ b/KeyGeneratorDlg.h @@ -39,7 +39,7 @@ class CKeyGeneratorDlg : public CDialogEx private : HICON m_hIcon ; std::string m_sFileToOpen ; - int m_nFlag ; + bool m_bSpecial ; DECLARE_MESSAGE_MAP() } ; diff --git a/KeyMaker.cpp b/KeyMaker.cpp index d0c8490..c059e53 100644 --- a/KeyMaker.cpp +++ b/KeyMaker.cpp @@ -175,7 +175,7 @@ KeyMaker::GetKey( string& sKey) //---------------------------------------------------------------------------- bool -KeyMaker::SaveData( void) +KeyMaker::SaveData( bool bSpecial) { // direttorio di salvataggio string sDataDir = GetPrivateProfileStringUtf8( "General", "DataDir", "C:/EgtProg/KeyGenerator", AfxGetApp()->m_pszProfileName) ; @@ -190,7 +190,8 @@ KeyMaker::SaveData( void) // se cambiati i dati, aggiungo nuova versione di licenza if ( DiffLicence( sLogFile.c_str())) { // salvo nuovo indice salvataggio - ++ nLast ; + if ( ! bSpecial) + ++ nLast ; WritePrivateProfileInt( "Index", "Last", nLast, sLogFile.c_str()) ; // aggiorno nome sezione sSec = "Licence" + ToString( nLast) ; @@ -200,7 +201,7 @@ KeyMaker::SaveData( void) } // path file licenza - string sLicFile = sDataDir + "\\" + m_sCustomer + "_" + sSec + ".lic" ; + string sLicFile = sDataDir + "\\" + m_sCustomer + ( bSpecial ? "" : "_" + sSec) + ".lic" ; // linea per evitare problemi con BOM ofstream ofOut( stringtoW( sLicFile), ios_base::out | ios_base::trunc) ; if ( ! ofOut.good()) diff --git a/KeyMaker.h b/KeyMaker.h index fc56326..5b36632 100644 --- a/KeyMaker.h +++ b/KeyMaker.h @@ -31,7 +31,7 @@ class KeyMaker bool SetOptExpirDays( int nOptExpDays) ; bool CalcKey( void) ; bool GetKey( std::string& sKey) ; - bool SaveData( void) ; + bool SaveData( bool bSpecial) ; private : bool DiffLicence( const char* szFile) ;