Corretta la gestione degli errori e visualizzazione del MsgBox finale.

Corretta gestione dell'errore di disco pieno.


git-svn-id: svn://10.65.10.50/trunk@1621 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
angelo 1995-07-20 09:06:33 +00:00
parent 14ac0c0356
commit 4db02131c2

View File

@ -64,7 +64,7 @@ HIDDEN int CGetField(const char *fieldname,RecDes* recd,RecType recin,long* d)
class TIsam_date_converter : public TApplication class TIsam_date_converter : public TApplication
{ {
TFilename _logfile; TFilename _logfile;
bool _errors_found;
protected: protected:
virtual bool create () ; virtual bool create () ;
virtual bool destroy(); virtual bool destroy();
@ -83,9 +83,6 @@ bool TIsam_date_converter::create() // initvar e arrmask
{ {
TApplication::create(); TApplication::create();
_logfile.temp("convlog");
FILE * fp = fopen((const char*)_logfile,"w");
fclose(fp);
update(); update();
return FALSE; return FALSE;
} }
@ -99,6 +96,11 @@ bool TIsam_date_converter::destroy() // releasev e arrmask
void TIsam_date_converter::update() void TIsam_date_converter::update()
{ {
_logfile.temp("cnvlog");
FILE * fp = fopen(_logfile,"w");
fclose(fp);
_errors_found = FALSE;
long firm = get_firm(); long firm = get_firm();
TString pref; TString pref;
if (firm == 0) pref = prefix().name(); if (firm == 0) pref = prefix().name();
@ -132,9 +134,13 @@ void TIsam_date_converter::update()
else prefix().set(pref); else prefix().set(pref);
set_autoload_new_files(TRUE); set_autoload_new_files(TRUE);
end_wait(); end_wait();
TString80 s; if (_errors_found)
s << "Esaminare il file di log " << _logfile << " in caso di errori." ; {
message_box(s); TString80 s;
s << "Esaminare il file di log " << _logfile << " per il riepilogo degli errori." ;
message_box(s);
} else
::remove(_logfile);
} }
void TIsam_date_converter::update_dir() void TIsam_date_converter::update_dir()
@ -204,147 +210,211 @@ int TIsam_date_converter::convert_file(int logicnum)
TDir dir; TDir dir;
TTrec r; TTrec r;
int err = NOERR; int err = NOERR;
bool restore_original=FALSE; bool restore_original=FALSE, retry_file=FALSE;
r.get(logicnum); r.get(logicnum);
RecDes *rd=r.rec(); RecDes *rd=r.rec();
TRecnotype i; TRecnotype i;
const int nflds = r.fields(); const int nflds = r.fields();
const int nkeys = r.keys(); const int nkeys = r.keys();
dir.get(logicnum);
if (dir.len() == 0 || nflds < 1 || nkeys < 1) return 0;
const char * fp = dir.name();
TFilename old(fp);
const TRecnotype nitems = dir.eod();
const TRecnotype neox = dir.eox();
TFile f(dir.len());
old.ext("dta"); do // External loop creation file in case of a disk full error.
if (fexist(old)) { // Appending records can easily reduce disk space!
{ dir.get(logicnum);
f.open(old); if (dir.len() == 0 || nflds < 1 || nkeys < 1) return 0;
{ const char * fp = dir.name();
TSystemisamfile newfile(logicnum); TFilename old(fp);
const TRecnotype nitems = dir.eod();
if (newfile.build(10) != NOERR) const TRecnotype neox = dir.eox();
fatal_box("Non riesco a creare il file %s : errore n. %d", fp, newfile.status()); TFile f(dir.len());
} old.ext("dta");
if (fexist(old))
TString s(80);
s.format("Aggiornamento archivio %s", fp);
TProgind p((long)(nitems ? nitems : 1), s, TRUE, TRUE, 70);
TLocalisamfile newfile(logicnum);
TToken_string ts(128); // Build token_string with the names of date fields and logical fields
TToken_string tslog(128);
for (int j=0; j<r.fields(); j++)
if (rd->Fd[j].TypeF == _datefld)
ts.add(rd->Fd[j].Name);
else
if (rd->Fd[j].TypeF == _boolfld)
tslog.add(rd->Fd[j].Name);
const int tslog_items = tslog.items();
const int ts_items = ts.items();
for (i = 1; newfile.good() && i <= dir.eod(); i++)
{ {
f.read(newfile.curr().string(),i); f.open(old);
if (newfile.curr().string()[0] == '\0') {
{ TSystemisamfile newfile(logicnum);
newfile.curr().recall(); bool retry = FALSE;
if (tslog_items > 0) do // Internal loop creation file in case of a disk full error.
for (const char * field_name = tslog.get(0); field_name != NULL; field_name = tslog.get()) { // The program asks to continue (suspending momentanely execution),
newfile.build(10); // permitting the user to switch to a DOS session and free space on disk.
switch (newfile.status())
{
case NOERR:
retry=FALSE;
break;
case _isfilefull:
if (!yesno_box("Il disco e' pieno. Non riesco a creare il file %s. Riprovo?", fp))
{ {
const TString16 value(newfile.curr().get_str(field_name)); message_box("Liberare spazio sull'unita' interessata e rieseguire la conversione.");
stop_run();
}
retry=TRUE;
break;
default:
fatal_box("Non riesco a creare il file %s : errore n. %d", fp, newfile.status());
break;
}
} while (retry);
}
newfile.put(field_name,value == "X"); TString s(80);
}
if (ts_items > 0) s.format("Aggiornamento archivio %s", fp);
for (const char *field_name = ts.get(0); field_name != NULL; field_name = ts.get()) TProgind p((long)(nitems ? nitems : 1), s, TRUE, TRUE, 70);
{ TLocalisamfile newfile(logicnum);
long wd; TToken_string ts(128); // Build token_string with the names of date fields and logical fields
CGetField(field_name,rd,newfile.curr().string(),&wd); TToken_string tslog(128);
TDate d(wd);
newfile.put(field_name,d); for (int j=0; j<r.fields(); j++)
} if (rd->Fd[j].TypeF == _datefld)
ts.add(rd->Fd[j].Name);
else
if (rd->Fd[j].TypeF == _boolfld)
tslog.add(rd->Fd[j].Name);
const int tslog_items = tslog.items();
const int ts_items = ts.items();
for (i = 1; newfile.good() && i <= dir.eod(); i++)
{
f.read(newfile.curr().string(),i);
newfile.curr().setdirty();
if (newfile.curr().string()[0] == '\0')
{
newfile.curr().recall();
if (tslog_items > 0)
for (const char * field_name = tslog.get(0); field_name != NULL; field_name = tslog.get())
{
const TString16 value(newfile.curr().get_str(field_name));
newfile.put(field_name,value == "X");
}
if (ts_items > 0)
for (const char *field_name = ts.get(0); field_name != NULL; field_name = ts.get())
{
long wd;
CGetField(field_name,rd,newfile.curr().string(),&wd);
TDate d(wd);
newfile.put(field_name,d);
}
}
else
newfile.curr().discard();
if ((i % 50) == 0) p.setstatus((long)(i + 1));
if (!newfile.curr().isdeleted())
newfile.write();
}
p.setstatus((long)nitems);
f.close();
err=newfile.status();
if (newfile.good())
{
old.ext("dta");
::remove(old);
old.ext("ndx");
::remove(old);
restore_original=FALSE;
retry_file=FALSE;
} }
else else
newfile.curr().discard(); {
if ((i % 50) == 0) p.setstatus((long)(i + 1)); _errors_found=TRUE;
if (!newfile.curr().isdeleted()) if (err == _isfilefull)
newfile.write(); {
} if (!yesno_box("Il disco e' pieno. Non riesco a scrivere sul file %s. Riprovo?", fp))
p.setstatus((long)nitems); {
f.close(); message_box("Liberare spazio sull'unita' interessata e rieseguire la conversione.");
err=newfile.status(); retry_file=FALSE;
if (newfile.good()) } else
{ retry_file=TRUE;
old.ext("dta"); }
::remove(old); else
old.ext("ndx"); {
::remove(old); error_box("Errore n.ro %d nella conversione dell' archivio %s:\n %ld records non convertiti.",
err, fp, nitems - i + 2);
retry_file=FALSE;
}
restore_original=TRUE;
}
} }
else else
{ {
error_box("Errore n.ro %d nella conversione dell' archivio %s:\n %ld records non convertiti.", // Crea il file se non esiste il relativo .DTA.
err, fp, nitems - i + 2); const TString pref(prefix().name());
restore_original=TRUE; const bool is_com = prefix().is_com();
}
}
else
{
// Crea il file se non esiste il relativo .DTA.
const TString pref(prefix().name());
const bool is_com = prefix().is_com();
prefix().set(""); prefix().set("");
dir.get(logicnum);
const int module = abs((int)dir.flags());
prefix().set(pref);
dir.get(logicnum, _nolock, _nordir, _sysdirop);
bool to_create = (is_com ? dir.is_com() : dir.is_firm());
if (to_create && has_module(module, CHK_DONGLE))
{
dir.get(logicnum); dir.get(logicnum);
TFilename s(dir.name()); const int module = abs((int)dir.flags());
s.ext("dbf"); prefix().set(pref);
if (!fexist(s)) // Crea il file solo se non esiste il .DBF dir.get(logicnum, _nolock, _nordir, _sysdirop);
bool to_create = (is_com ? dir.is_com() : dir.is_firm());
if (to_create && has_module(module, CHK_DONGLE))
{ {
TSystemisamfile f(logicnum); dir.get(logicnum);
f.build(10L); TFilename s(dir.name());
s.ext("dbf");
if (!fexist(s)) // Crea il file solo se non esiste il .DBF
{
TSystemisamfile f(logicnum);
bool retry = FALSE;
do
{
f.build(10);
switch (f.status())
{
case NOERR:
break;
case _isfilefull:
if (!yesno_box("Il disco e' pieno. Non riesco a creare il file %s. Riprovo?", fp))
{
message_box("Liberare spazio sull'unita' interessata e rieseguire la conversione.");
stop_run();
}
retry=TRUE;
break;
default:
fatal_box("Non riesco a creare il file %s : errore n. %d", fp, f.status());
break;
}
} while (retry);
}
} }
} }
} if (restore_original)
if (restore_original)
{
// Remove files partially converted
old.ext("dbf");
::remove(old);
TToken_string t(10);
get_idx_names(logicnum,t);
for (const char * name=t.get(0); name != NULL; name=t.get())
::remove(name);
if (t.items() > 1) // A .cgp must be removed too!
{ {
old.ext("cgp"); // Remove files partially converted
old.ext("dbf");
::remove(old); ::remove(old);
} TToken_string t(10);
// Put dir to restore original EOD and EOX. get_idx_names(logicnum,t);
dir.get(logicnum,_lock,_nordir,_sysdirop); for (const char * name=t.get(0); name != NULL; name=t.get())
dir.eod()=nitems; ::remove(name);
dir.eox()=neox; if (t.items() > 1) // A .cgp must be removed too!
dir.put(logicnum,_nordir,_sysdirop); {
old.ext("cgp");
::remove(old);
}
// Put dir to restore original EOD and EOX.
dir.get(logicnum,_lock,_nordir,_sysdirop);
dir.eod()=nitems;
dir.eox()=neox;
dir.put(logicnum,_nordir,_sysdirop);
FILE *fp = fopen((const char*)_logfile,"a"); if (!retry_file)
old.ext("dta"); {
fprintf(fp,"File: %s (%d). %ld records non convertiti. Errore %d.\n", FILE *f = fopen((const char*)_logfile,"a");
(const char*) old, logicnum, nitems-i+2, err); old.ext("dta");
fclose(fp); fprintf(f,"File: %s (%d). %ld records non convertiti. Errore %d.\n",
} (const char*) old, logicnum, nitems-i+2, err);
fclose(f);
}
}
} while (retry_file && (err == _isfilefull));
if (err == _isfilefull) // This happens only when the user decides to answer NO.
stop_run();
return err; return err;
} }
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
TIsam_date_converter a; TIsam_date_converter a;