📄 onguard.pas
字号:
constructor TOgCodeBase.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FAutoCheck := DefAutoCheck;
FStoreCode := DefStoreCode;
FStoreModifier := DefStoreModifier;
{$IFDEF TRIALRUN}
_CC_;
_VC_;
{$ENDIF}
end;
procedure TOgCodeBase.DoOnChecked(Value : TCodeStatus);
begin
if Assigned(FOnChecked) then
FOnChecked(Self, Value)
else if FAutoCheck then
raise EOnGuardException.CreateFmt(StrRes[SCNoOnCheck], [Self.ClassName]);
end;
function TOgCodeBase.DoOnGetCode : TCode;
begin
FillChar(Result, SizeOf(Result), 0);
if FStoreCode then
Result := FCode
else begin
if Assigned(FOnGetCode) then
FOnGetCode(Self, Result)
else
raise EOnGuardException.CreateFmt(StrRes[SCNoOnGetCode], [Self.ClassName]);
end;
{store code for easy access using the Code property} {!!.02}
FCode := Result; {!!.02}
end;
procedure TOgCodeBase.DoOnGetKey(var Key : TKey);
begin
FillChar(Key, SizeOf(TKey), 0);
if Assigned(FOnGetKey) then
FOnGetKey(Self, Key)
else
raise EOnGuardException.CreateFmt(StrRes[SCNoOnGetKey], [Self.ClassName]);
end;
{!!.02} {revised}
function TOgCodeBase.DoOnGetModifier : LongInt;
var
L : LongInt;
begin
Result := 0;
if FStoreModifier then
Result := FModifier
else if Assigned(FOnGetModifier) then begin
FOnGetModifier(Self, L);
if FStoreModifier then begin
{byte and word swap the modifier}
TLongIntRec(Result).HiHi := TLongIntRec(L).LoLo;
TLongIntRec(Result).HiLo := TLongIntRec(L).LoHi;
TLongIntRec(Result).LoHi := TLongIntRec(L).HiLo;
TLongIntRec(Result).LoLo := TLongIntRec(L).HiHi;
end else
Result := L;
end;
{store modifier for easy access using the Modifier property} {!!.02}
FModifier := Result; {!!.02}
end;
function TOgCodeBase.GetCode : string;
var
Work : TCode;
begin
Result := '$' + BufferToHex(FCode, SizeOf(FCode));
if not HexToBuffer(Result, Work, SizeOf(Work)) then
Result := '';
if HexStringIsZero(Result) then
Result := '';
end;
function TOgCodeBase.GetModifier : string;
var
Work : LongInt;
begin
Result := '$' + BufferToHex(FModifier, SizeOf(FModifier));
if not HexToBuffer(Result, Work, SizeOf(Work)) then
Result := '';
if HexStringIsZero(Result) then
Result := '';
end;
function TOgCodeBase.GetAbout : string; {!!.08}
begin
Result := OgVersionStr;
end;
function TOgCodeBase.IsCodeValid : Boolean;
begin
Result := (CheckCode(False) = ogValidCode);
end;
procedure TOgCodeBase.Loaded;
begin
inherited Loaded;
if FAutoCheck and not (csDesigning in ComponentState) then
CheckCode(True);
end;
procedure TOgCodeBase.SetCode(const Value : string);
begin
if not HexToBuffer(Value, FCode, SizeOf(FCode)) then
FillChar(FCode, SizeOf(FCode), 0);
end;
procedure TOgCodeBase.SetModifier(const Value : string);
begin
if not HexToBuffer(Value, FModifier, SizeOf(FModifier)) then
FModifier := 0;
end;
procedure TOgCodeBase.SetAbout(const Value : string); {!!.08}
begin
end;
{*** TOgDateCode ***}
function TOgDateCode.CheckCode(Report : Boolean) : TCodeStatus;
var
Code : TCode;
Key : TKey;
Modifier : LongInt;
begin
Result := ogValidCode;
DoOnGetKey(Key);
Code := DoOnGetCode;
Modifier := DoOnGetModifier;
ApplyModifierToKeyPrim(Modifier, Key, SizeOf(Key));
if IsDateCodeValid(Key, Code) then begin
if IsDateCodeExpired(Key, Code) then
Result := ogPastEndDate;
end else
Result := ogInvalidCode;
if Report then
DoOnChecked(Result);
end;
function TOgDateCode.GetValue : TDateTime;
var
Code : TCode;
Key : TKey;
Modifier : LongInt;
begin
DoOnGetKey(Key);
Code := DoOnGetCode;
Modifier := DoOnGetModifier;
ApplyModifierToKeyPrim(Modifier, Key, SizeOf(Key));
Result := GetDateCodeValue(Key, Code);
end;
{*** TOgDaysCode ***}
function TOgDaysCode.CheckCode(Report : Boolean) : TCodeStatus;
var
Code : TCode;
Key : TKey;
Modifier : LongInt;
begin
Result := ogValidCode;
DoOnGetKey(Key);
Code := DoOnGetCode;
Modifier := DoOnGetModifier;
ApplyModifierToKeyPrim(Modifier, Key, SizeOf(Key));
if IsDaysCodeValid(Key, Code) then begin
if IsDaysCodeExpired(Key, Code) then begin
Result := ogDayCountUsed;
if GetExpirationDate(Key, Code) < Date then
Result := ogCodeExpired;
end;
end else
Result := ogInvalidCode;
if Report then
DoOnChecked(Result);
end;
constructor TOgDaysCode.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FAutoDecrease := DefAutoDecrease;
{$IFDEF TRIALRUN}
_CC_;
_VC_;
{$ENDIF}
end;
procedure TOgDaysCode.Decrease;
var
Code : TCode;
Work : TCode;
Key : TKey;
Modifier : LongInt;
begin
DoOnGetKey(Key);
Code := DoOnGetCode;
Work := Code;
Modifier := DoOnGetModifier;
ApplyModifierToKeyPrim(Modifier, Key, SizeOf(Key));
{code is only decreased once per day - no matter how many times called}
DecDaysCode(Key, Work);
{save code if it was changed}
if (Work.CheckValue <> Code.CheckValue) or (Work.Days <> Code.Days) then
DoOnChangeCode(Work);
end;
procedure TOgDaysCode.DoOnChangeCode(Value : TCode);
begin
if Assigned(FOnChangeCode) then
FOnChangeCode(Self, Value)
else
raise EOnGuardException.CreateFmt(StrRes[SCNoOnChangeCode], [Self.ClassName]);
end;
function TOgDaysCode.GetValue : LongInt;
var
Code : TCode;
Key : TKey;
Modifier : LongInt;
begin
DoOnGetKey(Key);
Code := DoOnGetCode;
Modifier := DoOnGetModifier;
ApplyModifierToKeyPrim(Modifier, Key, SizeOf(Key));
Result := GetDaysCodeValue(Key, Code);
end;
procedure TOgDaysCode.Loaded;
begin
inherited Loaded;
if FAutoDecrease and not (csDesigning in ComponentState) then
Decrease;
end;
{*** TOgMakeCodes ***}
constructor TOgMakeCodes.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FCodeType := DefCodeType;
FShowHints := False;
{$IFDEF TRIALRUN}
_CC_;
_VC_;
{$ENDIF}
end;
function TOgMakeCodes.Execute : Boolean;
{$IFNDEF NoMakeCodesSupport} {!!.10}
var
F : TCodeGenerateFrm;
{$ENDIF} {!!.10}
begin
{$IFNDEF NoMakeCodesSupport} {!!.10}
F := TCodeGenerateFrm.Create(Owner);
try
F.CodeType := FCodeType;
F.SetKey(FKey); {!!.08}
F.KeyType := FKeyType;
F.KeyFileName := FKeyFileName;
F.ShowHint := FShowHints;
Result := F.ShowModal = mrOK;
if Result then begin
FCode := F.Code;
F.GetKey(FKey); {!!.08}
FKeyType := F.KeyType;
FKeyFileName := F.KeyFileName;
end;
finally
F.Free;
end;
{$ELSE} {!!.10}
Result := False; {!!.10}
{$ENDIF} {!!.10}
end;
function TOgMakeCodes.GetAbout : string; {!!.08}
begin
Result := OgVersionStr;
end;
procedure TOgMakeCodes.SetAbout(const Value : string); {!!.08}
begin
end;
procedure TOgMakeCodes.GetCode(var Value : TCode); {!!.08}
begin
Value := FCode;
end;
procedure TOgMakeCodes.SetCode(Value : TCode); {!!.08}
begin
FCode := Value;
end;
procedure TOgMakeCodes.GetKey(var Value : TKey); {!!.08}
begin
Value := FKey;
end;
procedure TOgMakeCodes.SetKey(Value : TKey); {!!.08}
begin
FKey := Value;
end;
{*** TOgMakeKeys ***}
constructor TOgMakeKeys.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
FKeyType := DefKeyType;
FShowHints := False;
{$IFDEF TRIALRUN}
_CC_;
_VC_;
{$ENDIF}
end;
function TOgMakeKeys.Execute : Boolean;
{$IFNDEF NoMakeCodesSupport} {!!.10}
var
F : TKeyMaintFrm;
{$ENDIF} {!!.10}
begin
{$IFNDEF NoMakeCodesSupport} {!!.10}
F := TKeyMaintFrm.Create(Owner);
try
F.SetKey(FKey); {!!.08}
F.KeyType := FKeyType;
F.KeyFileName := FKeyFileName;
F.ShowHint := FShowHints;
Result := F.ShowModal = mrOK;
if Result then begin
F.GetKey(FKey); {!!.08}
FKeyType := F.KeyType;
FKeyFileName := F.KeyFileName;
end;
finally
F.Free;
end;
{$ELSE} {!!.10}
Result := False; {!!.10}
{$ENDIF} {!!.10}
end;
procedure TOgMakeKeys.ApplyModifierToKey(Modifier : LongInt; var Key; KeySize : Cardinal);
begin
ApplyModifierToKeyPrim(Modifier, Key, KeySize);
end;
function TOgMakeKeys.GenerateDateModifier(D : TDateTime) : LongInt;
begin
Result := GenerateDateModifierPrim(D);
end;
function TOgMakeKeys.GenerateMachineModifier : LongInt;
begin
Result := GenerateMachineModifierPrim;
end;
procedure TOgMakeKeys.GenerateMDKey(var Key; KeySize : Cardinal; const Str : string);
begin
GenerateTMDKeyPrim(Key, KeySize, Str);
end;
procedure TOgMakeKeys.GenerateRandomKey(var Key; KeySize : Cardinal);
begin
GenerateRandomKeyPrim(Key, KeySize);
end;
function TOgMakeKeys.GenerateUniqueModifier : LongInt;
begin
Result := GenerateUniqueModifierPrim;
end;
function TOgMakeKeys.GenerateStringModifier(const S : string) : LongInt;
begin
Result := GenerateStringModifierPrim(S);
end;
function TOgMakeKeys.GetAbout : string; {!!.08}
begin
Result := OgVersionStr;
end;
procedure TOgMakeKeys.SetAbout(const Value : string); {!!.08}
begin
end;
procedure TOgMakeKeys.GetKey(var Value : TKey); {!!.08}
begin
Value := FKey;
end;
procedure TOgMakeKeys.SetKey(Value : TKey); {!!.08}
begin
FKey := Value;
end;
{*** TOgRegistrationCode ***}
function TOgRegistrationCode.CheckCode(Report : Boolean) : TCodeStatus;
var
Code : TCode;
Key : TKey;
Modifier : LongInt;
{RegStr : string;} {!!.02}
begin
Result := ogValidCode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -