I decided to rewrite this to address the issues that seemed to occur in my old one when used with Windows 7. So far this one indeed seems to work with Win7, albeit I haven't tested it with any other OS's so if you can do that and drop me a line telling whether there are any issues I would much appreciate it
Update as of 2012-12-30
----------------------------------------
The plugin has been changed a bit in a way that breaks backwards compatibility.
This is mainly through the introduction of manual resource freeing which will have to be carried out for each download once it is finished. This gives you various perks, most importantly it removes the need for the plugin to give extra time to download threads to finish which in turn led to slowing down things when you had lots of downloads. It also allows you to properly query the "finished" status of a download (in the previous release all such functions would immediately report zeroes or "no such download exists") for as long as you see fit.
Added functions:
DELETE DOWNLOAD
GET DOWNLOAD ERROR
GET DOWNLOAD ERROR MESSAGE
SET MAXIMUM DOWNLOAD THREADS
All of these have their own page in the documentation. Some other pages have been updated as well.
----------------------------------------
Features
♦ Asynchronous download of an arbitrary number of files.
♦ Download progress can be polled in realtime (for example number of bytes downloaded so far and total download size).
♦ Possibility to ignore cached downloads to ensure that the user always gets the latest version of a file.
Download
Verified to work on
♦ Windows 8 Professional
♦ Windows 7 Professional
♦ Windows XP SP2
Simple demo
remstart
***************************************
* Simple demonstration of downloading *
* multiple simultaneous files with *
* progress tracking. *
* *
* -Rudolpho 2012-12-30 *
***************************************
remend
` Basic setup
set display mode 640, 480, 32
set window size 640, 480
`make directory "downloads"
set dir "C:\Users\Joel\Documents\Visual Studio 2010\Projects\Plugins\DownloadPlugin v2\Downloader Test Project\dl\tmp"
sync on : sync rate 0
` Let's download three files simultaneously (and please don't overuse this demo with my files as that will exhaust my poor bandwidth,
` just change the target url's ;-))
dim download(3) as dword
download(0) = download file("http://files.squarefantasy.net/tmp/Large_File_1.dat", "Large_File_1.dat", 1) ` We set the purgeCache flag to true to ensure that
download(1) = download file("http://files.squarefantasy.net/tmp/Large_File_2.dat", "Large_File_2.dat", 1) ` we get the full file downloaded each time instead
download(2) = download file("http://files.squarefantasy.net/tmp/Large_File_3.dat", "Large_File_3.dat", 1) ` of pulling it from cache if it's been previously accessed
` Since we didn't set the autostart flag above the downloads should have started automatically by the time we get here.
` Let's show some rudimentary interface detailing the download process of the files
while not (is download finished(download(0)) and is download finished(download(1)) and is download finished(download(2)))
cls 0
for dl = 0 to 2
offset = dl * 160
text 10, offset, get download status text(download(dl))
box 18, offset + 18, 222, offset + 42, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
box 19, offset + 19, 221, offset + 41, 0xff000000, 0xff000000, 0xff000000, 0xff000000
percentage# = get download percentage(download(dl))
edgeCol = 0xff000000 || (lerp_byte(0xff, 0, percentage# / 100.0) << 16) || (lerp_byte(0, 0xff, percentage# / 100.0) << 8)
box 20, offset + 20, 20 + (2 * get download percentage(download(dl))), offset + 40, 0xffff0000, 0xffff0000, edgeCol, edgeCol
text 20, offset + 60, get download status description(download(dl))
` Has this download finished? If so it might be because of an error
if is download finished(dl) and get download error(dl) <> 0
text 20, offset + 44, "Download failed: " + get download error message(dl)
endif
next dl
sync
endwhile
` We have to delete the download trackers to avoid memory leaks
delete download download(0)
delete download download(1)
delete download download(2)
wait key
end
` Linear interpolation of a single byte (used for a colour channel here)
function lerp_byte(a as byte, b as byte, l as float)
a = a + ((b - a) * l)
endfunction a
Notes
The number of possible simultaneous downloads may vary from system to system. This seems to be bound to the number of processor cores available.
"Why do programmers get Halloween and Christmas mixed up?" Because Oct(31) = Dec(25)