Sign in to follow this  
Followers 0
Odewallrus

Array from ini file help

8 posts in this topic

Can someone please give me some assistance on how to create an array containing the group name and host names in the ini file so that I can run functions against them. For example the ping below disables any check boxes that do not respond, but if I want to ping the computers after initial startup of the script and/or select the hosts check boxes that are “alive” I need to effectively name each host so that I can call from a func. I have a script working well with each computer individually named in the code but am trying to learn to do this dynamically from a configuration ini file for ease of maintenance. I have read the help files extensively and searched the forum, tried everything I can think of for days now but continue to hit brick walls and am getting frustrated as I am sure this is relatively easy.

For $g = 1 To $Groups[0]
    GUICtrlCreateButton($Groups[$g],-1,15,0,20)
        $Hosts = stringsplit(IniRead($Ini,$Groups[$g],'ActiveHosts',1),',',0)
        for $h = 1 to $Hosts[0]
            $ChkBox= GUICtrlCreateCheckbox($Hosts[$h],-1,0,80,15)
            if ping($Hosts[$h],300) = 0 then GUICtrlSetState($ChkBox,$GUI_DISABLE)
            Next
        Next
While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

pushFiles.ini:
[Groups]
ActiveGroups=Grp1,Grp2,Grp3,Grp4,Grp5
IncativeGroups=Grp6
[Grp1]
ActiveHosts=Host1,Host2,Host3
IncativeHosts=
[Grp2]
ActiveHosts= Host4,Host5,Host6
IncativeHosts=
[Grp3]
ActiveHosts= Host7,Host8,Host9
IncativeHosts=
[Grp4]
ActiveHosts= Host10,Host11,Host12
IncativeHosts=
[Grp5]
ActiveHosts= Host13,Host14,Host15
IncativeHosts=
[Grp6]
ActiveHosts= Host16,Host17,Host18
IncativeHosts= Host19,Host20,Host21

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Hi and Welcome to the forums!

So you're asking how to know how many sections there are? Correct?

Use IniReadSectionNames() for that. See helpfile.

No I know how many sections there are. I have parsed out the ini file with:

$Hosts = stringsplit(IniRead($Ini,$Groups[$g],'ActiveHosts',1),',',0)

And

$ChkBox= GUICtrlCreateCheckbox($Hosts[$h],-1,0,80,15)

I just have not been able to name them for later use in my code.

I hope that makes sense… I am learning as I go.

I can see how IniReadSectionNames() will be better, but I am not sure that alone will fix my issue.

Edited by Odewallrus

Share this post


Link to post
Share on other sites

Did you mean the issue is keeping the ControlIDs of the Checkbox controls for future reference?

You would generally keep them in an array. A 1D array is enough to just have all the ControlIDs, or a 2D array could include the name and/or other info in additional columns. A particular item would be found by for example _ArraySearch() for the host name in column 1, then read the ControlID from column 0 of the same row.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Did you mean the issue is keeping the ControlIDs of the Checkbox controls for future reference?

You would generally keep them in an array. A 1D array is enough to just have all the ControlIDs, or a 2D array could include the name and/or other info in additional columns. A particular item would be found by for example _ArraySearch() for the host name in column 1, then read the ControlID from column 0 of the same row.

;)

Yes that is correct, however I have been unable to successfully create the array from the ini as expected. Can you give me an example of how to create a 2d array from the ini with 1st col containing “host name” second col containing “Control ID” of the check box and assign the control ID to the check boxes as they are created. Or just assign the control ID of the check box the same as the host name. I know this is basic, but I have read everything I could find so far and have searched code for something similar to reference without luck.

Share this post


Link to post
Share on other sites

Demo builds a 2D array of info for the checkboxes, then uses it to toggle certain items:

#include <GuiConstantsEx.au3>
#include <Array.au3> ; Only for _ArrayDisplay()

Global $sINI, $aGroups, $aActiveGroups, $sGroupName, $aGroupSection, $aActiveHosts
Global $aHosts[1][3] = [[0, "", ""]]
Global $iGuiH, $hGUI, $idButton

$sINI = @ScriptDir & "\Test1.ini"
$aGroups = IniReadSection($sINI, "Groups")
If @error Then
    MsgBox(16, "Error", "Failed to read 'Groups' section.")
    Exit
EndIf

If ($aGroups[0][0] >= 1) And ($aGroups[1][0] = "ActiveGroups") Then
    $aActiveGroups = StringSplit($aGroups[1][1], ",")
    If ($aActiveGroups[0] = 1) And (StringStripWS($aActiveGroups[1], 8) = "") Then Dim $aActiveGroups[1] = [0]
