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 ) ;
2009-01-19 10:27:20 +00:00
int nHeight = rect . GetHeight ( ) / 14 ;
wxFont * pFont = wxTheFontList - > FindOrCreateFont ( nHeight , wxFONTFAMILY_SWISS , wxFONTSTYLE_ITALIC , wxFONTWEIGHT_BOLD ) ;
2007-07-23 15:01:38 +00:00
dc . SetFont ( * pFont ) ;
dc . SetBackgroundMode ( wxTRANSPARENT ) ;
2009-01-19 10:27:20 +00:00
int w , h ;
dc . GetTextExtent ( RESELLER , & w , & h ) ;
while ( w > rect . width )
{
nHeight = nHeight * rect . width / w ;
pFont = wxTheFontList - > FindOrCreateFont ( nHeight , wxFONTFAMILY_SWISS , wxFONTSTYLE_ITALIC , wxFONTWEIGHT_BOLD ) ;
dc . SetFont ( * pFont ) ;
dc . GetTextExtent ( RESELLER , & w , & h ) ;
}
2007-07-23 15:01:38 +00:00
const int k = nHeight / 16 + 1 ;
dc . SetTextForeground ( c2 ) ;
2009-01-19 10:27:20 +00:00
dc . DrawText ( RESELLER , rect . GetRight ( ) - w - k / 2 , rect . GetHeight ( ) - h - k / 2 ) ;
2007-07-23 15:01:38 +00:00
dc . SetTextForeground ( c1 ) ;
2009-01-19 10:27:20 +00:00
dc . DrawText ( RESELLER , rect . GetRight ( ) - w - k , rect . GetHeight ( ) - h - k ) ;
2007-07-23 15:01:38 +00:00
dc . SetTextForeground ( c2 ) ;
2009-01-19 10:27:20 +00:00
dc . DrawText ( PRODUCT , k , k ) ;
2007-07-23 15:01:38 +00:00
dc . SetTextForeground ( c1 ) ;
2009-01-19 10:27:20 +00:00
dc . DrawText ( PRODUCT , k / 2 , k / 2 ) ;
2007-07-23 15:01:38 +00:00
}
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 ( ) ;
2009-01-20 11:16:02 +00:00
bool SystemRunning ( const wxString & strAppName , wxString strMsg ) const ;
2008-01-04 16:03:24 +00:00
bool LurchRunning ( ) const ;
2008-11-18 15:03:42 +00:00
bool CampoRunning ( ) 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-09 10:33:02 +00:00
void AssociateExtension ( const wxFileName & strExeFile , const wxString strExt ) ;
2008-01-04 16:03:24 +00:00
//...per i servers
bool CreateAutostartMode ( const LurchMode iSrvAutostartMode , const wxString & strPath ) ;
2008-01-07 11:29:42 +00:00
bool StopLurch ( ) const ;
bool StartLurch ( const wxString & strPrgLocPath ) const ;
2007-08-09 10:33:02 +00:00
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-12-17 16:36:30 +00:00
void CopyDir ( const wxString & strSourceDir , const wxString & strDestDir ) 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 ;
}
2008-01-04 16:03:24 +00:00
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 " ) ;
2009-01-20 11:16:02 +00:00
WriteRootRegistryKey ( APPNAME + wxT ( " \\ DefaultIcon " ) , str ) ;
2007-08-09 10:33:02 +00:00
str = strExeFile . GetFullPath ( ) ; str + = wxT ( " \" %1 \" " ) ;
2009-01-20 11:16:02 +00:00
WriteRootRegistryKey ( APPNAME + wxT ( " \\ shell \\ open \\ command " ) , str ) ;
2007-08-09 10:33:02 +00:00
}
2007-08-08 15:24:46 +00:00
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 ) )
2007-12-18 16:15:06 +00:00
{
2007-08-08 15:24:46 +00:00
// Set the path to the shortcut target and add the description.
psl - > SetPath ( strExeFile . GetFullPath ( ) ) ;
psl - > SetWorkingDirectory ( strExeFile . GetPath ( ) ) ;
2007-12-18 16:15:06 +00:00
psl - > SetDescription ( APPNAME ) ;
//sceglie l'icona da quelle possibili legate al .exe in base al tipo di installazione
const InstallationType uInstallationType = m_pWizard - > GetInstallationType ( ) ;
2009-01-19 10:27:20 +00:00
//anche l'icona deve essere scelta in base al reseller
wxString strIcon = Icon ( ) ;
//path completo del file icona, in modo da legarlo al link sul desktop;comincia con il path di Campo
wxString strPath = m_pWizard - > GetPrgLocPath ( ) ;
if ( ! strIcon . IsEmpty ( ) )
{
strPath + = " /setup/ " ; //se esiste l'icona del reseller sta in setup
}
else
2007-12-18 16:15:06 +00:00
{
2009-01-19 10:27:20 +00:00
strPath + = " /res/ " ; //se non trova l'icona del reseller prende quella standard in res
2007-12-18 16:15:06 +00:00
}
2007-08-08 15:24:46 +00:00
2009-01-19 10:27:20 +00:00
const int nPos = strIcon . Len ( ) - 4 ;
switch ( uInstallationType )
{
case it_server : strIcon . insert ( nPos , " Srv " ) ; break ;
case it_client : strIcon . insert ( nPos , " Cln " ) ; break ;
default : break ;
}
strPath < < strIcon ;
psl - > SetIconLocation ( strPath , 0 ) ;
2007-08-08 15:24:46 +00:00
// Query IShellLink for the IPersistFile interface for saving the
2007-12-18 16:15:06 +00:00
// shortcut in persistent storage.
IPersistFile * ppf ;
2007-08-08 15:24:46 +00:00
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
2008-01-04 16:03:24 +00:00
//-------------------------------------------
// ..per i servers di Campo
//-------------------------------------------
2008-01-07 11:29:42 +00:00
bool CampoSetup : : StopLurch ( ) const
2008-01-04 16:03:24 +00:00
{
2008-02-07 17:19:26 +00:00
bool ok = false ;
//cerca e ferma authoriz e lurch come processi
for ( int i = 0 ; i < 2 ; i + + )
{
wxHTTP scServer ;
if ( scServer . Connect ( " 127.0.0.1 " , i = = 0 ? 10000 : 1883 ) )
{
//if (scServer.BuildRequest("/stop.cgi", 0))
wxInputStream * isIs = scServer . GetInputStream ( " /stop.cgi " ) ;
if ( isIs )
{
delete isIs ;
wxSleep ( 3 ) ;
ok = true ;
break ;
}
}
}
//se lurch e' un servizio lo stoppa
2008-01-04 16:03:24 +00:00
const wxString strValue = ReadLocalMachineRegistryKey ( " SYSTEM \\ CurrentControlSet \\ Services \\ Lurch \\ Parameters \\ Application " ) ;
2008-01-07 11:29:42 +00:00
if ( ! strValue . IsEmpty ( ) )
{
wxString strExecService = GetFolderPath ( CSIDL_SYSTEM ) ;
strExecService + = " \\ NET STOP Lurch " ;
wxExecute ( strExecService , wxEXEC_SYNC ) ;
}
2008-02-07 17:19:26 +00:00
2008-01-07 11:29:42 +00:00
return ok ;
2008-01-04 16:03:24 +00:00
}
2008-01-07 11:29:42 +00:00
bool CampoSetup : : StartLurch ( const wxString & strPrgLocPath ) const
2008-01-04 16:03:24 +00:00
{
const wxString strValue = ReadLocalMachineRegistryKey ( " SYSTEM \\ CurrentControlSet \\ Services \\ Lurch \\ Parameters \\ Application " ) ;
2008-01-07 11:29:42 +00:00
if ( ! strValue . IsEmpty ( ) )
{
wxString strExecService = GetFolderPath ( CSIDL_SYSTEM ) ;
strExecService + = " \\ NET START Lurch " ;
wxExecute ( strExecService , wxEXEC_SYNC ) ;
}
else
{
wxString strPath = strPrgLocPath ;
strPath + = " /servers/lurch.exe " ;
wxExecute ( strPath , wxEXEC_ASYNC ) ;
}
return true ;
2008-01-04 16:03:24 +00:00
}
bool CampoSetup : : CreateAutostartMode ( const LurchMode iSrvAutostartMode , const wxString & strPath )
{
//creazione dei filenames e dei path necessari in giro per la funzione
//filename (con path quindi) di Lurch.exe
wxFileName strExe ( strPath , wxT ( " lurch.exe " ) ) ;
strExe . AppendDir ( " servers " ) ;
//stringa path della cartella Servers in base alle scelte dell'utente
const wxString strSrvPath = strExe . GetPath ( ) ;
//1) Cerca di eliminare Lurch se presente come servizio
const wxString strValue = ReadLocalMachineRegistryKey ( " SYSTEM \\ CurrentControlSet \\ Services \\ Lurch \\ Parameters \\ Application " ) ;
if ( ! strValue . IsEmpty ( ) )
{
//elimina un eventuale servizio precedente (senno' col cavolo che lo riesce a modificare!)
//utilizza il programma instsrv.exe dentro la cartella servers installata
wxString strRemove = strSrvPath + " \\ instsrv Lurch REMOVE " ;
const long lRemove = wxExecute ( strRemove , wxEXEC_SYNC ) ;
}
//2) Cerca di fermare Lurch se presente come programma in esecuzione automatica
2008-01-07 11:29:42 +00:00
else
{
if ( LurchRunning ( ) )
StopLurch ( ) ;
}
2008-01-04 16:03:24 +00:00
switch ( iSrvAutostartMode )
{
//esecuzione server come servizi (magia!)
case lm_service :
{
//aggiunge la voce ai servizi di windows (dentro strumenti di amministrazione)
//utilizza i programmi instrv.exe e srvany.exe dentro la cartella servers installata
wxString strCreateService = strSrvPath + " \\ instsrv Lurch " ;
strCreateService + = strSrvPath ;
strCreateService + = " \\ srvany.exe " ;
//esegue il programma di installazione servizi di Windows creando la voce
const long lExec = wxExecute ( strCreateService , wxEXEC_SYNC ) ;
if ( lExec > = 0 )
{
//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! " ) ;
}
else
WarningBox ( " Impossibile registrare il servizio per l'esecuzione automatica del gestore applicazioni. \n Selezionare una diversa modalita' di esecuzione! " ) ;
}
break ;
//link nella cartella esecuzione automatica
case lm_autostart :
{
CreateIcon ( CSIDL_COMMON_STARTUP , strExe , " lurch " ) ;
}
break ;
default :
break ;
}
return true ;
}
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
{
2008-01-07 11:29:42 +00:00
//Attenzione! Se c'e' il server di chiavi in funzione va fermato prima di procedere!!!!
const bool bLurch = strModule = = " sr " & & LurchRunning ( ) ;
if ( bLurch )
StopLurch ( ) ;
2007-11-21 10:37:43 +00:00
bool ok = false ;
2007-09-17 14:20:41 +00:00
wxArrayString asFilesList ;
2008-08-08 10:15:42 +00:00
size_t uFilesToCopy ;
2007-09-05 15:21:08 +00:00
//..contando anche quanti sono e memorizzandoli in un array asFileList
2008-08-08 10:15:42 +00:00
if ( wxDir : : Exists ( strSrc ) )
2007-09-05 15:55:53 +00:00
{
2008-08-08 10:15:42 +00:00
uFilesToCopy = wxDir : : GetAllFiles ( strSrc , & asFilesList , strModule + " *.zip " ) ;
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 ) ;
}
2007-09-05 15:55:53 +00:00
2008-08-08 10:15:42 +00:00
//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
wxFileName strLastFile ( asFilesList [ uFilesToCopy - 1 ] ) ; //zip con path completo
wxString strWrk = strLastFile . GetName ( ) ;
strWrk . Truncate ( strWrk . Len ( ) - 1 ) ;
strLastFile . SetName ( strWrk ) ;
strLastFile . SetExt ( " ini " ) ;
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
UpdateInstallIni ( strWrk , strPrgLocPath + " /install.ini " , strModule ) ;
}
2007-08-22 14:55:00 +00:00
}
2008-01-07 11:29:42 +00:00
//Adesso puo' far ripartire il server di chiavi
if ( bLurch )
StartLurch ( strPrgLocPath ) ;
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 ;
//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 )
{
2008-12-18 11:28:19 +00:00
strFileCurr . MakeLower ( ) ; //minuscolizzazione di sicurezza
const wxFileName strFileName ( strFileCurr ) ;
2007-09-19 14:47:17 +00:00
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 )
2007-12-17 16:36:30 +00:00
ok = CopiaFile ( FilesListI , strFileCurr ) ;
2008-12-18 11:28:19 +00:00
2007-09-19 14:47:17 +00:00
return ok ;
}
2007-12-13 14:49:46 +00:00
//metodo per copiare una directory e tutti i files che contiene
void CampoSetup : : CopyDir ( const wxString & strSourceDir , const wxString & strDestDir ) const
{
2008-08-08 10:15:42 +00:00
if ( wxDir : : Exists ( strSourceDir ) )
2007-12-13 14:49:46 +00:00
{
2008-08-08 10:15:42 +00:00
wxArrayString asFilesList ;
2008-12-18 11:28:19 +00:00
const size_t uFilesToCopy = wxDir : : GetAllFiles ( strSourceDir , & asFilesList , " *.* " ) ;
2008-08-08 10:15:42 +00:00
const size_t uFrom = strSourceDir . Len ( ) ;
for ( size_t i = 0 ; i < uFilesToCopy ; i + + )
{
wxString strFileDest = strDestDir + asFilesList [ i ] . Mid ( uFrom ) ;
CopiaFile ( asFilesList [ i ] , strFileDest ) ;
}
2007-12-13 14:49:46 +00:00
}
}
2007-11-21 15:42:21 +00:00
//metodo per accoppare tutti i files di una directory
void CampoSetup : : EmptyOutDir ( const wxString & strDir ) const
{
2008-07-11 08:49:54 +00:00
if ( wxFileName : : DirExists ( strDir ) )
{
wxArrayString asFilesList ;
const size_t uFilesToKill = wxDir : : GetAllFiles ( strDir , & asFilesList , " *.* " ) ;
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)
2007-12-17 16:36:30 +00:00
if ( ! CopiaFile ( strSrcPath , strDstPath ) )
2007-09-20 14:29:11 +00:00
{
2007-12-17 16:36:30 +00:00
wxString strError ;
2007-09-20 14:29:11 +00:00
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/ " ;
2008-08-08 10:15:42 +00:00
if ( wxDir : : Exists ( strTempDir ) )
{
EmptyOutDir ( strTempDir ) ; //deve svuotare la directory dai files per poterla eliminare!!!
: : wxRmdir ( strTempDir ) ; //elimina la dir adesso vuota
}
2008-12-18 11:28:19 +00:00
CheckAndMakeDir ( strTempDir , wxEmptyString ) ; //la ricrea con i permessi dell'utente windows corrente!!
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 ( ' " ' ) ;
2008-09-09 10:47:13 +00:00
if ( ! pi . Update ( ( int ) tfFilesList . GetCurrentLine ( ) , strHref ) )
break ;
//lavora solo con i files del modulo in questione
if ( strHref . StartsWith ( strModule ) )
2007-11-21 10:37:43 +00:00
{
2008-09-09 10:47:13 +00:00
const wxString strPatch = strHref . Mid ( 2 , 4 ) . Lower ( ) ;
2008-12-18 09:53:31 +00:00
const wxString strExt = strHref . Right ( 4 ) . Lower ( ) ;
2008-09-09 10:47:13 +00:00
// 1) e' un pacco
//se e' un pacco devo sapere se e' piu' recente della installazione corrente (potrebbe essere un pacco nuovo..
//..ricompattato) oppure se e' piu' vecchio e non va toccato (e' ad esempio il pacco originale)
if ( strPatch = = " inst " )
{
2008-12-18 09:53:31 +00:00
if ( strExt = = " .ini " ) //operazioni sull'ini x sapere versione e patch
2008-09-09 10:47:13 +00:00
{
HTTPGet ( strTempDir + strHref , strWebPath + strHref ) ;
CampoIniFile iniInst ( strTempDir + strHref , strModule ) ;
const int nRemoteVer = iniInst . GetInt ( " Versione " ) ;
const int nRemotePatch = iniInst . GetInt ( " Patch " ) ;
//se deve aggiornarsi con il pacco scarica pure lo zip cosi' e' a posto
if ( ( nRemoteVer > nLocVer ) | | ( ( nRemoteVer = = nLocVer ) & & ( nRemotePatch > nLocPatch ) ) )
{
const int nDot = strHref . Find ( ' . ' , true ) ;
strHref = strHref . Left ( nDot ) + " 1.zip " ;
HTTPGet ( strTempDir + strHref , strWebPath + strHref ) ;
}
else //se non deve aggiornarsi elimina l'ini in modo da non avere una mezza patch che farebbe incazzare l'unzipper
wxRemoveFile ( strTempDir + strHref ) ;
} //if(strHref.EndsWith("ini")...
} //if(strPatch == "inst")...
// 2) e' una patch
2008-12-18 09:53:31 +00:00
else //se invece e' una normale patch... else di if(strPatch=="inst"..
2008-09-09 10:47:13 +00:00
{
2008-12-18 09:53:31 +00:00
//controlla che sia pi<70> avanti del suo livello patch e che sia un file utile (servono solo .ini e .zip)
if ( atoi ( strPatch ) > nLocPatch & & ( strExt = = " .ini " | | strExt = = " .zip " ) )
2008-09-09 10:47:13 +00:00
HTTPGet ( strTempDir + strHref , strWebPath + strHref ) ;
}
} //if(strHref.StartsWith(strModule))...
} //if(nPos>0)...
} //for(wxString strWrk = tf...
2007-11-21 10:37:43 +00:00
//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
{
2008-12-03 11:10:55 +00:00
wxFileName fn ( m_strSetupPath ) ;
2007-11-21 10:37:43 +00:00
fn . AppendDir ( " .. " ) ;
fn . MakeAbsolute ( ) ;
2008-12-03 11:10:55 +00:00
fn . SetFullName ( " install.ini " ) ;
2007-11-21 10:37:43 +00:00
const wxString strLocalPath = fn . GetPath ( ) ;
2009-02-02 14:07:13 +00:00
2007-11-21 10:37:43 +00:00
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
}
2008-01-04 16:03:24 +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
{
2008-12-03 11:10:55 +00:00
wxFileName fn ( m_strSetupPath ) ;
2007-09-20 14:29:11 +00:00
fn . AppendDir ( " .. " ) ;
fn . MakeAbsolute ( ) ;
2008-12-03 11:10:55 +00:00
fn . SetFullName ( " install.ini " ) ;
2007-09-20 14:29:11 +00:00
const wxString strLocalPath = fn . GetPath ( ) ;
wxString strRemotePath ;
{
CampoIniFile iniLocalInstall ( fn . GetFullPath ( ) , " Main " ) ;
strRemotePath = iniLocalInstall . Get ( " DiskPath " ) ;
}
2008-01-04 16:03:24 +00:00
2007-11-21 15:42:21 +00:00
DiskUpdateModule ( strLocalPath , strRemotePath , " sy " ) ;
2008-01-04 16:03:24 +00:00
DiskUpdateModule ( strLocalPath , strRemotePath , " sr " ) ;
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
2008-12-03 11:10:55 +00:00
wxFileName fn ( m_strSetupPath ) ;
2007-11-21 15:42:21 +00:00
fn . AppendDir ( " .. " ) ;
fn . MakeAbsolute ( ) ;
2008-12-03 11:10:55 +00:00
fn . SetFullName ( " install.ini " ) ;
2007-11-21 15:42:21 +00:00
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 " ) ;
}
2008-01-04 16:03:24 +00:00
//aggiornamento dei moduli SY e SR via web
2007-11-21 15:42:21 +00:00
InternetUpdateModule ( strLocalPath , strRemotePath , " sy " ) ;
2008-01-04 16:03:24 +00:00
InternetUpdateModule ( strLocalPath , strRemotePath , " sr " ) ;
2007-11-21 15:42:21 +00:00
//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 " ) ;
2008-08-08 10:15:42 +00:00
if ( wxDir : : Exists ( strSrc ) )
2007-08-22 14:55:00 +00:00
{
2008-08-08 10:15:42 +00:00
const size_t uFilesToCopy = wxDir : : GetAllFiles ( strSrc , & asDemoList ) ;
wxString strFileCurr ;
const size_t nPathLenght = strSrc . Len ( ) ;
CampoProgressDialog pi ( " Installazione Versione Demo... " , ( int ) uFilesToCopy , m_pWizard ) ;
for ( size_t i = 0 ; i < uFilesToCopy ; i + + )
2007-08-23 13:18:25 +00:00
{
2008-08-08 10:15:42 +00:00
if ( ! pi . Update ( ( int ) i , asDemoList [ i ] ) )
2007-09-19 14:47:17 +00:00
break ;
2008-08-08 10:15:42 +00:00
asDemoList [ i ] . Lower ( ) ;
strFileCurr = strPrgLocPath ;
strFileCurr + = asDemoList [ i ] . Mid ( nPathLenght ) ;
if ( ! strFileCurr . IsEmpty ( ) )
{
if ( ! CopyFilesAndDirs ( asDemoList [ i ] , strFileCurr , false ) )
break ;
}
}
2007-08-22 09:16:29 +00:00
2008-08-08 10:15:42 +00:00
//icona sul desktop
const bool bDesktopShortcut = m_pWizard - > GetDesktopShortcut ( ) ;
if ( bDesktopShortcut )
{
const wxFileName strExe ( " c:/campodemo " , wxT ( " ba0.exe " ) ) ;
CreateIcon ( CSIDL_COMMON_DESKTOPDIRECTORY , strExe , " CampoDEMO " ) ;
}
2007-08-22 09:16:29 +00:00
2008-08-08 10:15:42 +00:00
//lanciare ba0.exe in uscita
wxSetWorkingDirectory ( strPrgLocPath ) ;
wxExecute ( " ba0 " ) ;
}
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)
2008-06-19 12:50:59 +00:00
//un client NON installa i dati!! (senno' e' una installazione locale semplice)
if ( uInstallationType ! = it_client )
CheckAndMakeDir ( strDataPath , " dati " ) ;
2007-09-19 14:47:17 +00:00
}
// 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 ( " .. " ) ;
2007-12-13 14:49:46 +00:00
strSourcePath . AppendDir ( " .. " ) ;
2009-01-20 11:16:02 +00:00
strSourcePath . AppendDir ( " campo " ) ; // NOME fisso della cartella del CD, non mettere APPNAME
2007-09-19 14:47:17 +00:00
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 ( ) ;
2009-02-04 16:28:37 +00:00
NormalizeSlash ( strSourceFile ) ;
2007-10-25 15:48:37 +00:00
//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!!!
2008-06-19 12:50:59 +00:00
//i DATI NON VANNO MAI installati in caso di installazione client!!!
2007-10-25 15:48:37 +00:00
//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
2008-06-19 12:50:59 +00:00
if ( bNewInstallation & & uInstallationType ! = it_client & & ! bInstallDemoData )
2007-10-25 15:48:37 +00:00
{
strFileCurr = strDataPath ;
strFileCurr + = asFilesList [ i ] . Mid ( nPathLenght + 5 ) ;
2008-06-19 12:50:59 +00:00
//Ulteriore controllo di sicurezza: se trova il file di destinazione gia' presente..
//..NON lo sovrascrive (lo mette vuoto cosi' non lo copia)
if ( wxFileName : : FileExists ( strFileCurr ) )
strFileCurr = " " ;
2007-10-25 15:48:37 +00:00
}
} 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 ;
2009-02-04 16:28:37 +00:00
//normalizza per sicurezza il nome (completo di path) del file (visto che ci sono metodi cui piace..
//..aggiungere / o \ a piacere..
NormalizeSlash ( strFileCurr ) ;
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 " ) ;
2008-01-04 16:03:24 +00:00
//server,client o standalone?
2007-10-18 14:51:26 +00:00
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-19 14:47:17 +00:00
2009-01-19 17:25:12 +00:00
// 6) AGGIORNAMENTO DI ADMIN.INI CON IL TEMA DEL RESELLER
//---------------------------------------------------------
//carica il tema predefinito del reseller dentro l'admin.ini che sta in cartella programmi\dati\config..
//..in modo da vederli subito quando lancer<65> ba1 (e successivamente ba0)
if ( bNewInstallation )
{
//file sorgente
const wxString strThemeFileName = Theme ( ) ;
wxString strSrcThemePath = m_strSetupPath ;
strSrcThemePath < < strThemeFileName ;
CampoIniFile CampoTheme ( strSrcThemePath , " Standard " ) ;
2009-01-20 09:59:58 +00:00
//file di destinazione
CampoIniFile CampoDestAdmin ( strDataPath + " /config/admin.ini " , " Colors " ) ;
2009-01-19 17:25:12 +00:00
//copia del tema standard nell'admin.ini di destinazione
long nIndex ;
wxString strKey ;
//ciclo su tutte le variabili del paragrafo di origine
for ( bool ok = CampoTheme . GetFirstEntry ( strKey , nIndex ) ; ok ; ok = CampoTheme . GetNextEntry ( strKey , nIndex ) )
{
//copia nel corrispondente paragrafo di destinazione
2009-01-20 09:59:58 +00:00
CampoDestAdmin . Set ( strKey , CampoTheme . Get ( strKey ) ) ;
2009-01-19 17:25:12 +00:00
}
}
2007-08-24 13:18:47 +00:00
2009-01-19 17:25:12 +00:00
// 7) AGGIORNAMENTO DEL MODULO SY CON EVENTUALI PATCH PRESENTI IN PROGRAM DEL CD E AGGIORNAMENTO INSTALL.INI
2007-09-19 14:47:17 +00:00
//----------------------------------------------------------------------------------------------------------
//procede poi al caricamento delle patch eventuali di sistema all'interno della dir 'program' e al..
2008-01-04 16:03:24 +00:00
//..conseguente riaggiornamento del livello versione/patch di SY ed SR 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 ) )
2007-12-13 14:49:46 +00:00
{
const wxString strSetupCDPath = strPrgCDPath + " /setup " ;
const wxString strSetupLocPath = strPrgLocPath + " /setup " ;
CopyDir ( strSetupCDPath , strSetupLocPath ) ;
2007-12-06 11:40:20 +00:00
UnzipModule ( strPrgLocPath , strPrgCDPath , " sy " ) ;
2008-01-04 16:03:24 +00:00
UnzipModule ( strPrgLocPath , strPrgCDPath , " sr " ) ;
}
2009-01-19 17:25:12 +00:00
// 8) CREAZIONE AUTOSTART DEI SERVERS (SE CI SONO)
2008-01-04 16:03:24 +00:00
//------------------------------------------------
//solo se sta installando campo in postazione server e deve installare un gestore di servizi..
//..avvia la procedura della creazione dell'autostart(un casino). Questa procedura non puo'..
//..valere per l'aggiornamento, che agisce in modo diverso
if ( bNewInstallation )
{
const LurchMode iSrvAutostartMode = m_pWizard - > GetSrvAutostartMode ( ) ;
if ( iSrvAutostartMode ! = lm_none )
{
CreateAutostartMode ( iSrvAutostartMode , strPrgLocPath ) ;
}
2007-12-13 14:49:46 +00:00
}
2007-09-05 15:21:08 +00:00
2007-08-24 13:18:47 +00:00
2009-01-19 17:25:12 +00:00
// 9) CREAZIONE DELL'ICONA SUL DESKTOP
2007-09-19 14:47:17 +00:00
//------------------------------------
const bool bDesktopShortcut = m_pWizard - > GetDesktopShortcut ( ) ;
if ( bDesktopShortcut )
{
const wxFileName strExe ( strPrgLocPath , wxT ( " ba0.exe " ) ) ;
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 ( ) ;
2009-01-20 11:16:02 +00:00
wxString strLnk = Product ( ) ;
2007-10-18 11:13:15 +00:00
switch ( nInstType )
2007-10-16 16:06:54 +00:00
{
2009-01-20 11:16:02 +00:00
case it_server : strLnk + = " (Server) " ; break ;
case it_client : strLnk + = " (Client) " ; break ;
default : break ;
2007-10-16 16:06:54 +00:00
}
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
2009-01-19 17:25:12 +00:00
// 10) AGGIORNAMENTO CAMPO.STP
2007-09-19 14:47:17 +00:00
//---------------------------
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
2009-01-19 17:25:12 +00:00
// 11) CHIUDE IL SETUP LANCIANDO BA1 -6 PER INSTALLAZIONE MODULI
2007-09-19 14:47:17 +00:00
//-------------------------------------------------------------
//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
}
2008-12-05 12:11:20 +00:00
//------------------------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////
// Metodi per il controllo preventivo di eventuali cazzate in procinto di accadere
////////////////////////////////////////////////////////////////////////////////////
2009-01-20 11:16:02 +00:00
bool CampoSetup : : SystemRunning ( const wxString & strAppName , wxString strMsg ) const
2007-09-26 12:59:37 +00:00
{
wxSingleInstanceChecker sicProgram ( strAppName ) ;
2007-10-09 13:22:42 +00:00
2009-01-20 11:16:02 +00:00
strMsg . Replace ( wxT ( " PRODUCT " ) , PRODUCT ) ;
2007-10-09 13:22:42 +00:00
int i ;
2008-07-08 10:51:07 +00:00
for ( i = 10 ; i > 0 & & sicProgram . IsAnotherRunning ( ) ; i - - )
2007-10-09 13:22:42 +00:00
wxSleep ( 1 ) ;
2008-01-04 16:03:24 +00:00
if ( i < = 0 & & ! strMsg . IsEmpty ( ) )
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
2008-01-04 16:03:24 +00:00
bool CampoSetup : : LurchRunning ( ) const
{
//cerca Lurch che funziona come programma (esecuzione in modalita' avvio automatico)...
2008-11-18 15:03:42 +00:00
bool ok = SystemRunning ( " Lurch " , wxEmptyString ) ;
2008-01-04 16:03:24 +00:00
if ( ! ok )
{
//...se non lo trova cerca il solo Authoriz sempre come programma...
2008-11-18 15:03:42 +00:00
ok = SystemRunning ( " Authorization " , wxEmptyString ) ;
2008-01-04 16:03:24 +00:00
//se non trova nulla cerca Lurch come servizio...
if ( ! ok )
{
int year = 0 ;
wxString strSrv = " 127.0.0.1 " ;
ok = ServerLogin ( year , strSrv ) ! = 0xFFFF ;
}
}
return ok ;
}
2008-11-18 15:03:42 +00:00
bool CampoSetup : : CampoRunning ( ) const
{
//ricerca di campo.aut per avere la lista dei moduli
//prima tenta con aggiornamento da disco...
wxString strInstallPath = " ../install.ini " ;
//...poi con aggiornamento da CD
if ( ! wxFileName : : FileExists ( strInstallPath ) )
strInstallPath = " ../../campo/install.ini " ;
//fa un giro sull'install.ini alla ricerca di tutti i moduli (sono i paragrafi lunghi 2) installati (se aggiornamento..
//..da disco) o da installare (se sta installando da CD)
wxArrayString asModuli ;
if ( wxFileName : : FileExists ( strInstallPath ) )
{
wxString strModulo ;
long nIndex ;
CampoIniFile iniInstall ( strInstallPath , strModulo ) ;
for ( bool ok = iniInstall . GetFirstGroup ( strModulo , nIndex ) ; ok ; ok = iniInstall . GetNextGroup ( strModulo , nIndex ) )
{
if ( strModulo . Len ( ) = = 2 )
asModuli . Add ( strModulo ) ; //aggiunge all'array tutti i moduli che trova in install.ini
}
}
else //non trova nessun install.ini (non dovrebbe mai accadere) e tenta i moduli pi<70> importanti
{
asModuli . Add ( " ba " ) ;
asModuli . Add ( " cg " ) ;
asModuli . Add ( " ve " ) ;
asModuli . Add ( " mg " ) ;
asModuli . Add ( " lv " ) ;
}
//scandisce l'array dei moduli alla ricerca di un eventuale programma di campo ancora running a sua insaputa
wxString strAppName ;
for ( size_t i = 0 ; i < asModuli . GetCount ( ) ; i + + )
{
for ( size_t j = 0 ; j < = 9 ; j + + )
{
strAppName = asModuli [ i ] ;
strAppName + = ( ' 0 ' + j ) ;
wxSingleInstanceChecker sicProgram ( strAppName ) ;
if ( sicProgram . IsAnotherRunning ( ) )
{
strAppName < < " <20> in esecuzione! E' necessario terminarlo utilizzando il Task Manager di Windows " ;
ErrorBox ( strAppName ) ;
return true ;
}
}
}
return false ; //campo non sta andando
}
2007-09-26 12:59:37 +00:00
//metodo principale che sceglie la modalita' di lancio del programma
void CampoSetup : : OnTimer ( wxTimerEvent & WXUNUSED ( e ) )
{
2009-01-21 16:15:45 +00:00
//controllo di un eventuale setup gi<67> lanciato (tipico di utonti e della premiata ditta bib<69> & bib<69> )
wxSingleInstanceChecker sicSetup ( " setup " ) ;
if ( sicSetup . IsAnotherRunning ( ) )
{
wxString msg ;
msg < < " Una installazione di " < < PRODUCT < < " <20> gi<67> in esecuzione! " ;
ErrorBox ( msg ) ;
m_pMainFrame - > Destroy ( ) ;
return ;
}
2007-09-26 12:59:37 +00:00
//controllo di eventuali Campo o servers attivi e conseguente interruzione dell'installazione
2008-07-08 10:51:07 +00:00
if ( LurchRunning ( ) )
{
2009-01-20 11:16:02 +00:00
wxString msg ;
msg < < " Per poter aggiornare/installare il programma " < < PRODUCT
< < " deve temporaneamente essere disattivato il gestore delle licenze! \n "
< < " Prima di disattivare il gestore delle licenze accertarsi che tutti gli utenti spengano il programma!! \n "
< < " Proseguire con la disattivazione? " ;
if ( YesNoBox ( msg ) )
StopLurch ( ) ;
2008-07-17 15:05:25 +00:00
else
2008-11-18 15:03:42 +00:00
{
m_pMainFrame - > Destroy ( ) ;
2008-07-17 15:05:25 +00:00
return ;
2008-11-18 15:03:42 +00:00
}
2008-07-08 10:51:07 +00:00
}
2009-01-20 11:16:02 +00:00
if ( SystemRunning ( " ba0 " , " Uscire dal programma PRODUCT prima di procedere con l'aggiornamento/installazione! " ) | |
SystemRunning ( " ba1 " , " Uscire dal programma di manutenzione di PRODUCT \n prima di procedere con l'aggiornamento/installazione! " ) )
2007-09-26 12:59:37 +00:00
{
m_pMainFrame - > Destroy ( ) ;
return ;
}
2008-11-18 15:03:42 +00:00
if ( CampoRunning ( ) )
{
2009-01-20 11:16:02 +00:00
wxString msg ;
msg < < " Un applicativo di " < < PRODUCT < < " <20> ancora in esecuzione! \n "
< < " L'installazione sar<61> interrotta immediatamente " ;
ErrorBox ( msg ) ;
2008-11-18 15:03:42 +00:00
m_pMainFrame - > Destroy ( ) ;
return ;
}
2007-09-26 12:59:37 +00:00
//path del programma setup.exe in esecuzione; serve in seguito in quanto alcuni metodi (tipo la GetAllFiles)..
//..fanno perdere questo path
2008-12-10 16:59:04 +00:00
//attenzione!!! il path DEVE terminare con "\" senn<6E> in base al tipo di chiamata (-uw,-uc,-ud) i rispettivi..
//..metodi funzionano a casaccio!!!
2009-02-04 16:28:37 +00:00
const wxString strCommand = argv [ 1 ] ;
2007-09-26 12:59:37 +00:00
if ( strCommand . IsEmpty ( ) )
2009-02-04 16:28:37 +00:00
{
wxFileName strPath ( argv [ 0 ] ) ;
strPath . MakeAbsolute ( ) ;
strPath . SetCwd ( ) ;
m_strSetupPath = strPath . GetPath ( ) ;
if ( ! m_strSetupPath . EndsWith ( wxT ( " \\ " ) ) )
m_strSetupPath < < ' \\ ' ;
//installazione normale da CD
2007-09-26 12:59:37 +00:00
NormalSetup ( ) ;
2009-02-04 16:28:37 +00:00
}
2007-09-26 12:59:37 +00:00
else
2007-11-21 10:37:43 +00:00
{
2009-02-04 16:28:37 +00:00
//attenzione: modifica richiesta perch<63> la cartella di esecuzione di setup <20> diversa nel caso sia un..
//..aggiornamento o una installazione da CD
m_strSetupPath = wxGetCwd ( ) ;
m_strSetupPath . MakeLower ( ) ;
if ( ! m_strSetupPath . EndsWith ( " setup " ) )
{
m_strSetupPath < < " \\ setup " ;
wxSetWorkingDirectory ( m_strSetupPath ) ;
}
if ( ! m_strSetupPath . EndsWith ( wxT ( " \\ " ) ) )
m_strSetupPath < < ' \\ ' ;
//aggiornamento da disco,client,web
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 ( ) ;
2008-09-09 10:47:13 +00:00
m_pWizard = NULL ; //finestra di programma nulla;deve esistere solo per il NormalSetup dove viene inizializzata
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 ;
}