licUtiles_V2017/Licencia.cpp

125 lines
3.4 KiB
C++

#include "StdAfx.h"
#include "Licencia.h"
#include "utl.h"
#include "dir_manager.h"
#include "b_file.h"
#include "LicUtilesDef.h"
#include "_app.h"
//*********************************************************************************************************************
Licencia::Licencia(void)
{
clear();
}
void Licencia::clear()
{
memset(this, 0, sizeof(Licencia));
id = -1;
}
//*********************************************************************************************************************
Licencia::~Licencia(void)
{
}
//*********************************************************************************************************************
void* Licencia::getLic( void *buf )
{
memcpy(buf,this, sizeof(Licencia));
Cutl::cifra1((BYTE*)buf, sizeof(Licencia));
return buf;
}
//*********************************************************************************************************************
Licencia* Licencia::setLic( void *buf )
{
Cutl::descifra1((BYTE*)buf, sizeof(Licencia));
*this=*(Licencia*)buf;
return this;
}
//*********************************************************************************************************************
char* Licencia::getIdm( char *buf )
{
return Cutl::id_pc(buf,128);
}
//*********************************************************************************************************************
bool Licencia::fillLic( char* pathProducto /*= 0;*/ )
{
char path[256];
strcpy(LicServerUrl, LU_DEFAULT_SERVER);
puertoServerLic = LU_DEFAULT_PUERTO;
Cutl::getWinUser(path)[31] = 0;
strcpy(nombre_user,path);
if(pathProducto)
strcpy(path, pathProducto);
else
{
if(C_app::GetApp()->archi.path_ejecutable[0] == 0)
{
if(!C_app::GetApp()->archi.rellena_dirs_ejecucion())
return false;
}
strcpy(path,C_app::GetApp()->archi.path_ejecutable);
}
if(!getIdm(idm))
return false;
if(!Cdir_manager::getVersionFile(path,version_producto))
return false;
char name[32];
if(!Cdir_manager::nombre_archivo(path,name))
return false;
char *ext =Cdir_manager::extension_archivo(name);
if(ext)
*(ext-1)=0;
strcpy(nombre_producto, name);
return true;
}
//*********************************************************************************************************************
bool Licencia::leeLic( Cb_file * f )
{
int i;
Licencia buf;
if(!f->lee(&i, sizeof(int)) || i != VERSION_LICENCIA)
return false;
if(!f->lee(&buf, sizeof(buf)))
return false;
setLic(&buf);
*this = buf;
return true;
}
//*********************************************************************************************************************
bool Licencia::grabaLic( Cb_file * f )
{
int i=VERSION_LICENCIA;
Licencia buf;
if(!f->escribe(&i, sizeof(int)))
return false;
if(!f->escribe(getLic(&buf), sizeof(Licencia)))
return false;
return true;
}
//*********************************************************************************************************************
void Licencia::set_nulls()
{
clave[31]=0;
nombre_user[31]=0;
version_producto[31]=0;
idm[127]=0;
nombre_producto[127]=0;
instaUsu[31]=0;
instaKey[31]=0;
instaVersion[31]=0;
}
//*********************************************************************************************************************
bool Licencia::fillidmYuser()
{
char buf[256];
Cutl::getWinUser(buf)[31] = 0;
strcpy(nombre_user,buf);
return getIdm(idm)!= NULL;
}
//*********************************************************************************************************************