75e4c8fde0
Files correlati : Ricompilazione Demo : [ ] Commento :modifiche necessarie alla 10.0 per integrarsi con il nuovo setup git-svn-id: svn://10.65.10.50/trunk@15916 c028cbd2-c16b-5b4b-a496-9718f37d4682
189 lines
4.6 KiB
C++
Executable File
189 lines
4.6 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <config.h>
|
||
#include <scanner.h>
|
||
#include <utility.h>
|
||
|
||
#include "ba1500.h"
|
||
|
||
HIDDEN void build_key(char* dninst_key)
|
||
{
|
||
for (int i = 0; i < 8; i++)
|
||
dninst_key[i] = 'A'+ rand() % 26;
|
||
}
|
||
|
||
HIDDEN void decode_string(char* dninst_key, char* data)
|
||
{
|
||
build_key(dninst_key);
|
||
char tmp[1024];
|
||
int i;
|
||
for (i = 0; data[i]; i++)
|
||
tmp[i] = data[i] - (i < 8 ? dninst_key[i] : tmp[i - 8]);
|
||
tmp[i] = '\0';
|
||
strcpy(data, tmp);
|
||
}
|
||
|
||
#ifdef DBG
|
||
|
||
HIDDEN void encode_string(char* dninst_key, char* data)
|
||
{
|
||
build_key(dninst_key);
|
||
|
||
char tmp[1024];
|
||
int i;
|
||
for (i = 0; data[i]; i++)
|
||
tmp[i] = data[i] + (i < 8 ? dninst_key[i] : data[i - 8]);
|
||
tmp[i] = '\0';
|
||
strcpy(data, tmp);
|
||
}
|
||
|
||
HIDDEN bool build_dninst()
|
||
{
|
||
ifstream inf("dninst.txt", ios::in);
|
||
if (inf.good())
|
||
{
|
||
char dninst_key[8] = "";
|
||
|
||
ofstream ouf("dninst.zip", ios::out | ios::binary);
|
||
char line[256];
|
||
inf.getline(line, sizeof(line));
|
||
const int year = atoi(line);
|
||
CHECKD(year >= 2006 && year <= 3000, "Anno errato:", year);
|
||
srand(883); // Inizializza generatore numeri casuali per l'anno
|
||
encode_string(dninst_key, line);
|
||
ouf << line << '\n';
|
||
srand(year); // Inizializza generatore numeri casuali per i moduli
|
||
|
||
while (!inf.eof())
|
||
{
|
||
inf.getline(line, sizeof(line));
|
||
encode_string(dninst_key, line);
|
||
ouf << line << '\n';
|
||
}
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
#endif
|
||
|
||
const char* split_ass(const int ass_year)
|
||
{
|
||
int year = ass_year, number = 0;
|
||
if (ass_year > 2007)
|
||
{
|
||
year = (ass_year/1000)*1000 + (ass_year%1000)/10;
|
||
number = ass_year%10;
|
||
}
|
||
|
||
TString& tmp = get_tmp_string();
|
||
tmp << year;
|
||
if (number > 0)
|
||
tmp << '/' << number;
|
||
return tmp;
|
||
}
|
||
|
||
|
||
HIDDEN bool show_error(const char* str)
|
||
{
|
||
int app_year, dum1, dum2, dum3;
|
||
TApplication::get_version_info(app_year, dum1, dum2, dum3);
|
||
|
||
TString msg;
|
||
msg << TR("Impossibile aggiornare automaticamente l'assistenza ")
|
||
<< split_ass(app_year) << ":\n" << str << '.';
|
||
return error_box(msg);
|
||
}
|
||
|
||
// Copia il file dninst.zip dal CD/server alla cartella corrente
|
||
bool update_dninst(bool force)
|
||
{
|
||
#ifdef DBG
|
||
if (force && main_app().argc() > 2 && strcmp(main_app().argv(2), "-dninst") == 0)
|
||
{
|
||
build_dninst();
|
||
return true;
|
||
}
|
||
#endif
|
||
|
||
//legge dal diskpath di install.ini la directory da cui aggiornarsi;se il dninst.zip di tale..
|
||
//..directory e' piu' nuovo di quello in locale -> lo copia in locale
|
||
const TFilename local_name = "setup/dninst.zip";
|
||
TConfig ini("install.ini", "Main");
|
||
TFilename remote_name = ini.get("DiskPath");
|
||
remote_name.add(local_name);
|
||
if (remote_name.exist())
|
||
{
|
||
if (!force)
|
||
{
|
||
force = !local_name.exist();
|
||
if (!force)
|
||
{
|
||
const long local_date = xvt_fsys_file_attr(local_name, XVT_FILE_ATTR_MTIME);
|
||
const long remote_date = xvt_fsys_file_attr(remote_name, XVT_FILE_ATTR_MTIME);
|
||
force = remote_date > local_date;
|
||
}
|
||
}
|
||
if (force)
|
||
{
|
||
make_dir(local_name.path());
|
||
fcopy(remote_name, local_name);
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool update_assistance_year()
|
||
{
|
||
if (dongle().hardware() == _dongle_network)
|
||
{
|
||
show_error(TR("Il server di autorizzazioni deve essere disattivato"));
|
||
return false;
|
||
}
|
||
|
||
update_dninst(true);
|
||
|
||
const TFilename dninst = "setup/dninst.zip";
|
||
if (dninst.exist())
|
||
{
|
||
char dninst_key[8] = "";
|
||
|
||
TScanner keys(dninst);
|
||
TString& anno = keys.line();
|
||
srand(883);
|
||
decode_string(dninst_key, anno.get_buffer());
|
||
const int ass_year = atoi(anno);
|
||
if (ass_year > dongle().year_assist())
|
||
{
|
||
const int serno = get_serial_number();
|
||
srand(ass_year);
|
||
while (!keys.eof())
|
||
{
|
||
TString& line = keys.line();
|
||
if (line.empty())
|
||
break;
|
||
decode_string(dninst_key, line.get_buffer());
|
||
const int sn = atoi(line);
|
||
if (sn == serno || line[0] == '*')
|
||
{
|
||
dongle().set_year_assist(ass_year);
|
||
if (dongle().burn())
|
||
{
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
show_error(FR("Errore di scrittura sulla chiave di protezione"));
|
||
return false;
|
||
} //if(dongle().burn...
|
||
} //if(sn==serno...
|
||
} //while(!keys.eof()...
|
||
show_error(TR("Il numero di serie di questa postazione non <20> presente sul database"));
|
||
}
|
||
else //if(ass_year>dongle...
|
||
show_error(TR("L'anno di assistenza sul database e' inferiore a quello registrato sulla chiave di protezione"));
|
||
}
|
||
else
|
||
show_error(TR("Il database dei numeri di serie non <20> accessibile"));
|
||
return false;
|
||
}
|