Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/20/2015 in all areas

  1. A transparent rolling text example with GDI Font and background picture are embedded in script. TransparentRollingText.au3
    3 points
  2. It depends on the values and types of data you are checking. I would use whichever if or switch represent the logic of your code in a manner that is easiest to understand. The differences between the 2 methods are so small that it makes no difference in normal circumstances. The only time it would make any noticeable difference is inside a loop that is being executed millions of times when detailed fine tuning can make a difference. Meanwhile just use the method that is easiest four you to understand.
    2 points
  3. wolf9228

    Thred Library

    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 Script ThredLibrary2.zip DownloaderMultiFiles.au3 #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 #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 #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 #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 #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 ;download https://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 #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); }
    1 point
  4. UEZ

    _ArrayUnique

    It is not that what I expected according to the post title "_ArrayUnique" but I like the idea to make string with delimiter unique. Imho, _StringUnique is more applicable. Made some tests and it seems to work properly. This might be useful!
    1 point
  5. jguinch

    Folder size exclude an ext

    Here is my code, using my suggest in #6 : $sDir = @SystemDir Global $fTimer = TimerInit() ConsoleWrite("Overall file size: " & FilesGetSize($sDir, ".exe") & " bytes / amount of files: " & @extended & @CRLF) ConsoleWrite(TimerDiff($fTimer) & " ms" & @CRLF & @CRLF) Global $fTimer = TimerInit() Local $aSizeAll = DirGetSize($sDir, 1) Local $aSizeDoc = _DirGetSizeByExtension($sDir, "exe", 1) ConsoleWrite("Overall file size: " & $aSizeAll[0] - $aSizeDoc[0] & " bytes / amount of files: " & $aSizeAll[1] - $aSizeDoc[1] & " / amount of folders: " & $aSizeAll[2] & @CRLF) ConsoleWrite(TimerDiff($fTimer) & " ms" & @CRLF) Func _DirGetSizeByExtension($sDir, $sExt = "*", $iFlag = 0) If NOT FileExists($sDir) Then Return SetError(1, 0, -1) If NOT StringInStr(FileGetAttrib($sDir), "D") Then Return SetError(1, 0, -1) If $sExt = "*" Then $sExt = "?.*" Local $aDirs[1] = [ StringRegExpReplace($sDir, "\\$", "") ] Local $iCountDir = 0, $iCountFile = 0, $n = 0 Local $hSearch, $sFileName Local $iSize = 0 While 1 $hSearch = FileFindFirstFile( $aDirs[$n] & "\*.*" ) If $hSearch <> -1 Then While 1 $sFileName = FileFindNextFile($hSearch) If @error Then ExitLoop If @Extended Then $iCountDir += 1 If $iCountDir >= UBound($aDirs) Then Redim $aDirs[ UBound($aDirs) * 2] $aDirs[$iCountDir] = $aDirs[$n] & "\" & $sFileName Else If StringRegExp($sFileName, "(?i)\." & $sExt & "$") Then $iSize += FileGetSize($aDirs[$n] & "\" & $sFileName) $iCountFile += 1 EndIf EndIf WEnd EndIf FileClose($hSearch) If $n = $iCountDir Then ExitLoop $n += 1 WEnd If NOT $iFlag Then Return $iSize Local $aResult[3] = [ $iSize, $iCountFile, $iCountDir ] Return $aResult EndFunc Func FilesGetSize($sDir, $sExcludeExt = ".au3", $bRecursiv = True) Local $hSearch = FileFindFirstFile($sDir & "\*"), $sFullFileName, $sFAttrib If $hSearch = -1 Then Return SetError(1, 0, 0) ;no files found Local Static $iFSize = 0, $iCounter = 0 While 1 $sFileName = FileFindNextFile($hSearch) If @error Then ExitLoop ; If there is no more file matching the search. $sFullFileName = $sDir & "\" & $sFileName $sFAttrib = FileGetAttrib($sFullFileName) If StringInStr($sFAttrib, "D") And $bRecursiv Then FilesGetSize($sFullFileName, $sExcludeExt, $bRecursiv) EndIf If StringRight($sFileName, StringLen($sExcludeExt)) <> $sExcludeExt Then $iFSize += FileGetSize($sFullFileName) $iCounter += 1 EndIf WEnd FileClose($hSearch) Return SetExtended($iCounter, $iFSize) EndFunc PS : 2193,45 ms UEZ : 720.19 ms jguinch : 128.77 ms Both AU3 codes return the same size, but PS returns a diffenrent size...
    1 point
  6. Ask your question publicly. If no one can help, then you can choose what to do from there.
    1 point
  7. JohnOne

    Which is the fastest?

    Also, Switch has the home team advantage that if it;s a dead heat, Switch takes credit
    1 point
  8. JohnOne

    CSVSplit

    I've been using this for a while now, are there any script breaking changes?
    1 point
  9. Works fine for me, except that flag=48 only displays one button. _MsgBoxEx(1+48, "Test", "Taste", -1, -1, "Pest", "Paste") P.S.: Upsa, didn't saw the answer on page 2 of the thread ...
    1 point
  10. czardas

    Parse CSV crash

    Here's the ticket I was refering to: #2997 It doesn't seem to be the cause of the problem with Jewtus' code.
    1 point
  11. JohnOne

    Searching an Excel file

    Local $Username = "Fred" $strComputers = "" For $i = 0 To UBound($aResult) -1 ; loop though array If $aResult[$i][0] = $Username Then $strComputers &= $aResult[$i][1] & " " EndIf Next MsgBox(0, "Answer", $Username & " uses computer " & $strComputers)
    1 point
  12. Hi ViciousXUSMC, cool Idea ! I use Irfan all the time with AutoIT because of the above mentioned reasons, your absolutely right ! couple of ideas for your your project: offer a zip download with the bat's and such to make it easier for the user to install / use. your FileInstall ('s) will not work like that for anyone but you) anytime you (your program) install and/or change the registry you should offer an uninstall which cleans up in case the user decides to bail Just my $0.02 cya, Bill
    1 point
  13. What's not working? I just tested this, found out that you're using the wrong flag for your msgbox. The flag #48 corresponds to $MB_ICONWARNING, when you use that by itself it tells AutoIt to create a msgbox with one button and the warning icon inside it. If you want both buttons to show up, you have to use one of the flags that has more than one button displayed. If you replace your _MsgBoxEx(48, with _MsgBoxEx(52, then it will show both buttons with the correct text on them. BTW, if you only specify text for 2 buttons and use a 3 button message box flag, the first button's text won't change.
    1 point
  14. Well I spent my lazy and rainy sunday afternoon trying to wrap the native 7z.dll in an AutoIt UDF. I searched the forum and found that it only works with a third party DLL wrapper (rasim's UDF). However, I also came across this codeproject with the following statement: I figured this meant that the problems involving COM and Interfaces was solved and that a third party wrapper was no longer necessary. Then I came across the following prototypes exported by 7z.dll: UInt32 WINAPI CreateObject(const GUID *clsID, const GUID *interfaceID, void **outObject); UInt32 WINAPI GetNumberOfMethods(UInt32 *numMethods); UInt32 WINAPI GetMethodProperty(UInt32 index, PROPID propID, PROPVARIANT *value); UInt32 WINAPI GetNumberOfFormats(UInt32 *numFormats); UInt32 WINAPI GetHandlerProperty(PROPID propID, PROPVARIANT *value); UInt32 WINAPI GetHandlerProperty2(UInt32 index, PROPID propID, PROPVARIANT *value); UInt32 WINAPI SetLargePageMode(); I wrote AutoIt equivalents and used the latest 7z.dll. Here's a sample of _7z_GetNumberOfMethods: Func _7z_GetNumberOfMethods() If Not _7z_Startup() Then Return SetError(@error, 0, 0) Local $aRes = DllCall($__7z_hDLL, 'uint', 'GetNumberOfMethods', 'uint*', 0) If @error Then Return SetError(@error, 0, 0) Return $aRes[1] EndFunc ;==>_7z_GetNumberOfMethods The entire UDF is attached below btw. Anyway, it works. Kinda. _7z_GetNumberOfMethods() returns 21 and _7z_GetNumberOfFormats() 42. But I can't get _7z_CreateObject() to work... It returns a pointer type as defined but it's always 0. Mind you, I'm not even sure the 7z GUID's are used correctly or that the DllCall() is using the right parameter types... Because 7zip uses COM objects I suspected that DllCall wasn't the right way so I didn't put too much research in it. Instead I read up on ObjGet and the likes and did another forum search. It became clear that in order to work at all, the DLL in question needs to be registered. But unfortunately 7z.dll neither exports a DllRegisterServer nor a DllInstall method. So the DLL can't be registered... Below is the UDF I came up with. It's still lots of boilerplate code but atleast I got a partial success. However, I feel like I'm in over my head here and before putting any more time in it I want to know if it's a dead-end I'm pursuing. And if it's not a dead-end, then how to continue? Is there a workaround for the DllRegisterServer problem that I can exploit to use Obj* functions? Or maybe I can use DllCallAddress() in any way? Maybe use a different DLL from the 7zip package? Any feedback would be much appreciated! The UDF: 7z.au3 A simple example: _7z_Startup() ; _7z_Startup('C:PathTo7z.dll') Global $sVersion = _7z_GetVersion() ; Works. Global $iNumMethods = _7z_GetNumberOfMethods() ; Works. Global $iNumFormats = _7z_GetNumberOfFormats() ; Works. ; $7Z_INTERFACE_UNKNOWN = '00000000-0000-0000-C000-000000000046' ; $7Z_INTERFACE_IN_ARCHIVE = '23170F69-40C1-278A-0000-006000060000' Global $o7zObj = _7z_CreateObject($7Z_INTERFACE_UNKNOWN, $7Z_INTERFACE_IN_ARCHIVE) ; FAIL. MsgBox(0, '', '7zip version: ' & $sVersion & @CRLF _ & 'Number of 7zip methods: ' & $iNumMethods & @CRLF _ & 'Number of 7zip formats: ' & $iNumFormats & @CRLF _ & '_7z_CreateObject result: ' & VarGetType($o7zObj) & ' value: ' & $o7zObj) NB: The example uses _7z_Startup() without any parameters. On line 273 in 7z.au3 the path is set to: Global $__7z_sDLLDir = @ScriptDir & 'Res' It's very likely your 7z.dll is located elsewhere, so pass the full path including 7z.dll filename to _7z_Startup(). Also make sure that the 7z.dll used is 64-bit when running 64-bit AutoIt. Same applies to 32-bit, the UDF has a function that checks for this.
    1 point
×
×
  • Create New...