WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Script Viewer


;******************************************************************************
;          		Program Information
;******************************************************************************
; ScriptLib.wbt
; Created by Brad Sjue 
; Date: November 21, 2003 
; This script will itemize scripts in a dir for a view.  

; Revisions:
; Changed from INI format to a flat file for performance reasons.  

;******************************************************************************
;          		Initialize Program
;******************************************************************************

;Optional Debugging
If IsKeyDown(@SHIFT || @CTRL)    
	sTrcFile = Strcat(Environment("TEMP"),"\~ScriptLib.trc")
	If FileExist(sTrcFile) Then FileDelete(sTrcFile)
	DebugTrace(@ON,sTrcFile)
Endif

CurrPath = FilePath(IntControl (1004, 0, 0, 0, 0))

SCRLIBDB = StrCat(CurrPath, "ScrLib.db")

;Add the File Searcher Extender for gathering file list.  
AddExtender("wsrch34i.dll")

;Disable multiple selections
IntControl(33, 0, 0, 0, 0)
;Set the min,max, control buttons
IntControl (49, 1, 0, 0, 0)


;******************************************************************************
;          		Subroutines and SubRoutines
;******************************************************************************
;==============================================================================
;		UDF_LISTSCRIPTS	
;==============================================================================
#DefineFunction UDF_ListScripts(SCRLIBDB)
sScrList = ""
fh=fileopen(SCRLIBDB, "READ")
while @TRUE             ; Loop till break do us end
    x = FileRead(fh)
    If x == "*EOF*" Then Break
	sScrList = StrCat(sScrList, StrCat(FileRoot(x),".",FileExtension(x)), @TAB)
endwhile
FileClose(fh)
Return sScrList
#EndFunction

;==============================================================================
;		UDF_GETFULLFILE	
;==============================================================================
#DefineFunction UDF_GETFULLFILE(FullFilePath)
	Return StrCat(FileRoot(FullFilePath), ".", Strlower(FileExtension(FullFilePath)))
#EndFunction

;==============================================================================
;		UDF_FILTERLIST	
;==============================================================================
#DefineFunction UDF_FilterList(Filter, SCRLIBDB)
	FilterRs=''
	fh=fileopen(SCRLIBDB, "READ")
	while @TRUE             ; Loop till break do us end
	    x = FileRead(fh)
	    If x == "*EOF*" Then Break
			If StrIndexNc( x, Filter, 1, @Fwdscan) != 0 
				FilterRs=ItemInsert( FileRoot(x), -1, FilterRs, @TAB )
			Endif
	endwhile
	FileClose(fh)

	Return ItemSort(FilterRs, @TAB )
#EndFunction

;==============================================================================
;		UDS_FTSEARCH	
;==============================================================================
#DefineSubroutine UDS_FTSEARCH()
	Keywords = AskLine( 'Full Text Search', 'Please enter keyword to search for', '' )
	If Keywords == '' Then Return 'No Keywords specified'
	ScriptList = FileGet(SCRLIBDB)
	ScriptList = StrReplace( ScriptList, @CRLF, @TAB )
	ScrCnt = ItemCount(ScriptList, @TAB)
	FTRslt = ''
	For x = 1 to ScrCnt
		ThisLocation = ItemExtract( x, ScriptList, @TAB )
		If !FileExist(ThisLocation) Then Continue
		fs1 = FileSize( ThisLocation )
		binbuf1 = binaryalloc( fs1 + 5000)
		a1 = BinaryRead( binbuf1, ThisLocation )
		a = BinaryIndexEx( binbuf1, 0, Keywords, @FWDSCAN ,0);find Keywords
		if a == -1
			binbuf1=BinaryFree(binbuf1)
			Drop(a, a1, fs1, binbuf1)
			Continue 
		else
			FTRslt = ItemInsert( FileRoot(ThisLocation), -1, FTRslt, @TAB )
		endif
		binbuf1=BinaryFree(binbuf1)
		Drop(a, a1, fs1, binbuf1)
	Next
	Return FTRslt
#EndSubroutine

