Files correlati : Tg2-Odeon ... Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@10257 c028cbd2-c16b-5b4b-a496-9718f37d4682
187 lines
4.2 KiB
C++
Executable File
187 lines
4.2 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <config.h>
|
||
#include <dongle.h>
|
||
#include <os_dep.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);
|
||
for (int i = 0; data[i]; i++)
|
||
__tmp_string[i] = data[i] - (i < 8 ? dninst_key[i] : __tmp_string[i - 8]);
|
||
__tmp_string[i] = '\0';
|
||
strcpy(data, __tmp_string);
|
||
}
|
||
|
||
#ifdef DBG
|
||
|
||
HIDDEN void encode_string(char* dninst_key, char* data)
|
||
{
|
||
build_key(dninst_key);
|
||
|
||
for (int i = 0; data[i]; i++)
|
||
__tmp_string[i] = data[i] + (i < 8 ? dninst_key[i] : data[i - 8]);
|
||
__tmp_string[i] = '\0';
|
||
strcpy(data, __tmp_string);
|
||
}
|
||
|
||
HIDDEN bool build_dninst(const TFilename& name)
|
||
{
|
||
TFilename src = name; src.ext("txt");
|
||
ifstream inf(src, ios::in | ios::nocreate);
|
||
if (inf.good())
|
||
{
|
||
char dninst_key[8] = "";
|
||
|
||
ofstream ouf(name, ios::out | ios::binary);
|
||
char line[256];
|
||
int year = 0;
|
||
while (!inf.eof())
|
||
{
|
||
inf.getline(line, sizeof(line));
|
||
if (year == 0)
|
||
{
|
||
srand(883);
|
||
year = atoi(line);
|
||
CHECKD(year >= 1997 && year <= 2997, "Anno errato:", year);
|
||
}
|
||
|
||
encode_string(dninst_key, line);
|
||
ouf << line << '\n';
|
||
|
||
if (year > 0)
|
||
{
|
||
srand(year);
|
||
year = -1;
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
#endif
|
||
|
||
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 << "Impossibile aggiornare automaticamente l'assistenza "
|
||
<< app_year << ":\n" << str << '.';
|
||
return error_box(msg);
|
||
}
|
||
|
||
HIDDEN int module2number(const TString& mod)
|
||
{
|
||
static TAssoc_array* ass = NULL;
|
||
if (ass == NULL)
|
||
{
|
||
TString8 num;
|
||
TScanner scanner(AUT_FILE);
|
||
ass = new TAssoc_array;
|
||
for (int aut = 0; scanner.line() != ""; aut++)
|
||
{
|
||
num.format("%d", aut);
|
||
const char* cod = scanner.token().left(2);
|
||
ass->add(cod, num);
|
||
}
|
||
}
|
||
int n = 0;
|
||
if (mod.len() == 2)
|
||
{
|
||
const TString* num = (const TString*)ass->objptr(mod);
|
||
if (num)
|
||
n = atoi(*num);
|
||
}
|
||
return n;
|
||
}
|
||
|
||
bool update_dninst(bool force)
|
||
{
|
||
const TFilename keys_name = "dninst.zip";
|
||
if (force || !keys_name.exist())
|
||
{
|
||
TConfig ini("install.ini", "Main");
|
||
TFilename remote_name = ini.get("DiskPath");
|
||
if (os_is_removable_drive(remote_name))
|
||
message_box("Assicuratevi che il CD di installazione sia nel lettore %c:", remote_name[0]);
|
||
remote_name.add(keys_name);
|
||
if (remote_name.exist())
|
||
fcopy(remote_name, keys_name);
|
||
#ifdef DBG
|
||
else
|
||
build_dninst(remote_name);
|
||
#endif
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
bool update_assistance_year()
|
||
{
|
||
update_dninst(TRUE);
|
||
|
||
TScanner keys("dninst.zip");
|
||
bool ok = FALSE;
|
||
if (keys.ok())
|
||
{
|
||
const int serno = get_serial_number();
|
||
int sn = 0;
|
||
char dninst_key[8] = "";
|
||
|
||
TString& anno = keys.line();
|
||
srand(883);
|
||
decode_string(dninst_key, anno.get_buffer());
|
||
const int ass_year = atoi(anno);
|
||
srand(ass_year);
|
||
|
||
while (!keys.eof())
|
||
{
|
||
TString& line = keys.line();
|
||
if (line.empty())
|
||
break;
|
||
decode_string(dninst_key, line.get_buffer());
|
||
sn = atoi(line);
|
||
if (sn == serno)
|
||
{
|
||
/*
|
||
TToken_string moduli(line, ';');
|
||
TString8 mod;
|
||
FOR_EACH_TOKEN(moduli, tok)
|
||
{
|
||
mod = tok;
|
||
const int nmod = module2number(mod);
|
||
if (nmod > 0)
|
||
dongle().deactivate(nmod);
|
||
}
|
||
*/
|
||
dongle().set_year_assist(ass_year);
|
||
if (dongle().burn())
|
||
{
|
||
message_box("Il contratto %d <20> stato attivato automaticamente", ass_year);
|
||
return TRUE;
|
||
}
|
||
else
|
||
{
|
||
show_error("errore di scrittura sulla chiave di protezione");
|
||
return FALSE;
|
||
}
|
||
}
|
||
}
|
||
show_error("il numero di serie di questa postazione non <20> presente sul database");
|
||
}
|
||
else
|
||
show_error("il database dei numeri di serie non <20> accessibile");
|
||
return FALSE;
|
||
}
|