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
{
TFilename _logfile;
bool _errors_found;
protected:
virtual bool create () ;
virtual bool destroy();
@ -83,9 +83,6 @@ bool TIsam_date_converter::create() // initvar e arrmask
{
TApplication::create();
_logfile.temp("convlog");
FILE * fp = fopen((const char*)_logfile,"w");
fclose(fp);
update();
return FALSE;
}
@ -99,6 +96,11 @@ bool TIsam_date_converter::destroy() // releasev e arrmask
void TIsam_date_converter::update()
{
_logfile.temp("cnvlog");
FILE * fp = fopen(_logfile,"w");
fclose(fp);
_errors_found = FALSE;
long firm = get_firm();
TString pref;
if (firm == 0) pref = prefix().name();
@ -132,9 +134,13 @@ void TIsam_date_converter::update()
else prefix().set(pref);
set_autoload_new_files(TRUE);
end_wait();
TString80 s;
s << "Esaminare il file di log " << _logfile << " in caso di errori." ;
message_box(s);
if (_errors_found)
{
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()
@ -204,147 +210,211 @@ int TIsam_date_converter::convert_file(int logicnum)
TDir dir;
TTrec r;
int err = NOERR;
bool restore_original=FALSE;
bool restore_original=FALSE, retry_file=FALSE;
r.get(logicnum);
RecDes *rd=r.rec();
TRecnotype i;
const int nflds = r.fields();
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");
if (fexist(old))
{
f.open(old);
{
TSystemisamfile newfile(logicnum);
if (newfile.build(10) != NOERR)
fatal_box("Non riesco a creare il file %s : errore n. %d", fp, newfile.status());
}
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++)
do // External loop creation file in case of a disk full error.
{ // Appending records can easily reduce disk space!
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");
if (fexist(old))
{
f.read(newfile.curr().string(),i);
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())
f.open(old);
{
TSystemisamfile newfile(logicnum);
bool retry = FALSE;
do // Internal loop creation file in case of a disk full error.
{ // 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");
}
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);
}
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);
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
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);
{
_errors_found=TRUE;
if (err == _isfilefull)
{
if (!yesno_box("Il disco e' pieno. Non riesco a scrivere sul file %s. Riprovo?", fp))
{
message_box("Liberare spazio sull'unita' interessata e rieseguire la conversione.");
retry_file=FALSE;
} else
retry_file=TRUE;
}
else
{
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
{
error_box("Errore n.ro %d nella conversione dell' archivio %s:\n %ld records non convertiti.",
err, fp, nitems - i + 2);
restore_original=TRUE;
}
}
else
{
// Crea il file se non esiste il relativo .DTA.
const TString pref(prefix().name());
const bool is_com = prefix().is_com();
// Crea il file se non esiste il relativo .DTA.
const TString pref(prefix().name());
const bool is_com = prefix().is_com();
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))
{
prefix().set("");
dir.get(logicnum);
TFilename s(dir.name());
s.ext("dbf");
if (!fexist(s)) // Crea il file solo se non esiste il .DBF
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))
{
TSystemisamfile f(logicnum);
f.build(10L);
dir.get(logicnum);
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)
{
// 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!
if (restore_original)
{
old.ext("cgp");
// Remove files partially converted
old.ext("dbf");
::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);
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(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");
old.ext("dta");
fprintf(fp,"File: %s (%d). %ld records non convertiti. Errore %d.\n",
(const char*) old, logicnum, nitems-i+2, err);
fclose(fp);
}
if (!retry_file)
{
FILE *f = fopen((const char*)_logfile,"a");
old.ext("dta");
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;
}
int main(int argc, char** argv)
{
TIsam_date_converter a;