//--------------------------------------------------------------------------- void __fastcall TForm1::CodeBtnClick(TObject *Sender) { TCode Work; String S = ""; // ask for code if (InputQuery("Usage Code Entry", "Enter the code", S)) { TIniFile* Ini = new TIniFile("ONGUARD.INI"); try { // store the usage code in the ini file if it looks OK if (HexToBuffer(S, &Work, sizeof(Work))) { // save the value Ini->WriteString("Codes", "UsageCode", S); CodeLbl->Caption = S; // tell the code component to test the new code, reporting the results OgUsageCode1->CheckCode(true); } } catch (...) { delete Ini; Ini = 0; } delete Ini; } }
//--------------------------------------------------------------------------- void __fastcall TForm1::OgUsageCode2GetCode(TObject *Sender, TCode &Code) { String S; TheDir = ExtractFilePath(ParamStr(0)); int L = TheDir.Length(); if (L > 3 && TheDir[L] != '\\') TheDir = TheDir + '\\'; if (FileExists(TheDir + "Usage2.INI")) { // open Ini File IniFile = new TIniFile(TheDir + "Usage2.INI"); try { // try to read release code S = IniFile->ReadString("Codes", "Uses", ""); // convert retrieved string to a code HexToBuffer(S, &Code, sizeof(Code)); } catch (...) { delete IniFile; IniFile = 0; } delete IniFile; } }
int TForm1::NumberOfSlots(const String Str) { TCode Code; int Result = -1; if (Str.Length() == sizeof(Code) * 2) { HexToBuffer(Str, &Code, sizeof(Code)); Result = DecodeNAFCountCode(Key, Code); } return Result; }
//--------------------------------------------------------------------------- void __fastcall TForm1::OgUsageCode2Checked(TObject *Sender, TCodeStatus Status) { String S; TCode Code; switch (Status) { case ogValidCode : { Label1->Caption = "Available Runs: " + String((int)OgUsageCode2->GetValue()); return; } case ogRunCountUsed : S = "No more runs allowed\r\n" " Register NOW "; break; case ogInvalidCode : { if (!FileExists(TheDir + "Usage2.INI")) { S = ""; if (InputQuery("Call Vendor NOW", "Code", S)) { if (HexToBuffer(S, &Code, sizeof(Code))) { IniFile = new TIniFile(TheDir + "Usage2.ini"); try { IniFile->WriteString("Codes", "Uses", S); } catch (...) { delete IniFile; IniFile = 0; } delete IniFile; OgUsageCode2->CheckCode(true); return; } else S = "Invalid Code entered"; } else S = "No Code entered"; } else S = "Invalid Code"; break; } case ogCodeExpired : S = "Trial Run period expired\r\n" " Register NOW "; } ShowMessage(S); Application->Terminate(); }
//--------------------------------------------------------------------------- void __fastcall TForm1::OgUsageCode1GetCode(TObject *Sender, TCode &Code) { String S; TIniFile* Ini = new TIniFile("ONGUARD.INI"); try { // get the usage code from the ini file S = Ini->ReadString("Codes", "UsageCode", ""); // convert to proper form HexToBuffer(S, &Code, sizeof(Code)); // set code label caption CodeLbl->Caption = S; } catch (...) { delete Ini; Ini = 0; } delete Ini; }
//--------------------------------------------------------------------------- void __fastcall TForm1::OgDateCode1GetCode(TObject *Sender, TCode &Code) { String S; TDateTime SD; TDateTime ED; // force the INI file to be in the same directory as the application} TheDir = ExtractFilePath(ParamStr(0)); int L = TheDir.Length(); if (L > 3 && TheDir[L] != '\\') TheDir = TheDir + '\\'; // open Ini File} TIniFile* IniFile = new TIniFile(TheDir + "Datep21.INI"); try { // try to read release code} S = IniFile->ReadString("Codes", "DateCode", ""); // If default string returned, create code on the fly} if (S == "") { SD = TDateTime::CurrentDate(); ED = TDateTime::CurrentDate(); ED += 21; InitDateCode(CKey, SD, ED, Code); // save string representation of release code to Ini File} S = BufferToHex(&Code, sizeof(Code)); IniFile->WriteString("Codes", "DateCode", S); } else // convert retrieved string to a code} HexToBuffer(S, &Code, sizeof(Code)); } catch (...) { delete IniFile; } delete IniFile; }
void __fastcall TForm1::LbRSASSA1GetSignature(TObject *Sender, TRSASignatureBlock &Sig) { HexToBuffer(mmoSignature->Text, Sig, sizeof(Sig)); }