Else
    MsgBox(16, "Error", "Missing or invalid Groups keys.")
    Exit
EndIf

For $g = 1 To $aActiveGroups[0]
    $sGroupName = $aActiveGroups[$g]

    $aGroupSection = IniReadSection($sINI, $sGroupName)
    If @error Then
        MsgBox(16, "Error", "Failed to read groups section: '" & $sGroupName & "'.")
        ContinueLoop
    EndIf

    If ($aGroupSection[0][0] >= 1) And ($aGroupSection[1][0] = "ActiveHosts") Then
        $aActiveHosts = StringSplit($aGroupSection[1][1], ",")
        If ($aActiveHosts[0] = 1) And (StringStripWS($aActiveHosts[1], 8) = "") Then Dim $aActiveHosts[1] = [0]

        For $h = 1 To $aActiveHosts[0]
            _AddActiveHost($sGroupName, $aActiveHosts[$h])
        Next
    Else
        MsgBox(16, "Error", "Missing or invalid keys in group: '" & $sGroupName & "'.")
        ContinueLoop
    EndIf
Next

$iGuiH = ($aHosts[0][0] * 30) + 50
$hGUI = GUICreate("Test", 400, $iGuiH)
For $n = 1 To $aHosts[0][0]
    $aHosts[$n][2] = GUICtrlCreateCheckbox("Group: " & $aHosts[$n][0] & "  --  Host: " & $aHosts[$n][1], 10, 10 + (($n - 1) * 30), 380, 20)
Next
$idButton = GUICtrlCreateButton("Toggle Grp3", 150, $iGuiH - 40, 100, 30)
GUISetState()

_ArrayDisplay($aHosts, "Debug: $aHosts")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idButton
            ; Toggle the checkboxes on all Grp3 hosts
            For $n = 1 To $aHosts[0][0]
                If $aHosts[$n][0] = "Grp3" Then
                    If ControlCommand($hGUI, "", $aHosts[$n][2], "IsChecked") Then
                        ControlCommand($hGUI, "", $aHosts[$n][2], "Uncheck")
                    Else
                        ControlCommand($hGUI, "", $aHosts[$n][2], "Check")
                    EndIf
                EndIf
            Next
    EndSwitch
WEnd

Func _AddActiveHost($sGrp, $sHost)
    ReDim $aHosts[UBound($aHosts) + 1][UBound($aHosts, 2)] ; Resize the array
    $aHosts[0][0] = UBound($aHosts) - 1 ; Save count in [0][0]
    $aHosts[$aHosts[0][0]][0] = $sGrp ; Put group in [n][0]
    $aHosts[$aHosts[0][0]][1] = $sHost ; Put host in [n][1]
EndFunc   ;==>_AddActiveHost

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Demo builds a 2D array of info for the checkboxes, then uses it to toggle certain items:

#include <GuiConstantsEx.au3>
#include <Array.au3> ; Only for _ArrayDisplay()

Global $sINI, $aGroups, $aActiveGroups, $sGroupName, $aGroupSection, $aActiveHosts
Global $aHosts[1][3] = [[0, "", ""]]
Global $iGuiH, $hGUI, $idButton

$sINI = @ScriptDir & "\Test1.ini"
$aGroups = IniReadSection($sINI, "Groups")
If @error Then
    MsgBox(16, "Error", "Failed to read 'Groups' section.")
    Exit
EndIf

If ($aGroups[0][0] >= 1) And ($aGroups[1][0] = "ActiveGroups") Then
    $aActiveGroups = StringSplit($aGroups[1][1], ",")
    If ($aActiveGroups[0] = 1) And (StringStripWS($aActiveGroups[1], 8) = "") Then Dim $aActiveGroups[1] = [0]
Else
    MsgBox(16, "Error", "Missing or invalid Groups keys.")
    Exit
EndIf

For $g = 1 To $aActiveGroups[0]
    $sGroupName = $aActiveGroups[$g]

    $aGroupSection = IniReadSection($sINI, $sGroupName)
    If @error Then
        MsgBox(16, "Error", "Failed to read groups section: '" & $sGroupName & "'.")
        ContinueLoop
    EndIf

    If ($aGroupSection[0][0] >= 1) And ($aGroupSection[1][0] = "ActiveHosts") Then
        $aActiveHosts = StringSplit($aGroupSection[1][1], ",")
        If ($aActiveHosts[0] = 1) And (StringStripWS($aActiveHosts[1], 8) = "") Then Dim $aActiveHosts[1] = [0]

        For $h = 1 To $aActiveHosts[0]
            _AddActiveHost($sGroupName, $aActiveHosts[$h])
        Next
    Else
        MsgBox(16, "Error", "Missing or invalid keys in group: '" & $sGroupName & "'.")
        ContinueLoop
    EndIf
