Sign in to follow this  
Followers 0
wanderson

Dynamic array for auto install programs

4 posts in this topic

I wonder if anyone has any idea how to identify the checkbox to create a dynamic script to run several applications with the same silent switch. Why can not any idea how to do this apart from that script I tried to do.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <Array.au3>

AutoItSetOption ("TrayIconDebug", 1)
$folderToList = @ScriptDir
$vSpacer = 90
$hSpacer = 16
$tasks = ''
$noFilesFound = ''
Global $chkList[100], $XS_n
Global $hGuiCfg = @ScriptDir & "\GuiDefaults.cfg"

$appList = _FileListToArray($folderToList, "*", 2)
If @error = 1 Then
    Exit
EndIf

Global $chkList[Ubound($chkList)] ; Declare an array to hold the checkbox ControlIDs

If $appList = '' Then
    $noFilesFound = 'Nenhum arquivo ou pasta encontrado.'
EndIf

;~ _ArrayDisplay($appList)
$autoAppLister = GUICreate("Instaladores",593, 412, 192, 124)
$Fundo = GUICtrlCreatePic("install_bg.bmp", 0, 0, 592, 412, $WS_GROUP)
$appListGrp = GUICtrlCreateGroup("Lista de jogos", 8, 64, 353, 295)
If $noFilesFound <> '' Then
    $noFilesLbl = GUICtrlCreateLabel($noFilesFound, 16, 152, 318, 28, $SS_CENTER)
    GUICtrlSetFont(-1, 8, 400, 0, "MS Sans Serif")
Else
    If $appList <> '' Then
        For $i = 1 To $appList[0]
            XPStyleToggle(1)
            $chkList[$i] = GUICtrlCreateCheckbox($appList[$i], $hSpacer, $vSpacer, 161, 17) ; Save the ControlIds on the new array 
            GUICtrlSetFont(-1, 11, 800, 0, "Segoe UI")
            GUICtrlSetColor(-1, 0xFFFFFF)
            GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
            XPStyleToggle(0);turn XP themes on again
            $vSpacer += 16
            If $vSpacer > 330 Then
                $vSpacer = 90
                $hSpacer = 192
            EndIf
        Next
    EndIf
EndIf

GUICtrlCreateGroup("", -99, -99, 1, 1)

$installBtn = GUICtrlCreateButton("Checked Boxes", 488, 200, 75, 25, $WS_GROUP)
$ButtonCheck = GUICtrlCreateButton("Tudo", 488, 160, 75, 25)
$hProgress = GUICtrlCreateProgress(168, 376, 406, 17)
If $appList = '' Then GUICtrlSetState(-1, $GUI_DISABLE) ; Is it not more elegant?

GUISetState(@SW_SHOW)

While 1
    $iCount = 0
            For $i = 1 To $appList[0]
                If GUICtrlRead($chkList[$i]) = 1 Then $iCount += 1
            Next
                If $iCount > 0 And BitAND(GUICtrlGetState($installBtn),$GUI_DISABLE) Then GUICtrlSetState($installBtn,$GUI_ENABLE)
                If $iCount = 0 And BitAND(GUICtrlGetState($installBtn),$GUI_ENABLE) Then GUICtrlSetState($installBtn,$GUI_DISABLE)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $installBtn
            GUICtrlSetData($hProgress, 0)
            For $i = 1 To $appList[0]
                If GUICtrlRead($chkList[$i]) = 1 Then $iCount += 1
            Next
            If $iCount > 0 Then
                ; How much is each checkbox worth?
                $iSegment = Int(100 / $iCount)
                ; Now increase the progress by that amount each time
                Do
                    GUICtrlSetData($hProgress, GUICtrlRead($hProgress) + $iSegment)
                    $iCount -= 1
                    Sleep(1000)
                Until $iCount < 0
                ; Wait 10 secs
                Sleep(1000)
            EndIf
            _listCheck()
        Case $ButtonCheck
            Switch GUICtrlRead($ButtonCheck)
                Case "Tudo"     ;Check All
                    For $i = 1 To $appList[0]
                    GUICtrlSetState ( $chkList[$i] , $GUI_CHECKED )
                    Next
                    GUICtrlSetData($ButtonCheck, "Nada")
                Case "Nada"     ;Clear All
                    For $i = 1 To $appList[0]
                    GUICtrlSetState ( $chkList[$i] , $GUI_UNCHECKED )
                    Next
                    GUICtrlSetData($ButtonCheck, "Tudo")
            EndSwitch
    EndSwitch
