Posts: 795
Threads: 136
Joined: Feb 2009
Hi gintaras, hi all
i want to download a file via the IntGetFile function, and have the macro stopped until the file is enterely downloaded in the
destination folder.
I tried a rep loop for file size (something like this)
rep
__if(filesize>0) break
but it does not work...
In other words, how to wait for a file without using the trigger feature?
Any suggestion?
Thanks
Posts: 1,000
Threads: 253
Joined: Feb 2008
IntGetFile waits?
Function Function137
str files=
;http://google-maps-icons.googlecode.com/files/video.png
;http://google-maps-icons.googlecode.com/files/audio.png
;http://google-maps-icons.googlecode.com/files/text.png
;http://google-maps-icons.googlecode.com/files/photoupright.png
;http://google-maps-icons.googlecode.com/files/toilets.png
;http://google-maps-icons.googlecode.com/files/wifi.png
;http://google-maps-icons.googlecode.com/files/disability.png
;http://google-maps-icons.googlecode.com/files/winetasting.png
;http://google-maps-icons.googlecode.com/files/fire.png
ARRAY(str) aFiles=files
for int'i 0 aFiles.len
,out "getting file"
,str localfile.getfilename(aFiles[i] 1)
,localfile-"$desktop$/"
,IntGetFile aFiles[i] localfile 16
,if(!dir(localfile))
,,out "THIS SHOULD NEVER OUTPUT"
,out "This won't fire until the file is downloaded"
Posts: 12,147
Threads: 143
Joined: Dec 2002
IntGetFile is synchronous. It waits until finished. Don't need another 'wait for file' function.
If need to wait in some other context:
Repeatedly try to open the file with 'write' access until success.
I'll create such function if you need.
Or you can Open the file with CFileInterlocked Collected QM apps, functions, samples
Posts: 795
Threads: 136
Joined: Feb 2009
First thanks for input both.
The real problem is that i *must* wait for the download to continue the macro.
But when the downloads begins, the file is created with 0 byte size, so the workaround is fooled
as it does not wait for the download to complete.
Maybe a lock test...but i fail at that.
If you can steer me Gintaras.
Posts: 12,147
Threads: 143
Joined: Dec 2002
If you download it with IntGetFile from other thread, you can use global variable.
int+ g_downloaded=0
IntGetFile ...
g_downloaded=1
in other thread wait until g_downloaded is 1.
int+ g_downloaded
wait 0 V g_downloaded
-----------------------------------
This is more universal code. Works with files downloaded with QM, Internet Explorer, Firefox, etc.
Function wait_file
str s="D:\downloads\quickmac.exe"
Dir d
rep
,if d.dir(s) and d.FileSize
,,__HFile f.Create(s OPEN_EXISTING 0 FILE_SHARE_READ); err
,,if(f) f.Close; break
,0.5
mes "downloaded"
;info: the d.FileSize is for Firefox, which at first creates empty file, then downloads to other file...
test
Macro Macro1446
str s="D:\downloads\quickmac.exe"
IntGetFile "http://www.quickmacros.com/quickmac.exe" s 16
Posts: 795
Threads: 136
Joined: Feb 2009
yep the "universal" code did it.
Isn't there a more simplier way, like a NotLock function anywhere?
File f
if(f.NotLock).....
BTW is possible to disable the mouse cursor for a while (hiding it or so)??
Posts: 12,147
Threads: 143
Joined: Dec 2002
Function WaitForFileNotLocked
;/
function $_file
opt waitmsg -1
Dir d
rep
,if d.dir(_file) and d.FileSize
,,__HFile f.Create(_file OPEN_EXISTING 0 FILE_SHARE_READ); err
,,if(f) f.Close; break
,0.5
example
Function wait_file2
str s="D:\downloads\quickmac.exe"
WaitForFileNotLocked s
mes "downloaded"
Posts: 12,147
Threads: 143
Joined: Dec 2002
I think you can hide cursor only in windows of current thread. Not sure.
Posts: 795
Threads: 136
Joined: Feb 2009
Thanks i'll check that cursor thing.
Why doesn't that code work:
i created and opened a file in notepad (so it is supposed to be locked).
File.f ("sometextfile.txt")
rep
,if(!f.write("crap") continue
,break (<----- when i close notepad it should be writable and i must get out the rep loop)
I think it's an indentation issue..
i sometimes miss the simplicity of the While and Until functions.........
Posts: 12,147
Threads: 143
Joined: Dec 2002
Notepad does not lock file. Maybe Word does.
In rep must be Open(), not Write().
Posts: 795
Threads: 136
Joined: Feb 2009
Aside the fact that i must open a file before writing to  i'm totally lost with the
rep structure
File f.Open("z:\Document.txt" "w+")
rep
,if(!f.Write("line1[]line2[]line3")) continue; else break
,_i+1
what's wrong in my syntax?
Posts: 12,147
Threads: 143
Joined: Dec 2002
Most File functions throw error if failed.
But normally there is no reason why Write() could fail.
Macro Macro1448
File f.Open("$Desktop$\Document.txt" "w+")
rep
,f.Write("line1[]line2[]line3[]")
,err break
,_i+1
,if(_i>100) break
|