1997-10-30 15:13:59 +00:00
# include <applicat.h>
# include <colors.h>
1998-08-21 10:58:38 +00:00
# include <defmask.h>
1999-05-24 13:34:11 +00:00
# include <dongle.h>
# include <execp.h>
1998-08-21 10:58:38 +00:00
# include <isamrpc.h>
1998-02-24 10:30:04 +00:00
# include <os_dep.h>
1997-10-30 15:13:59 +00:00
# include <progind.h>
1997-12-04 14:07:49 +00:00
# include <sheet.h>
1997-10-30 15:13:59 +00:00
# include <utility.h>
1998-08-25 17:46:29 +00:00
# include <prefix.h>
1998-11-04 18:04:26 +00:00
# include <urldefid.h>
1997-10-30 15:13:59 +00:00
# include "ba1.h"
1997-12-15 15:11:40 +00:00
# include "ba1500.h"
1997-10-30 15:13:59 +00:00
# include "ba1600.h"
# include "ba1700a.h"
1998-02-24 10:30:04 +00:00
1998-02-18 13:46:52 +00:00
// definizioni delle colonne dello sheet
# define C_MODULE 1
# define C_CODE 2
# define C_RELEASE 3
# define C_PATCH 4
# define C_DATAREL 5
# define C_CURRRELEASE 6
# define C_CURRPATCH 7
# define C_CURRDATAREL 8
# define C_ISPATCH 9
1998-01-29 13:42:30 +00:00
1998-08-25 17:46:29 +00:00
# ifdef _DEMO_
const char * const http_default_path = " /aga/eurodemo/zipdemo/ " ;
# else
const char * const http_default_path = " /aga/euro/zip/ " ;
# endif
1999-04-06 15:34:39 +00:00
1998-01-23 14:55:34 +00:00
HIDDEN int compare_version ( const char * v1 , int p1 , const char * v2 , int p2 )
1997-10-30 15:13:59 +00:00
{
1998-08-25 17:46:29 +00:00
TString16 ver1 ( v1 ) , ver2 ( v2 ) ;
1997-10-30 15:13:59 +00:00
ver1 . trim ( ) ;
1998-08-25 17:46:29 +00:00
if ( ver1 . len ( ) = = 4 )
1997-10-30 15:13:59 +00:00
ver1 . insert ( ( v1 [ 0 ] = = ' 9 ' ) ? " 19 " : " 20 " , 0 ) ;
ver2 . trim ( ) ;
1998-08-25 17:46:29 +00:00
if ( ver2 . len ( ) = = 4 )
1997-10-30 15:13:59 +00:00
ver2 . insert ( ( v2 [ 0 ] = = ' 9 ' ) ? " 19 " : " 20 " , 0 ) ;
1998-08-25 17:46:29 +00:00
1998-01-22 11:56:14 +00:00
int res = ver1 . compare ( ver2 , - 1 , TRUE ) ;
if ( res = = 0 )
1998-01-23 14:55:34 +00:00
res = p1 - p2 ;
1998-08-25 17:46:29 +00:00
1998-01-22 11:56:14 +00:00
return res ;
1997-10-30 15:13:59 +00:00
}
1997-12-15 15:11:40 +00:00
HIDDEN word version2year ( const char * v )
1998-08-25 17:46:29 +00:00
{
1997-12-15 15:11:40 +00:00
TString16 ver ( v ) ;
1998-08-25 17:46:29 +00:00
if ( ver . len ( ) = = 4 )
1997-12-15 15:11:40 +00:00
ver . insert ( ( v [ 0 ] = = ' 9 ' ) ? " 19 " : " 20 " , 0 ) ;
1998-08-25 17:46:29 +00:00
ver . cut ( 4 ) ;
1997-12-15 15:11:40 +00:00
return atoi ( ver ) ;
}
1998-08-25 17:46:29 +00:00
bool is_internet_path ( const TString & addr )
{
if ( addr . compare ( " www. " , 4 , TRUE ) = = 0 )
return TRUE ;
if ( addr . compare ( " http: " , 5 , TRUE ) = = 0 )
return TRUE ;
int a1 , a2 , a3 , a4 ;
if ( sscanf ( addr , " %d.%d.%d.%d " , & a1 , & a2 , & a3 , & a4 ) = = 4 )
return TRUE ;
return FALSE ;
}
1997-10-30 15:13:59 +00:00
///////////////////////////////////////////////////////////
// Maschera principale
///////////////////////////////////////////////////////////
1997-12-04 14:07:49 +00:00
class TInstaller_mask : public TArray_sheet
1998-08-25 17:46:29 +00:00
{
1997-12-04 14:07:49 +00:00
static TInstaller_mask * _curr_mask ;
1997-12-17 13:40:59 +00:00
word _year_assist ;
1998-01-29 13:42:30 +00:00
bool _installed ; // Flag per verificare se almeno un modulo e' stato installato
1998-11-04 18:04:26 +00:00
enum { NONE , NEW_MENU , NEW_MENUPRG , NEW_INSTALLER } _reboot_program ;
1997-12-04 14:07:49 +00:00
protected : // TSheet
1997-12-15 15:11:40 +00:00
virtual bool on_key ( KEY key ) ;
1998-11-04 18:04:26 +00:00
static bool quit_handler ( TMask_field & f , KEY k ) ;
1998-02-09 12:06:44 +00:00
static bool tutti_handler ( TMask_field & f , KEY k ) ;
1998-11-04 18:04:26 +00:00
int get_module_number ( const char * module ) const ;
1997-12-04 14:07:49 +00:00
1997-10-30 15:13:59 +00:00
protected :
static bool path_handler ( TMask_field & fld , KEY key ) ;
static bool sheet_notify ( TSheet_field & s , int r , KEY k ) ;
static bool install_handler ( TMask_field & fld , KEY key ) ;
1998-08-25 17:46:29 +00:00
static bool update_handler ( TMask_field & f , KEY k ) ;
1997-10-30 15:13:59 +00:00
1998-02-18 13:46:52 +00:00
bool add_module ( TConfig & ini , const TString & module , bool patch , int pos = - 1 ) ;
1998-02-09 12:06:44 +00:00
bool add_header ( TConfig & ini , const TString & module , bool patch ) ;
1998-11-04 18:04:26 +00:00
int precheck_modules ( bool only_newer = TRUE ) ;
1997-10-30 15:13:59 +00:00
void update_version ( ) ;
1997-12-15 15:11:40 +00:00
1998-01-29 13:42:30 +00:00
bool move_file ( const TFilename & fromdir , const TFilename & file , const char * dir ) const ;
1997-12-15 15:11:40 +00:00
bool move_module ( const TString & module , TInstall_ini & ini , bool update ) const ;
bool can_install ( const char * module , TInstall_ini & ini ) ;
1997-12-04 14:07:49 +00:00
void install_selection ( ) ;
1998-11-04 18:04:26 +00:00
bool install_patches ( const TString & module , const TString & lastrelease , int lastpatch , bool onlynew = TRUE ) ;
1998-08-25 17:46:29 +00:00
KEY askdisk ( TString & path , TFilename & cmdline , int d , int dischi , const char * modulo ) ;
1997-10-30 15:13:59 +00:00
1997-12-15 15:11:40 +00:00
bool do_process ( TToken_string & commands ) const ;
1997-10-30 15:13:59 +00:00
bool pre_process ( TInstall_ini & ini , const char * module ) const ;
bool post_process ( TInstall_ini & ini , const char * module ) const ;
1998-11-04 18:04:26 +00:00
bool get_internet_path ( TFilename & ininame ) ;
void parse_internet_path ( TString & http_server , TFilename & http_path ) ;
1997-10-30 15:13:59 +00:00
1998-01-29 13:42:30 +00:00
public :
bool installed ( ) { return _installed ; }
1997-10-30 15:13:59 +00:00
bool autoload ( ) ;
1998-01-23 14:55:34 +00:00
bool install ( const TString & module , int patch ) ;
1997-10-30 15:13:59 +00:00
TInstaller_mask ( ) ;
1997-12-04 14:07:49 +00:00
virtual ~ TInstaller_mask ( ) ;
1997-10-30 15:13:59 +00:00
} ;
1997-12-04 14:07:49 +00:00
TInstaller_mask * TInstaller_mask : : _curr_mask = NULL ;
1997-10-30 15:13:59 +00:00
// Copia nello sheet i dati di un modulo prendendoli da un .ini
1998-02-18 13:46:52 +00:00
bool TInstaller_mask : : add_module ( TConfig & ini , const TString & module , bool patch , int pos )
1997-10-30 15:13:59 +00:00
{
1998-01-26 10:45:15 +00:00
ini . write_protect ( ) ;
1997-10-30 15:13:59 +00:00
bool ok = ini . set_paragraph ( module ) ;
if ( ok )
2001-04-30 14:22:43 +00:00
{
const int numpatch = ini . get_int ( " Patch " ) ;
TString16 strpatch ;
if ( numpatch > 0 )
strpatch . format ( " %03d " , numpatch ) ;
1997-12-04 14:07:49 +00:00
TToken_string row ;
row = " " ; // Not selected
row . add ( ini . get ( " Descrizione " ) ) ;
1997-10-30 15:13:59 +00:00
row . add ( module ) ;
row . add ( ini . get ( " Versione " ) ) ;
2001-04-30 14:22:43 +00:00
row . add ( strpatch ) ;
1997-10-30 15:13:59 +00:00
row . add ( ini . get ( " Data " ) ) ;
1998-11-04 18:04:26 +00:00
row . add ( patch ? " X " : " " , C_ISPATCH ) ;
1998-02-18 13:46:52 +00:00
if ( pos = = - 1 )
add ( row ) ;
else
insert ( row , pos ) ;
1997-10-30 15:13:59 +00:00
}
return ok ;
}
1998-02-09 12:06:44 +00:00
// Copia nello sheet i dati di un modulo prendendoli da un .ini
bool TInstaller_mask : : add_header ( TConfig & ini , const TString & module , bool patch )
{
ini . write_protect ( ) ;
bool ok = ini . set_paragraph ( module ) ;
if ( ok )
1998-08-25 17:46:29 +00:00
{
1998-02-09 12:06:44 +00:00
TToken_string row ;
row = " " ; // Not selected
row . add ( ini . get ( " Descrizione " ) ) ;
row . add ( ini . get ( " " ) ) ;
enable_row ( add ( row ) , FALSE ) ;
}
return ok ;
}
1998-01-22 11:56:14 +00:00
static int compare_modules ( const TObject * * o1 , const TObject * * o2 )
{
TToken_string & ts1 = * ( TToken_string * ) ( * o1 ) ;
TToken_string & ts2 = * ( TToken_string * ) ( * o2 ) ;
1998-08-25 17:46:29 +00:00
1998-01-22 11:56:14 +00:00
int res = 0 ;
1998-08-25 17:46:29 +00:00
for ( int i = 2 ; i < 5 & & res = = 0 ; i + + )
1998-01-22 11:56:14 +00:00
{
TString16 s1 = ts1 . get ( i ) ;
const char * s2 = ts2 . get ( i ) ;
res = s1 . compare ( s2 ) ;
}
return res ;
}
1998-11-04 18:04:26 +00:00
int TInstaller_mask : : precheck_modules ( bool only_newer )
1998-01-22 11:56:14 +00:00
{
const int tot = int ( items ( ) ) ;
1998-02-18 13:46:52 +00:00
1998-11-04 18:04:26 +00:00
TString16 release , currrelease ;
int patchlevel , modnumber ;
1998-01-22 11:56:14 +00:00
for ( int r = 0 ; r < tot ; r + + )
1998-08-25 17:46:29 +00:00
{
1998-11-04 18:04:26 +00:00
release = row ( r ) . get ( C_RELEASE ) ;
patchlevel = row ( r ) . get_int ( C_PATCH ) ;
currrelease = row ( r ) . get ( C_CURRRELEASE ) ;
modnumber = get_module_number ( row ( r ) . get ( C_CODE ) ) ;
if ( modnumber > = 0 & &
! release . blank ( ) & &
( ( release > currrelease ) | |
( release = = currrelease
& & ( only_newer ? patchlevel > row ( r ) . get_int ( C_CURRPATCH ) : patchlevel > = row ( r ) . get_int ( C_CURRPATCH ) ) ) )
1999-07-16 14:59:11 +00:00
& & main_app ( ) . has_module ( modnumber , CHK_DONGLE ) )
1998-08-25 17:46:29 +00:00
{
1998-11-04 18:04:26 +00:00
// checca il modulo o la patch se ho installata la stessa versione
2001-06-25 10:41:20 +00:00
const bool chk = row ( r ) . get_char ( C_ISPATCH ) ! = ' X ' | | release = = row ( r ) . get ( C_CURRRELEASE ) ;
1998-11-04 18:04:26 +00:00
check ( r , chk ) ;
1998-01-22 11:56:14 +00:00
}
}
2001-06-25 10:41:20 +00:00
force_update ( ) ; // Indispensabile per vedere le righe aggiornate
1998-01-22 11:56:14 +00:00
return tot ;
}
1998-11-04 18:04:26 +00:00
int TInstaller_mask : : get_module_number ( const char * module ) const
{
int aut = - 1 ;
if ( module & & * module )
{
TScanner scanner ( " prassi.aut " ) ;
bool ok = FALSE ;
for ( aut = 0 ; scanner . line ( ) ! = " " ; aut + + )
if ( strncmp ( scanner . token ( ) , module , 2 ) = = 0 ) { ok = TRUE ; break ; }
}
return ok ? aut : - 1 ;
}
1997-10-30 15:13:59 +00:00
void TInstaller_mask : : update_version ( )
{
TInstall_ini ini ;
1998-08-25 17:46:29 +00:00
1997-12-04 14:07:49 +00:00
TString_array & array = rows_array ( ) ;
FOR_EACH_ARRAY_ROW_BACK ( array , m , row )
1998-08-25 17:46:29 +00:00
{
1998-02-18 13:46:52 +00:00
if ( * row - > get ( C_CODE ) ! = ' ' )
1998-02-09 12:06:44 +00:00
{
1998-02-18 13:46:52 +00:00
const TString16 module = row - > get ( C_CODE ) ;
1998-02-09 12:06:44 +00:00
ini . set_paragraph ( module ) ;
1998-08-25 17:46:29 +00:00
1998-02-18 13:46:52 +00:00
const TString16 newver = row - > get ( C_RELEASE ) ;
1998-02-09 12:06:44 +00:00
const TString16 oldver = ini . get ( " Versione " ) ;
2001-04-30 14:22:43 +00:00
const int numpatch = ini . get_int ( " Patch " ) ;
TString16 strpatch ;
if ( numpatch > 0 ) strpatch . format ( " %03d " , numpatch ) ;
1998-02-18 13:46:52 +00:00
row - > add ( oldver , C_CURRRELEASE ) ;
2001-04-30 14:22:43 +00:00
row - > add ( strpatch , C_CURRPATCH ) ;
1998-02-18 13:46:52 +00:00
row - > add ( ini . get ( " Data " ) , C_CURRDATAREL ) ;
1998-02-09 12:06:44 +00:00
}
1997-10-30 15:13:59 +00:00
}
1997-12-04 14:07:49 +00:00
force_update ( ) ;
1997-10-30 15:13:59 +00:00
}
// Cerca nel percorso specificato sulla maschera tutti i possibili files .ini
// utilizzabili per un'installazione e li inserisce nello spreadsheet
bool TInstaller_mask : : autoload ( )
1998-08-25 17:46:29 +00:00
{
1998-02-18 13:46:52 +00:00
TString_array & mask_rows = rows_array ( ) ;
1998-11-04 18:04:26 +00:00
1998-08-21 10:58:38 +00:00
TString http_server ;
TFilename http_path ;
1998-11-04 18:04:26 +00:00
TFilename path ;
1998-08-21 10:58:38 +00:00
TFilename ininame ;
1998-11-04 18:04:26 +00:00
const bool internet = get_internet_path ( path ) ;
1998-08-21 10:58:38 +00:00
if ( internet )
{
1998-11-04 18:04:26 +00:00
parse_internet_path ( http_server , http_path ) ;
/* http_server = get(F_PATH);
1998-08-21 10:58:38 +00:00
if ( http_server . compare ( " http:// " , 7 , TRUE ) = = 0 )
http_server . ltrim ( 7 ) ;
const int slash = http_server . find ( ' / ' ) ;
if ( slash > 0 )
{
1998-11-04 18:04:26 +00:00
http_path = http_server . mid ( slash ) ;
if ( http_path . right ( 1 ) ! = " / " )
http_path < < ' / ' ;
http_server . cut ( slash ) ;
1998-08-21 10:58:38 +00:00
}
else
1998-11-04 18:04:26 +00:00
http_path = http_default_path ; */
1998-08-21 10:58:38 +00:00
make_dir ( path ) ;
ininame = path ;
ininame . add ( TInstall_ini : : default_name ( ) ) ;
if ( ininame . exist ( ) & & yesno_box ( " Si desidera svuotare la cache dei files scaricati dal sito? " ) )
{
TString_array list ;
TFilename name = path ; name . add ( " *.* " ) ;
: : list_files ( name , list ) ;
1998-11-04 18:04:26 +00:00
1998-08-21 10:58:38 +00:00
FOR_EACH_ARRAY_ROW ( list , i , row )
: : remove ( * row ) ;
}
if ( ! ininame . exist ( ) )
{
1998-11-04 18:04:26 +00:00
bool httpresult ;
1998-08-21 10:58:38 +00:00
TFilename remote_ini = http_path ;
remote_ini < < TInstall_ini : : default_name ( ) ;
1998-11-04 18:04:26 +00:00
{
TIndwin contacting ( 60 , " Sto contattando il server HTTP... " , FALSE , FALSE ) ;
httpresult = http_get ( http_server , remote_ini , ininame ) ;
}
if ( ! httpresult )
return error_box ( " Impossibile trasferire %s da %s " ,
( const char * ) remote_ini , ( const char * ) http_server ) ;
1998-08-21 10:58:38 +00:00
}
1998-11-04 18:04:26 +00:00
}
if ( path . exist ( ) )
1998-08-21 10:58:38 +00:00
{
ininame = path ;
ininame . add ( TInstall_ini : : default_name ( ) ) ;
}
else
1997-10-30 15:13:59 +00:00
return error_box ( " Specificare un percorso valido " ) ;
TWait_cursor hourglass ;
1998-08-25 17:46:29 +00:00
// !?!?!? modifica per correggere il bug di libreria su _parked dei TSheet:
// !?!?!? (uso della stringa _park e dell'indice _parked )
// !?!?!? rimuovere appena si <20> corretto l'errore
1999-04-06 15:34:39 +00:00
// for (short pisellone =0; pisellone<100; pisellone++) add("");
1998-08-25 17:46:29 +00:00
// !?!?! fine modifica
1997-12-04 14:07:49 +00:00
destroy ( ) ;
1998-08-25 17:46:29 +00:00
force_update ( ) ;
1997-10-30 15:13:59 +00:00
1998-08-25 17:46:29 +00:00
ininame = path ;
ininame . add ( TInstall_ini : : default_name ( ) ) ;
1997-10-30 15:13:59 +00:00
1998-08-25 17:46:29 +00:00
TString_array modules ;
2001-06-25 10:41:20 +00:00
if ( ininame . exist ( ) )
1997-10-30 15:13:59 +00:00
{
1999-04-06 15:34:39 +00:00
// Presente il file ini generale "install.ini"
1997-10-30 15:13:59 +00:00
TInstall_ini ini ( ininame ) ;
1998-01-28 08:53:28 +00:00
1997-10-30 15:13:59 +00:00
ini . list_paragraphs ( modules ) ;
1997-12-15 15:11:40 +00:00
FOR_EACH_ARRAY_ROW ( modules , i , row )
1997-10-30 15:13:59 +00:00
{
1997-11-06 15:05:42 +00:00
const TString & module = * row ;
1998-02-09 12:06:44 +00:00
if ( module [ 0 ] = = ' _ ' | | module . len ( ) = = 2 )
{
if ( module [ 0 ] = = ' _ ' )
add_header ( ini , module , FALSE ) ;
else
add_module ( ini , module , FALSE ) ;
}
1997-10-30 15:13:59 +00:00
}
}
else
{
1998-11-04 18:04:26 +00:00
// Presenti i singoli file ini dei moduli
ininame = path ;
1997-10-30 15:13:59 +00:00
ininame . add ( " ??inst.ini " ) ;
1997-11-06 15:05:42 +00:00
list_files ( ininame , modules ) ;
1997-12-15 15:11:40 +00:00
FOR_EACH_ARRAY_ROW ( modules , m , row )
1998-08-25 17:46:29 +00:00
{
1997-11-06 15:05:42 +00:00
TString & ininame = * row ;
1997-10-30 15:13:59 +00:00
ininame . lower ( ) ;
const int pos = ininame . find ( " inst.ini " ) ;
1998-01-22 11:56:14 +00:00
CHECKS ( pos > = 2 , " Invalid installation configuration: " , ( const char * ) ininame ) ;
1997-10-30 15:13:59 +00:00
const TString16 module = ininame . mid ( pos - 2 , 2 ) ;
TConfig ini ( ininame , module ) ;
1998-01-23 14:55:34 +00:00
add_module ( ini , module , FALSE ) ;
1998-11-04 18:04:26 +00:00
}
1998-02-18 13:46:52 +00:00
}
// add patches
1999-04-06 15:34:39 +00:00
1998-02-18 13:46:52 +00:00
modules . destroy ( ) ;
1998-11-04 18:04:26 +00:00
1998-08-21 10:58:38 +00:00
if ( internet )
{
1998-11-04 18:04:26 +00:00
http_dir ( http_server , http_path , modules ) ;
for ( int i = modules . last ( ) ; i > = 0 ; i - - )
{
TString & str = modules . row ( i ) ;
if ( str . match ( " ??0???A.INI " ) | | str . match ( " ??0???a.ini " ) )
{
TFilename remote = http_path ;
remote < < str ;
ininame = path ;
ininame . add ( str ) ;
if ( ! ininame . exist ( ) & & ! http_get ( http_server , remote , ininame ) )
{
error_box ( " Errore di trasferimento del file %s " , ( const char * ) remote ) ;
modules . destroy ( i ) ;
}
str = ininame ;
}
else
modules . destroy ( i ) ;
}
modules . pack ( ) ;
1998-08-21 10:58:38 +00:00
}
else
{
1998-11-04 18:04:26 +00:00
ininame = path ;
1998-08-21 10:58:38 +00:00
ininame . add ( " ??0???a.ini " ) ;
list_files ( ininame , modules ) ;
}
1998-02-18 13:46:52 +00:00
modules . sort ( ) ; // sort to have patches in patchlevel order
1998-08-21 10:58:38 +00:00
1998-02-18 13:46:52 +00:00
FOR_EACH_ARRAY_ROW ( modules , am , arow )
1998-08-25 17:46:29 +00:00
{
1998-02-18 13:46:52 +00:00
TString & ininame = * arow ;
ininame . lower ( ) ;
const int pos = ininame . find ( " a.ini " ) ;
CHECKS ( pos > = 6 , " Invalid installation configuration: " , ( const char * ) ininame ) ;
const TString16 module = ininame . mid ( pos - 6 , 2 ) ;
1998-08-25 17:46:29 +00:00
TConfig ini ( ininame , module ) ;
ini . write_protect ( ) ;
2001-06-25 10:41:20 +00:00
for ( int r = int ( items ( ) - 1 ) ; r > = 0 ; r - - )
if ( module = = row ( r ) . get ( C_CODE ) )
break ;
if ( r > = 0 )
1998-02-18 13:46:52 +00:00
{
2001-06-25 10:41:20 +00:00
const TString16 patchversion = ini . get ( " Versione " ) ;
const int patchlevel = ini . get_int ( " Patch " ) ;
TToken_string & row = mask_rows . row ( r ) ;
if ( patchversion = = row . get ( C_RELEASE ) // se le versioni corrispondono ...
& & patchlevel > row . get_int ( C_PATCH ) ) // ..e il patchlevel <20> superiore
2001-04-30 14:22:43 +00:00
{
TString16 patch ; patch . format ( " %03d " , patchlevel ) ; //aggiunge zeri per avere 3 cifre sempre
2001-06-25 10:41:20 +00:00
row . add ( patch , C_PATCH ) ; // aggiorna il patchlevel mostrato per il modulo
if ( * row . get ( C_ISPATCH ) < = ' ' ) // se era un modulo ...
row . add ( " + " , C_ISPATCH ) ; // .....setta la presenza di patches
1998-04-30 14:38:35 +00:00
}
2001-06-25 10:41:20 +00:00
}
else
1998-01-23 14:55:34 +00:00
add_module ( ini , module , TRUE ) ;
1997-10-30 15:13:59 +00:00
}
1998-11-04 18:04:26 +00:00
update_version ( ) ;
const bool ok = precheck_modules ( ) > 0 ;
if ( ! ok )
1997-12-04 14:07:49 +00:00
error_box ( " Non e' stato trovato nessun modulo da installare \n "
" in %s " , ( const char * ) path ) ;
1998-08-21 10:58:38 +00:00
1997-10-30 15:13:59 +00:00
return ok ;
}
1997-12-15 15:11:40 +00:00
bool TInstaller_mask : : do_process ( TToken_string & commands ) const
1998-08-25 17:46:29 +00:00
{
1997-10-30 15:13:59 +00:00
bool ok = TRUE ;
TFilename cmd ;
for ( const char * c = commands . get ( 0 ) ; c & & ok ; c = commands . get ( ) )
{
cmd = c ;
if ( ! cmd . blank ( ) )
{
TWait_cursor hourglass ;
TExternal_app app ( cmd ) ;
ok = app . run ( ) = = 0 ;
}
}
return ok ;
}
bool TInstaller_mask : : pre_process ( TInstall_ini & ini , const char * module ) const
1998-08-25 17:46:29 +00:00
{
1997-12-17 13:40:59 +00:00
TAuto_token_string commands ( ini . get ( " PreProcess " , module ) ) ;
bool ok = do_process ( commands ) ;
1997-11-06 10:05:56 +00:00
return ok ;
1997-10-30 15:13:59 +00:00
}
bool TInstaller_mask : : post_process ( TInstall_ini & ini , const char * module ) const
{
TAuto_token_string commands ( ini . get ( " PostProcess " , module ) ) ;
return do_process ( commands ) ;
}
1997-12-15 15:11:40 +00:00
bool TInstaller_mask : : can_install ( const char * module , TInstall_ini & ini )
{
TInstall_ini curini ;
if ( curini . demo ( ) ! = ini . demo ( ) )
{
TString msg ;
msg < < " Attenzione: Non e' possibile installare la versione " ;
msg < < ( ini . demo ( ) ? " dimostrativa " : " normale " ) ;
msg < < " nella cartella della versione " ;
msg < < ( curini . demo ( ) ? " dimostrativa " : " normale " ) ;
return error_box ( msg ) ;
}
const TString & version = ini . version ( module ) ;
1997-12-17 13:40:59 +00:00
const word year = version2year ( version ) ;
1997-12-15 15:11:40 +00:00
if ( year < 1997 )
return error_box ( " Il modulo '%s' non ha una versione valida. " , module ) ;
1998-08-25 17:46:29 +00:00
1998-02-09 12:06:44 +00:00
# ifndef _DEMO_
1997-12-17 13:40:59 +00:00
if ( year > _year_assist )
return error_box ( " Per installare la versione %s del modulo '%s' \n "
" occorre il contratto di assistenza per l'anno %d. " ,
( const char * ) version , module , year ) ;
1998-02-09 12:06:44 +00:00
# endif
1998-08-25 17:46:29 +00:00
1997-12-15 15:11:40 +00:00
TAuto_token_string altri ( ini . get ( " Moduli " , module ) ) ;
if ( stricmp ( module , " ba " ) ! = 0 & & altri . get_pos ( " ba " ) < 0 )
altri . add ( " ba " ) ; // La base e' obbligatoria per tutti
1998-08-25 17:46:29 +00:00
1997-12-15 15:11:40 +00:00
bool ok = TRUE ;
TString submodule ;
for ( const char * mod = altri . get ( 0 ) ; mod & & ok ; mod = altri . get ( ) )
{
submodule = mod ;
if ( submodule . len ( ) = = 2 )
{
if ( curini . get ( " Versione " , submodule ) . empty ( ) )
1998-08-25 17:46:29 +00:00
{
1997-12-15 15:11:40 +00:00
TString msg ;
1997-12-17 13:40:59 +00:00
msg < < " L'installazione del modulo ' " < < module
< < " ' \n richiede la presenza del modulo ' " < < submodule
< < " ': \n Si desidera procedere alla sua installazione? " ;
1998-08-25 17:46:29 +00:00
ok = yesno_box ( msg ) ;
1997-12-15 15:11:40 +00:00
if ( ok )
1998-01-22 11:56:14 +00:00
ok = install ( submodule , 0 ) ;
1997-12-15 15:11:40 +00:00
}
1998-08-25 17:46:29 +00:00
}
}
return ok ;
1997-12-15 15:11:40 +00:00
}
1998-01-29 13:42:30 +00:00
// sposta il file dal direttorio temporaneo a quello passato come destinazione
1998-02-18 13:46:52 +00:00
// from: direttorio di partenza
// file: nome del file con path completo da spostare (pu<70> includere sottodirettori)
// todir: direttorio destinazione (si assume che esista gi<67> )
bool TInstaller_mask : : move_file ( const TFilename & from , const TFilename & file , const char * todir ) const
1997-12-15 15:11:40 +00:00
{
1998-02-18 13:46:52 +00:00
TFilename dest ( todir ) ;
1998-11-04 18:04:26 +00:00
const char * fname = file . mid ( from . len ( ) + 1 ) ;
2001-04-30 14:22:43 +00:00
if ( stricmp ( fname , " ba0.exe " ) = = 0 )
1998-11-04 18:04:26 +00:00
dest . add ( " BA0.EX_ " ) ;
2001-04-30 14:22:43 +00:00
else if ( stricmp ( fname , " ba1.exe " ) = = 0 )
1998-11-04 18:04:26 +00:00
dest . add ( " BA1.EX_ " ) ;
else
dest . add ( fname ) ;
if ( ! dest . exist ( ) )
1998-02-18 13:46:52 +00:00
{
TToken_string dirs ( ( const char * ) ( dest . path ( ) ) , ' \\ ' ) ;
1998-11-04 18:04:26 +00:00
// file contains non existent subdir specification ?
1998-02-18 13:46:52 +00:00
TFilename subdir ;
1999-07-16 14:59:11 +00:00
for ( int c = 0 ; c < dirs . items ( ) - 1 ; c + + )
1998-02-18 13:46:52 +00:00
{
subdir . add ( dirs . get ( c ) ) ;
1998-11-04 18:04:26 +00:00
if ( subdir . right ( 1 ) = = " : " )
subdir < < ' \\ ' ;
if ( ! subdir . exist ( ) )
1998-02-18 13:46:52 +00:00
// build destination directory
make_dir ( subdir ) ;
1998-08-25 17:46:29 +00:00
}
}
1997-12-15 15:11:40 +00:00
const long filesize = fsize ( file ) ;
1998-08-25 17:46:29 +00:00
1997-12-15 15:11:40 +00:00
bool space_ok = FALSE ;
while ( ! space_ok )
1999-04-06 15:34:39 +00:00
{
/*
1997-12-15 15:11:40 +00:00
int disk = 0 ;
if ( dest [ 1 ] = = ' : ' )
{
const char letter = toupper ( dest [ 0 ] ) ;
disk = ' A ' - letter + 1 ;
1999-04-06 15:34:39 +00:00
}
struct _diskfree_t drive ;
_dos_getdiskfree ( disk , & drive ) ;
1998-02-24 10:30:04 +00:00
1999-04-06 15:34:39 +00:00
const unsigned requested_clusters = unsigned ( filesize / drive . sectors_per_cluster / drive . bytes_per_sector ) + 1 ;
space_ok = requested_clusters < = drive . avail_clusters ;
*/
space_ok = os_test_disk_free_space ( dest , filesize ) ;
1997-12-15 15:11:40 +00:00
if ( ! space_ok )
{
TString msg ;
1998-08-21 10:58:38 +00:00
msg < < " Lo spazio su disco e' insufficiente: \n " ;
if ( : : os_is_removable_drive ( todir ) )
1997-12-15 15:11:40 +00:00
{
1998-08-21 10:58:38 +00:00
msg < < " Inserire un nuovo disco e ritentare? " ;
1997-12-15 15:11:40 +00:00
if ( ! yesno_box ( msg ) )
return FALSE ;
}
else
1999-04-06 15:34:39 +00:00
return error_box ( msg ) ;
}
}
1997-12-15 15:11:40 +00:00
bool write_ok = TRUE ;
1998-01-29 13:42:30 +00:00
bool user_retry = FALSE ;
1997-12-15 15:11:40 +00:00
do
{
write_ok = : : fcopy ( file , dest ) ;
1998-08-25 17:46:29 +00:00
if ( write_ok )
: : remove ( file ) ;
1997-12-15 15:11:40 +00:00
else
1998-01-29 13:42:30 +00:00
user_retry = yesno_box ( " Errore di copia del file %s. \n Si desidera ritentare? " ,
( const char * ) file ) ;
} while ( ! write_ok & & user_retry ) ;
1998-08-25 17:46:29 +00:00
1998-11-04 18:04:26 +00:00
if ( write_ok & & strcmp ( dest . ext ( ) , " men " ) = = 0 )
( ( TInstaller_mask * ) this ) - > _reboot_program = NEW_MENU ;
1997-12-15 15:11:40 +00:00
return write_ok ;
}
bool TInstaller_mask : : move_module ( const TString & module , TInstall_ini & ini , bool update ) const
1998-08-25 17:46:29 +00:00
{
1997-12-15 15:11:40 +00:00
bool ok = TRUE ;
1998-08-25 17:46:29 +00:00
1997-12-17 13:40:59 +00:00
TFilename src ; src . tempdir ( ) ;
1998-08-21 10:58:38 +00:00
const TString & dst = get ( F_CURPATH ) ;
1998-11-04 18:04:26 +00:00
const TFilename tempdir ( src ) ;
1997-12-15 15:11:40 +00:00
TString_array list ;
ini . build_list ( module , list ) ;
FOR_EACH_ARRAY_ROW ( list , f , file )
{
1997-12-17 13:40:59 +00:00
src = tempdir ;
1997-12-15 15:11:40 +00:00
src . add ( file - > get ( 0 ) ) ;
if ( update )
{
1998-08-21 10:58:38 +00:00
const bool move_ok = move_file ( tempdir , src , dst ) ;
1997-12-15 15:11:40 +00:00
if ( ! move_ok )
ok = update = FALSE ;
}
1998-08-25 17:46:29 +00:00
if ( ! update )
1997-12-15 15:11:40 +00:00
: : remove ( src ) ;
}
return ok ;
}
1998-08-25 17:46:29 +00:00
KEY TInstaller_mask : : askdisk ( TString & path , TFilename & cmdline , int d , int dischi , const char * modulo )
{
TMask retry_mask ( " Inserimento dischi " , 1 , 80 , 10 ) ;
retry_mask . add_static ( ( F_PATH = = 101 ? 102 : 101 ) , 0 ,
format ( " Inserire il disco %d di %d del modulo'%s' nell' unit<69> indicata " , d , dischi , modulo )
, 2 , 2 ) ;
retry_mask . add_static ( F_PATH + 3 , 0 , " oppure indicare un percorso diverso " , 2 , 3 ) ;
retry_mask . add_string ( F_PATH , 0 , " " , 2 , 5 , 48 ) ;
retry_mask . add_button ( DLG_OK , 0 , " Riprova " , - 12 , 7 , 9 , 2 ) ;
retry_mask . add_button ( DLG_QUIT , 0 , " " , - 22 , 7 , 9 , 2 ) ;
retry_mask . set ( F_PATH , path ) ;
KEY k ;
do {
if ( ( k = retry_mask . run ( ) ) = = K_QUIT )
break ;
if ( ! retry_mask . get ( F_PATH ) . blank ( ) )
{
if ( fexist ( retry_mask . get ( F_PATH ) ) )
{
TString16 tmpname ( cmdline . name ( ) ) ;
cmdline = path = retry_mask . get ( F_PATH ) ;
cmdline . add ( tmpname ) ;
break ;
}
else
error_box ( " Il percorso indicato non e' valido " ) ;
}
} while ( TRUE ) ;
return k ;
}
1998-01-23 14:55:34 +00:00
bool TInstaller_mask : : install ( const TString & module , int patchlevel )
1998-11-04 18:04:26 +00:00
{
1999-07-16 14:59:11 +00:00
bool cancelled = FALSE ;
1997-10-30 15:13:59 +00:00
bool ok = FALSE ;
1998-11-04 18:04:26 +00:00
TString msg ; // stringa per i messaggi
1998-04-30 14:38:35 +00:00
TString16 lastrelease ; // release che sto installando
int lastpatch = patchlevel ; // patchlevel che sto installando
1998-11-04 18:04:26 +00:00
TFilename path ;
1998-08-21 10:58:38 +00:00
TString http_server ;
TFilename http_path ;
1998-11-04 18:04:26 +00:00
const bool internet = get_internet_path ( path ) ;
1998-08-21 10:58:38 +00:00
if ( internet )
1998-11-04 18:04:26 +00:00
parse_internet_path ( http_server , http_path ) ;
1998-08-21 10:58:38 +00:00
1998-08-25 17:46:29 +00:00
const bool is_a_patch = ( patchlevel > 0 ) ;
1997-10-30 15:13:59 +00:00
TFilename ininame = path ;
ininame . add ( module ) ;
1998-08-25 17:46:29 +00:00
if ( is_a_patch )
1998-01-22 11:56:14 +00:00
{
1998-08-25 17:46:29 +00:00
TString16 name ;
1998-01-23 14:55:34 +00:00
name . format ( " %04da.ini " , patchlevel ) ;
1998-01-22 11:56:14 +00:00
ininame < < name ;
}
else
ininame < < " inst.ini " ;
1998-08-21 10:58:38 +00:00
if ( internet & & ! ininame . exist ( ) )
{
TFilename remote = ininame . name ( ) ;
remote . insert ( http_path , 0 ) ;
http_get ( http_server , remote , ininame ) ;
}
1998-11-04 18:04:26 +00:00
1998-08-21 10:58:38 +00:00
if ( ininame . exist ( ) )
1997-10-30 15:13:59 +00:00
{
1998-11-04 18:04:26 +00:00
// esiste un particolare .ini con formato XXinst.ini (moduli) o con XX9999a.ini (patch)
// (installazione da directory con .zip)
TInstall_ini * ini ;
ini = new TInstall_ini ( ininame ) ;
1998-06-10 16:38:58 +00:00
ini - > write_protect ( ) ;
lastpatch = ini - > get_int ( " Patch " , module ) ;
lastrelease = ini - > get ( " Versione " , module ) ;
if ( ! can_install ( module , * ini ) )
1998-08-25 17:46:29 +00:00
{
delete ini ;
1997-12-15 15:11:40 +00:00
return FALSE ;
1998-08-25 17:46:29 +00:00
}
1998-06-10 16:38:58 +00:00
const int dischi = ini - > get_int ( " Dischi " , module ) ;
1997-10-30 15:13:59 +00:00
ok = dischi > 0 ;
1997-11-06 10:05:56 +00:00
if ( ! ok )
{
1998-02-18 13:46:52 +00:00
return error_box ( " Impossibile determinare il numero dei dischetti in %s " , ininame . name ( ) ) ;
1997-11-06 10:05:56 +00:00
}
else
{
1998-06-10 16:38:58 +00:00
if ( patchlevel = = 0 )
ok = pre_process ( * ini , module ) ;
1998-08-25 17:46:29 +00:00
if ( ! ok )
{
delete ini ;
return FALSE ;
}
1997-11-06 10:05:56 +00:00
}
1998-11-04 18:04:26 +00:00
// ***************
// decompressione
msg = " Decompressione " ;
if ( is_a_patch )
1998-02-18 13:46:52 +00:00
msg < < " della patch " < < patchlevel ;
msg < < " del modulo ' " < < module < < " ' in corso... " ;
1998-01-23 14:55:34 +00:00
TProgind pi ( dischi , msg , FALSE , TRUE ) ;
1997-12-15 15:11:40 +00:00
TFilename tempdir ; tempdir . tempdir ( ) ;
1998-08-25 17:46:29 +00:00
1997-10-30 15:13:59 +00:00
TFilename cmdline ;
for ( int d = 1 ; d < = dischi & & ok ; d + + )
{
1997-11-06 10:05:56 +00:00
cmdline = path ;
1998-08-25 17:46:29 +00:00
cmdline . add ( module ) ;
1998-01-23 14:55:34 +00:00
if ( patchlevel > 0 )
{
1998-08-25 17:46:29 +00:00
TString16 name ;
1998-01-23 14:55:34 +00:00
name . format ( " %04da " , patchlevel ) ;
cmdline < < name ;
}
else
cmdline < < " inst " ;
cmdline < < d < < " .zip " ;
1998-08-21 10:58:38 +00:00
if ( internet & & ! cmdline . exist ( ) )
{
TFilename remote = cmdline . name ( ) ;
remote . insert ( http_path , 0 ) ;
http_get ( http_server , remote , cmdline ) ;
}
1998-08-25 17:46:29 +00:00
1998-01-23 14:55:34 +00:00
ok = cmdline . exist ( ) ;
1997-10-30 15:13:59 +00:00
while ( ! ok )
{
1998-08-25 17:46:29 +00:00
if ( askdisk ( path , cmdline , d , dischi , ( const char * ) ini - > get ( " Descrizione " ) ) = = K_QUIT )
break ;
ok = fexist ( cmdline ) ;
1997-10-30 15:13:59 +00:00
if ( ! ok )
1998-08-25 17:46:29 +00:00
message_box ( " Impossibile trovare %s \n " , ( const char * ) cmdline ) ;
1997-10-30 15:13:59 +00:00
}
1998-08-25 17:46:29 +00:00
1997-10-30 15:13:59 +00:00
if ( ok )
{
1997-12-15 15:11:40 +00:00
const long required = fsize ( cmdline ) * ( dischi - d + 1 ) * 4 ;
1999-04-06 15:34:39 +00:00
if ( ! os_test_disk_free_space ( tempdir , required ) )
1997-10-30 15:13:59 +00:00
{
ok = yesno_box ( " Lo spazio su disco potrebbe essere insufficiente: \n "
" Si desidera continuare ugualmente? " ) ;
}
}
1998-08-25 17:46:29 +00:00
1997-10-30 15:13:59 +00:00
if ( ok )
1998-08-25 17:46:29 +00:00
{
1997-10-30 15:13:59 +00:00
TWait_cursor hourglass ;
cmdline . insert ( " unzip.pif -o " , 0 ) ;
1997-12-17 13:40:59 +00:00
cmdline < < " -d " < < tempdir ;
1998-08-25 17:46:29 +00:00
1997-10-30 15:13:59 +00:00
TExternal_app app ( cmdline ) ;
ok = app . run ( FALSE , FALSE , FALSE , FALSE ) = = 0 ;
pi . addstatus ( 1 ) ;
1998-08-25 17:46:29 +00:00
}
}
// ***************
// trasferimento
1997-10-30 15:13:59 +00:00
if ( ok )
1998-08-25 17:46:29 +00:00
{
// si assicura che sia leggibile il .ini del primo disco
do {
cmdline = path ;
cmdline . add ( ininame . name ( ) ) ;
ok = fexist ( cmdline ) ;
if ( ! ok )
{
if ( askdisk ( path , cmdline , 1 , dischi , ( const char * ) ini - > get ( " Descrizione " ) ) = = K_QUIT )
break ;
ok = fexist ( cmdline ) ;
if ( ! ok )
message_box ( " Impossibile trovare %s \n " , ( const char * ) cmdline ) ;
else
{
delete ini ;
ini = new TInstall_ini ( cmdline ) ;
}
}
} while ( ! ok ) ;
if ( ok )
1997-12-15 15:11:40 +00:00
{
1998-08-25 17:46:29 +00:00
msg . cut ( 0 ) ;
msg < < " Aggiornamento del modulo ' " < < module < < " ' in corso... " ;
pi . set_text ( msg ) ;
ok = move_module ( module , * ini , TRUE ) ;
TAuto_token_string altri ( ini - > get ( " Moduli " , module ) ) ;
FOR_EACH_TOKEN ( altri , mod )
{
1998-11-04 18:04:26 +00:00
TAuto_token_string altri ( ini - > get ( " Moduli " , module ) ) ;
FOR_EACH_TOKEN ( altri , mod )
1997-12-15 15:11:40 +00:00
{
1998-11-04 18:04:26 +00:00
const TString16 submod = mod ;
if ( submod . len ( ) > 2 ) // sposta sottomoduli esterni
1998-08-25 17:46:29 +00:00
{
1998-11-04 18:04:26 +00:00
bool upd = ok ;
if ( ok )
{
TInstall_ini curini ;
const TString16 curver = curini . version ( submod ) ;
const int curpatch = curini . patch ( submod ) ;
const TString16 reqver = ini - > version ( submod ) ;
const int reqpatch = ini - > patch ( submod ) ;
int distance = compare_version ( reqver , reqpatch , curver , curpatch ) ;
upd = distance > 0 ;
}
ok & = move_module ( submod , * ini , upd ) ;
if ( upd & & ok ) // marca sull'install.ini di destinazione l'avvenuta installazione del sottomodulo "esterno"
ini - > export_paragraph ( submod , ini - > default_name ( ) , ! is_a_patch ) ;
1998-08-25 17:46:29 +00:00
}
}
}
1997-12-15 15:11:40 +00:00
}
1998-06-10 16:38:58 +00:00
}
1998-08-25 17:46:29 +00:00
if ( ok ) // marca sull'install.ini di destinazione l'avvenuta installazione del modulo
ini - > export_module_paragraphs ( module , ini - > default_name ( ) , ! is_a_patch ) ;
} // installazione da directory con zip
1997-10-30 15:13:59 +00:00
else
1998-08-25 17:46:29 +00:00
if ( ! is_a_patch )
1997-10-30 15:13:59 +00:00
{
1998-08-25 17:46:29 +00:00
//
// non c'e' il .ini del modulo ma un unico "install.ini"
// (installazione da directory con eseguibili)
ininame = path ;
ininame . add ( TInstall_ini : : default_name ( ) ) ;
ok = fexist ( ininame ) ;
if ( ok )
1997-10-30 15:13:59 +00:00
{
1998-08-25 17:46:29 +00:00
TInstall_ini ini ( ininame ) ;
ini . write_protect ( ) ;
lastpatch = ini . get_int ( " Patch " , module ) ;
lastrelease = ini . get ( " Versione " , module ) ;
if ( ! can_install ( module , ini ) )
return FALSE ;
TString_array list ;
const int files = ini . build_complete_list ( module , list ) ;
if ( files > 0 )
1997-10-30 15:13:59 +00:00
{
1998-08-25 17:46:29 +00:00
if ( patchlevel = = 0 )
ok = pre_process ( ini , module ) ;
if ( ok )
1997-11-06 10:05:56 +00:00
{
1998-11-04 18:04:26 +00:00
msg . cut ( 0 ) ;
1999-07-16 14:59:11 +00:00
msg < < " Copia del modulo ' " < < module < < " ' in corso ... " ;
TProgind pi ( files , msg , TRUE , TRUE ) ;
1998-08-25 17:46:29 +00:00
TFilename src , dst ;
for ( int f = 0 ; f < files & & ok ; f + + )
{
pi . addstatus ( 1 ) ;
dst = list . row ( f ) . get ( 0 ) ;
1998-11-04 18:04:26 +00:00
dst . lower ( ) ;
1998-08-25 17:46:29 +00:00
src = path ;
src . add ( dst ) ;
1998-11-04 18:04:26 +00:00
if ( dst = = " ba1.exe " )
dst = " ba1.ex_ " ;
if ( dst = = " ba0.exe " )
dst = " ba0.ex_ " ;
1998-08-25 17:46:29 +00:00
ok = fcopy ( src , dst ) ;
1999-07-16 14:59:11 +00:00
cancelled = pi . iscancelled ( ) ;
1998-08-25 17:46:29 +00:00
}
1999-07-16 14:59:11 +00:00
ok & = ! cancelled ;
1997-11-06 10:05:56 +00:00
}
1997-10-30 15:13:59 +00:00
1998-08-25 17:46:29 +00:00
if ( ok ) // marca sull'install.ini di destinazione l'avvenuta installazione del modulo
ini . export_module_paragraphs ( module , ini . default_name ( ) , TRUE ) ;
} // controllo esistenza lista di file non vuota per questo modulo
} // controllo esistenza install.ini
} // fine installazione da directory con eseguibili
1997-10-30 15:13:59 +00:00
if ( ok )
1998-08-25 17:46:29 +00:00
{
{
1998-08-21 10:58:38 +00:00
TInstall_ini ini ;
ini . set ( " DiskPath " , get ( F_PATH ) ) ;
ini . set ( " Data " , TDate ( TODAY ) , module ) ;
ini . update_prices ( ininame ) ;
1998-04-30 14:38:35 +00:00
}
// Non togliere le parentesi graffe soprastanti per permettere l'aggiornamento fisico del .ini (CON LA CHIAMATA DEL DISTRUTTORE)
1998-08-25 17:46:29 +00:00
update_version ( ) ;
1997-10-30 15:13:59 +00:00
}
1998-04-30 14:38:35 +00:00
1998-08-25 17:46:29 +00:00
if ( ok & & patchlevel = = 0 ) // Se installo un modulo pricipale ...
1998-04-30 14:38:35 +00:00
{
// ... installo DOPO tutte le patches successive
install_patches ( module , lastrelease , lastpatch ) ;
1998-08-25 17:46:29 +00:00
TInstall_ini ini ;
ok & = post_process ( ini , module ) ;
1998-04-30 14:38:35 +00:00
}
1997-11-06 10:05:56 +00:00
1997-10-30 15:13:59 +00:00
return ok ;
}
1998-04-30 14:38:35 +00:00
1998-11-04 18:04:26 +00:00
bool TInstaller_mask : : get_internet_path ( TFilename & ininame )
1998-04-30 14:38:35 +00:00
{
1998-11-04 18:04:26 +00:00
ininame = get ( F_PATH ) ;
1998-08-21 10:58:38 +00:00
if ( is_internet_path ( ininame ) )
{
ininame . tempdir ( ) ;
ininame . add ( " www " ) ;
1998-11-04 18:04:26 +00:00
return TRUE ;
}
return FALSE ;
}
void TInstaller_mask : : parse_internet_path ( TString & http_server , TFilename & http_path )
{
http_server = get ( F_PATH ) ;
if ( http_server . compare ( " http:// " , 7 , TRUE ) = = 0 )
http_server . ltrim ( 7 ) ;
const int slash = http_server . find ( ' / ' ) ;
if ( slash > 0 )
{
2001-04-30 14:22:43 +00:00
http_path = http_server . mid ( slash ) ;
if ( http_path . right ( 1 ) ! = " / " )
http_path < < ' / ' ;
http_server . cut ( slash ) ;
1998-08-21 10:58:38 +00:00
}
1998-11-04 18:04:26 +00:00
else
http_path = http_default_path ;
}
bool TInstaller_mask : : install_patches ( const TString & module , const TString & lastrelease , int lastpatch , bool only_newer )
{
bool ok = TRUE ;
TString_array modules ;
TFilename ininame ;
get_internet_path ( ininame ) ;
1998-08-21 10:58:38 +00:00
1998-04-30 14:38:35 +00:00
ininame . add ( module ) ;
ininame < < " 0???a.ini " ;
modules . destroy ( ) ;
list_files ( ininame , modules ) ;
modules . sort ( ) ; // sort by patch number
FOR_EACH_ARRAY_ROW ( modules , am , arow )
1998-08-25 17:46:29 +00:00
{
1998-04-30 14:38:35 +00:00
TString & ininame = * arow ;
ininame . lower ( ) ;
const int pos = ininame . find ( " a.ini " ) ;
CHECKS ( pos > = 6 , " Invalid installation configuration: " , ( const char * ) ininame ) ;
const TString16 patchmodule = ininame . mid ( pos - 6 , 2 ) ;
TConfig ini ( ininame , patchmodule ) ;
const int patchlevel = ini . get_int ( " Patch " ) ;
const char * patchversion = ini . get ( " Versione " ) ;
1998-11-04 18:04:26 +00:00
if ( ok & & lastrelease = = patchversion // installa solo le patch della stessa ver..
& & ( only_newer ? lastpatch < patchlevel : lastpatch < = patchlevel ) ) // ... e patch superiore o uguale (reinstalla l'ultima patch)
1998-04-30 14:38:35 +00:00
ok = install ( module , patchlevel ) ;
}
return ok ;
}
1998-08-25 17:46:29 +00:00
bool TInstaller_mask : : update_handler ( TMask_field & f , KEY k )
{
if ( k = = K_SPACE )
{
TInstaller_mask & m = ( TInstaller_mask & ) f . mask ( ) ;
m . autoload ( ) ;
}
return TRUE ;
}
1997-10-30 15:13:59 +00:00
bool TInstaller_mask : : path_handler ( TMask_field & fld , KEY key )
1998-08-25 17:46:29 +00:00
{
1997-10-30 15:13:59 +00:00
bool ok = TRUE ;
if ( key = = K_TAB & & fld . focusdirty ( ) )
{
1998-01-23 14:55:34 +00:00
TFilename path = fld . get ( ) ;
1998-08-21 10:58:38 +00:00
if ( path . not_empty ( ) )
1997-10-30 15:13:59 +00:00
{
1998-08-21 10:58:38 +00:00
if ( path . len ( ) = = 2 & & isalpha ( path [ 0 ] ) & & path [ 1 ] = = ' : ' )
{
path < < SLASH ;
fld . set ( path ) ;
1998-11-04 18:04:26 +00:00
}
1998-08-21 10:58:38 +00:00
if ( path . exist ( ) | | : : is_internet_path ( path ) )
_curr_mask - > autoload ( ) ;
else
ok = fld . error_box ( " Specificare un percorso valido " ) ;
}
1998-11-04 18:04:26 +00:00
}
return ok ;
}
1997-10-30 15:13:59 +00:00
1997-12-04 14:07:49 +00:00
void TInstaller_mask : : install_selection ( )
{
TString_array & arr = rows_array ( ) ;
FOR_EACH_ARRAY_ROW ( arr , r , row ) if ( checked ( r ) )
{
1999-04-06 15:34:39 +00:00
1998-02-18 13:46:52 +00:00
const TString newver = row - > get ( C_RELEASE ) ;
1998-08-25 17:46:29 +00:00
1998-02-09 12:06:44 +00:00
if ( newver . blank ( ) )
{
check ( r , FALSE ) ;
continue ;
}
1998-02-18 13:46:52 +00:00
const TString modulo = row - > get ( C_CODE ) ;
const int newpatch = row - > get_int ( C_PATCH ) ;
const TString oldver = row - > get ( C_CURRRELEASE ) ;
const int oldpatch = row - > get_int ( C_CURRPATCH ) ;
1998-08-25 17:46:29 +00:00
2001-06-25 10:41:20 +00:00
if ( version2year ( newver ) < 1998 )
1997-12-15 15:11:40 +00:00
{
error_box ( " Il modulo '%s' non ha una versione valida. " , ( const char * ) modulo ) ;
continue ;
}
1998-08-25 17:46:29 +00:00
1997-12-04 14:07:49 +00:00
bool ok = TRUE ;
1998-11-04 18:04:26 +00:00
bool is_patch = row - > get_char ( C_ISPATCH ) = = ' X ' ;
bool has_patch = row - > get_char ( C_ISPATCH ) = = ' + ' ;
1998-01-22 11:56:14 +00:00
const int cmp = compare_version ( oldver , oldpatch , newver , newpatch ) ;
1997-10-30 15:13:59 +00:00
if ( cmp = = 0 )
1998-08-21 10:58:38 +00:00
ok = noyes_box ( " Si desidera reinstallare la versione %s.%d del modulo '%s' ? " , ( const char * ) newver , newpatch , ( const char * ) modulo ) ;
1998-08-25 17:46:29 +00:00
if ( ! is_patch & & cmp > 0 )
1998-01-29 13:42:30 +00:00
{
TString256 msg ;
msg . format ( " Si desidera ritornare alla versione %s.%d del modulo '%s' ? \n "
1997-10-30 15:13:59 +00:00
" Attenzione: non e' garantito il corretto \n "
1998-01-29 13:42:30 +00:00
" funzionamento di tutti i programmi! " , ( const char * ) newver , newpatch , ( const char * ) modulo ) ;
ok = noyes_box ( msg ) ;
}
1999-04-06 15:34:39 +00:00
if ( ok & & is_patch )
1998-02-18 13:46:52 +00:00
{
// installo le patch solo se esiste gi<67> un modulo installato della stessa versione
if ( ! oldver . blank ( ) )
1999-04-06 15:34:39 +00:00
{
1998-02-18 13:46:52 +00:00
if ( oldver ! = newver )
1998-08-25 17:46:29 +00:00
ok = error_box ( " Il modulo '%s' installato ha versione %s: \n impossibile installare le patch della versione %s " , ( const char * ) modulo , ( const char * ) oldver , ( const char * ) newver ) ;
} else
ok = FALSE ; //error_box("Impossibile installare le patch perche' il modulo '%s' non e' installato",(const char *)modulo);
1998-02-18 13:46:52 +00:00
}
1997-10-30 15:13:59 +00:00
if ( ok )
1998-08-25 17:46:29 +00:00
{
1998-11-04 18:04:26 +00:00
if ( has_patch )
1998-08-21 10:58:38 +00:00
{
1998-11-04 18:04:26 +00:00
if ( newver = = oldver & & newpatch > = oldpatch & &
! noyes_box ( " Si desidera reinstallare l'intero modulo '%s'? \n "
" Rispondendo NO verranno installate le sole patch " , ( const char * ) modulo ) )
1998-08-21 10:58:38 +00:00
{
1998-08-25 17:46:29 +00:00
is_patch = TRUE ;
}
1998-08-21 10:58:38 +00:00
}
1998-08-25 17:46:29 +00:00
1998-04-30 14:38:35 +00:00
if ( is_patch )
1998-01-23 14:55:34 +00:00
{
1998-11-04 18:04:26 +00:00
ok = install_patches ( modulo , oldver , oldpatch , FALSE ) ; // installa l'ultima patch
1998-08-25 17:46:29 +00:00
if ( ! ok )
message_box ( " Impossibile installare le patch del modulo '%s' " , ( const char * ) modulo ) ;
1998-01-23 14:55:34 +00:00
}
1998-04-30 14:38:35 +00:00
else
ok = install ( modulo , 0 ) ; // installa il modulo
if ( ok )
_installed = TRUE ; // Setta il flag di almeno un modulo installato
1998-02-09 12:06:44 +00:00
if ( ok )
1998-08-25 17:46:29 +00:00
check ( r , FALSE ) ;
}
1998-11-04 18:04:26 +00:00
else
check ( r , FALSE ) ; // uncheck
1997-10-30 15:13:59 +00:00
}
1998-11-04 18:04:26 +00:00
if ( installed ( ) )
message_box ( " Installazione conclusa " ) ;
1997-12-04 14:07:49 +00:00
}
bool TInstaller_mask : : install_handler ( TMask_field & fld , KEY key )
1998-08-25 17:46:29 +00:00
{
1997-12-04 14:07:49 +00:00
if ( key = = K_SPACE )
1998-08-25 17:46:29 +00:00
{
1997-12-17 13:40:59 +00:00
if ( _curr_mask - > items ( ) = = 1 )
_curr_mask - > check ( 0 ) ;
1999-07-16 14:59:11 +00:00
const bool check_on = _curr_mask - > check_enabled ( ) ;
_curr_mask - > enable_check ( TRUE ) ;
const bool some = _curr_mask - > one_checked ( ) ;
_curr_mask - > enable_check ( check_on ) ;
if ( some )
1997-12-04 14:07:49 +00:00
_curr_mask - > install_selection ( ) ;
else
1998-08-25 17:46:29 +00:00
error_box ( " Selezionare uno piu' moduli da installare. " ) ;
1997-12-04 14:07:49 +00:00
}
return TRUE ;
}
1998-11-04 18:04:26 +00:00
bool TInstaller_mask : : quit_handler ( TMask_field & f , KEY k )
1998-02-09 12:06:44 +00:00
{
if ( k = = K_SPACE )
1998-08-25 17:46:29 +00:00
{
1998-11-04 18:04:26 +00:00
TInstaller_mask & m = ( TInstaller_mask & ) f . mask ( ) ;
1999-07-16 14:59:11 +00:00
const bool check_on = _curr_mask - > check_enabled ( ) ;
_curr_mask - > enable_check ( TRUE ) ;
const bool some = _curr_mask - > one_checked ( ) ;
_curr_mask - > enable_check ( check_on ) ;
if ( some )
2001-04-30 14:22:43 +00:00
return noyes_box ( " Alcuni moduli sono selezionati per l'installazione. \n Confermare l'uscita " ) ;
1998-02-09 12:06:44 +00:00
}
return TRUE ;
}
1998-11-04 18:04:26 +00:00
bool TInstaller_mask : : tutti_handler ( TMask_field & f , KEY k )
1998-08-21 10:58:38 +00:00
{
if ( k = = K_SPACE )
{
1998-11-04 18:04:26 +00:00
TInstaller_mask & m = ( TInstaller_mask & ) f . mask ( ) ;
if ( m . check_enabled ( ) )
{
if ( m . one_checked ( ) )
m . uncheck ( - 1 ) ;
else
m . precheck_modules ( FALSE ) ;
}
1998-08-21 10:58:38 +00:00
}
return TRUE ;
}
1997-12-04 14:07:49 +00:00
bool TInstaller_mask : : on_key ( KEY key )
1998-08-25 17:46:29 +00:00
{
1997-12-04 14:07:49 +00:00
bool ok = TRUE ;
1998-08-25 17:46:29 +00:00
switch ( key )
1998-08-21 10:58:38 +00:00
{
1998-08-25 17:46:29 +00:00
case K_F7 : autoload ( ) ; break ;
case K_F8 : field ( DLG_USER ) . on_hit ( ) ; break ;
default : ok = TArray_sheet : : on_key ( key ) ; break ;
1998-08-21 10:58:38 +00:00
}
1998-08-25 17:46:29 +00:00
return ok ;
1997-10-30 15:13:59 +00:00
}
TInstaller_mask : : TInstaller_mask ( )
1998-08-25 17:46:29 +00:00
: TArray_sheet ( 0 , 0 , 0 , 0 , " Installazione " ,
" @1|Modulo@30|Cod.|Versione da \n installare@11|Livello \n Patch@8|Data \n Rilascio@10|Versione \n Installata@10|Livello \n Patch@8|Data \n Installazione@13|Aggiornamento " ,
1997-12-04 14:07:49 +00:00
0x18 , 3 )
1998-08-25 17:46:29 +00:00
{
1997-12-04 14:07:49 +00:00
_curr_mask = this ;
1998-01-29 13:42:30 +00:00
_installed = FALSE ;
1998-11-04 18:04:26 +00:00
_reboot_program = NONE ;
1998-08-25 17:46:29 +00:00
1998-08-21 10:58:38 +00:00
add_string ( F_PATH , 0 , " Installa da " , 1 , 1 , 50 ) ;
add_string ( F_CURPATH , 0 , " Installa in " , 1 , 2 , 50 , " D " ) ;
1998-11-04 18:04:26 +00:00
//TMask::add_button(F_UPDATE, 0, "Rileggi", 60,1,9,1,""/*,BMP_LINK*/);
add_button ( F_UPDATE , " Rileggi " , ' \0 ' ) ;
//TMask::add_button(F_INSTALL, 0, "Installa", 60,1,9,1,""/*,BMP_LINK*/);
1997-12-04 14:07:49 +00:00
add_button ( F_INSTALL , " Installa " , ' \0 ' ) ; // NON mettere 'I'
1998-08-25 17:46:29 +00:00
1997-10-30 15:13:59 +00:00
set_handler ( F_PATH , path_handler ) ;
1997-12-04 14:07:49 +00:00
set_handler ( F_INSTALL , install_handler ) ;
1998-08-21 10:58:38 +00:00
set_handler ( F_UPDATE , update_handler ) ;
1998-11-04 18:04:26 +00:00
set_handler ( DLG_QUIT , quit_handler ) ;
1998-08-25 17:46:29 +00:00
set_handler ( DLG_USER , tutti_handler ) ;
1997-12-17 13:40:59 +00:00
TDongle dongle ; dongle . login ( ) ; dongle . logout ( ) ;
_year_assist = dongle . year_assist ( ) ;
1998-08-25 17:46:29 +00:00
1997-10-30 15:13:59 +00:00
TInstall_ini ini ;
TFilename path = ini . get ( " DiskPath " ) ;
set ( F_PATH , path ) ;
1998-08-25 17:46:29 +00:00
1999-04-06 15:34:39 +00:00
const bool floppy = os_is_removable_drive ( path ) ;
1998-08-21 10:58:38 +00:00
if ( path . not_empty ( ) & & ! floppy & & ! is_internet_path ( path ) )
1997-10-30 15:13:59 +00:00
autoload ( ) ;
1998-08-25 17:46:29 +00:00
DIRECTORY dir ;
1997-10-30 15:13:59 +00:00
xvt_fsys_get_dir ( & dir ) ;
xvt_fsys_convert_dir_to_str ( & dir , path . get_buffer ( ) , path . size ( ) ) ;
set ( F_CURPATH , path ) ;
}
1997-12-04 14:07:49 +00:00
TInstaller_mask : : ~ TInstaller_mask ( )
{
_curr_mask = NULL ;
1998-11-04 18:04:26 +00:00
TString msg ;
TFilename ba0exfile ( " ba0.ex_ " ) , ba1exfile ( " ba1.ex_ " ) ;
switch ( _reboot_program )
{
case NEW_MENU :
msg < < " sono stati aggiornati i menu' " ;
default :
if ( ba0exfile . exist ( ) )
{
if ( ! msg . blank ( ) )
msg < < " e " ;
else
msg < < " e' stato " ;
msg < < " aggiornato il navigatore dei menu' " ;
}
if ( ba1exfile . exist ( ) )
{
if ( ! msg . blank ( ) )
msg < < " e " ;
else
msg < < " e' stato " ;
msg < < " aggiornato l'installatore " ;
}
}
if ( ! msg . empty ( ) )
{
msg . insert ( " Attenzione: " ) ;
msg < < " . \n E' necessario uscire e rientrare dal programma " ;
warning_box ( msg ) ;
}
1997-12-04 14:07:49 +00:00
}
1997-10-30 15:13:59 +00:00
///////////////////////////////////////////////////////////
// Programma principale
///////////////////////////////////////////////////////////
class TInstaller : public TSkeleton_application
1998-08-25 17:46:29 +00:00
{
1997-10-30 15:13:59 +00:00
protected :
1999-07-16 14:59:11 +00:00
TInstaller_mask * _m ;
protected :
virtual bool create ( ) ;
1997-10-30 15:13:59 +00:00
virtual bool use_files ( ) const { return FALSE ; }
2001-06-25 10:41:20 +00:00
virtual bool test_assistance_year ( ) const ;
1997-10-30 15:13:59 +00:00
virtual void main_loop ( ) ;
2001-06-25 10:41:20 +00:00
bool testdatabase ( ) const ;
bool testprograms ( ) const ;
1997-10-30 15:13:59 +00:00
} ;
1998-11-04 18:04:26 +00:00
bool TInstaller : : testdatabase ( ) const
{
TConfig ini ( CONFIG_INSTALL ) ;
return ini . get ( " TestDatabase " , " Main " , - 1 , " Y " ) ! = " N " ;
}
1999-07-16 14:59:11 +00:00
bool TInstaller : : testprograms ( ) const
{
TConfig ini ( CONFIG_INSTALL ) ;
char c = ini . get ( " TestPrograms " , " Main " , - 1 , " N " ) [ 0 ] ;
return c = = ' X ' | | c = = ' Y ' ;
}
2001-06-25 10:41:20 +00:00
bool TInstaller : : test_assistance_year ( ) const
{
// Per il momento lascia continuare: ci pensa poi la create
return TRUE ;
}
1999-07-16 14:59:11 +00:00
bool TInstaller : : create ( )
{
2001-06-25 10:41:20 +00:00
if ( ! TApplication : : test_assistance_year ( ) )
{
TExternal_app attivazione ( " ba1 -4 " ) ;
attivazione . run ( ) ;
dongle ( ) . login ( ) ; // Rilegge anno assistenza
}
1999-07-16 14:59:11 +00:00
if ( testprograms ( ) )
{
_m = new TInstaller_mask ( ) ;
_m - > disable_check ( ) ;
_m - > disable ( F_PATH ) ;
_m - > disable ( F_UPDATE ) ;
_m - > disable ( DLG_USER ) ;
return TSkeleton_application : : create ( ) ;
2001-06-25 10:41:20 +00:00
}
return error_box ( " L'utente %s non <20> abilitato all'uso di questo programma " , ( const char * ) user ( ) ) ;
1999-07-16 14:59:11 +00:00
}
1997-10-30 15:13:59 +00:00
void TInstaller : : main_loop ( )
1999-07-16 14:59:11 +00:00
{
_m - > run ( ) ;
if ( _m - > installed ( ) & & testdatabase ( ) ) // Almeno 1 modulo installato ?
{
// Lancia conversione: ba1 -0 -C -uPRASSI
TExternal_app conversion ( " ba1 -0 -C " ) ;
conversion . run ( ) ;
}
2001-04-30 14:22:43 +00:00
delete _m ;
_m = NULL ;
1999-07-16 14:59:11 +00:00
}
class TExtendedInstaller : public TInstaller
{
protected :
virtual bool create ( ) ;
virtual void main_loop ( ) ;
} ;
bool TExtendedInstaller : : create ( )
{
2001-06-25 10:41:20 +00:00
if ( ! TApplication : : test_assistance_year ( ) )
{
TExternal_app attivazione ( " ba1 -4 " ) ;
attivazione . run ( ) ;
dongle ( ) . login ( ) ; // Rilegge anno assistenza
}
1999-07-16 14:59:11 +00:00
_m = new TInstaller_mask ( ) ;
return TSkeleton_application : : create ( ) ;
}
void TExtendedInstaller : : main_loop ( )
1997-10-30 15:13:59 +00:00
{
2001-04-30 14:22:43 +00:00
_m - > run ( ) ;
if ( _m - > installed ( ) & & testdatabase ( ) ) // Almeno 1 modulo installato ?
1998-01-29 13:42:30 +00:00
{
// Lancia conversione: ba1 -0 -C -uPRASSI
TExternal_app conversion ( " ba1 -0 -C " ) ;
conversion . run ( ) ;
}
2001-04-30 14:22:43 +00:00
delete _m ;
_m = NULL ;
1997-10-30 15:13:59 +00:00
}
1999-07-16 14:59:11 +00:00
# define PROGNAME "Installer"
1997-10-30 15:13:59 +00:00
int ba1700 ( int argc , char * argv [ ] )
1998-08-25 17:46:29 +00:00
{
1999-07-16 14:59:11 +00:00
if ( user ( ) ! = : : dongle ( ) . administrator ( ) )
1998-08-25 17:46:29 +00:00
{
TInstaller app ;
1999-07-16 14:59:11 +00:00
app . run ( argc , argv , PROGNAME ) ;
} else {
TExtendedInstaller app ;
app . run ( argc , argv , PROGNAME ) ;
}
1997-10-30 15:13:59 +00:00
return 0 ;
}