;==============================================================================
;		UDF_GETCAT	
;==============================================================================
#DefineFunction UDF_GetCat(SCRLIBDB)
CatList = ''
fh=fileopen(SCRLIBDB, "READ")
while @TRUE             ; Loop till break do us end
    x = FileRead(fh)
    If x == "*EOF*" Then Break
		ProjPath = FilePath (x)
		IF StrSub(ProjPath,StrLen(ProjPath),1)=="\" THEN ProjPath=StrSub(ProjPath,1,StrLen(ProjPath)-1) ; Remove last trailing slash. 
		If ItemLocate (ProjPath, CatList, @TAB) == 0 Then CatList = ItemInsert( ProjPath, -1, CatList, @TAB )
endwhile
FileClose(fh)

SelProj = AskItemList("Category Listing", CatList, @tab, @sorted, @single)
Return SelProj
#EndFunction

;==============================================================================
;		UDS_INIT_DD_CONSTANTS	
;==============================================================================
#DefineSubroutine UDS_Init_DD_Constants()
   ;DialogprocOptions Constants
   MSG_INIT=0                ; The one-time initilization
   MSG_TIMER=1               ; Timer event
   MSG_BUTTONPUSHED=2        ; Pushbutton or Picturebutton
   MSG_RADIOPUSHED=3         ; Radiobutton clicked
   MSG_CHECKBOX=4            ; Checkbox clicked
   MSG_EDITBOX=5             ; Editbox or Multilinebox
   MSG_FILESELECT=6          ; Filelistbox
   MSG_ITEMSELECT=7          ; Itembox
   MSG_COMBOCHANGE=8         ; Combobox/Droplistbox
   MSG_Calendar=9            ; Calendar date change
   MSG_SPINNER=10            ; Spinner number change
   MSG_CLOSEVIA49=11         ; Close clicked (Enabled via Intcontrol 49)
   MSG_FILEBOXDOUBLECLICK=12 ; Get douvle-click message on a FileListBox
   MSG_ITEMOXDOUBLECLICK=13  ; Get douvle-click message on an ItemBox
   DPO_DISABLESTATE=1000     ; codes -1=GetSetting 0=EnableDialog 1=DisableDialog
   DPO_CHANGEBACKGROUND=1001 ; -1=GetSetting otherise bitmap or color string
   ;DialogControlState Constants
   DCSTATE_SETFOCUS=1        ; Give Control Focus
   DCSTATE_QUERYSTYLE=2      ; Query control's style
   DCSTATE_ADDSTYLE=3        ; Add control style
   DCSTATE_REMOVESTYLE=4     ; Remove control style
   DCSTATE_GETFOCUS=5        ; Get control that has focus
   DCSTYLE_INVISIBLE=1       ; Set Control Invisible
                             ; ALL controls
   DCSTYLE_DISABLED=2        ; Set Control Disabled
                             ; PUSHBUTTON RADIOBUTTON CHECKBOX PICTUREBUTTON EDITBOX 
                             ; MULTILINEBOX ITEMBOX FILELISTBOX CALENDAR DROPLISTBOX 
                             ; SPINNER GROUPBOX VARYTEXT STATICTEXT
   DCSTYLE_NOUSERDATA=4      ; Note: Setable via DialogControlState SubRoutine ONLY
                             ; SPINNER control only
   DCSTYLE_READONLY=8        ; Sets control to read-only (user cannot type in data)
                             ; EDITBOX MULTILINEBOX SPINNER
   DCSTYLE_PASSWORD=16       ; Sets "password mode" where only *'s are displayed
                             ; EDITBOX
   DCSTYLE_DEFAULTBUTTON=32  ; Sets a button as a the default button
                             ; PUSHBUTTON PICTUREBUTTON
   DCSTYLE_DIGITSONLY=64     ; Set edit box to accept digits only
                             ; EDITMOX MULTILINEBOX
   ;DialogControlSet / DialogControlGet Constants
   DC_CHECKBOX=1             ; CHECKBOX
   DC_RADIOBUTTON=2          ; RADIOBUTTON
   DC_EDITBOX=3              ; EDITBOX MULTILINEBOX
   DC_TITLE=4                ; PICTURE RADIOBUTTON CHECKBOX PICTUREBUTTON VARYTEXT
                             ; STATICTEXT GROUPBOX PUSHBUTTON
   DC_ITEMBOXCONTENTS=5      ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_ITEMBOXSELECT=6        ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_CALENDAR=7             ; CALENDAR
   DC_SPINNER=8              ; SPINNER
   DC_MULTITABSTOPS=9        ; MULTILINEBOX
   DC_ITEMSCROLLPOS=10       ; ITEMBOX FILELISTBOX
   DC_BACKGROUNDCOLOR=11     ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON
                             ; ITEMBOX FILELISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX
   DC_PICTUREBITMAP=12       ; PICTURE PICTUREBUTTON
   DC_TEXTCOLOR=13           ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON
                             ; ITEMBOX FIELLISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX
   DC_ITEMBOXADD=14          ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_ITEMBOXREMOVE=15       ; ITEMBOX FILELISTBOX DROPLISTBOX
   return 0
