16900d6356
Files correlati : ba7 Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@17407 c028cbd2-c16b-5b4b-a496-9718f37d4682
179 lines
4.0 KiB
C++
Executable File
179 lines
4.0 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <defmask.h>
|
|
#include <prefix.h>
|
|
#include <progind.h>
|
|
#include <relation.h>
|
|
#include <utility.h>
|
|
|
|
#include "ba7200a.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Main app
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TCopia_dati_app : public TSkeleton_application
|
|
{
|
|
bool copy_dir(const char* src, const char* dst) const;
|
|
|
|
public:
|
|
virtual void main_loop();
|
|
};
|
|
|
|
inline TCopia_dati_app& app() { return (TCopia_dati_app&)main_app(); }
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Step 1
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TCopia_dati_mask : public TAutomask
|
|
{
|
|
public:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
TCopia_dati_mask() : TAutomask("ba7200a") { }
|
|
};
|
|
|
|
bool TCopia_dati_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case F01_DATIL:
|
|
if (e == fe_close || e == fe_modify)
|
|
{
|
|
const TFilename n = o.get();
|
|
const bool esiste = n.exist();
|
|
if (strlen(n.name()) > 8)
|
|
return error_box("L'area dati ha un nome troppo lungo: %s", (const char*)n.name());
|
|
if (esiste)
|
|
return error_box("L'area dati in Lire esiste già");
|
|
} else
|
|
if (e == fe_init)
|
|
{
|
|
TFilename src, dst;
|
|
src = prefix().get_studio();
|
|
src.rtrim(1);
|
|
set(F01_DATI, src);
|
|
dst << src << "l";
|
|
set(F01_DATIL, dst);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
int list_dirs(
|
|
const char* filelist, // @parm Stringa contenente la maschera di estrazione
|
|
TString_array& result) // @parm Array da riempire con la lista dei file
|
|
|
|
{
|
|
TWait_cursor hourglass;
|
|
TFilename dir(filelist);
|
|
int i;
|
|
|
|
for (i = dir.len()-1; i >= 0; i--)
|
|
if (is_slash(dir[i]) || dir[i] == ':') break;
|
|
|
|
TFilename mask(dir.mid(i+1));
|
|
dir.cut(i > 0 ? i+1 : 0);
|
|
|
|
DIRECTORY curdir;
|
|
xvt_fsys_get_dir(&curdir);
|
|
|
|
if (dir.not_empty())
|
|
{
|
|
DIRECTORY thedir; xvt_fsys_convert_str_to_dir(dir, &thedir);
|
|
BOOLEAN ok = xvt_fsys_set_dir(&thedir);
|
|
if (!ok)
|
|
{
|
|
error_box("Impossibile entrare in %s", (const char*)dir);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
SLIST files = xvt_fsys_list_files(DIR_TYPE, "", TRUE);
|
|
const int count = xvt_slist_count(files);
|
|
|
|
for (SLIST_ELT e = xvt_slist_get_first(files); e; e = xvt_slist_get_next(files, e))
|
|
{
|
|
const char* f = xvt_slist_get(files, e, NULL);
|
|
if (*f != '.' && f[1] != ':')
|
|
{
|
|
if (dir.not_empty())
|
|
{
|
|
mask = dir;
|
|
mask.add(f);
|
|
result.add(mask);
|
|
}
|
|
else
|
|
result.add(f);
|
|
}
|
|
}
|
|
|
|
xvt_slist_destroy(files);
|
|
|
|
xvt_fsys_set_dir(&curdir);
|
|
|
|
return count;
|
|
}
|
|
|
|
bool TCopia_dati_app::copy_dir(const char* src, const char* dst) const
|
|
{
|
|
bool ok = TRUE;
|
|
if (!fexist(dst))
|
|
make_dir(dst);
|
|
|
|
TString_array files;
|
|
TFilename file1, file2;
|
|
|
|
file1 = src; file1.add("*.*");
|
|
list_dirs(file1, files);
|
|
FOR_EACH_ARRAY_ROW(files, d, dir)
|
|
{
|
|
file1 = *dir;
|
|
file2 = dst; file2.add(file1.name());
|
|
ok &= copy_dir(file1, file2);
|
|
}
|
|
files.destroy();
|
|
|
|
file1 = src; file1.add("*.*");
|
|
list_files(file1, files);
|
|
TString str;
|
|
str << "Copia da " << src << " a " << dst << "...";
|
|
TProgind pi(files.items(), str, FALSE, TRUE);
|
|
FOR_EACH_ARRAY_ROW(files, i, file)
|
|
{
|
|
pi.addstatus(1);
|
|
|
|
file1 = *file;
|
|
file2 = dst; file2.add(file1.name());
|
|
ok &= fcopy(file1, file2);
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Main
|
|
///////////////////////////////////////////////////////////
|
|
|
|
void TCopia_dati_app::main_loop()
|
|
{
|
|
TCopia_dati_mask m;
|
|
if (m.run() == K_ENTER)
|
|
{
|
|
prefix().set(NULL);
|
|
const char* dir1 = m.get(F01_DATI);
|
|
const char* dir2 = m.get(F01_DATIL);
|
|
copy_dir(dir1, dir2);
|
|
}
|
|
}
|
|
|
|
int ba7200(int argc, char* argv[])
|
|
{
|
|
TCopia_dati_app ma;
|
|
ma.run(argc, argv, "Copia Studio");
|
|
|
|
return 0;
|
|
}
|