Files correlati : ba1.exe Ricompilazione Demo : [ ] Commento : 0001036: installazione cd patch 180 Installando ex novo ed indicando una società esistente di dati su una cartella diversa viene segnalato l'errore ba1.exe in fase di conversione archivi, richiamando da manutenzione archivi la conversione vengono generati gli errori allegati. Nell'area ftp di Aga, cartella Ilaria allego l'area dati SIDA per il test. git-svn-id: svn://10.65.10.50/trunk@17973 c028cbd2-c16b-5b4b-a496-9718f37d4682
270 lines
7.5 KiB
C++
Executable File
270 lines
7.5 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <dongle.h>
|
|
#include <diction.h>
|
|
#include <isam.h>
|
|
#include <prefix.h>
|
|
#include <progind.h>
|
|
#include <sheet.h>
|
|
#include <statbar.h>
|
|
#include <urldefid.h>
|
|
#include <utility.h>
|
|
|
|
#include "ba1.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// 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)
|
|
{
|
|
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;
|
|
|
|
protected:
|
|
virtual void main_loop();
|
|
virtual bool create () ;
|
|
virtual bool destroy();
|
|
virtual bool extended_firm() const { return true; }
|
|
|
|
public:
|
|
void build_sheet();
|
|
void search_blanks(TSystemisamfile& f);
|
|
void pack_all();
|
|
void save_all();
|
|
|
|
TPackFiles_application() : _selsheet(NULL), _firm(0) {}
|
|
};
|
|
|
|
bool TPackFiles_application::create() // initvar e arrmask
|
|
{
|
|
_firm = get_firm();
|
|
if (!set_firm())
|
|
return false;
|
|
_selsheet = new TSel_sheet;
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
bool TPackFiles_application::destroy()
|
|
{
|
|
if (_firm) set_firm(_firm);
|
|
if (_selsheet != NULL) delete _selsheet;
|
|
return TSkeleton_application::destroy() ;
|
|
}
|
|
|
|
void TPackFiles_application::build_sheet()
|
|
{
|
|
_selsheet->destroy();
|
|
TDir cdir(LF_DIR);
|
|
const int nitems = (int)cdir.eod();
|
|
TToken_string riga;
|
|
for (int i = LF_USER; i <= nitems; i++) // fill sheet
|
|
{
|
|
cdir.get(i, _nolock, _nordir, _sysdirop);
|
|
riga = " ";
|
|
riga.add(i);
|
|
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);
|
|
}
|
|
}
|
|
|
|
void TPackFiles_application::search_blanks(TSystemisamfile& f)
|
|
{
|
|
// Scorre il file corrente per record cancellando eventuali record vuoti/blank
|
|
const TIsam_handle h = f.open(_excllock, true);
|
|
if (h >= 0)
|
|
{
|
|
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);
|
|
safely_close_closeable_isamfiles();
|
|
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);
|
|
|
|
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)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TPackFiles_application::main_loop()
|
|
{
|
|
KEY tasto = K_ENTER;
|
|
while (tasto != K_ESC)
|
|
{
|
|
build_sheet();
|
|
tasto = _selsheet->run();
|
|
switch(tasto)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
int ba1300(int argc, char** argv)
|
|
{
|
|
TPackFiles_application a;
|
|
a.run(argc,argv,TR("Compatta files"));
|
|
return 0;
|
|
}
|