#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <GUIListView.au3>
#Include <WinAPI.au3>
$hGui = GUICreate("AutoIt3-Explorer V1.1 ;-)", 762, 578, -1, -1, BitOr($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
$nViewMenu = GUICtrlCreateMenu("&View")
$nViewItem1 = GUICtrlCreateMenuItem("Icons", $nViewMenu, -1, 1)
$nViewItem2 = GUICtrlCreateMenuItem("Report", $nViewMenu, -1, 1)
GUICtrlSetState(-1, $GUI_CHECKED)
$nViewItem3 = GUICtrlCreateMenuItem("Small Icons", $nViewMenu, -1, 1)
$nViewItem4 = GUICtrlCreateMenuItem("List", $nViewMenu, -1, 1)
$Input1 = GUICtrlCreateInput("", 160, 24, 449, 21)
$nListView = GUICtrlCreateListView("Name|Size/Type|Changed",162, 49, 447, 489)
GUICtrlSendMsg(-1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$file = FileOpen("test.txt", 0)
DirToList($file)
GUICtrlSendMsg($nListView, $LVM_SETCOLUMNWIDTH, 0, 180)
GUISetState()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
            
        Case $nViewItem1 To $nViewItem4
            GUICtrlSetStyle($nListView, BitOr($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $nMsg - $nViewItem1))
    EndSwitch
WEnd
Func DirToList($szPath)
    Dim $hSearch, $szFile, $szDate, $szType, $nItem
	While 1
		$line = FileReadLine($szPath)
		If @error = -1 Then ExitLoop
		$days = StringSplit($line, "|")
		$xline = StringRegExpReplace($days[1], '^.*\\', '')
		If $xline = "" Then
		Else
			$nItem = GUICtrlCreateListViewItem($xline & "|", $nListView)
			local $Icon = _GetRegDefIcon($days[1])
			GUICtrlSetImage($nItem, $Icon[0], $Icon[1])
			If $days[2] = "Dir" Then
				GUICtrlSetData($nItem,"|DIR|" & $days[3])
				GUICtrlSetImage($nItem, "shell32.dll", 4)
			Else
				GUICtrlSetData($nItem,"|" & $days[2] & "|" & $days[3])
			EndIf
		EndIf
	Wend
	GUICtrlSetData($Input1, StringRegExpReplace($days[1], '\\.[^\\]*\Z', '\\'))
	FileClose($file)
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView = $nListView
    If Not IsHWnd($nListView) Then $hWndListView = GUICtrlGetHandle($nListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
   
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_DBLCLK
					$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
					$iItem = DllStructGetData($tInfo, 'Index')
					$xName = _GUICtrlListView_GetItemText($hWndListView, $iItem)
					If $xName = "" Then
					Else
						$days = StringSplit(GUICtrlRead(GUICtrlRead($nListView)), "||")
						If $days[2] = "DIR" Then
							MsgBox(4096,"", GUICtrlRead($Input1) & $xName)
							MsgBox(4096,"", "DIRRRR")
						Else
							MsgBox(4096,"", GUICtrlRead($Input1) & $xName)
							MsgBox(4096,"", "FILEEE")						
						EndIf	
					EndIf	
            EndSwitch
    EndSwitch
   
    Return $GUI_RUNDEFMSG
EndFunc
func _GetRegDefIcon($Path)
    
    const $DF_NAME  = @SystemDir & '\shell32.dll'
    const $DF_INDEX = 0
    
    local $filename, $name, $ext, $count, $curver, $defaulticon, $ret[2] = [$DF_NAME, $DF_INDEX]
    
    $filename = StringTrimLeft($Path, StringInStr($Path, '\', 0, -1))
    $count = StringInStr($filename, '.', 0, -1)
    if $count > 0 then
        $count = StringLen($filename) - $count + 1
    endif
    $name = StringStripWS(StringTrimRight($filename, $count), 3)
    $ext = StringStripWS(StringRight($filename, $count - 1), 8)
    if (StringLen($name) = 0) or (StringLen($ext) = 0) then
        return $ret
    endif
    $curver = StringStripWS(RegRead('HKCR\' & RegRead('HKCR\' & '.' & $ext, '') & '\CurVer', ''), 3)
    if (@error) or (StringLen($curver) = 0) then
        $defaulticon =  _WinAPI_ExpandEnvironmentStrings(StringReplace(RegRead('HKCR\' & RegRead('HKCR\' & '.' & $ext, '') & '\DefaultIcon', ''), '''', ''))
    else
        $defaulticon =  _WinAPI_ExpandEnvironmentStrings(StringReplace(RegRead('HKCR\' & $curver & '\DefaultIcon', ''), '''', ''))
    endif
    $count = StringInStr($defaulticon, ',', 0, -1)
    if $count > 0 then
        $count = StringLen($defaulticon) - $count
        $ret[0] = StringStripWS(StringTrimRight($defaulticon, $count + 1), 3)
        if $count > 0 then
            $ret[1] = StringStripWS(StringRight($defaulticon, $count), 8)
        endif
    else
        $ret[0] = StringStripWS(StringTrimRight($defaulticon, $count), 3)
    endif
    if StringLeft($ret[0], 1) = '%' then
        $count = DllCall('shell32.dll', 'int', 'ExtractIcon', 'int', 0, 'str', $Path, 'int', -1)
        if $count[0] = 0 then
            $ret[0] = $DF_NAME
            if StringLower($ext) = 'exe' then
                $ret[1] = 2
            else
                $ret[1] = 0
            endif
        else
            $ret[0] = StringStripWS($Path, 3)
            $ret[1] = 0
        endif
    else
        if (StringLen($ret[0]) > 0) and (StringInStr($ret[0], '\', 0) = 0) then
            $ret[0] = @SystemDir & '\' & $ret[0]
        endif
    endif
    if not FileExists($ret[0]) then
        $ret[0] = $DF_NAME
        $ret[1] = $DF_INDEX
    endif
    if $ret[1] < 0 then
        $ret[1] = - $ret[1]
    else
        $ret[1] = - $ret[1] - 1
    endif
    return $ret
endfunc; _GetRegDefIcon