WEnd

Func _listCheck()
    For $i = 1 To $appList[0]
        If GUICtrlRead($chkList[$i]) = 1 Then ; Check the checkboxes
            $tasks &= $appList[$i] & @LF ; Add the text from the file list
        EndIf
    Next
    $okPressed = MsgBox(0, '', $tasks)
    If $okPressed = 1 Then
        $tasks = ''
    EndIf
EndFunc   ;==>_listCheck

Func XPStyleToggle($Off = 1)
     If Not StringInStr(@OSTYPE, "WIN32_NT") Then Return 0
      
     If $Off Then
        $XS_n = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
         DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
         Return 1
     ElseIf IsArray($XS_n) Then
         DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $XS_n[0])
         $XS_n = ""
         Return 1
     EndIf
     Return 0
 EndFunc

;~   for $i = 1 to $apps[0]
;~    If IsChecked($APP_CHKBOX[$i]) Then RunWait($apps[$i])
;~   next
;~ ...
;~   
;~ Func IsChecked($control)
;~     Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
;~ EndFunc

Everyone has a great new year.

Thanks.

Share this post


Link to post
Share on other sites



I don't understand your question and I don't see it also from your code.

But your main loop is definitely bad/not optimal

Here is correction:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $installBtn
            GUICtrlSetData($hProgress, 0)
            If $iCount > 0 Then
                ; How much is each checkbox worth?
                $iSegment = Int(100 / $iCount)
                ; Now increase the progress by that amount each time
                $iCountPom = $iCount ; [reserve global $iCount
                Do
                    GUICtrlSetData($hProgress, GUICtrlRead($hProgress) + $iSegment)
                    $iCountPom -= 1
                    Sleep(1000)
                Until $iCountPom < 0
                ; Wait 10 secs
                Sleep(1000)
            EndIf
            _listCheck()
        Case $ButtonCheck
            Switch GUICtrlRead($ButtonCheck)
                Case "Tudo"     ;Check All
                    For $i = 1 To $appList[0]
                        GUICtrlSetState ( $chkList[$i] , $GUI_CHECKED )
                    Next
                    $iCount = $appList[0]
                    GUICtrlSetData($ButtonCheck, "Nada")
                Case "Nada"     ;Clear All
                    For $i = 1 To $appList[0]
                        GUICtrlSetState ( $chkList[$i] , $GUI_UNCHECKED )
                    Next
                    $iCount = 0
                    GUICtrlSetData($ButtonCheck, "Tudo")
            EndSwitch
        Case Else
            ; call CanEnableInstallBtn() only when one of checkbox changes
            For $i = 1 To $appList[0]
                If $nMsg = $chkList[$i] Then CanEnableInstallBtn()
            Next
    EndSwitch
WEnd

Func CanEnableInstallBtn()
    $iCount = 0
    For $i = 1 To $appList[0]
        If GUICtrlRead($chkList[$i]) = 1 Then $iCount += 1
    Next
    If $iCount > 0 And BitAND(GUICtrlGetState($installBtn),$GUI_DISABLE) Then GUICtrlSetState($installBtn,$GUI_ENABLE)
    If $iCount = 0 And BitAND(GUICtrlGetState($installBtn),$GUI_ENABLE) Then GUICtrlSetState($installBtn,$GUI_DISABLE)
EndFunc

Share this post


Link to post
Share on other sites

The problem is, the script lists the directories of the games you want to install so I can add more games without having to modify the program. I am having difficulty identifying the checkbox to run the installer created the game listed on the checkbox selected, or thought about using IniRead dictionary with the applications of games.

I have not had opportunity to check your Zedner fix, I might even change the way you create the checkbox to create it from a different IniRead checkbox with the name and address of the application to run the game.

;~   for $i = 1 to $apps[0]
;~    If IsChecked($APP_CHKBOX[$i]) Then RunWait($apps[$i])
;~   next
;~ ...
;~   
;~ Func IsChecked($control)
;~     Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
;~ EndFunc

Share this post


Link to post
Share on other sites

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <resources.au3>

Opt("TrayIconDebug", 1)
Opt("WinWaitDelay",100)
Opt("WinDetectHiddenText",1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)

$hTray_Show_Item = TrayCreateItem("Hide")
TrayItemSetOnEvent(-1, "To_Tray")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "On_Exit")

