// // DemoAndLicensing.m // // Created by Andrew Salamon on 12/6/07. // Copyright 2007 Machine Perception Laboratory, University of California San Diego. All rights reserved. #include "DemoAndLicensing_Win.h" #include //#include "winreg.h" namespace CERT { DemoAndLicensing_Win::DemoAndLicensing_Win() { } DemoAndLicensing_Win::~DemoAndLicensing_Win() { } bool DemoAndLicensing_Win::readDemoStartDate() { if( getStarted() ) return true; int val; if( !readKey( HKEY_LOCAL_MACHINE, val ) ) { if( !readKey( HKEY_CURRENT_USER, val ) ) { return false; } } // de-obfuscate it and turn it into a date time_t dateNum = deobfuscate( val ); setStartFromTime( dateNum ); return true; } bool DemoAndLicensing_Win::writeDemoStartDate() { if( getStarted() ) return true; time_t dateInt = time( NULL ); time_t dateIntObf = obfuscate( dateInt ); if( !writeKey( HKEY_LOCAL_MACHINE, dateIntObf ) ) { // Possibly also try HKEY_USERS? if( !writeKey( HKEY_CURRENT_USER, dateIntObf ) ) { return false; } } setStartFromTime( dateInt ); return true; } static const char *regKey = "Software\\edu.ucsd.mplab\\cert"; bool DemoAndLicensing_Win::writeKey( HKEY domain, int val ) { HKEY hKey; unsigned long dwDisp; if( RegCreateKeyEx( domain, regKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp ) ) { return false; } DWORD dwData = val; RegSetValueEx( hKey, "CERT1", 0, REG_DWORD, (LPBYTE)&dwData, sizeof(DWORD) ); RegCloseKey( hKey ); return true; } bool DemoAndLicensing_Win::readKey( HKEY domain, int &val ) { HKEY hKey; unsigned long dwDisp; if( RegOpenKeyEx( domain, regKey, 0, KEY_QUERY_VALUE, &hKey ) ) // if( RegCreateKeyEx( domain, regKey, // 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp ) ) { return false; } DWORD dwSize = sizeof(DWORD); DWORD dwDate = 0; unsigned long datatype; RegQueryValueEx( hKey, "CERT1", NULL, &datatype, (LPBYTE)&dwDate, &dwSize ); val = dwDate; RegCloseKey( hKey ); return true; } } // end namespace CERT