Sign in to follow this  
Followers 0
XPhiles

Rebuilding a Tree

4 posts in this topic

I have a gui that I am using to do file compares on a remote and local machine. What I want to do is when the tree is created (which can take a while because of the directories chosen, I create a backup of the created tree. What I want to do is delete the tree and rebuild it using the backup that has nothing checked. I have tried to uncheck all items and it simply does not work, it unchecks some but not all. Here is a code snippet. This assumes the local and remote machines are passed to the function

Func _FileCompareResults($Comp)
   Global $YAxis = 500
   Global $FileCompareGUI = GUICreate("Path Comparison Results", 650, $YAxis, 212, 212)
   Local Const $sMessage = "Select the starting path"
   Local $SearchOption = "folders"
   Local $SearchParameter = 2 ;folders only
   if $Comp <> @ComputerName Then
      $RemotePath = "\\" & $ComputerNameValue & "\c$\"
   Else
      MsgBox($MB_SYSTEMMODAL, "Incomplete Request", "Please specify a remote machine above.")
      Return
   EndIf
   Local $sFileSelectFolderLocal = FileSelectFolder($sMessage, "C:\")
   Local $sFileSelectFolderRemote = FileSelectFolder($ComputerNameValue & ": " & $sMessage, $RemotePath)
   If @error OR $sFileSelectFolderLocal = "" OR $sFileSelectFolderRemote = "" Then
      MsgBox($MB_ICONERROR, "", "Required paths not selected.")
      GUIDelete($FileCompareGUI)
      Return
   EndIf
   GUISetState(@SW_SHOW, $FileCompareGUI)
   $LocalPath = $sFileSelectFolderLocal
   $RemotePath = $sFileSelectFolderRemote

   $LocalSide = GUICtrlCreateLabel("Local Computer", 6, 5, 80,20)
   $RemoteSide = GUICtrlCreateLabel("Remote Computer", 350, 5, 90,20)
   Global $idTreeView_1 = GUICtrlCreateTreeView(6, 20, 290, 290, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE)
   ;Local $hTreeView_1 = ControlGetHandle($FileCompareGUI, "", $idTreeView_1)
   Global $idTreeView_2 = GUICtrlCreateTreeView(350, 20, 290, 290, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE)
   ;Local $hTreeView_2 = ControlGetHandle($FileCompareGUI, "", $idTreeView_2)


   $idRootLocal = _GUICtrlTreeView_AddChild($idTreeView_1,"",$LocalPath)
   $idRootRemote = _GUICtrlTreeView_AddChild($idTreeView_2,"",$RemotePath)

   If GuiCtrlRead($LCheckboxFiles) = $GUI_CHECKED Then
      $SearchOption = "folders and files"
      $SearchParameter = 0
   EndIf
   Global $CompareProgressValue = GuiCtrlCreateLabel("", 350, 310, 50, 25)
   GUICtrlSetData($CompareProgressValue, "Scanning ")
   Global $RemoteTotal = _FileListToArrayRec($RemotePath,"*",$SearchParameter,1)
   GUICtrlDelete($CompareProgressValue)
   Global $CompareProgressValue = GuiCtrlCreateLabel("", 6, 310, 50, 25)
   GUICtrlSetData($CompareProgressValue, "Scanning ")
   Global $LocalTotal = _FileListToArrayRec($LocalPath,"*",$SearchParameter,1)
   GUICtrlDelete($CompareProgressValue)
   Global $CompareProgressValue = GuiCtrlCreateLabel("", 10, $YAxis - 55, 300, 25)
   GUICtrlSetData($CompareProgressValue, "")
   Global $TotalItems = UBound($LocalTotal,$UBOUND_ROWS) - 1
   Global $TotalDirItems = 0
   Global $FilesCompareProgress = GUICtrlCreateProgress(10, $YAxis - 25, 70, 15)
   GUICtrlSetColor(-1, 32250)
   GUICtrlSetData($CompareProgressValue, "Building Local Directory Tree...Please wait")
   _SearchFolder($LocalPath,$idRootLocal)
   _WinAPI_RedrawWindow ($FileCompareGUI)
   Global $TotalItems = UBound($RemoteTotal,$UBOUND_ROWS) - 1
   Global $TotalDirItemsLocal = $TotalDirItems
   Global $CompareResultsDataLocal = GuiCtrlCreateLabel("Found " & $TotalDirItemsLocal & " total " & $SearchOption, 6, $YAxis - 190, 200, 25)
   $TotalDirItems = 0
   GUICtrlSetData($CompareProgressValue, "Building Remote Directory Tree...Please wait")
   _SearchFolder($RemotePath,$idRootRemote)
   Global $TotalDirItemsRemote = $TotalDirItems
   _WinAPI_RedrawWindow ($FileCompareGUI)
   GUICtrlDelete($FilesCompareProgress)
   GUICtrlDelete($CompareProgressValue)
   Local $Button_GetItemValue = GUICtrlCreateButton("Selected Item Value", 6, $YAxis - 100)
   Local $Button_ResetTree = GUICtrlCreateButton("Reset Trees", 250, $YAxis - 100)
   GUICtrlSetState($Button_ResetTree, $GUI_DISABLE)
   Local $Button_GetCheckedItems = GUICtrlCreateButton("List Selected Items", 130, $YAxis - 100)
   Global $CompareResultsDataRemote = GuiCtrlCreateLabel("Found " & $TotalDirItemsRemote & " total " & $SearchOption, 350, $YAxis - 190, 300, 25)
   Global $idTreeView_1Backup = $idTreeView_1 ; backup of tree created for reset feature
   Global $idTreeView_2Backup = $idTreeView_2 ; same
   While 1
      $GUIMessages = GUIGetMsg()
      Select
         Case $GUIMessages = $GUI_EVENT_CLOSE
            GUIDelete($FileCompareGUI)
            ExitLoop
         Case $GUIMessages = $Button_GetItemValue
            Local $ValueText = _GUICtrlTreeView_GetSelection($idTreeView_1)
            MsgBox(0,"",_TreePath($idTreeView_1,$ValueText))
         Case $GUIMessages = $Button_GetCheckedItems
            Global $CheckedTreeItems[0]
            Global $List = ""
            Global $CompareProgressValue = GuiCtrlCreateLabel("Getting List...", 230, $YAxis - 90, 75, 25)
            _ListCheckedItemsInTree($idTreeView_1)
            $ListLeft = $List
            $List = ""
            _ListCheckedItemsInTree($idTreeView_2)
            $ListRight = $List
            GUICtrlDelete($CompareProgressValue)
            MsgBox(0,"","Left Side Checked: " & @CRLF & $ListLeft & @CRLF & @CRLF & "Right Side Checked: " & @CRLF & $ListRight)
            $List = ""
            $ListLeft = ""
            $ListRight = ""
            GUICtrlSetState($Button_ResetTree, $GUI_ENABLE)
            _ArraySort($CheckedTreeItems)
            _ArrayDisplay($CheckedTreeItems)
         Case $GUIMessages = $Button_ResetTree
            $idTreeView_1 = $idTreeView_1Backup
            $idTreeView_2 = $idTreeView_2Backup
            GUICtrlSetState($idTreeView_1)
            ;_ResetTree($idTreeView_1)
            ;_ResetTree($idTreeView_2)
         EndSelect
    WEnd
 EndFunc

Func _ResetTree($tree)
    For $i = 1 to UBound($CheckedTreeItems)-1
      _GUICtrlTreeView_SetChecked($tree, $CheckedTreeItems[$i], False)
   Next
EndFunc

Func _ListCheckedItemsInTree($treeview)
   $hItem = _GUICtrlTreeView_GetFirstItem($treeview)
   Do
      $status = _GUICtrlTreeView_GetChecked($treeview, $hItem)
      If $status = "True" Then
         _ArrayAdd($CheckedTreeItems, _GUICtrlTreeView_GetItemHandle($treeview, $hItem))
         $List =  $List & @CRLF & _TreePath($treeview, $hItem)
      EndIf
      $hItem = _GUICtrlTreeView_GetNext($treeview, $hItem)
   Until Not $hItem
EndFunc

Func _TreePath($treeview, $item)
   $txt = _GUICtrlTreeView_GetText($treeview, $item)
   _GUICtrlTreeView_SetChecked($treeview, $item)
   Do
      $parent = _GUICtrlTreeView_GetParentHandle($treeview, $item)
         if $parent <> 0 then
            $txt = _GUICtrlTreeView_GetText($treeview, $parent) & "\" & $txt
            _GUICtrlTreeView_SetChecked($treeview, $parent)
            $item = $parent
         EndIf
   Until $parent = 0
   Return $txt
EndFunc

Func _SearchFolder($folder,$parent)
   $folders = _FileListToArray($folder,"*",2)
   _FolderFunc($folders,$folder,$parent)
   If GuiCtrlRead($LCheckboxFiles) = $GUI_CHECKED Then
      $files = _FileListToArray($folder,"*",1)
      _FileFunc($files,$parent)
   EndIf
EndFunc

Func _FileFunc($files,$parent)
   For $i = 1 To UBound($files)-1
      $TotalDirItems = $TotalDirItems + 1
      GUICtrlSetData($FilesCompareProgress, ($TotalDirItems / $TotalItems * 100))
      _GUICtrlTreeView_AddChild($idTreeView_1,$parent,$files[$i])
   Next
EndFunc

Func _FolderFunc($folders,$parentdir,$parent)
   For $i = 1 To UBound($folders)-1
      $TotalDirItems = $TotalDirItems + 1
      GUICtrlSetData($FilesCompareProgress, ($TotalDirItems / $TotalItems * 100))
      $parentitem = _GUICtrlTreeView_AddChild($idTreeView_1,$parent,$folders[$i])
      _SearchFolder($parentdir & "\" & $folders[$i],$parentitem)
   Next
EndFunc

 

Share this post


Link to post
Share on other sites



I have a gui that I am using to do file compares on a remote and local machine. What I want to do is when the tree is created (which can take a while because of the directories chosen, I create a backup of the created tree. What I want to do is delete the tree and rebuild it using the backup that has nothing checked. I have tried to uncheck all items and it simply does not work, it unchecks some but not all. Here is a code snippet. This assumes the local and remote machines are passed to the function

Func _FileCompareResults($Comp)
   Global $YAxis = 500
   Global $FileCompareGUI = GUICreate("Path Comparison Results", 650, $YAxis, 212, 212)
   Local Const $sMessage = "Select the starting path"
   Local $SearchOption = "folders"
   Local $SearchParameter = 2 ;folders only
   if $Comp <> @ComputerName Then
      $RemotePath = "\\" & $ComputerNameValue & "\c$\"
   Else
      MsgBox($MB_SYSTEMMODAL, "Incomplete Request", "Please specify a remote machine above.")
      Return
   EndIf
   Local $sFileSelectFolderLocal = FileSelectFolder($sMessage, "C:\")
   Local $sFileSelectFolderRemote = FileSelectFolder($ComputerNameValue & ": " & $sMessage, $RemotePath)
   If @error OR $sFileSelectFolderLocal = "" OR $sFileSelectFolderRemote = "" Then
      MsgBox($MB_ICONERROR, "", "Required paths not selected.")
      GUIDelete($FileCompareGUI)
      Return
   EndIf
   GUISetState(@SW_SHOW, $FileCompareGUI)
   $LocalPath = $sFileSelectFolderLocal
   $RemotePath = $sFileSelectFolderRemote

   $LocalSide = GUICtrlCreateLabel("Local Computer", 6, 5, 80,20)
   $RemoteSide = GUICtrlCreateLabel("Remote Computer", 350, 5, 90,20)
   Global $idTreeView_1 = GUICtrlCreateTreeView(6, 20, 290, 290, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE)
   ;Local $hTreeView_1 = ControlGetHandle($FileCompareGUI, "", $idTreeView_1)
   Global $idTreeView_2 = GUICtrlCreateTreeView(350, 20, 290, 290, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE)
   ;Local $hTreeView_2 = ControlGetHandle($FileCompareGUI, "", $idTreeView_2)


   $idRootLocal = _GUICtrlTreeView_AddChild($idTreeView_1,"",$LocalPath)
   $idRootRemote = _GUICtrlTreeView_AddChild($idTreeView_2,"",$RemotePath)

   If GuiCtrlRead($LCheckboxFiles) = $GUI_CHECKED Then
      $SearchOption = "folders and files"
      $SearchParameter = 0
   EndIf
   Global $CompareProgressValue = GuiCtrlCreateLabel("", 350, 310, 50, 25)
   GUICtrlSetData($CompareProgressValue, "Scanning ")
   Global $RemoteTotal = _FileListToArrayRec($RemotePath,"*",$SearchParameter,1)
   GUICtrlDelete($CompareProgressValue)
   Global $CompareProgressValue = GuiCtrlCreateLabel("", 6, 310, 50, 25)
   GUICtrlSetData($CompareProgressValue, "Scanning ")
   Global $LocalTotal = _FileListToArrayRec($LocalPath,"*",$SearchParameter,1)
   GUICtrlDelete($CompareProgressValue)
   Global $CompareProgressValue = GuiCtrlCreateLabel("", 10, $YAxis - 55, 300, 25)
   GUICtrlSetData($CompareProgressValue, "")
   Global $TotalItems = UBound($LocalTotal,$UBOUND_ROWS) - 1
   Global $TotalDirItems = 0
   Global $FilesCompareProgress = GUICtrlCreateProgress(10, $YAxis - 25, 70, 15)
   GUICtrlSetColor(-1, 32250)
   GUICtrlSetData($CompareProgressValue, "Building Local Directory Tree...Please wait")
   _SearchFolder($LocalPath,$idRootLocal)
   _WinAPI_RedrawWindow ($FileCompareGUI)
   Global $TotalItems = UBound($RemoteTotal,$UBOUND_ROWS) - 1
   Global $TotalDirItemsLocal = $TotalDirItems
   Global $CompareResultsDataLocal = GuiCtrlCreateLabel("Found " & $TotalDirItemsLocal & " total " & $SearchOption, 6, $YAxis - 190, 200, 25)
   $TotalDirItems = 0
   GUICtrlSetData($CompareProgressValue, "Building Remote Directory Tree...Please wait")
   _SearchFolder($RemotePath,$idRootRemote)
   Global $TotalDirItemsRemote = $TotalDirItems
   _WinAPI_RedrawWindow ($FileCompareGUI)
   GUICtrlDelete($FilesCompareProgress)
   GUICtrlDelete($CompareProgressValue)
   Local $Button_GetItemValue = GUICtrlCreateButton("Selected Item Value", 6, $YAxis - 100)
   Local $Button_ResetTree = GUICtrlCreateButton("Reset Trees", 250, $YAxis - 100)
   GUICtrlSetState($Button_ResetTree, $GUI_DISABLE)
   Local $Button_GetCheckedItems = GUICtrlCreateButton("List Selected Items", 130, $YAxis - 100)
   Global $CompareResultsDataRemote = GuiCtrlCreateLabel("Found " & $TotalDirItemsRemote & " total " & $SearchOption, 350, $YAxis - 190, 300, 25)
   Global $idTreeView_1Backup = $idTreeView_1 ; backup of tree created for reset feature
   Global $idTreeView_2Backup = $idTreeView_2 ; same
   While 1
      $GUIMessages = GUIGetMsg()
      Select
         Case $GUIMessages = $GUI_EVENT_CLOSE
            GUIDelete($FileCompareGUI)
            ExitLoop
         Case $GUIMessages = $Button_GetItemValue
            Local $ValueText = _GUICtrlTreeView_GetSelection($idTreeView_1)
            MsgBox(0,"",_TreePath($idTreeView_1,$ValueText))
         Case $GUIMessages = $Button_GetCheckedItems
            Global $CheckedTreeItems[0]
            Global $List = ""
            Global $CompareProgressValue = GuiCtrlCreateLabel("Getting List...", 230, $YAxis - 90, 75, 25)
            _ListCheckedItemsInTree($idTreeView_1)
            $ListLeft = $List
            $List = ""
            _ListCheckedItemsInTree($idTreeView_2)
            $ListRight = $List
            GUICtrlDelete($CompareProgressValue)
            MsgBox(0,"","Left Side Checked: " & @CRLF & $ListLeft & @CRLF & @CRLF & "Right Side Checked: " & @CRLF & $ListRight)
            $List = ""
            $ListLeft = ""
            $ListRight = ""
            GUICtrlSetState($Button_ResetTree, $GUI_ENABLE)
            _ArraySort($CheckedTreeItems)
            _ArrayDisplay($CheckedTreeItems)
         Case $GUIMessages = $Button_ResetTree
            $idTreeView_1 = $idTreeView_1Backup
            $idTreeView_2 = $idTreeView_2Backup
            GUICtrlSetState($idTreeView_1)
            ;_ResetTree($idTreeView_1)
            ;_ResetTree($idTreeView_2)
         EndSelect
    WEnd
 EndFunc

Func _ResetTree($tree)
    For $i = 1 to UBound($CheckedTreeItems)-1
      _GUICtrlTreeView_SetChecked($tree, $CheckedTreeItems[$i], False)
   Next
EndFunc

Func _ListCheckedItemsInTree($treeview)
   $hItem = _GUICtrlTreeView_GetFirstItem($treeview)
   Do
      $status = _GUICtrlTreeView_GetChecked($treeview, $hItem)
      If $status = "True" Then
         _ArrayAdd($CheckedTreeItems, _GUICtrlTreeView_GetItemHandle($treeview, $hItem))
         $List =  $List & @CRLF & _TreePath($treeview, $hItem)
      EndIf
      $hItem = _GUICtrlTreeView_GetNext($treeview, $hItem)
   Until Not $hItem
EndFunc

Func _TreePath($treeview, $item)
   $txt = _GUICtrlTreeView_GetText($treeview, $item)
   _GUICtrlTreeView_SetChecked($treeview, $item)
   Do
      $parent = _GUICtrlTreeView_GetParentHandle($treeview, $item)
         if $parent <> 0 then
            $txt = _GUICtrlTreeView_GetText($treeview, $parent) & "\" & $txt
            _GUICtrlTreeView_SetChecked($treeview, $parent)
            $item = $parent
         EndIf
   Until $parent = 0
   Return $txt
EndFunc

Func _SearchFolder($folder,$parent)
   $folders = _FileListToArray($folder,"*",2)
   _FolderFunc($folders,$folder,$parent)
   If GuiCtrlRead($LCheckboxFiles) = $GUI_CHECKED Then
      $files = _FileListToArray($folder,"*",1)
      _FileFunc($files,$parent)
   EndIf
EndFunc

Func _FileFunc($files,$parent)
   For $i = 1 To UBound($files)-1
      $TotalDirItems = $TotalDirItems + 1
      GUICtrlSetData($FilesCompareProgress, ($TotalDirItems / $TotalItems * 100))
      _GUICtrlTreeView_AddChild($idTreeView_1,$parent,$files[$i])
   Next
EndFunc

Func _FolderFunc($folders,$parentdir,$parent)
   For $i = 1 To UBound($folders)-1
      $TotalDirItems = $TotalDirItems + 1
      GUICtrlSetData($FilesCompareProgress, ($TotalDirItems / $TotalItems * 100))
      $parentitem = _GUICtrlTreeView_AddChild($idTreeView_1,$parent,$folders[$i])
      _SearchFolder($parentdir & "\" & $folders[$i],$parentitem)
   Next
EndFunc

 

Share this post


Link to post
Share on other sites

Please stick to one thread.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

i think i accidentally posted twice, that was the issue

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