nend Posted November 17, 2011 Share Posted November 17, 2011 This is a small piece of code of a much bigger project. The problem is when the inetget routine has been canceled the file keeps being in use so that I can insert a album art. Is this a bug from inetget routine or is it a bug from my code? With the previous inetget version it worked al well. (inetgetabort) Link to comment Share on other sites More sharing options...
nend Posted November 18, 2011 Author Share Posted November 18, 2011 One day later and still no one knows a solution for this problem? Is it a bug in Autoit or in my code? (see the source code in the attachment) Link to comment Share on other sites More sharing options...
guinness Posted November 18, 2011 Share Posted November 18, 2011 Try InetClose() and look at my example of _InetGUI() in my signature. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
nend Posted November 18, 2011 Author Share Posted November 18, 2011 (edited) Hoi Guiness,Thank for the reply.I've already try d inetclose() but if a complete file is downloaded it go's alright.But when a file is not entirely downloaded and you stop the download inetgetclose() keeps the file in use (the file that inetget makes) until you exit the program.See the sourcode I've provide. Edited November 18, 2011 by nend Link to comment Share on other sites More sharing options...
guinness Posted November 18, 2011 Share Posted November 18, 2011 Use the latest beta version of AutoIt. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
nend Posted November 19, 2011 Author Share Posted November 19, 2011 Ok Thanks guiness, I will download it and try it. Link to comment Share on other sites More sharing options...
nend Posted November 19, 2011 Author Share Posted November 19, 2011 Hoi Guinness, I've tryd it with the latest beta but stil the same bug. If you look at this small function I found on the forum you will see that the file keeps being in use til you exit the script. I really think it's a bug in AutoIt, shall I report it as a bug? Func _FileInUse($sFilename, $iAccess = 0) Local $aRet, $hFile, $iError, $iDA Local Const $GENERIC_WRITE = 0x40000000 Local Const $GENERIC_READ = 0x80000000 Local Const $FILE_ATTRIBUTE_NORMAL = 0x80 Local Const $OPEN_EXISTING = 3 $iDA = $GENERIC_READ If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE) $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ "dword", $iDA, _ "dword", 0x00000000, _ "dword", 0x00000000, _ "dword", $OPEN_EXISTING, _ "dword", $FILE_ATTRIBUTE_NORMAL, _ "hwnd", 0) $iError = @error If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1) $hFile = $aRet[0] If $hFile = -1 Then $aRet = DllCall("Kernel32.dll", "int", "GetLastError") If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1) Return SetError($aRet[0], 0, 1) Else DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(@error, 0, 0) EndIf EndFunc Link to comment Share on other sites More sharing options...
trancexx Posted November 19, 2011 Share Posted November 19, 2011 If you really think the only explanation for behavior you experience is a bug then report a bug. But be to a point with your code.That's why we have that part of the machine. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
guinness Posted November 19, 2011 Share Posted November 19, 2011 I didn't find a bug on Windows 7 x64 when I used my example, which was taken from >>Note: I used WinAPIEx.au3 for _WinAPI_FileInUse().expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <WinAPIEx.au3> _Main() Func _Main() Local $sFilePathURL = "http://ftp.opera.com/pub/opera/win/1152/en/Opera_1152_en_Setup.exe" Local $hGUI, $iButton, $iLabel, $iProgressBar, $sFilePath $hGUI = GUICreate("_InetGetGUI()", 370, 90, -1, -1) $iLabel = GUICtrlCreateLabel("Welcome to the simple Downloader!", 5, 5, 270, 40) $iButton = GUICtrlCreateButton("&Download", 275, 2.5, 90, 25) $iProgressBar = GUICtrlCreateProgress(5, 60, 360, 20) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $iButton $sFilePath = _InetGetGUI($sFilePathURL, $iLabel, $iProgressBar, $iButton, @ScriptDir) If @error Then Switch @extended ; Check what the actual error was by using the @extended command. Case 0 ConsoleWrite("Is file in use? = " & _WinAPI_FileInUse(@ScriptDir & "" & $sFilePath) & @LF) MsgBox(64, "Error", "Check the URL or your Internet Connection!") Case 1 ConsoleWrite("Is file in use? = " & _WinAPI_FileInUse(@ScriptDir & "" & $sFilePath) & @LF) MsgBox(64, "Fail", "Seems the download was canecelled, but the file was >> " & $sFilePath) EndSwitch Else MsgBox(64, "Success", "Downloaded >> " & $sFilePath) EndIf EndSwitch WEnd EndFunc ;==>_Main ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _InetGetGUI ; AutoIt Version : v3.3.2.0 or higher ; Language ......: English ; Description ...: Download a file updating a GUICtrlCreateProgress. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ; _InetGetGUI: Download a file updating a GUICtrlCreateProgress. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; _ByteSuffix ......; Convert bytes to the largest measure. Thanks to Spliff69 - http://www.autoitscript.com/forum/topic/...ync-tool/page__view__findpost_ ; =============================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _InetGetGUI() ; Description ...: Download a file updating a GUICtrlCreateProgress(). ; Syntax.........: _InetGetGUI($sURL, $iLabel, $iProgress, $iButton, [$sDirectory = @ScriptDir]) ; $sURL - A valid URL that contains the filename too. ; $iLabel - ControlID of a GUICtrlCreateLabel. ; $iProgress - ControlID of a GUICtrlCreateProgress. ; $iButton - ControlID of a GUICtrlCreateButton. ; $sDirectory - [Optional] Directory of where to download to. Default = @ScriptDir ; Parameters ....: None ; Requirement(s).: v3.3.2.0 or higher ; Return values .: Success - Downloaded filename. ; Failure - Returns downloaded filename & sets @error = 1 (@extended = 0 if internal error or @extended = 1 if cancelled was selected.) ; Author ........: guinness ; Example........; Yes ;===================================================================================================================== Func _InetGetGUI($sURL, $iLabel, $iProgress, $iButton, $sDirectory = @ScriptDir) Local $hDownload, $iBytesRead = 0, $iError = 0, $iFileSize, $iPercentage, $iSpeed = 0, $iTimer = 0, $sFilePath, $sProgressText, $sRead = GUICtrlRead($iButton), $sSpeed $sFilePath = StringRegExpReplace($sURL, "^.*/", "") If @error Then Return SetError(1, 0, $sFilePath) EndIf $sDirectory = StringRegExpReplace($sDirectory, "[/]+z", "") & "" & $sFilePath $iFileSize = InetGetSize($sURL, 1) $hDownload = InetGet($sURL, $sDirectory, 0, 1) If @error Then Return SetError(1, $iError, $sFilePath) EndIf GUICtrlSetData($iButton, "&Cancel") $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s" $iTimer = TimerInit() While InetGetInfo($hDownload, 2) = 0 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $iButton GUICtrlSetData($iLabel, "Download Cancelled!") $iError = 1 ExitLoop EndSwitch $iBytesRead = InetGetInfo($hDownload, 0) $iPercentage = $iBytesRead * 100 / $iFileSize $sProgressText = "Downloading " & _ByteSuffix($iBytesRead, 0) & " Of " & _ByteSuffix($iFileSize, 0) & @LF & $sSpeed GUICtrlSetData($iLabel, $sProgressText) GUICtrlSetData($iProgress, $iPercentage) If TimerDiff($iTimer) > 1000 Then $sSpeed = "Current Speed: " & _ByteSuffix($iBytesRead - $iSpeed) & "/s" $iSpeed = $iBytesRead $iTimer = TimerInit() EndIf Sleep(100) WEnd InetClose($hDownload) GUICtrlSetData($iButton, $sRead) Return SetError($iError, $iError, $sFilePath) EndFunc ;==>_InetGetGUI ; #INTERNAL_USE_ONLY#============================================================================================================ Func _ByteSuffix($iBytes, $iRound = 2) Local $A, $aArray[9] = [" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"] While $iBytes > 1023 $A += 1 $iBytes /= 1024 WEnd Return Round($iBytes, $iRound) & $aArray[$A] EndFunc ;==>_ByteSuffix ; #INTERNAL_USE_ONLY#============================================================================================================My suggestion is don't have the download portion of the code in your main loop e.g. like I've done above. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
nend Posted November 20, 2011 Author Share Posted November 20, 2011 Hoi Guys, Thanks for all your reply. I will test it a lot more and probely it's a problem with my code or my Windows. Thanks anyway! 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