wolf9228 Posted February 5, 2011 Share Posted February 5, 2011 (edited) ThredLibrary A simple mistake in the type of data through File_Copy function mistake in this line $File_CopyHandle = DllCall($iDll,"DWORD","File_Copy","wstr",$SourceFile,"wstr", $DestFile,"wstr",$BytesNumberAtaTime,"DWORD",$iFlag) correctly Line $File_CopyHandle = DllCall($iDll,"DWORD","File_Copy","wstr",$SourceFile,"wstr", $DestFile,"DWORD",$BytesNumberAtaTime,"DWORD",$iFlag) And another mistake in the same function in ThredLibrary Code mistakes Has been modified New ScriptThredLibrary2.zip DownloaderMultiFiles.au3 expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #Include "GUICtrlSetOnEventEx.au3" $iDll = DllOpen("ThredLibrary.dll") Global $Array , $complete = 1 $controlID1 = DownloaderMultiFiles($Array,"http://www.swfmax.com/get/SWF.max.exe",@ScriptDir & "\Dir1\SWF.max.exe") GUICtrlSetOnEventEx($controlID1,$BN_CLICKED,"Clicked_Pause_Buttons") GUICtrlSetOnEventEx($controlID1 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID2 = DownloaderMultiFiles($Array,"http://download.winzip.com/winzip150.exe",@ScriptDir & "\Dir1\winzip150.exe") GUICtrlSetOnEventEx($controlID2,$BN_CLICKED,"Clicked_Pause_Buttons") GUICtrlSetOnEventEx($controlID2 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID3 = DownloaderMultiFiles($Array,"http://www.flash-swf-converter.com/downloads/swfconverter.exe","",2) GUICtrlSetOnEventEx($controlID3,$BN_CLICKED,"Clicked_Pause_Buttons") GUICtrlSetOnEventEx($controlID3 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID4 = DownloaderMultiFiles($Array,"http://www.win-rar.com/downloads/rar/wrar393.exe",@ScriptDir & "\Dir2\wrar393.exe") GUICtrlSetOnEventEx($controlID4,$BN_CLICKED,"Clicked_Pause_Buttons") GUICtrlSetOnEventEx($controlID4 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons") While 1 if ($complete = 1) Then $complete = ProgressLoop($Array) Else MsgBox(0,"","download is complete") Exit EndIf WEnd Func Clicked_Pause_Buttons($ControlID,$NotificationCode) $WPARAM = OnEventExGetWParam($ControlID,$NotificationCode) $LPARAM = OnEventExGetLParam($ControlID,$NotificationCode) $HWND = OnEventExGetHWND($ControlID,$NotificationCode) For $i = 0 To UBound($Array) - 1 if $ControlID = $Array[$i][5] Then ExitLoop Next $Array[$i][9] = Not $Array[$i][9] if ($Array[$i][9]) Then GUICtrlSetData($ControlID,"Reset") Else GUICtrlSetData($ControlID,"Pause") EndIf $DownlHandle = EnvGet($ControlID) PauseDownload($DownlHandle,$Array[$i][9]) EndFunc Func Clicked_Cancel_Buttons($ControlID,$NotificationCode) $WPARAM = OnEventExGetWParam($ControlID,$NotificationCode) $LPARAM = OnEventExGetLParam($ControlID,$NotificationCode) $HWND = OnEventExGetHWND($ControlID,$NotificationCode) $DownlHandle = EnvGet($ControlID) CancelDownload($DownlHandle) EndFunc Func ProgressLoop($Array) Dim $TempArray[1][10] $complete = 2 For $i = 0 To UBound($Array) - 1 $ProgressTime = $Array[$i][8] Sleep($ProgressTime) $InfoArray = DownloadGetInfo($Array[$i][7]) if Not @error Then if ($InfoArray[0]) Then _ $TotalReadTimes = $InfoArray[1] $NumberOfBytesRead = $InfoArray[2] $FileSize = $InfoArray[3] $IsComplete = $InfoArray[4] GUICtrlSetData($Array[$i][3],(100 / $FileSize) * $NumberOfBytesRead) GUICtrlSetData($Array[$i][4],"( " & StringLeft(int($NumberOfBytesRead / 1024) / 1024 ,12) _ & " OF " & StringLeft(int($FileSize /1024) / 1024 ,12) & " ) MB") If Not ($IsComplete) Then $complete = 1 $TempArray[UBound($TempArray) -1][0] = $Array[$i][0] $TempArray[UBound($TempArray) -1][1] = $Array[$i][1] $TempArray[UBound($TempArray) -1][2] = $Array[$i][2] $TempArray[UBound($TempArray) -1][3] = $Array[$i][3] $TempArray[UBound($TempArray) -1][4] = $Array[$i][4] $TempArray[UBound($TempArray) -1][5] = $Array[$i][5] $TempArray[UBound($TempArray) -1][6] = $Array[$i][6] $TempArray[UBound($TempArray) -1][7] = $Array[$i][7] $TempArray[UBound($TempArray) -1][8] = $Array[$i][8] $TempArray[UBound($TempArray) -1][9] = $Array[$i][9] ReDim $TempArray[UBound($TempArray) +1][10] Else GUICtrlSetBkColor($Array[$i][4] - 2, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetBkColor($Array[$i][4], $GUI_BKCOLOR_TRANSPARENT) EndIf EndIf Next if $complete = 2 Then GUIDelete($Array[0][0]) Else ReDim $TempArray[UBound($TempArray) - 1][10] $Array = $TempArray EndIf Return $complete EndFunc Func DownloaderMultiFiles(ByRef $Array,$link,$FileName,$iFlag = 1,$ProgressTime = 500) if Not IsArray($Array) Then Dim $Array[1][10] $Array[0][0] = GUICreate("Downloader Progress", 785, 140, 5, 200, _ BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW _ ,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS)) GUISetState(@SW_SHOW) Else ReDim $Array[UBound($Array) + 1][10] EndIf If $iFlag = 1 Then $OutDir = StringSplit($FileName,"\") if Not FileExists(StringTrimRight($FileName,StringLen($OutDir[$OutDir[0]]))) _ Then DirCreate(StringTrimRight($FileName,StringLen($OutDir[$OutDir[0]]))) $Array[UBound($Array) - 1][1] = $link $Array[UBound($Array) - 1][2] = $FileName GUICtrlCreateLabel(StringLeft($OutDir[$OutDir[0]],23), 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER)) Else $Array[UBound($Array) - 1][1] = $link GUICtrlCreateLabel("< [ Memory ] >", 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER)) EndIf GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Array[UBound($Array) - 1][3] = GUICtrlCreateProgress(190, 10 + ((UBound($Array) - 1) * 30), 200, 20) $Array[UBound($Array) - 1][4] = GUICtrlCreateLabel("", 400, 10 + ((UBound($Array) - 1) * 30), 250, 20,BitOR($SS_CENTER,$WS_BORDER)) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Array[UBound($Array) - 1][5] = GUICtrlCreateButton("Pause", 655, 10 + ((UBound($Array) - 1) * 30), 60,20) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") $Array[UBound($Array) - 1][6] = GUICtrlCreateButton("Cancel", 720, 10 + ((UBound($Array) - 1) * 30), 60,20) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") $Array[UBound($Array) - 1][7] = DownloadFile($Array[UBound($Array) - 1][1],$Array[UBound($Array) - 1][2],100,$iFlag) EnvSet($Array[UBound($Array) - 1][5],$Array[UBound($Array) - 1][7]) EnvSet($Array[UBound($Array) - 1][6],$Array[UBound($Array) - 1][7]) $Array[UBound($Array) - 1][8] = $ProgressTime Return $Array[UBound($Array) - 1][5] EndFunc Func DownloadFile($Url,$FilePath,$BytesNumberAtaTime = 1,$iFlag = 1,$MemSize = 0) ;$iFlag = 1 Download To File ($FilePath) ;$iFlag = 2 Download To Memory (Tag_Download_Info ==> hMemory) ;$MemSize Download Size From $Url To hMemory (Tag_Download_Info ==> hMemory) (can be set to 0) ;returned. The handle can be used with DownloadGetInfo And PauseDownload And CancelDownload $DownlHandle = DllCall($iDll,"DWORD","DownloadFile","wstr",$Url,"wstr",$FilePath,"DWORD", _ $BytesNumberAtaTime,"DWORD",$iFlag,"DWORD",$MemSize) if @error Then Return 0 Return $DownlHandle[0] EndFunc Func DownloadGetInfo($DownlHandle,$Element = 0) Dim $InfoArray[6] $Tag_Download_Info = _ "HANDLE hMemory;" & _ "DWORD TotalReadTimes;" & _ "DWORD NumberOfBytesRead;" & _ "DWORD FileSize;" & _ "DWORD IsComplete;" & _ "DWORD IsError" $Download_Info = DllStructCreate($Tag_Download_Info) $BOOL = DllCall($iDll,"bool","DownloadGetInfo","DWORD",$DownlHandle, _ "ptr",DllStructGetPtr($Download_Info)) if @error Then Return SetError(1,0,$InfoArray) if ($BOOL[0] = 0 ) Then Return SetError(2,0,$InfoArray) if ($Element) Then if ($Element < 1 Or $Element > 6) Then SetError(3,0,0) Return SetError(0,0,DllStructGetData($Download_Info,$Element)) EndIf $InfoArray[0] = DllStructGetData($Download_Info,1) $InfoArray[1] = DllStructGetData($Download_Info,2) $InfoArray[2] = DllStructGetData($Download_Info,3) $InfoArray[3] = DllStructGetData($Download_Info,4) $InfoArray[4] = DllStructGetData($Download_Info,5) $InfoArray[5] = DllStructGetData($Download_Info,6) Return SetError(0,0,$InfoArray) EndFunc Func PauseDownload($DownlHandle,$BoolPause = 1) $BOOL = DllCall($iDll,"BOOL","PauseDownload","DWORD",$DownlHandle,"BOOL",$BoolPause) if @error Then Return SetError(1,0,0) Return SetError($BOOL[0] == 0,0,$BOOL[0]) EndFunc Func CancelDownload($DownlHandle) $BOOL = DllCall($iDll,"BOOL","CancelDownload","DWORD",$DownlHandle) if @error Then Return SetError(1,0,0) Return SetError($BOOL[0] == 0,0,$BOOL[0]) EndFunc FtpGetMultiFiles.au3 expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #Include "GUICtrlSetOnEventEx.au3" $iDll = DllOpen("ThredLibrary.dll") $jDll = DllOpen("Wininet.dll") Dim $Array , $complete = 1 $iConnect = InternetConnect("ServerName","Username","Password") if Not ($iConnect) Then Exit ;Only one file can be open in a single FTP session. Therefore, no file handle is returned ;and the application simply uses the FTP session handle when necessary. $jConnect = InternetConnect("ServerName","Username","Password") if Not ($jConnect) Then Exit $controlID1 = FtpGetMultiFiles($Array,$iConnect _ ,"CurrentDir/Text/Dir1/Text1.txt", _ ;$RemoteFile @ScriptDir & "\Dir4\Text1.txt", _ ; $LocalFile "",1) ;$CurrentDir = "" , ($iFlag = 1 ==> File) GUICtrlSetOnEventEx($controlID1,$BN_CLICKED,"Clicked_Pause_Buttons") GUICtrlSetOnEventEx($controlID1 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID2 = FtpGetMultiFiles($Array,$jConnect, _ "Dir2/Text2.txt", _ ; $RemoteFile "", _ ;$LocalFile = "" "CurrentDir/Text",2) ;$CurrentDir = "CurrentDir/Text" , ($iFlag = 2 ==> Memory) GUICtrlSetOnEventEx($controlID2,$BN_CLICKED,"Clicked_Pause_Buttons") GUICtrlSetOnEventEx($controlID2 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons") While 1 if ($complete = 1) Then $complete = ProgressLoop($Array) Else MsgBox(0,"","FtpGet is complete") Exit EndIf WEnd Func Clicked_Pause_Buttons($ControlID,$NotificationCode) $WPARAM = OnEventExGetWParam($ControlID,$NotificationCode) $LPARAM = OnEventExGetLParam($ControlID,$NotificationCode) $HWND = OnEventExGetHWND($ControlID,$NotificationCode) For $i = 0 To UBound($Array) - 1 if $ControlID = $Array[$i][5] Then ExitLoop Next $Array[$i][9] = Not $Array[$i][9] if ($Array[$i][9]) Then GUICtrlSetData($ControlID,"Reset") Else GUICtrlSetData($ControlID,"Pause") EndIf $FtpGetHandle = EnvGet($ControlID) PauseFtpGet($FtpGetHandle,$Array[$i][9]) EndFunc Func Clicked_Cancel_Buttons($ControlID,$NotificationCode) $WPARAM = OnEventExGetWParam($ControlID,$NotificationCode) $LPARAM = OnEventExGetLParam($ControlID,$NotificationCode) $HWND = OnEventExGetHWND($ControlID,$NotificationCode) $FtpGetHandle = EnvGet($ControlID) CancelFtpGet($FtpGetHandle) EndFunc Func ProgressLoop($Array) Dim $TempArray[1][10] $complete = 2 For $i = 0 To UBound($Array) - 1 $ProgressTime = $Array[$i][8] Sleep($ProgressTime) $InfoArray = FtpGetFileInfo($Array[$i][7]) if Not @error Then $TotalReadTimes = $InfoArray[1] $NumberOfBytesRead = $InfoArray[2] $FileSize = $InfoArray[3] $IsComplete = $InfoArray[4] GUICtrlSetData($Array[$i][3],(100 / $FileSize) * $NumberOfBytesRead) GUICtrlSetData($Array[$i][4],"( " & StringLeft(int($NumberOfBytesRead / 1024) / 1024 ,12) _ & " OF " & StringLeft(int($FileSize /1024) / 1024 ,12) & " ) MB") If Not ($IsComplete) Then $complete = 1 $TempArray[UBound($TempArray) -1][0] = $Array[$i][0] $TempArray[UBound($TempArray) -1][1] = $Array[$i][1] $TempArray[UBound($TempArray) -1][2] = $Array[$i][2] $TempArray[UBound($TempArray) -1][3] = $Array[$i][3] $TempArray[UBound($TempArray) -1][4] = $Array[$i][4] $TempArray[UBound($TempArray) -1][5] = $Array[$i][5] $TempArray[UBound($TempArray) -1][6] = $Array[$i][6] $TempArray[UBound($TempArray) -1][7] = $Array[$i][7] $TempArray[UBound($TempArray) -1][9] = $Array[$i][9] ReDim $TempArray[UBound($TempArray) +1][10] Else GUICtrlSetBkColor($Array[$i][4] - 2, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetBkColor($Array[$i][4], $GUI_BKCOLOR_TRANSPARENT) EndIf EndIf Next if $complete = 2 Then GUIDelete($Array[0][0]) Else ReDim $TempArray[UBound($TempArray) - 1][10] $Array = $TempArray EndIf Return $complete EndFunc Func FtpGetMultiFiles(ByRef $Array,$iConnect,$RemoteFile,$LocalFile,$CurrentDir = "", _ $iFlag = 1,$ProgressTime = 500) if Not IsArray($Array) Then Dim $Array[1][10] $Array[0][0] = GUICreate("FtpGet Progress", 785, 140, 5, 200, _ BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW _ ,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS)) GUISetState(@SW_SHOW) Else ReDim $Array[UBound($Array) + 1][10] EndIf if $iFlag = 1 Then $OutDir = StringSplit($LocalFile,"\") if Not FileExists(StringTrimRight($LocalFile,StringLen($OutDir[$OutDir[0]]))) _ Then DirCreate(StringTrimRight($LocalFile,StringLen($OutDir[$OutDir[0]]))) $Array[UBound($Array) - 1][1] = $RemoteFile $Array[UBound($Array) - 1][2] = $LocalFile GUICtrlCreateLabel(StringLeft($OutDir[$OutDir[0]],23), 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER)) Else $Array[UBound($Array) - 1][1] = $RemoteFile GUICtrlCreateLabel("< [ Memory ] >", 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER)) EndIf GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Array[UBound($Array) - 1][3] = GUICtrlCreateProgress(190, 10 + ((UBound($Array) - 1) * 30), 200, 20) $Array[UBound($Array) - 1][4] = GUICtrlCreateLabel("", 400, 10 + ((UBound($Array) - 1) * 30), 250, 20,BitOR($SS_CENTER,$WS_BORDER)) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Array[UBound($Array) - 1][5] = GUICtrlCreateButton("Pause", 655, 10 + ((UBound($Array) - 1) * 30), 60,20) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") $Array[UBound($Array) - 1][6] = GUICtrlCreateButton("Cancel", 720, 10 + ((UBound($Array) - 1) * 30), 60,20) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") $Array[UBound($Array) - 1][7] = FtpMemGetFile($iConnect,$Array[UBound($Array) - 1][1],$Array[UBound($Array) - 1][2],$CurrentDir,1,$iFlag) EnvSet($Array[UBound($Array) - 1][5],$Array[UBound($Array) - 1][7]) EnvSet($Array[UBound($Array) - 1][6],$Array[UBound($Array) - 1][7]) $Array[UBound($Array) - 1][8] = $ProgressTime Return $Array[UBound($Array) - 1][5] EndFunc Func FtpMemGetFile($iConnect,$RemoteFile,$LocalFile,$CurrentDir = "", _ $BytesNumberAtaTime = 1,$iFlag = 1,$MemSize = 0) ;$iFlag = 1 FtpGet To File ($LocalFile) ;$iFlag = 2 FtpGet To Memory (Tag_Download_Info ==> hMemory) ;$MemSize FtpGet Size From $RemoteFile To hMemory ($Tag_GetFile_Info ==> hMemory) (can be set to 0) ;returned. The handle can be used with FtpGetFileInfo And PauseFtpGet And CancelFtpGet $FtpGetHandle = DllCall($iDll,"DWORD","FtpMemGetFile","HANDLE",$iConnect,"wstr",$RemoteFile,"wstr", _ $LocalFile,"wstr",$CurrentDir,"DWORD",$BytesNumberAtaTime,"DWORD",$iFlag,"DWORD",$MemSize) if @error Then Return 0 Return $FtpGetHandle[0] EndFunc Func FtpGetFileInfo($FtpGetHandle,$Element = 0) Dim $InfoArray[6] $Tag_GetFile_Info = _ "HANDLE hMemory;" & _ "DWORD TotalReadTimes;" & _ "DWORD NumberOfBytesRead;" & _ "DWORD FileSize;" & _ "DWORD IsComplete;" & _ "DWORD IsError" $GetFile_Info = DllStructCreate($Tag_GetFile_Info) $BOOL = DllCall($iDll,"bool","FtpGetFileInfo","DWORD",$FtpGetHandle, _ "ptr",DllStructGetPtr($GetFile_Info)) if @error Then Return SetError(1,0,$InfoArray) if ($BOOL[0] = 0 ) Then Return SetError(2,0,$InfoArray) if ($Element) Then if ($Element < 1 Or $Element > 6) Then SetError(3,0,0) Return SetError(0,0,DllStructGetData($GetFile_Info,$Element)) EndIf $InfoArray[0] = DllStructGetData($GetFile_Info,1) $InfoArray[1] = DllStructGetData($GetFile_Info,2) $InfoArray[2] = DllStructGetData($GetFile_Info,3) $InfoArray[3] = DllStructGetData($GetFile_Info,4) $InfoArray[4] = DllStructGetData($GetFile_Info,5) $InfoArray[5] = DllStructGetData($GetFile_Info,6) Return SetError(0,0,$InfoArray) EndFunc Func PauseFtpGet($FtpGetHandle,$BoolPause = 1) $BOOL = DllCall($iDll,"BOOL","PauseFtpGet","DWORD",$FtpGetHandle,"BOOL",$BoolPause) if @error Then Return SetError(1,0,0) Return SetError($BOOL[0] == 0,0,$BOOL[0]) EndFunc Func CancelFtpGet($FtpGetHandle) $BOOL = DllCall($iDll,"BOOL","CancelFtpGet","DWORD",$FtpGetHandle) if @error Then Return SetError(1,0,0) Return SetError($BOOL[0] == 0,0,$BOOL[0]) EndFunc Func InternetOpen($lpszAgent,$dwAccessType = 0,$lpszProxyName = "",$lpszProxyBypass = "",$dwFlags = 0) $HINTERNET = DllCall($jDll,"HANDLE","InternetOpen","str",$lpszAgent,"DWORD",$dwAccessType, _ "str",$lpszProxyName,"str",$lpszProxyBypass,"DWORD",$dwFlags) if @error Then Return SetError(1,0,0) if Not ($HINTERNET[0]) Then Return SetError(2,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc Func InternetConnect($lpszServerName,$lpszUsername,$lpszPassword,$nServerPort = 0 _ ,$dwService = 1,$dwFlags = 0,$dwContext = 0) $hInternet = InternetOpen("Open") $HINTERNET = DllCall($jDll,"HANDLE","InternetConnectA","HANDLE",$hInternet,"str",$lpszServerName , _ "int",$nServerPort,"str",$lpszUsername,"str",$lpszPassword,"DWORD",$dwService,"DWORD",$dwFlags , _ "ptr",$dwContext) if @error Then Return SetError(1,0,0) if Not ($HINTERNET[0]) Then Return SetError(2,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc FtpPutMultiFiles.au3 expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #Include <Memory.au3> #Include <GuiButton.au3> #Include "GUICtrlSetOnEventEx.au3" $iDll = DllOpen("ThredLibrary.dll") $jDll = DllOpen("Wininet.dll") Dim $Array , $complete = 1 $Text = _ "AutoIt v3 is a freeware BASIC-like scripting language designed for" & @CRLF & _ "automating the Windows GUI and general scripting. It uses a combination" & @CRLF & _ "of simulated keystrokes, mouse movement and window/control" & @CRLF & _ "manipulation in order to automate tasks in a way not possible or reliable" & @CRLF & _ "with other languages (e.g. VBScript and SendKeys). AutoIt is also very" & @CRLF & _ "small, self-contained and will run on all versions of Windows out-of-the-" & @CRLF & _ "box with no annoying 'runtimes' required!" & @CRLF & _ "" & @CRLF & _ "AutoIt was initially designed for PC 'roll out' situations to reliably automate" & @CRLF & _ "and configure thousands of PCs. Over time it has become a powerful" & @CRLF & _ "language that supports complex expressions, user functions, loops and" & @CRLF & _ "everything else that veteran scripters would expect." & @CRLF & @CRLF $iConnect = InternetConnect("ServerName","Username","Password") if Not ($iConnect) Then Exit ;Only one file can be open in a single FTP session. Therefore, no file handle is returned ;and the application simply uses the FTP session handle when necessary. $jConnect = InternetConnect("ServerName","Username","Password") if Not ($jConnect) Then Exit For $i = 1 To 11 $Text &= $Text Next DirCreate(@ScriptDir & "\Dir1") DirCreate(@ScriptDir & "\Dir2") $FO1 = FileOpen(@ScriptDir & "\Dir1\Text1.txt",2) $FO2 = FileOpen(@ScriptDir & "\Dir2\Text2.txt",2) FileWrite($FO1,$Text) FileWrite($FO2,$Text) FileClose($FO1) FileClose($FO2) $controlID1 = FtpPutMultiFiles($Array,$iConnect, _ "CurrentDir/Text/Dir1/Text1.txt", _ ; $RemoteFile @ScriptDir & "\Dir1\Text1.txt", _ ;$LocalFile "",1,1) ; CurrentDir = "" , $CreateDir = 1 , ($iFlag = 1 ==> File) GUICtrlSetOnEventEx($controlID1,$BN_CLICKED,"Clicked_Pause_Buttons") GUICtrlSetOnEventEx($controlID1 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons") $hMemory = FileToGlobalAlloc(@ScriptDir & "\Dir2\Text2.txt") ;Mem File $controlID2 = FtpPutMultiFiles($Array,$jConnect, _ "Dir2/Text2.txt", _ ; $RemoteFile "", _ ;$LocalFile = "" "CurrentDir/Text", _ ;CurrentDir = "CurrentDir/Text" 1,2, _ ;$CreateDir = 1 , ($iFlag = 2 ==> Memory) $hMemory) ; $hMemory = $hMemory GUICtrlSetOnEventEx($controlID2,$BN_CLICKED,"Clicked_Pause_Buttons") GUICtrlSetOnEventEx($controlID2 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons") While 1 if ($complete = 1) Then $complete = ProgressLoop($Array) Else MsgBox(0,"","FtpPut is complete") Exit EndIf WEnd Func Clicked_Pause_Buttons($ControlID,$NotificationCode) $WPARAM = OnEventExGetWParam($ControlID,$NotificationCode) $LPARAM = OnEventExGetLParam($ControlID,$NotificationCode) $HWND = OnEventExGetHWND($ControlID,$NotificationCode) For $i = 0 To UBound($Array) - 1 if $ControlID = $Array[$i][5] Then ExitLoop Next $Array[$i][9] = Not $Array[$i][9] if ($Array[$i][9]) Then GUICtrlSetData($ControlID,"Reset") Else GUICtrlSetData($ControlID,"Pause") EndIf $FtpPutHandle = EnvGet($ControlID) PauseFtpPut($FtpPutHandle,$Array[$i][9]) EndFunc Func Clicked_Cancel_Buttons($ControlID,$NotificationCode) $WPARAM = OnEventExGetWParam($ControlID,$NotificationCode) $LPARAM = OnEventExGetLParam($ControlID,$NotificationCode) $HWND = OnEventExGetHWND($ControlID,$NotificationCode) $FtpPutHandle = EnvGet($ControlID) CancelFtpPut($FtpPutHandle) EndFunc Func ProgressLoop($Array) Dim $TempArray[1][10] $complete = 2 For $i = 0 To UBound($Array) - 1 $ProgressTime = $Array[$i][8] Sleep($ProgressTime) $InfoArray = FtpPutFileInfo($Array[$i][7]) if Not @error Then $TotalReadTimes = $InfoArray[0] $NumberOfBytesRead = $InfoArray[1] $FileSize = $InfoArray[2] $IsComplete = $InfoArray[3] GUICtrlSetData($Array[$i][3],(100 / $FileSize) * $NumberOfBytesRead) GUICtrlSetData($Array[$i][4],"( " & StringLeft(int($NumberOfBytesRead / 1024) / 1024 ,12) _ & " OF " & StringLeft(int($FileSize /1024) / 1024 ,12) & " ) MB") Sleep(500) If Not ($IsComplete) Then $complete = 1 $TempArray[UBound($TempArray) -1][0] = $Array[$i][0] $TempArray[UBound($TempArray) -1][1] = $Array[$i][1] $TempArray[UBound($TempArray) -1][2] = $Array[$i][2] $TempArray[UBound($TempArray) -1][3] = $Array[$i][3] $TempArray[UBound($TempArray) -1][4] = $Array[$i][4] $TempArray[UBound($TempArray) -1][5] = $Array[$i][5] $TempArray[UBound($TempArray) -1][6] = $Array[$i][6] $TempArray[UBound($TempArray) -1][7] = $Array[$i][7] ReDim $TempArray[UBound($TempArray) +1][10] Else GUICtrlSetBkColor($Array[$i][4] - 2, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetBkColor($Array[$i][4], $GUI_BKCOLOR_TRANSPARENT) EndIf EndIf Next if $complete = 2 Then GUIDelete($Array[0][0]) Else ReDim $TempArray[UBound($TempArray) - 1][10] $Array = $TempArray EndIf Return $complete EndFunc Func FtpPutMultiFiles(ByRef $Array,$iConnect,$RemoteFile,$LocalFile,$CurrentDir = "", _ $CreateDir = 0,$iFlag = 1,$hMemory = 0,$ProgressTime = 500) if Not IsArray($Array) Then Dim $Array[1][10] $Array[0][0] = GUICreate("FtpPut Progress", 785, 140, 5, 200, _ BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW _ ,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS)) GUISetState(@SW_SHOW) Else ReDim $Array[UBound($Array) + 1][10] EndIf if $iFlag = 1 Then $OutDir = StringSplit($LocalFile,"\") if Not FileExists(StringTrimRight($LocalFile,StringLen($OutDir[$OutDir[0]]))) _ Then DirCreate(StringTrimRight($LocalFile,StringLen($OutDir[$OutDir[0]]))) $Array[UBound($Array) - 1][1] = $RemoteFile $Array[UBound($Array) - 1][2] = $LocalFile GUICtrlCreateLabel(StringLeft($OutDir[$OutDir[0]],23), 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER)) Else $Array[UBound($Array) - 1][1] = $RemoteFile GUICtrlCreateLabel("< [ Memory ] >", 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER)) EndIf GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Array[UBound($Array) - 1][3] = GUICtrlCreateProgress(190, 10 + ((UBound($Array) - 1) * 30), 200, 20) $Array[UBound($Array) - 1][4] = GUICtrlCreateLabel("", 400, 10 + ((UBound($Array) - 1) * 30), 250, 20,BitOR($SS_CENTER,$WS_BORDER)) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Array[UBound($Array) - 1][5] = GUICtrlCreateButton("Pause", 655, 10 + ((UBound($Array) - 1) * 30), 60,20) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") $Array[UBound($Array) - 1][6] = GUICtrlCreateButton("Cancel", 720, 10 + ((UBound($Array) - 1) * 30), 60,20) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") $Array[UBound($Array) - 1][7] = FtpMemPutFile($iConnect,$Array[UBound($Array) - 1][1],$Array[UBound($Array) - 1][2],$CurrentDir,$CreateDir,1,$iFlag,$hMemory) EnvSet($Array[UBound($Array) - 1][5],$Array[UBound($Array) - 1][7]) EnvSet($Array[UBound($Array) - 1][6],$Array[UBound($Array) - 1][7]) $Array[UBound($Array) - 1][8] = $ProgressTime Return $Array[UBound($Array) - 1][5] EndFunc Func FtpMemPutFile($iConnect,$RemoteFile,$LocalFile,$CurrentDir = "",$CreateDir = 0 , _ $BytesNumberAtaTime = 1 ,$iFlag = 1,$hMemory = 0) ;$iFlag = 1 FtpPut From File ($LocalFile) ;$iFlag = 2 FtpPut From Memory ($hMemory) ;returned. The handle can be used with FtpPutFileInfo And PauseFtpPut And CancelFtpPut $FtpPutHandle = DllCall($iDll,"DWORD","FtpMemPutFile","HANDLE",$iConnect,"wstr", _ $RemoteFile,"wstr",$LocalFile,"wstr",$CurrentDir,"DWORD",$CreateDir,"DWORD", _ $BytesNumberAtaTime,"DWORD",$iFlag,"ptr",$hMemory) if @error Then Return 0 Return $FtpPutHandle[0] EndFunc Func FtpPutFileInfo($FtpPutHandle,$Element = 0) Dim $InfoArray[5] $Tag_PutFile_Info = _ "DWORD TotalReadTimes;" & _ "DWORD NumberOfBytesWrite;" & _ "DWORD FileSize;" & _ "DWORD IsComplete;" & _ "DWORD IsError" $PutFile_Info = DllStructCreate($Tag_PutFile_Info) $BOOL = DllCall($iDll,"bool","FtpPutFileInfo","DWORD",$FtpPutHandle, _ "ptr",DllStructGetPtr($PutFile_Info)) if @error Then Return SetError(1,0,$InfoArray) if ($BOOL[0] = 0 ) Then Return SetError(2,0,$InfoArray) if ($Element) Then if ($Element < 1 Or $Element > 5) Then SetError(3,0,0) Return SetError(0,0,DllStructGetData($PutFile_Info,$Element)) EndIf $InfoArray[0] = DllStructGetData($PutFile_Info,1) $InfoArray[1] = DllStructGetData($PutFile_Info,2) $InfoArray[2] = DllStructGetData($PutFile_Info,3) $InfoArray[3] = DllStructGetData($PutFile_Info,4) $InfoArray[4] = DllStructGetData($PutFile_Info,5) Return SetError(0,0,$InfoArray) EndFunc Func PauseFtpPut($FtpPutHandle,$BoolPause = 1) $BOOL = DllCall($iDll,"BOOL","PauseFtpPut","DWORD",$FtpPutHandle,"BOOL",$BoolPause) if @error Then Return SetError(1,0,0) Return SetError($BOOL[0] == 0,0,$BOOL[0]) EndFunc Func CancelFtpPut($FtpPutHandle) $BOOL = DllCall($iDll,"BOOL","CancelFtpPut","DWORD",$FtpPutHandle) if @error Then Return SetError(1,0,0) Return SetError($BOOL[0] == 0,0,$BOOL[0]) EndFunc Func FileToGlobalAlloc($LocalFile) Local $nBytes $Size = FileGetSize($LocalFile) $hMemory = _MemGlobalAlloc($Size,$GPTR) $hFile = _WinAPI_CreateFile($LocalFile, 2, 2) if Not ($hFile) Then Return 0 _WinAPI_ReadFile($hFile,_MemGlobalLock($hMemory),$Size,$nBytes) _WinAPI_CloseHandle($hFile) Return $hMemory EndFunc Func InternetOpen($lpszAgent,$dwAccessType = 0,$lpszProxyName = "",$lpszProxyBypass = "",$dwFlags = 0) $HINTERNET = DllCall($jDll,"HANDLE","InternetOpenW","wstr",$lpszAgent,"DWORD",$dwAccessType, _ "wstr",$lpszProxyName,"wstr",$lpszProxyBypass,"DWORD",$dwFlags) if @error Then Return SetError(1,0,0) if Not ($HINTERNET[0]) Then Return SetError(2,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc Func InternetConnect($lpszServerName,$lpszUsername,$lpszPassword,$nServerPort = 0 _ ,$dwService = 1,$dwFlags = 0x08000000,$dwContext = 0) ;INTERNET_FLAG_PASSIVE 0x08000000 $hInternet = InternetOpen("Open") $HINTERNET = DllCall($jDll,"HANDLE","InternetConnectW","HANDLE",$hInternet,"wstr",$lpszServerName , _ "int",$nServerPort,"wstr",$lpszUsername,"wstr",$lpszPassword,"DWORD",$dwService,"DWORD",$dwFlags , _ "ptr",$dwContext) if @error Then Return SetError(1,0,0) if Not ($HINTERNET[0]) Then Return SetError(2,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc CopyMultiFiles.au3 expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #Include <Memory.au3> #Include <GuiButton.au3> #Include "GUICtrlSetOnEventEx.au3" $iDll = DllOpen("ThredLibrary.dll") Dim $Array , $complete = 1 $Text = _ "AutoIt v3 is a freeware BASIC-like scripting language designed for" & @CRLF & _ "automating the Windows GUI and general scripting. It uses a combination" & @CRLF & _ "of simulated keystrokes, mouse movement and window/control" & @CRLF & _ "manipulation in order to automate tasks in a way not possible or reliable" & @CRLF & _ "with other languages (e.g. VBScript and SendKeys). AutoIt is also very" & @CRLF & _ "small, self-contained and will run on all versions of Windows out-of-the-" & @CRLF & _ "box with no annoying 'runtimes' required!" & @CRLF & _ "" & @CRLF & _ "AutoIt was initially designed for PC 'roll out' situations to reliably automate" & @CRLF & _ "and configure thousands of PCs. Over time it has become a powerful" & @CRLF & _ "language that supports complex expressions, user functions, loops and" & @CRLF & _ "everything else that veteran scripters would expect." & @CRLF & @CRLF For $i = 0 To 12 $Text &= $Text Next Dim $nBytes DirCreate(@ScriptDir & "\SourceFile") $Size = StringLen($Text) $Buffer = DllStructCreate("char[" & $Size & "]") $hFile = _WinAPI_CreateFile(@ScriptDir & "\SourceFile\SourceFile.txt", 1) For $i = 1 To 10 _WinAPI_WriteFile($hFile,DllStructGetPtr($Buffer),$Size,$nBytes) Next _WinAPI_CloseHandle($hFile) $controlID1 = CopyMultiFiles($Array, _ @ScriptDir & "\SourceFile\SourceFile.txt", _ ; $SourceFile @ScriptDir & "\DestDir\DestFile1\DestFile1.txt" , _ ;$DestFile 9) ; $iFlag = 9 (1 + 8) GUICtrlSetOnEventEx($controlID1,$BN_CLICKED,"Clicked_Pause_Buttons") GUICtrlSetOnEventEx($controlID1 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID2 = CopyMultiFiles($Array, _ @ScriptDir & "\SourceFile\SourceFile.txt", _ ; $SourceFile @ScriptDir & "\DestDir\DestFile2\DestFile2.txt" , _ ;$DestFile 9) ; $iFlag = 9 (1 + 8) GUICtrlSetOnEventEx($controlID2,$BN_CLICKED,"Clicked_Pause_Buttons") GUICtrlSetOnEventEx($controlID2 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons") While 1 if ($complete = 1) Then $complete = ProgressLoop($Array) Else MsgBox(0,"","File_Copy is complete") Exit EndIf WEnd Func Clicked_Pause_Buttons($ControlID,$NotificationCode) $WPARAM = OnEventExGetWParam($ControlID,$NotificationCode) $LPARAM = OnEventExGetLParam($ControlID,$NotificationCode) $HWND = OnEventExGetHWND($ControlID,$NotificationCode) For $i = 0 To UBound($Array) - 1 if $ControlID = $Array[$i][5] Then ExitLoop Next $Array[$i][9] = Not $Array[$i][9] if ($Array[$i][9]) Then GUICtrlSetData($ControlID,"Reset") Else GUICtrlSetData($ControlID,"Pause") EndIf $File_CopyHandle = EnvGet($ControlID) PauseCopyFile($File_CopyHandle,$Array[$i][9]) EndFunc Func Clicked_Cancel_Buttons($ControlID,$NotificationCode) $WPARAM = OnEventExGetWParam($ControlID,$NotificationCode) $LPARAM = OnEventExGetLParam($ControlID,$NotificationCode) $HWND = OnEventExGetHWND($ControlID,$NotificationCode) $File_CopyHandle = EnvGet($ControlID) CancelCopyFile($File_CopyHandle) EndFunc Func ProgressLoop($Array) Dim $TempArray[1][10] $complete = 2 For $i = 0 To UBound($Array) - 1 $ProgressTime = $Array[$i][8] Sleep($ProgressTime) $InfoArray = File_CopyGetInfo($Array[$i][7]) if Not @error Then $TotalCopyTimes = $InfoArray[0] $NumberOfBytesCopy = $InfoArray[1] $FileSize = $InfoArray[2] $IsComplete = $InfoArray[3] GUICtrlSetData($Array[$i][3],(100 / $FileSize) * $NumberOfBytesCopy) GUICtrlSetData($Array[$i][4],"( " & StringLeft(int($NumberOfBytesCopy / 1024) / 1024 ,12) _ & " OF " & StringLeft(int($FileSize /1024) / 1024 ,12) & " ) MB") Sleep(500) If Not ($IsComplete) Then $complete = 1 $TempArray[UBound($TempArray) -1][0] = $Array[$i][0] $TempArray[UBound($TempArray) -1][1] = $Array[$i][1] $TempArray[UBound($TempArray) -1][2] = $Array[$i][2] $TempArray[UBound($TempArray) -1][3] = $Array[$i][3] $TempArray[UBound($TempArray) -1][4] = $Array[$i][4] $TempArray[UBound($TempArray) -1][5] = $Array[$i][5] $TempArray[UBound($TempArray) -1][6] = $Array[$i][6] $TempArray[UBound($TempArray) -1][7] = $Array[$i][7] ReDim $TempArray[UBound($TempArray) +1][10] Else GUICtrlSetBkColor($Array[$i][4] - 2, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetBkColor($Array[$i][4], $GUI_BKCOLOR_TRANSPARENT) EndIf EndIf Next if $complete = 2 Then GUIDelete($Array[0][0]) Else ReDim $TempArray[UBound($TempArray) - 1][10] $Array = $TempArray EndIf Return $complete EndFunc Func CopyMultiFiles(ByRef $Array,$SourceFile,$DestFile,$iFlag = 1,$ProgressTime = 100) if Not IsArray($Array) Then Dim $Array[1][10] $Array[0][0] = GUICreate("File_Copy Progress", 785, 140, 5, 200, _ BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW _ ,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS)) GUISetState(@SW_SHOW) Else ReDim $Array[UBound($Array) + 1][10] EndIf $FileName = StringSplit($SourceFile,"\") $Array[UBound($Array) - 1][1] = $SourceFile $Array[UBound($Array) - 1][2] = $DestFile GUICtrlCreateLabel(StringLeft($FileName[$FileName[0]],23), 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER)) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Array[UBound($Array) - 1][3] = GUICtrlCreateProgress(190, 10 + ((UBound($Array) - 1) * 30), 200, 20) $Array[UBound($Array) - 1][4] = GUICtrlCreateLabel("", 400, 10 + ((UBound($Array) - 1) * 30), 250, 20,BitOR($SS_CENTER,$WS_BORDER)) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Array[UBound($Array) - 1][5] = GUICtrlCreateButton("Pause", 655, 10 + ((UBound($Array) - 1) * 30), 60,20) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") $Array[UBound($Array) - 1][6] = GUICtrlCreateButton("Cancel", 720, 10 + ((UBound($Array) - 1) * 30), 60,20) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") $Array[UBound($Array) - 1][7] = File_Copy($Array[UBound($Array) - 1][1],$Array[UBound($Array) - 1][2],100,$iFlag) EnvSet($Array[UBound($Array) - 1][5],$Array[UBound($Array) - 1][7]) EnvSet($Array[UBound($Array) - 1][6],$Array[UBound($Array) - 1][7]) $Array[UBound($Array) - 1][8] = $ProgressTime Return $Array[UBound($Array) - 1][5] EndFunc Func File_Copy($SourceFile,$DestFile,$BytesNumberAtaTime = 1,$iFlag = 1) ;$iFlag = 0 do not overwrite existing files ;$iFlag = 1 overwrite existing files ;$iFlag = 8 Create destination directory structure if it doesn't exist ;returned. The handle can be used with File_CopyGetInfo And PauseCopyFile And CancelCopyFile $File_CopyHandle = DllCall($iDll,"DWORD","File_Copy","wstr",$SourceFile,"wstr", _ $DestFile,"DWORD",$BytesNumberAtaTime,"DWORD",$iFlag) if @error Then Return 0 Return $File_CopyHandle[0] EndFunc Func File_CopyGetInfo($File_CopyHandle,$Element = 0) Dim $InfoArray[5] $Tag_File_Copy_Info = _ "DWORD TotalCopyTimes;" & _ "DWORD NumberOfBytesCopy;" & _ "DWORD FileSize;" & _ "DWORD IsComplete;" & _ "DWORD IsError" $File_Copy_Info = DllStructCreate($Tag_File_Copy_Info) $BOOL = DllCall($iDll,"bool","File_CopyGetInfo","DWORD",$File_CopyHandle, _ "ptr",DllStructGetPtr($File_Copy_Info)) if @error Then Return SetError(1,0,$InfoArray) if ($BOOL[0] = 0 ) Then Return SetError(2,0,$InfoArray) if ($Element) Then if ($Element < 1 Or $Element > 5) Then SetError(3,0,0) Return SetError(0,0,DllStructGetData($File_Copy_Info,$Element)) EndIf $InfoArray[0] = DllStructGetData($File_Copy_Info,1) $InfoArray[1] = DllStructGetData($File_Copy_Info,2) $InfoArray[2] = DllStructGetData($File_Copy_Info,3) $InfoArray[3] = DllStructGetData($File_Copy_Info,4) $InfoArray[4] = DllStructGetData($File_Copy_Info,5) Return SetError(0,0,$InfoArray) EndFunc Func PauseCopyFile($File_CopyHandle,$BoolPause = 1) $BOOL = DllCall($iDll,"BOOL","PauseCopyFile","DWORD",$File_CopyHandle,"BOOL",$BoolPause) if @error Then Return SetError(1,0,0) Return SetError($BOOL[0] == 0,0,$BOOL[0]) EndFunc Func CancelCopyFile($File_CopyHandle) $BOOL = DllCall($iDll,"BOOL","CancelCopyFile","DWORD",$File_CopyHandle) if @error Then Return SetError(1,0,0) Return SetError($BOOL[0] == 0,0,$BOOL[0]) EndFunc FastSaveImage.au3 expandcollapse popup#include <WindowsConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <StructureConstants.au3> #include <GUIConstantsEx.au3> #include <StructureConstants.au3> #include <Constants.au3> $iDll = DllOpen("ThredLibrary.dll") $complete = 0 DirCreate(@ScriptDir & "\ImageDir") Dim $ArrayOfSaveImageHandle[100] For $i = 0 To 99 $hBmp = BitmapCreate() $ArrayOfSaveImageHandle[$i] = SaveImage($hBmp,@ScriptDir & "\ImageDir\" & "Gifimage" & $i & ".gif") Next MsgBox(0,"","SaveImage is complete") While 1 $complete = 1 For $i = 0 To 99 $IsComplete = SaveImageGetInfo($ArrayOfSaveImageHandle[$i],1) if Not $IsComplete Then $complete = 0 Next If ($complete) Then MsgBox(0,"","SaveImage is complete") Exit EndIf WEnd Func BitmapCreate() $DC = _WinAPI_GetDC(0) $CompatibleDC = _WinAPI_CreateCompatibleDC($DC) $hBitmap = _WinAPI_CreateCompatibleBitmap($DC,@DesktopWidth,@DesktopHeight) _WinAPI_SelectObject($CompatibleDC,$hBitmap) _WinAPI_BitBlt($CompatibleDC,0,0,@DesktopWidth,@DesktopHeight,$DC,0,0,$SRCCOPY) _WinAPI_ReleaseDC(0,$DC) _WinAPI_ReleaseDC(0,$CompatibleDC) Return $hBitmap EndFunc Func SaveImage($hBmp,$NewImageName,$iQuality = 100,$DeletImage = 1) ;returned. The handle can be used with SaveImageGetInfo $SaveImageHandle = DllCall($iDll,"DWORD","SaveImage","Handle",$hBmp,"str", _ $NewImageName,"int",$iQuality,"bool",$DeletImage) if @error Then Return 0 Return $SaveImageHandle[0] EndFunc Func SaveImageGetInfo($SaveImageHandle,$Element = 0) Dim $InfoArray[2] $Tag_SaveImage_Info = _ "DWORD IsComplete;" & _ "DWORD IsError" $SaveImage_Info = DllStructCreate($Tag_SaveImage_Info) $BOOL = DllCall($iDll,"bool","SaveImageGetInfo","DWORD",$SaveImageHandle, _ "ptr",DllStructGetPtr($SaveImage_Info)) if @error Then Return SetError(1,0,$InfoArray) if ($BOOL[0] = 0 ) Then Return SetError(2,0,$InfoArray) if ($Element) Then if ($Element < 1 Or $Element > 2) Then SetError(3,0,0) Return SetError(0,0,DllStructGetData($SaveImage_Info,$Element)) EndIf $InfoArray[0] = DllStructGetData($SaveImage_Info,1) $InfoArray[1] = DllStructGetData($SaveImage_Info,2) Return SetError(0,0,$InfoArray) EndFunc Compiler.au3 ;C++ Compiler 5.5 ;downloadhttps://downloads.embarcadero.com/free/c_builder ;C++Builder Compiler (bcc compiler) free download. See the file bcb5tool.hlp in the Help ;directory for complete instructions on using the C++Builder Compiler and Command Line Tools. ;Windows English 8.5MB #include <Constants.au3> #Include <WinAPI.au3> ;C:\Borland\BCC55\Bin\bcc32.exe $var1 = FileOpenDialog("Choose bcc32.exe","C:\", "(*.Exe)", 1 + 4 ,"bcc32.exe") if @error Then Exit $var2 = FileOpenDialog("Choose ThredLibrary.cpp","C:\", "(*.cpp)", 1 + 4 ,"ThredLibrary.cpp") if @error Then Exit $var3 = FileSelectFolder("Choose Out File folder.", "") if @error Then Exit Dim $iPatch1 = "" , $iPatch2 = $var2 , $iPatch3 = $var3 , $foo , $line = "" $Patch1 = StringSplit($var1,"\") For $i = 1 To $Patch1[0] - 2 $iPatch1 &= $Patch1[$i] & "\" Next $iPatch1 = StringTrimRight($iPatch1,1) FileChangeDir(FileGetShortName($iPatch1 & "\Bin\")) $Command = "bcc32.exe " & _ "-I" & FileGetShortName($iPatch1 & "\Include ") & _ "-L" & FileGetShortName($iPatch1 & "\Lib ") & _ "-e" & FileGetShortName($iPatch3 & "\ThredLibrary.dll ") & _ "-tWD " & FileGetShortName($iPatch2) $foo = Run($Command,"", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($foo) If @error Then ExitLoop MsgBox(0, "STDOUT", $line) Wend C ++ ThredLibrary.cpp expandcollapse popup#include <shlobj.h> #include <stdio.h> #include <windows.h> #include <tchar.h> #include <string> #include <vector> #include <iostream> #include <algorithm> DWORD ThreadCases; HMODULE HMO , NETHMO = LoadLibrary("Wininet.dll"); class EncoderParameter { public: GUID Guid; ULONG NumberOfValues; ULONG Type; VOID* Value; }; class EncoderParameters { public: UINT Count; EncoderParameter Parameter[1]; }; typedef struct { UINT32 GdiplusVersion; int DebugEventCallback; BOOL SuppressBackgroundThread; BOOL SuppressExternalCodecs; } Gdiplus; class GpImage {}; class GpGraphics {}; Gdiplus Gdiplusi; int Status,token,output; typedef struct { HGLOBAL hMemory; DWORD TotalReadTimes; DWORD NumberOfBytesRead; DWORD FileSize; DWORD IsComplete; DWORD IsError;} NetInfoR; typedef struct { DWORD TotalWriteTimes; DWORD NumberOfBytesWrite; DWORD FileSize; DWORD IsComplete; DWORD IsError;} NetInfoW; typedef struct { DWORD TotalCopyTimes; DWORD NumberOfBytesCopy; DWORD FileSize; DWORD IsComplete; DWORD IsError;} FileInfo; typedef struct { DWORD IsComplete; DWORD IsError;} ImageInfo; #ifdef __cplusplus extern "C" { #endif __declspec(dllexport) DWORD WINAPI FtpMemGetFile(HANDLE iConnect,LPCWSTR RemoteFile,LPCWSTR LocalFile,LPCWSTR CurrentDir,DWORD BytesNumberAtaTime,DWORD iFlag,DWORD MemSize); __declspec(dllexport) DWORD WINAPI FtpMemPutFile(HANDLE iConnect,LPCWSTR RemoteFile,LPCWSTR LocalFile,LPCWSTR CurrentDir,DWORD CreateDir,DWORD BytesNumberAtaTime,DWORD iFlag,HGLOBAL hMemory); __declspec(dllexport) DWORD WINAPI DownloadFile(LPCWSTR Url,LPCWSTR FilePath,DWORD BytesNumberAtaTime,DWORD iFlag,DWORD MemSize); __declspec(dllexport) DWORD WINAPI File_Copy(LPCWSTR SourceFile,LPCWSTR DestFile,DWORD BytesNumberAtaTime,DWORD iFlag); __declspec(dllexport) DWORD WINAPI SaveImage(HBITMAP hBmp,CHAR* NewImageName,int iQuality,bool DeletImage); __declspec(dllexport) bool WINAPI FtpGetFileInfo(DWORD FtpGetNO,NetInfoR &NInfo); __declspec(dllexport) bool WINAPI PauseFtpGet(DWORD FtpGetNO,bool Pause); __declspec(dllexport) bool WINAPI CancelFtpGet(DWORD FtpGetNO); __declspec(dllexport) bool WINAPI FtpPutFileInfo(DWORD FtpPutNO,NetInfoW &NInfo); __declspec(dllexport) bool WINAPI PauseFtpPut(DWORD FtpPutNO,bool Pause); __declspec(dllexport) bool WINAPI CancelFtpPut(DWORD FtpPutNO); __declspec(dllexport) bool WINAPI DownloadGetInfo(DWORD DownlNO,NetInfoR &NInfo); __declspec(dllexport) bool WINAPI PauseDownload(DWORD DownlNO,bool Pause); __declspec(dllexport) bool WINAPI CancelDownload(DWORD DownlNO); __declspec(dllexport) bool WINAPI File_CopyGetInfo(DWORD CopyNO,FileInfo &FInfo); __declspec(dllexport) bool WINAPI PauseCopyFile(DWORD CopyNO,bool Pause); __declspec(dllexport) bool WINAPI CancelCopyFile(DWORD CopyNO); __declspec(dllexport) bool WINAPI SaveImageGetInfo(DWORD SaveNO,ImageInfo &IInfo); __declspec(dllexport) bool WINAPI FtpCreate_Dir(HANDLE hConnect,LPCWSTR Dir,LPCWSTR CurrentDir); #ifdef __cplusplus } #endif DWORD FtpGetCount = 0; HANDLE GetThreadH = NULL; std::vector<DWORD> GetTestArray; std::vector<HANDLE> GetConnectArray; std::vector<HANDLE> GetFileArray; std::vector<HANDLE> GetOFileArray; std::vector<HGLOBAL> GethMemoryArray; std::vector<BYTE*> GetBytePtrArray; std::vector<std::wstring> GetRemoteFileArray; std::vector<std::wstring> GetCurrentDirArray; std::vector<DWORD> GetFileSizeArray; std::vector<DWORD> GetByteAtaTimeArray; std::vector<DWORD> GetBytesReadArray; std::vector<DWORD> GetTotalReadTimesArray; std::vector<DWORD> GetCompleteArray; std::vector<DWORD> GetErrorArray; std::vector<DWORD> GetMemSizeArray; std::vector<DWORD> GetNewDownlArray; std::vector<DWORD> GetPauseArray; std::vector<DWORD> GetMovePosArray; DWORD FtpPutCount = 0; HANDLE PutThreadH = NULL; std::vector<DWORD> PutiTestArray; std::vector<DWORD> PutCreateDirArray; std::vector<HANDLE> PutConnectArray; std::vector<HANDLE> PutOFileArray; std::vector<HANDLE> PutFileArray; std::vector<HGLOBAL> PuthMemoryArray; std::vector<BYTE*> PutBytePtrArray; std::vector<std::wstring> PutRemoteFileArray; std::vector<std::wstring> PutCurrentDirArray; std::vector<DWORD> PutFileSizeArray; std::vector<DWORD> PutBytesAtaTimeArray; std::vector<DWORD> PutBytesToWrite; std::vector<DWORD> PutTotalWriteTimesArray; std::vector<DWORD> PutCompleteArray; std::vector<DWORD> PutErrorArray; std::vector<DWORD> PutNewuploadArray; std::vector<DWORD> PutPauseArray; std::vector<DWORD> PutMovePosArray; DWORD DownlCount = 0; HANDLE DownlThreadH = NULL; HANDLE DownlOInte = NULL; std::vector<DWORD> DownliTestArray; std::vector<HANDLE> DownlFileArray; std::vector<HANDLE> DownlOUrlArray; std::vector<DWORD> DownlMovePosArray; std::vector<DWORD> DownlFileSizeArray; std::vector<DWORD> DownlByteAtaTimeArray; std::vector<DWORD> DownlBytesReadArray; std::vector<DWORD> DownlTotalReadTimesArray; std::vector<DWORD> DownlCompleteArray; std::vector<DWORD> DownlErrorArray; std::vector<BYTE*> DownlBytePtrArray; std::vector<HGLOBAL> DownlhMemoryArray; std::vector<DWORD> DownlPauseArray; std::vector<std::wstring> DownlStrUrlArray; std::vector<DWORD> DownlNewDownlArray; std::vector<DWORD> DownlMemSizeArray; DWORD CopyCount = 0; HANDLE CopyThreadH = NULL; std::vector<HANDLE> CopyShFileArray; std::vector<HANDLE> CopyDhFileArray; std::vector<DWORD> CopyFileSizeArray; std::vector<DWORD> CopyMovePosArray; std::vector<DWORD> CopyBytesAtaTimeArray; std::vector<DWORD> CopyBytesArray; std::vector<DWORD> CopyTotalTimesArray; std::vector<DWORD> CopyCompleteArray; std::vector<DWORD> CopyErrorArray; std::vector<DWORD> CopyPauseArray; std::vector<DWORD> CopyNewCopyArray; DWORD SaveImageCount = 0; HANDLE SaveThrHD = NULL; std::vector<GpImage*> SaveImageArray; std::vector<WCHAR*> SaveNewImageNameArray; std::vector<CLSID> SaveGUIDImageArray; std::vector<EncoderParameters> SaveParameterArray; std::vector<DWORD> SaveCompleteArray; std::vector<DWORD> SaveErrorArray; std::vector<DWORD> SaveNewSaveArray; DWORD WINAPI ThreadProc(LPVOID lpParameter); HANDLE Internet_Open(LPCWSTR lpszAgent,DWORD dwAccessType,LPCWSTR lpszProxyName,LPCWSTR lpszProxyBypass,DWORD dwFlags); HANDLE Internet_OpenUrl(HANDLE hInternet,LPCWSTR lpszUrl,LPCWSTR lpszHeaders,DWORD dwHeadersLength,DWORD dwFlags,LPVOID dwContext); HANDLE Internet_Connect(HANDLE hInternet,LPCWSTR lpszServerName,WORD nServerPort,LPCTSTR lpszUsername,LPCTSTR lpszPassword,DWORD dwService,DWORD dwFlags,LPVOID dwContext); HANDLE FtpOpen_File(HANDLE hConnect,LPCWSTR lpszFileName,DWORD dwAccess,DWORD dwFlags,LPVOID dwContext); DWORD FtpGetFileFileSize(HANDLE hFile,LPDWORD lpdwFileSizeHigh); BOOL Internet_ReadFile(HANDLE hFile,LPVOID lpBuffer,DWORD dwNumberOfBytesToRead,LPDWORD lpdwNumberOfBytesRead); BOOL Internet_WriteFile(HANDLE hFile,LPCVOID lpBuffer,DWORD dwNumberOfBytesToWrite,LPDWORD lpdwNumberOfBytesWritten); BOOL HttpQueryInfo(HANDLE hRequest,DWORD dwInfoLevel,LPVOID lpvBuffer,LPDWORD lpdwBufferLength,LPDWORD lpdwIndex); BOOL InternetQuery_DataAvailable(HANDLE hFile,LPDWORD lpdwNumberOfBytesAvailable,DWORD dwFlags,LPVOID dwContext); BOOL Internet_CloseHandle(HANDLE hInternet); BOOL FtpCreate_Directory(HANDLE hConnect,LPCWSTR lpszDirectory); BOOL SHCreate_DirectoryExW(HWND hwnd,LPCWSTR pszPath,SECURITY_ATTRIBUTES *psa); BOOL FtpSetCurrent_Directory(HANDLE hConnect,LPCWSTR lpszDirectory); BOOL FtpGetCurrent_Directory(HANDLE hConnect,LPCWSTR lpszCurrentDirectory,LPDWORD lpdwCurrentDirectory); void atThreadLibraryExit(void); extern "C" BOOL WINAPI DllMain(HANDLE hinstDLL,DWORD dwReason, LPVOID lpvReserved) { atexit(atThreadLibraryExit); return 1; } DWORD WINAPI FtpMemGetFile(HANDLE iConnect,LPCWSTR RemoteFile,LPCWSTR LocalFile,LPCWSTR CurrentDir,DWORD BytesNumberAtaTime,DWORD iFlag,DWORD MemSize) { DWORD FBOOL = (iFlag != 1 && iFlag != 2); if (BytesNumberAtaTime <= 0 || !iConnect || FBOOL) return 0; HANDLE GetFile; DWORD GetTest; if (iFlag == 1) { GetTest = 1; GetFile = CreateFileW(LocalFile,GENERIC_WRITE, 0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if (GetFile == INVALID_HANDLE_VALUE) return 0; } else { GetTest = 0; } GetConnectArray.push_back(iConnect); GetFileArray.push_back(GetFile); GetRemoteFileArray.push_back(RemoteFile); GetCurrentDirArray.push_back(CurrentDir); GetTestArray.push_back(GetTest); GetFileSizeArray.push_back(0); GetByteAtaTimeArray.push_back(BytesNumberAtaTime); GetOFileArray.push_back(0); GetBytesReadArray.push_back(0); GetTotalReadTimesArray.push_back(0); GetCompleteArray.push_back(0); GetErrorArray.push_back(0); GethMemoryArray.push_back(0); GetBytePtrArray.push_back(0); GetMemSizeArray.push_back(MemSize); GetNewDownlArray.push_back(1); GetPauseArray.push_back(0); GetMovePosArray.push_back(0); DWORD ThreadID; FtpGetCount++; ThreadCases = 1; if (!GetThreadH) { GetThreadH = CreateThread(NULL,0,ThreadProc,NULL,0,&ThreadID); } return FtpGetCount; } bool WINAPI FtpGetFileInfo(DWORD FtpGetNO,NetInfoR &NInfo) { if (FtpGetNO < 1 || FtpGetNO > FtpGetCount) return 0; FtpGetNO--; NInfo.TotalReadTimes = GetTotalReadTimesArray[FtpGetNO]; NInfo.NumberOfBytesRead = GetBytesReadArray[FtpGetNO]; NInfo.FileSize = GetFileSizeArray[FtpGetNO]; NInfo.IsComplete = GetCompleteArray[FtpGetNO]; NInfo.IsError = GetErrorArray[FtpGetNO]; if ((!GetTestArray[FtpGetNO]) && (GetCompleteArray[FtpGetNO] == 1)) NInfo.hMemory = GethMemoryArray[FtpGetNO]; return 1; } bool WINAPI PauseFtpGet(DWORD FtpGetNO,bool Pause) { if (FtpGetNO < 1 || FtpGetNO > FtpGetCount || GetCompleteArray[FtpGetNO - 1]) return 0; FtpGetNO--; if (Pause) { GetPauseArray[FtpGetNO] = 1; } else { GetPauseArray[FtpGetNO] = 0; } return 1; } bool WINAPI CancelFtpGet(DWORD FtpGetNO) { if (FtpGetNO < 1 || FtpGetNO > FtpGetCount || GetCompleteArray[FtpGetNO - 1]) return 0; PauseFtpGet(FtpGetNO,1); FtpGetNO--; CloseHandle(GetFileArray[FtpGetNO]); Internet_CloseHandle(GetOFileArray[FtpGetNO]); GlobalFree(GethMemoryArray[FtpGetNO]); GetCompleteArray[FtpGetNO] = 2; return 1; } DWORD WINAPI FtpMemPutFile(HANDLE iConnect,LPCWSTR RemoteFile,LPCWSTR LocalFile,LPCWSTR CurrentDir,DWORD CreateDir,DWORD BytesNumberAtaTime,DWORD iFlag,HGLOBAL hMemory) { DWORD FBOOL = (iFlag != 1 && iFlag != 2); if (BytesNumberAtaTime <= 0 || !iConnect || FBOOL) return 0; DWORD PutTest , LoDWORD , HiDWORD , FileSize; HANDLE PutFile; BYTE* BytePtr; BYTE* iBytePtr; HGLOBAL ihMemory; if (iFlag == 1) { PutTest = 1; PutFile = CreateFileW(LocalFile,GENERIC_READ,FILE_SHARE_READ, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if (PutFile == INVALID_HANDLE_VALUE) return 0; LoDWORD = GetFileSize(PutFile,&HiDWORD); FileSize = LoDWORD; } else { PutTest = 0; FileSize = GlobalSize(hMemory); BytePtr = (BYTE*) GlobalLock(hMemory); if (!BytePtr) return 0; ihMemory = GlobalAlloc(GPTR,FileSize); iBytePtr = (BYTE*) GlobalLock(ihMemory); CopyMemory(iBytePtr,BytePtr,FileSize); } PutConnectArray.push_back(iConnect); PutRemoteFileArray.push_back(RemoteFile); PutCurrentDirArray.push_back(CurrentDir); PutiTestArray.push_back(PutTest); PutFileArray.push_back(PutFile); PutOFileArray.push_back(0); PuthMemoryArray.push_back(ihMemory); PutBytePtrArray.push_back(iBytePtr); PutFileSizeArray.push_back(FileSize); PutMovePosArray.push_back(0); PutBytesAtaTimeArray.push_back(BytesNumberAtaTime); PutBytesToWrite.push_back(0); PutTotalWriteTimesArray.push_back(0); PutCompleteArray.push_back(0); PutErrorArray.push_back(0); PutPauseArray.push_back(0); PutNewuploadArray.push_back(1); PutCreateDirArray.push_back(CreateDir); DWORD ThreadID; FtpPutCount++; ThreadCases = 2; if (!PutThreadH) { PutThreadH = CreateThread(NULL,0,ThreadProc,NULL,0,&ThreadID); } return FtpPutCount; } bool WINAPI FtpPutFileInfo(DWORD FtpPutNO,NetInfoW &NInfo) { if (FtpPutNO < 1 || FtpPutNO > FtpPutCount) return 0; FtpPutNO--; NInfo.TotalWriteTimes = PutTotalWriteTimesArray[FtpPutNO]; NInfo.NumberOfBytesWrite = PutBytesToWrite[FtpPutNO]; NInfo.FileSize = PutFileSizeArray[FtpPutNO]; NInfo.IsComplete = PutCompleteArray[FtpPutNO]; NInfo.IsError = PutErrorArray[FtpPutNO]; return 1; } bool WINAPI PauseFtpPut(DWORD FtpPutNO,bool Pause) { if (FtpPutNO < 1 || FtpPutNO > FtpPutCount || PutCompleteArray[FtpPutNO - 1]) return 0; FtpPutNO--; if (Pause) { PutPauseArray[FtpPutNO] = 1; } else { PutPauseArray[FtpPutNO] = 0; } return 1; } bool WINAPI CancelFtpPut(DWORD FtpPutNO) { if (FtpPutNO < 1 || FtpPutNO > FtpPutCount || PutCompleteArray[FtpPutNO - 1]) return 0; PauseFtpPut(FtpPutNO,1); FtpPutNO--; CloseHandle(PutFileArray[FtpPutNO]); Internet_CloseHandle(PutOFileArray[FtpPutNO]); GlobalFree(PuthMemoryArray[FtpPutNO]); PutCompleteArray[FtpPutNO] = 2; return 1; } DWORD WINAPI DownloadFile(LPCWSTR Url,LPCWSTR FilePath,DWORD BytesNumberAtaTime,DWORD iFlag,DWORD MemSize) { DWORD DBOOL = (iFlag != 1 && iFlag != 2); if (BytesNumberAtaTime <= 0 || DBOOL) return 0; if (!DownlOInte) { DownlOInte = Internet_Open((LPCWSTR) "OPEN",NULL,NULL,NULL,0); if(!DownlOInte) return 0; } DWORD DownlTest; HANDLE DownlFile; if (iFlag == 1) { DownlTest = 1; DownlFile = CreateFileW(FilePath,GENERIC_WRITE, 0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if (DownlFile == INVALID_HANDLE_VALUE) return 0; } else { DownlTest = 0; } DownlStrUrlArray.push_back(Url); DownliTestArray.push_back(DownlTest); DownlFileArray.push_back(DownlFile); DownlOUrlArray.push_back(0); DownlMovePosArray.push_back(0); DownlBytePtrArray.push_back(0); DownlhMemoryArray.push_back(0); DownlFileSizeArray.push_back(0); DownlByteAtaTimeArray.push_back(BytesNumberAtaTime); DownlBytesReadArray.push_back(0); DownlTotalReadTimesArray.push_back(0); DownlCompleteArray.push_back(0); DownlErrorArray.push_back(0); DownlPauseArray.push_back(0); DownlMemSizeArray.push_back(MemSize); DownlNewDownlArray.push_back(1); DWORD ThreadID; DownlCount++; ThreadCases = 3; if (!DownlThreadH) { DownlThreadH = CreateThread(NULL,0,ThreadProc,NULL,0,&ThreadID); } return DownlCount; } bool WINAPI DownloadGetInfo(DWORD DownlNO,NetInfoR &NInfo) { if (DownlNO < 1 || DownlNO > DownlCount) return 0; DownlNO--; NInfo.TotalReadTimes = DownlTotalReadTimesArray[DownlNO]; NInfo.NumberOfBytesRead = DownlBytesReadArray[DownlNO]; NInfo.FileSize = DownlFileSizeArray[DownlNO]; NInfo.IsComplete = DownlCompleteArray[DownlNO]; NInfo.IsError = DownlErrorArray[DownlNO]; if ((!DownliTestArray[DownlNO]) && (DownlCompleteArray[DownlNO] == 1)) NInfo.hMemory = DownlhMemoryArray[DownlNO]; return 1; } bool WINAPI PauseDownload(DWORD DownlNO,bool Pause) { if (DownlNO < 1 || DownlNO > DownlCount || DownlCompleteArray[DownlNO - 1]) return 0; DownlNO--; if (Pause != 0) { DownlPauseArray[DownlNO] = 1; } else { DownlPauseArray[DownlNO] = 0; } return 1; } bool WINAPI CancelDownload(DWORD DownlNO) { if (DownlNO < 1 || DownlNO > DownlCount || DownlCompleteArray[DownlNO - 1]) return 0; PauseDownload(DownlNO,1); DownlNO--; CloseHandle(DownlFileArray[DownlNO]); Internet_CloseHandle(DownlOUrlArray[DownlNO]); GlobalFree(DownlhMemoryArray[DownlNO]); DownlCompleteArray[DownlNO] = 2; return 1; } DWORD WINAPI File_Copy(LPCWSTR SourceFile,LPCWSTR DestFile,DWORD BytesNumberAtaTime,DWORD iFlag) { HANDLE HSFile , HDFile; DWORD LoDWORD , HiDWORD , FileSize , iTest; DWORD RT = 0 , nBufferLength; int Pos = 0,TestPeriodslash = 0,iNo = 0; std::wstring iDir = DestFile; DWORD CdirLength = MAX_PATH; WCHAR Cdir[MAX_PATH]; iTest = (iFlag == 0 || iFlag == 1 || iFlag == 8 || iFlag == 9); if (BytesNumberAtaTime <= 0 || !iTest || iDir.length() < 1 || iDir.length() > MAX_PATH) return 0; HSFile = CreateFileW(SourceFile,GENERIC_READ,FILE_SHARE_READ, NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if (HSFile == INVALID_HANDLE_VALUE) return 0; LoDWORD = GetFileSize(HSFile,&HiDWORD); FileSize = LoDWORD; if (iFlag) { if (iFlag != 1) { if (iDir[0] == (char) 92 || iDir[0] == (char) 58) return FALSE; if (iDir.length() > 2) { if (iDir[1] == (char) 58 && iDir[2] != (char) 92) return FALSE; } if (iDir.length() == 2) { if (iDir[1] == (char) 58) return FALSE; } if (iDir.length() == 3) { if (iDir[1] == (char) 58 && iDir[2] == (char) 92) return FALSE; } if (iDir.length() > 1) { Pos = 0; if (iDir[1] == (char) 58) Pos = 2; }else{ Pos = 0; } if ( iDir.find ( L"<" , 0 ) != std::string::npos || iDir.find ( L">" , 0 ) != std::string::npos || iDir.find ( L":" ,Pos) != std::string::npos || iDir.find ( L'"' , 0 ) != std::string::npos || iDir.find ( L"/" , 0 ) != std::string::npos || iDir.find ( L"|" , 0 ) != std::string::npos || iDir.find ( L"\\\\",0) != std::string::npos || iDir.find ( L"?" , 0 ) != std::string::npos ) return FALSE; for (int i= iDir.length() - 1; i >= 0 ; i--) { if (iDir[i] == (char) 46 && !TestPeriodslash) TestPeriodslash = 1; if (iDir[i] == (char) 92 && !TestPeriodslash) TestPeriodslash = 2; } if (TestPeriodslash) { for (int i= iDir.length() - 1; i >= 0 ; i--) { if (iDir[i] == (char) 92) { TestPeriodslash = 3; iNo = i; break; }} if (TestPeriodslash == 3) { iDir = iDir.substr(0,iNo); if (iDir.length() > 1) { if (iDir[1] != (char) 58 ) { RT = GetCurrentDirectoryW(CdirLength,Cdir); if (!RT) return 0; iDir = std::wstring(L"\\") + iDir; iDir = std::wstring(Cdir) + iDir; }} SHCreate_DirectoryExW(NULL,iDir.c_str(),NULL); }} } HDFile = CreateFileW(DestFile,GENERIC_WRITE ,0,NULL,CREATE_ALWAYS,NULL,NULL); if (HDFile == INVALID_HANDLE_VALUE) return 0; } else { HDFile = CreateFileW(DestFile,GENERIC_WRITE ,0,NULL,CREATE_NEW,NULL,NULL); if (HDFile == INVALID_HANDLE_VALUE) return 0; } CopyShFileArray.push_back(HSFile); CopyDhFileArray.push_back(HDFile); CopyFileSizeArray.push_back(FileSize); CopyMovePosArray.push_back(0); CopyBytesAtaTimeArray.push_back(BytesNumberAtaTime); CopyBytesArray.push_back(0); CopyTotalTimesArray.push_back(0); CopyCompleteArray.push_back(0); CopyErrorArray.push_back(0); CopyPauseArray.push_back(0); CopyNewCopyArray.push_back(1); DWORD ThreadID; CopyCount++; ThreadCases = 4; if (!CopyThreadH) { CopyThreadH = CreateThread(NULL,0,ThreadProc,NULL,0,&ThreadID); } return CopyCount; } bool WINAPI File_CopyGetInfo(DWORD CopyNO,FileInfo &FInfo) { if (CopyNO < 1 || CopyNO > CopyCount) return 0; CopyNO--; FInfo.TotalCopyTimes = CopyTotalTimesArray[CopyNO]; FInfo.NumberOfBytesCopy = CopyBytesArray[CopyNO]; FInfo.FileSize = CopyFileSizeArray[CopyNO]; FInfo.IsComplete = CopyCompleteArray[CopyNO]; FInfo.IsError = CopyErrorArray[CopyNO]; return 1; } bool WINAPI PauseCopyFile(DWORD CopyNO,bool Pause) { if (CopyNO < 1 || CopyNO > CopyCount || CopyCompleteArray[CopyNO - 1]) return 0; CopyNO--; if (Pause) { CopyPauseArray[CopyNO] = 1; } else { CopyPauseArray[CopyNO] = 0; } return 1; } bool WINAPI CancelCopyFile(DWORD CopyNO) { if (CopyNO < 1 || CopyNO > CopyCount || CopyCompleteArray[CopyNO - 1]) return 0; PauseCopyFile(CopyNO,1); CopyNO--; CloseHandle(CopyShFileArray[CopyNO]); CloseHandle(CopyDhFileArray[CopyNO]); CopyCompleteArray[CopyNO] = 2; return 1; } DWORD WINAPI SaveImage(HBITMAP hBmp,CHAR* NewImageName,int iQuality,bool DeletImage) { GpImage* hbmReturn; CLSID GUIDImage; EncoderParameters encoderParams; CLSID iEncoderQuality; int ImageType = 0 , Nowide; WCHAR* lpWideCharStr = new WCHAR[600]; std::string Ext = (std::string) NewImageName; if (Ext.length() < 4) return 0; Ext = Ext.substr(Ext.length() - 4,4); for (int i = 0; i < Ext.length(); i++) {Ext[i] = toupper(Ext[i]);} if (Ext == std::string(".BMP")) ImageType = 1; if (Ext == std::string(".JPG")) ImageType = 2; if (Ext == std::string(".PNG")) ImageType = 3; if (Ext == std::string(".GIF")) ImageType = 4; if (Ext == std::string(".TIF")) ImageType = 5; if (!ImageType) return 0; if (!HMO) { HMO = LoadLibrary("gdiplus.dll"); if (!HMO) return 0; Gdiplusi.GdiplusVersion = 1; Gdiplusi.DebugEventCallback = 0; Gdiplusi.SuppressBackgroundThread = 0; Gdiplusi.SuppressExternalCodecs = 0; typedef int (CALLBACK* parametersA) (LPVOID,LPVOID,LPVOID); parametersA ProcA = (parametersA) GetProcAddress(HMO,_T("GdiplusStartup")); Status = ProcA(&token,&Gdiplusi,&output); if (Status != 0) return 0; } typedef int (CALLBACK* parametersB) (HBITMAP,int,GpImage**); parametersB ProcB = (parametersB) GetProcAddress(HMO,_T("GdipCreateBitmapFromHBITMAP")); Status = ProcB(hBmp,0,&hbmReturn); if (Status != 0) return 0; if (DeletImage) DeleteObject((HGDIOBJ) hBmp); switch (ImageType) { case 1://bmp CLSIDFromString(L"{557CF400-1A04-11D3-9A73-0000F81EF32E}",&GUIDImage); break; case 2://jpg CLSIDFromString(L"{557CF401-1A04-11D3-9A73-0000F81EF32E}",&GUIDImage); break; case 3://png CLSIDFromString(L"{557CF406-1A04-11D3-9A73-0000F81EF32E}",&GUIDImage); break; case 4://gif CLSIDFromString(L"{557CF402-1A04-11D3-9A73-0000F81EF32E}",&GUIDImage); break; case 5://tif CLSIDFromString(L"{557CF405-1A04-11D3-9A73-0000F81EF32E}",&GUIDImage); break; } CLSIDFromString(L"{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}",&iEncoderQuality); encoderParams.Count = 1; encoderParams.Parameter[0].NumberOfValues = 1; encoderParams.Parameter[0].Guid = iEncoderQuality; encoderParams.Parameter[0].Type = 4; encoderParams.Parameter[0].Value = &iQuality; memset(lpWideCharStr,0,sizeof(lpWideCharStr)); Nowide = MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,(CHAR*) NewImageName,-1,lpWideCharStr,0); MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,(CHAR*) NewImageName,Nowide,lpWideCharStr,600 * sizeof(WCHAR)); SaveImageArray.push_back(hbmReturn); SaveNewImageNameArray.push_back(lpWideCharStr); SaveGUIDImageArray.push_back(GUIDImage); SaveParameterArray.push_back(encoderParams); SaveCompleteArray.push_back(0); SaveErrorArray.push_back(0); SaveNewSaveArray.push_back(1); DWORD ThreadID; SaveImageCount++; ThreadCases = 5; if (!SaveThrHD) { SaveThrHD = CreateThread(NULL,0,ThreadProc,NULL,0,&ThreadID); } return SaveImageCount; } bool WINAPI SaveImageGetInfo(DWORD SaveNO,ImageInfo &IInfo) { if (SaveNO < 1 || SaveNO > SaveImageCount) return 0; SaveNO--; IInfo.IsComplete = SaveCompleteArray[SaveNO]; IInfo.IsError = SaveErrorArray[SaveNO]; return 1; } DWORD WINAPI ThreadProc(LPVOID lpParameter) { DWORD LocalThreadCases = ThreadCases; if (LocalThreadCases == 1) { DWORD BytesRead,MovePos = 0,Err,MemSize; DWORD BytesAtaTime,FileSize,GetTest; DWORD LoDWORD,HiDWORD; DWORD CdirLength = MAX_PATH * 2; WCHAR Cdir[MAX_PATH * 2]; HANDLE FtpGetOFile,GetFile,iConnect; BYTE* BytePtr; HGLOBAL hMemory; bool RT; LPCWSTR RemoteFile , CurrentDir; while(1) { for (int i = 0; i < FtpGetCount; i++) { if (GetCompleteArray[i] || GetPauseArray[i]) continue; iConnect = GetConnectArray[i]; GetTest = GetTestArray[i]; FtpGetOFile = GetOFileArray[i]; GetFile = GetFileArray[i]; BytesAtaTime = GetByteAtaTimeArray[i]; FileSize = GetFileSizeArray[i]; MovePos = GetMovePosArray[i]; MemSize = GetMemSizeArray[i]; BytePtr = GetBytePtrArray[i]; if (GetNewDownlArray[i]) { CurrentDir = GetCurrentDirArray[i].c_str(); if (std::wstring(CurrentDir).length()) { RT = FtpSetCurrent_Directory(iConnect,CurrentDir); Err = GetLastError(); if (!RT) { CloseHandle(GetFile); GetErrorArray[i] = Err; GetCompleteArray[i] = 1; GetNewDownlArray[i] = 0; continue; } } RemoteFile = GetRemoteFileArray[i].c_str(); FtpGetOFile = FtpOpen_File(iConnect,RemoteFile,GENERIC_READ,0,NULL); Err = GetLastError(); if (!FtpGetOFile) { CloseHandle(GetFile); GetErrorArray[i] = Err; GetCompleteArray[i] = 1; GetNewDownlArray[i] = 0; continue; } LoDWORD = FtpGetFileFileSize(FtpGetOFile,&HiDWORD); FileSize = LoDWORD; if (!GetTest) { if (MemSize) FileSize = MemSize; hMemory = GlobalAlloc(GPTR,FileSize); BytePtr = (BYTE*) GlobalLock(hMemory); GetBytePtrArray[i] = BytePtr; GethMemoryArray[i] = hMemory; } GetFileSizeArray[i] = FileSize; GetOFileArray[i] = FtpGetOFile; GetNewDownlArray[i] = 0; continue; } if (GetTest) { BytesRead = min(BytesAtaTime,FileSize - MovePos); BYTE* iBytePtr = new BYTE[BytesRead]; if (GetPauseArray[i]) continue; RT = Internet_ReadFile(FtpGetOFile,iBytePtr,BytesRead,&BytesRead); Err = GetLastError(); if(!RT || BytesRead <= 0) { CloseHandle(GetFile); Internet_CloseHandle(FtpGetOFile); GetErrorArray[i] = Err; GetCompleteArray[i] = 1; continue; } WriteFile(GetFile,iBytePtr,BytesRead,&BytesRead,NULL); GetMovePosArray[i] += BytesRead; GetBytesReadArray[i] += BytesRead; GetTotalReadTimesArray[i]++; } else { if (MovePos == FileSize) { Internet_CloseHandle(FtpGetOFile); GetErrorArray[i] = Err; GetCompleteArray[i] = 1; continue; } BytesRead = min(BytesAtaTime,FileSize - MovePos); BYTE* iBytePtr = new BYTE[BytesRead]; if (GetPauseArray[i]) continue; RT = Internet_ReadFile(FtpGetOFile,iBytePtr,BytesRead,&BytesRead); Err = GetLastError(); if(!RT || BytesRead <= 0) { Internet_CloseHandle(FtpGetOFile); GetErrorArray[i] = Err; GetCompleteArray[i] = 1; continue; } BYTE* OutPtr = BytePtr + MovePos; CopyMemory(OutPtr,iBytePtr,BytesRead); GetMovePosArray[i] += BytesRead; GetBytesReadArray[i] += BytesRead; GetTotalReadTimesArray[i]++; }} }} if (LocalThreadCases == 2) { DWORD BytesToWrite , MovePos = 0 , Err; DWORD PutTest , BytesAtaTime , FileSize; HANDLE PutOFile , PutFile , iConnect; BYTE* BytePtr; LPCWSTR RemoteFile , Dir , CurrentDir; bool RT; while(1) { for (int i = 0; i < FtpPutCount; i++) { if (PutCompleteArray[i] || PutPauseArray[i]) continue; PutTest = PutiTestArray[i]; PutOFile = PutOFileArray[i]; PutFile = PutFileArray[i]; BytePtr = PutBytePtrArray[i]; BytesAtaTime = PutBytesAtaTimeArray[i]; FileSize = PutFileSizeArray[i]; MovePos = PutMovePosArray[i]; RemoteFile = PutRemoteFileArray[i].c_str(); CurrentDir = PutCurrentDirArray[i].c_str(); if (PutNewuploadArray[i]) { iConnect = PutConnectArray[i]; if (PutCreateDirArray[i]) { RT = FtpCreate_Dir(iConnect,RemoteFile,CurrentDir); Err = GetLastError(); if (!RT) { GlobalFree(PuthMemoryArray[i]); PutNewuploadArray[i] = 0; PutErrorArray[i] = Err; PutCompleteArray[i] = 1; continue; } } PutOFile = FtpOpen_File(iConnect,RemoteFile,GENERIC_WRITE,0,NULL); Err = GetLastError(); if (!PutOFile) { CloseHandle(PutFile); GlobalFree(PuthMemoryArray[i]); PutNewuploadArray[i] = 0; PutErrorArray[i] = Err; PutCompleteArray[i] = 1; continue; } PutOFileArray[i] = PutOFile; PutNewuploadArray[i] = 0; continue; } if (PutTest) { BytesToWrite = min(BytesAtaTime,FileSize - MovePos); if (MovePos == FileSize) { CloseHandle(PutFile); Internet_CloseHandle(PutOFile); PutErrorArray[i] = Err; PutCompleteArray[i] = 1; continue; } BYTE* iBytePtr = new BYTE[BytesToWrite]; SetFilePointer(PutFile,MovePos,NULL,0); if (PutPauseArray[i]) continue; RT = ReadFile(PutFile,iBytePtr,BytesToWrite,&BytesToWrite, NULL); if (PutPauseArray[i]) continue; RT = Internet_WriteFile(PutOFile,iBytePtr,BytesToWrite,&BytesToWrite); Err = GetLastError(); if(!RT || BytesToWrite <= 0) { CloseHandle(PutFile); Internet_CloseHandle(PutOFile); PutErrorArray[i] = Err; PutCompleteArray[i] = 1; continue; } PutMovePosArray[i] += BytesToWrite; PutBytesToWrite[i] += BytesToWrite; PutTotalWriteTimesArray[i]++; } else { BytesToWrite = min(BytesAtaTime,FileSize - MovePos); if (MovePos == FileSize) { Internet_CloseHandle(PutOFile); PutErrorArray[i] = Err; PutCompleteArray[i] = 1; continue; } BYTE* iBytePtr = new BYTE[BytesToWrite]; BYTE* OutPtr = BytePtr + MovePos; CopyMemory(iBytePtr,OutPtr,BytesToWrite); RT = Internet_WriteFile(PutOFile,iBytePtr,BytesToWrite,&BytesToWrite); Err = GetLastError(); if(!RT || BytesToWrite <= 0) { Internet_CloseHandle(PutOFile); PutErrorArray[i] = Err; PutCompleteArray[i] = 1; continue; } PutMovePosArray[i] += BytesToWrite; PutBytesToWrite[i] += BytesToWrite; PutTotalWriteTimesArray[i]++; }} }} if (LocalThreadCases == 3) { DWORD BytesRead , MovePos = 0 , Err; DWORD FileSize , DownlTest , ByteAtaTime; DWORD MemSize; HANDLE DownlOUrl , DownlFile; LPCWSTR Url; bool RT; HGLOBAL hMemory; BYTE* BytePtr; while(1) { for (int i = 0; i < DownlCount; i++) { if (DownlCompleteArray[i] || DownlPauseArray[i]) continue; DownlOUrl = DownlOUrlArray[i]; DownlFile = DownlFileArray[i]; FileSize = DownlFileSizeArray[i]; DownlTest = DownliTestArray[i]; ByteAtaTime = DownlByteAtaTimeArray[i]; MemSize = DownlMemSizeArray[i]; MovePos = DownlMovePosArray[i]; BytePtr = DownlBytePtrArray[i]; if (DownlNewDownlArray[i]) { DWORD BufferLength = 2000; WCHAR BufferFileSize[2000]; Url = DownlStrUrlArray[i].c_str(); DownlOUrl = Internet_OpenUrl(DownlOInte,Url,NULL,NULL,NULL,NULL); Err = GetLastError(); RT = HttpQueryInfo(DownlOUrl,5,BufferFileSize,&BufferLength,NULL); if (!Err) Err = GetLastError(); if(!DownlOUrl || !RT) { CloseHandle(DownlFile); Internet_CloseHandle(DownlOUrl); DownlErrorArray[i] = Err; DownlCompleteArray[i] = 1; DownlNewDownlArray[i] = 0; continue; } FileSize = _wtoi(BufferFileSize); if (!DownlTest) { if (MemSize) FileSize = MemSize; hMemory = GlobalAlloc(GPTR,FileSize); BytePtr = (BYTE*) GlobalLock(hMemory); DownlhMemoryArray[i] = hMemory; DownlBytePtrArray[i] = BytePtr; } DownlOUrlArray[i] = DownlOUrl; DownlNewDownlArray[i] = 0; DownlFileSizeArray[i] = FileSize; continue; } if (DownlTest) { BytesRead = min(ByteAtaTime,FileSize - MovePos); BYTE* iBytePtr = new BYTE[BytesRead]; if (DownlPauseArray[i]) continue; RT = Internet_ReadFile(DownlOUrl,iBytePtr,BytesRead,&BytesRead); Err = GetLastError(); if(!RT || BytesRead <= 0) { CloseHandle(DownlFile); Internet_CloseHandle(DownlOUrl); DownlErrorArray[i] = Err; DownlCompleteArray[i] = 1; continue; } WriteFile(DownlFile,iBytePtr,BytesRead,&BytesRead,NULL); DownlMovePosArray[i] += BytesRead; DownlBytesReadArray[i] += BytesRead; DownlTotalReadTimesArray[i]++; } else { if (MovePos == FileSize) { Internet_CloseHandle(DownlOUrl); DownlErrorArray[i] = Err; DownlCompleteArray[i] = 1; continue; } BytesRead = min(ByteAtaTime,FileSize - MovePos); BYTE* iBytePtr = new BYTE[BytesRead]; if (DownlPauseArray[i]) continue; RT = Internet_ReadFile(DownlOUrl,iBytePtr,BytesRead,&BytesRead); Err = GetLastError(); if(!RT || BytesRead <= 0 ) { Internet_CloseHandle(DownlOUrl); DownlErrorArray[i] = Err; DownlCompleteArray[i] = 1; continue; } BYTE* OutPtr = BytePtr + MovePos; CopyMemory(OutPtr,iBytePtr,BytesRead); DownlMovePosArray[i] += BytesRead; DownlBytesReadArray[i] += BytesRead; DownlTotalReadTimesArray[i]++; }} }} if (LocalThreadCases == 4) { HANDLE HSFile , HDFile; DWORD BytesRead , MovePos = 0 , Err; DWORD BytesAtaTime , FileSize ,CompleteAll; BYTE* BytePtr; bool RT; while(1) { for (int i = 0; i < CopyCount; i++) { if (CopyCompleteArray[i] || CopyPauseArray[i] ) continue; HSFile = CopyShFileArray[i]; HDFile = CopyDhFileArray[i]; BytesAtaTime = CopyBytesAtaTimeArray[i]; FileSize = CopyFileSizeArray[i]; MovePos = CopyMovePosArray[i]; BytesRead = min(BytesAtaTime,FileSize - MovePos); if (MovePos == FileSize) { CloseHandle(HSFile); CloseHandle(HDFile); CopyErrorArray[i] = Err; CopyCompleteArray[i] = 1; continue; } BytePtr = new BYTE[BytesRead]; if (CopyPauseArray[i]) continue; RT = ReadFile(HSFile,BytePtr,BytesRead,&BytesRead,NULL); Err = GetLastError(); if(!RT || BytesRead <= 0) { CloseHandle(HSFile); CloseHandle(HDFile); CopyErrorArray[i] = Err; CopyCompleteArray[i] = 1; continue; } RT = WriteFile(HDFile,BytePtr,BytesRead,&BytesRead,NULL); CopyMovePosArray[i] += BytesRead; CopyBytesArray[i] += BytesRead; CopyTotalTimesArray[i]++; } }} if (LocalThreadCases == 5) { GpImage* ihbmReturn; WCHAR* ilpWideCharStr; CLSID iGUIDImage; EncoderParameters iencoderParams; while(1) { for (int i = 0; i < SaveImageCount; i++) { if (SaveCompleteArray[i]) continue; ihbmReturn = SaveImageArray[i]; ilpWideCharStr = SaveNewImageNameArray[i]; iGUIDImage = SaveGUIDImageArray[i]; iencoderParams = SaveParameterArray[i]; typedef int (CALLBACK* parametersC) (GpImage*,WCHAR*,CLSID*,EncoderParameters*); parametersC ProcC = (parametersC) GetProcAddress(HMO,_T("GdipSaveImageToFile")); Status = ProcC(ihbmReturn,ilpWideCharStr,&iGUIDImage,&iencoderParams); typedef int (CALLBACK* parametersE) (GpImage*); parametersE ProcE = (parametersE) GetProcAddress(HMO,_T("GdipDisposeImage")); ProcE(ihbmReturn); DeleteObject((HGDIOBJ) ihbmReturn); SaveCompleteArray[i] = 1; SaveErrorArray[i] = Status; } }} return 0; } HANDLE Internet_Open(LPCWSTR lpszAgent,DWORD dwAccessType,LPCWSTR lpszProxyName,LPCWSTR lpszProxyBypass,DWORD dwFlags) { typedef HANDLE (CALLBACK* parameters) (LPCWSTR,DWORD,LPCWSTR,LPCWSTR,DWORD); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("InternetOpenW")); return Proc(lpszAgent,dwAccessType,lpszProxyName,lpszProxyBypass,dwFlags); } HANDLE Internet_Connect(HANDLE hInternet,LPCWSTR lpszServerName,WORD nServerPort,LPCWSTR lpszUsername,LPCWSTR lpszPassword,DWORD dwService,DWORD dwFlags,LPVOID dwContext) { typedef HANDLE (CALLBACK* parameters) (HANDLE,LPCWSTR,WORD,LPCWSTR,LPCWSTR,DWORD,DWORD,LPVOID); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("InternetConnectW")); return Proc(hInternet,lpszServerName,nServerPort,lpszUsername,lpszPassword,dwService,dwFlags,dwContext); } HANDLE FtpOpen_File(HANDLE hConnect,LPCWSTR lpszFileName,DWORD dwAccess,DWORD dwFlags,LPVOID dwContext) { typedef HANDLE (CALLBACK* parameters) (HANDLE,LPCWSTR,DWORD,DWORD,LPVOID); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("FtpOpenFileW")); return Proc(hConnect,lpszFileName,dwAccess,dwFlags,dwContext); } BOOL Internet_WriteFile(HANDLE hFile,LPCVOID lpBuffer,DWORD dwNumberOfBytesToWrite,LPDWORD lpdwNumberOfBytesWritten) { typedef BOOL (CALLBACK* parameters) (HANDLE,LPCVOID,DWORD,LPDWORD); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("InternetWriteFile")); return Proc(hFile,lpBuffer,dwNumberOfBytesToWrite,lpdwNumberOfBytesWritten); } HANDLE Internet_OpenUrl(HANDLE hInternet,LPCWSTR lpszUrl,LPCWSTR lpszHeaders,DWORD dwHeadersLength,DWORD dwFlags,LPVOID dwContext) { typedef HANDLE (CALLBACK* parameters) (HANDLE,LPCWSTR,LPCWSTR,DWORD,DWORD,LPVOID); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("InternetOpenUrlW")); return Proc(hInternet,lpszUrl,lpszHeaders,dwHeadersLength,dwFlags,dwContext); } BOOL HttpQueryInfo(HANDLE hRequest,DWORD dwInfoLevel,LPVOID lpvBuffer,LPDWORD lpdwBufferLength,LPDWORD lpdwIndex) { typedef BOOL (CALLBACK* parameters) (HANDLE,DWORD,LPVOID,LPDWORD,LPDWORD); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("HttpQueryInfoW")); return Proc(hRequest,dwInfoLevel,lpvBuffer,lpdwBufferLength,lpdwIndex); } DWORD FtpGetFileFileSize(HANDLE hFile,LPDWORD lpdwFileSizeHigh) { typedef DWORD (CALLBACK* parameters) (HANDLE,LPDWORD); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("FtpGetFileSize")); return Proc(hFile,lpdwFileSizeHigh); } BOOL Internet_ReadFile(HANDLE hFile,LPVOID lpBuffer,DWORD dwNumberOfBytesToRead,LPDWORD lpdwNumberOfBytesRead) { typedef BOOL (CALLBACK* parameters) (HANDLE,LPVOID,DWORD,LPDWORD); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("InternetReadFile")); return Proc(hFile,lpBuffer,dwNumberOfBytesToRead,lpdwNumberOfBytesRead); } BOOL Internet_CloseHandle(HANDLE hInternet) { typedef BOOL (CALLBACK* parameters) (HANDLE); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("InternetCloseHandle")); return Proc(hInternet); } BOOL InternetQuery_DataAvailable(HANDLE hFile,LPDWORD lpdwNumberOfBytesAvailable,DWORD dwFlags,LPVOID dwContext) { typedef BOOL (CALLBACK* parameters) (HANDLE,LPDWORD,DWORD,LPVOID); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("InternetQueryDataAvailable")); return Proc(hFile,lpdwNumberOfBytesAvailable,dwFlags,dwContext); } BOOL FtpSetCurrent_Directory(HANDLE hConnect,LPCWSTR lpszDirectory) { typedef BOOL (CALLBACK* parameters) (HANDLE,LPCWSTR); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("FtpSetCurrentDirectoryW")); return Proc(hConnect,lpszDirectory); } BOOL FtpGetCurrent_Directory(HANDLE hConnect,LPCWSTR lpszCurrentDirectory,LPDWORD lpdwCurrentDirectory) { typedef BOOL (CALLBACK* parameters) (HANDLE,LPCWSTR,LPDWORD); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("FtpGetCurrentDirectoryW")); return Proc(hConnect,lpszCurrentDirectory,lpdwCurrentDirectory); } BOOL FtpCreate_Directory(HANDLE hConnect,LPCWSTR lpszDirectory) { typedef BOOL (CALLBACK* parameters) (HANDLE,LPCWSTR); parameters Proc = (parameters) GetProcAddress(NETHMO,_T("FtpCreateDirectoryW")); return Proc(hConnect,lpszDirectory); } BOOL SHCreate_DirectoryExW(HWND hwnd,LPCWSTR pszPath,SECURITY_ATTRIBUTES *psa) { HMODULE SHHMO = LoadLibrary("Shell32.dll"); typedef BOOL (CALLBACK* parameters) (HWND,LPCWSTR,SECURITY_ATTRIBUTES*); parameters Proc = (parameters) GetProcAddress(SHHMO,_T("SHCreateDirectoryExW")); return Proc(hwnd,pszPath,psa); } bool WINAPI FtpCreate_Dir(HANDLE hConnect,LPCWSTR Dir,LPCWSTR CurrentDir) { std::wstring iDir = Dir,nDir; DWORD CdirLength = MAX_PATH * 2; WCHAR Cdir[MAX_PATH * 2]; int Pos = 0 , Err = 0 , TestPeriodslash = 0 , iNo = 0; bool RT; if (iDir.length() < 1 || iDir.length() > MAX_PATH || !hConnect ) return FALSE; if ( iDir.find ( L"<" , 0 ) != std::string::npos || iDir.find ( L">" , 0 ) != std::string::npos || iDir.find ( L":" , 0 ) != std::string::npos || iDir.find ( L'"' , 0 ) != std::string::npos || iDir.find ( L"\\", 0 ) != std::string::npos || iDir.find ( L"|" , 0 ) != std::string::npos || iDir.find ( L"//", 0 ) != std::string::npos || iDir.find ( L"?" , 0 ) != std::string::npos ) return FALSE; if (iDir[0] == (char) 47) iDir = iDir.substr(1,iDir.length()); if (iDir[iDir.length() - 1] == (char) 47) iDir = iDir.substr(0,iDir.length() - 1); for (int i= iDir.length() - 1; i >= 0 ; i--) { if (iDir[i] == (char) 46 && !TestPeriodslash) TestPeriodslash = 1; if (iDir[i] == (char) 47 && !TestPeriodslash) TestPeriodslash = 2; } if (!std::wstring(CurrentDir).length()) { RT = FtpGetCurrent_Directory(hConnect,Cdir,&CdirLength); if (!RT) return FALSE; CurrentDir = Cdir; } else { RT = FtpGetCurrent_Directory(hConnect,Cdir,&CdirLength); if (!RT) return FALSE; if (std::wstring(Cdir) != std::wstring(L"/")) { CurrentDir = (std::wstring(Cdir) + std::wstring(L"/") + std::wstring(CurrentDir)).c_str(); } RT = FtpSetCurrent_Directory(hConnect,CurrentDir); if (!RT) return FALSE; } if (!TestPeriodslash) { return TRUE; } if (TestPeriodslash) { for (int i= iDir.length() - 1; i >= 0 ; i--) { if (iDir[i] == (char) 47) { TestPeriodslash = 3; iNo = i; break; } } if (TestPeriodslash != 3) { return TRUE; } else { iDir = iDir.substr(0,iNo); } } if (iDir[iDir.length() - 1] != (char) 47) iDir = iDir + std::wstring(L"/"); for (int i=0; i < iDir.length(); i++) { if (iDir[i] == (char) 47) { nDir = iDir.substr(Pos,i - Pos); RT = FtpCreate_Directory(hConnect,nDir.c_str()); Err = GetLastError(); if (!RT && Err != 12003) return FALSE; //12003 ERROR_INTERNET_EXTENDED_ERROR RT = FtpSetCurrent_Directory(hConnect,nDir.c_str()); if (!RT) return FALSE; Pos = i + 1; } } RT = FtpSetCurrent_Directory(hConnect,L"/"); if (!RT) return FALSE; RT = FtpSetCurrent_Directory(hConnect,CurrentDir); if (!RT) return FALSE; return TRUE; } void atThreadLibraryExit(void) { if (DownlOInte) Internet_CloseHandle(DownlOInte); if (GetThreadH) CloseHandle(GetThreadH); if (PutThreadH) CloseHandle(PutThreadH); if (DownlThreadH) CloseHandle(DownlThreadH); if (CopyThreadH) CloseHandle(CopyThreadH); if (SaveThrHD) CloseHandle(SaveThrHD); } Edited March 17, 2015 by wolf9228 KaFu 1 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
wolf9228 Posted February 7, 2011 Author Share Posted February 7, 2011 (edited) A simple mistake in the type of data through File_Copy function mistake in this line $File_CopyHandle = DllCall($iDll,"DWORD","File_Copy","wstr",$SourceFile,"wstr", $DestFile,"wstr",$BytesNumberAtaTime,"DWORD",$iFlag) correctly Line $File_CopyHandle = DllCall($iDll,"DWORD","File_Copy","wstr",$SourceFile,"wstr", $DestFile,"DWORD",$BytesNumberAtaTime,"DWORD",$iFlag) And another mistake in the same function in ThredLibrary Code mistakes Has been modified New Script Edited February 9, 2011 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
jixiren001 Posted January 8, 2012 Share Posted January 8, 2012 it is good! Link to comment Share on other sites More sharing options...
MrCreatoR Posted February 21, 2015 Share Posted February 21, 2015 Anyone knows how to use the hMemory for downloads? I want to be able to save the data in hMemory to some file, how i would do it? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted February 21, 2015 Share Posted February 21, 2015 Answering to myself: Local $hProcess = _WinAPI_GetCurrentProcess() Local $stBuffer = DllStructCreate('byte[' & $NumberOfBytesRead & ']') Local $iRead = 0 _WinAPI_ReadProcessMemory($hProcess, $hMemory, DllStructGetPtr($stBuffer), DllStructGetSize($stBuffer), $iRead) Local $bMemory = DllStructGetData($stBuffer, 1) If BinaryLen($bMemory) Then Local $hFile = FileOpen('file.zip', 2 + 16) FileWrite($hFile, $bMemory) FileClose($hFile) $bMemory = 0 EndIf Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
wolf9228 Posted February 23, 2015 Author Share Posted February 23, 2015 Anyone knows how to use the hMemory for downloads? I want to be able to save the data in hMemory to some file, how i would do it? Func DownloadFile($Url,$FilePath,$BytesNumberAtaTime = 1,$iFlag = 1,$MemSize = 0) ;$iFlag = 1 Download To File ($FilePath) ;$iFlag = 2 Download To Memory (Tag_Download_Info ==> hMemory) ;$MemSize Download Size From $Url To hMemory (Tag_Download_Info ==> hMemory) (can be set to 0) ;returned. The handle can be used with DownloadGetInfo And PauseDownload And CancelDownload $Tag_Download_Info = _ "HANDLE hMemory;" & _ "DWORD TotalReadTimes;" & _ "DWORD NumberOfBytesRead;" & _ "DWORD FileSize;" & _ "DWORD IsComplete;" & _ "DWORD IsError" HANDLE hMemory /// After the completion of download data // IsComplete = 1 Must Free the memory using the _MemGlobalFree function صرح السماء كان هنا Link to comment Share on other sites More sharing options...
MrCreatoR Posted February 24, 2015 Share Posted February 24, 2015 (edited) wolf9228 Hi, thank you for this great UDF, but there is few more issues with it: 1) If downloading large file, the memory increased to read size (if downloading to file). 2) The CPU is high when download completed or canceled (there is no active downloads after at least one download). 3) When trying to close dll the script is crashed. 4) Downloading uses IE proxy settings, perhaps it is better to have options to set proxy or disable it completely. Any chance that these issues can be resolved? Edited February 24, 2015 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted February 27, 2015 Share Posted February 27, 2015 *Up* Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
wolf9228 Posted March 20, 2015 Author Share Posted March 20, 2015 (edited) wolf9228 Hi, thank you for this great UDF, but there is few more issues with it: 1) If downloading large file, the memory increased to read size (if downloading to file). 2) I will be doing another version , a very old topic , there really errors library , I do not have enough time now , but I will do a second version soon , Thank you for your feedback, 3) When trying to close dll the script is crashed. 4) Downloading uses IE proxy settings, perhaps it is better to have options to set proxy or disable it completely. Any chance that these issues can be resolved? II will be doing another version , a very old topic , there really errors library , I do not have enough time now , but I will do a second version soon , Thank you for your feedback, Edited March 20, 2015 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
wolf9228 Posted March 20, 2015 Author Share Posted March 20, 2015 *Up* Sorry I frequented the site sometimes, and I'm not continuous with you on an ongoing basis , to busy across many sites صرح السماء كان هنا Link to comment Share on other sites More sharing options...
KaFu Posted March 20, 2015 Share Posted March 20, 2015 Too sad, you always provide interesting examples ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
wolf9228 Posted March 22, 2015 Author Share Posted March 22, 2015 (edited) wolf9228 Hi, thank you for this great UDF, but there is few more issues with it: 1) If downloading large file, the memory increased to read size (if downloading to file). 2) The CPU is high when download completed or canceled (there is no active downloads after at least one download). 3) When trying to close dll the script is crashed. 4) Downloading uses IE proxy settings, perhaps it is better to have options to set proxy or disable it completely. Any chance that these issues can be resolved? There are no errors in the first version of the library, but has been programmed primitive manner,You just have to put a zero on the variables value in this way$ Array = 0$ complete = 1Then restart the process of downloading files, errors do not occurIf the pose variables again this way errors occurGlobal $ Array, $ complete = 1 any way, I am doing a part of the second version you can use it. ThredLibrary second version ThredLibrary.zip ThredLibrary.au3 expandcollapse popup#include <WinAPI.au3> #include <Memory.au3> Global $tagDownloadInfoSt = "INT Complete;INT Cancel;INT Error;INT BytesAtaTime;INT64 MovePos;INT64 FileSize;" & _ "BOOL MemBool;INT NuOfBytesRead;INT NuOfBytesWn;PTR vhMemory;PTR hThread;PTR hFile;PTR HttpOpen;PTR Connect;" & _ "PTR OpenRequest" Global $Winhttp = DllOpen("Winhttp.dll") , $ThredLibrary = DllOpen("ThredLibrary.dll") Func DownloadFile($lpszUrl,$DownloadDir,$BytesAtOneLoop = 4096,$lpszProxyName = "",$lpszProxyBypass = "",$MemBool = False) Local $vFileName = "",$nFileName = "",$hFile = 0,$DISPOSITION = "" Local $Extension = "" ,$jFileName = "" ,$vhMemory = 0,$hMemory = 0 Local $HostName , $UrlPath $URL_COMPONENTS = WinHttpCrackUrl($lpszUrl,0,$HostName,$UrlPath) if @error Then Return SetError(1,0,0) $HttpOpen = WinHttpOpen("OPEN",$lpszProxyName,$lpszProxyBypass) if Not($HttpOpen) Then Return SetError(2,0,0) $Connect = WinHttpConnect($HttpOpen,$HostName,0) if Not $Connect Then WinHttpCloseHandle($HttpOpen) Return SetError(3,0,0) EndIf $OpenRequest = WinHttpOpenRequest($Connect,"GET",$UrlPath) if Not $OpenRequest Then WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(4,0,0) EndIf $Return = WinHttpSendRequest($OpenRequest) if Not $Return Then WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(5,0,0) EndIf $Return = WinHttpReceiveResponse($OpenRequest) if Not $Return Then WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(6,0,0) EndIf $OriginalUrl = WinHttpQueryOption($OpenRequest,34) if @error Then WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(7,0,0) EndIf $FileSize = WinHttpQueryHeaders($OpenRequest,5) $FileSize = Abs(Number($FileSize)) $DISPOSITION = WinHttpQueryHeaders($OpenRequest,47) if Not @error Then $DISPOSITION = StringSplit($DISPOSITION,";") $DISPOSITION = $DISPOSITION[$DISPOSITION[0]] $DISPOSITION = StringSplit($DISPOSITION,"=") $DISPOSITION = $DISPOSITION[$DISPOSITION[0]] $DISPOSITION = StringReplace($DISPOSITION,'"',"") $DISPOSITION = StringReplace($DISPOSITION,"'","") Else $DISPOSITION = "" EndIf if Not($MemBool) Then if Not($DISPOSITION == "") Then $jFileName = $DISPOSITION $Extension = StringSplit($jFileName,".") $Extension = "." & $Extension[$Extension[0]] $nFileName = StringLeft($jFileName,StringLen($jFileName) - StringLen($Extension)) $vFileName = StringLeft($nFileName,30) Else $jFileName = StringSplit($OriginalUrl,"/") $jFileName = $jFileName[$jFileName[0]] $Extension = StringSplit($jFileName,".") $Extension = "." & $Extension[$Extension[0]] $nFileName = StringLeft($jFileName,StringLen($jFileName) - StringLen($Extension)) $vFileName = StringLeft($nFileName,30) EndIf if StringRight($DownloadDir,1) == "\" Then $DownloadDir = StringTrimRight($DownloadDir,1) if Not FileExists($DownloadDir) Then DirCreate($DownloadDir) if Not FileExists($DownloadDir) Then WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(8,0,0) EndIf $nFileName = $DownloadDir & "\" & $vFileName & $Extension Local $i = 1 While FileExists($nFileName) $nFileName = $DownloadDir & "\" & $vFileName & "(" & $i & ")" & $Extension $i += 1 WEnd $hFile = _WinAPI_CreateFile($nFileName,0) if Not($hFile) Then WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(9,0,0) EndIf Else if $FileSize = 0 Then WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(10,0,0) EndIf $vhMemory = _MemGlobalAlloc($FileSize,$GHND) if Not($vhMemory) Then WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(11,0,0) EndIf EndIf $hMemory = _MemGlobalAlloc(DllStructGetSize(DllStructCreate($tagDownloadInfoSt)),$GHND) if Not($hMemory) Then if ($vhMemory) Then _MemGlobalFree($vhMemory) WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) if ($hFile) Then _WinAPI_CloseHandle($hFile) FileDelete($nFileName) EndIf Return SetError(12,0,0) EndIf $hLock = _MemGlobalLock($hMemory) if Not($hLock) Then if ($vhMemory) Then _MemGlobalFree($vhMemory) if ($hFile) Then _WinAPI_CloseHandle($hFile) FileDelete($nFileName) EndIf WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(13,0,0) EndIf $DownloadInfoSt = DllStructCreate($tagDownloadInfoSt,$hLock) DllStructSetData($DownloadInfoSt,"FileSize",$FileSize) DllStructSetData($DownloadInfoSt,"BytesAtaTime",$BytesAtOneLoop) DllStructSetData($DownloadInfoSt,"MemBool",$MemBool) DllStructSetData($DownloadInfoSt,"vhMemory",$vhMemory) DllStructSetData($DownloadInfoSt,"hFile",$hFile) DllStructSetData($DownloadInfoSt,"HttpOpen",$HttpOpen) DllStructSetData($DownloadInfoSt,"Connect",$Connect) DllStructSetData($DownloadInfoSt,"OpenRequest",$OpenRequest) $Return = DllCall($ThredLibrary,"BOOL","DownloadFile","ptr",$hLock) if @error Or $Return[0] = False Then if ($vhMemory) Then _MemGlobalFree($vhMemory) _MemGlobalUnlock($hMemory) _MemGlobalFree($hMemory) if ($hFile) Then _WinAPI_CloseHandle($hFile) FileDelete($nFileName) EndIf WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(14,0,0) EndIf Local $HandleArray[7] $HandleArray[0] = $hLock $HandleArray[1] = $nFileName $HandleArray[2] = $FileSize $HandleArray[3] = $OriginalUrl $HandleArray[4] = $DISPOSITION $HandleArray[5] = $hMemory $HandleArray[6] = $vhMemory Return SetError(0,0,$HandleArray) EndFunc Func DownloadGetFileOption($lpszUrl,$lpszProxyName = "",$lpszProxyBypass = "") Local $HostName , $UrlPath $URL_COMPONENTS = WinHttpCrackUrl($lpszUrl,0,$HostName,$UrlPath) if @error Then Return SetError(1,0,0) $HttpOpen = WinHttpOpen("OPEN",$lpszProxyName,$lpszProxyBypass) if Not($HttpOpen) Then Return SetError(2,0,0) $Connect = WinHttpConnect($HttpOpen,$HostName,0) if Not $Connect Then WinHttpCloseHandle($HttpOpen) Return SetError(3,0,0) EndIf $OpenRequest = WinHttpOpenRequest($Connect,"GET",$UrlPath) if Not $OpenRequest Then WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(4,0,0) EndIf $Return = WinHttpSendRequest($OpenRequest) if Not $Return Then WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(5,0,0) EndIf $Return = WinHttpReceiveResponse($OpenRequest) if Not $Return Then WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(6,0,0) EndIf $DISPOSITION = WinHttpQueryHeaders($OpenRequest,47) if Not @error Then $DISPOSITION = StringSplit($DISPOSITION,";") $DISPOSITION = $DISPOSITION[$DISPOSITION[0]] $DISPOSITION = StringSplit($DISPOSITION,"=") $DISPOSITION = $DISPOSITION[$DISPOSITION[0]] $DISPOSITION = StringReplace($DISPOSITION,'"',"") $DISPOSITION = StringReplace($DISPOSITION,"'","") Else $DISPOSITION = "" EndIf $OriginalUrl = WinHttpQueryOption($OpenRequest,34) if @error Then WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Return SetError(7,0,0) EndIf $FileSize = WinHttpQueryHeaders($OpenRequest,5) $FileSize = Abs(Number($FileSize)) WinHttpCloseHandle($OpenRequest) WinHttpCloseHandle($Connect) WinHttpCloseHandle($HttpOpen) Local $OptionArray[3] $OptionArray[0] = $FileSize $OptionArray[1] = $OriginalUrl $OptionArray[2] = $DISPOSITION Return SetError(0,0,$OptionArray) EndFunc Func DownloadFreeHandle($HandleArray) if Not IsArray($HandleArray) Or UBound($HandleArray) < 7 Or UBound($HandleArray) > 7 Then Return SetError(1,0,False) $hLock = $HandleArray[0] $hMemory = $HandleArray[5] $vhMemory = $HandleArray[6] $InfoStruct = DllStructCreate($tagDownloadInfoSt,$hLock) if @error Then Return SetError(2,0,False) $Complete = DllStructGetData($InfoStruct,"Complete") if $Complete = 0 Then DllStructSetData($InfoStruct,"Cancel",1) While DllStructGetData($InfoStruct,"Complete") = 0 Sleep(100) WEnd EndIf $hThread = DllStructGetData($InfoStruct,"hThread") _WinAPI_CloseHandle($hThread) _MemGlobalUnlock($hMemory) _MemGlobalFree($hMemory) if ($vhMemory) Then _MemGlobalUnlock($vhMemory) _MemGlobalFree($vhMemory) EndIf Return SetError(0,0,True) EndFunc Func DownloadGetInfo($HandleArray) if Not IsArray($HandleArray) Or UBound($HandleArray) < 7 Or UBound($HandleArray) > 7 Then Return SetError(1,0,0) $InfoStruct = DllStructCreate($tagDownloadInfoSt,$HandleArray[0]) if @error Then Return SetError(2,0,0) Return SetError(0,0,$InfoStruct) EndFunc Func WinHttpQueryOption($hInternet,$dwOption) Local $lpdwBufferLength = 10000 $DLLSDWORD = DllStructCreate("DWORD") DllStructSetData($DLLSDWORD,1,$lpdwBufferLength) $LPDWORDLENGTH = DllStructGetPtr($DLLSDWORD) $DLLSlpvBuffer = DllStructCreate("WCHAR[" & $lpdwBufferLength & "]") $lpvBuffer = DllStructGetPtr($DLLSlpvBuffer) $BOOL = DllCall($Winhttp,"BOOL","WinHttpQueryOption","HANDLE",$hInternet _ ,"DWORD",$dwOption,"ptr",$lpvBuffer,"ptr",$LPDWORDLENGTH) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,DllStructGetData($DLLSlpvBuffer,1)) EndFunc Func WinHttpQueryHeaders($hRequest,$dwInfoLevel,$lpdwIndex = 0) Local $lpdwBufferLength = 10000 $DLLSDWORD = DllStructCreate("DWORD") DllStructSetData($DLLSDWORD,1,$lpdwBufferLength) $LPDWORDLENGTH = DllStructGetPtr($DLLSDWORD) $DLLSlpvBuffer = DllStructCreate("WCHAR[" & $lpdwBufferLength & "]") $lpvBuffer = DllStructGetPtr($DLLSlpvBuffer) $BOOL = DllCall($Winhttp,"BOOL","WinHttpQueryHeaders","HANDLE",$hRequest,"DWORD",$dwInfoLevel, _ "wstr","","ptr",$lpvBuffer,"ptr",$LPDWORDLENGTH,"DWORD",0) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,DllStructGetData($DLLSlpvBuffer,1)) EndFunc Func WinHttpOpen($pwszUserAgent,$dwAccessType = 0,$lpszProxyName = "",$lpszProxyBypass = "",$dwFlags = 0) $HINTERNET = DllCall($Winhttp,"HANDLE","WinHttpOpen","wstr",$pwszUserAgent,"DWORD",$dwAccessType, _ "wstr",$lpszProxyName,"wstr",$lpszProxyBypass,"DWORD",$dwFlags) if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc Func WinHttpConnect($hSession,$pswzServerName,$INTERNET_PORT,$dwReserved = 0) $HINTERNET = DllCall($Winhttp,"HANDLE","WinHttpConnect","HANDLE",$hSession,"wstr",$pswzServerName, _ "DWORD",$INTERNET_PORT,"DWORD",$dwReserved) if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc Func WinHttpOpenRequest($hConnect,$pwszVerb,$pwszObjectName,$pwszVersion = "",$pwszReferrer = "",$ppwszAcceptTypes = 0,$dwFlags = 0) $HINTERNET = DllCall($Winhttp,"HANDLE","WinHttpOpenRequest","HANDLE",$hConnect,"wstr",$pwszVerb, _ "wstr",$pwszObjectName,"wstr",$pwszVersion,"wstr",$pwszReferrer,"ptr",$ppwszAcceptTypes,"DWORD",$dwFlags) if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc Func WinHttpSendRequest($hRequest,$pwszHeaders = "",$dwHeadersLength = 0,$lpOptional = 0, _ $dwOptionalLength = 0,$dwTotalLength = 0,$dwContext = 0) $HINTERNET = DllCall($Winhttp,"HANDLE","WinHttpSendRequest","HANDLE",$hRequest,"wstr",$pwszHeaders, _ "DWORD",$dwHeadersLength,"ptr",$lpOptional,"DWORD",$dwOptionalLength,"DWORD",$dwTotalLength,"ptr",$dwContext) if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc Func WinHttpReceiveResponse($hRequest) $HINTERNET = DllCall($Winhttp,"BOOL","WinHttpReceiveResponse","HANDLE",$hRequest,"ptr",0) if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0) Return SetError(0,0,$HINTERNET[0]) EndFunc Func WinHttpCrackUrl($lpszUrl , $dwFlags, ByRef $HostName , ByRef $UrlPath ) Local $INTERNET_MAX_URL_LENGTH = 2084 , $dwUrlLength = StringLen($lpszUrl) $tagURL_COMPONENTS = "DWORD dwStructSize;ptr lpszScheme;DWORD dwSchemeLength;DWORD nScheme;ptr lpszHostName;" & _ "DWORD dwHostNameLength;DWORD nPort;ptr lpszUserName;DWORD dwUserNameLength;ptr lpszPassword;" & _ "DWORD dwPasswordLength;ptr lpszUrlPath;DWORD dwUrlPathLength;ptr lpszExtraInfo;DWORD dwExtraInfoLength" $URL_COMPONENTS = DllStructCreate($tagURL_COMPONENTS) $lpszHostName = DllStructCreate("WCHAR[" & $INTERNET_MAX_URL_LENGTH & "]") $szPath = DllStructCreate("WCHAR[" & $INTERNET_MAX_URL_LENGTH & "]") DllStructSetData($URL_COMPONENTS,"dwStructSize",DllStructGetSize($URL_COMPONENTS)) DllStructSetData($URL_COMPONENTS,"lpszHostName",DllStructGetPtr($lpszHostName)) DllStructSetData($URL_COMPONENTS,"lpszUrlPath",DllStructGetPtr($szPath)) DllStructSetData($URL_COMPONENTS,"dwUrlPathLength",$INTERNET_MAX_URL_LENGTH) DllStructSetData($URL_COMPONENTS,"dwHostNameLength",$INTERNET_MAX_URL_LENGTH) $Return = DllCall($Winhttp,"BOOL","WinHttpCrackUrl","wstr",$lpszUrl,"DWORD",$dwUrlLength _ ,"DWORD",$dwFlags,"ptr",DllStructGetPtr($URL_COMPONENTS)) if @error Or Not ($Return[0]) Then Return SetError(1,0,False) $HostName = DllStructGetData($lpszHostName,1) $UrlPath = DllStructGetData($szPath,1) Return SetError(0,0,True) EndFunc Func WinHttpCloseHandle($hInternet) $BOOL = DllCall($Winhttp,"BOOL","WinHttpCloseHandle","HANDLE",$hInternet) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,$BOOL[0]) EndFunc ThredLibrary.cpp expandcollapse popup#include <shlobj.h> #include <stdio.h> #include <windows.h> // ------------------------------------------------DownloadFile-------------------------------------------------- typedef struct { DWORD Complete; DWORD Cancel; DWORD Error; DWORD BytesAtaTime; INT64 MovePos; INT64 FileSize; BOOL MemBool; DWORD NuOfBytesRead; DWORD NuOfBytesWn; LPVOID vhMemory; LPVOID hThread; LPVOID hFile; LPVOID HttpOpen; LPVOID Connect; LPVOID OpenRequest;} DownloadInfo; HMODULE WinhttphModule = LoadLibraryW(L"Winhttp.dll"); typedef BOOL (WINAPI* parametersA) (LPVOID,LPVOID,DWORD,LPDWORD); parametersA WinHttpReadData = (parametersA) GetProcAddress(WinhttphModule,"WinHttpReadData"); typedef BOOL (WINAPI* parametersB) (LPVOID); parametersB WinHttpCloseHandle = (parametersB) GetProcAddress(WinhttphModule,"WinHttpCloseHandle"); DWORD WINAPI DownloadProc(LPVOID lpParameter); // ------------------------------------------------DownloadFile-------------------------------------------------- #ifdef __cplusplus extern "C" { #endif __declspec(dllexport) BOOL WINAPI DownloadFile(DownloadInfo &vDownloadInfo); #ifdef __cplusplus } #endif BOOL WINAPI DllMain( HINSTANCE hinstDLL, // handle to DLL module DWORD fdwReason, // reason for calling function LPVOID lpReserved ) // reserved { // Perform actions based on the reason for calling. switch( fdwReason ) { case DLL_PROCESS_ATTACH: // Initialize once for each new process. // Return FALSE to fail DLL load. break; case DLL_THREAD_ATTACH: // Do thread-specific initialization. break; case DLL_THREAD_DETACH: // Do thread-specific cleanup. break; case DLL_PROCESS_DETACH: // Perform any necessary cleanup. break; } return TRUE; // Successful DLL_PROCESS_ATTACH. } BOOL WINAPI DownloadFile(DownloadInfo &vDownloadInfo) { DWORD ThreadID; HANDLE hThread = CreateThread(NULL,0,DownloadProc,&vDownloadInfo,0,&ThreadID); if (hThread == 0) return false; vDownloadInfo.hThread = hThread; return true; } DWORD WINAPI DownloadProc(LPVOID lpParameter) { BOOL vReturn; DownloadInfo* vDInfo = ((DownloadInfo*)lpParameter); if (vDInfo->FileSize == 0) { BYTE* lpBuffer = new BYTE[vDInfo->BytesAtaTime]; while(1) { if (vDInfo->Cancel) { vDInfo->Complete = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; } vReturn = WinHttpReadData(vDInfo->OpenRequest,lpBuffer,vDInfo->BytesAtaTime,&vDInfo->NuOfBytesRead); if (vReturn) { vReturn = WriteFile(vDInfo->hFile,lpBuffer,vDInfo->NuOfBytesRead,&vDInfo->NuOfBytesWn,0); if (vReturn) { vDInfo->MovePos += vDInfo->NuOfBytesRead; if (vDInfo->NuOfBytesRead == 0) { vDInfo->Complete = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; } } else { vDInfo->Complete = 1; vDInfo->Error = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; } } else { vDInfo->Complete = 1; vDInfo->Error = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; }} } else { if (vDInfo->vhMemory) { BYTE* hLock = (BYTE*) GlobalLock(vDInfo->vhMemory); if (!(hLock)) { vDInfo->Complete = 1; vDInfo->Error = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; } while(1) { if (vDInfo->Cancel) { vDInfo->Complete = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; } DWORD dwNumberOfBytesToRead = vDInfo->BytesAtaTime; if (dwNumberOfBytesToRead > (vDInfo->FileSize - vDInfo->MovePos)) dwNumberOfBytesToRead = (vDInfo->FileSize - vDInfo->MovePos); BOOL vReturn = WinHttpReadData(vDInfo->OpenRequest,hLock,dwNumberOfBytesToRead,&vDInfo->NuOfBytesRead); if (vReturn) { vDInfo->MovePos += vDInfo->NuOfBytesRead; if (vDInfo->MovePos == vDInfo->FileSize) { vDInfo->Complete = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; } hLock += vDInfo->NuOfBytesRead; } else { vDInfo->Complete = 1; vDInfo->Error = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; }} } else { BYTE* lpBuffer = new BYTE[vDInfo->BytesAtaTime]; while(1) { if (vDInfo->Cancel) { vDInfo->Complete = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; } DWORD dwNumberOfBytesToRead = vDInfo->BytesAtaTime; if (dwNumberOfBytesToRead > (vDInfo->FileSize - vDInfo->MovePos)) dwNumberOfBytesToRead = (vDInfo->FileSize - vDInfo->MovePos); vReturn = WinHttpReadData(vDInfo->OpenRequest,lpBuffer,dwNumberOfBytesToRead,&vDInfo->NuOfBytesRead); if (vReturn) { vReturn = WriteFile(vDInfo->hFile,lpBuffer,vDInfo->NuOfBytesRead,&vDInfo->NuOfBytesWn,0); if (vReturn) { vDInfo->MovePos += vDInfo->NuOfBytesRead; if (vDInfo->MovePos == vDInfo->FileSize) { vDInfo->Complete = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; } } else { vDInfo->Complete = 1; vDInfo->Error = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; } } else { vDInfo->Complete = 1; vDInfo->Error = 1; CloseHandle(vDInfo->hFile); WinHttpCloseHandle(vDInfo->OpenRequest); WinHttpCloseHandle(vDInfo->Connect); WinHttpCloseHandle(vDInfo->HttpOpen); return 0; } }}} return 0; } DownloaderMultiFiles.au3 expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #Include "GUICtrlSetOnEventEx.au3" #Include "ThredLibrary.au3" Global $Array , $complete = 1 $controlID1 = DownloaderMultiFiles($Array,"http://www.swfmax.com/get/SWF.max.exe",@ScriptDir) GUICtrlSetOnEventEx($controlID1,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID2 = DownloaderMultiFiles($Array,"http://download.winzip.com/winzip150.exe",@ScriptDir) GUICtrlSetOnEventEx($controlID2,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID3 = DownloaderMultiFiles($Array,"http://www.flash-swf-converter.com/downloads/swfconverter.exe","",True) GUICtrlSetOnEventEx($controlID3,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID4 = DownloaderMultiFiles($Array,"http://bookstore.ashrae.biz/journal/download.php?file=ASHRAE-D-AJ10Jan05-20091230.pdf",@ScriptDir) GUICtrlSetOnEventEx($controlID4,$BN_CLICKED,"Clicked_Cancel_Buttons") While 1 if ($complete = 1) Then $complete = ProgressLoop($Array) Else MsgBox(0,"","download is complete") ExitLoop EndIf WEnd Global $nBytes $hLock = EnvGet($controlID3) $InfoStruct = DllStructCreate($tagDownloadInfoSt,Ptr($hLock)) $FileSize = DllStructGetData($InfoStruct,"FileSize") $vhMemory = DllStructGetData($InfoStruct,"vhMemory") $hLock = _MemGlobalLock($vhMemory) $hFile = _WinAPI_CreateFile("MemFile.exe",1) _WinAPI_WriteFile($hFile,$hLock,$FileSize,$nBytes) _WinAPI_CloseHandle($hFile) For $i = 0 To UBound($Array) - 1 $HandleArray = $Array[$i][7] DownloadFreeHandle($HandleArray) Next $Array = 0 $complete = 1 $controlID1 = DownloaderMultiFiles($Array,"http://www.swfmax.com/get/SWF.max.exe",@ScriptDir) GUICtrlSetOnEventEx($controlID1,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID2 = DownloaderMultiFiles($Array,"http://download.winzip.com/winzip150.exe",@ScriptDir) GUICtrlSetOnEventEx($controlID2,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID3 = DownloaderMultiFiles($Array,"http://www.flash-swf-converter.com/downloads/swfconverter.exe","",True) GUICtrlSetOnEventEx($controlID3,$BN_CLICKED,"Clicked_Cancel_Buttons") $controlID4 = DownloaderMultiFiles($Array,"http://bookstore.ashrae.biz/journal/download.php?file=ASHRAE-D-AJ10Jan05-20091230.pdf",@ScriptDir) GUICtrlSetOnEventEx($controlID4,$BN_CLICKED,"Clicked_Cancel_Buttons") While 1 if ($complete = 1) Then $complete = ProgressLoop($Array) Else MsgBox(0,"","download is complete") ExitLoop EndIf WEnd Global $nBytes $hLock = EnvGet($controlID3) $InfoStruct = DllStructCreate($tagDownloadInfoSt,Ptr($hLock)) $FileSize = DllStructGetData($InfoStruct,"FileSize") $vhMemory = DllStructGetData($InfoStruct,"vhMemory") $hLock = _MemGlobalLock($vhMemory) $hFile = _WinAPI_CreateFile("MemFile.exe",1) _WinAPI_WriteFile($hFile,$hLock,$FileSize,$nBytes) _WinAPI_CloseHandle($hFile) For $i = 0 To UBound($Array) - 1 $HandleArray = $Array[$i][7] DownloadFreeHandle($HandleArray) Next Func Clicked_Cancel_Buttons($ControlID,$NotificationCode) $WPARAM = OnEventExGetWParam($ControlID,$NotificationCode) $LPARAM = OnEventExGetLParam($ControlID,$NotificationCode) $HWND = OnEventExGetHWND($ControlID,$NotificationCode) $hLock = EnvGet($ControlID) Local $tagDownloadInfoSt = "INT Complete;INT Cancel;INT Error;INT BytesAtaTime;INT64 MovePos;INT64 FileSize;" & _ "BOOL MemBool;INT NuOfBytesRead;INT NuOfBytesWn;PTR vhMemory;PTR hThread;PTR hFile;PTR HttpOpen;PTR Connect;" & _ "PTR OpenRequest" $InfoStruct = DllStructCreate($tagDownloadInfoSt,Ptr($hLock)) DllStructSetData($InfoStruct,"Cancel",1) EndFunc Func ProgressLoop($Array) Dim $TempArray[1][8] $complete = 2 For $i = 0 To UBound($Array) - 1 $ProgressTime = $Array[$i][5] Sleep($ProgressTime) $InfoStruct = DownloadGetInfo($Array[$i][7]) if Not @error Then $MovePos = DllStructGetData($InfoStruct,"MovePos") $FileSize = DllStructGetData($InfoStruct,"FileSize") $IsComplete = DllStructGetData($InfoStruct,"Complete") if $FileSize Then GUICtrlSetData($Array[$i][3],(100 / $FileSize) * $MovePos) GUICtrlSetData($Array[$i][4],"( " & StringLeft(($MovePos / 1024) / 1024 ,12) _ & " OF " & StringLeft(($FileSize /1024) / 1024 ,12) & " ) MB") Else GUICtrlSetData($Array[$i][3],100) GUICtrlSetData($Array[$i][4],"( " & StringLeft(($MovePos / 1024) / 1024 ,12) _ & " OF Unknown Size )") EndIf If Not ($IsComplete) Then $complete = 1 $TempArray[UBound($TempArray) -1][0] = $Array[$i][0] $TempArray[UBound($TempArray) -1][1] = $Array[$i][1] $TempArray[UBound($TempArray) -1][2] = $Array[$i][2] $TempArray[UBound($TempArray) -1][3] = $Array[$i][3] $TempArray[UBound($TempArray) -1][4] = $Array[$i][4] $TempArray[UBound($TempArray) -1][5] = $Array[$i][5] $TempArray[UBound($TempArray) -1][6] = $Array[$i][6] $TempArray[UBound($TempArray) -1][7] = $Array[$i][7] ReDim $TempArray[UBound($TempArray) + 1][8] Else GUICtrlSetBkColor($Array[$i][4], $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetBkColor($Array[$i][4] + 2, $GUI_BKCOLOR_TRANSPARENT) EndIf EndIf Next if $complete = 2 Then GUIDelete($Array[0][0]) Else ReDim $TempArray[UBound($TempArray) - 1][10] $Array = $TempArray EndIf Return $complete EndFunc Func DownloaderMultiFiles(ByRef $Array,$lpszUrl,$DownloadDir,$MemBool = False,$ProgressTime = 200,$lpszProxyName = "",$lpszProxyBypass = "") if Not IsArray($Array) Then Dim $Array[1][8] $Array[0][0] = GUICreate("Downloader Progress", 730, 140, 5, 200, _ BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW _ ,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS)) GUISetState(@SW_SHOW) Else ReDim $Array[UBound($Array) + 1][8] EndIf $Array[UBound($Array) - 1][3] = GUICtrlCreateProgress(190, 10 + ((UBound($Array) - 1) * 30), 200, 20) $Array[UBound($Array) - 1][4] = GUICtrlCreateLabel("", 400, 10 + ((UBound($Array) - 1) * 30), 250, 20,BitOR($SS_CENTER,$WS_BORDER)) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) $Array[UBound($Array) - 1][5] = $ProgressTime $Array[UBound($Array) - 1][6] = GUICtrlCreateButton("Cancel", 655, 10 + ((UBound($Array) - 1) * 30), 60,20) GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") $HandleArray = DownloadFile($lpszUrl,$DownloadDir,4096,$lpszProxyName,$lpszProxyBypass,$MemBool) $Array[UBound($Array) - 1][7] = $HandleArray EnvSet($Array[UBound($Array) - 1][6],$HandleArray[0]) If Not $MemBool Then $HandleArray = $Array[UBound($Array) - 1][7] $FileName = $HandleArray[1] $FileName = StringSplit($FileName,"\") $Array[UBound($Array) - 1][1] = $HandleArray[3] $Array[UBound($Array) - 1][2] = $FileName[$FileName[0]] GUICtrlCreateLabel($Array[UBound($Array) - 1][2], 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER)) Else $Array[UBound($Array) - 1][1] = $lpszUrl GUICtrlCreateLabel("< [ Memory ] >", 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER)) EndIf GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, 0xFFFFFF) Return $Array[UBound($Array) - 1][6] EndFunc Compiler.au3 #include <Constants.au3> #Include <WinAPI.au3> ;C:\Borland\BCC55\Bin\bcc32.exe $var1 = FileOpenDialog("Choose bcc32.exe","C:\Borland\BCC55\Bin", "(*.Exe)", 1 + 4 ,"bcc32.exe") if @error Then Exit $var2 = FileOpenDialog("Choose ThredLibrary.cpp",@ScriptDir, "(*.cpp)", 1 + 4 ,"ThredLibrary.cpp") if @error Then Exit $var3 = FileSelectFolder("Choose Out File folder.", @ScriptDir) if @error Then Exit Dim $iPatch1 = "" , $iPatch2 = $var2 , $iPatch3 = $var3 , $foo , $line = "" $Patch1 = StringSplit($var1,"\") For $i = 1 To $Patch1[0] - 2 $iPatch1 &= $Patch1[$i] & "\" Next FileDelete($iPatch3 & "\ThredLibrary.dll") $iPatch1 = StringTrimRight($iPatch1,1) FileChangeDir(FileGetShortName($iPatch1 & "\Bin\")) $Command = "bcc32.exe " & _ "-I" & FileGetShortName($iPatch1 & "\Include ") & _ "-L" & FileGetShortName($iPatch1 & "\Lib ") & _ "-e" & FileGetShortName($iPatch3 & "\ThredLibrary.dll ") & _ "-tWD " & FileGetShortName($iPatch2) $foo = Run($Command,"", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($foo) If @error Then ExitLoop MsgBox(0, "STDOUT", $line) Wend Edited March 30, 2015 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
wolf9228 Posted March 22, 2015 Author Share Posted March 22, 2015 Too sad, you always provide interesting examples ... Thank you صرح السماء كان هنا Link to comment Share on other sites More sharing options...
MrCreatoR Posted March 28, 2015 Share Posted March 28, 2015 restart the process of downloading files, errors do not occur I am not sure that i understand, how exactly i should restart the process? ThredLibrary second version Thank you, what the changes that was made? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now