Patch level :

Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Aggiornameto programmi via Internet


git-svn-id: svn://10.65.10.50/trunk@6972 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1998-08-21 10:58:38 +00:00
parent d2856aefe3
commit d6c69c7f57
2 changed files with 241 additions and 65 deletions

View File

@ -1,11 +1,13 @@
#include <applicat.h>
#include <colors.h>
#include <defmask.h>
#include <execp.h>
#include <isamrpc.h>
#include <os_dep.h>
#include <progind.h>
#include <sheet.h>
#include <utility.h>
#include <defmask.h>
#include "ba1.h"
#include "ba1500.h"
@ -23,6 +25,7 @@
#define C_CURRDATAREL 8
#define C_ISPATCH 9
const char* const http_default_path = "/aga/campo/";
HIDDEN int compare_version(const char* v1, int p1, const char* v2, int p2)
{
@ -63,6 +66,7 @@ class TInstaller_mask : public TArray_sheet
protected: // TSheet
virtual bool on_key(KEY key);
static bool tutti_handler(TMask_field& f, KEY k);
static bool update_handler(TMask_field& f, KEY k);
protected:
static bool path_handler(TMask_field& fld, KEY key);
@ -205,21 +209,90 @@ void TInstaller_mask::update_version()
force_update();
}
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;
}
// Cerca nel percorso specificato sulla maschera tutti i possibili files .ini
// utilizzabili per un'installazione e li inserisce nello spreadsheet
bool TInstaller_mask::autoload()
{
TString_array& mask_rows = rows_array();
const TString& path = get(F_PATH);
if (!fexist(path))
TFilename path = get(F_PATH);
TString http_server;
TFilename http_path;
TFilename ininame;
const bool internet = is_internet_path(path);
if (internet)
{
http_server = path;
if (http_server.compare("http://", 7, TRUE) == 0)
http_server.ltrim(7);
const int slash = http_server.find('/');
if (slash > 0)
{
http_path = http_server.mid(slash);
if (http_path.right(1) != "/")
http_path << '/';
http_server.cut(slash);
}
else
http_path = http_default_path;
path.tempdir();
path.add("www");
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);
FOR_EACH_ARRAY_ROW(list, i, row)
::remove(*row);
}
if (!ininame.exist())
{
TFilename remote_ini = http_path;
remote_ini << TInstall_ini::default_name();
if (!http_get(http_server, remote_ini, ininame))
return error_box("Impossibile trasferire %s da %s",
(const char*)remote_ini, (const char*)http_server);
}
}
if (fexist(path))
{
ininame = path;
ininame.add(TInstall_ini::default_name());
}
else
return error_box("Specificare un percorso valido");
TWait_cursor hourglass;
destroy();
TFilename ininame;
ininame = path;
ininame.add(TInstall_ini::default_name());
TString_array modules;
@ -255,15 +328,47 @@ bool TInstaller_mask::autoload()
const TString16 module = ininame.mid(pos-2, 2);
TConfig ini(ininame, module);
add_module(ini, module, FALSE);
}
}
}
// add patches
ininame = path;
ininame.add("??0???a.ini");
modules.destroy();
list_files(ininame, modules);
if (internet)
{
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();
}
else
{
ininame = path;
ininame.add("??0???a.ini");
list_files(ininame, modules);
}
modules.sort(); // sort to have patches in patchlevel order
FOR_EACH_ARRAY_ROW(modules, am, arow)
{
TString& ininame = *arow;
@ -286,7 +391,8 @@ bool TInstaller_mask::autoload()
mask_rows.row(r+1).add(patchlevel, C_PATCH); // aggiorna il patchlevel mostrato per il modulo
force_update(r+1);
}
} else
}
else
add_module(ini, module, TRUE);
}
@ -296,7 +402,7 @@ bool TInstaller_mask::autoload()
else
error_box("Non e' stato trovato nessun modulo da installare\n"
"in %s", (const char*)path);
return ok;
}
@ -417,19 +523,23 @@ bool TInstaller_mask::move_file(const TFilename& from, const TFilename& file, co
disk = 'A' - letter + 1;
}
space_ok = ::os_test_disk_free_space(dest, filesize);
space_ok = ::os_test_disk_free_space(todir, filesize);
if (!space_ok)
{
TString msg;
msg << "Lo spazio sull'unita' e' insufficiente";
if (::os_is_removable_drive(dest))
msg << "Lo spazio su disco e' insufficiente:\n";
if (::os_is_removable_drive(todir))
{
msg << ":\nInserire un nuovo disco e ritentare?";
msg << "Inserire un nuovo disco e ritentare?";
if (!yesno_box(msg))
return FALSE;
}
else
return error_box(msg);
{
msg << "Si desidera proseguire ugualmente?";
if (!noyes_box(msg))
return FALSE;
}
}
}
@ -454,6 +564,7 @@ bool TInstaller_mask::move_module(const TString& module, TInstall_ini& ini, bool
TFilename src; src.tempdir();
const TFilename tempdir(src);
const TString& dst = get(F_CURPATH);
TString_array list;
ini.build_list(module, list);
@ -463,7 +574,7 @@ bool TInstaller_mask::move_module(const TString& module, TInstall_ini& ini, bool
src.add(file->get(0));
if (update)
{
const bool move_ok = move_file(tempdir, src, ".");
const bool move_ok = move_file(tempdir, src, dst);
if (!move_ok)
ok = update = FALSE;
}
@ -479,12 +590,37 @@ bool TInstaller_mask::move_module(const TString& module, TInstall_ini& ini, bool
bool TInstaller_mask::install(const TString& module, int patchlevel)
{
TInstall_ini *ini;
TInstall_ini* ini = NULL;
bool ok = FALSE;
TString16 lastrelease; // release che sto installando
int lastpatch=patchlevel; // patchlevel che sto installando
const TString& path = get(F_PATH);
TFilename path = get(F_PATH);
TString http_server;
TFilename http_path;
const bool internet = is_internet_path(path);
if (internet)
{
http_server = path;
if (http_server.compare("http://", 7, TRUE) == 0)
http_server.ltrim(7);
const int slash = http_server.find('/');
if (slash > 0)
{
http_path = http_server.mid(slash);
if (http_path.right(1) != "/")
http_path << '/';
http_server.cut(slash);
}
else
http_path = http_default_path;
path.tempdir();
path.add("www");
}
TFilename ininame = path;
ininame.add(module);
@ -496,8 +632,15 @@ bool TInstaller_mask::install(const TString& module, int patchlevel)
}
else
ininame << "inst.ini";
if (internet && !ininame.exist())
{
TFilename remote = ininame.name();
remote.insert(http_path, 0);
http_get(http_server, remote, ininame);
}
if (fexist(ininame))
if (ininame.exist())
{
ini = new TInstall_ini (ininame);
ini->write_protect();
@ -519,10 +662,12 @@ bool TInstaller_mask::install(const TString& module, int patchlevel)
if (!ok) return FALSE;
}
TString msg("Decompressione");
TString msg;
msg << "Decompressione";
if (patchlevel > 0 )
msg << " della patch " << patchlevel ;
msg << " del modulo '" << module << "' in corso...";
TProgind pi(dischi, msg, FALSE, TRUE);
TFilename tempdir; tempdir.tempdir();
@ -540,13 +685,20 @@ bool TInstaller_mask::install(const TString& module, int patchlevel)
else
cmdline << "inst";
cmdline << d << ".zip";
if (internet && !cmdline.exist())
{
TFilename remote = cmdline.name();
remote.insert(http_path, 0);
http_get(http_server, remote, cmdline);
}
ok = cmdline.exist();
while (!ok)
{
message_box("Inserire il disco %d di %d del modulo\n'%s'",
d, dischi, (const char*)ini->get("Descrizione"));
ok = fexist(cmdline);
ok = cmdline.exist();
if (!ok)
{
if (!yesno_box("Impossibile trovare %s\nSi desidera riprovare?",
@ -558,7 +710,8 @@ bool TInstaller_mask::install(const TString& module, int patchlevel)
if (ok)
{
const long required = fsize(cmdline) * (dischi-d+1) * 4;
if (::os_test_disk_free_space("", required))
const TString& dest = get(F_CURPATH);
if (!::os_test_disk_free_space(dest, required))
{
ok = yesno_box("Lo spazio su disco potrebbe essere insufficiente:\n"
"Si desidera continuare ugualmente?");
@ -659,10 +812,10 @@ bool TInstaller_mask::install(const TString& module, int patchlevel)
if (ok)
{
{
ini = new TInstall_ini();
ini->set("DiskPath", path);
ini->set("Data", TDate(TODAY), module);
ini->update_prices(ininame);
TInstall_ini ini;
ini.set("DiskPath", get(F_PATH));
ini.set("Data", TDate(TODAY), module);
ini.update_prices(ininame);
}
// Non togliere le parentesi graffe soprastanti per permettere l'aggiornamento fisico del .ini (CON LA CHIAMATA DEL DISTRUTTORE)
update_version();
@ -684,7 +837,13 @@ bool TInstaller_mask::install_patches(const TString& module, const TString& last
{
bool ok = FALSE;
TString_array modules;
TFilename ininame = get(F_PATH);
TFilename ininame = get(F_PATH);
if (is_internet_path(ininame))
{
ininame.tempdir();
ininame.add("www");
}
ininame.add(module);
ininame << "0???a.ini";
modules.destroy();
@ -713,26 +872,27 @@ bool TInstaller_mask::path_handler(TMask_field& fld, KEY key)
if (key == K_TAB && fld.focusdirty())
{
TFilename path = fld.get();
if (path.len() == 2 && isalpha(path[0]) && path[1] == ':')
if (path.not_empty())
{
path << SLASH;
fld.set(path);
}
if (path.exist())
_curr_mask->autoload();
else
ok = fld.error_box("Specificare un percorso valido");
if (path.len() == 2 && isalpha(path[0]) && path[1] == ':')
{
path << SLASH;
fld.set(path);
}
if (path.exist() || ::is_internet_path(path))
_curr_mask->autoload();
else
ok = fld.error_box("Specificare un percorso valido");
}
}
return ok;
}
void TInstaller_mask::install_selection()
{
TString_array& arr = rows_array();
FOR_EACH_ARRAY_ROW(arr, r, row) if (checked(r))
{
const TString newver = row->get(C_RELEASE);
if (newver.blank())
@ -755,7 +915,7 @@ void TInstaller_mask::install_selection()
bool ok = TRUE;
const int cmp = compare_version(oldver, oldpatch, newver, newpatch);
if (cmp == 0)
ok = yesno_box("Si desidera reinstallare la versione %s.%d del modulo '%s' ?", (const char*)newver, newpatch, (const char*)modulo);
ok = noyes_box("Si desidera reinstallare la versione %s.%d del modulo '%s' ?", (const char*)newver, newpatch, (const char*)modulo);
if (cmp > 0)
{
TString256 msg;
@ -764,7 +924,8 @@ void TInstaller_mask::install_selection()
"funzionamento di tutti i programmi!", (const char*)newver, newpatch, (const char*)modulo);
ok = noyes_box(msg);
}
const bool is_patch = row->get_char(C_ISPATCH) > ' ';
bool is_patch = row->get_char(C_ISPATCH) > ' ';
if (is_patch)
{
// installo le patch solo se esiste già un modulo installato della stessa versione
@ -772,8 +933,18 @@ void TInstaller_mask::install_selection()
if (oldver != newver)
ok =error_box("Impossibile installare le patch della versione %s \nperché il modulo '%s' installato ha versione %s ",(const char *)newver,(const char *)modulo,(const char *)oldver);
}
if (ok)
{
if (!is_patch)
{
if (newver == oldver && newpatch != oldpatch &&
!noyes_box("Si desidera reinstallare l'intero modulo?\n"
"Rispondendo NO verranno installate le sole patch"))
{
is_patch = TRUE;
}
}
if (is_patch)
{
@ -782,7 +953,11 @@ void TInstaller_mask::install_selection()
ok = install(modulo, newpatch); // re-installa l'ultima per sicurezza ()
}
else
{
ok = install(modulo, 0); // installa il modulo
}
if (ok)
_installed = TRUE; // Setta il flag di almeno un modulo installato
if (ok)
@ -832,26 +1007,25 @@ bool TInstaller_mask::tutti_handler(TMask_field& f, KEY k)
return TRUE;
}
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;
}
bool TInstaller_mask::on_key(KEY key)
{
bool ok = TRUE;
if (key == K_CTRL+'N')
autoload();
else
if (key == K_F8)
{
for (long i = items()-1; i >= 0; i--)
{
TToken_string r = row(i);
const TString16 newver = r.get(C_RELEASE);
const int newpatch = r.get_int(C_PATCH);
const TString16 curver = r.get(C_CURRRELEASE);
const int curpatch = r.get_int(C_CURRPATCH);
check(i, compare_version(newver, newpatch, curver, curpatch) > 0);
}
}
else
ok = TArray_sheet::on_key(key);
switch(key)
{
case K_F7: autoload(); break;
case K_F8: field(DLG_USER).on_hit(); break;
default : ok = TArray_sheet::on_key(key); break;
}
return ok;
}
@ -863,13 +1037,15 @@ TInstaller_mask::TInstaller_mask()
_curr_mask = this;
_installed = FALSE;
add_string(F_PATH, 0, "Percorso da cui installare ", 1, 1, 50);
add_string(F_CURPATH, 0, "Percorso in cui installare ", 1, 2, 50, "D");
add_string(F_PATH, 0, "Installa da ", 1, 1, 50);
add_string(F_CURPATH, 0, "Installa in ", 1, 2, 50, "D");
add_button(F_UPDATE, "Lista", '\0');
add_button(F_INSTALL, "Installa", '\0'); // NON mettere 'I'
set_handler(F_PATH, path_handler);
set_handler(F_INSTALL, install_handler);
set_handler(DLG_USER, tutti_handler);
set_handler(F_UPDATE, update_handler);
TDongle dongle; dongle.login(); dongle.logout();
_year_assist = dongle.year_assist();
@ -878,9 +1054,8 @@ TInstaller_mask::TInstaller_mask()
TFilename path = ini.get("DiskPath");
set(F_PATH, path);
const char lettera = toupper(path[0]);
const bool floppy = ::os_is_removable_drive(path);
if (path.not_empty() && !floppy)
if (path.not_empty() && !floppy && !is_internet_path(path))
autoload();
DIRECTORY dir;
@ -908,7 +1083,6 @@ protected:
void TInstaller::main_loop()
{
TInstaller_mask m;
m.load();
m.run();
if (m.installed()) // Almeno 1 modulo installato ?
{

View File

@ -1,3 +1,5 @@
#define F_PATH 201
#define F_CURPATH 202
#define F_INSTALL 203
#define F_SELECT 204
#define F_UPDATE 205