'On Error Resume Next

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Dim Fso, Shell, ts, batfile, rarfile, oExec

Set Fso = CreateObject("Scripting.FileSystemObject")
Set Shell = CreateObject("WScript.Shell")
AP = Fso.GetParentFolderName(Wscript.ScriptFullName)

batfile = AP & "\cap.bat"
rarfile = AP & "\AlonePlayer.rar"

if not Fso.FileExists(rarfile) Then
                
    ' 创建文件        
    Set ts = Fso.OpenTextFile(batfile, ForWriting, TristateUseDefault)
    ts.WriteLine("cd " & AP )
    ts.write("Rar.dll a -o+ -ep1 -ap ")
    ts.write(chr(34) & AP & "\AlonePlayer.rar" & chr(34))
    ' 播放器文件
    ts.write(" AlonePlayer.exe ")
    
    ' 从xml中读入文件
    set Doc = CreateObject("Microsoft.XMLDOM") 
    Doc.async = false 
    if Doc.load(AP & "\EdmDecode.xml") then
        ' 公共部分
        set objRootsite = Doc.documentElement.selectSingleNode("Common")  
        If objRootsite.HasChildNodes Then
            For i = 0 To objRootsite.ChildNodes.length - 1
               ts.write(objRootsite.ChildNodes.item(i).text & " ")                
            next   
        end if
        
        ' 各种板卡
        set objRootsite = Doc.documentElement.selectSingleNode("Soft")    
        If objRootsite.HasChildNodes Then
            For i = 0 To objRootsite.ChildNodes.length - 1
               ts.write(objRootsite.ChildNodes.item(i).Attributes.item(1).text & " ")
               ts.write(objRootsite.ChildNodes.item(i).text & " ")
            next   
        end if
    end if  
    ts.Close()

    ' 执行批处理    
    Shell.Run chr(34)&batfile&chr(34), 1, true
    
    ' 删除批处理
    Fso.DeleteFile(batfile) 
end if

if Fso.FileExists(rarfile) Then
    Shell.Run("Explorer " & chr(34)&rarfile&chr(34))
Else
    WScript.Echo("文件产生失败[Documents have failed]")
end if