Next

$iGuiH = ($aHosts[0][0] * 30) + 50
$hGUI = GUICreate("Test", 400, $iGuiH)
For $n = 1 To $aHosts[0][0]
    $aHosts[$n][2] = GUICtrlCreateCheckbox("Group: " & $aHosts[$n][0] & "  --  Host: " & $aHosts[$n][1], 10, 10 + (($n - 1) * 30), 380, 20)
Next
$idButton = GUICtrlCreateButton("Toggle Grp3", 150, $iGuiH - 40, 100, 30)
GUISetState()

_ArrayDisplay($aHosts, "Debug: $aHosts")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idButton
            ; Toggle the checkboxes on all Grp3 hosts
            For $n = 1 To $aHosts[0][0]
                If $aHosts[$n][0] = "Grp3" Then
                    If ControlCommand($hGUI, "", $aHosts[$n][2], "IsChecked") Then
                        ControlCommand($hGUI, "", $aHosts[$n][2], "Uncheck")
                    Else
                        ControlCommand($hGUI, "", $aHosts[$n][2], "Check")
                    EndIf
                EndIf
            Next
    EndSwitch
WEnd

Func _AddActiveHost($sGrp, $sHost)
    ReDim $aHosts[UBound($aHosts) + 1][UBound($aHosts, 2)] ; Resize the array
    $aHosts[0][0] = UBound($aHosts) - 1 ; Save count in [0][0]
    $aHosts[$aHosts[0][0]][0] = $sGrp ; Put group in [n][0]
    $aHosts[$aHosts[0][0]][1] = $sHost ; Put host in [n][1]
EndFunc   ;==>_AddActiveHost

;)

WOW… Thank you so much for the quick response. I have not digested all of it yet, but this was exactly what I was looking for plus some.

You are the best!

Share this post


Link to post
Share on other sites

SaltyD,

Thanks for the kick start… if you are interested. Here is what I have so far…

I am still working on the progress bars and having a bit of trouble with how to get a return from _LargeFileCopy $sFunction.

PushFiles.ini

[Groups]
ActiveGroups=Group1,Group2,Group3,Group4,Group5
InactiveGroups=Group6
PingTimeout=300

[Group1]
ActiveHosts=Computer1,Computer2,Computer,Computer3,Computer4
InactiveHosts=
Share=C$

[Group2]
ActiveHosts=Computer5,Computer6,Computer7,Computer8,Computer9
InactiveHosts=
Share=C$

[Group3]
ActiveHosts=Computer10,Computer11,Computer12,Computer13,Computer14
InactiveHosts=
Share=C$

[Group4]
ActiveHosts=Computer15,Computer16,Computer17,Computer18
InactiveHosts=
Share=C$

[Group5]
ActiveHosts=Computer19,Computer20,Computer21,Computer22
IncativeHosts=
Share=C$

[Group6]
ActiveHosts=Computer23,Computer24,Computer25
InactiveHosts=
Share=C$

PushFiles.au3

#include <Array.au3> ; Only for _ArrayDisplay()
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#Include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <GUIScrollbars_Ex.au3>
#include <EditConstants.au3>
#include <_LargeFileCopy.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <_FileListToArray_Recursive.au3>
#Include <File.au3>
#Include <Date.au3>



Global $aHosts[1][5] = [[0, "", "", "", ""]]
Global $FilesArray[1][3]
Global $Answer,$SrcDir,$DestDir,$TotSize,$TotFiles,$TotFolders,$FileCalc
$Logfile = @ScriptDir & '\' & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @min & "-" & @SEC & "_" & 'PushFiles.log'


;~ Create Gui
$sTitle = "Push Files"
$sINI = @ScriptDir & "\PushFiles.ini"
$Gui = GUICreate($sTitle, 500, 550, -1, -1)




