2f0ccd9475
git-svn-id: svn://10.65.10.50/trunk@4758 c028cbd2-c16b-5b4b-a496-9718f37d4682
174 lines
5.2 KiB
C++
Executable File
174 lines
5.2 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <execp.h>
|
|
#include <isam.h>
|
|
#include <prefix.h>
|
|
#include <sheet.h>
|
|
#include <urldefid.h>
|
|
#include <utility.h>
|
|
|
|
#include "ba1.h"
|
|
|
|
|
|
class TPackFiles_application:public TApplication
|
|
{
|
|
TArray_sheet * _selsheet;
|
|
long _firm;
|
|
|
|
protected:
|
|
virtual bool menu(MENU_TAG);
|
|
virtual bool create () ;
|
|
virtual bool destroy();
|
|
virtual bool extended_firm() const { return TRUE; }
|
|
void build_sheet();
|
|
public:
|
|
TPackFiles_application() : _selsheet(NULL), _firm(0) {}
|
|
~TPackFiles_application() {};
|
|
};
|
|
|
|
bool TPackFiles_application::create() // initvar e arrmask
|
|
|
|
{
|
|
TApplication::create();
|
|
_firm = get_firm();
|
|
if (!set_firm())
|
|
return FALSE;
|
|
const bool is_prassi = user() == "PRASSI";
|
|
_selsheet = new TArray_sheet(-1, -1, -4, -4, "Selezione files",
|
|
is_prassi ?
|
|
"@1|N.@5|Nome@20|EOD@7|EOX@7|Lung. |Descrizione@43|Flags@7" :
|
|
"N.@5|Nome@20|EOD@7|EOX@7|Lung. |Descrizione@43|Flags@7",
|
|
is_prassi ? 0 : 0x10);
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
return TRUE ;
|
|
}
|
|
|
|
bool TPackFiles_application::destroy()
|
|
|
|
{
|
|
if (_firm) set_firm(_firm);
|
|
if (_selsheet != NULL) delete _selsheet;
|
|
return TApplication::destroy() ;
|
|
}
|
|
|
|
void TPackFiles_application::build_sheet()
|
|
{
|
|
_selsheet->destroy();
|
|
TDir cdir;
|
|
cdir.get(LF_DIR,_nolock,_nordir,_sysdirop);
|
|
const bool is_prassi = user() == "PRASSI";
|
|
const int nitems = (int)cdir.eod();
|
|
for (int i = 0; i < nitems; i++) // fill sheet
|
|
{
|
|
TToken_string riga(128);
|
|
cdir.get(i+1,_nolock,_nordir,_sysdirop);
|
|
if (is_prassi)
|
|
riga.add("");
|
|
riga.add(i+1);
|
|
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);
|
|
}
|
|
}
|
|
|
|
bool TPackFiles_application::menu(MENU_TAG m)
|
|
{
|
|
KEY tasto;
|
|
|
|
do
|
|
{
|
|
build_sheet();
|
|
switch(tasto = _selsheet->run())
|
|
{
|
|
case K_ENTER:
|
|
if (_selsheet->checked()>0)
|
|
{
|
|
int status;
|
|
const long items = _selsheet->items();
|
|
bool retry,present;
|
|
TFilename f_name,d_name;
|
|
TString cmd;
|
|
TDir d;
|
|
for (int i = 2; i<=items; i++) // Skip LF_DIR
|
|
{
|
|
if (!_selsheet->checked(i-1))
|
|
continue;
|
|
d.get(i);
|
|
const long flags = d.flags();
|
|
const int module = abs((int)flags);
|
|
if (flags >= 10000L)
|
|
continue; // Skip files with flags over 10000
|
|
TSystemisamfile f(i);
|
|
|
|
f_name = d.name();
|
|
f_name.ext("dbf");
|
|
retry = FALSE;
|
|
present = access(f_name,0) == 0;
|
|
do
|
|
{
|
|
status = NOERR;
|
|
if (present) // Se il file c'e' prova a compattarlo
|
|
{
|
|
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("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("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.
|
|
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.eod() = 0L;
|
|
d.put(i, is_com ? _comdir : _nordir);
|
|
if (f.pack() == NOERR)
|
|
if (f.load(d_name) == NOERR) // Reload
|
|
unlink(f_name);
|
|
else
|
|
error_box("Impossibile ricaricare %s. Errore %d",(const char*) d_name, f.status());
|
|
else
|
|
error_box("Impossibile azzerare %s. Errore %d",(const char*) f_name, f.status());
|
|
}
|
|
else
|
|
error_box("Impossibile scaricare %s. Errore %d",(const char*) d_name, f.status());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
warning_box("Nessun file selezionato");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
} while (tasto != K_ESC);
|
|
return FALSE;
|
|
}
|
|
|
|
int ba1300(int argc, char** argv)
|
|
{
|
|
TPackFiles_application a;
|
|
a.run(argc,argv,"Compatta files");
|
|
return 0;
|
|
}
|