Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 2.1 598 git-svn-id: svn://10.65.10.50/trunk@13909 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			184 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			184 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <config.h>
 | 
						||
#include <dongle.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];
 | 
						||
  for (int 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];
 | 
						||
  for (int 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 | ios::nocreate);
 | 
						||
  if (inf.good())
 | 
						||
  {                   
 | 
						||
    char dninst_key[8] = "";
 | 
						||
  
 | 
						||
    ofstream ouf("dninst.zip", 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 >= 2005 && year <= 3000, "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 << TR("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)
 | 
						||
{                             
 | 
						||
#ifdef DBG
 | 
						||
  if (force && main_app().argc() > 2 && strcmp(main_app().argv(2), "-dninst") == 0)
 | 
						||
  {
 | 
						||
    build_dninst();
 | 
						||
    return true;
 | 
						||
  }
 | 
						||
#endif  
 | 
						||
 | 
						||
  const TFilename keys_name = "dninst.zip";
 | 
						||
  if (force || !keys_name.exist())
 | 
						||
  {
 | 
						||
    TConfig ini("install.ini", "Main");
 | 
						||
    TFilename remote_name = ini.get("DiskPath");
 | 
						||
    if (xvt_fsys_is_removable_drive(remote_name))
 | 
						||
      message_box(FR("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);
 | 
						||
  } 
 | 
						||
  return true;
 | 
						||
}
 | 
						||
 | 
						||
bool update_assistance_year()
 | 
						||
{   
 | 
						||
  update_dninst(true);
 | 
						||
 | 
						||
  const TFilename dninst = "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())
 | 
						||
          {
 | 
						||
            message_box(FR("Il contratto %d <20> stato attivato automaticamente"), ass_year);
 | 
						||
            return TRUE;
 | 
						||
          }
 | 
						||
          else
 | 
						||
          {
 | 
						||
            show_error(FR("Errore di scrittura sulla chiave di protezione"));
 | 
						||
            return FALSE;
 | 
						||
          }
 | 
						||
        }
 | 
						||
      }
 | 
						||
      show_error(TR("Il numero di serie di questa postazione non <20> presente sul database"));
 | 
						||
    }
 | 
						||
    else
 | 
						||
      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;
 | 
						||
}
 |