PDA

View Full Version : BWINISelector



David Kummerow
02-12-2007, 12:23 AM
EDIT 13.02.07:
New version uploaded. Changed: checks if an INI folder has been created in the BW folder if using GUI mode.


Hi,

I just finished a little program to select between alternate BW ini files.

Can be run in GUI mode or called from the commandline (eg having a link on the desktop and so a bit more speedy that using the built-in BW config manager).

To run in GUI mode: just open the program BWINISelector.exe from either a shortcut you've made or double-clicking on it.

To run from the commandline: specify the ini file you want to use from the ini folder, eg "C:\Program Files\BibleWorks 7\BWINISelector.exe" "C:\Program Files\BibleWorks 7\ini\layout1.ini". BW will start with the desired configuration without the GUI.

Requirements: 1) BW 7 (of course); 2) INI files located in a folder named INI in the BW folder (eg C:\Program Files\BibleWorks 7\ini); 3) Place BWINISelector.exe in the BW folder.

See the attached zip file for the program.

Here's a pic:
http://img201.imageshack.us/img201/1879/bwiniselectormd5.png

And here's the AutoIt code if someone else wants to tinker:

BWINISelector.au3


; Script for selecting alternate BibleWorks INI files
; A GUI allows for selecting the desired INI FileChangeDir
; Alternatively, an INI file can be specified from the commandline for using in .LNK files etc,
; eg BWINISelector.exe "C:\Program Files\BibleWorks 7\ini\layout1.ini"
;
; Script created by David Kummerow 13.02.2007.
; Ver 0.2.
;
; Requirements: 1) BW 7 (of course);
; 2) INI files located in a folder named INI in the BW folder (eg C:\Program Files\BibleWorks 7\ini)
; 3) Place BWINISelector.exe in the BW folder.
;
; Make sure you backup your default BW700.ini before using this program!!! (Just in case.)

#include <GUIConstants.au3>
#include <Array.au3>
#include <string.au3>
#NoTrayIcon

If $CmdLine[0] = 0 Then
ElseIf $CmdLine[0] > 1 Then
MsgBox(0+16+262144, "Error...", 'Too many commandline parameters were passed to the program.' & @CRLF & @CRLF & _
'Make sure only one BW ini file is passed and that if the filename and path include spaces that the parameter is given in "quotes".')
Exit
ElseIf $CmdLine[0] = 1 Then
$parameter = $CmdLine[1]
If StringInStr($parameter, "\ini\") Then
inicommandline()
Else
MsgBox(0+16+262144, "Error...", 'Parameter passed from commandline error.' & @CRLF & @CRLF & _
'Make sure full path and file name is given and that if the filename and path include spaces that the parameter is given in "quotes".')
Exit
EndIf
EndIf

$inifolder = @ScriptDir & "\ini"
If FileExists($inifolder) = 0 Then
MsgBox(0+16+262144, "Error...", 'The INI folder could not be found' & @CRLF & @CRLF & _
'Make sure you have located your INI files in a folder named "ini" in you BW program directory, eg "C:\Program Files\BibleWorks 7\ini".')
Exit
Else
EndIf
$array = _FileListToArrayEx($inifolder, '*.ini', 0, '', False)

$list = ""
For $i = 1 to $array[0]
If $i > 1 Then
$list = $list & "|"
EndIf
$list = $list & $array[$i]
Next

$gui=GUICreate("BibleWorks INI Selector - v.0.2", 370, 112.5)
GUICtrlCreateGroup ("Seclect INI file for BW to use", 10, 10, 350, 92.5)
$inifiles = GUICtrlCreateCombo ("", 20,30,330)
GUICtrlSetData($inifiles, $list, $array[1])
GUICtrlCreateGroup ("",-99,-99,1,1)

$Button1 = GUICtrlCreateButton ("Apply", 20, 65, 85)
$Button2 = GUICtrlCreateButton ("Cancel", 265, 65, 85)

GUISetState(@SW_SHOW,$gui)
GUISetState(@SW_SHOW,$Button1)
GUISetState(@SW_SHOW,$Button2)

While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then
Exit
ElseIf $msg = $Button1 Then
$iniselection = GUICtrlRead($inifiles)
$iniselectionpath = @ScriptDir & "\ini\" & $iniselection
$iniselectionpath = StringStripWS ($iniselectionpath, 1)
$iniselectionpath = StringStripWS ($iniselectionpath, 2)
FileDelete(@ScriptDir & '\bw700.ini')
FileCopy($iniselectionpath, @ScriptDir & '\bw700.ini')
Run(@ScriptDir & '\bw700.exe')
Exit
ElseIf $msg = $Button2 Then
Exit
EndIf
Wend

Func inicommandline()
$iniselectionpath = $parameter
$iniselectionpath = StringStripWS ($iniselectionpath, 1)
$iniselectionpath = StringStripWS ($iniselectionpath, 2)
FileDelete(@ScriptDir & '\bw700.ini')
FileCopy($iniselectionpath, @ScriptDir & '\bw700.ini')
Run(@ScriptDir & '\bw700.exe')
Exit
EndFunc

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
If Not FileExists($sPath) Then Return SetError(1, 1, '')
If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
For $iCC = 0 To 5
If StringInStr($sFilter, $aBadChar[$iCC]) Or _
StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
Next
If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead
For $iCC = 1 To $aSplit[0]
If StringStripWS($aSplit[$iCC], 8) = '' Then ContinueLoop
If StringLeft($aSplit[$iCC], 1) = '.' And _
UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
Local $iPid
If Not $iRecurse Then
$iPid = Run(@ComSpec & ' /c ' & 'dir "' & $sPath & '\' & $aSplit[$iCC] & '" /b /o-e /od', '', @SW_HIDE, 6)
Else
$iPid = Run(@Comspec & ' /c dir /b /s /a "' & $sPath & '\' & $aSplit[$iCC] & '"', '', @SW_HIDE, 6)
EndIf
While 1
$sRead &= StdoutRead($iPid)
If @error Then ExitLoop
WEnd
Next
If StringStripWS($sRead, 8) = '' Then Return SetError(4, 4, '')
Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
Local $sHold
For $iCC = 1 To $aFSplit[0]
If $sExclude And StringLeft(StringTrimLeft($aFSplit[$iCC], StringInStr($aFSplit[$iCC], '\', 0, -1)), _
StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
Switch $iFlag
Case 0
$sHold &= $aFSplit[$iCC] & Chr(1)
Case 1
If StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then ContinueLoop
$sHold &= $aFSplit[$iCC] & Chr(1)
Case 2
If Not StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then ContinueLoop
$sHold &= $aFSplit[$iCC] & Chr(1)
EndSwitch
Next
If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
Return SetError(4, 4, '')
EndFunc
Hope someone finds this useful.

Regards,
David Kummerow.

Philip Brown
02-14-2007, 09:42 AM
Hi, David,

Just wondering how your BWINISelector differs from BW's built in configuration manager? I use it all the time to select different .inis

David Kummerow
02-14-2007, 03:36 PM
It allows for commandline input. So you can create, say, two desktop shortcuts to run your two most used profiles by just double-clicking. It speeds up the process.

If the BW configuration manager can also do this, then they do the same and I wasted my time. But I couldn't figure out how to do it.

Regards,
David Kummerow.