2002-05-27 13:16:06 +00:00
|
|
|
|
#include <agasys.h>
|
2002-04-26 10:47:22 +00:00
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
#include <automask.h>
|
|
|
|
|
#include <execp.h>
|
1995-06-01 15:21:50 +00:00
|
|
|
|
#include <isam.h>
|
2000-10-03 13:45:12 +00:00
|
|
|
|
#include <mailbox.h>
|
|
|
|
|
#include <progind.h>
|
|
|
|
|
#include <utility.h>
|
1995-02-24 13:19:06 +00:00
|
|
|
|
|
|
|
|
|
#include "ba2200.h"
|
2000-10-03 13:45:12 +00:00
|
|
|
|
#include "ba2201.h"
|
|
|
|
|
|
2009-11-04 14:40:51 +00:00
|
|
|
|
#include <user.h>
|
2007-12-12 16:14:54 +00:00
|
|
|
|
#include <nditte.h>
|
|
|
|
|
|
2001-05-07 13:28:51 +00:00
|
|
|
|
struct TAFile_info : public TObject
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
|
|
|
|
TFilename _name;
|
|
|
|
|
long _size;
|
|
|
|
|
int _disk;
|
|
|
|
|
int _last_disk;
|
|
|
|
|
};
|
1995-02-24 13:19:06 +00:00
|
|
|
|
|
2009-05-20 15:37:50 +00:00
|
|
|
|
bool is_real_floppy(const TFilename& path)
|
|
|
|
|
{
|
|
|
|
|
return (path[0] == 'A' || path[0] == 'B') && xvt_fsys_is_removable_drive(path);
|
|
|
|
|
}
|
|
|
|
|
|
1995-02-24 13:19:06 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
2000-10-03 13:45:12 +00:00
|
|
|
|
// Archiving mask
|
1995-02-24 13:19:06 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
class TArchive_mask : public TAutomask
|
1995-02-24 13:19:06 +00:00
|
|
|
|
{
|
|
|
|
|
protected:
|
2000-10-03 13:45:12 +00:00
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
1995-02-24 13:19:06 +00:00
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
public:
|
|
|
|
|
TArchive_mask();
|
1995-02-24 13:19:06 +00:00
|
|
|
|
};
|
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
TArchive_mask::TArchive_mask() : TAutomask("ba2200")
|
|
|
|
|
{
|
2009-05-20 15:37:50 +00:00
|
|
|
|
TList_field& lf = lfield(F_FLOPPY);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
TToken_string codes, values;
|
|
|
|
|
TString4 str;
|
|
|
|
|
int k = 0;
|
|
|
|
|
for (int d = 0; d < 26; d++)
|
|
|
|
|
{
|
2007-12-12 16:14:54 +00:00
|
|
|
|
str.format("%c:", 'A'+d);
|
2009-05-20 15:37:50 +00:00
|
|
|
|
const bool isrem = xvt_fsys_is_removable_drive(str) != 0;
|
2003-03-28 15:33:12 +00:00
|
|
|
|
const bool isfix = !isrem && xvt_fsys_is_fixed_drive(str);
|
2004-05-04 13:21:37 +00:00
|
|
|
|
const bool isnet = !isrem && !isfix && xvt_fsys_is_network_drive(str);
|
|
|
|
|
if (isrem || isfix || isnet)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
|
|
|
|
codes.add(str);
|
|
|
|
|
values.add(str);
|
|
|
|
|
TToken_string& message = *lf.message(k++, TRUE);
|
2009-05-20 15:37:50 +00:00
|
|
|
|
if (isrem && is_real_floppy(str))
|
2009-09-10 09:14:29 +00:00
|
|
|
|
message.format("CLEAR,%d", F_PATH);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
else
|
|
|
|
|
message.format("ENABLE,%d", F_PATH);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lf.replace_items(codes, values);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TArchive_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
|
{
|
|
|
|
|
switch (o.dlg())
|
|
|
|
|
{
|
2009-11-04 14:40:51 +00:00
|
|
|
|
case F_PATH:
|
|
|
|
|
if (e == fe_button)
|
2009-09-10 09:14:29 +00:00
|
|
|
|
{
|
2009-11-04 14:40:51 +00:00
|
|
|
|
TFilename path = get(F_FLOPPY); path << SLASH; path.add(o.get());
|
|
|
|
|
DIRECTORY dir; xvt_fsys_convert_str_to_dir(path, &dir);
|
|
|
|
|
if (xvt_dm_post_dir_sel(&dir) == FL_OK)
|
|
|
|
|
{
|
|
|
|
|
xvt_fsys_convert_dir_to_str(&dir, path.get_buffer(), path.size());
|
|
|
|
|
o.set(path);
|
|
|
|
|
e = fe_modify;
|
|
|
|
|
}
|
2009-09-10 09:14:29 +00:00
|
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (e == fe_modify)
|
|
|
|
|
{
|
|
|
|
|
TFilename path = o.get();
|
|
|
|
|
if (path[1] == ':')
|
|
|
|
|
{
|
|
|
|
|
set(F_FLOPPY, path.left(2));
|
|
|
|
|
o.set(path.mid(2));
|
|
|
|
|
}
|
2009-11-04 14:40:51 +00:00
|
|
|
|
path = get(F_FLOPPY); path << SLASH; path.add(o.get());
|
|
|
|
|
if (!path.exist())
|
|
|
|
|
return error_box(FR("Percorso non valido: %s"), (const char*)path);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_DITTA:
|
|
|
|
|
if (e == fe_modify || e == fe_init)
|
|
|
|
|
{
|
2009-05-25 09:59:53 +00:00
|
|
|
|
set(F_RAGSOC, !o.empty() ? TR("Tutte le ditte") : TR("Nessuna ditta"));
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_CODDITTA:
|
|
|
|
|
if (e == fe_modify)
|
|
|
|
|
{
|
|
|
|
|
if (o.empty())
|
2002-10-24 10:47:49 +00:00
|
|
|
|
set(F_RAGSOC, o.active() ? TR("Tutte le ditte") : TR("Nessuna ditta"));
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case F_SALVA:
|
|
|
|
|
if (e == fe_button)
|
|
|
|
|
{
|
|
|
|
|
const long ditta = get_long(F_CODDITTA);
|
|
|
|
|
if (ditta > 0L && !prefix().exist(ditta))
|
2002-10-24 10:47:49 +00:00
|
|
|
|
return error_box(FR("La ditta %ld non esiste"), ditta);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-05-25 09:59:53 +00:00
|
|
|
|
return true;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// Archiving application
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
1995-02-24 13:19:06 +00:00
|
|
|
|
bool TArchive_app::create()
|
|
|
|
|
{
|
2009-05-25 09:59:53 +00:00
|
|
|
|
bool ok = true;
|
2003-01-28 14:27:05 +00:00
|
|
|
|
|
1998-03-30 14:11:42 +00:00
|
|
|
|
TIsamfile utenti(LF_USER);
|
1995-06-01 15:21:50 +00:00
|
|
|
|
utenti.open(_excllock);
|
|
|
|
|
for (int err = utenti.first(); err == NOERR; err = utenti.next())
|
|
|
|
|
{
|
2009-11-04 14:40:51 +00:00
|
|
|
|
const TString& u = utenti.get(USR_USERNAME);
|
|
|
|
|
if (u != user() && utenti.get_bool(USR_CONNECTED))
|
2003-01-28 14:27:05 +00:00
|
|
|
|
#ifdef DBG
|
|
|
|
|
ok = yesno_box("L'archiviazione non puo' essere effettuata\nse ci sono altri utenti collegati (%s)", (const char*)u);
|
|
|
|
|
#else
|
2002-10-24 10:47:49 +00:00
|
|
|
|
ok = error_box(FR("L'archiviazione non puo' essere effettuata\nse ci sono altri utenti collegati (%s)"), (const char*)u);
|
2003-01-28 14:27:05 +00:00
|
|
|
|
#endif
|
1995-06-01 15:21:50 +00:00
|
|
|
|
}
|
|
|
|
|
utenti.close();
|
|
|
|
|
|
|
|
|
|
if (ok)
|
1998-02-24 10:30:04 +00:00
|
|
|
|
ok = TSkeleton_application::create();
|
1995-06-01 15:21:50 +00:00
|
|
|
|
|
|
|
|
|
return ok;
|
1995-02-24 13:19:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
KEY TArchive_app::query(int& mode, long& firm, TFilename& floppy_path, TString& desc) const
|
1998-02-09 12:06:44 +00:00
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
TArchive_mask m;
|
1998-02-09 12:06:44 +00:00
|
|
|
|
|
1995-02-24 13:19:06 +00:00
|
|
|
|
const KEY k = m.run();
|
|
|
|
|
if (k != K_QUIT)
|
2000-05-05 15:25:49 +00:00
|
|
|
|
{
|
|
|
|
|
mode = 0x0;
|
|
|
|
|
firm = 0L;
|
|
|
|
|
|
|
|
|
|
if (m.get_bool(F_COM))
|
|
|
|
|
mode |= 0x1;
|
|
|
|
|
if (m.get_bool(F_DITTA))
|
|
|
|
|
{
|
|
|
|
|
mode |= 0x2;
|
1995-06-28 16:31:24 +00:00
|
|
|
|
firm = m.get_long(F_CODDITTA);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
}
|
|
|
|
|
if (m.get_bool(F_CONFIG))
|
|
|
|
|
mode |= 0x4;
|
|
|
|
|
if (m.get_bool(F_770))
|
|
|
|
|
mode |= 0x8;
|
2004-09-10 13:29:09 +00:00
|
|
|
|
if (m.get_bool(F_CUSTOM))
|
|
|
|
|
mode |= 0x10;
|
2000-05-05 15:25:49 +00:00
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
floppy_path.format("%c:%c", toupper(m.get(F_FLOPPY)[0]), SLASH);
|
|
|
|
|
floppy_path.add(m.get(F_PATH));
|
|
|
|
|
|
1995-02-24 13:19:06 +00:00
|
|
|
|
desc = m.get(F_DESCR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return k;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TArchive_app::add_file(const TFilename& name)
|
|
|
|
|
{
|
2001-05-07 13:28:51 +00:00
|
|
|
|
TAFile_info* fi = new TAFile_info;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
fi->_name = name;
|
|
|
|
|
fi->_size = fsize(name);
|
|
|
|
|
fi->_disk = fi->_last_disk = 1;
|
|
|
|
|
_zip_list.add(fi);
|
1995-02-24 13:19:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
bool TArchive_app::split_file(const TFilename& archive, unsigned long max_chunk)
|
|
|
|
|
{
|
2009-05-25 09:59:53 +00:00
|
|
|
|
bool ok = true;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
TFilename output(archive);
|
|
|
|
|
output.ext("z00");
|
|
|
|
|
|
2009-05-25 09:59:53 +00:00
|
|
|
|
if (max_chunk > 0 && max_chunk < LONG_MAX) // Devo davvero suddividere archive?
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2009-05-25 09:59:53 +00:00
|
|
|
|
int disk = 0;
|
|
|
|
|
unsigned long scritti = 0;
|
|
|
|
|
|
|
|
|
|
FILE* i = fopen(archive, "rb");
|
|
|
|
|
if (i == NULL)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
FILE* o = fopen(output, "wb");
|
|
|
|
|
|
|
|
|
|
const int BUFSIZE = 1024*16;
|
|
|
|
|
TString buf(BUFSIZE);
|
|
|
|
|
char* buffer = buf.get_buffer();
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
2009-05-25 09:59:53 +00:00
|
|
|
|
ok = true;
|
|
|
|
|
while (ok)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2009-05-25 09:59:53 +00:00
|
|
|
|
const size_t letti = fread(buffer, 1, BUFSIZE, i);
|
|
|
|
|
if (letti == 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (scritti >= max_chunk)
|
|
|
|
|
{
|
|
|
|
|
fclose(o);
|
|
|
|
|
add_file(output);
|
|
|
|
|
|
|
|
|
|
TString4 ext; ext.format("z%02d", ++disk);
|
|
|
|
|
output.ext(ext);
|
|
|
|
|
o = fopen(output, "wb");
|
|
|
|
|
scritti = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ok = fwrite(buffer, letti, 1, o) > 0;
|
|
|
|
|
scritti += letti;
|
|
|
|
|
}
|
|
|
|
|
fclose(i);
|
|
|
|
|
fclose(o);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
2009-05-25 09:59:53 +00:00
|
|
|
|
archive.fremove();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (output.exist())
|
|
|
|
|
output.fremove();
|
|
|
|
|
ok = ::rename(archive, output) == 0; // Basta rinominarlo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
|
add_file(output);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TArchive_app::zip_dir(const TFilename& name, unsigned long max_chunk)
|
|
|
|
|
{
|
|
|
|
|
TFilename tmp; tmp.tempdir();
|
|
|
|
|
tmp.add(name.name());
|
|
|
|
|
tmp.ext("zip");
|
|
|
|
|
|
2009-05-25 09:59:53 +00:00
|
|
|
|
bool ok = false;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
2009-05-25 09:59:53 +00:00
|
|
|
|
if (name.full())
|
|
|
|
|
{
|
|
|
|
|
TFilename filenames = name; filenames.add("*.*");
|
|
|
|
|
TString msg;
|
|
|
|
|
msg << TR("Creazione del file temporaneo ") << tmp << "...";
|
|
|
|
|
TIndwin waitw(100, msg, false, false);
|
|
|
|
|
ok = aga_zip(filenames, tmp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok && tmp.exist())
|
2002-05-27 13:16:06 +00:00
|
|
|
|
ok = split_file(tmp, max_chunk);
|
|
|
|
|
|
|
|
|
|
return ok;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TArchive_app::can_save_as(const TFilename& src, const TFilename& dst) const
|
|
|
|
|
{
|
|
|
|
|
if (dst.exist())
|
|
|
|
|
remove(dst);
|
|
|
|
|
long s = fsize(src);
|
2003-03-28 15:33:12 +00:00
|
|
|
|
return xvt_fsys_test_disk_free_space(dst.left(3), s) != 0;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-25 09:59:53 +00:00
|
|
|
|
bool TArchive_app::save_zip_files(const TFilename& floppy_path, const TString& desc, unsigned long max_chunk)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
|
|
|
|
// Assegna un disco di destinazione a tutti i files
|
|
|
|
|
int disk = 1;
|
|
|
|
|
unsigned long written = 0;
|
2004-03-13 00:29:26 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < _zip_list.items(); i++)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2001-05-07 13:28:51 +00:00
|
|
|
|
TAFile_info& fi = (TAFile_info&)_zip_list[i];
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (written > 0 && (written+fi._size) >= max_chunk)
|
|
|
|
|
{
|
|
|
|
|
disk++;
|
|
|
|
|
written = 0;
|
|
|
|
|
}
|
|
|
|
|
fi._disk = disk;
|
|
|
|
|
written += fi._size;
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-20 17:11:37 +00:00
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
|
|
const bool is_floppy = is_real_floppy(floppy_path);
|
|
|
|
|
if (is_floppy)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2002-10-24 10:47:49 +00:00
|
|
|
|
const char* msg = TR("Si desidera procedere con l'operazione di salvataggio?");
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (disk == 1)
|
2002-10-24 10:47:49 +00:00
|
|
|
|
ok = yesno_box(FR("Controllare che il primo disco sia nel drive %c:\n%s"), floppy_path[0], msg);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
else
|
2002-10-24 10:47:49 +00:00
|
|
|
|
ok = yesno_box(FR("Preparare %d dischetti vuoti e controllare che il primo sia nel drive %c:\n%s"), disk, floppy_path[0], msg);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
2009-05-25 09:59:53 +00:00
|
|
|
|
else
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2009-05-25 09:59:53 +00:00
|
|
|
|
if (!xvt_fsys_mkdir(floppy_path))
|
|
|
|
|
ok = error_box(FR("Impossibile creare la cartella %s"), (const char*)floppy_path);
|
|
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
2009-05-25 09:59:53 +00:00
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
|
TFilename name; name = floppy_path; name.add("backup.ini");
|
|
|
|
|
name.fremove();
|
|
|
|
|
TConfig ini(name, "Main");
|
|
|
|
|
ini.set("Date", oggi.string());
|
|
|
|
|
ini.set("Description", desc);
|
|
|
|
|
ini.set("Disks", disk);
|
|
|
|
|
ini.set("Format", "zip");
|
|
|
|
|
|
|
|
|
|
TFilename last_name;
|
|
|
|
|
long size = 0;
|
|
|
|
|
for (i = 0; i < _zip_list.items(); i++)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2009-05-25 09:59:53 +00:00
|
|
|
|
const TAFile_info& fi = (const TAFile_info&)_zip_list[i];
|
|
|
|
|
name = fi._name.name(); name.ext("");
|
|
|
|
|
if (name != last_name)
|
|
|
|
|
{
|
|
|
|
|
ini.set("FirstDisk", fi._disk, name);
|
|
|
|
|
last_name = name;
|
|
|
|
|
size = 0;
|
|
|
|
|
}
|
|
|
|
|
ini.set("LastDisk", fi._disk);
|
|
|
|
|
ini.set("Size", size += fi._size);
|
|
|
|
|
}
|
|
|
|
|
ini.set_paragraph("Main"); // Forza scrittura ultimo paragrafo
|
|
|
|
|
|
|
|
|
|
int curr_disk = 1;
|
|
|
|
|
|
|
|
|
|
TProgind pi(_zip_list.items(), TR("Salvataggio dati in corso..."), FALSE, TRUE);
|
|
|
|
|
for (i = 0; i < _zip_list.items(); i++)
|
|
|
|
|
{
|
|
|
|
|
pi.addstatus(1);
|
|
|
|
|
const TAFile_info& fi = (const TAFile_info&)_zip_list[i];
|
|
|
|
|
if (fi._disk != curr_disk)
|
|
|
|
|
message_box(FR("Inserire il disco vuoto n.%d"), curr_disk = fi._disk);
|
|
|
|
|
TFilename dest;
|
|
|
|
|
dest = floppy_path; dest.add(fi._name.name());
|
|
|
|
|
while(!can_save_as(fi._name, dest))
|
|
|
|
|
{
|
|
|
|
|
if (!yesno_box(FR("Sul disco %d non c'e' spazio sufficiente per il file %s\nSi desidera sostituire il disco e ritentare?"), curr_disk, (const char*)dest))
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
fcopy(fi._name, dest);
|
|
|
|
|
fi._name.fremove();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ok;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TArchive_app::backup(int mode, long firm, const TFilename& floppy_path, const TString& desc)
|
|
|
|
|
{
|
|
|
|
|
TPointer_array ditte;
|
|
|
|
|
if (firm == 0)
|
2009-05-25 09:59:53 +00:00
|
|
|
|
prefix().firms(ditte);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
else
|
|
|
|
|
ditte.add_long(firm);
|
|
|
|
|
|
|
|
|
|
const TString16 old = prefix().name();
|
|
|
|
|
prefix().set(NULL); // Libera tutti i lock
|
|
|
|
|
|
2003-12-19 14:34:56 +00:00
|
|
|
|
long max_chunk = LONG_MAX;
|
2005-12-20 17:11:37 +00:00
|
|
|
|
|
|
|
|
|
if (is_real_floppy(floppy_path))
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2002-10-24 10:47:49 +00:00
|
|
|
|
message_box(FR("Inserire un disco vuoto nel drive %c:"), floppy_path[0]);
|
2003-12-15 14:07:48 +00:00
|
|
|
|
max_chunk = xvt_fsys_get_disk_size(floppy_path, 'B') - (1024L*64L);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_zip_list.destroy();
|
|
|
|
|
|
2009-05-25 09:59:53 +00:00
|
|
|
|
bool ok = true;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
|
|
|
|
TFilename name;
|
|
|
|
|
if (ok && (mode & 0x1))
|
|
|
|
|
{
|
|
|
|
|
name = firm2dir(0);
|
|
|
|
|
ok = zip_dir(name, max_chunk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok && (mode & 0x2))
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; ok && i < ditte.items(); i++)
|
|
|
|
|
{
|
|
|
|
|
firm = ditte.get_long(i);
|
|
|
|
|
if (prefix().exist(firm))
|
|
|
|
|
{
|
|
|
|
|
name = firm2dir(firm);
|
|
|
|
|
ok = zip_dir(name, max_chunk);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ok && (mode & 0x4))
|
|
|
|
|
{
|
|
|
|
|
name = firm2dir(-1); // __ptprf
|
|
|
|
|
name.add("config"); // Aggiungi configurazioni
|
|
|
|
|
ok = zip_dir(name, max_chunk);
|
2004-09-13 13:50:29 +00:00
|
|
|
|
}
|
|
|
|
|
if (ok && (mode & 0x8))
|
2003-12-19 14:34:56 +00:00
|
|
|
|
{
|
|
|
|
|
name = firm2dir(-1); // __ptprf
|
2004-09-13 13:50:29 +00:00
|
|
|
|
name.add("m770"); // Aggiungi 770
|
2003-12-19 14:34:56 +00:00
|
|
|
|
if (name.exist())
|
|
|
|
|
ok = zip_dir(name, max_chunk);
|
|
|
|
|
}
|
2004-09-13 13:50:29 +00:00
|
|
|
|
if (ok && (mode & 0x10))
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
|
|
|
|
name = firm2dir(-1); // __ptprf
|
2004-09-13 13:50:29 +00:00
|
|
|
|
name.add("custom"); // Aggiungi personalizzazioni
|
2003-12-19 14:34:56 +00:00
|
|
|
|
if (name.exist())
|
|
|
|
|
ok = zip_dir(name, max_chunk);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prefix().set(old); // Ripristina prefix
|
|
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
|
save_zip_files(floppy_path, desc, max_chunk);
|
|
|
|
|
else
|
2002-10-24 10:47:49 +00:00
|
|
|
|
error_box(TR("Si <20> verificato un errore di accesso al disco:\nVerificare lo spazio disponibile"));
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TArchive_app::read_paragraph(TConfig& ini, const char* para)
|
|
|
|
|
{
|
|
|
|
|
const int first = ini.get_int("FirstDisk", para);
|
|
|
|
|
const int last = ini.get_int("LastDisk");
|
|
|
|
|
const bool ok = first > 0 && last >= first;
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
TFilename dir; dir.tempdir();
|
|
|
|
|
TString16 ext;
|
|
|
|
|
int e = 0;
|
|
|
|
|
for (int d = first; d <= last; d++)
|
|
|
|
|
{
|
2001-05-07 13:28:51 +00:00
|
|
|
|
TAFile_info* fi = new TAFile_info;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
TFilename& name = fi->_name;
|
|
|
|
|
ext.format("z%02d", e++);
|
|
|
|
|
name = dir; name.add(para); name.ext(ext);
|
|
|
|
|
fi->_disk = d;
|
|
|
|
|
fi->_last_disk = last;
|
|
|
|
|
fi->_size = ini.get_int("Size");
|
|
|
|
|
_zip_list.add(fi);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TArchive_app::load_zip_files(const TFilename& floppy_path)
|
|
|
|
|
{
|
|
|
|
|
TString msg;
|
|
|
|
|
TFilename dir; dir.tempdir();
|
|
|
|
|
const int files = _zip_list.items();
|
2002-10-24 10:47:49 +00:00
|
|
|
|
TProgind pi(files, TR("Ripristino dati in corso..."), TRUE, TRUE);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
int curr_disk = 1;
|
|
|
|
|
for (int i = 0; i < files; i++)
|
|
|
|
|
{
|
2001-05-07 13:28:51 +00:00
|
|
|
|
const TAFile_info& info = (const TAFile_info&)_zip_list[i];
|
2000-10-03 13:45:12 +00:00
|
|
|
|
const int& disk = info._disk;
|
|
|
|
|
|
2006-04-21 12:02:34 +00:00
|
|
|
|
msg = TR("Ripristino "); msg << info._name.name() << TR("...");
|
2000-10-03 13:45:12 +00:00
|
|
|
|
pi.set_text(msg);
|
|
|
|
|
pi.addstatus(1);
|
|
|
|
|
if (pi.iscancelled())
|
|
|
|
|
break;
|
|
|
|
|
|
2005-12-20 17:11:37 +00:00
|
|
|
|
if (is_real_floppy(floppy_path))
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
|
|
|
|
if (disk != curr_disk)
|
|
|
|
|
{
|
2002-10-24 10:47:49 +00:00
|
|
|
|
message_box(FR("Inserire il disco %d del backup"), disk);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
curr_disk = disk;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TFilename src; src = floppy_path; src.add(info._name.name());
|
|
|
|
|
TFilename dst; dst = dir; dst.add(info._name.name()); dst.ext("zip");
|
2006-04-21 12:02:34 +00:00
|
|
|
|
while (!fcopy(src, dst, i > 0))
|
2002-10-24 10:47:49 +00:00
|
|
|
|
if (!yesno_box(TR("Si desidera ritentare?")))
|
2000-10-03 13:45:12 +00:00
|
|
|
|
return;
|
|
|
|
|
if (disk == info._last_disk)
|
|
|
|
|
{
|
|
|
|
|
TFilename exdir;
|
|
|
|
|
exdir = firm2dir(-1); exdir.add(dst.name()); exdir.ext("");
|
2002-07-03 14:48:48 +00:00
|
|
|
|
aga_unzip(dst, exdir);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TArchive_app::restore(int mode, long firm, const TFilename& floppy_path)
|
|
|
|
|
{
|
|
|
|
|
_zip_list.destroy();
|
|
|
|
|
|
|
|
|
|
TFilename name; name = floppy_path; name.add("backup.ini");
|
|
|
|
|
TConfig ini(name, "Main");
|
|
|
|
|
ini.write_protect();
|
|
|
|
|
|
|
|
|
|
if (mode & 0x1)
|
|
|
|
|
read_paragraph(ini, "com");
|
|
|
|
|
|
|
|
|
|
if (mode & 0x2)
|
|
|
|
|
{
|
|
|
|
|
if (firm > 0)
|
|
|
|
|
{
|
2006-04-26 15:22:42 +00:00
|
|
|
|
TString8 para; para.format("%05lda", firm);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
read_paragraph(ini, para);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TString_array para;
|
|
|
|
|
ini.list_paragraphs(para);
|
|
|
|
|
for (int i = 0; i < para.items(); i++)
|
|
|
|
|
{
|
|
|
|
|
const TString& n = para.row(i);
|
|
|
|
|
if (atol(n) > 0 && n.right(1) == "a")
|
|
|
|
|
read_paragraph(ini, n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode & 0x4)
|
|
|
|
|
read_paragraph(ini, "config");
|
2004-09-10 13:29:09 +00:00
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (mode & 0x8)
|
|
|
|
|
read_paragraph(ini, "m770");
|
|
|
|
|
|
2004-09-13 13:50:29 +00:00
|
|
|
|
if (mode & 0x10)
|
|
|
|
|
read_paragraph(ini, "custom");
|
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
const int tot = _zip_list.items();
|
|
|
|
|
if (tot > 0)
|
|
|
|
|
{
|
|
|
|
|
TString fola;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
fola = TR("Verranno ripristinati i seguenti archivi:\n");
|
2000-10-03 13:45:12 +00:00
|
|
|
|
for (int i = 0; i < tot; i++)
|
|
|
|
|
{
|
2001-05-07 13:28:51 +00:00
|
|
|
|
const TAFile_info& info = (const TAFile_info&)_zip_list[i];
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (info._disk == info._last_disk)
|
|
|
|
|
{
|
|
|
|
|
TFilename n = info._name.name();
|
|
|
|
|
n.ext("");
|
|
|
|
|
fola << n << ", ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fola.rtrim(2);
|
2002-10-24 10:47:49 +00:00
|
|
|
|
fola << TR(".\nSi desidera continuare?");
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (yesno_box(fola))
|
|
|
|
|
{
|
|
|
|
|
const TString16 old = prefix().name();
|
|
|
|
|
prefix().set(NULL); // Libera tutti i lock
|
|
|
|
|
load_zip_files(floppy_path); // Scompatta i files
|
|
|
|
|
prefix().set(old); // Ripristina prefix
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2002-10-24 10:47:49 +00:00
|
|
|
|
warning_box(TR("I dati richiesti non sono presenti sul backup"));
|
2000-10-03 13:45:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TArchive_app::interactive_mode()
|
|
|
|
|
{
|
1995-02-24 13:19:06 +00:00
|
|
|
|
KEY k;
|
2000-05-05 15:25:49 +00:00
|
|
|
|
int mode;
|
1995-02-24 13:19:06 +00:00
|
|
|
|
long firm;
|
2000-10-03 13:45:12 +00:00
|
|
|
|
TFilename floppy_path;
|
|
|
|
|
TString80 desc;
|
1995-02-24 13:19:06 +00:00
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
while ((k = query(mode, firm, floppy_path, desc)) != K_QUIT)
|
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (mode)
|
1998-05-04 09:42:27 +00:00
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (k == K_SAVE)
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2002-05-27 13:16:06 +00:00
|
|
|
|
backup(mode, firm, floppy_path, desc);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
}
|
1998-05-04 09:42:27 +00:00
|
|
|
|
else
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
2002-05-27 13:16:06 +00:00
|
|
|
|
TFilename ini_name = floppy_path; ini_name.add("backup.ini");
|
2005-12-20 17:11:37 +00:00
|
|
|
|
if (is_real_floppy(floppy_path))
|
2002-10-24 10:47:49 +00:00
|
|
|
|
message_box(FR("Inserire il primo disco del backup nel drive %c"), floppy_path[0]);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (ini_name.exist())
|
2002-05-27 13:16:06 +00:00
|
|
|
|
restore(mode, firm, floppy_path);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
else
|
2002-10-24 10:47:49 +00:00
|
|
|
|
error_box(FR("Impossibile trovare il file %s"), (const char*)ini_name);
|
2000-05-05 15:25:49 +00:00
|
|
|
|
}
|
1998-05-04 09:42:27 +00:00
|
|
|
|
}
|
2000-05-05 15:25:49 +00:00
|
|
|
|
else
|
2002-10-24 10:47:49 +00:00
|
|
|
|
error_box(TR("Non e' stato specificato nessun archivio"));
|
1995-02-24 13:19:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
void TArchive_app::batch_mode(const TString& cmd)
|
|
|
|
|
{
|
|
|
|
|
const int mode = ~0;
|
|
|
|
|
const long firm = 0;
|
|
|
|
|
const TFilename floppy_path = cmd;
|
|
|
|
|
restore(mode, firm, floppy_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TArchive_app::main_loop()
|
|
|
|
|
{
|
|
|
|
|
TString cmd;
|
|
|
|
|
|
|
|
|
|
if (argc() > 2)
|
|
|
|
|
{
|
|
|
|
|
TFilename ini = argv(2);
|
2001-05-07 13:28:51 +00:00
|
|
|
|
if (ini.compare("/i", 2, TRUE) == 0) // qui
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
|
|
|
|
ini.ltrim(2);
|
|
|
|
|
TConfig cfg(ini, "Main");
|
|
|
|
|
cmd = cfg.get("Action");
|
2001-05-07 13:28:51 +00:00
|
|
|
|
if (cmd.compare("Restore ", 8, TRUE) == 0) //qui
|
2000-10-03 13:45:12 +00:00
|
|
|
|
{
|
|
|
|
|
cmd.ltrim(8);
|
|
|
|
|
cmd.trim();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
cmd.cut(0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ini.exist())
|
|
|
|
|
cmd = ini;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cmd.empty())
|
|
|
|
|
{
|
|
|
|
|
TMailbox mail;
|
|
|
|
|
TMessage* msg = mail.next_s("RESTORE");
|
|
|
|
|
if (msg == NULL)
|
|
|
|
|
{
|
|
|
|
|
mail.restart();
|
|
|
|
|
msg = mail.next_s("Restore");
|
|
|
|
|
}
|
|
|
|
|
if (msg)
|
|
|
|
|
cmd = msg->body();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cmd.empty())
|
|
|
|
|
interactive_mode();
|
|
|
|
|
else
|
|
|
|
|
batch_mode(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
1995-02-24 13:19:06 +00:00
|
|
|
|
int ba2200(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
TArchive_app a;
|
2002-10-24 10:47:49 +00:00
|
|
|
|
a.run(argc, argv, TR("Archiviazione"));
|
1995-02-24 13:19:06 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|