#Region ### START Koda GUI section ### Form=k:\prog\gui\main.kxf
$main = GUICreate("Instalador de jogos.", 623, 442, -1, -1)
GUISetBkColor(0xFFFFFF)
Dim $Checkbox[16]
$Checkbox[0] = GUICtrlCreateCheckbox("CrossFire", 64, 96, 97, 17)
$Checkbox[1] = GUICtrlCreateCheckbox("MuConnection", 64, 120, 97, 17)
$Checkbox[2] = GUICtrlCreateCheckbox("MuAway", 64, 144, 97, 17)
$Checkbox[3] = GUICtrlCreateCheckbox("MuHellFire", 64, 168, 97, 17)
$Checkbox[4] = GUICtrlCreateCheckbox("GunBound", 64, 192, 97, 17)
$Checkbox[5] = GUICtrlCreateCheckbox("Cabal Online", 64, 216, 97, 17)
$Checkbox[6] = GUICtrlCreateCheckbox("Flyff", 64, 240, 97, 17)
$Checkbox[7] = GUICtrlCreateCheckbox("GTA San Andreas", 64, 264, 105, 17)
$Checkbox[8] = GUICtrlCreateCheckbox("Counter-striker 1.6", 248, 96, 105, 17)
$Checkbox[9] = GUICtrlCreateCheckbox("Warcraft", 248, 120, 97, 17)
$Checkbox[10] = GUICtrlCreateCheckbox("The Duel", 248, 144, 105, 17)
$Checkbox[11] = GUICtrlCreateCheckbox("Combat Arms", 248, 168, 105, 17)
$Checkbox[12] = GUICtrlCreateCheckbox("Lineage II - Interlude", 248, 192, 113, 17)
$Checkbox[13] = GUICtrlCreateCheckbox("Lineage II - Freya", 248, 216, 121, 17)
$Checkbox[14] = GUICtrlCreateCheckbox("Lineage II - Gracia", 248, 240, 105, 17)
$Checkbox[15] = GUICtrlCreateCheckbox("CrossFire", 248, 264, 97, 17)
$foot = GUICtrlCreateLabel("Mais uma facilidade LanHouse Casarão.", 118, 376, 378, 32)
GUICtrlSetFont(-1, 15, 800, 0, "Segoe UI")
GUICtrlSetColor(-1, 0x0000FF)
$Logo = GUICtrlCreatePic("", 69, 0, 476, 68)
_ResourceSetImageToCtrl($Logo, "LOGO_BMP", $RT_BITMAP)
$Button1 = GUICtrlCreateButton("Tudo", 504, 144, 75, 25)
$Button2 = GUICtrlCreateButton("Instalar", 504, 280, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_MINIMIZE
            To_Tray()
        Case $Button1
            Switch GUICtrlRead($Button1)
                Case "Tudo"
                    For $i = 0 To UBound($checkbox) - 1
                        GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
                    Next
                    GUICtrlSetData($Button1, "Nada")
                Case "Nada"
                    For $i = 0 To UBound($checkbox) - 1
                        GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED)
                    Next
                    GUICtrlSetData($Button1, "Tudo")
            EndSwitch
        Case $Button2
            $fSelected = False
            DisableGUI()
            To_Tray()
            If BitAND(GUICtrlRead($Checkbox[0]), $GUI_CHECKED) = $GUI_CHECKED Then
                If _inno("\crossfire\crossfire.exe") = 0 Then
                GUICtrlSetState($Checkbox[0], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[1]), $GUI_CHECKED) = $GUI_CHECKED Then
                If _inno("\muconection\muconection.exe") = 0 Then
                GUICtrlSetState($Checkbox[1], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[2]), $GUI_CHECKED) = $GUI_CHECKED Then
                If _inno("\muaway\muaway.exe") = 0 Then
                GUICtrlSetState($Checkbox[2], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[3]), $GUI_CHECKED) = $GUI_CHECKED Then
                If _inno("\muhellfire\muhellfire.exe") = 0 Then
                GUICtrlSetState($Checkbox[3], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[4]), $GUI_CHECKED) = $GUI_CHECKED Then
                if _inno("\gunbound\GunBoundWC.exe") = 0 Then
                GUICtrlSetState($Checkbox[4], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[5]), $GUI_CHECKED) = $GUI_CHECKED Then
                If _inno("\cabal\CabalOnline.exe") = 0 Then
                GUICtrlSetState($Checkbox[5], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[6]), $GUI_CHECKED) = $GUI_CHECKED Then
                If _inno("\Flyff\Flyffv15.exe") = 0 Then
                GUICtrlSetState($Checkbox[6], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[7]), $GUI_CHECKED) = $GUI_CHECKED Then
                _InstallShield("\gta\setup.exe", "GTA San Andreas")
                GUICtrlSetState($Checkbox[7], $GUI_UNCHECKED)
                $fSelected = True
            EndIf
            If BitAND(GUICtrlRead($Checkbox[8]), $GUI_CHECKED) = $GUI_CHECKED Then
                If _inno("\counter-strike\cstrike.exe") = 0 Then
                GUICtrlSetState($Checkbox[8], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[9]), $GUI_CHECKED) = $GUI_CHECKED Then
                If _inno("\warcraft\WarcraftIII.exe") = 0 Then
                RegWrite("HKEY_CURRENT_USER\current\software\Blizzard Entertainment\Warcraft III","InstallPath","REG_SZ","C:\Arquivos de programas\LanHouse Casarão\Warcraft III")
                RegWrite("HKEY_CURRENT_USER\current\software\Blizzard Entertainment\Warcraft III","InstallPathX","REG_SZ","C:\Arquivos de programas\LanHouse Casarão\Warcraft III")
                RegWrite("HKEY_CURRENT_USER\current\software\Blizzard Entertainment\Warcraft III","Program","REG_SZ","C:\Arquivos de programas\LanHouse Casarão\Warcraft III\Warcraft III.exe")
                RegWrite("HKEY_CURRENT_USER\current\software\Blizzard Entertainment\Warcraft III","ProgramX","REG_SZ","C:\Arquivos de programas\LanHouse Casarão\Warcraft III\Frozen Throne.exe")
                GUICtrlSetState($Checkbox[9], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[10]), $GUI_CHECKED) = $GUI_CHECKED Then
                If _inno("\theduel\theduel.exe") = 0 Then
                GUICtrlSetState($Checkbox[10], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[11]), $GUI_CHECKED) = $GUI_CHECKED Then
                If _inno("\combatarms\combatarms.exe") = 0 Then
                GUICtrlSetState($Checkbox[11], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            EndIf
            If BitAND(GUICtrlRead($Checkbox[12]), $GUI_CHECKED) = $GUI_CHECKED Then
                _InstallShield("\interlude\setup.exe", "Lineage II - Interlude")
                GUICtrlSetState($Checkbox[12], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            If BitAND(GUICtrlRead($Checkbox[13]), $GUI_CHECKED) = $GUI_CHECKED Then
                _InstallShield("\Freya\Disk1\setup.exe", "Lineage II - Freya")
                GUICtrlSetState($Checkbox[13], $GUI_UNCHECKED)
                $fSelected = True
                EndIf
            If BitAND(GUICtrlRead($Checkbox[14]), $GUI_CHECKED) = $GUI_CHECKED Then
                _InstallShield("\gracia\setup.exe", "Lineage II - Gracia")
                GUICtrlSetState($Checkbox[14], $GUI_UNCHECKED)
                $fSelected = True
            EndIf
;~          If BitAND(GUICtrlRead($Checkbox[15]), $GUI_CHECKED) = $GUI_CHECKED Then
;~              If _inno("\crossfire\crossfire.exe") = 0 Then
;~              GUICtrlSetState($Checkbox[15], $GUI_UNCHECKED)
;~              $fSelected = True
;~              EndIf
;~          EndIf
            EnableGUI()
            To_Tray()
            If $fSelected = False Then MsgBox(0, "erro", "Nada selecionado!")
            ;### Tidy Error -> "endswitch" is closing previous "while" on line 41
    EndSwitch
WEnd
Func _inno($App)
    RunWait(@ScriptDir & $App & " /silent /NOCANCEL /SUPPRESSMSGBOXES ")
EndFunc
Func _WinWaitActivate($title,$text,$timeout=10)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc
Func _InstallShield($app, $game)
    Run(@ScriptDir& $app)
    _WinWaitActivate($game & " - InstallShield Wizard","&Avançar")
    ControlClick($game & " - InstallShield Wizard","Bem-vindo ao Assistente InstallShield","&Avançar >")
    _WinWaitActivate($game & " - InstallShield Wizard","Escolha o local de destino")
    ControlClick($game & " - InstallShield Wizard","Escolha o local de destino","&Avançar >")
    _WinWaitActivate($game & " - InstallShield Wizard","Pronto para instalar o programa")
    ControlClick($game & " - InstallShield Wizard","Pronto para instalar o programa","&Instalar")
    _WinWaitActivate($game & " - InstallShield Wizard","Status da instalação")
    _WinWaitActivate($game & " - InstallShield Wizard","InstallShield Wizard concluído")
    ControlClick($game & " - InstallShield Wizard","InstallShield Wizard concluído","Concluir")
EndFunc
Func DisableGUI()
    GUICtrlSetState($Checkbox[0], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[1], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[2], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[3], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[4], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[5], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[6], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[7], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[8], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[9], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[10], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[11], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[12], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[13], $GUI_DISABLE)
    GUICtrlSetState($Checkbox[14], $GUI_DISABLE)
EndFunc
Func EnableGUI()
    GUICtrlSetState($Checkbox[0], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[1], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[2], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[3], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[4], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[5], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[6], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[7], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[8], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[9], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[10], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[11], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[12], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[13], $GUI_ENABLE)
    GUICtrlSetState($Checkbox[14], $GUI_ENABLE)
EndFunc
Func On_Exit()
    Exit
EndFunc

Func To_Tray()

    If TrayItemGetText($hTray_Show_Item) = "Hide" Then
        GUISetState(@SW_HIDE, $main)
        TrayItemSetText($hTray_Show_Item, "Show")
    Else
        GUISetState(@SW_SHOW, $main)
        GUISetState(@SW_RESTORE, $main)
        TrayItemSetText($hTray_Show_Item, "Hide")
    EndIf

EndFunc

It would be something like this but without all

If BitAND(GUICtrlRead($Checkbox[0]), $GUI_CHECKED) = $GUI_CHECKED

I'm trying to clean and optimize the code and makes it more dynamic for simple change of names or directory name of the game.

Zedna. Thanks for the help. :x

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