2007-07-25 10:43:05 +00:00
//Il sorgente va scritto in notazione ungherese.
//Le variabili seguono la seguente regola: 'acronimo tipo'+'nome variabile cammellata'
//Es. wxArrayString 'as' + 'AcceptRefuse' -> asAcceptRefuse
2007-07-23 15:01:38 +00:00
# include "wxinc.h"
# ifdef WIN32
# include <shlobj.h>
# endif
2007-11-21 10:37:43 +00:00
# include <wx/protocol/http.h>
2007-09-26 12:59:37 +00:00
# include <wx/snglinst.h>
2007-09-20 09:53:21 +00:00
# include "key.h"
# include "wizard.h"
# include "utils.h"
2007-08-08 09:24:19 +00:00
2007-07-23 15:01:38 +00:00
///////////////////////////////////////////////////////////
2007-08-08 09:24:19 +00:00
// CampoFrame
2007-07-23 15:01:38 +00:00
///////////////////////////////////////////////////////////
2007-08-08 09:24:19 +00:00
class CampoFrame : public wxFrame
2007-07-23 15:01:38 +00:00
{
protected :
DECLARE_EVENT_TABLE ( ) ;
virtual void OnErase ( wxEraseEvent & e ) ;
public :
2007-08-08 09:24:19 +00:00
CampoFrame ( ) ;
2007-07-23 15:01:38 +00:00
} ;
2007-08-08 09:24:19 +00:00
BEGIN_EVENT_TABLE ( CampoFrame , wxFrame )
EVT_ERASE_BACKGROUND ( CampoFrame : : OnErase )
2007-07-23 15:01:38 +00:00
END_EVENT_TABLE ( )
2007-08-08 09:24:19 +00:00
void CampoFrame : : OnErase ( wxEraseEvent & e )
2007-07-23 15:01:38 +00:00
{
//preparazione background
wxDC & dc = * e . GetDC ( ) ;
const wxRect rect = GetClientSize ( ) ;
wxColour c0 = wxSystemSettings : : GetColour ( wxSYS_COLOUR_3DLIGHT ) ;
wxColour c1 = wxSystemSettings : : GetColour ( wxSYS_COLOUR_3DFACE ) ;
wxColour c2 = wxSystemSettings : : GetColour ( wxSYS_COLOUR_3DDKSHADOW ) ;
wxRect rect1 = rect ; rect1 . SetBottom ( rect . GetBottom ( ) / 2 ) ;
dc . GradientFillLinear ( rect1 , c0 , c1 , wxSOUTH ) ;
wxRect rect2 = rect ; rect2 . SetTop ( rect . GetBottom ( ) / 2 ) ;
dc . GradientFillLinear ( rect2 , c1 , c2 , wxDOWN ) ;
2007-10-04 14:46:14 +00:00
const int nHeight = rect . GetHeight ( ) / 10 ;
2007-07-23 15:01:38 +00:00
wxFont * pFont = wxTheFontList - > FindOrCreateFont ( nHeight , wxFONTFAMILY_SWISS , wxFONTSTYLE_ITALIC ,
wxFONTWEIGHT_BOLD ) ;
dc . SetFont ( * pFont ) ;
dc . SetBackgroundMode ( wxTRANSPARENT ) ;
const int k = nHeight / 16 + 1 ;
dc . SetTextForeground ( c2 ) ;
dc . DrawText ( APPNAME , k , k ) ;
dc . SetTextForeground ( c1 ) ;
dc . DrawText ( APPNAME , k / 2 , k / 2 ) ;
int w , h ;
const wxString strSetup = wxT ( " Setup " ) ;
dc . GetTextExtent ( strSetup , & w , & h ) ;
dc . SetTextForeground ( c2 ) ;
dc . DrawText ( strSetup , rect . GetRight ( ) - w - k / 2 , rect . GetHeight ( ) - h - k / 2 ) ;
dc . SetTextForeground ( c1 ) ;
dc . DrawText ( strSetup , rect . GetRight ( ) - w - k , rect . GetHeight ( ) - h - k ) ;
}
2007-08-08 09:24:19 +00:00
CampoFrame : : CampoFrame ( )
2007-07-23 15:01:38 +00:00
: wxFrame ( NULL , wxID_ANY , wxEmptyString , wxDefaultPosition , wxDefaultSize , 0 )
{
ShowFullScreen ( true ) ;
}
///////////////////////////////////////////////////////////
2007-08-08 09:24:19 +00:00
// CampoSetup
2007-07-23 15:01:38 +00:00
///////////////////////////////////////////////////////////
2007-08-08 09:24:19 +00:00
//classe principale, ovvero applicazione
class CampoSetup : public wxApp
2007-07-23 15:01:38 +00:00
{
2007-08-08 09:24:19 +00:00
CampoFrame * m_pMainFrame ;
2007-07-23 15:01:38 +00:00
wxLocale m_locale ;
2007-09-17 14:20:41 +00:00
wxString m_strSetupPath ;
2007-07-23 15:01:38 +00:00
2007-09-14 11:07:04 +00:00
CampoWizard * m_pWizard ;
2007-08-09 10:33:02 +00:00
private :
bool WriteRegistryKey ( HKEY hBaseKey , const wxString strKey , const wxString & strValue ) const ;
wxString ReadRegistryKey ( HKEY hBaseKey , const wxString strKey ) const ;
2007-08-20 15:50:49 +00:00
wxString GetFolderPath ( unsigned int uPathID ) const ;
2007-08-09 10:33:02 +00:00
2007-07-23 15:01:38 +00:00
protected :
DECLARE_EVENT_TABLE ( )
2007-11-21 15:42:21 +00:00
//metodi principali dell'applicazione
2007-07-23 15:01:38 +00:00
void OnTimer ( wxTimerEvent & e ) ;
2007-11-21 10:37:43 +00:00
void DiskUpdate ( ) ;
void InternetUpdate ( ) ;
2007-09-20 14:29:11 +00:00
void ClientUpdate ( ) ;
void NormalSetup ( ) ;
2007-09-26 12:59:37 +00:00
bool CampoRunning ( const wxString & strAppName , const wxString & strMsg ) const ;
2007-09-20 14:29:11 +00:00
2007-11-21 15:42:21 +00:00
//metodi di interfaccia con Windows
2007-09-19 14:47:17 +00:00
bool CreateIcon ( unsigned int csidl , const wxFileName & strExeFile , const wxString & strLinkName ) const ;
2007-08-08 15:24:46 +00:00
bool CreateAutostartMode ( const int iSrvAutostartMode , const wxString & strPath ) ;
2007-08-09 10:33:02 +00:00
void AssociateExtension ( const wxFileName & strExeFile , const wxString strExt ) ;
2007-11-21 15:42:21 +00:00
//metodi di interfaccia con il registry di Windows
2007-08-09 10:33:02 +00:00
wxString ReadRootRegistryKey ( const wxString strKey ) const ;
wxString ReadLocalMachineRegistryKey ( const wxString strKey ) const ;
bool WriteRootRegistryKey ( const wxString strKey , const wxString & strValue ) const ;
bool WriteLocalMachineRegistryKey ( const wxString strKey , const wxString & strValue ) const ;
2007-07-23 15:01:38 +00:00
2007-11-21 15:42:21 +00:00
//metodi di utility per i vari modi di aggiornamento
2007-09-17 14:20:41 +00:00
const wxString GetSourceDir ( const wxString strDirName ) const ;
2007-11-21 10:37:43 +00:00
void EmptyOutDir ( const wxString & strDir ) const ;
bool UnzipModule ( const wxString & strPrgLocPath , const wxString & strSrc , const wxString & strModule ) const ;
2007-11-21 15:42:21 +00:00
bool CopyFilesAndDirs ( const wxString & FilesListI , wxString strFileCurr , const bool bIni ) const ;
void UpdateInstallIni ( const wxString strSourcePath , const wxString strDestPath , const wxString & strModule ) const ;
2007-11-21 10:37:43 +00:00
bool HTTPGet ( const wxString & strLocalPath , const wxString & strWebPath ) const ;
2007-11-21 15:42:21 +00:00
//metodi di aggiornamento non standard (client, da disco e via web con installazione moduli)
int ClientUpdateModule ( const wxString & strLocalPath , const wxString & strRemotePath , const wxString strModule ) const ;
bool DiskUpdateModule ( const wxString & strLocalPath , const wxString & strWebPath , const wxString strModule ) const ;
2007-11-21 10:37:43 +00:00
bool InternetUpdateModule ( const wxString & strLocalPath , const wxString & strWebPath , const wxString strModule ) const ;
2007-07-23 15:01:38 +00:00
public :
virtual bool OnInit ( ) ;
} ;
2007-08-08 09:24:19 +00:00
IMPLEMENT_APP ( CampoSetup )
2007-07-23 15:01:38 +00:00
2007-08-08 09:24:19 +00:00
BEGIN_EVENT_TABLE ( CampoSetup , wxApp )
2007-07-23 15:01:38 +00:00
EVT_TIMER ( 883 , OnTimer )
END_EVENT_TABLE ( )
2007-11-21 15:42:21 +00:00
//----------------------------------------------------------------
// Metodi di lettura/scrittura registry di Windows (fantastici!)
//----------------------------------------------------------------
2007-08-09 10:33:02 +00:00
wxString CampoSetup : : ReadRegistryKey ( HKEY hBaseKey , const wxString strKey ) const
{
wxString strValue ;
HKEY hKey = NULL ;
wxString strPath , strName ;
wxFileName : : SplitPath ( strKey , & strPath , & strName , NULL ) ;
bool ok = : : RegOpenKeyEx ( hBaseKey , strPath , 0 , KEY_READ , & hKey ) = = ERROR_SUCCESS ;
if ( ok )
{
BYTE buff [ 512 ] ;
DWORD type = REG_SZ ;
DWORD dw = sizeof ( buff ) ;
ok = : : RegQueryValueEx ( hKey , strName , NULL , & type , buff , & dw ) = = ERROR_SUCCESS ;
if ( ok )
strValue = buff ;
: : RegCloseKey ( hKey ) ;
}
return strValue ;
}
wxString CampoSetup : : ReadRootRegistryKey ( const wxString strKey ) const
{
return ReadRegistryKey ( HKEY_CLASSES_ROOT , strKey ) ;
}
wxString CampoSetup : : ReadLocalMachineRegistryKey ( const wxString strKey ) const
{
return ReadRegistryKey ( HKEY_LOCAL_MACHINE , strKey ) ;
}
bool CampoSetup : : WriteRegistryKey ( HKEY hBaseKey , const wxString strKey , const wxString & strValue ) const
{
HKEY hKey = NULL ;
DWORD dw = 0 ;
2007-08-20 15:50:49 +00:00
//splitta la stringa in path e valore
wxString strPath , strName ;
wxFileName : : SplitPath ( strKey , & strPath , & strName , NULL ) ;
bool ok = : : RegCreateKeyEx ( hBaseKey , strPath , 0 , REG_NONE ,
2007-08-09 10:33:02 +00:00
REG_OPTION_NON_VOLATILE , KEY_WRITE | KEY_READ , NULL , & hKey , & dw ) = = ERROR_SUCCESS ;
if ( ok )
{
2007-08-20 15:50:49 +00:00
ok = : : RegSetValueEx ( hKey , strName , 0 , REG_SZ ,
( BYTE * ) ( const wxChar * ) strValue , DWORD ( 2 * strValue . Len ( ) + 2 ) ) = = ERROR_SUCCESS ;
2007-08-09 10:33:02 +00:00
: : RegCloseKey ( hKey ) ;
}
return ok ;
}
bool CampoSetup : : WriteRootRegistryKey ( const wxString strKey , const wxString & strValue ) const
{
return WriteRegistryKey ( HKEY_CLASSES_ROOT , strKey , strValue ) ;
}
bool CampoSetup : : WriteLocalMachineRegistryKey ( const wxString strKey , const wxString & strValue ) const
{
return WriteRegistryKey ( HKEY_LOCAL_MACHINE , strKey , strValue ) ;
}
2007-11-21 15:42:21 +00:00
//----------------------------------
// Metodi di interfaccia con Windows
//----------------------------------
2007-08-20 15:50:49 +00:00
wxString CampoSetup : : GetFolderPath ( unsigned int uPathID ) const
{
TCHAR szPath [ MAX_PATH ] = wxT ( " " ) ;
HRESULT hres = : : SHGetFolderPath ( NULL , uPathID , NULL , SHGFP_TYPE_CURRENT , szPath ) ;
return szPath ;
}
2007-08-09 10:33:02 +00:00
void CampoSetup : : AssociateExtension ( const wxFileName & strExeFile , const wxString strExt )
{
// Register icon and application
WriteRootRegistryKey ( strExt , APPNAME ) ;
wxString str = strExeFile . GetFullPath ( ) ; str + = wxT ( " ,0 " ) ;
WriteRootRegistryKey ( wxT ( " Campo \\ DefaultIcon " ) , str ) ;
str = strExeFile . GetFullPath ( ) ; str + = wxT ( " \" %1 \" " ) ;
WriteRootRegistryKey ( wxT ( " Campo \\ shell \\ open \\ command " ) , str ) ;
}
2007-08-08 15:24:46 +00:00
bool CampoSetup : : CreateAutostartMode ( const int iSrvAutostartMode , const wxString & strPath )
{
2007-08-23 13:18:25 +00:00
//creazione dei filenames e dei path necessari in giro per la funzione
//filename (con path quindi) di Lurch.exe
2007-08-20 15:50:49 +00:00
wxFileName strExe ( strPath , wxT ( " lurch.exe " ) ) ;
strExe . AppendDir ( " servers " ) ;
2007-08-23 13:18:25 +00:00
//stringa path della cartella Servers in base alle scelte dell'utente
const wxString strSrvPath = strPath + " \\ servers " ;
2007-08-08 15:24:46 +00:00
switch ( iSrvAutostartMode )
{
2007-08-09 10:33:02 +00:00
//esecuzione server come servizi (magia!)
case 0 :
{
2007-08-20 15:50:49 +00:00
//cerca se non esiste per caso gia' da una precedente installazione..
//..non serve piu' a un cazzo ma si e' tenuto come prova in debug di lettura del registry!
wxString strValue = ReadLocalMachineRegistryKey ( " SYSTEM \\ CurrentControlSet \\ Services \\ Lurch \\ Parameters \\ Application " ) ;
//elimina un eventuale servizio precedente (senno' col cavolo che lo riesce a modificare!)
2007-08-23 13:18:25 +00:00
//utilizza il programma instsrv.exe dentro la cartella servers installata
2007-08-24 13:18:47 +00:00
wxString strRemove = strSrvPath + " \\ instsrv Lurch REMOVE " ;
const long lRemove = wxExecute ( strRemove , wxEXEC_SYNC ) ;
2007-08-20 15:50:49 +00:00
//aggiunge la voce ai servizi di windows (dentro strumenti di amministrazione)
2007-08-23 13:18:25 +00:00
//utilizza i programmi instrv.exe e srvany.exe dentro la cartella servers installata
wxString strCreateService = strSrvPath + " \\ instsrv Lurch " ;
strCreateService + = strSrvPath ;
2007-08-20 15:50:49 +00:00
strCreateService + = " \\ srvany.exe " ;
//esegue il programma di installazione servizi di Windows creando la voce
const long lExec = wxExecute ( strCreateService , wxEXEC_SYNC ) ;
if ( lExec > = 0 )
2007-08-09 10:33:02 +00:00
{
2007-08-20 15:50:49 +00:00
//crea le voci nel registry di windows
WriteLocalMachineRegistryKey ( " SYSTEM \\ CurrentControlSet \\ Services \\ Lurch \\ Parameters \\ Application " , strExe . GetFullPath ( ) ) ;
wxString strExecService = GetFolderPath ( CSIDL_SYSTEM ) ;
strExecService + = " \\ NET START Lurch " ;
//avvia il servizio
const long lExecLurch = wxExecute ( strExecService , wxEXEC_SYNC ) ;
if ( lExecLurch < 0 )
WarningBox ( " Impossibile eseguire il servizio del gestore applicazioni. \n Lanciarlo manualmente dagli strumenti di amministrazione nel pannello di controllo! " ) ;
2007-08-09 10:33:02 +00:00
}
2007-08-20 15:50:49 +00:00
else
WarningBox ( " Impossibile registrare il servizio per l'esecuzione automatica del gestore applicazioni. \n Selezionare una diversa modalita' di esecuzione! " ) ;
2007-08-09 10:33:02 +00:00
}
break ;
2007-08-08 15:24:46 +00:00
//link nella cartella esecuzione automatica
case 1 :
{
2007-09-19 14:47:17 +00:00
CreateIcon ( CSIDL_COMMON_STARTUP , strExe , " lurch " ) ;
2007-08-08 15:24:46 +00:00
}
break ;
default :
break ;
}
return true ;
}
2007-09-19 14:47:17 +00:00
bool CampoSetup : : CreateIcon ( unsigned int csidl , const wxFileName & strExeFile , const wxString & strLinkName ) const
2007-08-08 15:24:46 +00:00
{
//csidl = CSIDL_COMMON_DESKTOPDIRECTORY = desktop
//csidl = CSIDL_COMMON_STARTUP = all users esecuzione automatica
2007-08-21 08:59:43 +00:00
wxString strDesktopPath = GetFolderPath ( csidl ) ;
2007-08-08 15:24:46 +00:00
2007-08-21 08:59:43 +00:00
if ( ! strDesktopPath . IsEmpty ( ) )
2007-08-08 15:24:46 +00:00
{
CoInitialize ( NULL ) ;
// Get a pointer to the IShellLink interface.
IShellLink * psl ;
2007-08-20 15:50:49 +00:00
HRESULT hres = CoCreateInstance ( CLSID_ShellLink , NULL , CLSCTX_INPROC_SERVER , IID_IShellLink , ( void * * ) & psl ) ;
2007-08-08 15:24:46 +00:00
if ( SUCCEEDED ( hres ) )
{
IPersistFile * ppf ;
// Set the path to the shortcut target and add the description.
psl - > SetPath ( strExeFile . GetFullPath ( ) ) ;
psl - > SetWorkingDirectory ( strExeFile . GetPath ( ) ) ;
psl - > SetDescription ( APPNAME ) ;
// Query IShellLink for the IPersistFile interface for saving the
// shortcut in persistent storage.
hres = psl - > QueryInterface ( IID_IPersistFile , ( void * * ) & ppf ) ;
if ( SUCCEEDED ( hres ) )
{
2007-09-19 14:47:17 +00:00
wxFileName fnLnk ;
wxString strName = strLinkName + " .lnk " ;
fnLnk . Assign ( strDesktopPath , strName ) ;
2007-08-21 08:59:43 +00:00
2007-08-08 15:24:46 +00:00
// Save the link by calling IPersistFile::Save.
2007-09-19 14:47:17 +00:00
wxString strPath = fnLnk . GetFullPath ( ) ;
2007-08-08 15:24:46 +00:00
wchar_t buff [ _MAX_PATH ] ;
memset ( buff , 0 , sizeof ( buff ) ) ;
2007-09-19 14:47:17 +00:00
wxConvLocal . MB2WC ( buff , strPath , strPath . Len ( ) ) ;
2007-08-08 15:24:46 +00:00
hres = ppf - > Save ( buff , true ) ;
ppf - > Release ( ) ;
}
psl - > Release ( ) ;
}
CoUninitialize ( ) ;
}
return true ;
}
2007-09-05 15:21:08 +00:00
2007-11-21 15:42:21 +00:00
//----------------------------------------------------------------
// Metodi di utility per i vari tipi di aggiornamento
//----------------------------------------------------------------
2007-09-05 15:21:08 +00:00
static int PatchCompare ( const wxString & first , const wxString & second )
{
const wxFileName fn1 ( first ) ;
const wxFileName fn2 ( second ) ;
const wxString strName1 = fn1 . GetName ( ) . Lower ( ) ;
const wxString strName2 = fn2 . GetName ( ) . Lower ( ) ;
if ( strName1 = = " syinst1 " )
return - 1 ;
if ( strName2 = = " syinst1 " )
return 1 ;
return strName1 . CompareTo ( strName2 ) ;
}
2007-09-17 14:20:41 +00:00
const wxString CampoSetup : : GetSourceDir ( const wxString strDirName ) const
2007-09-05 15:21:08 +00:00
{
2007-09-17 14:20:41 +00:00
wxFileName strSourcePath ( m_strSetupPath , " pippo.txt " ) ;
strSourcePath . AppendDir ( " .. " ) ;
2007-09-05 15:21:08 +00:00
strSourcePath . AppendDir ( " .. " ) ;
2007-09-17 14:20:41 +00:00
strSourcePath . AppendDir ( strDirName ) ;
2007-09-05 15:21:08 +00:00
strSourcePath . MakeAbsolute ( ) ;
2007-09-17 14:20:41 +00:00
const wxString strSrc = strSourcePath . GetPath ( ) ;
return strSrc ;
}
2007-10-25 15:48:37 +00:00
//metodo per aggiornare il modulo SY in install.ini
2007-11-21 15:42:21 +00:00
void CampoSetup : : UpdateInstallIni ( const wxString strSourcePath , const wxString strDestPath , const wxString & strModule ) const
2007-10-25 15:48:37 +00:00
{
for ( int j = 0 ; j < 2 ; j + + )
{
2007-11-21 15:42:21 +00:00
wxString strParagraph = strModule ;
2007-10-25 15:48:37 +00:00
if ( j > 0 )
strParagraph < < j ;
CampoIniFile InstallIniSource ( strSourcePath , strParagraph ) ;
CampoIniFile InstallIniDest ( strDestPath , strParagraph ) ;
wxString strWrk ;
long nIndex ;
for ( bool ok = InstallIniSource . GetFirstEntry ( strWrk , nIndex ) ; ok ; ok = InstallIniSource . GetNextEntry ( strWrk , nIndex ) )
{
InstallIniDest . Set ( strWrk , InstallIniSource . Get ( strWrk ) ) ;
}
}
}
2007-11-21 10:37:43 +00:00
bool CampoSetup : : UnzipModule ( const wxString & strPrgLocPath , const wxString & strSrc , const wxString & strModule ) const
2007-09-17 14:20:41 +00:00
{
2007-11-21 10:37:43 +00:00
bool ok = false ;
2007-09-17 14:20:41 +00:00
wxArrayString asFilesList ;
2007-09-05 15:21:08 +00:00
//..contando anche quanti sono e memorizzandoli in un array asFileList
2007-11-21 10:37:43 +00:00
const size_t uFilesToCopy = wxDir : : GetAllFiles ( strSrc , & asFilesList , strModule + " *.zip " ) ;
2007-09-05 15:55:53 +00:00
if ( uFilesToCopy > 0 )
{
//ordina le patch per numero crescente ma mette davanti a tutte il pacco (sysinst1)
asFilesList . Sort ( PatchCompare ) ;
for ( size_t i = 0 ; i < uFilesToCopy ; i + + )
{
UnzipFile ( asFilesList [ i ] , strPrgLocPath ) ;
}
//aggiorna l'install.ini in base al numero di patch e versione dell'ultimo file zip di sistema
//ci vuole un giro allucinogeno per trasformare il .zip in .ini e togliere quel cazzo di 1 in fondo
2007-09-06 09:49:40 +00:00
wxFileName strLastFile ( asFilesList [ uFilesToCopy - 1 ] ) ; //zip con path completo
2007-09-05 15:55:53 +00:00
wxString strWrk = strLastFile . GetName ( ) ;
strWrk . Truncate ( strWrk . Len ( ) - 1 ) ;
strLastFile . SetName ( strWrk ) ;
strLastFile . SetExt ( " ini " ) ;
2007-09-06 09:49:40 +00:00
strWrk = strLastFile . GetFullPath ( ) ;
//adesso che ha trovato quello sporco ultimo .ini prende versione e patch e le copia nell'install.ini..
//..nella dir dei programmi; lo fa paragrafo x paragrafo ([sy],[sy1]..)
//potrebbe sembrare assurdo un for, ma e' per futuri sottomoduli con numero > 1
2007-11-21 15:42:21 +00:00
UpdateInstallIni ( strWrk , strPrgLocPath + " /install.ini " , " sy " ) ;
2007-08-22 14:55:00 +00:00
}
2007-11-21 10:37:43 +00:00
return uFilesToCopy > 0 ;
2007-08-22 14:55:00 +00:00
}
2007-09-19 14:47:17 +00:00
bool CampoSetup : : CopyFilesAndDirs ( const wxString & FilesListI , wxString strFileCurr , const bool bIni ) const
{
bool ok = true ;
strFileCurr . MakeLower ( ) ; //minuscolizzazione di sicurezza
const wxFileName strFileName ( strFileCurr ) ;
//i files .ini vanno trattati con i guanti (se esistono gia' non vanno copiati!!!)
//parte da eseguire solo in caso sia indicata la trattazione degli ini (bIni true)
if ( bIni )
{
if ( strFileName . GetExt ( ) = = " ini " )
{
const wxString strName = strFileName . GetName ( ) ;
//campo.ini e install.ini vanno lasciati stare se esistono (aggiornamento)!!!
if ( ( strName = = " campo " | | strName = = " install " ) & & strFileName . FileExists ( ) )
ok = false ;
}
}
if ( ok )
{
//eventuali sottodirectory le crea (solo se hanno un nome)
const wxString strDir = strFileName . GetPath ( ) ;
if ( ! strDir . IsEmpty ( ) & & ! wxDirExists ( strDir ) )
wxMkdir ( strDir ) ;
if ( ! wxCopyFile ( FilesListI , strFileCurr ) )
{
wxString strErr = " Impossibile copiare il file " ;
strErr + = FilesListI ;
strErr + = " in " ;
strErr + = strFileCurr ;
strErr + = " \n Installazione interrotta! " ;
ErrorBox ( strErr ) ;
ok = false ;
}
}
return ok ;
}
2007-11-21 15:42:21 +00:00
//metodo per accoppare tutti i files di una directory
void CampoSetup : : EmptyOutDir ( const wxString & strDir ) const
{
wxArrayString asFilesList ;
const size_t uFilesToKill = wxDir : : GetAllFiles ( strDir , & asFilesList , " *.* " ) ;
2007-11-22 15:31:53 +00:00
for ( size_t i = 0 ; i < uFilesToKill ; i + + )
: : wxRemoveFile ( asFilesList [ i ] ) ;
2007-11-21 15:42:21 +00:00
}
2007-09-20 14:29:11 +00:00
2007-11-21 15:42:21 +00:00
//-----------------------------------------------------
// METODI BASSO LIVELLO PER AGGIORNAMENTI NON STANDARD
//-----------------------------------------------------
//----------------------------
// 1) AGGIORNAMENTO CLIENT
//----------------------------
//Aggiornatore client. Copia i files del programma da una directory remota su un server campo nella directory...
//...locale di campo
int CampoSetup : : ClientUpdateModule ( const wxString & strLocalPath , const wxString & strRemotePath , const wxString strModule ) const
2007-07-23 15:01:38 +00:00
{
2007-09-20 14:29:11 +00:00
int nLocVer , nLocPatch , nRemVer , nRemPatch ;
{
CampoIniFile iniLocalInstall ( strLocalPath + " /install.ini " , strModule ) ;
nLocVer = iniLocalInstall . GetInt ( " Versione " ) ;
nLocPatch = iniLocalInstall . GetInt ( " Patch " ) ;
CampoIniFile iniRemoteInstall ( strRemotePath + " /install.ini " , strModule ) ;
nRemVer = iniRemoteInstall . GetInt ( " Versione " ) ;
nRemPatch = iniRemoteInstall . GetInt ( " Patch " ) ;
}
int cmp = nLocVer - nRemVer ;
if ( cmp = = 0 )
cmp = nLocPatch - nRemPatch ;
//il client e' piu' indietro e quindi va aggiornato!
if ( cmp < 0 )
{
bool bOk = true ;
2007-12-06 11:40:20 +00:00
CampoProgressDialog pi ( " Aggiornamento elenco files dal server... " , 100 , m_pWizard ) ;
2007-09-20 14:29:11 +00:00
wxArrayString asGroups ;
{
wxString strGroup ;
long nIndex ;
CampoIniFile iniRemoteInstall ( strRemotePath + " /install.ini " , " " ) ;
for ( bool ok = iniRemoteInstall . GetFirstGroup ( strGroup , nIndex ) ; ok ; ok = iniRemoteInstall . GetNextGroup ( strGroup , nIndex ) )
{
if ( strGroup . Len ( ) > 2 & & strGroup . StartsWith ( strModule ) )
asGroups . Add ( strGroup ) ;
}
}
//controlla tutti i sottomoduli del modulo [sy1],[sy2]...
for ( size_t i = 0 ; i < asGroups . GetCount ( ) & & bOk ; i + + )
{
const wxString & strParagraph = asGroups [ i ] ;
CampoIniFile iniRemoteInstallModule ( strRemotePath + " /install.ini " , strParagraph ) ;
2007-10-25 15:48:37 +00:00
//install.ini locale che deve essere aggiornato durante la copia dei files!
CampoIniFile iniLocalInstall ( strLocalPath + " /install.ini " , strParagraph ) ;
2007-09-20 14:29:11 +00:00
//ogni file dell'elenco del sottomodulo corrente va copiato
for ( int j = 0 ; ; j + + )
{
pi . Pulse ( ) ; //magica barra modello supercar!
2007-10-25 15:48:37 +00:00
const wxString strVarName = wxString : : Format ( " File(%d) " , j ) ;
wxString strCurrFile = iniRemoteInstallModule . Get ( strVarName ) ;
2007-09-20 14:29:11 +00:00
if ( strCurrFile . IsEmpty ( ) )
break ;
2007-10-22 09:28:09 +00:00
strCurrFile = strCurrFile . BeforeFirst ( ' | ' ) ;
2007-09-20 14:29:11 +00:00
const wxString strSrcPath = strRemotePath + " / " + strCurrFile ;
const wxString strDstPath = strLocalPath + " / " + strCurrFile ;
//copia il file remoto di origine sul file locale di destinazione (overwrite=true di default)
if ( ! wxCopyFile ( strSrcPath , strDstPath ) )
{
wxString strError = " Impossibile copiare il file " ;
strError + = strSrcPath ;
strError + = " in " ;
strError + = strDstPath ;
strError + = " \n Assicurarsi che il client locale di " ;
strError + = APPNAME ;
strError + = " non sia in funzione. \n " ;
strError + = " Assicurarsi che il server di " ;
strError + = APPNAME ;
strError + = " sia in funzione e raggiungibile in rete. \n " ;
strError + = " Aggiornamento interrotto! " ;
ErrorBox ( strError ) ;
bOk = false ;
break ;
}
//se ci sono zip deve scompattarli (per ora esiste solo res.zip)
if ( strCurrFile . EndsWith ( " res.zip " ) )
{
UnzipFile ( strDstPath , strLocalPath + " /res " ) ;
}
2007-10-25 15:48:37 +00:00
//se riesce la copia del file aggiorna l'install.ini sul file (se non lo facesse non comparirebbero...
//...eventuali nuovi files
iniLocalInstall . Set ( strVarName , strCurrFile ) ;
2007-09-20 14:29:11 +00:00
} //for(int j...
//una volta termiata la copia dei files del sottmodulo[i] scatta l'aggiornamento dell'install.ini locale...
//...al livello versione/patch appena copiate sempre del sottomodulo[i]
iniLocalInstall . Set ( " Versione " , nRemVer ) ;
iniLocalInstall . Set ( " Patch " , nRemPatch ) ;
} //for(int i...
//una volta termiata la copia dei files dell'intero modulo scatta l'aggiornamento dell'install.ini locale al..
//..livello versione/patch appena copiate
CampoIniFile iniLocalInstall ( strLocalPath + " /install.ini " , strModule ) ;
iniLocalInstall . Set ( " Versione " , nRemVer ) ;
iniLocalInstall . Set ( " Patch " , nRemPatch ) ;
} //if(cmp<0...
return cmp ;
}
2007-11-21 15:42:21 +00:00
//----------------------------
// 2) AGGIORNAMENTO DA DISCO
//----------------------------
//Aggiornatore da disco. Copia i files delle patch da una directory su disco in una directory di appoggio...
//...temporanea dove esegue lo scompattamento con destinazione la directory locale
bool CampoSetup : : DiskUpdateModule ( const wxString & strLocalPath , const wxString & strDiskPath , const wxString strModule ) const
{
//puo' chiamare direttamente il metodo che scompatta tutte le patch del modulo a partire dal pacco iniziale...
//...fino all'ultima;il metodo le ordina gia' in modo crescente di numero d'ordine
return UnzipModule ( strLocalPath , strDiskPath , strModule ) ;
}
//-------------------------------
// 3) AGGIORNAMENTO DA INTERNET
//-------------------------------
2007-11-21 10:37:43 +00:00
bool CampoSetup : : HTTPGet ( const wxString & strLocalPath , const wxString & strWebPath ) const
{
wxString strServer , strPath ;
int nSlash = strWebPath . First ( ' / ' ) ;
strServer = strWebPath . Left ( nSlash ) ;
strPath = strWebPath . Mid ( nSlash ) ;
wxHTTP http ;
//connessione al server web con le patch
if ( http . Connect ( strServer ) )
{
wxInputStream * pStream = http . GetInputStream ( strPath ) ;
if ( pStream ! = NULL )
{
//compila un file di testo temporaneo con l'elenco dei files che trova sul server
wxFileOutputStream fos ( strLocalPath ) ;
fos . Write ( * pStream ) ;
delete pStream ;
return true ;
}
}
return false ;
}
2007-11-21 15:42:21 +00:00
//Aggiornatore via web. Copia i files delle patch da una directory web remota in una directory di appoggio...
//...temporanea dove esegue lo scompattamento con destinazione la directory locale
2007-11-21 10:37:43 +00:00
bool CampoSetup : : InternetUpdateModule ( const wxString & strLocalPath , const wxString & strWebPath , const wxString strModule ) const
{
bool ok = false ;
int nLocVer , nLocPatch ;
{
CampoIniFile iniLocalInstall ( strLocalPath + " /install.ini " , strModule ) ;
nLocVer = iniLocalInstall . GetInt ( " Versione " ) ;
nLocPatch = iniLocalInstall . GetInt ( " Patch " ) ;
}
2007-11-21 15:42:21 +00:00
//Svuota,elimina e ricrea una directory temporanea di appoggio ove mettere i files delle patch da scompattare
//E' necessaria questa operazione per non trovarsi ancora files di vecchie patch parcheggiati nella dir!
2007-11-21 10:37:43 +00:00
const wxString strTempDir = wxFileName : : GetTempDir ( ) + " /setup/ " ;
2007-11-21 15:42:21 +00:00
EmptyOutDir ( strTempDir ) ; //deve svuotare la directory dai files per poterla eliminare!!!
if ( : : wxRmdir ( strTempDir ) ) //elimina la dir adesso vuota
: : wxMkDir ( strTempDir ) ; //la ricrea
2007-11-21 10:37:43 +00:00
const wxString strTempFile = strTempDir + " httpdir.txt " ;
if ( HTTPGet ( strTempFile , strWebPath ) )
{
//partendo dal file temporaneo ne compila un secondo con i soli nomi dei file validi da scaricare
//i criteri di selezione sono il nome del modulo ed il livello patch
wxTextFile tfFilesList ;
if ( tfFilesList . Open ( ( strTempFile ) ) )
{
2007-12-06 11:40:20 +00:00
CampoProgressDialog pi ( " Aggiornamento elenco files dal server... " , ( int ) tfFilesList . GetLineCount ( ) , m_pWizard ) ;
2007-11-21 10:37:43 +00:00
for ( wxString strWrk = tfFilesList . GetFirstLine ( ) ; ! tfFilesList . Eof ( ) ; strWrk = tfFilesList . GetNextLine ( ) )
{
int nPos = strWrk . Find ( " href " ) ;
if ( nPos > 0 )
{
wxString strHref = strWrk . Mid ( nPos + 5 , 16 ) ;
strHref = strHref . AfterFirst ( ' " ' ) ;
strHref = strHref . BeforeLast ( ' " ' ) ;
2007-11-22 15:31:53 +00:00
if ( strHref . StartsWith ( strModule ) & & ( ( atoi ( strHref . Mid ( 2 ) ) > nLocPatch ) | | ( nLocPatch = = 0 ) ) )
2007-11-21 10:37:43 +00:00
{
if ( ! pi . Update ( ( int ) tfFilesList . GetCurrentLine ( ) , strHref ) )
break ;
HTTPGet ( strTempDir + strHref , strWebPath + strHref ) ;
}
}
}
//chiude il file temporaneo
tfFilesList . Close ( ) ;
} //if(tfFilesList...
//scompatta le patch di sistema e aggiorna l'install.ini locale
ok = UnzipModule ( strLocalPath , strTempDir , strModule ) ;
} //if(HTTPGet(...
return ok ;
}
2007-11-21 15:42:21 +00:00
//-----------------------------------------------------
// METODI ALTO LIVELLO PER AGGIORNAMENTI NON STANDARD
//-----------------------------------------------------
//---------------------------------------------------------------
// 1) metodo per l'aggiornamento dei client di rete in automatico
//---------------------------------------------------------------
void CampoSetup : : ClientUpdate ( )
2007-11-21 10:37:43 +00:00
{
wxFileName fn ( m_strSetupPath , " install.ini " ) ;
fn . AppendDir ( " .. " ) ;
fn . MakeAbsolute ( ) ;
const wxString strLocalPath = fn . GetPath ( ) ;
wxString strRemotePath ;
{
CampoIniFile iniLocalInstall ( fn . GetFullPath ( ) , " Main " ) ;
2007-11-21 15:42:21 +00:00
strRemotePath = iniLocalInstall . Get ( " DiskPath " ) ;
2007-11-21 10:37:43 +00:00
}
2007-11-21 15:42:21 +00:00
ClientUpdateModule ( strLocalPath , strRemotePath , " sy " ) ;
2007-11-21 10:37:43 +00:00
wxSetWorkingDirectory ( strLocalPath ) ;
wxExecute ( " ba1 -6 /uADMIN " ) ;
}
2007-08-08 09:24:19 +00:00
2007-11-21 15:42:21 +00:00
//-----------------------------------------------------------------------------------------------
// 2) metodo per l'aggiornamento da disco attraverso il menu di Manutenzione/Installazione moduli
//-----------------------------------------------------------------------------------------------
void CampoSetup : : DiskUpdate ( )
2007-09-20 14:29:11 +00:00
{
wxFileName fn ( m_strSetupPath , " install.ini " ) ;
fn . AppendDir ( " .. " ) ;
fn . MakeAbsolute ( ) ;
const wxString strLocalPath = fn . GetPath ( ) ;
wxString strRemotePath ;
{
CampoIniFile iniLocalInstall ( fn . GetFullPath ( ) , " Main " ) ;
strRemotePath = iniLocalInstall . Get ( " DiskPath " ) ;
}
2007-11-21 15:42:21 +00:00
DiskUpdateModule ( strLocalPath , strRemotePath , " sy " ) ;
2007-09-20 14:29:11 +00:00
wxSetWorkingDirectory ( strLocalPath ) ;
wxExecute ( " ba1 -6 /uADMIN " ) ;
}
2007-11-21 10:37:43 +00:00
//----------------------------------------------------------------------------------------
2007-11-21 15:42:21 +00:00
// 3) metodo per l'aggiornamento via internet attraverso Manutenzione/Installazione moduli
2007-11-21 10:37:43 +00:00
//----------------------------------------------------------------------------------------
2007-11-21 15:42:21 +00:00
void CampoSetup : : InternetUpdate ( )
2007-11-21 10:37:43 +00:00
{
2007-11-21 15:42:21 +00:00
//install.ini locale dove setup.exe e' in esecuzione
wxFileName fn ( m_strSetupPath , " install.ini " ) ;
fn . AppendDir ( " .. " ) ;
fn . MakeAbsolute ( ) ;
const wxString strLocalPath = fn . GetPath ( ) ;
//quale e' il path web da cui aggiornarmi?
wxString strRemotePath ;
{
//Install.ini locale da cui leggere il path di dove sta il mio server web
CampoIniFile iniLocalInstall ( fn . GetFullPath ( ) , " Main " ) ;
strRemotePath = iniLocalInstall . Get ( " WebPath " ) ;
}
//aggiornamento del modulo SY via web
InternetUpdateModule ( strLocalPath , strRemotePath , " sy " ) ;
//lanciare ba1.exe -6 in uscita
wxSetWorkingDirectory ( strLocalPath ) ;
wxExecute ( " ba1 -6 /uADMIN " ) ;
2007-11-21 10:37:43 +00:00
}
2007-11-21 15:42:21 +00:00
//--------------------------------------------------------------------------
//metodo per tutte le installazioni e gli aggiornamenti automatici in locale
//--------------------------------------------------------------------------
2007-09-20 14:29:11 +00:00
void CampoSetup : : NormalSetup ( )
{
2007-12-03 14:22:50 +00:00
//creazione del CampoWizard, ovvero dell'insieme di finestre per gestire installazione/aggiornamento
2007-09-20 14:29:11 +00:00
m_pWizard = new CampoWizard ( m_pMainFrame ) ;
2007-09-14 11:07:04 +00:00
if ( m_pWizard - > Run ( ) )
2007-07-23 15:01:38 +00:00
{
2007-09-19 14:47:17 +00:00
//e' una DEMO o una versione normale?
const bool bInstallDemoVersion = m_pWizard - > GetInstDemoVersion ( ) ;
2007-07-23 15:01:38 +00:00
2007-09-19 14:47:17 +00:00
// 0) INSTALLAZIONE VERSIONE DEMO (SIETE PAZZI?)
//----------------------------------------------
if ( bInstallDemoVersion )
2007-08-22 09:16:29 +00:00
{
2007-09-19 14:47:17 +00:00
const wxString & strPrgLocPath = " c:/campodemo " ;
const wxString & strDataPath = strPrgLocPath + " /dati " ;
const wxString & strHelpPath = strPrgLocPath + " /htmlhelp " ;
//creazione delle directories necessarie alla installazione DEMO
2007-08-23 13:18:25 +00:00
CheckAndMakeDir ( strPrgLocPath , " programmi " ) ;
CheckAndMakeDir ( strDataPath , " dati " ) ;
2007-09-19 14:47:17 +00:00
CheckAndMakeDir ( strHelpPath , " help " ) ;
2007-08-22 09:16:29 +00:00
2007-09-19 14:47:17 +00:00
//copia della campodemo sull'hard disk in c:\campodemo
wxArrayString asDemoList ;
const wxString strSrc = GetSourceDir ( " campodemo " ) ;
const size_t uFilesToCopy = wxDir : : GetAllFiles ( strSrc , & asDemoList ) ;
wxString strFileCurr ;
const size_t nPathLenght = strSrc . Len ( ) ;
2007-12-06 11:40:20 +00:00
CampoProgressDialog pi ( " Installazione Versione Demo... " , ( int ) uFilesToCopy , m_pWizard ) ;
2007-09-19 14:47:17 +00:00
for ( size_t i = 0 ; i < uFilesToCopy ; i + + )
2007-08-22 14:55:00 +00:00
{
2007-09-19 14:47:17 +00:00
if ( ! pi . Update ( ( int ) i , asDemoList [ i ] ) )
break ;
asDemoList [ i ] . Lower ( ) ;
strFileCurr = strPrgLocPath ;
strFileCurr + = asDemoList [ i ] . Mid ( nPathLenght ) ;
if ( ! strFileCurr . IsEmpty ( ) )
2007-08-23 13:18:25 +00:00
{
2007-09-19 14:47:17 +00:00
if ( ! CopyFilesAndDirs ( asDemoList [ i ] , strFileCurr , false ) )
break ;
2007-08-23 13:18:25 +00:00
}
2007-08-22 14:55:00 +00:00
}
2007-09-19 14:47:17 +00:00
//icona sul desktop
const bool bDesktopShortcut = m_pWizard - > GetDesktopShortcut ( ) ;
if ( bDesktopShortcut )
2007-08-22 14:55:00 +00:00
{
2007-09-19 14:47:17 +00:00
const wxFileName strExe ( " c:/campodemo " , wxT ( " ba0.exe " ) ) ;
CreateIcon ( CSIDL_COMMON_DESKTOPDIRECTORY , strExe , " CampoDEMO " ) ;
2007-08-22 14:55:00 +00:00
}
2007-08-22 09:16:29 +00:00
2007-09-19 14:47:17 +00:00
//lanciare ba0.exe in uscita
wxSetWorkingDirectory ( strPrgLocPath ) ;
wxExecute ( " ba0 " ) ;
2007-08-22 09:16:29 +00:00
2007-09-19 14:47:17 +00:00
}
else //tutti i casi normali (std,server,client,aggiornamento)
2007-09-06 15:46:28 +00:00
{
2007-09-19 14:47:17 +00:00
// 1) RACCOLTA PARAMETRI GENERALI INSTALLAZIONE (tipo,path,cartelle,servers,...)
//------------------------------------------------------------------------------
//tipo di installazione/aggiornamento
2007-10-18 14:51:26 +00:00
const InstallationType uInstallationType = m_pWizard - > GetInstallationType ( ) ;
const bool bNewInstallation = uInstallationType ! = it_upgrade ;
2007-09-19 14:47:17 +00:00
//installazione servers? solo per server di campo
2007-10-18 14:51:26 +00:00
const bool bInstallLurch = uInstallationType = = it_server & & ( m_pWizard - > GetInstUseAuth ( ) | | m_pWizard - > GetInstUseDict ( ) ) ;
2007-09-19 14:47:17 +00:00
//uso servers? sarebbe solo per i client ma lo teniamo buono per tutti
2007-10-18 14:51:26 +00:00
const bool bUseLurch = uInstallationType ! = it_server & & ( ! m_pWizard - > GetSrvAuth ( ) . IsEmpty ( ) | | ! m_pWizard - > GetSrvDict ( ) . IsEmpty ( ) ) ;
2007-09-19 14:47:17 +00:00
//installazione datidemo? (oddio speriamo di no!; comunque vale solo per installazione standard)
2007-10-18 14:51:26 +00:00
const bool bInstallDemoData = uInstallationType = = it_standalone & & m_pWizard - > GetInstDemoData ( ) ;
2007-09-19 14:47:17 +00:00
//cartelle selezionate dall'utente
const wxString & strPrgLocPath = m_pWizard - > GetPrgLocPath ( ) ;
const wxString & strDataPath = m_pWizard - > GetDataPath ( ) ;
//se nuova installazione deve anche creare la directory di destinazione
if ( bNewInstallation )
{
//creazione della directory dei programmi (compreso l'intero albero directory)
CheckAndMakeDir ( strPrgLocPath , " programmi " ) ;
//creazione della directory dei dati (compreso l'intero albero directory)
CheckAndMakeDir ( strDataPath , " dati " ) ;
}
// 2) COPIA DEI FILES DI INSTALLAZIONE DALLA CARTELLA CAMPO (E SUBDIRS) (SU CD) ALLA CARTELLA DESTINAZIONE
//--------------------------------------------------------------------------------------------------------
//copia del contenuto della cartella campo nella cartella di destinazione (installaz/aggiornam)
//per prima cosa cerca la cartella dei files sorgente...
wxArrayString asFilesList ;
wxFileName strSourcePath ( m_strSetupPath , " *.* " ) ;
strSourcePath . AppendDir ( " .. " ) ;
strSourcePath . MakeAbsolute ( ) ;
//stringa inutile al programma ma decisiva per il programmatore
const wxString strSrc = strSourcePath . GetPath ( ) ;
//..contando anche quanti sono e memorizzandoli in un array asFileList
const size_t uFilesToCopy = wxDir : : GetAllFiles ( strSrc , & asFilesList ) ;
2007-09-17 14:20:41 +00:00
const size_t nPathLenght = strSrc . Len ( ) ;
2007-09-19 14:47:17 +00:00
//progress bar
2007-12-06 11:40:20 +00:00
CampoProgressDialog pi ( " Installazione Dati e Programmi di base... " , ( int ) uFilesToCopy , m_pWizard ) ;
2007-09-19 14:47:17 +00:00
2007-09-06 15:46:28 +00:00
for ( size_t i = 0 ; i < uFilesToCopy ; i + + )
2007-10-16 13:52:19 +00:00
{
//per ogni file da copiare controlla i path sorgente e destinazione(problema con sottodirectory tipo..
//..dati); strFileCurr va lasciato qui perche' DEVE ESSERE AZZERATO ad ogni cambio file!!!!!!
wxString strFileCurr ;
2007-10-25 15:48:37 +00:00
//controlla se il file corrente e' dentro una sottodirectory (tipo dati,servers,setup...) oppure e' al..
//..primo livello (quindi e' un file di programma)
wxString strSourceFile = asFilesList [ i ] . Lower ( ) ;
strSourceFile . Replace ( " \\ " , " / " ) ;
//e' in una subdir se la lunghezza del suo path prima dell'ultimo '/' e' > della lunghezza del path di root
const bool bIsSubDir = strSourceFile . Find ( ' / ' , true ) > ( int ) nPathLenght ;
//2A) files con subdirectory
if ( bIsSubDir )
2007-09-06 15:46:28 +00:00
{
2007-10-25 15:48:37 +00:00
//files dei dati standard! solo in caso di nuova installazione!!
2007-10-26 09:09:51 +00:00
if ( strSourceFile . Find ( " /dati/ " ) > 0 )
2007-09-06 15:46:28 +00:00
{
2007-10-25 15:48:37 +00:00
//i DATI NON VANNO MAI installati in caso di aggiornamento!!!
//e nemmeno in caso si scelga di installare i dati demo (senno' sporca la dir dati e i datidemo non si installano)
//Ricordare che c'e' gia' stato il controllo nella Forward della pagina di selezione, quindi la cartella..
//..di destinazione e' comunque vuota
if ( bNewInstallation & & ! bInstallDemoData )
{
strFileCurr = strDataPath ;
strFileCurr + = asFilesList [ i ] . Mid ( nPathLenght + 5 ) ;
}
} else
2007-10-26 09:09:51 +00:00
if ( strSourceFile . Find ( " /servers/ " ) > 0 ) //che fare con i servers? copiare la directory...
2007-09-19 14:47:17 +00:00
{
if ( bInstallLurch ) //..ma solo se devi installare i servers
{
strFileCurr = strPrgLocPath ;
2007-10-26 09:09:51 +00:00
strFileCurr + = " /servers " ;
2007-09-19 14:47:17 +00:00
strFileCurr + = asFilesList [ i ] . Mid ( nPathLenght + 8 ) ;
}
}
2007-10-25 15:48:37 +00:00
else //files vari di altre subdirectory che si installano sempre (es. setup)
2007-09-19 14:47:17 +00:00
{
strFileCurr = strPrgLocPath ;
strFileCurr + = asFilesList [ i ] . Mid ( nPathLenght ) ;
}
}
2007-10-25 15:48:37 +00:00
//2B) files senza subdirectory (programmi!)
else
{
strFileCurr = strPrgLocPath ;
strFileCurr + = asFilesList [ i ] . Mid ( nPathLenght ) ;
}
2007-09-19 14:47:17 +00:00
//copia i files nella cartella di destinazione (programmi,dati,cazzi e mazzi);se il nome del file..
//..di destinazione e' vuoto significa che non lo deve copiare!! (es. dati in aggiornamento)
if ( ! strFileCurr . IsEmpty ( ) )
{
2007-10-16 13:52:19 +00:00
//aggiorna la progind
if ( ! pi . Update ( ( int ) i , asFilesList [ i ] ) )
break ;
2007-09-19 14:47:17 +00:00
//eventuali sottodirectory le crea (solo se hanno un nome) e poi copia fisicamente i files
//se un file non si copia interrompe l'installazione con un ErrorBox
if ( ! CopyFilesAndDirs ( asFilesList [ i ] , strFileCurr , true ) )
break ;
2007-09-06 15:46:28 +00:00
} //if (!strFileCurr.IsEmpty()..
2007-09-19 14:47:17 +00:00
} //for(size_t...
2007-11-21 15:42:21 +00:00
UpdateInstallIni ( strSrc + " /install.ini " , strPrgLocPath + " /install.ini " , " sy " ) ;
2007-10-25 15:48:37 +00:00
2007-09-19 14:47:17 +00:00
// 3) INSTALLAZIONE DATI DEMO
//---------------------------
//installazione dei dati dimostrativi (che schifo!).Non si puo' fare in aggiornamento!
2007-09-28 10:22:37 +00:00
/* if (bInstallDemoData && uInstallationType < 3)
2007-09-19 14:47:17 +00:00
{
//trova la cartella datidemo da copiare
wxArrayString asDataList ;
const wxString strSrc = GetSourceDir ( " datidemo " ) ;
//conta i files da copiare e si lancia nell'operazione di copiatura...
//Vale quanto detto per l'installazione dell'area dati
const size_t uFilesToCopy = wxDir : : GetAllFiles ( strSrc , & asDataList ) ;
wxString strFileCurr ;
const size_t nPathLenght = strSrc . Len ( ) ;
2007-12-06 11:40:20 +00:00
CampoProgressDialog pi ( " Installazione Dati Demo... " , ( int ) uFilesToCopy , m_pWizard ) ;
2007-09-19 14:47:17 +00:00
for ( size_t i = 0 ; i < uFilesToCopy ; i + + )
2007-09-03 15:44:42 +00:00
{
2007-09-19 14:47:17 +00:00
if ( ! pi . Update ( ( int ) i , asDataList [ i ] ) )
break ;
asDataList [ i ] . Lower ( ) ;
strFileCurr = strDataPath ;
strFileCurr + = asDataList [ i ] . Mid ( nPathLenght ) ;
if ( ! strFileCurr . IsEmpty ( ) )
{
//eventuali sottodirectory le crea (solo se hanno un nome) e poi copia fisicamente i files
//se un file non si copia interrompe l'installazione con un ErrorBox
if ( ! CopyFilesAndDirs ( asDataList [ i ] , strFileCurr , false ) )
break ;
} //if (!strFileCurr.IsEmpty()..
} //for (size_t i = 0...
2007-09-28 10:22:37 +00:00
} //if(bInstallDemoData... */
2007-09-19 14:47:17 +00:00
// 4) COMPILAZIONE CAMPO.INI CON CONFIGURAZIONE NUOVA INSTALLAZIONE
//-----------------------------------------------------------------
//adesso deve compilare il campo.ini se nuova installazione..
if ( bNewInstallation )
{
{ //parentesi necessaria per la scrittura immediata (non cancellare! serve per debug)
//paragrafo [Main]
CampoIniFile CampoIniMain ( strPrgLocPath + " /campo.ini " , " Main " ) ;
const unsigned int uDongleType = m_pWizard - > GetDongleType ( ) ;
CampoIniMain . Set ( " Donglehw " , uDongleType ) ;
CampoIniMain . Set ( " Study " , strDataPath ) ;
CampoIniMain . Set ( " Firm " , " com " ) ;
//client o non client?
2007-10-18 14:51:26 +00:00
//(attenzione che in Campo e' Std=1 Srv=2 Cli=3)
CampoIniMain . Set ( " Type " , uInstallationType ) ;
2007-09-03 15:44:42 +00:00
}
2007-09-19 14:47:17 +00:00
//paragrafo [Server]
if ( bInstallLurch | | bUseLurch )
2007-09-03 15:44:42 +00:00
{
2007-09-19 14:47:17 +00:00
CampoIniFile CampoIniSrv ( strPrgLocPath + " /campo.ini " , " Server " ) ;
CampoIniSrv . Set ( " Dongle " , m_pWizard - > GetSrvAuth ( ) ) ;
CampoIniSrv . Set ( " Dictionary " , m_pWizard - > GetSrvDict ( ) ) ;
2007-09-03 15:44:42 +00:00
}
2007-09-19 14:47:17 +00:00
} //if(bNewInstallation...
2007-09-28 10:22:37 +00:00
else //e' un aggiornamento! scrive il type
{
CampoIniFile CampoIniMain ( strPrgLocPath + " /campo.ini " , " Main " ) ;
2007-10-16 13:52:19 +00:00
//SOLO se sta aggiornando una versione antecedente alla 10.0 scrive la variabile Type nel campo.ini..
//..ovvero deve testare se Type = 0
if ( CampoIniMain . GetInt ( " Type " ) = = 0 )
2007-10-18 14:51:26 +00:00
CampoIniMain . Set ( " Type " , CampoIniMain . GetInstallationType ( ) ) ;
2007-09-28 10:22:37 +00:00
}
2007-09-06 09:49:40 +00:00
2007-09-19 14:47:17 +00:00
// 5) COMPILAZIONE\AGGIORNAMENTO INSTALL.INI CON DISKPATH
//-------------------------------------------------------
//..e modificare comunque l'install.ini aggiornando eventualmente l'origine dei programmi
//parentesi necessaria per la scrittura immediata (non cancellare! serve per debug)
2007-09-03 15:44:42 +00:00
{
2007-09-19 14:47:17 +00:00
CampoIniFile CampoInstall ( strPrgLocPath + " /install.ini " , " Main " ) ;
2007-10-18 14:51:26 +00:00
if ( uInstallationType = = it_client ) //client: directory origine sul server
2007-09-19 14:47:17 +00:00
CampoInstall . Set ( " DiskPath " , m_pWizard - > GetPrgNetPath ( ) ) ;
else //e' il path assoluto dell'install.ini che sta in 'program' (es. D:\program)
{
const wxString strSrc = GetSourceDir ( " program " ) ;
CampoInstall . Set ( " DiskPath " , strSrc ) ;
}
2007-09-03 15:44:42 +00:00
}
2007-09-06 09:49:40 +00:00
2007-09-19 14:47:17 +00:00
// 6) CREAZIONE AUTOSTART DEI SERVERS (SE CI SONO)
//------------------------------------------------
//solo se sta installando campo in postazione server e deve installare un gestore di servizi..
//..avvia la procedura della creazione dell'autostart(un casino)
2007-10-18 14:51:26 +00:00
const int iSrvAutostartMode = m_pWizard - > GetSrvAutostartMode ( ) ;
if ( iSrvAutostartMode ! = lm_none )
2007-09-19 14:47:17 +00:00
{
CreateAutostartMode ( iSrvAutostartMode , strPrgLocPath ) ;
}
2007-08-24 13:18:47 +00:00
2007-09-19 14:47:17 +00:00
// 7) AGGIORNAMENTO DEL MODULO SY CON EVENTUALI PATCH PRESENTI IN PROGRAM DEL CD E AGGIORNAMENTO INSTALL.INI
//----------------------------------------------------------------------------------------------------------
//procede poi al caricamento delle patch eventuali di sistema all'interno della dir 'program' e al..
//..conseguente riaggiornamento del livello versione/patch del SY in install.ini
2007-11-21 10:37:43 +00:00
const wxString strPrgCDPath = GetSourceDir ( " program " ) ;
2007-12-06 11:40:20 +00:00
if ( wxFileName : : DirExists ( strPrgCDPath ) )
UnzipModule ( strPrgLocPath , strPrgCDPath , " sy " ) ;
2007-09-05 15:21:08 +00:00
2007-08-24 13:18:47 +00:00
2007-09-19 14:47:17 +00:00
// 8) CREAZIONE DELL'ICONA SUL DESKTOP
//------------------------------------
const bool bDesktopShortcut = m_pWizard - > GetDesktopShortcut ( ) ;
if ( bDesktopShortcut )
{
const wxFileName strExe ( strPrgLocPath , wxT ( " ba0.exe " ) ) ;
2007-10-16 16:06:54 +00:00
wxString strLnk ;
2007-10-18 11:13:15 +00:00
CampoIniFile CampoIniMain ( strPrgLocPath + " /campo.ini " , " Main " ) ;
2007-10-18 14:51:26 +00:00
InstallationType nInstType = CampoIniMain . GetInstallationType ( ) ;
2007-10-18 11:13:15 +00:00
switch ( nInstType )
2007-10-16 16:06:54 +00:00
{
2007-10-18 14:51:26 +00:00
case it_server :
2007-10-18 11:13:15 +00:00
strLnk = " Campo (Server) " ;
break ;
2007-10-18 14:51:26 +00:00
case it_client :
2007-10-16 16:06:54 +00:00
strLnk = " Campo (Client) " ;
break ;
default :
strLnk = " Campo " ;
break ;
}
2007-10-18 11:13:15 +00:00
//crea comunque l'icona
2007-10-16 16:06:54 +00:00
CreateIcon ( CSIDL_COMMON_DESKTOPDIRECTORY , strExe , strLnk ) ;
2007-09-19 14:47:17 +00:00
}
2007-09-05 15:55:53 +00:00
2007-09-06 09:49:40 +00:00
2007-09-19 14:47:17 +00:00
// 9) AGGIORNAMENTO CAMPO.STP
//---------------------------
if ( bNewInstallation )
{
//deve aggiungere la nuova installazione al campo.stp
for ( int i = 1 ; ; i + + )
{
wxString strGroup ;
strGroup < < i ;
CampoIniFile CampoStp ( " C: \\ campo.stp " , strGroup ) ;
wxString strPath = CampoStp . Get ( " Program " ) ;
if ( strPath . IsEmpty ( ) )
{
CampoStp . Set ( " Program " , strPrgLocPath ) ;
break ;
}
2007-09-06 11:05:56 +00:00
}
}
2007-09-19 14:47:17 +00:00
2007-09-06 15:46:28 +00:00
2007-09-19 14:47:17 +00:00
// 10) CHIUDE IL SETUP LANCIANDO BA1 -6 PER INSTALLAZIONE MODULI
//-------------------------------------------------------------
//lanciare ba1.exe -6 in uscita
2007-10-18 11:13:15 +00:00
if ( wxSetWorkingDirectory ( strPrgLocPath ) )
wxExecute ( " ba1 -6 /uADMIN " ) ;
else
ErrorBox ( " Impossibile installare i moduli. Cartella di destinazione irraggiungibile! " ) ;
2007-09-19 14:47:17 +00:00
}
2007-09-06 11:05:56 +00:00
2007-09-14 11:07:04 +00:00
} //if (m_pWizard->Run())...
m_pWizard - > Destroy ( ) ;
2007-09-26 12:59:37 +00:00
}
bool CampoSetup : : CampoRunning ( const wxString & strAppName , const wxString & strMsg ) const
{
wxSingleInstanceChecker sicProgram ( strAppName ) ;
2007-10-09 13:22:42 +00:00
int i ;
for ( i = 3 ; i > 0 & & sicProgram . IsAnotherRunning ( ) ; i - - )
wxSleep ( 1 ) ;
if ( i < = 0 )
2007-09-26 12:59:37 +00:00
ErrorBox ( strMsg ) ;
2007-10-09 13:22:42 +00:00
return i < = 0 ;
2007-09-26 12:59:37 +00:00
}
2007-07-23 15:01:38 +00:00
2007-09-26 12:59:37 +00:00
//metodo principale che sceglie la modalita' di lancio del programma
void CampoSetup : : OnTimer ( wxTimerEvent & WXUNUSED ( e ) )
{
//controllo di eventuali Campo o servers attivi e conseguente interruzione dell'installazione
if ( CampoRunning ( " ba0 " , " Uscire dal programma CAMPO prima di procedere con l'aggiornamento/installazione! " ) | |
CampoRunning ( " ba1 " , " Uscire dal programma di manutenzione di CAMPO \n prima di procedere con l'aggiornamento/installazione! " ) | |
CampoRunning ( " Authorization " , " Spegnere il server di autorizzazioni per poter aggiornare/installare il programma CAMPO! " ) )
{
m_pMainFrame - > Destroy ( ) ;
return ;
}
//panegirico all'apparenza inutile ma in realta' decisivo per reperire i veri path assoluti dove funzionano...
//..setup, ba0, ba1. NON cancellare!!!
wxString strIni = " install.ini " ;
wxFileName strPath ;
if ( wxFileName : : FileExists ( strIni ) )
{
strPath = " setup " ;
}
else
{
strIni . insert ( 0 , " ../ " ) ;
if ( wxFileName : : FileExists ( strIni ) )
strPath = " . " ;
else
{
m_pMainFrame - > Destroy ( ) ;
return ;
}
}
strPath . MakeAbsolute ( ) ;
strPath . SetCwd ( ) ;
//path del programma setup.exe in esecuzione; serve in seguito in quanto alcuni metodi (tipo la GetAllFiles)..
//..fanno perdere questo path
m_strSetupPath = strPath . GetPath ( ) ;
wxString strCommand = argv [ 1 ] ;
if ( strCommand . IsEmpty ( ) )
NormalSetup ( ) ;
else
2007-11-21 10:37:43 +00:00
{
if ( strCommand = = " -ud " )
DiskUpdate ( ) ;
if ( strCommand = = " -uc " )
ClientUpdate ( ) ;
if ( strCommand = = " -uw " )
InternetUpdate ( ) ;
}
2007-09-26 12:59:37 +00:00
//finestrina x chiudere a mano il programma (sconsigliata causa lancio ba1.exe)
// ::wxMessageBox(wxT("Installazione terminata"), APPNAME, wxOK | wxICON_INFORMATION);
m_pMainFrame - > Destroy ( ) ;
2007-07-23 15:01:38 +00:00
}
2007-09-26 12:59:37 +00:00
2007-08-08 09:24:19 +00:00
bool CampoSetup : : OnInit ( )
2007-07-23 15:01:38 +00:00
{
wxInitAllImageHandlers ( ) ;
m_locale . Init ( ) ;
2007-08-08 09:24:19 +00:00
m_pMainFrame = new CampoFrame ;
2007-07-23 15:01:38 +00:00
SetTopWindow ( m_pMainFrame ) ;
wxTimerEvent e ( 883 ) ;
AddPendingEvent ( e ) ;
return true ;
}