Opt("GUICoordMode", 2)
$GrpCord = GUISetCoord(200,10)
$radio1 = GUICtrlCreateRadio("Dir Copy", -1, -1, 75, 20)
GUICtrlSetTip(-1, 'Copies the current directory and all sub directories.' & @CR & 'Will create the entire directory structure on the host.')
$radio2 = GUICtrlCreateRadio("File Copy", 0, -1, 75, 20)
GUICtrlSetTip(-1, 'Copies ONLY the current directory and files.' & @CR & 'No sub directories will be created on the host.')
GUICtrlSetState($radio2, $GUI_CHECKED)
;~ Buttons
$bRePing = GUICtrlCreateButton("Re-Ping Hosts",45, 1, 100, 20, $BS_VCENTER + $BS_CENTER)
GUICtrlSetTip(-1, "Re-ping hosts for changes in their status")
$ModifyIni = GUICtrlCreateButton("Open Config File", -1, 1, 100, 20, $BS_VCENTER + $BS_CENTER)
GUICtrlSetTip(-1, "Modify the configuration file")
GUICtrlCreateLabel ('Source Folder:', -340, 1, 100)
$input1 = GUICtrlCreateEdit($SrcDir, -1, 1, 320, 20, $ES_READONLY)
$SelectSource = GUICtrlCreateButton("...",0, -1, 20, 20, $BS_VCENTER + $BS_CENTER)
GUICtrlSetTip(-1, "Select directory containing files to push")
GUICtrlCreateLabel ('Destination Folder:', -340, 15, 100)
GUICtrlCreateLabel ('\\<Computer>\<Share>\', -1, 1,120)
$input2 = GUICtrlCreateEdit($DestDir, 0, -1, 200, 20, $ES_READONLY)
$SelectDestination = GUICtrlCreateButton("...", 0, -1, 20, 20, $BS_VCENTER + $BS_CENTER)
GUICtrlSetTip(-1, "Select directory containing files to push")
GUICtrlCreateLabel ('Log:', -340, 15, 100)
$GuiLog = GUICtrlCreateList("",-1,1,340,175)
$Lbl1 = GUICtrlCreateLabel('Size(MegaBytes): ' & $TotSize, -340, 15, 240)
$CopyFiles = GUICtrlCreateButton("Copy Files",0,-1, 100, 20, $BS_VCENTER + $BS_CENTER)
GUICtrlSetTip(-1, "Copy files to selected computers")
GUICtrlSetState($CopyFiles, $GUI_DISABLE)

$Lbl2 = GUICtrlCreateLabel('          Total Files: ' & $TotFiles, -340, 0, 200)
$Lbl3 = GUICtrlCreateLabel('        Sub Folders: ' & $TotFolders, -1, 0, 300)
$lbl_Status = GUICtrlCreateLabel('',-1, 0, 400)
$PbFile = GUICtrlCreateProgress(-1,1,300,10,$PBS_SMOOTH)
$PrFile = GUICtrlCreateLabel("0 %", 0, -1, 35, 16, $SS_RIGHT)
$PbHost = GUICtrlCreateProgress(-335,1,300,10,$PBS_SMOOTH)
$PrHost = GUICtrlCreateLabel("0 %", 0, -1, 35, 16, $SS_RIGHT)
$PbOverall = GUICtrlCreateProgress(-335,0,300,10,$PBS_SMOOTH)
$PrOverall = GUICtrlCreateLabel("0 %", 0, -1, 35, 16, $SS_RIGHT)

GUISetState()

;~ Create Child gui
$cGUI = GUICreate("Child GUI", 130,525,10,10, $WS_CHILD, $WS_EX_CLIENTEDGE, $Gui)
GUICtrlSetResizing($cGUI, $GUI_DOCKALL)
Opt("GUICoordMode", 2)
$GrpCord = GUISetCoord(10,10)

$bToggleAll = GUICtrlCreateButton("Toggle All", -1, 1, 100, 20)

GUISetState()

FileOpen($Logfile,1)
FileWrite($Logfile, _Now() & " - Session started" & @CRLF)

;~ Read ini
$aGroups = IniReadSection($sINI, "Groups")
If @error Then
    MsgBox(16, "Error", "Failed to read 'Groups' section.")
    FileWrite($Logfile, _Now() & " - Failed to read 'Groups' section" & @CRLF)
    Exit
EndIf

$PingTimeout = IniRead($sINI,'Groups','PingTimeout',300)
FileWrite($Logfile, _Now() & " - Ping Timeout set to '" & $PingTimeout & "'"& @CRLF)




If ($aGroups[0][0] >= 1) And ($aGroups[1][0] = "ActiveGroups") Then
    $aActiveGroups = StringSplit($aGroups[1][1], ",")
    If ($aActiveGroups[0] = 1) And (StringStripWS($aActiveGroups[1], 8) = "") Then Dim $aActiveGroups[1] = [0]
Else
    MsgBox(16, "Error", "Missing or invalid Groups keys.")
    FileWrite($Logfile, _Now() & " - Missing or invalid Groups keys" & @CRLF)
    Exit
EndIf

For $g = 1 To $aActiveGroups[0]
    $sGroupName = $aActiveGroups[$g]

    $aGroupSection = IniReadSection($sINI, $sGroupName)
    If @error Then
        MsgBox(16, "Error", "Failed to read groups section: '" & $sGroupName & "'.")
        FileWrite($Logfile, _Now() & " - Failed to read groups section: '" & $sGroupName & "'" & @CRLF)
        ContinueLoop
    EndIf

    If ($aGroupSection[0][0] >= 1) And ($aGroupSection[1][0] = "ActiveHosts") Then
        $aActiveHosts = StringSplit($aGroupSection[1][1], ",")
        If ($aActiveHosts[0] = 1) And (StringStripWS($aActiveHosts[1], 8) = "") Then Dim $aActiveHosts[1] = [0]


        For $h = 1 To $aActiveHosts[0]
            _AddActiveHost($sGroupName, $aActiveHosts[$h])
        Next
    Else
        MsgBox(16, "Error", "Missing or invalid keys in group: '" & $sGroupName & "'.")
        FileWrite($Logfile, _Now() & " - Missing or invalid keys in group: '" & $sGroupName & "'." & @CRLF)
        ContinueLoop
    EndIf
Next

Dim $GrpButton[($aActiveGroups[0] + 1)]
$Btn_Start = GUICtrlCreateDummy()

SplashTextOn ("Available Hosts", "Checking available hosts. Please be patient...", 400, 80,-1,-1, 1,"",20)

For $g = 1 To $aActiveGroups[0]
    $GrpButton[$g] = GUICtrlCreateButton($aActiveGroups[$g],-1, 1, 100, 20)
    FileWrite($Logfile, _Now() & " - Group created: '" & $aActiveGroups[$g] & "'" & @CRLF)

        For $n = 1 To $aHosts[0][0]

            if $aActiveGroups[$g] = $aHosts[$n][0] then $aHosts[$n][2] = GUICtrlCreateCheckbox($aHosts[$n][1],-1,0,100,15)
            if $aActiveGroups[$g] = $aHosts[$n][0] then FileWrite($Logfile, _Now() & " - Host created: '" & $aHosts[$n][1] & "'")
            if $aActiveGroups[$g] = $aHosts[$n][0] then $aHosts[$n][3] = IniRead($sINI, $aActiveGroups[$g], 'Share','C$')
            if $aActiveGroups[$g] = $aHosts[$n][0] then $aHosts[$n][4] = ping ($aHosts[$n][1],$PingTimeout)
            if not $aHosts[$n][4] = 1 then GUICtrlSetState ($aHosts[$n][2],$GUI_DISABLE)
            if $aHosts[$n][4] = 1 then GUICtrlSetState ($aHosts[$n][2],$GUI_ENABLE)
            if $aActiveGroups[$g] = $aHosts[$n][0] and not $aHosts[$n][4] = 1 then
                FileWrite($Logfile, " -DISABLED" & @CRLF)
            Elseif $aActiveGroups[$g] = $aHosts[$n][0] Then
                FileWrite($Logfile, @CRLF)
            EndIf
        Next

Next

$Btn_End = GUICtrlCreateDummy()
_GUIScrollbars_Generate($cGUI, 0, ($n * 15) + ($g * 21)) ;number of checkboxes in the list * 15 pixels (height of the checkbox + spacing ???)
SplashOff()

While 1
    $Msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            FileWrite($Logfile, _Now() & ' - Session ended normally' & @CRLF)
            FileClose($Logfile)
            Exit
        Case $radio1
            $RecursiveSearch = True
            if not $SrcDir = "" then
                SplashTextOn ("Selecting Files", "Calculating selected files and folders. Please be patient...", 400, 80,-1,-1, 1,"",20)
                FileWrite($Logfile, _Now() & " - Set to 'Dir Copy'" & @CRLF)
                $DirArray = _FileListToArray_Recursive($SrcDir, "", "*", "", 2, 2, $recursiveSearch)
                $FilesArray = _FileListToArray_Recursive($SrcDir, "", "*", "", 1, 2, $recursiveSearch)
                If ControlCommand($GUI, "", $radio1, "IsChecked") Then $size = DirGetSize($SrcDir,1)
                If ControlCommand($GUI, "", $radio2, "IsChecked") Then $size = DirGetSize($SrcDir,1+2)
                    If IsArray($size) Then
                        $TotSize = Round($size[0]/ 1024 / 1024)
                        $TotFiles = $size[1]
                        $TotFolders = $size[2] + 1
                        GUICtrlSetData ($Lbl1, 'Size(MegaBytes): ' & $TotSize,'')
                        GUICtrlSetData ($Lbl2, '          Total Files: ' & $TotFiles,'')
                        If ControlCommand($GUI, "", $radio1, "IsChecked") Then GUICtrlSetData ($Lbl3, '        Sub Folders: ' & $TotFolders,'')
                        If ControlCommand($GUI, "", $radio2, "IsChecked") Then GUICtrlSetData ($Lbl3, '        Sub Folders: Subfolders will not be coppied!','')
                    EndIf
                    EndIf
                SplashOff()
        Case $radio2
            $RecursiveSearch = False
            if not $SrcDir = "" then
                SplashTextOn ("Selecting Files", "Calculating selected files and folders. Please be patient...", 400, 80,-1,-1, 1,"",20)
                FileWrite($Logfile, _Now() & " - Set to 'File Copy'" & @CRLF)
                $DirArray = _FileListToArray_Recursive($SrcDir, "", "*", "", 2, 2, $recursiveSearch)
                $FilesArray = _FileListToArray_Recursive($SrcDir, "", "*", "", 1, 2, $recursiveSearch)
                If ControlCommand($GUI, "", $radio1, "IsChecked") Then $size = DirGetSize($SrcDir,1)
                If ControlCommand($GUI, "", $radio2, "IsChecked") Then $size = DirGetSize($SrcDir,1+2)
                    If IsArray($size) Then
                        $TotSize = Round($size[0]/ 1024 / 1024)
                        $TotFiles = $size[1]
                        $TotFolders = $size[2] + 1
                        GUICtrlSetData ($Lbl1, 'Size(MegaBytes): ' & $TotSize,'')
                        GUICtrlSetData ($Lbl2, '          Total Files: ' & $TotFiles,'')
                        If ControlCommand($GUI, "", $radio1, "IsChecked") Then GUICtrlSetData ($Lbl3, '        Sub Folders: ' & $TotFolders,'')
                        If ControlCommand($GUI, "", $radio2, "IsChecked") Then GUICtrlSetData ($Lbl3, '        Sub Folders: Subfolders will not be coppied!','')
                    EndIf
                    EndIf
                SplashOff()
        Case $SelectSource
            _SelectSource()
            If ControlCommand($GUI, "", $radio1, "IsChecked") Then $RecursiveSearch = True
            If ControlCommand($GUI, "", $radio2, "IsChecked") Then $RecursiveSearch = False
;~          _FileListToArray_Recursive([$sPath, [$sExcludeFolderList, $sIncludeList, $sExcludeList, $iReturnType, $iReturnFormet, $bRecursive]
            $DirArray = _FileListToArray_Recursive($SrcDir, "", "*", "", 2, 2, $recursiveSearch)
            $FilesArray = _FileListToArray_Recursive($SrcDir, "", "*", "", 1, 2, $recursiveSearch)

            If Not $SrcDir = "" and not $DestDir = "" then GUICtrlSetState($CopyFiles, $GUI_ENABLE)

            FileWrite($Logfile, _Now() & " - Source directory: '" & $SrcDir & "'" & @CRLF)

            If $TotFiles > 0 Then
                _ArrayAdd_Column($FilesArray)
            Else
                MsgBox(0,'Error','Source directory contains no files!')
                FileWrite($Logfile, _Now() & " - Source directory contains no files!" & @CRLF)
                GUICtrlSetData($input1,"")
            EndIf


            $TotalToDownload = 0
            For $i = 1 To UBound($FileCalc)-1
                ; Get the File size
                $FileSize = FileGetSize($FileCalc[$i][0])
                ; Current File Size
                $FileCalc[$i][1] = $FileSize
                ; Cumulative Total
                $FileCalc[$i][2] = $TotalToDownload
                ; Add the current file size to the total
                $TotalToDownload += $FileSize
            Next


        Case $SelectDestination
            _SelectDestination()
            If Not $SrcDir = "" and not $DestDir = "" then GUICtrlSetState($CopyFiles, $GUI_ENABLE)
            FileWrite($Logfile, _Now() & " - Destination directory: '" & $DestDir & "'" & @CRLF)

        Case $CopyFiles
            FileWrite($Logfile, _Now() & " - 'Copy Files' button selected" & @CRLF)
            ; Disable the download button
            GUICtrlSetState($CopyFiles, $GUI_DISABLE)

            _ArrayAdd_Column($FilesArray)

            GUICtrlSetData($GuiLog, "")

            $TotalToDownload = 0
            For $i = 1 To UBound($FileCalc)-1
                ; Get the File size
                $FileSize = FileGetSize($FileCalc[$i][0])
                ; Current File Size
                $FileCalc[$i][1] = $FileSize
                ; Cumulative Total
                $FileCalc[$i][2] = $TotalToDownload
                ; Add the current file size to the total
                $TotalToDownload += $FileSize
            Next



            if $SrcDir = "" or $DestDir = "" then
                MsgBox(0,'Error','You must select a source and destination!')
                FileWrite($Logfile, _Now() & " - You must select a source and destination!" & @CRLF)
            else
                if MsgBox(1+32+256,'Push Files','From:' & @CRLF & $SrcDir & @CRLF & 'To:' & @CRLF & '\\<Computer>\<Share>\' & $DestDir) = 1 then
                    FileWrite($Logfile, _Now() & " - Push files From: '" & $SrcDir & "' To: '" & $DestDir & "'" & @CRLF)
                for $n = 1 to $aHosts[0][0]
                    If ControlCommand($cGUI, "", $aHosts[$n][2], "IsEnabled") Then
                    If ControlCommand($cGUI, "", $aHosts[$n][2], "IsChecked") Then

;~                      _ArrayDisplay($DirArray)
                        If IsArray($DirArray) Then
                            For $d = 1 to $DirArray[0]
;~                              MsgBox (0,'test','\\' & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & StringReplace($DirArray[$d],$SrcDir,$DestDir,1,2))
                                If ControlCommand($GUI, "", $radio1, "IsChecked") Then DirCreate ('\\' & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & StringReplace($DirArray[$d],$SrcDir,$DestDir,1,2))
                                If ControlCommand($GUI, "", $radio1, "IsChecked") Then FileWrite($Logfile, _Now() & " - Create Directory : '\\" & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & StringReplace($DirArray[$d],$SrcDir,$DestDir,1,2) & "'" & @CRLF)
                                If ControlCommand($GUI, "", $radio2, "IsChecked") And  Not FileExists ('\\' & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & $DestDir) Then DirCreate ('\\' & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & $DestDir)
                                If ControlCommand($GUI, "", $radio2, "IsChecked") And  Not FileExists ('\\' & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & $DestDir) Then FileWrite($Logfile, _Now() & '\\' & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & $DestDir & @CRLF)
                            Next
                        Else
                        EndIf

                        For $f = 1 to $FilesArray[0]
;~                          _LargeFileCopy($sSrc, $sDest[, $fOverwrite = False[, $fFlush = False[, $fVerify = False[, $sFunction = ""[, $vUserVar = Default[, $iAlg = $CALG_MD5]]]]]])
;~                          msgbox(0,'test','\\' & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & StringReplace($FilesArray[$f],$SrcDir,$DestDir,1,2))
                            $Answer = _LargeFileCopy($FilesArray[$f], '\\' & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & StringReplace($FilesArray[$f],$SrcDir,$DestDir,1,2), True, False, True, "1", Default, $CALG_MD5)
                            $DirCopyError = @error
                            if $Answer = 1 then
                                GUICtrlSetData($GuiLog, 'Sucess: \\' & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & StringReplace($FilesArray[$f],$SrcDir,$DestDir,1,2))
                                FileWrite($Logfile, _Now() & " - Sucess: \\" & $aHosts[$n][1] & '\' & $aHosts[$n][3] & '\' & StringReplace($FilesArray[$f],$SrcDir,$DestDir,1,2) & @CRLF)
                            Else
                            if $Answer = 0 then
                                GUICtrlSetData($GuiLog, 'Failed: ' & $aHosts[$n][1] & ' ' & $FilesArray[$f] & ' ' & $DirCopyError)
                                FileWrite($Logfile, _Now() & " - Failed: " & $aHosts[$n][1] & ' ' & $FilesArray[$f] & ' ' & $DirCopyError & @CRLF)

                            EndIf
                            EndIf
                        Next

                    Else
                    EndIf
                    ControlCommand($cGUI, "", $aHosts[$n][2], "Uncheck")

                EndIf
                Next

            ; Enable the download button
            GUICtrlSetState($CopyFiles, $GUI_DISABLE)
            EndIf
            EndIf
        Case $bRePing
            FileWrite($Logfile, _Now() & " - Re-Ping Hosts" & @CRLF)
;~          _ArrayDisplay($aHosts, "Debug: $aHosts")
;~          _ArrayDisplay($FileCalc)
;~          _ArrayDisplay($DirArray)
;~          _ArrayDisplay($FilesArray)
            _RePingHosts()
        Case $bToggleAll
            For $n = 1 To $aHosts[0][0]
                If $aHosts[$n][0] = True Then
                    If ControlCommand($cGUI, "", $aHosts[$n][2], "IsEnabled") Then
                    If ControlCommand($cGUI, "", $aHosts[$n][2], "IsChecked") Then
                        ControlCommand($cGUI, "", $aHosts[$n][2], "Uncheck")
                    Else
                        ControlCommand($cGUI, "", $aHosts[$n][2], "Check")
                    EndIf
                    EndIf
                EndIf
            Next
        Case $Btn_Start To $Btn_End
            For $n = 1 To $aHosts[0][0]
                    If $aHosts[$n][0] = GUICtrlRead($Msg) Then
                    If ControlCommand($cGUI, "", $aHosts[$n][2], "IsEnabled") Then
                    If ControlCommand($cGUI, "", $aHosts[$n][2], "IsChecked") Then
                        ControlCommand($cGUI, "", $aHosts[$n][2], "Uncheck")
                    Else
                        ControlCommand($cGUI, "", $aHosts[$n][2], "Check")
                    EndIf
                    EndIf
                EndIf
            Next
        Case $ModifyIni
                $Answer = MsgBox(1, 'Information','You must restart the application for configuration modifications to take effect')
                if $Answer = 1 then
                    Run("notepad.exe " & $sINI)
                Else
            EndIf
    EndSwitch
WEnd








Func _ArrayAdd_Column($Array)
    Global $FileCalc[UBound($Array)][UBound($Array, 0) + 2]
    For $i = 0 To UBound($Array) - 1
        For $j = 0 To UBound($Array, 0) - 1
            If UBound($Array, 0) = 1 Then $FileCalc[$i][0] = $Array[$i]
            If UBound($Array, 0) > 1 Then $FileCalc[$i][$j] = $Array[$i][$j]
        Next
    Next

;~     Return $FileCalc

EndFunc

Func _AddActiveHost($sGrp, $sHost)
    ReDim $aHosts[UBound($aHosts) + 1][UBound($aHosts, 2)] ; Resize the array
    $aHosts[0][0] = UBound($aHosts) - 1 ; Save count in [0][0]
    $aHosts[$aHosts[0][0]][0] = $sGrp ; Put group in [n][0]
    $aHosts[$aHosts[0][0]][1] = $sHost ; Put host in [n][1]
EndFunc   ;==>_AddActiveHost

Func _RePingHosts()
    SplashTextOn ("Available Hosts", "Checking available hosts. Please be patient...", 400, 80,-1,-1, 1,"",20)
    For $g = 1 To $aActiveGroups[0]
        For $n = 1 To $aHosts[0][0]
            if $aActiveGroups[$g] = $aHosts[$n][0] then $aHosts[$n][4] = ping ($aHosts[$n][1],$PingTimeout)
            if not $aHosts[$n][4] = 1 then
            GUICtrlSetState ($aHosts[$n][2],$GUI_DISABLE)
            if $aActiveGroups[$g] = $aHosts[$n][0] then FileWrite($Logfile, _Now() & " - '" & $aHosts[$n][1] & "' -DISABLED" & @CRLF)
            EndIf
            if $aHosts[$n][4] = 1 then
            GUICtrlSetState ($aHosts[$n][2],$GUI_ENABLE)
            if $aActiveGroups[$g] = $aHosts[$n][0] then FileWrite($Logfile, _Now() & " - '" & $aHosts[$n][1] & "'" & @CRLF)
            EndIf
    Next

    Next
    SplashOff()
EndFunc

Func _SelectSource()
        $SrcDir = FileSelectFolder("Select the source directory", "",2)
        GUICtrlSetData($input1,$SrcDir,'')
        if @error == 1 Then
        MsgBox(0, "Error", "Unable to read the source directory.")
        Exit
    EndIf
    if not $SrcDir = "" then
    SplashTextOn ("Selecting Files", "Calculating selected files and folders. Please be patient...", 400, 80,-1,-1, 1,"",20)
    If ControlCommand($GUI, "", $radio1, "IsChecked") Then $size = DirGetSize($SrcDir,1)
    If ControlCommand($GUI, "", $radio2, "IsChecked") Then $size = DirGetSize($SrcDir,1+2)
        If IsArray($size) Then
            $TotSize = Round($size[0]/ 1024 / 1024)
            $TotFiles = $size[1]
            $TotFolders = $size[2] + 1
            GUICtrlSetData ($Lbl1, 'Size(MegaBytes): ' & $TotSize,'')
            GUICtrlSetData ($Lbl2, '          Total Files: ' & $TotFiles,'')
            If ControlCommand($GUI, "", $radio1, "IsChecked") Then GUICtrlSetData ($Lbl3, '        Sub Folders: ' & $TotFolders,'')
            If ControlCommand($GUI, "", $radio2, "IsChecked") Then GUICtrlSetData ($Lbl3, '        Sub Folders: Subfolders will not be coppied!','')
        EndIf
        EndIf
    SplashOff()
EndFunc

Func _SelectDestination()
        $DestDir = StringTrimLeft(FileSelectFolder("Select the Destination directory", "",1+2),3)
        GUICtrlSetData($input2,$DestDir,'')
        If @error == 1 Then
        MsgBox(0, "Error", "Unable to read the source directory.")
        Exit
    EndIf
EndFunc

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