WDL2INI




WDL2INI.WBT   Version 1.00  2003:09:22

- Converts a WinBatch WDL Dialog definition file into an ini file.

- SubRoutine udsReadIniWDL() can create a WinBatch dialog from inifile definitions on runtime.

Version History
  • 2003:09:22 v1.00
    - Initial release.


If you have questions about WinBatch, you are encouraged to use online WebBoard BBS at http://webboard.windowware.com


;==========================================================================================================================================
; WDL2INI.wbt
; Convert WinBatch WDL dialog definition file into inifile format.
;
; Detlev Dalitz.20030922
;==========================================================================================================================================


;--------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfFileGetLineCount (sFilename)
iBBSize = FileSizeEx(sFilename)
If !iBBSize Then Return (0)
hBB = BinaryAlloc(iBBSize)
iHigh = BinaryRead(hBB,sFilename)-1
While (@CR==BinaryPeekStr(hBB,iHigh,1))
   iHigh = iHigh-1
EndWhile
iLineCount = BinaryStrCnt(hBB,0,iHigh,@LF)
iLineCount = iLineCount+(@LF<>BinaryPeekStr(hBB,iHigh,1))
BinaryFree(hBB)
Return (iLineCount)
;..........................................................................................................................................
; This function "udfFileGetLineCount" returns the number of lines counted in a textfile.
; This function takes only @LF characters into account.
; All @CR characters are ommitted.
; The function provides the same number of lines as counted by the WIL standard FileRead function.
; Detlev Dalitz.20020820
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfReturnSub (a, b)
Return (a)
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineSubRoutine udsAskFilenameIn (AF_default)
AF_folder = FilePath(AF_default)
If !DirExist(AF_folder) Then AF_folder = IniReadPvt(sAppProductName,"Wdl_Folder","",sAppIni)
If !DirExist(AF_folder) Then AF_folder = Environment("temp")
If !DirExist(AF_folder) Then AF_folder = ShortCutDir("Desktop",0,@TRUE)
If (AF_default=="") Then AF_default = IniReadPvt(sAppProductName,"Wdl_File","",sAppIni)
If (AF_default=="") Then AF_default = "*.wdl"
AF_title = StrCat(sAppProductName,": Select WDL file to convert to Winbatch ...")
AF_filetypes = "Wdl Files|*.wdl|Ini Files|*.ini|Wdl & Ini Files|*.wdl;*.ini|All Files|*.*|"
AF_flag = 1  ; Open single file.
AF_file = AskFilename(AF_title,AF_folder,AF_filetypes,AF_default,AF_flag)
If FileExist(AF_file) Then AF_file = FileNameLong(StrUpper(AF_file))
AF_folder = FilePath(AF_file)
IniWritePvt(sAppProductName,"Wdl_Folder",AF_folder,sAppIni)
IniWritePvt(sAppProductName,"Wdl_File",AF_file,sAppIni)
IniWritePvt("","","",sAppIni)
Return (udfReturnSub(AF_file,DropWild("AF_*")))
#EndSubRoutine
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineSubRoutine udsAskFilenameOut (AF_default)
AF_folder = FilePath(AF_default)
If !DirExist(AF_folder) Then AF_folder = IniReadPvt(sAppProductName,"Ini_Folder","",sAppIni)
If !DirExist(AF_folder) Then AF_folder = Environment("temp")
If !DirExist(AF_folder) Then AF_folder = ShortCutDir("Desktop",0,@TRUE)
If (AF_default=="") Then AF_default = IniReadPvt(sAppProductName,"Ini_File","",sAppIni)
If (AF_default=="") Then AF_default = "*.ini"
AF_title = StrCat(sAppProductName,": Save Ini file as ...")
AF_filetypes = "Ini Files|*.ini|Wdl Files|*.wdl|Wdl & Ini Files|*.wdl;*.ini|All Files|*.*|"
AF_flag = 0 ; Save style
AF_file = AskFilename(AF_title,AF_folder,AF_filetypes,AF_default,AF_flag)
If FileExist(AF_file) Then AF_file = FileNameLong(StrUpper(AF_file))
AF_folder = FilePath(AF_file)
IniWritePvt(sAppProductName,"Ini_Folder",AF_folder,sAppIni)
IniWritePvt(sAppProductName,"Ini_File",AF_file,sAppIni)
IniWritePvt("","","",sAppIni)
Return (udfReturnSub(AF_file,DropWild("AF_*")))
#EndSubRoutine
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfMsgBox (sCaption, sText, iFlags)
Return (DllCall(StrCat(DirWindows(1),"User32.dll"),long:"MessageBoxA",long:DllHwnd(""),lpstr:sText,lpstr:sCaption,long:iFlags))
;..........................................................................................................................................
;+-----STYLE-----------------------+-----ICONS-----------------------+
;| OK               = 0            | STOP      = 16                  |
;| OKCANCEL         = 1            | QUESTION  = 32                  |
;| ABORTRETRYIGNORE = 2            | EXCLAIM   = 48                  |
;| YESNOCANCEL      = 3            | INFO      = 64                  |
;| YESNO            = 4            | WINICON   = 4096                |
;| RETRYCANCEL      = 5            |                                 |
;+-----BUTTONS---------------------|----RETURN VALUES----------------|
;| DEFAULTBUTTON1   = 0            | IDOK      = 1                   |
;| DEFAULTBUTTON2   = 256          | IDCANCEL  = 2                   |
;| DEFAULTBUTTON3   = 512          | IDABORT   = 3                   |
;+---------------------------------| IDRETRY   = 4                   |
;| Combine flags with OR operator: | IDIGNORE  = 5                   |
;|      Flags=4|48|256|4096        | IDYES     = 6                   |
;|                                 | IDNO      = 7                   |
;+---------------------------------+---------------------------------+
;From:  MWorrel mworrel@yahoo.com
;Date:  Friday, September 12, 2003 08:54 AM
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------




