'
' Author: tlviewer@yahoo.com
' script: chmdump.vbs
' Description: open the dropped chm and write a toc in html from the HHC
' keywords: content msits htmlhelp dump toc
' Date: 02/22/07
'
' ------------------------------------------------
' --- revision history ---------------------------
''''''''''''''' set cscript to default engine '''''''''''''
' >cscript //H:Cscript
''''''''''''''''''''''''''''''''''''
'
'ms-its:\\hercules\e$\batch\perl\PDF_Hacks_Aug2004_OReilly.chm::/0596006551/main.html
'ms-its:e:\batch\perl\PDF_Hacks_Aug2004_OReilly.chm::/0596006551/main.html
' --- end of revisions ---------------------------
' ------ begin DumpCHM.vbs ------------
set osh = createobject("WScript.Shell")
set fso = createobject("Scripting.FileSystemObject")
' classic url type
sSrcUrl = "mk:@MSITStore:C:\Wsh\script56.chm::"
mychm = "e:\batch\perl\PDF_Hacks_Aug2004_OReilly.chm"
' use of the dropped filename is preferred
set args = WScript.Arguments
if args.count > 0 then
mychm = args(0)
end if
if NOT fso.fileexists( mychm) then
wscript.echo "your CHM file is not found"
wscript.quit
end if
' for IE 4+ use this form for the URL
sSrcUrl = "ms-its:" & mychm & "::"
' "ms-its:C:\Wsh\script56.chm::"
'
sDestFolder = "e:\batch\vbscript\"
sDestFolder = ScriptPath()
'sHHC = "0596006551.hhc" '"#STRINGS"
dlstr = DLFile( sSrcUrl & "#STRINGS")
' convert byte array to string
'dim strout()
'redim strout(ubound(dlstr)-1)
for I = 1 to Ubound(dlstr) - 1
strout = strout & Chr(AscB(MidB(dlstr, I, 1)))
Next
wscript.echo vartype(dlstr)
arDL = split(strout, chr(0) )
wscript.echo len(dlstr),ubound(arDL)
for nI=0 to ubound(arDL)
sHHC = arDL(nI)
if right(sHHC,3) = "hhc" then
wscript.echo sHHC, "leaving loop"
exit for
end if
next
'0596006551.hhc"
gotfile = fso.fileexists( sDestFolder & sHHC )
wscript.echo gotfile
if NOT gotfile then
wscript.echo "writing HHC file"
httpbody = DLFile( sSrcUrl & sHHC )
set oStream = createobject("adodb.stream")
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2
oStream.type = adTypeBinary
oStream.open
oStream.write httpbody
oStream.savetofile sDestFolder & sHHC, adSaveCreateOverWrite
else
wscript.echo "HHC found"
end if
infile = fso.OpenTextFile( sDestFolder & sHHC ).ReadAll()
wscript.echo len(infile)
arrObj = split( infile, "" & vbcrlf)
wscript.echo ubound(arrObj)
set outfile = fso.createtextfile( sDestFolder & "mytoc.html" , vbtrue)
for nJ = 0 to ubound(arrObj)
nameval = split( arrObj(nJ),">" & vbCrLf)
if ubound(nameval) > 3 then
for nK=0 to ubound(nameval)
spair = split(nameval(nK)," 0 then
val = split(spair(1), """ value=""")
sname = vbNullString
if right(val(0),4)="Name" then sname= left(val(1),len(val(1))-1)
if right(val(0),4)="ocal" then sval = left(val(1),len(val(1))-1)
'wscript.echo spair(1)
if len(sname)>0 then
outfile.writeline "" & sname & "" & "
"
end if
end if
next
end if
next
outfile.close
' show the toc in IE browser
osh.run "iexplore.exe " & sDestFolder & "mytoc.html"
' ------------helper functions ------------
Function ScriptPath()
ScriptPath = Left(WScript.ScriptFullName, _
Len(WScript.ScriptFullName) - Len(WScript.ScriptName))
End Function
function DLFile(myfile)
' returns 8209 byte array -- watch out!
set oHTTP = CreateObject("msxml2.XMLHTTP")
oHTTP.open "GET", myfile, False
oHTTP.send
DLFile = oHTTP.responseBody
set oHTTP = nothing
end function
'wscript.echo join(arrObj, vbcrlf)
' -------- end script ---------------