;Intercept.wbt Intercepts program command-line parameters
CR=strcat(num2char(13),num2char(10)) ;Carriage Return
tabchr=Num2Char(9) ;Tab
ExeName=WinName()
WinHide("%ExeName%")
ExeName=StrUpper(StrSub(ExeName,7,-1))
Vdot=FileVerInfo(ExeName, "", "FileVersion")
ExeRoot=StrUpper(FileRoot(ExeName))
Path2Exe=FileLocate("%ExeName%") ;Go find where default.wbt lives
Path2Exe=StrUpper(FilePath(Path2Exe))
err=0
;DEBUG(@ON)
if IsKeyDown(@SHIFT)==@YES then Debug(@ON)
if IsKeyDown(@CTRL)==@YES then goto MANAGE
Parameters=""
:REDIRECTED
x=param0
if x=="0" then goto NOPARAMETERS
for y=1 to x
Parameters=StrCat(Parameters," ",param%y%)
Next
AskLine("Parameters","%Path2Exe%\%ExeName% has the following passed parameters%CR%",Parameters)
Run("C:\INTERCEPT\%ExeName%","%Parameters%")
Exit
:NOPARAMETERS
if AskYesNo("No Parameters","%Path2Exe%\%ExeName% has no parameters%CR%%CR%Continue without parameters?")==@NO then Exit
Run("C:\INTERCEPT\%ExeName%","")
Exit
:MANAGE
InterceptFormat=`WWWDLGED,5.0`
InterceptCaption=`Program Interceptor (v. %vdot%)`
InterceptX=90
InterceptY=109
InterceptWidth=115
InterceptHeight=106
InterceptNumControls=8
Intercept01=`18,84,36,DEFAULT,PUSHBUTTON,DEFAULT,"&OK",1`
Intercept02=`58,84,36,DEFAULT,PUSHBUTTON,DEFAULT,"&Cancel",0`
Intercept03=`20,24,64,DEFAULT,RADIOBUTTON,Option,"&Intercept",1`
Intercept04=`20,64,64,DEFAULT,RADIOBUTTON,Option,"&Restore",2`
Intercept05=`10,4,90,DEFAULT,STATICTEXT,DEFAULT,"Select to INTERCEPT a program-call"`
Intercept06=`10,44,90,DEFAULT,STATICTEXT,DEFAULT,"Select to RESTORE a previously"`
Intercept07=`10,12,102,DEFAULT,STATICTEXT,DEFAULT,"and identify the command line parameters"`
Intercept08=`10,52,64,DEFAULT,STATICTEXT,DEFAULT,"'Intercepted' program"`
ButtonPushed=Dialog("Intercept")
if Option=="1" then goto INTERCEPT
if Option=="2" then goto RESTORE
:INTERCEPT
FileTypes="EXE Files|*.EXE|All Files|*.*"
Program=AskFileName("Select Program", Path2Exe,filetypes, "", 1)
if Program=="" then goto NOSELECTION
if DirExist("C:\INTERCEPT")==@FALSE then DirMake("C:\INTERCEPT")
FileMove(Program,"C:\INTERCEPT",@TRUE)
FileCopy("%Path2Exe%\%ExeName%",Program,@TRUE)
ProgramRoot=FileRoot(Program)
IniWritePvt("PROGRAMS",ProgramRoot,Program,"C:\INTERCEPT\INTERCEPT.INI")
Message("%ProgramRoot% Intercepted","%Program% has been intercepted, and moved to C:\INTERCEPT.%CR%%CR%To restore, run this program again while holding down the CTRL key.")
Exit
:RESTORE
if FileExist("C:\INTERCEPT\INTERCEPT.INI")==@FALSE then goto NONEYET
Programs=IniItemizePvt("PROGRAMS","C:\INTERCEPT\INTERCEPT.INI")
if Programs=="" then goto NONELEFT
;FileTypes="EXE Files|*.EXE|All Files|*.*"
;Program=AskFileName("Select Program","C:\INTERCEPT",filetypes, "", 1)
Program=AskItemList("Restore Program",Programs,@TAB,@sorted,@single)
if Program=="" then goto NOSELECTION
;ProgramRoot=FileRoot(Program)
Destination=IniReadPvt("PROGRAMS",Program,"","C:\INTERCEPT\INTERCEPT.INI")
if FileMove("C:\INTERCEPT\%Program%.EXE",Destination,@TRUE)==@FALSE then goto ABORTED
IniDeletePvt("PROGRAMS",Program,"C:\INTERCEPT\INTERCEPT.INI")
Message("Restored","%Program% has been moved back to %Destination%")
Exit
:NONELEFT
Message("None to Restore","No Programs are left to be restored from having been intercepted")
Exit
:NONEYET
Message("First Time Run","No Programs have yet been intercepted")
Exit
:NOSELECTION
Message("DUH!","Nothing selected, nothing to do!")
Exit
:ABORTED
Message("ABORT","The restore of %Program% to %Destination% was aborted.")
Exit