;------------------------------------------------------------------------------------------------------------------------------------------
; Main
;------------------------------------------------------------------------------------------------------------------------------------------
sAppProductName     = "WDL2INI"
sAppProductVersion  = "1"
sAppFileVersion     = "1.00"
sAppFileVersionDate = "20030922"
sAppDescription     = "Conversion from WinBatch dialog file (wdl) to Ini file (ini)"
sAppCopyright       = "(c)20030922 Detlev Dalitz"
;..........................................................................................................................................
sAppFolder = FilePath(IntControl(1004,0,0,0,0))
sAppIni = StrCat(sAppFolder,sAppProductName,".ini")
sStartFolder = DirGet()
;..........................................................................................................................................
IniWritePvt(sAppProductName,"ProductName"    ,sAppProductName    ,sAppIni)
IniWritePvt(sAppProductName,"FileVersion"    ,sAppFileVersion    ,sAppIni)
IniWritePvt(sAppProductName,"FileVersionDate",sAppFileVersionDate,sAppIni)
IniWritePvt(sAppProductName,"FileDescription",sAppDescription    ,sAppIni)
IniWritePvt(sAppProductName,"ProductVersion" ,sAppProductVersion ,sAppIni)
IniWritePvt(sAppProductName,"LegalCopyright" ,sAppCopyright      ,sAppIni)
;..........................................................................................................................................
;sMsgError   = StrCat(sAppProductName,": Error")
;sMsgWarning = StrCat(sAppProductName,": Warning")
;..........................................................................................................................................
; Find the WDL file to be converted.
sFileWdl = udsAskFilenameIn("")
; Find a place to store the INI file to be created.
sFileIni = StrCat(FilePath(sFileWdl),FileBaseName(sFileWdl),".to.ini")
sFileIni = udsAskFilenameOut(sFileIni)
;..........................................................................................................................................
sMsgTitle = StrCat(sAppProductName,": ",sAppDescription)
sMsgText  = "Processing ..."
BoxOpen(sMsgTitle,sMsgText)
WinPlace(100,250,900,370,"")
;..........................................................................................................................................
; Read the basic dialog structure definitions from my inifile.
sListDlgHdrAttr   = IniItemizePvt("DLG_HDR_ATTR",sAppIni)
sListDlgCtrlAttr  = IniItemizePvt("DLG_CTRL_ATTR",sAppIni)
iCountDlgHdrAttr  = ItemCount(sListDlgHdrAttr,@TAB)
iCountDlgCtrlAttr = ItemCount(sListDlgCtrlAttr,@TAB)
;..........................................................................................................................................
; Define some constants.
@READ = "READ"
@EOF  = "*EOF*"
@0    = ""
@40   = "("
@41   = ")"
@44   = ","
@61   = "="
@ZERO = "0"
@DBLQ = '""'
@P1   = "{1}"
@P2   = "{2}"
@P3   = "{3}"
sMsgTextMask = StrCat("# {1}/{2}",@LF,"{3} ...")
;..........................................................................................................................................
iFileInLines  = udfFileGetLineCount(sFileWdl)
sMsgTextMask = StrReplace(sMsgTextMask,@P1,iFileInLines)
;..........................................................................................................................................
; Process the wdl file and write to ini.

