;-------------------------------------------------------------------------
; wsinit.dll  - WinBatch version
;
; WinBatch Studio checks for the existence of this file at startup, looking
; in the WinBatch Studio directory. It allows you a chance to customize 
; every part of WinBatch Studio at startup without user intervention.
; 
; If WinBatch Studio executes the script it saves the file date stamp.  Subsequently
; at startup, WinBatch Studio will compare the file date with the saved time and
; will only re-run the script if it's newer than the saved timestamp.
;
;
regword="WinBatch Studio"
if "%param1%"=="CLEARTOOLBAR"
   GOTO CLEARTOOLBAR
endif

;gosub NukeSomeSettings
gosub SetupPage
gosub SetupFind
gosub SetupGlobal
gosub WILFileSettings
; Set up some file types.  Maybe should be first, as later items override earlier items...
gosub SetupHTML     ; This one here primarily as an example.
;
gosub ClearToolbarSetup

exit


:SetupHTML
        ;-------------------------------------------------------------------------
        ; File specific settings
        ;
        ; This example sets up WinBatch Studio for HTML files. 
        ;-------------------------------------------------------------------------

        ; First, verify these settings were not already installed so we don't
        ; overwrite changes made by the user on a mere update.  If thiere is
        ; a real update, then yes we do overwrite user customizations.
        FileKind="HTML"         ; Name of manil file group for this type of files
        ConfigVerWBT=7     ; Configuration version number,.  Update when changing this section

        if RegExistValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\File types\%FileKind% Files[ConfigVer]")
             ConfigVerReg=RegQueryValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\File types\%FileKind% Files[ConfigVer]")
             if ConfigVerReg >= ConfigVerWBT then return  ; if reg is newer, do not excecute
        endif
        RegSetValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\File types\%FileKind% Files[ConfigVer]",ConfigVerWBT)



        ; The File mapping key sets up the file extensions with a particular 
        ; file group.  e.g.   HTML, HTM and ASP type files all belong to the
        ; HTML file group 
        
        regkey = RegCreateKey(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\File mapping")
        
        RegSetValue(regkey, "[HTML]", FileKind)
        RegSetValue(regkey, "[HTM]",  FileKind)
        RegSetValue(regkey, "[ASP]",  FileKind)
        RegSetValue(regkey, "[XML]",  FileKind)
        RegCloseKey(regkey)
        
        
        ;-------------------------------------------------------------------------
        ; the File types key sets up the file extension - specific settings
        
        regkey = RegCreateKey(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\File types\%FileKind% Files")
        
        ; add this file type to the FileOpen dialog
        RegSetDWord(regkey, "[AddToFileDialog]", 1)
        
        ; description and wild cards to use in FileOpen dialog
        RegSetValue(regkey, "[FileOpenMask]", "%FileKind% Files|*.htm;*.html;*.asp;*.xml")
        
        ; case sensitivity
        RegSetDWord(regkey, "[Case]", 0)
        
        ; show chroma coding
        RegSetDWord(regkey, "[Chroma]", 1)
        
        ; comment definition - two available
        RegSetValue(regkey, "[Comment Start 1]", "<!--")
        RegSetValue(regkey, "[Comment End 1]", "-->")
        
        RegSetValue(regkey, "[Comment Start 2]", "")
        RegSetValue(regkey, "[Comment End 2]", "")
        
        ; font information for this file type													  
        RegSetValue(regkey, "[Font name]", "Courier New")
        RegSetDWord(regkey, "[Font size]", 10)
        
        ; 400 = normal, 700 = bold
        RegSetDWord(regkey, "[Font weight]", 400)
        RegSetDWord(regkey, "[Font italic]", 0)
        
        ; 1 = insert mode; 0 = overtype
        RegSetDWord(regkey, "[Insert]", 1)
        
        ; pathname of keyword listing file
        RegSetValue(regkey, "[Keywords]", "%FileKind%.clr")
        
        ; 0 = CR/LF; 1 = LF; 2 = LF/CR; 3 = CR
        RegSetDWord(regkey, "[Line end type]", 0)
        
        ; leave files locked when open
        RegSetDWord(regkey, "[Lock files]", 0)
        
        ; 1 = use tabs; 0 = insert spaces
        RegSetDWord(regkey, "[Keep tabs]", 1)
        
        ; show visible tab marks on screen
        RegSetDWord(regkey, "[Show tabs]", 0)
        
        ; tab size in characters
        RegSetDWord(regkey, "[Tab size]", "3")
        
        ; extra characters to be considered part of a word
        RegSetValue(regkey, "[Extra word chars]", "!")
        
        ; extra characters that might start a word
        RegSetValue(regkey, "[Start chars]", "")
        
        ; extra characters that might end a word
        RegSetValue(regkey, "[Terminator chars]", "")
        
        ; colors.  R,G,B values as a string
        RegSetValue(regkey, "[Background]", "255,255,255")
        RegSetValue(regkey, "[Comment]", "0,128,0")
        RegSetValue(regkey, "[Default Text]", "0,0,0")
        RegSetValue(regkey, "[Keyword]", "0,0,255")
        RegSetValue(regkey, "[Quote]", "255,0,0")
        
        ; character set 0 = ANSI, 1 = OEM
        RegSetDWord(regkey, "[CharSet]", 0)
        
        ; compile command
        RegSetValue(regkey, "[Compile command]", "")
        
        ; call a custom WIL error parsing script after compiling
        RegSetDWord(regkey, "[UseWBT]", 0)
        
        ; if so, the name of the script
        RegSetValue(regkey, "[WBTErrorFile]", "")
        RegCloseKey(regkey)
        return

        
:SetupPage
        ;-------------------------------------------------------------------------
        ; the PageSetup key handles all the printing settings
        
        ;First check to try not to needlessly overwrite user settings

        ConfigVerWBT=5     ; Configuration version number,.  Update when changing this section

        if RegExistValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\PageSetup[ConfigVer]")
             ConfigVerReg=RegQueryValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\PageSetup[ConfigVer]")
             if ConfigVerReg >= ConfigVerWBT then return  ; if reg is newer, do not excecute
        endif
        RegSetValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\PageSetup[ConfigVer]",ConfigVerWBT)

        
        regkey = RegCreateKey(@REGCURRENT, "Software\Wilson WindowWare\%regword%\PageSetup")
        
        ; 0 = ANSI, 1 = OEM
        RegSetDWord(regkey,"[CharSet]", 0)
        
        ; 1 = print in color, 0 = OFF
        RegSetDWord(regkey, "[Color syntax]", 1)
        
        ; 1 = print italics, 0 = regular
        RegSetDWord(regkey, "[Font Italic]", 0)
        
        ; name of font 
        RegSetValue(regkey, "[Font name]", "Courier New")
        
        ; size of font in points
        RegSetDWord(regkey, "[Font size]", 12)
        
        ; 400 = normal, 700 = bold
        RegSetDWord(regkey, "[Font weight]", 400)
        
        ; footer macro string
        RegSetValue(regkey, "[Footer]", "Page $(PageNo)")
        
        ; print file time in footer, 1 = yes, 0 = no
        RegSetDWord(regkey, "[FooterTime]", 0)
        
        ; header macro string
        RegSetValue(regkey, "[Header]", "$(FilePath) - $(FileTime)")
        
        ; print file time in header, 1 = yes, 0 = no
        RegSetDWord(regkey, "[HeaderTime]", 0)
        
        ; print line numbers, 1 = yes, 0 = no
        RegSetDWord(regkey, "[Line numbers]", 0)
        
        ; print pages two up, 1 = yes, 0 = no
        RegSetDWord(regkey, "[Twoup]", 0)
        
        ; 0 = use screen font, 1 = use printer font defined above
        RegSetDWord(regkey, "[Use printer font]", 0)
        
        RegCloseKey(regkey)
        return

:SetupFind
        ;-------------------------------------------------------------------------
        ; the Settings\Find key handles the find\replace settings

        ;First check to try not to needlessly overwrite user settings

        ConfigVerWBT=5     ; Configuration version number,.  Update when changing this section

        if RegExistValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Find[ConfigVer]")
             ConfigVerReg=RegQueryValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Find[ConfigVer]")
             if ConfigVerReg >= ConfigVerWBT then return  ; if reg is newer, do not excecute
        endif
        RegSetValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Find[ConfigVer]",ConfigVerWBT)

        regkey = RegCreateKey(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Find")
        
        ; these keys are all true/false, 1 = ON, 0 = OFF
        RegSetDWord(regkey, "[Forward]", 1)
        RegSetDWord(regkey, "[Match case]", 0)
        RegSetDWord(regkey, "[Regular expressions]", 0)
        RegSetDWord(regkey, "[Wrap search]", 0)
        RegCloseKey(regkey)
        return

:setupGlobal
        ;-------------------------------------------------------------------------
        ; the Settings\Main Window key handles the global editor settings

       ;First check to try not to needlessly overwrite user settings

        ConfigVerWBT=6     ; Configuration version number,.  Update when changing this section

        if RegExistValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ConfigVer]")
             ConfigVerReg=RegQueryValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ConfigVer]")
             if ConfigVerReg >= ConfigVerWBT then return  ; if reg is newer, do not excecute
        endif
        RegSetValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ConfigVer]",ConfigVerWBT)

        regkey = RegCreateKey(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window")
        
        ; backup location macro string
        RegSetValue(regkey, "[Backup location]", "$(FilePath).backup")
        RegSetValue(regkey, "[Autosave location]", "$(FilePath).autosave")
        
        ; the name of the active project
        RegSetValue(regkey, "[Active Workspace]", "Default")
        
        ; the autosave interval, in minutes
        RegSetDWord(regkey, "[Autosave interval]", 5)
        
        ; the rest are all true/false, on/off
        RegSetDWord(regkey, "[AutoSave]", 1)
        RegSetDWord(regkey, "[Horizontal Scrollbar]", 1)
        RegSetDWord(regkey, "[Make Backups]", 1)
        
        ; leave the cursor at the end of pasted text
        RegSetDWord(regkey, "[Paste After]", 1)
        
        ; automatically save files before running tools
        RegSetDWord(regkey, "[Save Before]", 1)
        
        ; don't prompt before automatically saving files
        RegSetDWord(regkey, "[Prompt Before]", 0)
        
        ; reload the open files from the last session
        RegSetDWord(regkey, "[Restore Workspace]", 0)
        
        ; allow only one instance of %regword%
        RegSetDWord(regkey, "[Single Instance]", 1)
        
        ; allow the cursor to move past the ends of lines
        RegSetDWord(regkey, "[VirtualWhitespace]", 1)
        RegCloseKey(regkey)

        ; set WIL files to be FileOpen default
        regkey = RegCreateKey(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Options")
        RegSetDWord(regkey, "[FilterIndex]", 3)
        RegCloseKey(regkey)

        return
:WILFileSettings
		  
		  ;First check to try not to needlessly overwrite user settings
        ConfigVerWBT=1     ; Configuration version number.  Update when changing this section
        if RegExistValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\File types\WIL Files[ConfigVer]")
             ConfigVerReg=RegQueryValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\File types\WIL Files[ConfigVer]")
             if ConfigVerReg >= ConfigVerWBT then return  ; if reg is newer, do not excecute
        endif
        RegSetValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\File types\WIL Files[ConfigVer]",ConfigVerWBT)

        ; Set WIL files run command  to use the $(WinBatch) substitution macro instead of WBML.EXE Primarily necessary only when user is 
		  ; not installer.  !!!IMPORTANT!!!This is also set in setup.dll so changes need to be made in both places.!!!!
		  RegSetValue(@RegCurrent,"Software\Wilson WindowWare\%regword%\Settings\File types\WIL Files[Run command]",'$(WinBatch) "$(FilePath)"')
	
		  return

:NukeSomeSettings
        ConfigVerWBT=2     ; Configuration version number,.  Update when changing this section

        if RegExistValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ResetBetaVer]")
             ConfigVerReg=RegQueryValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ResetBetaVer]")
             if ConfigVerReg >= ConfigVerWBT then return  ; if reg is same or newer, do not excecute
        endif
        RegSetValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ResetBetaVer]",ConfigVerWBT)

        ;nothing to do this week.
        return