#EndSubroutine

;==============================================================================
;		Dialog Subroutine	
;==============================================================================

#DefineSubRoutine DlgProc(Handle,DlgMsg,DlgID,rsvd1,rsvd2)

switch DlgMsg
	case MSG_INIT
		DialogProcOptions(Handle,MSG_BUTTONPUSHED,@TRUE)
		DialogProcOptions(Handle, MSG_ITEMSELECT, @TRUE)           ; Pass item listbox selection changes.
		DialogProcOptions(Handle,MSG_EDITBOX,@TRUE)
		return(-1)
	
	CASE MSG_ITEMSELECT
		sSelection = DialogControlGet(Handle,SCRIPTLISTBOX,DC_ITEMBOXSELECT) ; Get selection for SCRIPTLISTBOX
		If sSelection == ""
			sSelection = "Unknown"
			Message("Item Could Not Be Found", "ERROR - Item Could not be determined, please select another script")
			Return (-2)
		Endif
		
; 		ScrLoc = IniReadPvt (sSelection, "FileLocation", "Unknown FileName", SCRLIBDB)
	fh=fileopen(SCRLIBDB, "READ")
	while @TRUE             ; Loop till break do us end
        x = FileRead(fh)
        If x == "*EOF*" Then Break
			If StrIndexNc( x, sSelection, 1, @Fwdscan) != 0 
				ScrLoc = x
				break
			Endif
	endwhile
		
		If !FileExist(ScrLoc) 
			ThisScript = "File Not Found"
			DialogControlSet(Handle,SCREDITBOX,DC_TITLE,'File Not Found')   ; Set text for static text control
		Else
			ThisScript = FileGet(ScrLoc)
			DialogControlSet(Handle,SCREDITBOX,DC_EDITBOX,ThisScript)   ; Set the edit text
			DialogControlSet(Handle,SCREDITBOX,DC_ITEMSCROLLPOS,1)   ; Scroll to top
		Endif
		break
		
	CASE MSG_EDITBOX
	switch DlgID	
		CASE FILTERBOX	
			DialogControlState(Handle,FILTERBTN,DCSTATE_ADDSTYLE,DCSTYLE_DEFAULTBUTTON) ;Set the control to the filter button
			return(-2)
	Endswitch
			 
	case MSG_BUTTONPUSHED
		switch DlgID
		CASE 001	;Exit Button
		  return(-1)

		CASE FILTERBTN
			FilterTxt = DialogControlGet(Handle, FILTERBOX, DC_EDITBOX)      ; Get text in Edit Box
			If FilterTxt == ""
				Message("Missing Criteria", "Search text cannot be blank")
				Return (-2)
			Endif
			FilteredList = UDF_FilterList(FilterTxt, SCRLIBDB)
			DialogControlSet(Handle,SCRIPTLISTBOX,DC_ITEMBOXCONTENTS,FilteredList)
			Return(-2)
		CASE CLIPITBTN  ;CLIPIT BUTTON
			If !IsDefined(ThisScript)
				Message("No File Selected", "Error no file selected, select a file and then try again")
				Return(-2)
			Endif

			Clipput(ThisScript)
			Display(1, "Script placed in the clipboard", "Done")
			return(-2)
		CASE FULLTEXTBTN  ;Full Text BUTTON

			DialogProcOptions(Handle,DPO_DISABLESTATE,1)	;Disable Dialog
			FTRslts = UDS_FTSEARCH() ;Run the FT UDS. 
			If FTRslts == ''
				Message('Full Text Search', 'No Results found')
				Return(-2)
			Endif
			FilterTxt = DialogControlSet(Handle, FILTERBOX, DC_EDITBOX,'') ;Set the Filter text box to nothing.
			DialogControlSet(Handle,SCRIPTLISTBOX,DC_ITEMBOXCONTENTS,FTRslts)	;Update the script box with contents. 
			DialogProcOptions(Handle,DPO_DISABLESTATE,0)	;Enable Dialog
			Return(-2)
		CASE LISTSCRBTN ; List all scripts. 
			sScrList = UDF_ListScripts(SCRLIBDB)
			DialogControlSet(Handle,SCRIPTLISTBOX,DC_ITEMBOXCONTENTS,sScrList)
			FilterTxt = DialogControlSet(Handle, FILTERBOX, DC_EDITBOX,'') ;Set the Filter text box to nothing.
			Return(-2)
		
		CASE LISTCATBTN ; List Categories. 
			CatList = UDF_GetCat(SCRLIBDB)
			FilteredList = UDF_FilterList(CatList, SCRLIBDB)
			DialogControlSet(Handle, FILTERBOX, DC_EDITBOX, CatList)      ; Set text in filter box to reflect difference
			DialogControlSet(Handle,SCRIPTLISTBOX,DC_ITEMBOXCONTENTS,FilteredList)
			Return(-2)		
					
		endswitch    ;DlgID
	return(-1)      ;  Do default processing