sMsgText = "Processing Pass 1 ..."
BoxText(sMsgText)

IniWritePvt("DLG","Created",TimeYmdHms(),sFileIni)

iDetectedFormat = @FALSE
iDetectedButtonPushed = @FALSE

iLine = 0
hFR = FileOpen(sFileWDL,@READ)
While @TRUE
   sLine = FileRead(hFR)
   If (sLine==@EOF) Then Break
   iLine = iLine+1
   sLine = StrTrim(sLine)
   If (sLine==@0) Then Continue
   If !iDetectedFormat
      If (StrIndexWild(sLine,"*Format*=*",1)==1)
         BoxText(StrReplace(StrReplace(sMsgTextMask,@P2,iLine),@P3,StrSub(sLine,1,100)))
         sDlgName = ItemExtract(1,sLine,@61)
         sDlgName = StrSub(sDlgName,1,StrLen(sDlgName)-StrLen("Format"))
         IniWritePvt("DLG","Name",sDlgName,sFileIni)
         iLineStart = StrLen(sDlgName)+1
         iDetectedFormat = @TRUE
      EndIf
   EndIf
   If !iDetectedButtonPushed
      If (StrIndexWild(sLine,"*ButtonPushed*=*Dialog*",1)==1)
         BoxText(StrReplace(StrReplace(sMsgTextMask,@P2,iLine),@P3,StrSub(sLine,1,100)))
         iIgnoreFlag = ItemExtract(2,ItemExtract(1,ItemExtract(2,ItemExtract(2,sLine,@61),@40),@41),@44)
         If (iIgnoreFlag==@0) Then iIgnoreFlag=1
         IniWritePvt("DLG","IgnoreFlag",iIgnoreFlag,sFileIni)
         IniWritePvt("DLG","UniqueReturnVar",(StrIndex(sLine,sDlgName,1,@FWDSCAN)==1),sFileIni)
         iDetectedButtonPushed = @TRUE
      EndIf
   EndIf
EndWhile
FileClose(hFR)

sMsgText = "Processing Pass 2 ..."
BoxText(sMsgText)

