1994-11-11 18:01:12 +00:00
|
|
|
#include <applicat.h>
|
1999-05-24 13:34:11 +00:00
|
|
|
#include <dongle.h>
|
2002-10-24 10:47:49 +00:00
|
|
|
#include <diction.h>
|
1994-11-11 18:01:12 +00:00
|
|
|
#include <isam.h>
|
1997-06-25 12:40:37 +00:00
|
|
|
#include <prefix.h>
|
1999-04-06 15:34:39 +00:00
|
|
|
#include <progind.h>
|
1994-12-07 11:07:54 +00:00
|
|
|
#include <sheet.h>
|
2008-12-16 10:30:02 +00:00
|
|
|
#include <statbar.h>
|
|
|
|
#include <urldefid.h>
|
2004-03-13 00:22:18 +00:00
|
|
|
#include <utility.h>
|
1994-11-11 18:01:12 +00:00
|
|
|
|
|
|
|
#include "ba1.h"
|
|
|
|
|
2008-12-16 10:30:02 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TSel_sheet
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TSel_sheet : public TArray_sheet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TSel_sheet();
|
|
|
|
};
|
|
|
|
|
|
|
|
TSel_sheet::TSel_sheet()
|
|
|
|
: TArray_sheet(-1, -1, -4, -4, TR("Selezione files"),
|
|
|
|
HR("@1|N.@5|Nome@20|EOD@7|EOX@7|Lunghezza|Descrizione@43|Flags@7"), 0x8)
|
1994-11-11 18:01:12 +00:00
|
|
|
{
|
2008-12-16 10:30:02 +00:00
|
|
|
if (is_power_station())
|
|
|
|
add_button(DLG_EDIT, PR("Salva TXT"), K_SAVE, BMP_ARCHIVE);
|
|
|
|
add_button(-1, "", 0, 1); // Separatore
|
|
|
|
add_button(DLG_INFO, TR("Info"), K_F2, BMP_INFO);
|
|
|
|
add_button(DLG_HELP, TR("Help"), K_F1, BMP_HELP);
|
|
|
|
xvt_toolbar_set_last_tool(toolbar(), DLG_QUIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TPackFiles_application
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TPackFiles_application : public TSkeleton_application
|
|
|
|
{
|
|
|
|
TSel_sheet* _selsheet;
|
|
|
|
long _firm;
|
1994-11-11 18:01:12 +00:00
|
|
|
|
|
|
|
protected:
|
2000-05-05 15:25:49 +00:00
|
|
|
virtual void main_loop();
|
1994-11-11 18:01:12 +00:00
|
|
|
virtual bool create () ;
|
|
|
|
virtual bool destroy();
|
2008-12-16 10:30:02 +00:00
|
|
|
virtual bool extended_firm() const { return true; }
|
|
|
|
|
1994-11-11 18:01:12 +00:00
|
|
|
public:
|
2008-12-16 10:30:02 +00:00
|
|
|
void build_sheet();
|
|
|
|
void search_blanks(TSystemisamfile& f);
|
|
|
|
void pack_all();
|
|
|
|
void save_all();
|
|
|
|
|
1997-06-25 12:40:37 +00:00
|
|
|
TPackFiles_application() : _selsheet(NULL), _firm(0) {}
|
1994-11-11 18:01:12 +00:00
|
|
|
};
|
|
|
|
|
1997-06-25 12:40:37 +00:00
|
|
|
bool TPackFiles_application::create() // initvar e arrmask
|
1994-11-11 18:01:12 +00:00
|
|
|
{
|
|
|
|
_firm = get_firm();
|
1997-06-25 12:40:37 +00:00
|
|
|
if (!set_firm())
|
2008-12-16 10:30:02 +00:00
|
|
|
return false;
|
|
|
|
_selsheet = new TSel_sheet;
|
2000-05-05 15:25:49 +00:00
|
|
|
return TSkeleton_application::create();
|
1994-11-11 18:01:12 +00:00
|
|
|
}
|
|
|
|
|
1997-06-25 12:40:37 +00:00
|
|
|
bool TPackFiles_application::destroy()
|
1994-11-11 18:01:12 +00:00
|
|
|
{
|
|
|
|
if (_firm) set_firm(_firm);
|
2008-12-16 10:30:02 +00:00
|
|
|
if (_selsheet != NULL) delete _selsheet;
|
2000-05-05 15:25:49 +00:00
|
|
|
return TSkeleton_application::destroy() ;
|
1994-11-11 18:01:12 +00:00
|
|
|
}
|
|
|
|
|
1997-06-25 12:40:37 +00:00
|
|
|
void TPackFiles_application::build_sheet()
|
1994-11-11 18:01:12 +00:00
|
|
|
{
|
1997-06-25 12:40:37 +00:00
|
|
|
_selsheet->destroy();
|
2008-12-16 10:30:02 +00:00
|
|
|
TDir cdir(LF_DIR);
|
1997-06-25 12:40:37 +00:00
|
|
|
const int nitems = (int)cdir.eod();
|
2008-12-16 10:30:02 +00:00
|
|
|
TToken_string riga;
|
|
|
|
for (int i = LF_USER; i <= nitems; i++) // fill sheet
|
1997-06-25 12:40:37 +00:00
|
|
|
{
|
2008-12-16 10:30:02 +00:00
|
|
|
cdir.get(i, _nolock, _nordir, _sysdirop);
|
|
|
|
riga = " ";
|
|
|
|
riga.add(i);
|
1997-06-25 12:40:37 +00:00
|
|
|
riga.add(cdir.name());
|
|
|
|
riga.add(cdir.eod());
|
|
|
|
riga.add(cdir.eox());
|
|
|
|
riga.add((int)cdir.len());
|
|
|
|
riga.add(cdir.des());
|
|
|
|
riga.add(cdir.flags());
|
|
|
|
_selsheet->add(riga);
|
|
|
|
}
|
1994-11-11 18:01:12 +00:00
|
|
|
}
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
void TPackFiles_application::search_blanks(TSystemisamfile& f)
|
|
|
|
{
|
2008-12-16 10:30:02 +00:00
|
|
|
// Scorre il file corrente per record cancellando eventuali record vuoti/blank
|
|
|
|
if (f.open(_excllock, true))
|
|
|
|
{
|
|
|
|
const long records = f.items();
|
|
|
|
TString k;
|
|
|
|
TRectype& curr = f.curr();
|
|
|
|
for (long i = 0; f.status() == NOERR && i < records; i++)
|
|
|
|
{
|
|
|
|
f.readat(i + 1); // Legge per numero di record, evitando falli di indice...
|
|
|
|
k = curr.key(); // Chiave 1; non puo' essere vuota (anche perche' no si puo' scrivere un record vuoto)
|
|
|
|
if (curr.empty() || k.blank()) // Teoricamente ce ne sarebbe uno solo...
|
|
|
|
{ // ma se l'indice e' rovinato possono esserci piu' records vuoti
|
|
|
|
curr.discard(); // che vanno cmq eliminati; le pack() successive completano l'opera.
|
|
|
|
f.rewriteat(i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
f.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPackFiles_application::pack_all()
|
|
|
|
{
|
|
|
|
TProgind p(_selsheet->checked(), TR("Compattazione in corso..."), true, true);
|
|
|
|
FOR_EACH_CHECKED_ROW(*_selsheet, k, row)
|
|
|
|
{
|
|
|
|
if (!p.addstatus(1))
|
|
|
|
break;
|
|
|
|
const int i = row->get_int(1);
|
|
|
|
TDir d(i);
|
|
|
|
if (d.len() == 0)
|
|
|
|
continue; // Skip files with flags over 10000
|
|
|
|
const TString pref(prefix().name());
|
|
|
|
prefix().set("");
|
|
|
|
const TDir ds(i);
|
|
|
|
prefix().set(pref);
|
|
|
|
const long flags = ds.flags();
|
|
|
|
if (flags >= 10000L)
|
|
|
|
continue; // Skip files with flags over 10000
|
|
|
|
|
|
|
|
TFilename f_name = d.filename();
|
|
|
|
f_name.ext("dbf");
|
|
|
|
p.set_text(f_name);
|
|
|
|
bool retry = FALSE;
|
|
|
|
const bool present = f_name.exist();
|
|
|
|
int status = NOERR;
|
|
|
|
TSystemisamfile f(i);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
status = NOERR;
|
|
|
|
if (present && flags < 10000L) // Se il file c'e' prova a compattarlo
|
|
|
|
{
|
|
|
|
search_blanks(f);
|
|
|
|
if (f.packfile() == NOERR)
|
|
|
|
f.packindex();
|
|
|
|
status = f.status();
|
|
|
|
if (status == -60) // Se ritorna -60 allora il file e' aperto da qualcuno
|
|
|
|
retry = yesno_box(FR("Il file %s non puo' essere compattato perche' aperto da altre applicazioni. Riprovare?"),(const char*) f_name);
|
|
|
|
}
|
|
|
|
} while (retry); // Ci riprovo !
|
|
|
|
|
|
|
|
if (!present || status == -60)
|
|
|
|
{
|
|
|
|
// if (!present && d.len() > 0 && has_module(module,CHK_DONGLE))// Se il file non esiste lo costruisce
|
|
|
|
// f.build(0L);
|
|
|
|
|
|
|
|
continue; // Se il file non esiste e non si ha il modulo abilitato evita inutili controlli
|
|
|
|
} // Se le pack() hanno ritornato -60 ma il file esiste, allora prosegue con il prossimo
|
|
|
|
if (status != NOERR &&
|
|
|
|
yesno_box(FR("Rilevato l'errore %d cercando di compattare il file %s. Si desidera scaricarlo e ricaricarlo?"),status,(const char*)f_name))
|
|
|
|
{
|
|
|
|
// Dump the file, Zap it and Reload it.
|
|
|
|
TFilename d_name; d_name.temp("fdump");
|
|
|
|
if (f.dump(d_name,0) == NOERR) // Dump
|
|
|
|
{
|
|
|
|
// Zap
|
|
|
|
d.get(i,_nolock, _nordir,_sysdirop);
|
|
|
|
bool is_com = d.is_com();
|
|
|
|
d.get(i,_nolock, is_com ? _comdir : _nordir);
|
|
|
|
d.set_eod(0);
|
|
|
|
d.put(i, is_com ? _comdir : _nordir);
|
|
|
|
if (f.pack() == NOERR)
|
|
|
|
if (f.load(d_name) == NOERR) // Reload
|
|
|
|
d_name.fremove();
|
|
|
|
else
|
|
|
|
error_box(FR("Impossibile ricaricare %s. Errore %d"),(const char*) d_name, f.status());
|
|
|
|
else
|
|
|
|
error_box(FR("Impossibile azzerare %s. Errore %d"),(const char*) f_name, f.status());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error_box(FR("Impossibile scaricare %s. Errore %d"),(const char*) d_name, f.status());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TPackFiles_application::save_all()
|
|
|
|
{
|
|
|
|
TFilename cartella; cartella.tempdir();
|
|
|
|
TString8 firm; firm.format("%05ldA", get_firm());
|
|
|
|
cartella.add(firm);
|
|
|
|
if (!cartella.exist())
|
|
|
|
xvt_fsys_mkdir(cartella);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
2008-12-16 10:30:02 +00:00
|
|
|
DIRECTORY dir; xvt_fsys_convert_str_to_dir(cartella, &dir);
|
|
|
|
xvt_fsys_save_dir();
|
|
|
|
xvt_fsys_set_dir(&dir);
|
|
|
|
const int ret = xvt_dm_post_dir_sel(&dir);
|
|
|
|
xvt_fsys_restore_dir();
|
|
|
|
|
|
|
|
if (ret == FL_OK)
|
1999-04-06 15:34:39 +00:00
|
|
|
{
|
2008-12-16 10:30:02 +00:00
|
|
|
xvt_fsys_convert_dir_to_str(&dir, cartella.get_buffer(), cartella.size());
|
|
|
|
if (!cartella.ends_with(firm))
|
|
|
|
cartella.add(firm);
|
|
|
|
xvt_fsys_mkdir(cartella);
|
|
|
|
|
|
|
|
TProgind p(_selsheet->checked(), TR("Salvataggio in corso..."), true, true);
|
|
|
|
FOR_EACH_CHECKED_ROW(*_selsheet, k, row)
|
|
|
|
{
|
|
|
|
if (!p.addstatus(1))
|
|
|
|
break;
|
|
|
|
const TIsam_handle logic = row->get_int(1);
|
|
|
|
const TDir d(logic);
|
|
|
|
if (d.len() > 0)
|
|
|
|
{
|
|
|
|
TSystemisamfile f(logic);
|
|
|
|
if (f.is_valid(false) == NOERR)
|
|
|
|
{
|
|
|
|
TFilename fname = cartella;
|
|
|
|
TString16 name; row->get(2, name); name.ltrim(1);
|
|
|
|
fname.add(name);
|
|
|
|
fname.ext("txt");
|
|
|
|
f.dump(fname);
|
|
|
|
}
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-05 15:25:49 +00:00
|
|
|
void TPackFiles_application::main_loop()
|
1994-11-11 18:01:12 +00:00
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
KEY tasto = K_ENTER;
|
|
|
|
while (tasto != K_ESC)
|
1994-11-11 18:01:12 +00:00
|
|
|
{
|
1997-06-25 12:40:37 +00:00
|
|
|
build_sheet();
|
2000-05-05 15:25:49 +00:00
|
|
|
tasto = _selsheet->run();
|
|
|
|
switch(tasto)
|
1994-11-11 18:01:12 +00:00
|
|
|
{
|
2008-12-16 10:30:02 +00:00
|
|
|
case K_ENTER:
|
|
|
|
if (_selsheet->one_checked())
|
|
|
|
pack_all();
|
|
|
|
else
|
|
|
|
warning_box(TR("Nessun file selezionato"));
|
|
|
|
break;
|
|
|
|
case K_SAVE:
|
|
|
|
if (_selsheet->one_checked())
|
|
|
|
save_all();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1994-11-11 18:01:12 +00:00
|
|
|
}
|
2000-05-05 15:25:49 +00:00
|
|
|
}
|
1994-11-11 18:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ba1300(int argc, char** argv)
|
|
|
|
{
|
1997-06-25 12:40:37 +00:00
|
|
|
TPackFiles_application a;
|
2002-10-24 10:47:49 +00:00
|
|
|
a.run(argc,argv,TR("Compatta files"));
|
1994-11-11 18:01:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|