Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GUIConstantsEx.au3>
- #include <GuiMenu.au3>
- #include <WindowsConstants.au3>
- #include <StaticConstants.au3>
- #include <ButtonConstants.au3>
- #include <GuiButton.au3>
- #include <GuiImageList.au3>
- #include <FontConstants.au3>
- #include <Array.au3>
- $sp = '|'
- Opt("GUIDataSeparatorChar", $sp)
- Local $i_ID_Boot_Item[1], $a_List, $i_ID_Src_Item[1], $aDrive
- $hGUI = GUICreate("Test WinSetup", 576, 473)
- If Not @Compiled Then GUISetIcon("shell32.dll", -42)
- $iBtnSource = GUICtrlCreateButton('Dummy', 0, 0, 570, 23)
- $hImgSrc = _GUIImageList_Create(32, 32, 5, 3, 6)
- ; _GUIImageList_AddIcon($hImgSrc, "shell32.dll", -42, True)
- _GUIImageList_AddIcon($hImgSrc, "shell32.dll", 235, True)
- $hImgDisk = _GUIImageList_Create(32, 32, 5, 3, 6)
- ; _GUIImageList_AddIcon($hImgDisk, "shell32.dll", -9, True)
- _GUIImageList_AddIcon($hImgDisk, "shell32.dll", 234, True)
- GUICtrlCreateGroup('Select location of Windows installation files', 10, 33, 550, 90)
- GUICtrlSetFont(-1, 11, 400)
- $iBtnSource = GUICtrlCreateButton('Select...', 20, 58, 90, 40)
- _GUICtrlButton_SetImageList(-1, $hImgSrc)
- $iLbSource = GUICtrlCreateInput('', 120, 65, 430, 22)
- $iDummySrc = GUICtrlCreateDummy()
- GUICtrlCreateGroup('Select location of the Boot drive', 10, 128, 550, 90)
- GUICtrlSetFont(-1, 11, 400)
- $iBtnDisk = GUICtrlCreateButton('Select', 20, 158, 90, 40)
- _GUICtrlButton_SetImageList(-1, $hImgDisk)
- $iLbDisk = GUICtrlCreateLabel(' Disk: none', 120, 165, 330, 26, $SS_CENTERIMAGE + $SS_LEFTNOWORDWRAP)
- ; GUICtrlSetBkColor(-1, 0xF0F0F0)
- ; $iLbDiskBig = GUICtrlCreateInput('', 120, 143, 40, 26)
- GUICtrlSetFont(-1, 10, 400)
- ; GUICtrlSetBkColor(-1, 0xfdffae)
- GUICtrlCreateLabel('MBR', 450, 140, 80, 17, $SS_RIGHT)
- GUICtrlCreateLabel('BOOTMGR PBR', 450, 160, 80, 17, $SS_RIGHT)
- GUICtrlCreateLabel('BOOT PART', 450, 180, 80, 17, $SS_RIGHT)
- $icon1 = GUICtrlCreateIcon("shell32.dll", -145, 534, 140, 16, 16)
- $icon2 = GUICtrlCreateIcon("shell32.dll", -145, 534, 160, 16, 16)
- $icon3 = GUICtrlCreateIcon("shell32.dll", -145, 534, 180, 16, 16)
- $iBtnFrm = GUICtrlCreateButton('Formatting', 250, 192, 90, 22)
- GUICtrlSetState(-1, $GUI_DISABLE)
- GUICtrlCreateGroup('Select location of the Installation drive', 10, 228, 550, 90)
- GUICtrlSetFont(-1, 11, 400)
- $iBtnDisk2 = GUICtrlCreateButton('Select', 20, 258, 90, 40)
- _GUICtrlButton_SetImageList(-1, $hImgDisk)
- $iLbDisk2 = GUICtrlCreateLabel(' 0:3 E: Fixed WinXP_50/1000 NTFS 50.294 Gb', 120, 265, 330, 26, $WS_BORDER + $SS_CENTERIMAGE + $SS_LEFTNOWORDWRAP)
- GUICtrlSetBkColor(-1, 0xFFFFCE)
- ; $iLbDiskBig2 = GUICtrlCreateInput('', 120, 243, 40, 22)
- GUICtrlSetFont(-1, 11, 400)
- ; GUICtrlSetBkColor(-1, 0xfdffae)
- $iBtnFrm = GUICtrlCreateButton('Formatting', 250, 292, 90, 22)
- GUICtrlCreateGroup('Options', 10, 323, 550, 100)
- GUICtrlCreateGroup('', 10, 423, 550, 40)
- GUISetState()
- GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
- While 1
- Switch GUIGetMsg()
- Case $iDummySrc
- $sPath = FileOpenDialog('Choose...', "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "image (*.wim)", 1 + 4, 'install.wim', $hGUI)
- If Not @error Then GUICtrlSetData($iLbSource, $sPath)
- Case $iBtnDisk
- _CreateMenuDisk()
- Case $iBtnSource
- $tmp = _CreateMenuSource()
- If @extended Then GUICtrlSetData($iLbSource, $tmp)
- Case $GUI_EVENT_CLOSE
- Exit
- EndSwitch
- WEnd
- Func _CreateMenuSource()
- Local $aPos, $iContMenu, $tpoint, $d, $sPath ;, $hFont
- $aDrive = DriveGetDrive('ALL')
- If Not @error Then
- $iContMenu = GUICtrlCreateContextMenu($iBtnSource)
- ; GUICtrlSetFont(-1, -1, -1, -1, "Courier New")
- ; $hFont = _WinAPI_CreateFont(16, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, "Courier New")
- ; If $hFont Then
- ; _WinAPI_SetFont(GUICtrlGetHandle($iContMenu), $hFont)
- ; Else
- ; $iError += 1
- ; EndIf
- ReDim $i_ID_Src_Item[$aDrive[0] + 1]
- $i_ID_Src_Item[0] = $aDrive[0]
- $d = 0
- For $i = 1 To $aDrive[0]
- If $aDrive[$i] = 'a:' Or $aDrive[$i] = 'b:' Then ContinueLoop
- If FileExists($aDrive[$i] & '\sources\install.wim') Then
- $d += 1
- $aDrive[$d] = $aDrive[$i] & '\sources\install.wim'
- $i_ID_Src_Item[$d] = GUICtrlCreateMenuItem($aDrive[$d], $iContMenu)
- EndIf
- Next
- If $d = 0 Then
- GUICtrlDelete($iContMenu)
- ; If $hFont Then _WinAPI_DeleteObject($hFont)
- ReDim $i_ID_Src_Item[1]
- $i_ID_Src_Item[0] = 0
- $aDrive = 0
- $sPath = FileOpenDialog('Choose...', "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "image (*.wim)", 1 + 4, 'install.wim', $hGUI)
- If Not @error Then Return SetError(0, 1, $sPath)
- Return
- EndIf
- $d += 1
- $aDrive[$d] = 'Choose other'
- $i_ID_Src_Item[$d] = GUICtrlCreateMenuItem($aDrive[$d], $iContMenu)
- ReDim $i_ID_Src_Item[$d + 1]
- $i_ID_Src_Item[0] = $d
- ReDim $aDrive[$d + 1]
- $aPos = ControlGetPos($hGUI, "", $iBtnSource)
- $tpoint = DllStructCreate("int X;int Y")
- DllStructSetData($tpoint, "X", $aPos[0])
- DllStructSetData($tpoint, "Y", $aPos[1] + $aPos[3])
- _WinAPI_ClientToScreen($hGUI, $tpoint)
- _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($iContMenu), $hGUI, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 1)
- GUICtrlDelete($iContMenu)
- ; If $hFont Then _WinAPI_DeleteObject($hFont)
- EndIf
- ReDim $i_ID_Src_Item[1]
- $i_ID_Src_Item[0] = 0
- $aDrive = 0
- Return
- EndFunc ;==>_CreateMenu
- Func _CreateMenuDisk()
- Local $aPos, $iContMenu, $sList, $tpoint
- $sList = _GetDrv()
- If $sList Then
- $iContMenu = GUICtrlCreateContextMenu($iBtnDisk)
- GUICtrlSetFont(-1, -1, -1, -1, "Courier New")
- $a_List = StringSplit($sList, $sp)
- ReDim $i_ID_Boot_Item[$a_List[0] + 1]
- $i_ID_Boot_Item[0] = $a_List[0]
- For $i = 1 To $a_List[0]
- $i_ID_Boot_Item[$i] = GUICtrlCreateMenuItem($a_List[$i], $iContMenu)
- Next
- $aPos = ControlGetPos($hGUI, "", $iBtnDisk)
- $tpoint = DllStructCreate("int X;int Y")
- DllStructSetData($tpoint, "X", $aPos[0])
- DllStructSetData($tpoint, "Y", $aPos[1] + $aPos[3])
- _WinAPI_ClientToScreen($hGUI, $tpoint)
- _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($iContMenu), $hGUI, DllStructGetData($tpoint, "X"), DllStructGetData($tpoint, "Y"), 1)
- GUICtrlDelete($iContMenu)
- EndIf
- ReDim $i_ID_Boot_Item[1]
- $i_ID_Boot_Item[0] = 0
- $a_List = 0
- EndFunc ;==>_CreateMenu
- Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
- Local $iID = BitAND($wParam, 0x0000FFFF)
- If $i_ID_Boot_Item[0] Then
- Switch $iID
- Case $i_ID_Boot_Item[1] To $i_ID_Boot_Item[$i_ID_Boot_Item[0]]
- GUICtrlSetData($iLbDisk, $a_List[$iID - $i_ID_Boot_Item[1] + 1])
- ; Local $tmp = StringRegExp($a_List[$iID - $i_ID_Boot_Item[1] + 1], '(?i)^.{6}([a-z]:).+', 1)
- ; If Not @error Then GUICtrlSetData($iLbDiskBig, $tmp[0])
- $i_ID_Boot_Item[0] = 0
- Return $GUI_RUNDEFMSG
- EndSwitch
- EndIf
- If $i_ID_Src_Item[0] Then
- Switch $iID
- Case $i_ID_Src_Item[1] To $i_ID_Src_Item[$i_ID_Src_Item[0]]
- If $aDrive[$iID - $i_ID_Src_Item[1] + 1] = 'Choose other' Then
- GUICtrlSendToDummy($iDummySrc)
- Else
- GUICtrlSetData($iLbSource, $aDrive[$iID - $i_ID_Src_Item[1] + 1])
- EndIf
- $i_ID_Src_Item[0] = 0
- Return $GUI_RUNDEFMSG
- EndSwitch
- EndIf
- EndFunc ;==>WM_COMMAND
- Func _GetDrv()
- Local $sInfo = _ComboListDrive('Fixed')
- $sInfo &= _ComboListDrive('Removable')
- Return StringTrimLeft($sInfo, 1)
- EndFunc
- Func _ComboListDrive($Type) ; coded by AZJIO (2013.01.26)
- Local $aDrive = DriveGetDrive($Type), $list = '', $sString, $sLabel, $aDisc_Partition
- If @error Then Return ''
- If $Type = 'Removable' Then $Type = 'Rem'
- For $i = 1 To $aDrive[0]
- If $aDrive[$i] = 'A:' Then ContinueLoop
- $sLabel = DriveGetLabel($aDrive[$i])
- If StringLen($sLabel) > 15 Then $sLabel = StringLeft($sLabel, 12) & '...'
- $aDisc_Partition = _GetDiskNimberForDrive($aDrive[$i])
- ; If @error Then Local $aDisc_Partition[2] = ['?', '?']
- $sString = StringFormat('%2s:%-2s %-2s %-5s %-15s %-5s ', $aDisc_Partition[0], $aDisc_Partition[1], StringUpper($aDrive[$i]), $Type, $sLabel, _
- DriveGetFileSystem($aDrive[$i])) & _GetSize(DriveSpaceTotal($aDrive[$i])) & ' Gb'
- $list &= $sp & $sString
- Next
- Return $list
- EndFunc ;==>_ComboListDrive
- Func _GetSize($s)
- $s = StringFormat('%.03f', $s / 1024)
- If StringLen($s) > 7 Then $s = StringRegExpReplace(StringTrimRight($s, 4), '(\A\d{1,3}(?=(\d{3})+\z)|\d{3}(?=\d))', '\1 ') & StringRight($s, 4)
- Return StringFormat('%9s', $s) ; 9 терабайт
- EndFunc
- ; http://www.autoitscript.com/forum/topic/91598-get-disk-number-from-drive-letter/?p=659721
- ; Описание ........: Возвращает номер диска и номер раздела в формате n:n (<номер диска>:<номер раздела>)
- ; Параметры:
- ; $sDriveLetter - Буква диска с двоеточием, например C:
- ; Неудачно , возвращает -1, @error:
- ; |1 - Ошибка CreateFile, ваша система очень старая
- ; |2 - Диск не существует
- ; |3 - Неудачный вызов DeviceIoControl
- ; |4 - Не раздела диска
- Func _GetDiskNimberForDrive($sDriveLetter) ; Буква диска
- Local $aDrive[2] = ['?', '?']
- Local $a_hCall = DllCall("kernel32.dll", "hwnd", "CreateFile", _
- "str", "\\.\" & $sDriveLetter, _; Буква диска
- "dword", 0, _
- "dword", 0, _
- "ptr", 0, _
- "dword", 3, _; OPEN_EXISTING
- "dword", 128, _; FILE_ATTRIBUTE_NORMAL
- "ptr", 0)
- If @error Then
- Return SetError(1, 0, $aDrive); Ваша система очень старая. Сделайте что-нибудь.
- EndIf
- If $a_hCall[0] = -1 Then
- Return SetError(2, 0, $aDrive) ; Диск не существует
- EndIf
- Local $hDevice = $a_hCall[0]
- Local $tIOCTL_STORAGE_GET_DEVICE_NUMBER = DllStructCreate("dword DeviceType;" & _
- "dword DeviceNumber;" & _
- "int PartitionNumber")
- Local $a_iCall = DllCall("kernel32.dll", "int", "DeviceIoControl", _
- "hwnd", $hDevice, _
- "dword", 0x2D1080, _; IOCTL_STORAGE_GET_DEVICE_NUMBER
- "ptr", 0, _
- "dword", 0, _
- "ptr", DllStructGetPtr($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _
- "dword", DllStructGetSize($tIOCTL_STORAGE_GET_DEVICE_NUMBER), _
- "dword*", 0, _
- "ptr", 0)
- If @error Or Not $a_hCall[0] Then
- DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice)
- Return SetError(3, 0, $aDrive); неудачный вызов DeviceIoControl
- EndIf
- DllCall("kernel32.dll", "int", "CloseHandle", "hwnd", $hDevice)
- If DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceType") = 7 Then; FILE_DEVICE_DISK
- $aDrive[0] = DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "DeviceNumber")
- $aDrive[1] = DllStructGetData($tIOCTL_STORAGE_GET_DEVICE_NUMBER, "PartitionNumber")
- Return SetError(0, 0, $aDrive)
- EndIf
- Return SetError(4, 0, $aDrive); Не раздела диска
- EndFunc ;==>_GetDiskNimberForDrive
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement