Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/12/2024 in all areas

  1. You must be aware of bit fields declarations. For InterfaceAndOperStatusFlags it will be used one byte, not 8 bytes: struct { BOOLEAN HardwareInterface : 1; BOOLEAN FilterInterface : 1; BOOLEAN ConnectorPresent : 1; BOOLEAN NotAuthenticated : 1; BOOLEAN NotMediaConnected : 1; BOOLEAN Paused : 1; BOOLEAN LowPower : 1; BOOLEAN EndPointInterface : 1; } InterfaceAndOperStatusFlags; Local $sTAG_InterfaceAndOperStatusFlags = "boolean HardwareInterface;boolean FilterInterface;boolean ConnectorPresent;boolean NotAuthenticated;boolean NotMediaConnected;boolean Paused;boolean LowPower;boolean EndPointInterface;" Local $tInterfaceAndOperStatusFlags = DllStructCreate($sTAG_InterfaceAndOperStatusFlags) ConsoleWrite(DllStructGetSize($tInterfaceAndOperStatusFlags) & @CRLF)
    2 points
  2. I was needing to copy some files something like a backup of a folder without overwrite file. I found in this thread a suggestion to use _WinAPI_ShellFileOperation but for my surprise it does overwrite files all the time 🤔. So I was checking MSDN and found out that IFileOperation implemented a nice operation flag to handle what I was needing(FOFX_KEEPNEWERFILE) so I just wrote this sample in case anyone was looking for it. #include <WinAPIShellEx.au3> ;~ Global Const $FOF_ALLOWUNDO = 0x40 ;~ Global Const $FOF_CONFIRMMOUSE = 0x2 ;~ Global Const $FOF_FILESONLY = 0x80 ;~ Global Const $FOF_MULTIDESTFILES = 0x1 ;~ Global Const $FOF_NO_CONNECTED_ELEMENTS = 0x2000 ;~ Global Const $FOF_NOCONFIRMATION = 0x10 ;~ Global Const $FOF_NOCONFIRMMKDIR = 0x200 ;~ Global Const $FOF_NOCOPYSECURITYATTRIBS = 0x800 ;~ Global Const $FOF_NOERRORUI = 0x400 ;~ Global Const $FOF_NORECURSION = 0x1000 ;~ Global Const $FOF_RENAMEONCOLLISION = 0x8 ;~ Global Const $FOF_SILENT = 0x4 ;~ Global Const $FOF_SIMPLEPROGRESS = 0x100 ;~ Global Const $FOF_WANTMAPPINGHANDLE = 0x20 ;~ Global Const $FOF_WANTNUKEWARNING = 0x4000 Global Const $FOFX_ADDUNDORECORD = 0x20000000 Global Const $FOFX_NOSKIPJUNCTIONS = 0x00010000 Global Const $FOFX_PREFERHARDLINK = 0x00020000 Global Const $FOFX_SHOWELEVATIONPROMPT = 0x00040000 Global Const $FOFX_EARLYFAILURE = 0x00100000 Global Const $FOFX_PRESERVEFILEEXTENSIONS = 0x00200000 Global Const $FOFX_KEEPNEWERFILE = 0x00400000 Global Const $FOFX_NOCOPYHOOKS = 0x00800000 Global Const $FOFX_NOMINIMIZEBOX = 0x01000000 Global Const $FOFX_MOVEACLSACROSSVOLUMES = 0x02000000 Global Const $FOFX_DONTDISPLAYSOURCEPATH = 0x04000000 Global Const $OFX_DONTDISPLAYDESTPATH = 0x08000000 Global Const $FOFX_RECYCLEONDELETE = 0x00080000 Global Const $FOFX_REQUIREELEVATION = 0x10000000 Global Const $FOFX_COPYASDOWNLOAD = 0x40000000 Global Const $FOFX_DONTDISPLAYLOCATIONS = 0x80000000 Global Const $IID_IShellItem = "{43826d1e-e718-42ee-bc55-a1e261c37bfe}" Global Const $dtag_IShellItem = _ "BindToHandler hresult(ptr;clsid;clsid;ptr*);" & _ "GetParent hresult(ptr*);" & _ "GetDisplayName hresult(int;ptr*);" & _ "GetAttributes hresult(int;int*);" & _ "Compare hresult(ptr;int;int*);" Global Const $IID_IShellItemArray = "{b63ea76d-1f85-456f-a19c-48159efa858b}" Global Const $dtagIShellItemArray = "BindToHandler hresult();GetPropertyStore hresult();" & _ "GetPropertyDescriptionList hresult();GetAttributes hresult();GetCount hresult(dword*);" & _ "GetItemAt hresult();EnumItems hresult();" Global Const $BHID_EnumItems = "{94F60519-2850-4924-AA5A-D15E84868039}" Global Const $IID_IEnumShellItems = "{70629033-e363-4a28-a567-0db78006e6d7}" Global Const $dtagIEnumShellItems = "Next hresult(ulong;ptr*;ulong*);Skip hresult();Reset hresult();Clone hresult();" Global Const $CLSID_IFileOperation = "{3AD05575-8857-4850-9277-11B85BDB8E09}" Global Const $IID_IFileOperation = "{947AAB5F-0A5C-4C13-B4D6-4BF7836FC9F8}" Global Const $dtagIFileOperation = "Advise hresult(ptr;dword*);" & _ "Unadvise hresult(dword);" & _ "SetOperationFlags hresult(dword);" & _ "SetProgressMessage hresult(wstr);" & _ "SetProgressDialog hresult(ptr);" & _ "SetProperties hresult(ptr);" & _ "SetOwnerWindow hresult(hwnd);" & _ "ApplyPropertiesToItem hresult(ptr);" & _ "ApplyPropertiesToItems hresult(ptr);" & _ "RenameItem hresult(ptr;wstr;ptr);" & _ "RenameItems hresult(ptr;wstr);" & _ "MoveItem hresult(ptr;ptr;wstr;ptr);" & _ "MoveItems hresult(ptr;ptr);" & _ "CopyItem hresult(ptr;ptr;wstr;ptr);" & _ "CopyItems hresult(ptr;ptr);" & _ "DeleteItem hresult(ptr;ptr);" & _ "DeleteItems hresult(ptr);" & _ "NewItem hresult(ptr;dword;wstr;wstr;ptr);" & _ "PerformOperations hresult();" & _ "GetAnyOperationsAborted hresult(ptr*);" _Test() Func _Test() Local $sPathFrom = @ScriptDir & "\PathFrom\" Local $sPathTo = @ScriptDir & "\PathTo\" DirRemove($sPathFrom, 1) DirRemove($sPathTo, 1) DirCreate($sPathFrom) For $i = 1 To 5000 FileWrite($sPathFrom & $i & ".txt", "Hello World - " & $i) Next _WinAPI_ShellFileOperation($sPathFrom & "*.*", $sPathTo, $FO_COPY, BitOR($FOF_NOERRORUI, $FOF_NOCONFIRMATION)) ;update file From and To FileWrite($sPathFrom & 1 & ".txt", " Only this should be update in 'To' Folder") FileWrite($sPathTo & 2 & ".txt", " This should not be overwritten but it does :(") MsgBox(0, "ShellFileOperation", "Check these files: " & @CRLF & $sPathFrom & 1 & ".txt" & @CRLF & @CRLF & $sPathTo & 2 & ".txt") _WinAPI_ShellFileOperation($sPathFrom & "*.*", $sPathTo, $FO_COPY, BitOR($FOF_NOERRORUI, $FOF_NOCONFIRMATION)) MsgBox(0, "ShellFileOperation", "Check these files: " & @CRLF & $sPathFrom & 1 & ".txt" & @CRLF & @CRLF & $sPathTo & 2 & ".txt") ;update file From and To FileWrite($sPathFrom & 1 & ".txt", " - I was updated again :-S") FileWrite($sPathTo & 2 & ".txt", " This will not be overwritten :)") MsgBox(0, "IFileOperation", "Check these files: " & @CRLF & $sPathFrom & 1 & ".txt" & @CRLF & @CRLF & $sPathTo & 2 & ".txt") _IFileOperationCopyFiles($sPathFrom, $sPathTo) MsgBox(0, "IFileOperation", "Check these files: " & @CRLF & $sPathFrom & 1 & ".txt" & @CRLF & @CRLF & $sPathTo & 2 & ".txt") DirRemove($sPathFrom, 1) DirRemove($sPathTo, 1) EndFunc ;==>_Test Func _IFileOperationCopyFiles($sPathFrom, $sPathTo, $iFlags = BitOR($FOF_NOERRORUI, $FOFX_KEEPNEWERFILE, $FOFX_NOCOPYHOOKS, $FOF_NOCONFIRMATION)) If Not FileExists($sPathFrom) Then Return SetError(1, 0, False) EndIf If Not FileExists($sPathTo) Then DirCreate($sPathTo) EndIf Local $tIIDIShellItem = CLSIDFromString($IID_IShellItem) Local $tIIDIShellItemArray = CLSIDFromString($IID_IShellItemArray) Local $oIFileOperation = ObjCreateInterface($CLSID_IFileOperation, $IID_IFileOperation, $dtagIFileOperation) If Not IsObj($oIFileOperation) Then Return SetError(2, 0, False) Local $pIShellItemFrom = 0 Local $pIShellItemTo = 0 _SHCreateItemFromParsingName($sPathFrom, 0, DllStructGetPtr($tIIDIShellItem), $pIShellItemFrom) _SHCreateItemFromParsingName($sPathTo, 0, DllStructGetPtr($tIIDIShellItem), $pIShellItemTo) If Not $pIShellItemFrom Or Not $pIShellItemTo Then Return SetError(3, 0, False) Local $oIShellItem = ObjCreateInterface($pIShellItemFrom, $IID_IShellItem, $dtag_IShellItem) Local $pEnum = 0 $oIShellItem.BindToHandler(0, $BHID_EnumItems, $IID_IEnumShellItems, $pEnum) Local $oIEnumShellItems = ObjCreateInterface($pEnum, $IID_IEnumShellItems, $dtagIEnumShellItems) If Not $pEnum Then Return SetError(4, 0, False) $oIFileOperation.SetOperationFlags($iFlags) Local $pItem = 0 Local $iFeched = 0 While $oIEnumShellItems.Next(1, $pItem, $iFeched) = 0 $oIFileOperation.CopyItems($pItem, $pIShellItemTo) WEnd Return $oIFileOperation.PerformOperations() = 0 EndFunc ;==>_IFileOperationCopyFiles Func _SHCreateItemFromParsingName($szPath, $pbc, $riid, ByRef $pv) Local $aRes = DllCall("shell32.dll", "long", "SHCreateItemFromParsingName", "wstr", $szPath, "ptr", $pbc, "ptr", $riid, "ptr*", 0) If @error Then Return SetError(1, 0, @error) $pv = $aRes[4] Return $aRes[0] EndFunc ;==>_SHCreateItemFromParsingName Func CLSIDFromString($sString) Local $tCLSID = DllStructCreate("dword;word;word;byte[8]") Local $aRet = DllCall("Ole32.dll", "long", "CLSIDFromString", "wstr", $sString, "ptr", DllStructGetPtr($tCLSID)) If @error Then Return SetError(1, 0, @error) If $aRet[0] <> 0 Then Return SetError(2, $aRet[0], 0) Return $tCLSID EndFunc ;==>CLSIDFromString Saludos
    2 points
  3. Try removing the document part, and search from the window instead...
    1 point
  4. There is no limit. But dealing with the hierarchy can be troublesome. I frequently highlight controls during development or do a findall in a subtree which can be slower but is programming wise easier certainly when you start with uia. Dealing with html can potentially be easier with webdriver but both have a challenging learning curve.
    1 point
  5. I can share the code, no problem dude, it's just a bunch of methods and clicks. BIG WARNING: I put up the fastest and ugliest code to make the thing work because I needed to upload a lot of stuff. Even if it's horrible code, it still saved me a TON of time and I uploaded in an afternoon what would have took me 2 weeks. So I'm happy for the result anyway. That said, I also need to tell you that it needs a lot of polishing and testing. If you wish I can post more as I progress into developing it, but I do it in my free time and it will take some time to add missing features and refactor the code in a more ordered and organized way. It's far from perfect and completed and I plan to add a ton of stuff, but here you go: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> ;TODO ;F-01 Filtro lista file? ;F-02 Gestione cartelle ;DONE - F-03 Flag resetta numero file dopo caricamento cartella ;F-04 Btn selezione deseleziona tutte le opzioni ;F-05 Flag scrivi lista dei file ;F-06 Eventuale index per corsi caricati a topic singolo ;BUGS ;B-01: Alcune immagini sono renderizzate nel popup di upload diversamente (vedi corso L1 Calimove) e questo fa saltare l'upload, andrebbe considerato un detect ;grafico del bottone save visto che la UI non si riesce a catturare? ;B-02 BIG FIX: I made a lot of mess for finding "Send" button in upload screen. Instead ;it's just sufficient to send {ENTER} and no detection at all is needed. Damn :D Opt('GUIOnEventMode', '1') HotKeySet('!p', '_Exit') #Region ### START Koda GUI section ### Form= ;CREATE FORM $TgUpperForm = GUICreate("TGUpper", 713, 677, 192, 124) ;CREATE LISTVIEW $ListView1 = GUICtrlCreateListView("", 208, 32, 490, 574) _GUICtrlListView_InsertColumn($ListView1, 0, "File", 380) _GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT)) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 400) ;CREATE TOP BUTTONS $btnSelectFolder = GUICtrlCreateButton("Select Folder", 8, 8, 195, 25) $btnSelectFile = GUICtrlCreateButton("Select File", 8, 40, 195, 25) $btnCreateTopic = GUICtrlCreateButton("Create Topic", 8, 72, 195, 25) $btnSelectAll = GUICtrlCreateButton("Select All", 8, 104, 195, 25) ;CREATE GRUP FOLDER PROGRESSIVE $grpFolderProgressive = GUICtrlCreateGroup("Folder Progressive", 8, 136, 193, 209) $txtPrefixFolderProgressive = GUICtrlCreateInput("", 16, 272, 49, 21) $btnIncreaseFolderProgressiveCounter = GUICtrlCreateButton("+", 16, 176, 43, 25) $txtPostfixFolderProgressive = GUICtrlCreateInput("", 144, 272, 49, 21) $btnDecreaseFolderProgressiveCounter = GUICtrlCreateButton("-", 64, 176, 43, 25) $txtCounterFolderProgressive = GUICtrlCreateInput("0", 80, 272, 49, 21) $btnResetFolderProgressiveCounter = GUICtrlCreateButton("Reset", 112, 176, 75, 25) $chkEnableFolderProgressive = GUICtrlCreateCheckbox("Enable Folder Progressive", 16, 152, 169, 17) GUICtrlSetState(-1, $GUI_CHECKED) $chkAutoIncrementFolderProgressiveCounter = GUICtrlCreateCheckbox("Autoincrement", 16, 208, 97, 17) GUICtrlSetState(-1, $GUI_CHECKED) $lblPrefixFolderProgressive = GUICtrlCreateLabel("Prefix", 16, 248, 30, 17) $lblCounterFolderProgressive = GUICtrlCreateLabel("Counter", 80, 248, 41, 17) $lblPostfixCounterprogressive = GUICtrlCreateLabel("Postfix", 144, 248, 35, 17) $lblFolderProgressiveSeparator = GUICtrlCreateLabel("Separator", 128, 208, 50, 17) $txtFolderProgressiveSeparator = GUICtrlCreateInput(" ", 128, 224, 57, 21) $txtReplaceTextInTopicName = GUICtrlCreateInput("", 16, 312, 177, 21) $lblReplaceTextInTopicName = GUICtrlCreateLabel("Text to replace in topic name", 16, 296, 141, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) ;CREATE GROUP FILE PROGRESSIVE $grpFileProgressive = GUICtrlCreateGroup("File Progressive", 8, 352, 193, 193) $txtPrefixFileProgressive = GUICtrlCreateInput("", 16, 488, 49, 21) $btnIncreaseFileProgressiveCounter = GUICtrlCreateButton("+", 16, 392, 43, 25) $txtPostfixFileProgressive = GUICtrlCreateInput("", 144, 488, 49, 21) $btnDecreaseFileProgressiveCounter = GUICtrlCreateButton("-", 64, 392, 43, 25) $txtCounterFileProgressive = GUICtrlCreateInput("1", 80, 488, 49, 21) $btnResetFileProgressiveCounter = GUICtrlCreateButton("Reset", 112, 392, 75, 25) $chkEnableFileProgressive = GUICtrlCreateCheckbox("Enable File Progressive", 16, 368, 169, 17) GUICtrlSetState(-1, $GUI_CHECKED) $chkAutoIncrementFileProgressiveCounter = GUICtrlCreateCheckbox("Autoincrement", 16, 424, 169, 17) GUICtrlSetState(-1, $GUI_CHECKED) $lblPrefixFileProgressive = GUICtrlCreateLabel("Prefix", 16, 464, 30, 17) $lblCounterFileProgressive = GUICtrlCreateLabel("Counter", 80, 464, 41, 17) $lblPostfixFileProgressive = GUICtrlCreateLabel("Postfix", 144, 464, 35, 17) $txtFileProgressiveSeparator = GUICtrlCreateInput(" ", 128, 440, 57, 21) $lblFileProgressiveSeparator = GUICtrlCreateLabel("Separator", 128, 424, 50, 17) $chkResetFileProgressiveCounterOnReopenFolderOrdFile = GUICtrlCreateCheckbox("Reset count after file/folder open", 16, 520, 177, 17) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlCreateGroup("", -99, -99, 1, 1) ;CREATE BOTTOM BUTTONS $chkRefocusFormAfterTopicCreation = GUICtrlCreateCheckbox("Refocus form after creating topic", 16, 555, 177, 17) GUICtrlSetState(-1, $GUI_CHECKED) $chkAutoLoadFilesAfterTopic = GUICtrlCreateCheckbox("Autoload files after topic creation", 16, 577, 185, 17) GUICtrlSetState(-1, $GUI_CHECKED) $chkAskEveryFile = GUICtrlCreateCheckbox("Ask confirmation for every file", 16, 619, 185, 17) $chkElaborateAllFolders = GUICtrlCreateCheckbox("Elaborate all folders automatically", 16, 598, 177, 17) $btnProcessFiles = GUICtrlCreateButton("Process selected files", 8, 640, 195, 25) GUICtrlSetState($btnProcessFiles, $GUI_DISABLE) ;CREATE UPPER LISTVIEW LABELS $lblCurrentFolderDesc = GUICtrlCreateLabel("Current folder", 208, 8, 67, 17) $lblNextFolderDesc = GUICtrlCreateLabel("Next folder", 456, 8, 55, 17) $txtCurrentFolder = GUICtrlCreateInput("-", 280, 5, 169, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) $txtNextFolder = GUICtrlCreateInput("-", 512, 5, 185, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY)) ;CREATE LOWER LISTVIEW BUTTONS/LABELS $chkNextFolderAutoSwap = GUICtrlCreateCheckbox("Auto swap next folder", 224, 616, 121, 17) $btnOpenFolder = GUICtrlCreateButton("Open Folder", 352, 612, 139, 25) $btnSwapNextFolder = GUICtrlCreateButton("Next Folder", 504, 612, 195, 25) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $actionsdelay = 2200 Global $actionsdelay_short = 700 Global $actionsdelay_very_short = 400 Global $lastButtonClicked = "" Global $folder = "" Global $nextFolder = "" GUICtrlSetOnEvent($btnSelectFolder, "SelectFolder") GUICtrlSetOnEvent($btnSelectFile, "SelectFile") GUICtrlSetOnEvent($btnCreateTopic, "CreateTopic") GUICtrlSetOnEvent($btnIncreaseFolderProgressiveCounter, "IncreaseFolderProgressiveCounter") GUICtrlSetOnEvent($btnDecreaseFolderProgressiveCounter, "DecreaseFolderProgressiveCounter") GUICtrlSetOnEvent($btnResetFolderProgressiveCounter, "ResetFolderProgressiveCounter") GUICtrlSetOnEvent($btnIncreaseFileProgressiveCounter, "IncreaseFileProgressiveCounter") GUICtrlSetOnEvent($btnDecreaseFileProgressiveCounter, "DecreaseFileProgressiveCounter") GUICtrlSetOnEvent($btnResetFileProgressiveCounter, "ResetFileProgressiveCounter") GUICtrlSetOnEvent($btnProcessFiles, "ProcessFiles") GUICtrlSetOnEvent($btnSelectAll, "SelectAll") GUICtrlSetOnEvent($btnSwapNextFolder, "SwapNextFolder") GUICtrlSetOnEvent($chkNextFolderAutoSwap, "_chkNextFolderAutoSwap") GUICtrlSetOnEvent($chkAutoLoadFilesAfterTopic, "_chkAutoLoadFilesAfterTopic") While 1 Sleep(100) WEnd Func SelectFolder() $folder = FileSelectFolder("Select a folder", "") If @error Then MsgBox($MB_OK, "Error", "No folder selected.") Return EndIf $files = _FileListToArray($folder, "*", 1) If @error Then MsgBox($MB_OK, "Error", "No files found in the selected folder.") Return EndIf UpdateFileList($files) $lastButtonClicked = "SelectFolder" If GUICtrlRead($chkResetFileProgressiveCounterOnReopenFolderOrdFile) = $GUI_CHECKED Then ResetFileProgressiveCounter() EndIf UpdateCurrentFolderDisplay() UpdateNextFolderDisplay() UpdateSwapNextFolderButton() UpdateProcessFilesButton() SelectAll() EndFunc Func SelectFile() $selectedFile = FileOpenDialog("Select a file", @WorkingDir, "All files (.)", 1) If @error Then MsgBox($MB_OK, "Error", "No file selected.") Return EndIf $files = StringSplit($selectedFile, "|", 1) UpdateFileList($files) $lastButtonClicked = "SelectFile" If GUICtrlRead($chkResetFileProgressiveCounterOnReopenFolderOrdFile) = $GUI_CHECKED Then ResetFileProgressiveCounter() EndIf UpdateCurrentFolderDisplay() UpdateNextFolderDisplay() UpdateSwapNextFolderButton() UpdateProcessFilesButton() EndFunc Func UpdateFileList($files) _GUICtrlListView_DeleteAllItems($ListView1) For $i = 1 To UBound($files) - 1 If Not StringIsDigit($files[$i]) Then _GUICtrlListView_AddItem($ListView1, $files[$i]) EndIf Next EndFunc Func IncreaseFolderProgressiveCounter() $folderCounter = Int(GUICtrlRead($txtCounterFolderProgressive)) + 1 GUICtrlSetData($txtCounterFolderProgressive, $folderCounter) EndFunc Func DecreaseFolderProgressiveCounter() $folderCounter = Int(GUICtrlRead($txtCounterFolderProgressive)) If $folderCounter > 0 Then $folderCounter -= 1 GUICtrlSetData($txtCounterFolderProgressive, $folderCounter) EndIf EndFunc Func ResetFolderProgressiveCounter() GUICtrlSetData($txtCounterFolderProgressive, 0) EndFunc Func IncreaseFileProgressiveCounter() $fileCounter = Int(GUICtrlRead($txtCounterFileProgressive)) + 1 GUICtrlSetData($txtCounterFileProgressive, $fileCounter) EndFunc Func DecreaseFileProgressiveCounter() $fileCounter = Int(GUICtrlRead($txtCounterFileProgressive)) If $fileCounter > 0 Then $fileCounter -= 1 GUICtrlSetData($txtCounterFileProgressive, $fileCounter) EndIf EndFunc Func ResetFileProgressiveCounter() GUICtrlSetData($txtCounterFileProgressive, 1) EndFunc Func ProcessFiles() Local $selectedFiles[0] For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1 If _GUICtrlListView_GetItemChecked($ListView1, $i) Then _ArrayAdd($selectedFiles, _GUICtrlListView_GetItemText($ListView1, $i)) EndIf Next If UBound($selectedFiles) = 0 Then MsgBox($MB_OK, "Error", "No files selected.") Return EndIf $askConfirmation = (GUICtrlRead($chkAskEveryFile) = $GUI_CHECKED) For $i = 0 To UBound($selectedFiles) - 1 $filePath = $selectedFiles[$i] If $askConfirmation Then $confirmResult = MsgBox($MB_OKCANCEL, "Confirmation", "Process file:" & @CRLF & $filePath) If $confirmResult = $IDCANCEL Then Return ; Abort the whole process EndIf EndIf If $lastButtonClicked = "SelectFolder" Then ProcessFolderFile($filePath) ElseIf $lastButtonClicked = "SelectFile" Then ProcessSingleFile($filePath) EndIf Next If GUICtrlRead($chkNextFolderAutoSwap) = $GUI_CHECKED Then SwapNextFolder() WinActivate($TgUpperForm) EndIf EndFunc Func ProcessFolderFile($filePath) $folderName = GetFolderName($folder) $fileName = GetFileName($filePath) $fileFullPath = $folder & "\" & $filePath $filePrefix = GUICtrlRead($txtPrefixFileProgressive) $fileCounter = GUICtrlRead($txtCounterFileProgressive) $filePostfix = GUICtrlRead($txtPostfixFileProgressive) $fileSeparator = GuiCtrlRead($txtFileProgressiveSeparator) If GUICtrlRead($chkEnableFileProgressive) = $GUI_CHECKED Then $finalFileName = $filePrefix & $fileCounter & $filePostfix & $fileSeparator & $fileName Else $finalFileName = $fileName EndIf If GUICtrlRead($chkAutoIncrementFileProgressiveCounter) = $GUI_CHECKED Then $fileCounter = Int($fileCounter) + 1 GUICtrlSetData($txtCounterFileProgressive, $fileCounter) EndIf UploadFile($fileFullPath, $finalFileName) EndFunc Func ProcessSingleFile($filePath) $folderName = GetFolderName($folder) $fileName = GetFileName($filePath) $fileFullPath = $folder & "" & $filePath $filePrefix = GUICtrlRead($txtPrefixFileProgressive) $fileCounter = GUICtrlRead($txtCounterFileProgressive) $filePostfix = GUICtrlRead($txtPostfixFileProgressive) If GUICtrlRead($chkEnableFileProgressive) = $GUI_CHECKED Then $finalFileName = $filePrefix & $fileCounter & $filePostfix & " - " & $fileName Else $finalFileName = $fileName EndIf $folderPrefix = GUICtrlRead($txtPrefixFolderProgressive) $folderCounter = GUICtrlRead($txtCounterFolderProgressive) $folderPostfix = GUICtrlRead($txtPostfixFolderProgressive) If GUICtrlRead($chkEnableFolderProgressive) = $GUI_CHECKED Then $finalFolderName = $folderPrefix & $folderCounter & $folderPostfix & " - " & $folderName Else $finalFolderName = $folderName EndIf MsgBox($MB_OK, "Processing Single File", "Folder Name: " & $finalFolderName & @CRLF & "File Full Path: " & $fileFullPath & @CRLF & "File Name: " & $finalFileName) If GUICtrlRead($chkAutoIncrementFileProgressiveCounter) = $GUI_CHECKED Then $fileCounter = Int($fileCounter) + 1 GUICtrlSetData($txtCounterFileProgressive, $fileCounter) EndIf EndFunc Func GetFolderNameFromPath($path) Return StringRegExpReplace($path, "^.*\\", "") EndFunc Func GetFolderName($folderPath) Local $folderName = StringRegExpReplace($folderPath, "^.*\", "") Return $folderName EndFunc Func GetFileName($filePath) Local $fileName = StringRegExpReplace($filePath, "^.*\", "") Return $fileName EndFunc Func SelectAll() For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1 _GUICtrlListView_SetItemChecked($ListView1, $i) Next EndFunc Func _Exit() Exit EndFunc Func CreateTopic() If _GUICtrlListView_GetItemCount($ListView1) < 1 Then MsgBox($MB_OK, "Error", "No files selected.") Return EndIf $TopicName = GetFolderName($folder) Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" Local $aPathSplit = _PathSplit($folder, $sDrive, $sDir, $sFileName, $sExtension) $folderPrefix = GUICtrlRead($txtPrefixFolderProgressive) $folderCounter = GUICtrlRead($txtCounterFolderProgressive) $folderPostfix = GUICtrlRead($txtPostfixFolderProgressive) $folderSeparator = GuiCtrlRead($txtFolderProgressiveSeparator) $folderName = $aPathSplit[3] If GUICtrlRead($chkEnableFolderProgressive) = $GUI_CHECKED Then $topicName = $folderPrefix & $folderCounter & $folderPostfix & $folderSeparator & $folderName Else $topicName = $folderName EndIf If GUICtrlRead($chkAutoIncrementFolderProgressiveCounter) = $GUI_CHECKED Then $folderCounter = Int($folderCounter) + 1 GUICtrlSetData($txtCounterFolderProgressive, $folderCounter) EndIf $replaceText = GUICtrlRead($txtReplaceTextInTopicName) If $replaceText <> "" Then $topicName = StringReplace($topicName, $replaceText, "") $topicName = StringStripWS($topicName, 3) EndIf ;click on 3 dots MouseClick("left", 310, 50, 1, $actionsdelay) ;click on Create Topic MouseClick("left", 230, 85, 1, $actionsdelay) ;click on Create Topic MouseClick("left", 890, 360, 1, $actionsdelay) Send($TopicName, 1) ;click on Create Topic MouseClick("left", 1080, 755, 1, $actionsdelay) $filesList = _FileListToArray($folder, "*", 1) $fileListMessage = $topicName & @LF & "Files: " & _ArrayToString($filesList, @LF) WriteMessage($fileListMessage) If GUICtrlRead($chkRefocusFormAfterTopicCreation) = $GUI_CHECKED Then Sleep($actionsdelay_very_short) WinActivate($TgUpperForm) EndIf If GUICtrlRead($chkAutoLoadFilesAfterTopic) = $GUI_CHECKED Then ProcessFiles() EndIf ElaborateAllFolders() ; Call the new function EndFunc Func UploadFile($Path, $Filename) $chooseFilesWindowTitle = "Choose Files" ;click on clip icon to open file upload MouseClick("left", 355, 1010, 1, $actionsdelay_short) WinWait($chooseFilesWindowTitle) Sleep($actionsdelay) ;click on path textbox of upload file window ControlClick($chooseFilesWindowTitle, "", 1148) Sleep($actionsdelay_short) ;Inputs file path on the textbox Send($Path, 1) Sleep($actionsdelay_short) ;Click open to start uploading file on telegram ControlClick($chooseFilesWindowTitle, "", 1) ;Longer wait for telegram file upload window Sleep($actionsdelay) ;click on textbox for telegram file ;if Mp4 preview moves buttons down $extension = StringUpper(StringRight($Filename, 4)) If $extension = ".MP4" Then MouseClick("left", 865, 630, 1) ElseIf $extension = ".JPG" Or $extension = ".PNG" Or StringUpper(StringRight($Filename, 5)) = ".JPEG" Or StringUpper(StringRight($Filename, 5)) = ".JFIF" Then MouseClick("left", 865, 700, 1) Else MouseClick("left", 865, 560, 1) EndIf Sleep($actionsdelay_short) ;Write file name Send($Filename, 1) Sleep($actionsdelay_short) ;Clicks Send If $extension = ".mp4" Then MouseClick("left", 1100, 675, 1) ElseIf $extension = ".JPG" Or $extension = ".PNG" Or StringUpper(StringRight($Filename, 5)) = ".JPEG" Or StringUpper(StringRight($Filename, 5)) = ".JFIF" Then MouseClick("left", 1100, 745, 1) Sleep($actionsdelay_short) ;temp fix for smaller/different resolution images that move up the Send button ;Will be solved with pixelchecksum method While PixelGetColor(785,320) = 16777215 Sleep($actionsdelay_short) MouseClick("left",1100,720,1) WEnd Else MouseClick("left", 1100, 610, 1) EndIf EndFunc Func UpdateCurrentFolderDisplay() GUICtrlSetData($txtCurrentFolder, GetFolderName($folder)) EndFunc Func UpdateNextFolderDisplay() $nextFolder = GetNextFolderInAlphabeticalOrder($folder) GUICtrlSetData($txtNextFolder, GetFolderName($nextFolder)) EndFunc Func GetNextFolderInAlphabeticalOrder($currentFolder) Local $folderList = _FileListToArray($currentFolder & "\..", "*", 2) If @error Then Return "" EndIf Local $currentFolderName = GetFolderNameFromPath($currentFolder) Local $currentFolderIndex = _ArraySearch($folderList, $currentFolderName, 1) ; If folder is the last one then no next folder If $currentFolderIndex = UBound($folderList) - 1 Then Return "END-FOLDERS" EndIf Return _PathFull($currentFolder & "\..") & "\" & $folderList[$currentFolderIndex + 1] EndFunc Func SwapNextFolder() If $nextFolder = "" Or $nextFolder = "END-FOLDERS" Then MsgBox($MB_OK, "Info", "This was the last folder to process. No more folders to open.") Return EndIf $folder = $nextFolder $files = _FileListToArray($folder, "*", 1) If @error Then MsgBox($MB_OK, "Error", "No files found in the selected folder.") Return EndIf UpdateFileList($files) $lastButtonClicked = "SelectFolder" If GUICtrlRead($chkResetFileProgressiveCounterOnReopenFolderOrdFile) = $GUI_CHECKED Then ResetFileProgressiveCounter() EndIf UpdateCurrentFolderDisplay() UpdateNextFolderDisplay() UpdateSwapNextFolderButton() UpdateProcessFilesButton() SelectAll() EndFunc Func _chkNextFolderAutoSwap() If GUICtrlRead($chkNextFolderAutoSwap) = $GUI_CHECKED Then GUICtrlSetState($btnSwapNextFolder, $GUI_DISABLE) Else GUICtrlSetState($btnSwapNextFolder, $GUI_ENABLE) EndIf EndFunc Func _chkAutoLoadFilesAfterTopic() If GUICtrlRead($chkAutoLoadFilesAfterTopic) = $GUI_CHECKED Then GUICtrlSetState($btnProcessFiles, $GUI_DISABLE) Else GUICtrlSetState($btnProcessFiles, $GUI_ENABLE) EndIf EndFunc Func UpdateSwapNextFolderButton() If GUICtrlRead($chkNextFolderAutoSwap) = $GUI_CHECKED Then GUICtrlSetState($btnSwapNextFolder, $GUI_DISABLE) Else GUICtrlSetState($btnSwapNextFolder, $GUI_ENABLE) EndIf EndFunc Func UpdateProcessFilesButton() If GUICtrlRead($chkAutoLoadFilesAfterTopic) = $GUI_CHECKED Then GUICtrlSetState($btnProcessFiles, $GUI_DISABLE) Else GUICtrlSetState($btnProcessFiles, $GUI_ENABLE) EndIf EndFunc ;NOTE: @CRLF will result in telegram sending the message ;To write multiline message you got to use @LF and then manually send {ENTER} Func WriteMessage($message) Sleep($actionsdelay_short) MouseClick("left", 400, 1010, 1) Send($message, 1) Send("{ENTER}") EndFunc Func ElaborateAllFolders() If GUICtrlRead($chkElaborateAllFolders) = $GUI_CHECKED Then While True CreateTopic() ProcessFiles() If GUICtrlRead($txtNextFolder) = "END-FOLDERS" Then ExitLoop EndIf SwapNextFolder() WinActivate($TgUpperForm) WEnd EndIf EndFunc
    1 point
  6. So just for the heck of it: the full SciTE4AutoIt3 comes with a PersonalTools.lua in the %localappdata%\AutoIt v3\SciTE, so this is an example LUA function how you could update the version on each save, when it is found in the source file: -- Update version of line with this format: -- ;Version: 1.001 -- on each save function PersonalTools:OnBeforeSave(path) if editor.Lexer == SCLEX_AU3 and path ~= "" then local spos, epos = editor:findtext('^\\s*;Version:\\s*[\\d\\.]*', SCFIND_REGEXP, 0) if spos then local dline = editor:textrange(spos, epos) local curversion = dline:match('Version:%s*([%d%.]*)') newversion = curversion + 0.001 editor:SetSel(spos, epos) editor:ReplaceSel(";Version: " .. string.format("%.3f", newversion)) end end end Over to you to modify it to your wishes.
    1 point
×
×
  • Create New...