#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=Warning_Shield_Grey.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #Include Opt("TrayMenuMode",1) $ssh = TrayCreateMenu("ssh") $scp = TrayCreateMenu("scp") $rdesktop = TrayCreateMenu("rdesktop") ;############## $currsubmenu = 0 global $ssh_submenus[1] global $scp_submenus[1] global $rdst_submenus[1] $ssh_submenus[0] = TrayCreateMenu("sonstige",$ssh) $scp_submenus[0] = TrayCreateMenu("sonstige",$scp) $rdst_submenus[0] = TrayCreateMenu("sonstige",$rdesktop) global $ssh_items[1] global $scp_items[1] global $rdst_items[1] ; needed to find the hostname for name after item click global $all_names[1] global $all_hosts[1] global $type = "" global $control = ""; ;######################### global $tc = getvol("TC"); $exefile = $tc & "\data\putty_runner.exe"; getitems() $exit = TrayCreateItem("beenden") $update = TrayCreateItem("update") func clear_all() ReDim $scp_items[1] redim $ssh_items[1] ReDim $rdst_items[1] $rdst_items[0] = "" $ssh_items[0] = "" $scp_items[0] = "" for $m in $ssh_submenus TrayItemDelete($m) Next for $m in $rdst_submenus TrayItemDelete($m) Next for $m in $scp_submenus TrayItemDelete($m) Next EndFunc func getitems() $content = FileRead($tc & "\data\pws.txt") $splits = stringsplit($content,@crlf,0) $currcompany_has_ssh = false; $currcompany_has_rdst = false; $line_counter =0; for $s in $splits $s = StringReplace($s,@crlf,"") $s = StringReplace($s,@cr,"") $s = StringReplace($s,@lf,"") $do = true; if stringlen($s) <= 5 Then $do = False endif if(stringleft($s,1) == "#") Then $do = false endif ;########## if(stringleft($s,4) == "### ") Then ; first check if we better delete empty menu items ; !!!!after the loop there is the same code again!!!! ;if($currsubmenu > 0) Then if($currcompany_has_ssh == false) Then TrayItemDelete($ssh_submenus[$currsubmenu]) TrayItemDelete($scp_submenus[$currsubmenu]) endif if($currcompany_has_rdst == false) Then TrayItemDelete($rdst_submenus[$currsubmenu]) endif ;endif ;; should create company submenu $currsubmenu = $currsubmenu +1 $submenu_name = StringRight($s,StringLen($s)-4) redim $ssh_submenus[$currsubmenu+1]; redim $scp_submenus[$currsubmenu+1]; redim $rdst_submenus[$currsubmenu+1]; $ssh_submenus[$currsubmenu] = TrayCreateMenu($submenu_name,$ssh) $scp_submenus[$currsubmenu] = TrayCreateMenu($submenu_name,$scp) $rdst_submenus[$currsubmenu] = TrayCreateMenu($submenu_name,$rdesktop) $currcompany_has_ssh = false; $currcompany_has_rdst = false; endif ;############### if $do Then $tmp = StringSplit($s," "); $host = $tmp[1] $type = $tmp[2] $name = $host if(stringleft($splits[$line_counter -1], 3) == "#- ") then $name = StringRight($splits[$line_counter -1], stringlen($splits[$line_counter -1])-3) endif ReDim $all_hosts[UBound($all_hosts)+1] ReDim $all_names[Ubound($all_names)+1] $all_names[UBound($all_names)-1] = $name; $all_hosts[UBound($all_hosts)-1] = $host; if($type == "ssh") Then redim $ssh_items[Ubound($ssh_items)+1]; redim $scp_items[UBound($scp_items)+1]; $ssh_items[Ubound($ssh_items)-1] = TrayCreateItem($name,$ssh_submenus[$currsubmenu]); $scp_items[Ubound($scp_items)-1] = TrayCreateItem($name,$scp_submenus[$currsubmenu]); $currcompany_has_ssh = true; Else redim $rdst_items[Ubound($rdst_items)+1]; $rdst_items[Ubound($rdst_items)-1] = TrayCreateItem($name,$rdst_submenus[$currsubmenu]); $currcompany_has_rdst = true; endif EndIf $line_counter = $line_counter + 1; Next ; remove not found submenu also, it this is the last entry :-) ;!!! Same code is in the loop (near ### search) !!!! if($currcompany_has_ssh == false) Then TrayItemDelete($ssh_submenus[$currsubmenu]) TrayItemDelete($scp_submenus[$currsubmenu]) endif if($currcompany_has_rdst == false) Then TrayItemDelete($rdst_submenus[$currsubmenu]) endif TraySetState() endfunc While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop case $msg = $exit Exit case $msg = $update clear_all() getitems() EndSelect $type = "" $control = ""; find_control($msg); if($type == "rdesktop" or $type == "scp" or $type = "ssh") Then $host = get_hostname_by_control($control) $cmd = $exefile & " """ & $host & """ " & $type; run($cmd); endif sleep(100) WEnd Exit func find_control($msg) for $do_ssh in $ssh_items if($msg == $do_ssh) Then $type = "ssh" $control = $do_ssh; return true endif next for $do_scp in $scp_items if($msg == $do_scp) Then $type = "scp" $control = $do_scp; return true endif next for $do_rdst in $rdst_items if($msg == $do_rdst) Then $type = "rdesktop" $control = $do_rdst; return true endif next EndFunc func get_hostname_by_control($control) $name = TrayItemGetText($control) $name_key = array_key_by_value($all_names,$name) $host = $all_hosts[$name_key]; return $host; endfunc #cs gets the key in $haystack for $needle return -1 if not found #ce func array_key_by_value($haystack,$needle) $counter = 0; for $v in $haystack if($v == $needle) Then return $counter endif $counter = $counter + 1 Next return -1 EndFunc func getvol($type) if($type="SD") Then $file = "SDToken" EndIf if($type="TC") Then $file = "TCToken" endif $var = DriveGetDrive( "all" ) If NOT @error Then For $i = 1 to $var[0] $status = DriveStatus( $var[$i]); if($status = "READY") then ;if($var[$i] <> "a:" and $var[$i] <> "b:") then if(fileexists($var[$i] & "\" & $file)) Then return $var[$i] endif endif Next EndIf return false endfunc