Sure. It's just an implementation of a paywall. There are many ways to do this, mostly contingent on the platform. The config data could be stored in the registry or a database, and the triggers are usually time-based, with date-based hash keys to disable them. And we'd insert an easter egg somewhere in the main UI, activated by some keyboard/mouse combination, to disable the self-destruct when required.
For clarity's sake, this simplified demo utilises a run-count and a registration flag stored in a binary file with a hardcoded "kill" code. The easter egg is marked with a red square, and is activated by a control left mouse click on the square. The app will stop working after five runs if the self-destruct is not disabled.
Code: Select all
EnableExplicit
#allowedRuns = 5
#killCode = 123456
#disable = #True
#checkState = #False
#configFile = "app.cfg"
Global appQuit = #False
Global appTitle.s = "App Title"
Define.i x, y, event, wFlags, killCode.s
Procedure throwError()
MessageRequester(appTitle,
"Critical error launching the application. " +
"Please contact technical support for assistance.",
#PB_MessageRequester_Ok | #PB_MessageRequester_Warning)
appQuit = #True
EndProcedure
Procedure selfDestruct(disable)
Define.i runs, licensed, runString.s
If FileSize(#configFile) > -1
If OpenFile(0, #configFile)
If disable
WriteInteger(0, 1)
WriteInteger(0, 0)
SetWindowTitle(0, "App Title (licensed)")
Else
licensed = ReadInteger(0)
runs = ReadInteger(0)
If licensed = 0
If runs => #allowedRuns
throwError()
Else
runs + 1
If runs = #allowedRuns - 1 : runString = " run " : Else : runString = " runs " : EndIf
appTitle + " (unlicensed: " + Str(#allowedRuns - runs) + runString + "remaining)"
FileSeek(0, 0)
WriteInteger(0, 0)
WriteInteger(0, runs)
EndIf
Else
appTitle + " (licensed)"
EndIf
EndIf
CloseFile(0)
Else
throwError()
EndIf
Else
If CreateFile(0, #configFile)
WriteInteger(0, 0)
WriteInteger(0, 1)
CloseFile(0)
EndIf
appTitle + " (unlicensed: " + Str(#allowedRuns - 1) + " runs remaining)"
EndIf
EndProcedure
selfDestruct(#checkState)
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
If OpenWindow(0, 0, 0, 600, 400, appTitle, wFlags)
CanvasGadget(0, 0, 0, 600, 400, #PB_Canvas_Keyboard)
If StartDrawing(CanvasOutput(0))
Box(555, 55, 10, 10, #Red)
StopDrawing()
EndIf
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow
appQuit = #True
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_LeftButtonDown
If GetGadgetAttribute(0, #PB_Canvas_Modifiers) & #PB_Canvas_Control
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
If x > 554 And x < 566 And y > 54 And y < 66
killCode = InputRequester("Disable Self-Destruct", "Kill Code: ",
"", #PB_InputRequester_Password)
If Val(Trim(killCode)) = #killCode
selfDestruct(#disable)
EndIf
EndIf
EndIf
EndSelect
EndSelect
EndSelect
Until appQuit
EndIf
Enjoy!
