From b75f368c637770f2a1ce69c7517de92a536b1699 Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 30 Mar 1998 14:08:53 +0000 Subject: [PATCH] ba11*.* Adeguata gestione files alla nuova gestione handles ba1400.cpp Tolti include inutili ba1600.cpp Tolti include inutili ba1800.cpp Migliorato riconoscimento del file origine dei trasferimenti git-svn-id: svn://10.65.10.50/trunk@6459 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- ba/ba1100.cpp | 206 +++++++++++++++++++++++++++++--------------------- ba/ba1100.h | 2 +- ba/ba1101.cpp | 18 +++-- ba/ba1400.cpp | 9 +-- ba/ba1600.cpp | 1 + ba/ba1800.cpp | 6 +- 6 files changed, 139 insertions(+), 103 deletions(-) diff --git a/ba/ba1100.cpp b/ba/ba1100.cpp index 9f49951d3..a6c67cf21 100755 --- a/ba/ba1100.cpp +++ b/ba/ba1100.cpp @@ -46,6 +46,8 @@ protected: void edit_riga(const TString&); void delete_riga(); virtual bool extended_firm() const { return TRUE; } + + bool recover(TSystemisamfile& f, int err); void update(); void update_dir(); void convert_dir(); @@ -93,7 +95,6 @@ TManutenzione_app::TManutenzione_app() : _browse(NULL), _rec(NULL), _mask(NULL), { // vengono creati se non esistono TDir d; FileDes* fd = d.filedesc(); - int handle; strcpy(fd->SysName,"$dir.gen"); fd->LenR =160; @@ -102,11 +103,9 @@ TManutenzione_app::TManutenzione_app() : _browse(NULL), _rec(NULL), _mask(NULL), strcpy(fd->Des ,"Directory"); strcpy(fd->FCalc,"0"); strcpy(fd->GenPrompt,""); -#if XVT_OS == XVT_OS_WIN - if ((handle = sopen(Dir_file, O_RDWR|O_BINARY|O_CREAT,SH_DENYNO,S_IREAD|S_IWRITE)) != -1) -#else - if ((handle = open(Dir_file, O_RDWR|O_BINARY|O_CREAT,0666)) != -1) -#endif + + int handle = sopen(Dir_file, O_RDWR|O_BINARY|O_CREAT,SH_DENYNO,S_IREAD|S_IWRITE); + if (handle != -1) { if (write( handle, (char*)fd, sizeof(FileDes)) == -1) fatal_box("Impossibile scrivere il file dir.gen per dati standard: errore %d",errno); @@ -118,12 +117,8 @@ TManutenzione_app::TManutenzione_app() : _browse(NULL), _rec(NULL), _mask(NULL), { TTrec r; RecDes* rd = r.rec(); - int handle; -#if XVT_OS == XVT_OS_WIN - if ((handle = sopen(Trc_file, O_RDWR|O_BINARY|O_CREAT,SH_DENYNO,S_IREAD|S_IWRITE)) != -1) -#else - if ((handle = open(Trc_file, O_RDWR|O_BINARY|O_CREAT,0666)) != -1) -#endif + int handle = sopen(Trc_file, O_RDWR|O_BINARY|O_CREAT,SH_DENYNO,S_IREAD|S_IWRITE); + if (handle != -1) { if (write( handle, (char*)rd, sizeof(RecDes)) == -1) fatal_box("Impossibile scrivere il file trc.gen per dati standard: errore %d",errno); @@ -352,6 +347,7 @@ bool TManutenzione_app::create() // initvar e arrmask _browse->add_button(DLG_INSFILE, "~Inserisci", K_F6); _browse->add_button(DLG_CONVERT, "~Converti", K_F7); _browse->add_button(DLG_ADDFILE, "~Aggiungi", K_F8); + TButton_field& butt = ((TMask*)_browse)->add_button(DLG_OTHERFILE, 0, "A~ltri", 0, -1, 9, 2, "", 0, 0); butt.set_hot_key(K_F5); _mask->enable(-1); // Abilita campi privilegiati @@ -364,7 +360,6 @@ bool TManutenzione_app::create() // initvar e arrmask } bool TManutenzione_app::destroy() // releasev e arrmask - { if (_firm) set_firm(_firm); if (_browse != NULL) delete _browse; @@ -546,7 +541,6 @@ void TManutenzione_app::edit_riga (const TString& name) } void TManutenzione_app::edit_riga (long riga_sel, TToken_string& riga) - { KEY tasto; FileDes dep; @@ -617,21 +611,23 @@ void TManutenzione_app::edit_riga (long riga_sel, TToken_string& riga) dep.Des, dep.FCalc); _browse->dir()->put(logicnum, _nordir, _sysdirop); - { - TSystemisamfile f(logicnum); - if (eox != oldeox) { + TSystemisamfile f(logicnum); d.get(logicnum); TFilename f_name(d.name()); f_name.ext("dbf"); - - if (!fexist(f_name)) f.build(eox); - else f.extend(eox); + if (f_name.exist()) + f.extend(eox); + else + f.build(eox); _browse->dir()->get(logicnum, _nolock, _nordir, _sysdirop); } - if (tasto == K_F5) + switch (tasto) { + case K_F5: + { + TSystemisamfile f(logicnum); f.packfile(); f.packindex(); //Pack supplementare tramite FOXPRO (da togliere con CodeBase 6) @@ -650,61 +646,64 @@ void TManutenzione_app::edit_riga (long riga_sel, TToken_string& riga) } #endif } - else - if (tasto == K_F6) - { - _rec = new TRec_sheet(logicnum, _mask->get(F_TAB)); - _rec->edit(); - delete _rec; - _rec = NULL; - } - else - if (tasto == K_F7) - { - TMask m("ba1100b"); - - TFilename nout(dumpfilename(dep)); - m.set(FLD_OUTFILE, nout); - - if (m.run() == K_ENTER) - { - nout = m.get(FLD_OUTFILE); - if (nout.not_empty()) - { - const char fs = *esc(m.get(FLD_FS)); - const char fd = *esc(m.get(FLD_FD)); - const char rs = *esc(m.get(FLD_RS)); - const bool withdel = m.get_bool(FLD_WITHDEL); - const int keyno = m.get_int(FLD_KEYNO); - f.dump(nout, keyno, fs, fd, rs, withdel); - } - } - } - else - if (tasto == K_F8) - { - TMask m("ba1100c"); - TFilename ninp(dumpfilename(dep)); - m.set(FLD_INFILE, ninp); - if (m.run() == K_ENTER) - { - char fs = *esc(m.get(FLD_FS)); - char fd = *esc(m.get(FLD_FD)); - char rs = *esc(m.get(FLD_RS)); - ninp = m.get(FLD_INFILE); - f.load(ninp, fs, fd, rs); - } - } - } - } break; + case K_F6: + { + _rec = new TRec_sheet(logicnum, _mask->get(F_TAB)); + _rec->edit(); + delete _rec; + _rec = NULL; + } + break; + case K_F7: + { + TMask m("ba1100b"); + + TFilename nout(dumpfilename(dep)); + m.set(FLD_OUTFILE, nout); + + if (m.run() == K_ENTER) + { + nout = m.get(FLD_OUTFILE); + if (nout.not_empty()) + { + TSystemisamfile f(logicnum); + const char fs = *esc(m.get(FLD_FS)); + const char fd = *esc(m.get(FLD_FD)); + const char rs = *esc(m.get(FLD_RS)); + const bool withdel = m.get_bool(FLD_WITHDEL); + const int keyno = m.get_int(FLD_KEYNO); + f.dump(nout, keyno, fs, fd, rs, withdel); + } + } + } + break; + case K_F8: + { + TMask m("ba1100c"); + TFilename ninp(dumpfilename(dep)); + m.set(FLD_INFILE, ninp); + if (m.run() == K_ENTER) + { + TSystemisamfile f(logicnum); + char fs = *esc(m.get(FLD_FS)); + char fd = *esc(m.get(FLD_FD)); + char rs = *esc(m.get(FLD_RS)); + ninp = m.get(FLD_INFILE); + f.load(ninp, fs, fd, rs); + } + } + break; + default: + break; + } + } default: break; } } void TManutenzione_app::delete_riga () - { _browse->dir()->get(LF_DIR); if (_browse->dir()->eod() == 0) return; @@ -712,16 +711,27 @@ void TManutenzione_app::delete_riga () int logicnum = (int)_browse->items(); _browse->dir()->get(logicnum); - if (yesnocancel_box("Confermare l'eliminzione dell'archivio %s", _browse->dir()->name()) != K_YES) return; + if (!yesno_box("Confermare l'eliminzione dell'archivio %s", _browse->dir()->name())) + return; _browse->dir()->get(LF_DIR); _browse->dir()->eod()--; _browse->set_items(_browse->dir()->eod()); _browse->dir()->put(LF_DIR); + // Azzera il tracciato record del file eliminato. TTrec r; r.zero(); r.put(logicnum); +} +bool TManutenzione_app::recover(TSystemisamfile& f, int err) +{ + if (err == -60 || err == _ispatherr || + (err > -600 && err <= -300)) + { + err = f.packindex(); + } + return err == NOERR; } void TManutenzione_app::update_dir() @@ -805,19 +815,23 @@ void TManutenzione_app::update_dir() { fseek(f, 0L, SEEK_END); const long size = ftell(f); - fclose(f); if (size > 0L && d.len() > 0) { - TBaseisamfile b(i); + TSystemisamfile b(i); int err = b.is_valid(); - if (err == NOERR) + if (err != NOERR && flags < 10000L) { - TLocalisamfile f(i); - } - else - { - if (flags < 10000L && !yesno_box("Il file %d non puo' essere aperto: errore %d. Continuo?",i,err)) + KEY k = yesnocancel_box("Il file %d non puo' essere aperto: errore %d\n" + "Si desidera tentare il recupero dei dati?\n" + "Rispondendo No l'errore verra' ignorato.",i,err); + if (k == K_YES) + { + if (!recover(b, err)) + k = yesno_box("Impossibile recuperare i dati\n" + "Si desidera proseguire ugualmente?") ? K_NO : K_ESC; + } + if (k == K_ESC) stop_run(); } } @@ -1023,18 +1037,28 @@ void TManutenzione_app::convert_dir() // prefix().set(pref); if (ds.len() > 0) { - if (flags < 10000L && flags > -1L) + if (flags >= 0L && flags < 10000L) { - TBaseisamfile b(i); + TSystemisamfile b(i); const int module = abs((int)ds.flags()); int err = b.is_valid(); if (err == -60 || err == -64) err=NOERR; // verif. d.get(i, _nolock, _nordir, _sysdirop); if (i > 2 && err != NOERR && ((is_com && d.is_com()) || (!is_com && d.is_firm()))) { - if (!yesno_box("Il file %d non puo' essere aperto: errore %d. Continuo?",i,err)) + KEY k = yesnocancel_box("Il file %d non puo' essere aperto: errore %d\n" + "Si desidera tentare il recupero dei dati?\n" + "Rispondendo Annulla il programma terminera'",i,err); + if (k == K_YES) + { + if (!recover(b, err)) + k = yesno_box("Impossibile recuperare i dati\n" + "Si desidera proseguire ugualmente?") ? K_NO : K_ESC; + } + if (k == K_ESC) stop_run(); - else continue; + else + continue; } //d.get(i, _nolock, _nordir, _sysdirop); @@ -1043,9 +1067,8 @@ void TManutenzione_app::convert_dir() // I files LF_PCON, LF_CAUS, LF_RCAUS, LF_CLIFO, LF_CFVEN, LF_INDSPED // vanno creati comunque nel direttorio COM, vuoti, (se non esistono gia'). - if (is_com && !to_create) - if (movable_file(i)) - to_create = TRUE; + if (is_com && !to_create && movable_file(i)) + to_create = TRUE; if (to_create && has_module(module, CHK_DONGLE)) { @@ -1180,6 +1203,8 @@ void TManutenzione_app::load_des() infile.close(); //unlink(fn); } + + /* // Aggiorna il numero di files presenti in totale nel direttorio if (last_newln > items) // rialloca openf altrimenti la TPrefix::closeall() provoca un grazioso errore in applicazione { @@ -1189,6 +1214,7 @@ void TManutenzione_app::load_des() delete openf; openf = newopenf; } + */ d.eod() = (long)last_newln; d.eox() = (long)last_newln; d.flags() = _level = flags; @@ -1255,7 +1281,7 @@ void TManutenzione_app::update() { bool ok = TRUE; - TIsamfile utenti(LF_USER, FALSE); + TIsamfile utenti(LF_USER); utenti.open(_excllock); for (int err = utenti.first(); err == NOERR; err = utenti.next()) @@ -1265,8 +1291,14 @@ void TManutenzione_app::update() { if (utenti.get("AUTSTR") == "CONVERTING") { - ok = error_box("Impossibile proseguire: esiste gia' conversione in corso"); +#ifdef DBG + ok = yesno_box("E' gia' in corso una conversione:\nProseguire ugualmente?"); + if (!ok) + break; +#else + ok = error_box("E' gia' in corso una conversione:\nImpossibile proseguire"); break; +#endif } else { diff --git a/ba/ba1100.h b/ba/ba1100.h index d2703f688..af1b564f8 100755 --- a/ba/ba1100.h +++ b/ba/ba1100.h @@ -40,7 +40,7 @@ public: void rebuild() { _items = _dir->items();} TDir_sheet(const char* title,byte buttons=0x8,const char* col = "N.@5|Nome@20|EOD@7|EOX@7|Lung. |Descrizione@43|Formula@33|Flags@7"); - ~TDir_sheet(); + virtual ~TDir_sheet(); }; class TRec_sheet : public TObject diff --git a/ba/ba1101.cpp b/ba/ba1101.cpp index 04aa960f8..892688bd2 100755 --- a/ba/ba1101.cpp +++ b/ba/ba1101.cpp @@ -5,17 +5,14 @@ #include #include #include +#include #include #include #include #include "ba1100.h" -extern "C" { - extern isfdptr* openf; -}; - -TMask* TRec_sheet::_mask = NULL; +TMask* TRec_sheet::_mask = NULL; void TDir_sheet::add () { @@ -31,12 +28,14 @@ void TDir_sheet::add () d.zero(); d.put(nitems, _nordir, _sysdirop); _items = nitems; - + +/* isfdptr *newopenf = new isfdptr[_items]; for (int i = 0; i<_items; i++) newopenf[i] = i<(_items-1) ? openf[i] : NULL; delete openf; openf = newopenf; +*/ } TDir_sheet::TDir_sheet(const char* title, byte buttons, const char* colonne) @@ -135,8 +134,11 @@ TRec_sheet::TRec_sheet(TExternisamfile* file) _rec = new TTrec; _rec_old = new TTrec; _mask = new TMask("ba1100d"); - memcpy(_dir->filedesc(),file->filehnd()->d,sizeof(FileDes)); - memcpy(_rec->rec(),file->filehnd()->r,sizeof(RecDes)); + + const FileDes& d = prefix().get_filedes(file->num()); + const RecDes& r = prefix().get_recdes(file->num()); + memcpy(_dir->filedesc(),&d,sizeof(FileDes)); + memcpy(_rec->rec(),&r,sizeof(RecDes)); if (_dir->len() == 0) _rec->zero(); *_rec_old = *_rec; diff --git a/ba/ba1400.cpp b/ba/ba1400.cpp index 0287856c0..49b04f780 100755 --- a/ba/ba1400.cpp +++ b/ba/ba1400.cpp @@ -1,11 +1,8 @@ -#include - -#include -#include #include -#include -#include #include +#include +#include +#include #include "ba1.h" #include "ba1500.h" diff --git a/ba/ba1600.cpp b/ba/ba1600.cpp index e48d6383c..d82e012cf 100755 --- a/ba/ba1600.cpp +++ b/ba/ba1600.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/ba/ba1800.cpp b/ba/ba1800.cpp index 044419d03..113d8a287 100755 --- a/ba/ba1800.cpp +++ b/ba/ba1800.cpp @@ -573,6 +573,10 @@ void TWizard_mask::load_ini(const TString& ininame) } } + TString use = ini.get("USE"); + if (use.not_empty()) + set(F_ISAM, use); + TRelation_description* rd = rel_desc(); TFields_sheet& fs = (TFields_sheet&)sfield(F_FIELDS); @@ -928,7 +932,7 @@ bool TWizard_mask::file_handler(TOperable_field& f, TField_event e) if (n.exist()) { set(F_INI, n, TRUE); - break; + return TRUE; } } }