Jump to content

List Right Click


tlokz
 Share

Recommended Posts

Ok, I'm making a pure Auto-It FTP client and I am using WinINet.dll and the UDF. (BTW.. Damn that UDF is sweet!)

Well I got it to put the FTP files into a list and I wanna be able to right click them and have a little menu to pop up allowing actions. Also would like to allow drag and drop, and allow quick renaming like how you do on your Windows Desktop. Here's the code so far if it helps. And yes I have looked around a lot.

#RequireAdmin
#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\Icons\Tyreal.ico
#AutoIt3Wrapper_Outfile=FuckTheProtocol.exe
#AutoIt3Wrapper_Res_Description=FTP
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=n
#AutoIt3Wrapper_res_requestedExecutionLevel=highestAvailable
#AutoIt3Wrapper_Au3Check_Parameters=-w 3 -w 4 -w 5
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/gd
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
;=====================================================================
; Name...........: Fuck The Protocol FTP Client
; Description ...: FTP Client
;
; Remarks .......: Nice name Shonnie!
;
; Author[s] .....: T_LOKZz, Shonnie
; AutoIt Version.: 3.2.12.1
;=====================================================================

#include <WinINet.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <GUIEdit.au3>
#include <GUIComboBox.au3>
#include <GUIListBox.au3>

;~ ===================================================================
;~ StartUp (Declare Vars)
;~ ===================================================================
Opt("GUIOnEventMode", 1)
Global $sServerName, $iServerPort, $sUsername, $sPassword, $iPauseTime, $sDirectory, $sFilenameFilter, $hInternetOpen, $hInternetConnect, $avFtpFile, $Host, $Username, $Password, $Loaded
Global $GUI2, $HostIn, $UsernameIn, $PasswordIn, $Form1
$FileDir = @AppDataDir & "\FuckTheProtocol\"

;~ ===================================================================
;~ Activate FTP Funcs
;~ ===================================================================
_WinINet_Startup()

;~ ===================================================================
;~ GUI
;~ ===================================================================
$GUI = GUICreate("Fuck The Protocol", 415, 483, -1, -1)
$Info = GUICtrlCreateEdit("", 8, 56, 393, 105, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_BORDER, $WS_VSCROLL))
GUICtrlSetData(-1, "")
$FTPDir = GUICtrlCreateList("", 8, 184, 393, 253)
GUICtrlSetOnEvent(-1, "_FTPEvent")
GUICtrlCreateLabel("Profile:", 8, 16, 45, 20)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$Profile = GUICtrlCreateCombo("", 56, 16, 129, 25)
GUICtrlSetData(-1, "|New")
GUICtrlSetOnEvent(-1, "_ProfileEvent")
_GenerateList($Profile, $FileDir)
$Button1 = GUICtrlCreateButton("Connect", 192, 16, 59, 17, 0)
GUICtrlSetOnEvent(-1, "_Connect")
$Button2 = GUICtrlCreateButton("Disconnect", 271, 17, 59, 17, 0)
GUICtrlSetOnEvent(-1, "_CleanUp")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState(@SW_SHOW)

;~ ===================================================================
;~ Infinite Loop
;~ ===================================================================
While 1
    Sleep(200)
WEnd

;~ ===================================================================
;~ Establish FTP Connection with variables in GUI
;~ ===================================================================
Func _Connect()
    $sServerName = $Host
    $iServerPort = 21
    $sUsername = $Username
    $sPassword = $Password

    $iPauseTime = 3000
    $sDirectory = "/"
    $sFilenameFilter = "*"

    $hInternetOpen = _WinINet_InternetOpen("AutoIt/" & @AutoItVersion)
    $hInternetConnect = _WinINet_InternetConnect($hInternetOpen, $INTERNET_SERVICE_FTP, $sServerName, $iServerPort, 0, $sUsername, $sPassword)
    _GUICtrlEdit_AppendText($Info, _WinINet_InternetGetLastResponseInfo())
    _EnumFTP()
EndFunc  ;==>_Connect

;~ ===================================================================
;~ Enumerate all the files in the FTP
;~ ===================================================================
Func _EnumFTP()
    If _WinINet_FtpSetCurrentDirectory($hInternetConnect, $sDirectory) Then
        $avFtpFile = _WinINet_FtpFindFirstFile($hInternetConnect, $sFilenameFilter)
        While Not @error
            GUICtrlSetData($FTPDir, DllStructGetData($avFtpFile[1], "FileName") & @CRLF)
            _WinINet_InternetFindNextFile($avFtpFile[0], DllStructGetPtr($avFtpFile[1]))
        WEnd
    EndIf
EndFunc  ;==>_EnumFTP

;~ ===================================================================
;~ FTP Funcs
;~ ===================================================================
Func _FTPEvent()
    $CurFile = _GUICtrlListBox_GetText($FTPDir, _GUICtrlListBox_GetCurSel($FTPDir))
    _FTPFileGui($CurFile)
    _GUICtrlEdit_AppendText($Info, _WinINet_InternetGetLastResponseInfo())
EndFunc  ;==>_FTPEvent

