AutoHotkey Community

It is currently May 27th, 2012, 6:47 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: April 20th, 2009, 11:48 am 
Offline

Joined: November 30th, 2008, 12:11 am
Posts: 18
Hi Guys,
I noticed a bug several times during the last days work:
If I want to get the size of a file (GetFileSize) with a label, which is called with the SetTimer-Command, I works the first two times but afterwards the Size isn't recognized anymore.
This happens with nearly every Progressbar which should show your Download for example. It stucks at 15% (depending on the file). Sometimes it only shows the progress until 7% or 13% (so it isn't always the same point), then the script crashes.
The file gets downloaded anyway and the progressbar shows 100% suddenly.

The strange thing: If I right-click the file OR refresh the folder, the file gets loaded into (context menu>refresh), the progressbar notices that and shows the correct percentage (afterwards it crashes again).

It doesn't need to be a progressbar, any display-technique collapses.

If I take a relatively high SetTimer-time (5000ms for example), the script works a bit longer (it shows three or four times the correct filesize); crashes later.

I wrote an little example which crashes, if I wanna use it:
Code:
#Persistent
Gui, Add, Edit, vEdit w300 h300
Gui, Show, w300 h300 center, GetFileSize-bug
SetTimer, Checkfilesize, 500
UrlDownloadToFile, http://91.121.68.38/~web2/xhaozaoj/Umani_1080p_x264.avi, %A_Desktop%/Umani.avi

Checkfilesize:
FileGetSize, filesize, %A_Desktop%/Umani.avi, K
  If Errorlevel != 0
    msgbox, 0, Error, Can't get the Filesize ;this isn't shown by the script :(
Guicontrol, Text, Edit, %filesize%
return
So the problem is the GetFileSize-Command and not the SetTimer-Command, I think. It's a Vista-bug actually. I tried some workarounds, like refreshing the folder during that getfilesize-sequence etc., but I didn't make it (maybe u know some help).

Will there be a bugfix or anything?

Thanks,
ease

PS: I hope this bug isn't known yet; I searched the forum well.
edit: I missed my system-status: I got all windows updates, for sure! I got a quad-core PC, so it shouldn't be any kind of overload.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2009, 12:57 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Strange behavior. I can't think of any obvious explanation, but here's the main part of the code behind FileGetSize:
Code:
; Don't use CreateFile() & FileGetSize() because they will fail to work on a file that's in use.
; Research indicates that this method has no disadvantages compared to the other method.
WIN32_FIND_DATA found_file;
HANDLE file_search = FindFirstFile(aFilespec, &found_file);
if (file_search == INVALID_HANDLE_VALUE)
   return OK;  // Let ErrorLevel Tell the story.
FindClose(file_search);
unsigned __int64 size = (found_file.nFileSizeHigh * (unsigned __int64)MAXDWORD) + found_file.nFileSizeLow;

You could try using DllCall+CreateFile+FileGetSize, though the comment in the code above indicates that it might not work if the file is "in use".


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2009, 2:22 pm 
Offline

Joined: November 30th, 2008, 12:11 am
Posts: 18
Thx for the Code, Chris.
I've read about the "DllCall+CreateFile+FileGetSize-way" anywhere in this forum.
I'll will check this possibility as well as search for reasons for the malfunction on my own PC, if this isn't a known bug, reported of different people, yet.

I will post any solution I find :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject: wow
PostPosted: April 24th, 2009, 8:18 am 
I'm seeing this same bug in the same exact situation.

If I have the folder open and I hit refresh the progress bar updates, but other wise it will remain at 0%. :/

Really wish this would work.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 17th, 2009, 7:57 pm 
Offline

Joined: November 30th, 2008, 12:11 am
Posts: 18
any news about it?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 20th, 2009, 3:11 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
As implied earlier, the problem doesn't seem to occur on Windows XP (at least I can reproduce it on XP, though I waited only a few minutes for a few megabytes to download).

Maybe try saving to a folder other than the desktop. Also, I notice the example code at the top uses forward-slashes in the file paths. Although I doubt it would matter, you could try changing them to backslashes.

Finally, you could try running the script as administrator in case it makes any difference:

On Windows Vista, some scripts might require administrator privileges to function properly (such as a script that interacts with a process or window that is run as administrator). To achieve this, add the following at the top of the script (this would need to be enhanced to work for compiled scripts and/or to pass parameters):
Code:
if not A_IsAdmin
{
   DllCall("shell32\ShellExecuteA", uint, 0, str, "RunAs", str, A_AhkPath
      , str, """" . A_ScriptFullPath . """", str, A_WorkingDir, int, 1)
   ExitApp
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 20th, 2009, 12:26 pm 
Offline

Joined: November 30th, 2008, 12:11 am
Posts: 18
Thanks for your answer!!!

I searched around a bit and found the following.
This code works for XP, I believe (I'm using vista). It does probably refresh the explorer.
Code:
WinGetClass, eh_Class,A ;dunno if this is needed..
Else PostMessage, 0x111, 28931,,, A ;REFRESH!
..and this refreshes the desktop in vista:
Code:
PostMessage, 0x111, 28931,,, ahk_class Progman
PostMessage, 0x111, 28931,,, ahk_class CabinetWClass
so we got a little workaround.

and this should work if you dont mind an open folder:
Code:
Run, YOURFOLDERHERE,,,OutputVarPID
SendMessage, 0x1A, 42,,, ahk_id %OutputVarPID%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 15th, 2011, 9:10 pm 
Offline

Joined: October 5th, 2007, 10:41 pm
Posts: 11
In AutoHotkey_L you can use "FileOpen()" (This will make it notice the file size change) to get FileGetSize to work in Windows 7.
You have to set the flag to "r" (read):

Code:
FileOpen(File, "r")
FileGetSize, %File%, K


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2011, 6:56 am 
Offline

Joined: June 10th, 2010, 10:19 pm
Posts: 27
I have had partial success to the point where i cannot duplicate it, but one person did duplicate it after after several tries. before you call getfile size, get the attributes, save them, and then set the attributes u just saved back unto the file. It makes windows re-cache the file. if that doesn't work get the atribs, delete them all, then set them again; but the first approach did it for me


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group