#RequireAdmin
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
Global $Wimlib="F:\PETOOLS\镜像工具\wimlib\wimlib-imagex.exe"
Global $wimdism=@WindowsDir&"\system32\dism.exe"
$Form_main = GUICreate("", 530, 520, -1, -1)
Global $Edit = GUICtrlCreateEdit("",20, 445, 490, 50)
GUICtrlSetData(-1, "<返回值显示区域>")
GUICtrlCreateGroup("", -99, -99, 1, 1)
Local $idListview = GUICtrlCreateListView("", 50, 50, 430, 350,-1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES,$LVS_EX_CHECKBOXES))
_GUICtrlListView_AddColumn($idListview, "", 40, 2)
_GUICtrlListView_AddColumn($idListview, " 映像文件", 160, 2)
_GUICtrlListView_AddColumn($idListview, "卷号", 40, 2)
_GUICtrlListView_AddColumn($idListview, " 名称", 140, 2)
_GUICtrlListView_AddColumn($idListview, "描述", 50, 2)
_GUICtrlListView_AddColumn($idListview, "系统标志", 50, 2)
$Handle = GUICtrlGetHandle(-1)
$Button1 = GUICtrlCreateButton("添加文件", 208, 402, 73, 33)
$Button2 = GUICtrlCreateButton("导出文件", 308, 402, 73, 33)
GUISetState(@SW_SHOW, $Form_main)
;GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Button1
$addfile = FileOpenDialog("请选择一个映像文件", "", "wim文件 (*.wim)", 1, "", $Form_main)
;MsgBox(0,"",$addfile)
disminfo()
Case $Button2
ab()
EndSwitch
WEnd
Func disminfo()
Local $sMountInfo = @ScriptDir&"\MountInfo.txt"
FileDelete($sMountInfo)
RunWait(@ComSpec & ' /C ' & $wimdism & ' /Get-WimInfo /WimFile:'&$addfile&' > '& $sMountInfo, @WindowsDir & '\system32', @SW_HIDE)
;RunWait(@ComSpec & ' /C ' & $Wimlib & ' info '&$addfile&' > '& $sMountInfo, @WindowsDir & '\system32', @SW_HIDE)
$MountTxt = FileRead($sMountInfo)
Local $Index = StringRegExp($MountTxt, '索引:(\V+)', 3)
Local $Filepath = StringRegExp($MountTxt, '映像的详细信息: (\V+)', 3)
Local $imagename=StringRegExp($MountTxt, '名称:(\V+)', 3)
Local $imageDescription=StringRegExp($MountTxt, '描述: (\V+)', 3)
;Local $imageFlags=StringRegExp($MountTxt, 'Flags: (\V+)', 3)
For $i = 0 To UBound($imagename )-1
GUICtrlCreateListViewItem(""&"|"& $Filepath[0] &"|"&$Index[$i]&"|"&$imagename[$i]&"|"&$imageDescription[$i],$idListview)
Next
EndFunc
Func ab()
GUICtrlSetState($Button1 ,$GUI_DISABLE)
GUICtrlSetState($Button2 ,$GUI_DISABLE)
Local $bool = False
If _GUICtrlListView_GetItemCount($idListview)=0 Then
MsgBox(0,"","还没添加文件,不能继续!!!")
GUICtrlSetState($Edit, $GUI_ENABLE)
GUICtrlSetState($Button1,$GUI_ENABLE)
GUICtrlSetState($Button2,$GUI_ENABLE)
ElseIf _GUICtrlListView_GetItemCount($idListview)>=1 Then
$WimFile =""
$ImageID=""
$ImageName=""
For $I = 0 To _GUICtrlListView_GetItemCount($idListview)-1
If _GUICtrlListView_GetItemChecked($idListview,$i)=False Then ;如此处加入未选中判断,但要点很多次确定,怎样才能实现未选中停止执行
MsgBox(0,"","没有选择,不能继续")
ElseIf _GUICtrlListView_GetItemChecked($idListview,$i)=True Then
$WimFile &= _GUICtrlListView_GetItemText($idListview, $i,1)&@CRLF
$ImageID &=_GUICtrlListView_GetItemText($idListview, $i,2)&@CRLF
$ImageName&=_GUICtrlListView_GetItemText($idListview, $i,3)&@CRLF
EndIf
Next
Local $expropath="e:\test.wim"
Local $aData=StringRegExp($WimFile,'(?<grp0>[^\n]+)',3)
Local $id=StringRegExp($ImageID,'(?<grp0>[^\D]+)',3)
For $i=0 To UBound($aData)-1
ToolTip(" 正在合并 " & ($aData)[$i] &"--------"&$id[$i]&"号卷映像 ", @DesktopWidth-320, @DesktopHeight-100)
Local $exportwim=Run(@ComSpec & ' /C ' & $wimdism& ' /Export-Image /SourceImageFile:' & $aData[$i] & ' /SourceIndex:'& $id[$i] & ' /DestinationImageFile:'&$expropath, @WindowsDir & '\system32',@SW_HIDE, $STDOUT_CHILD);dism导出wim映像
While 1
$line = StdoutRead($exportwim)
If @error Then ExitLoop
GUICtrlSetData($Edit, $line, -1)
Wend
Next
MsgBox(0,"","合并完成!!!",5)
GUICtrlSetState($Edit, $GUI_ENABLE)
GUICtrlSetState($Button1,$GUI_ENABLE)
GUICtrlSetState($Button2,$GUI_ENABLE)
EndIf
EndFunc