iLine = 0
hFR = FileOpen(sFileWDL,@READ)
While @TRUE
   sLine = FileRead(hFR)
   If (sLine==@EOF) Then Break
   iLine = iLine+1
   sLine = StrTrim(sLine)
   If (sLine==@0) Then Continue
   BoxText(StrReplace(StrReplace(sMsgTextMask,@P2,iLine),@P3,StrSub(sLine,1,100)))
   sLine = StrSub(sLine,iLineStart,-1)
   sKey = ItemExtract(1,sLine,@61)
   sData = ItemExtract(2,sLine,@61)

   If IsNumber(sKey)
      sSection = sKey
      sData = StrSub(sData,2,StrLen(sData)-2) ; Remove Quotes.
      For ia=1 To iCountDlgCtrlAttr
         sAttr = ItemExtract(ia,sListDlgCtrlAttr,@TAB)
         sValue = ItemExtractCSV(ia,sData,0,@44)
         If StrScan(sValue,"| .:\",1,@FWDSCAN) Then sValue = StrCat(@DBLQ,sValue,@DBLQ)
         IniWritePvt(sSection,sAttr,sValue,sFileIni)
      Next
   Else
      If !IsNumber(sData) Then sData = StrSub(sData,2,StrLen(sData)-2) ; Remove Quotes.
      If ItemLocate(sKey,sListDlgHdrAttr,@TAB) Then IniWritePvt("DLG_HDR",sKey,sData,sFileIni)
   EndIf

EndWhile
FileClose(hFR)
IniWritePvt(@0,@0,@0,sFileIni)

sMsgText = "Conversion completed."
BoxText(sMsgText)
;..........................................................................................................................................
MB_OK = 0
MB_ICONINFORMATION = 64
sMsgText = "Conversion Completed."
iResult = udfMsgBox(sMsgTitle,sMsgText,MB_OK|MB_ICONINFORMATION)
;..........................................................................................................................................
MB_YESNO = 4
MB_ICONQUESTION = 32
IDYES = 6
sMsgText = "Open target folder?"
iResult = udfMsgBox(sMsgTitle,sMsgText,MB_YESNO|MB_ICONQUESTION)
If (iResult==IDYES) Then Run("explorer.exe",StrCat("/select, ",sFileIni))
;..........................................................................................................................................
:CANCEL
DirChange(sStartFolder)
BoxShut()
Exit
;==========================================================================================================================================
;*EOF*


;------------------------------------------------------------------------------------------------------------------------------------------
; Create WinBatch WDL dialog from inifile.
; Inifile must be created prior with WinBatch script program WDL2INI.wbt
;
; Detlev Dalitz.20030922
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineSubRoutine udsReadIniWDL (sIniFileWDL2INI, sIniFileWDL)
; Read the basic dialog structure definitions from my inifile.
sListDlgHdrAttr   = IniItemizePvt("DLG_HDR_ATTR",sAppIni)
sListDlgCtrlAttr  = IniItemizePvt("DLG_CTRL_ATTR",sAppIni)
iCountDlgHdrAttr  = ItemCount(sListDlgHdrAttr,@TAB)
iCountDlgCtrlAttr = ItemCount(sListDlgCtrlAttr,@TAB)
;..........................................................................................................................................
sSection = "DLG"
sDlgName = IniReadPvt(sSection,"Name","",sIniFileWDL)
If (sDlgName=="") Then Return "" ; Error. Return immediately. WDL inifile is not valid.
;..........................................................................................................................................
sDlgIgnoreFlag = IniReadPvt(sSection,"IgnoreFlag",1,sIniFileWDL)
sDlgIgnoreFlag = Int(sDlgIgnoreFlag)
;..........................................................................................................................................
sSection="DLG_HDR"
For ii=1 To iCountDlgHdrAttr
   sKey = ItemExtract(ii,sListDlgHdrAttr,@TAB)
   sData = IniReadPvt(sSection,sKey,"DEFAULT",sIniFileWDL)
   %sDlgName%%sKey% = sData
Next
;..........................................................................................................................................
iCountCtrl = Int(%sDlgName%NumControls)
For ic=1 To iCountCtrl
   sCtrlId = StrFixLeft(ic,"0",3)
   sCtrlAttr = ""
   For ia=1 To iCountDlgCtrlAttr
      sAttr = ItemExtract(ia,sListDlgCtrlAttr,@TAB)
      If (sAttr=="") Then Continue
      sValue = IniReadPvt(sCtrlId,sAttr,"",sIniFileWDL)
      sCtrlAttr = ItemInsert(sValue,-1,sCtrlAttr,",")
   Next
   %sDlgName%%sCtrlId% = sCtrlAttr
Next
;..........................................................................................................................................
sResult = StrCat('ButtonPushed=Dialog("',sDlgName,'",',sDlgIgnoreFlag,')')
If IniReadPvt("DLG","UniqueReturnVar",0,sIniFileWDL) Then sResult = StrCat(sDlgName,sResult)
;..........................................................................................................................................
Drop(ia,ic,iCountCtrl,iCountDlgCtrlAttr,iCountDlgHdrAttr,ii,sAttr,sCtrlAttr,sCtrlId)
Drop(sData,sKey,sListDlgCtrlAttr,sListDlgHdrAttr,sSection,sValue)
;..........................................................................................................................................
Return (sResult)
;..........................................................................................................................................
; Create WinBatch WDL dialog from inifile.
; Inifile must be created prior with WinBatch script program WDL2INI.wbt
;
; Detlev Dalitz.20030922
;..........................................................................................................................................
#EndSubRoutine
;------------------------------------------------------------------------------------------------------------------------------------------




; --- test ---

;..........................................................................................................................................
sAppProductName = "WDL2INI"

; sAppFolder = FilePath(IntControl(1004,0,0,0,0))
sAppFolder = "G:\temp\wbt\WDL2INI\"                              ; <== Change to your needs.

; WDL2INI.ini contain default values.
sAppIni = StrCat(sAppFolder,sAppProductName,".ini")
;..........................................................................................................................................

; Define the inifile, which contains WDL definitions, converted prior by WDL2INI.wbt.

sIniFileWDL = StrCat(sAppFolder,"Test.BigDialog.ini")            ; <== Change to your needs.

;..........................................................................................................................................

; Create the dialog statements to use here in the script.
sDialog = udsReadIniWDL(sAppIni,sIniFileWDL)

;..........................................................................................................................................

; Invoke dialog.
If (sDialog>"") Then Execute %sDialog%

;..........................................................................................................................................

Exit
;------------------------------------------------------------------------------------------------------------------------------------------
;*EOF*


; Example WinBatch WDL Dialog definition file.

MsgBoxFormat=`WWWDLGED,6.1`

MsgBoxCaption=`Demo  udfMsgBox()`
MsgBoxX=-01
MsgBoxY=-01
MsgBoxWidth=112
MsgBoxHeight=051
MsgBoxNumControls=005
MsgBoxProcedure=`DEFAULT`
MsgBoxFont=`DEFAULT`
MsgBoxTextColor=`DEFAULT`
MsgBoxBackground=`DEFAULT,DEFAULT`
MsgBoxConfig=0

MsgBox001=`023,009,058,010,STATICTEXT,DEFAULT,"This is my message box",DEFAULT,DEFAULT,0,DEFAULT,DEFAULT,DEFAULT`
MsgBox002=`023,017,078,010,STATICTEXT,DEFAULT,"containing two lines.",DEFAULT,DEFAULT,1024,DEFAULT,DEFAULT,DEFAULT`
MsgBox003=`023,031,036,012,PUSHBUTTON,DEFAULT,"OK",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MsgBox004=`065,031,036,012,PUSHBUTTON,DEFAULT,"Continue",2,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MsgBox005=`003,009,016,020,PICTURE,DEFAULT,"Picture 1",DEFAULT,5,DEFAULT,DEFAULT,DEFAULT,"D:\Programme\WinBatch\System\WBOwl.bmp"`

ButtonPushed=Dialog("MsgBox")


;------------------------------------------------------------------------------------------------------------------------------------------
; Example Inifile, converted by WDL2INI.wbt v1.00
;------------------------------------------------------------------------------------------------------------------------------------------

[DLG]
Created=2003:09:22:18:35:25
Name=MsgBox
IgnoreFlag=1
UniqueReturnVar=0

[DLG_HDR]
Format=WWWDLGED,6.1
Caption=Demo  udfMsgBox()
X=-01
Y=-01
Width=112
Height=051
NumControls=005
Procedure=DEFAULT
Font=DEFAULT
Background=DEFAULT,DEFAULT
Config=0

[001]
X=023
Y=009
Width=058
Height=010
Type=STATICTEXT
Var=DEFAULT
Text=""This is my message box""
Value=DEFAULT
Taborder=DEFAULT
Style=0
Font=DEFAULT
Textcolor=DEFAULT
Background=DEFAULT

[002]
X=023
Y=017
Width=078
Height=010
Type=STATICTEXT
Var=DEFAULT
Text=""containing two lines.""
Value=DEFAULT
Taborder=DEFAULT
Style=1024
Font=DEFAULT
Textcolor=DEFAULT
Background=DEFAULT

[003]
X=023
Y=031
Width=036
Height=012
Type=PUSHBUTTON
Var=DEFAULT
Text=OK
Value=1
Taborder=1
Style=DEFAULT
Font=DEFAULT
Textcolor=DEFAULT
Background=DEFAULT

[004]
X=065
Y=031
Width=036
Height=012
Type=PUSHBUTTON
Var=DEFAULT
Text=Continue
Value=2
Taborder=2
Style=DEFAULT
Font=DEFAULT
Textcolor=DEFAULT
Background=DEFAULT

[005]
X=003
Y=009
Width=016
Height=020
Type=PICTURE
Var=DEFAULT
Text=""Picture 1""
Value=DEFAULT
Taborder=5
Style=DEFAULT
Font=DEFAULT
Textcolor=DEFAULT
Background=""D:\Programme\WinBatch\System\WBOwl.bmp""
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
; Main Inifile for WDL2INI.wbt.
; Needed while runtime.
; Must be used along with WDL2INI.wbt.
;------------------------------------------------------------------------------------------------------------------------------------------

[DLG_HDR_ATTR]
Format=1
Caption=2
X=3
Y=4
Width=5
Height=6
NumControls=7
Procedure=8
Font=9
Textcolor=10
Background=11
Config=12

[DLG_CTRL_ATTR]
X=1
Y=2
Width=3
Height=4
Type=5
Var=6
Text=7
Value=8
Taborder=9
Style=10
Font=11
Textcolor=12
Background=13

[WDL2INI]
ProductName=WDL2INI
FileVersion=1.00
FileVersionDate=20030922
FileDescription=Conversion from WinBatch dialog file (wdl) to Ini file (ini)
ProductVersion=1
LegalCopyright=(c)20030922 Detlev Dalitz

;------------------------------------------------------------------------------------------------------------------------------------------