Link to home
Start Free TrialLog in
Avatar of hibbidiji
hibbidiji

asked on

best way to implement a download manager: extension

This is a question for TheRealLoki and is a reference to:
https://www.experts-exchange.com/questions/21854739/best-way-to-implement-a-download-manager.html

TheRealLoki,
Can you please post the extended code example you mentioned in your previous answer?
Avatar of hibbidiji
hibbidiji

ASKER

What I need to implement will ne in a new window and will use a gridview for it's display.  I will be calling these objects from my main form.
I also look forward to seeing the extended code, TheRealLoki answered my questions about Threads the other day and I found his code to be excellent, I read the previous question (in your question) and again his code is really nice to read.... learning alot from you TheRealLoki  =) keep up the good work.
I'm glad to see that these questions are helping other people - I always worry that I'm too specific :)
ASKER CERTIFIED SOLUTION
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
oh, for later versions, check the main page directly
https://sourceforge.net/projects/internetdemos/
Hey there,

Thanks for this, however I goto download it and it says invalid archive (16.6k big)
tired all the mirrors and get the same on all of them...  Will try again in 15 but just a heads up.
TheRealLoki,
I downloaded and opened the project in D2005 with Indy9.    On opening the project for the first time I got a couple messages about properties that did not exist for the client - these did not return (for me to report to you) on any subsequent open.    When attempting to compile, I get the following errors:

[Error] MultiFileDownloaderMain.pas(235): E2009 Incompatible types: 'Parameter lists differ'
[Error] MultiFileDownloaderMain.pas(236): E2009 Incompatible types: 'Parameter lists differ'
[Fatal Error] MultiFileDownloader.dpr(5): F2063 Could not compile used unit 'MultiFileDownloaderMain.pas'

It seems that trying to open the zip file with winzip gives that error, however winrar was OK.
I compiled the source ok and only got a res file error when opening first time (no issue though).

:D
you are not using Indy 9
you are most likely using indy 10, that is why I have the demos in specific releases, 1 for each environment I actually own.
so, "Indy 9 Delphi 7" and "Indy 10 Delphi 5"
I have just made an Indy 10 demo also
goto the main site, and click on download for the appropriate version you have
hmmm, maybe i should start zipping these up with an older pkzip just to be compatible with everyone. I use WinRar 8 for most things
My errors even with package titled:  
I take it back - I DID get an error when opening the indy10 packaged app but it compiled fine and runs like a champ :)
Fantastic work as usual - now I just need to read it enough times to understand it.   Kudos.
Loki,
If you are still watching this question, I would like to add pause and cancel functionality as well as cancel all downloads.    I'm happy to open a new question but I would appreciate assistance if you see this.
A good way to learn is first write down on paper how you think it would work in just enlish
ie
get thread name
pause/stop thread
display this to user

or something
then from there look at writing the code as to how you think it would work, and then post here
just a suggestion =)
You cannot just "pause", so I'm guessing you mean, stop, but allow this to be continued  (resumed) later.
note: not all servers support "resuming"

to "cancel" - all you need to do, is terminate the thread, and have the indy IdHTTP component stop somehow.
1 way to do this is raise an exception in the IdHTTP.OnWOrk event.
eg. in the IdHTTP.OnWork have some code like
if terminated then raise EUserAskedMeToCancel.create('cancelling.') else....
( declared as:  type EUserAskedMeToCancel = class Exception; // made my own exception to show cancelling )
This unfortunately means you will have to keep track of the thread
ie. instead of just
 TIndyInAThread.create(....
you will need to have
IndyInAThread: TIndyInAThread;
..
IndyInAThread := TIndyInAThread.Create(...
so that you can just say "IndyInAThread.Terminate;" to cancel.
perhaps put this in a "StopDownload" procedure of TDownloadableFile

so to stop all, you would do

    var
        i: integer;
    begin
        for i := 0 to pred(DownloadableFileList.Count) do
          TDownloadableFile(DownloadableFileList[i]).StopDownload;
    end;


Info I'm sure you'll want later...
To have Indy "resume" a download from a specifed point, you set the
Request.ContentRangeStart and Request.ContentRangeEnd values before you perform the GET()
It is possible to have 5 threads (for example) grabbing different parts of the same file. This is a common method to improve download speeds where servers throttle each connection. you have 5 connections, so you get the file faster. (assuming you have an internet connection faster than the server's "throttled" limit for each connection)
Note: some servers have caught on to this, and only allow 1 or 2 connections per IP adddress

Let me know if you want me to do a proper demo for you on this, but I know the above works
TheRealLoki:
In the interest of making sure this is done right, I've opened a new question. it is here:
https://www.experts-exchange.com/questions/21875700/best-way-to-implement-a-download-manager-extension-2.html

Your work is excellent and I hope you will be able to update your demo with this new functionality (just cancellation, not pause / resume)
I am working in d2005 with indy10