Func _FTPFileGui($CurFile)
    $Form1 = GUICreate("FileInfo", 352, 169, 193, 125)
    GUICtrlCreateLabel("File:", 48, 24, 30, 21)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    GUICtrlCreateLabel("Size:", 48, 60, 38, 21)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    GUICtrlCreateLabel($CurFile, 83, 24, 200, 21)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $hFtpOpenFile = _WinINet_FtpOpenFile($hInternetConnect, $CurFile, $GENERIC_WRITE)
    $hFtpFileSize = _WinINet_FtpGetFileSize($hFtpOpenFile)
    GUICtrlCreateLabel($hFtpFileSize & " kb", 88, 60, 200, 21)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    GUICtrlCreateButton("Delete", 16, 120, 75, 25, 0)
    GUICtrlSetOnEvent(-1, "_DeleteFile")
    GUICtrlCreateButton("Download", 128, 120, 75, 25, 0)
    GUICtrlSetOnEvent(-1, "_DownloadFile")
    GUICtrlCreateButton("Rename", 242, 120, 75, 25, 0)
    GUICtrlSetOnEvent(-1, "_RenameFile")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseFileGUI")
    GUISetState(@SW_SHOW)
EndFunc  ;==>_FTPFileGui

Func _DeleteFile()
EndFunc  ;==>_DeleteFile

Func _DownloadFile()
EndFunc  ;==>_DownloadFile

Func _RenameFile()
EndFunc  ;==>_RenameFile

Func _CloseFileGUI()
    GUIDelete($Form1)
EndFunc  ;==>_CloseFileGUI

;~ ===================================================================
;~ Profile Funcs
;~ ===================================================================
Func _ProfileEvent()
    Local $CurSel = GUICtrlRead($Profile)
    If $CurSel = "New" Then
        _NewProfile()
    Else
        _LoadProfile($CurSel)
    EndIf
EndFunc  ;==>_ProfileEvent

Func _NewProfile()
    $GUI2 = GUICreate("New Profile", 285, 144, -1, -1)
    GUICtrlCreateLabel("Host:", 24, 16, 42, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $HostIn = GUICtrlCreateInput("ftp.somehost.com", 64, 16, 185, 21)
    GUICtrlCreateLabel("Username:", 24, 49, 82, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $UsernameIn = GUICtrlCreateInput("user@somehost.com", 106, 49, 143, 21)
    GUICtrlCreateLabel("Password:", 21, 80, 77, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $PasswordIn = GUICtrlCreateInput("", 98, 81, 150, 21, $ES_PASSWORD)
    GUICtrlCreateButton("Save", 184, 112, 75, 25, 0)
    GUICtrlSetOnEvent(-1, "_NewProfileHelper")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitNew")
    GUISetState(@SW_SHOW)
EndFunc  ;==>_NewProfile

Func _NewProfileHelper()
    If Not FileExists($FileDir) Then DirCreate($FileDir)
    $Host = GUICtrlRead($HostIn)
    $Username = GUICtrlRead($UsernameIn)
    $Password = GUICtrlRead($PasswordIn)
    $FileName = StringTrimRight($Username, 4)
    $File = $FileDir & $FileName & ".ini"
    _FileCreate($File)
    IniWrite($File, "Settings", "Host", $Host)
    IniWrite($File, "Settings", "Username", $Username)
    IniWrite($File, "Settings", "Password", $Password)
    _GUICtrlEdit_AppendText($Info, "New Profile Created: " & $FileName & @CRLF)
    _LoadProfile($FileName)
    _GenerateList($Profile, $FileDir)
    GUIDelete($GUI2)
EndFunc  ;==>_NewProfileHelper

Func _ExitNew()
    GUIDelete($GUI2)
EndFunc  ;==>_ExitNew

Func _LoadProfile($CurSel)
    $File = $FileDir & $CurSel & ".ini"
    $Host = IniRead($File, "Settings", "Host", "")
    $Username = IniRead($File, "Settings", "Username", "")
    $Password = IniRead($File, "Settings", "Password", "")
    _GUICtrlEdit_AppendText($Info, "Loaded Profile: " & $CurSel & @CRLF)
EndFunc  ;==>_LoadProfile

Func _GenerateList($hListToUse, $vDirectoryToSearch)
    $aFileList = _FileListToArray($vDirectoryToSearch, "*.ini")
    For $i = 1 To UBound($aFileList) - 1
        $fil = String($aFileList[$i])
        $filee = StringTrimRight($fil, 4)
        GUICtrlSetData($hListToUse, $filee)
    Next
EndFunc  ;==>_GenerateList

;~ ===================================================================
;~ Close FTP Connections and ShutDown App
;~ ===================================================================
Func _CleanUp()
    _WinINet_InternetCloseHandle($hInternetConnect)
    _WinINet_InternetCloseHandle($hInternetOpen)
    _GUICtrlEdit_AppendText($Info, "Closed connection to: " & $Host & @CRLF)
    GUICtrlSetData($FTPDir, "")
EndFunc  ;==>_CleanUp

Func _Exit()
    _CleanUp()
    _WinINet_Shutdown()
    Exit
EndFunc  ;==>_Exit
Edited by tlokz
Link to comment
Share on other sites

Use a ListView instead of ListBox

thnx for the reply.. i looked into this also and couldnt find the it either :)

ill keep looking

also I know this is the wrong area but the UDF decalres

Global Const $tagSYSTEMTIME yet it's already decalred in the other structure include...

any way to fix this? I tried commenting it out and i don't know if its my script but it doesn't allow me to do anything with the files but allows me to connect the FTO

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...