endswitch       ; DlgMsg
   return(-1)      ;  Do default processing
#EndSubRoutine       ;End of Dialog Callback DlgProc




;******************************************************************************
;          		Main Program
;******************************************************************************
; Load the dialog constants
UDS_Init_DD_Constants()

; Initialize the script list the first time.  
If !FileExist(SCRLIBDB)
	flags=1|2|4
	ScriptDir=AskDirectory("Select Directory for Winbatch Scripts to Catalog", "", "","Are you sure?",flags)
	BoxOpen ("Script Library", "Initializing")
	handle=srchInit(ScriptDir,"*.wbt","","",16)   ; Only do .wbt files
	fh=fileopen(SCRLIBDB, "WRITE")
; 	handle=srchInit(ScriptDir,"*.*","","",16)   ; Do all files
	while 1
	   ScrFile=srchNext(handle)
	   if ScrFile=="" then break
		filewrite(fh, ScrFile)
		BoxText(StrCat("Cataloging ", ScrFile))
	endwhile
	srchFree(handle)
	fileclose(fh)
	BoxShut()
Endif

BoxOpen("Script Library", "Initializing Script Listing")
sScrList = UDF_ListScripts(SCRLIBDB)
BoxShut()
;******************************************************************************
;          		Dialogs
;******************************************************************************


SCRIPTLISTBOX=002
SCREDITBOX=003
FILTERBTN=005
FILTERBOX=004
CLIPITBTN =006
FULLTEXTBTN =007
LISTSCRBTN =008
LISTCATBTN =009

ScrViewerFormat=`WWWDLGED,6.1`

ScrViewerCaption=`Script Library`
ScrViewerX=071
ScrViewerY=135
ScrViewerWidth=358
ScrViewerHeight=274
ScrViewerNumControls=009
ScrViewerProcedure=`DlgProc`
ScrViewerFont=`DEFAULT`
ScrViewerTextColor=`DEFAULT`
ScrViewerBackground=`DEFAULT,DEFAULT`
ScrViewerConfig=0

ScrViewer001=`313,257,036,012,PUSHBUTTON,DEFAULT,"E&xit",1,1,32,DEFAULT,DEFAULT,DEFAULT`
ScrViewer002=`007,015,108,222,ITEMBOX,sScrList,DEFAULT,DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ScrViewer003=`121,015,228,224,MULTILINEBOX,sScrEdit,DEFAULT,DEFAULT,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ScrViewer004=`007,241,080,012,EDITBOX,sFilter,DEFAULT,DEFAULT,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ScrViewer005=`091,241,024,012,PUSHBUTTON,DEFAULT,"Filter",2,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ScrViewer006=`205,001,036,012,PUSHBUTTON,DEFAULT,"C&lip It",3,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ScrViewer007=`227,243,070,012,PUSHBUTTON,DEFAULT,"Full Text Search",4,8,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ScrViewer008=`007,001,048,012,PUSHBUTTON,DEFAULT,"Script Listing",5,9,DEFAULT,"Microsoft Sans Serif|5632|70|34","0|0|0",DEFAULT`
ScrViewer009=`153,243,066,012,PUSHBUTTON,DEFAULT,"List Categories",6,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("ScrViewer")


;******************************************************************************
;          		End of Program
;******************************************************************************
Exit
;EOF

Article ID:   W16203
File Created: 2004:03:30:15:43:14
Last Updated: 2004:03:30:15:43:14