jackhab / tccd

Directory switcher for external console and Total Commander
BSD 2-Clause "Simplified" License
3 stars 0 forks source link

ShellExecute is not necessary #1

Closed NSP-0123456 closed 2 years ago

NSP-0123456 commented 2 years ago

Stdin is captured by the CUI application for console write ... to be able to send to current console you have to free the console to not just echo. This is a modified version of tccd.au3 `#Region ; Directives created by AutoIt3Wrapper_GUI

AutoIt3Wrapper_Outfile=tccd32.exe

AutoIt3Wrapper_Outfile_x64=tccd64.exe

AutoIt3Wrapper_Compile_Both=y

AutoIt3Wrapper_Change2CUI=y

AutoIt3Wrapper_Add_Constants=y

EndRegion ; Directives created by AutoIt3Wrapper_GUI

NoTrayIcon

include

AutoItSetOption("MustDeclareVars", 1)

;get Total Commander window handler Local $hTcWin = WinGetHandle("[CLASS:TTOTAL_CMD]") If $hTcWin = 0 Then ConsoleWrite("Total Commander window is not found") EndIf

;get path handles Local $iSide = DllCall("user32.dll", "handle", "SendMessage", "hwnd", $hTcWin, "uint", 1074, "wparam", 1000, "lparam", 0)[0] Local $hLeftPath = DllCall("user32.dll", "handle", "SendMessage", "hwnd", $hTcWin, "uint", 1074, "wparam", 9, "lparam", 0)[0] Local $hRightPath = DllCall("user32.dll", "handle", "SendMessage", "hwnd", $hTcWin, "uint", 1074, "wparam", 10, "lparam", 0)[0]

;get path text Local $sLeftPath = ControlGetText($hTcWin, "", $hLeftPath) Local $sRightPath = ControlGetText($hTcWin, "", $hRightPath)

;Local $sLeftPath = ControlGetText($hTcWin, "", "[CLASSNN:Window13]") ;Local $sRightPath = ControlGetText($hTcWin, "", "[CLASSNN:Window18]")

;trim trailing non-path chars $sLeftPath = StringRegExpReplace($sLeftPath, "\[^\]+$", "") $sRightPath = StringRegExpReplace($sRightPath, "\[^\]+$", "")

;since current process cannot send "cd path" keys to current console ;because it's blocking it we will relaunch outselves in a new process ;that actually send the keys If $CmdLine[0] = "" Then ConsoleWrite("l / l " & $sLeftPath & @CRLF) ConsoleWrite("2 / r " & $sRightPath & @CRLF) ConsoleWrite("Active " & $iSide & @CRLF)

ElseIf ($CmdLine[1] = "d") Then ConsoleWrite("TC window " & $hTcWin & @CRLF) ConsoleWrite("Left path " & $hLeftPath & @CRLF) ConsoleWrite("Right path " & $hRightPath & @CRLF)

ElseIf ($CmdLine[1] = "l" Or $CmdLine[1] = "1") Then

_ChangeFolder($sLeftPath)

ElseIf ($CmdLine[1] = "r" Or $CmdLine[1] = "2") Then _ChangeFolder($sRightPath)

ElseIf ($CmdLine[1] = "s" And $iSide = 2 ) Then _ChangeFolder($sRightPath)

ElseIf ($CmdLine[1] = "s" And $iSide = 1 ) Then _ChangeFolder($sLeftPath)

ElseIf ($CmdLine[1] = "t" And $iSide = 1 ) Then _ChangeFolder($sRightPath)

ElseIf ($CmdLine[1] = "t" And $iSide = 2 ) Then _ChangeFolder($sLeftPath)

ElseIf $CmdLine[1] = "/?" Then ConsoleWrite("TCCD by jackhab" & @CRLF & "This utility reads left and right panel paths from Total Commander" & @CRLF & "and sends them to current console." & @CRLF & "Usage:" & @CRLF & " tccd print left and right paths" & @CRLF & " tccd l cd to left path" & @CRLF & " tccd r cd to right path" & @CRLF & " tccd s cd to src path" & @CRLF & " tccd t cd to tgt path" & @CRLF & _ @CRLF ) EndIf Exit

Func _ChangeFolder( $sPath ) DllCall("kernel32.dll", "bool", "FreeConsole") Send('pushd "' & $sPath & '"' & @CRLF, $SEND_RAW) endFunc`

jackhab commented 2 years ago

Thanks for the idea - this also sends the text faster.