Sign in to follow this  
Followers 0
sulfurious

Open array in treeview, choose what to strip out

1 post in this topic

Providing the .reg file to be opened is ASCII.

#include <GUIConstants.au3>
#include <GuiTreeView.au3>
#include <file.au3>
#include <string.au3>
#include <array.au3>

Dim $arrFIN[1][2]
Opt("GUIOnEventMode", 1)
$winFinalFilter = GUICreate("Remove leftovers", 622, 465, 326, 115,$WS_SIZEBOX+$WS_SYSMENU)
GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT")
$treFILTERS = GUICtrlCreateTreeView(3, 3, 615, 400,BitOr($TVS_HASBUTTONS,$TVS_CHECKBOXES, $TVS_HASLINES, $TVS_LINESATROOT _
, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
GUICtrlSetResizing(-1,$GUI_DOCKBOTTOM)
$btnFinishFinal = GUICtrlCreateButton("Finish",15,405,50,25)
GUICtrlSetResizing(-1,$GUI_DOCKBOTTOM + $GUI_DOCKLEFT + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH)
GUICtrlSetOnEvent(-1,"_valsWRITE")
GUISetState(@SW_SHOW)
_fillTREE()
While 1
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc

Func _fillTREE()
    Local $fi = FileOpen(@DesktopDir & "\c3.reg",0)
    Local $re = FileRead($fi)
    Local $ar = StringSplit($re,"[")
    Local $arr
    For $i = 1 To $ar[0]
        $arr = StringSplit($ar[$i],@CRLF)
        For $x = 1 To $arr[0]
            If $arr[$x] = "" Then ContinueLoop
            If $x = 1 Then 
                _ArrayAdd2($arrFIN,1,"[" & $arr[$x])
            Else
                _ArrayAdd2($arrFIN,0,$arr[$x])
            EndIf
        Next
    Next
    ReDim $arrFIN[UBound($arrFIN)-1][3]
    Local $ix = 1
    For $i = 1 To UBound($arrFIN) - 1
        If $arrFIN[$i][0] = 1 Then
            $ix = $i 
            $arrFIN[$i][2] = GUICtrlCreateTreeViewItem($arrFIN[$i][1],$treFILTERS)
            _GUICtrlTreeViewSetState($treFILTERS,-1,48)
            GUICtrlSetOnEvent(-1,"_treeEVENT")
        Else
            $arrFIN[$i][2] = GUICtrlCreateTreeViewItem($arrFIN[$i][1],$arrFIN[$ix][2])
            GUICtrlSetOnEvent(-1,"_treeEVENT")
        EndIf
    Next
EndFunc

Func _treeEVENT()
    For $x = 1 to UBound($arrFIN) - 1
        If $arrFIN[$x][2] = @GUI_CtrlId Then
            If $arrFIN[$x][0] = 0 Then ; Child directory
                If BitAND(GUICtrlRead(@GUI_CtrlId),$GUI_CHECKED) Then
                    $arrFIN[$x][1] = "del"
                    GUICtrlSetColor(@GUI_CtrlId,0xFF0000)
                    ExitLoop
                Else
                    $arrFIN[$x][1] = GUICtrlRead(@GUI_CtrlId,1)
                    GUICtrlSetColor(@GUI_CtrlId,0x000000)
                    If BitAND(GUICtrlRead(_GUICtrlTreeViewGetParentID($treFILTERS)),$GUI_CHECKED) Then
                        GUICtrlSetState(_GUICtrlTreeViewGetParentID($treFILTERS),$GUI_UNCHECKED)
                        GUICtrlSetColor(_GUICtrlTreeViewGetParentID($treFILTERS),0x000000)
                        For $i = 1 To UBound($arrFIN) - 1
                            If $arrFIN[$i][2] = _GUICtrlTreeViewGetParentID($treFILTERS) Then
                                $arrFIN[$i][1] = GUICtrlRead(_GUICtrlTreeViewGetParentID($treFILTERS),1)
                                ExitLoop
                            EndIf
                        Next
                    EndIf
                    ExitLoop
                EndIf
            ElseIf $arrFIN[$x][0] = 1 Then ; Parent dirctory
                If BitAND(GUICtrlRead(@GUI_CtrlId),$GUI_CHECKED) Then
                    $arrFIN[$x][1] = "del"
                    GUICtrlSetColor(@GUI_CtrlId,0xFF0000)
                    $ix = $x + 1
                    While  1
                        If $arrFIN[$ix][0] = 1 Or $ix = UBound($arrFIN) - 1 Then ExitLoop
                        GUICtrlSetColor($arrFIN[$ix][2],0xFF0000)
                        GUICtrlSetState($arrFIN[$ix][2],$GUI_CHECKED)
                        $arrFIN[$ix][1] = "del"
                        $ix+=1
                    WEnd
                    ExitLoop
                Else
                    $arrFIN[$x][1] = GUICtrlRead(@GUI_CtrlId,1)
                    GUICtrlSetColor(@GUI_CtrlId,0x000000)
                    $ix = $x + 1
                    While 1
                        If $arrFIN[$ix][0] = 1 Or $ix = UBound($arrFIN) - 1 Then ExitLoop
                        GUICtrlSetColor($arrFIN[$ix][2],0x000000)
                        GUICtrlSetState($arrFIN[$ix][2],$GUI_UNCHECKED)                     
                        $arrFIN[$ix][1] = GUICtrlRead($arrFIN[$ix][2],1)
                        $ix+=1
                    WEnd
                    ExitLoop
                EndIf
            EndIf
        EndIf
    Next
EndFunc
Func _valsWRITE()
    Local $f = FileOpen(@DesktopDir & "\thurdaytest.txt",2)
    For $i = 1 to UBound($arrFIN) - 1
        If $arrFIN[$i][1] <> "del" Then FileWriteLine($f,$arrFIN[$i][1])
    Next
    FileClose($f)
    MsgBox(0,"","done",1)   
EndFunc


Func _ArrayAdd2(ByRef $avArray, $sValue1 = "", $sValue2 = "")
    If IsArray($avArray) Then
        ReDim $avArray[UBound($avArray) + 1][2]
        $avArray[UBound($avArray) - 1][0] = $sValue1
        $avArray[UBound($avArray) - 1][1] = $sValue2
        SetError(0)
        Return 1
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc   ;--->>> _ArrayAdd2

late,

Sul

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0