:CLEARTOOLBARSETUP
        ;First check to try not to needlessly delete users toolbar view
		 
		  ;!!!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!
        ;!!!!!!!!!!!!!IMPORTANT - Variable must be the same under the  :CLEARTOOLBAR lable. 
		  ConfigVerWBT=5     ; Configuration version number.  Update when changing this section
		  ;!!!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!
       
		  if RegExistValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ToolBarLevel]")
             ConfigVerReg=RegQueryValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ToolBarLevel]")
             if ConfigVerReg == ConfigVerWBT then return  ; if reg is same, do not excecute
         endif
			
        ;Run exe to cleartoolbar
        Run("winbatch_IF.exe",strcat('"',DirHome(),'WSINIT.DLL" CLEARTOOLBAR'))

		return

:CLEARTOOLBAR
      IntControl(12,2+8,"WinBatch Setup%@CRLF%Please close WinBatch Studio before trying to exit Windows.",0,0)
      ;Wait for WBStudio to exit
      AppWaitClose("WinBatch Studio.exe")
       
	   ;!!!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!
      ;!!!!!!!!!!!!!IMPORTANT - Variable must be the same under the :CLEARTOOLBARSETUP lable. 
	   ConfigVerWBT=5     ; Configuration version number.  Update when changing this section
	   ;!!!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!
		
		if RegExistValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ToolBarLevel]")
      	ConfigVerReg=RegQueryValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ToolBarLevel]")
			if ConfigVerReg != ConfigVerWBT   ; if reg is not the same

      		if RegExistKey(@REGCURRENT,"Software\Wilson WindowWare\%regword%\Toolbars")
         		RegDeleteKey(@REGCURRENT,"Software\Wilson WindowWare\%regword%\Toolbars")
      		endif
		   endif
		endif
	       
	   RegSetValue(@REGCURRENT, "Software\Wilson WindowWare\%regword%\Settings\Main Window[ToolBarLevel]",ConfigVerWBT)

	   exit












