best way to implement a download manager: extension #2

This is an extension of this question:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21865836.html
and is designed to add cancellation functionality to the download manager that is shown in the previous question.  

LVL 1
hibbidijiAsked:
Who is Participating?
 
TheRealLokiSenior DeveloperCommented:
I'll put this code in later, I'm just adding the "get filename from url" code, so don't want to mess with it just yet.
but this is the code you need to clear the top list, remove any temp files, and remove the downloaded file
comment out what you don't need.
double click on the TActionList, add a new action, call it what you like, double click onthe action, and put this code
now, add a TBitBtn (or use the popupmenu) and set the BitBtn or menu item's "action" prperty to your action.

    var
        i: integer;
        s: string;
    begin
        for i := pred(DownloadableFileList.Count) downto 0 do // count backwards when deleting
        begin
// delete the temp files
            s := ExtractFilePath(Paramstr(0)) + 'Temp\' + TDownloadableFile(DownloadableFileList[i]).TempFilename;
            if FileExists(S) then
              DeleteFile(S);
// delete the complete downloaded file
            s := ExtractFilePath(Paramstr(0)) + 'In\' + TDownloadableFile(DownloadableFileList[i]).Filename;
            if FileExists(S) then
              DeleteFile(S);

            DownloadableFileList.Delete(i); // this calls the destroy of the object
// because the download list matches the listview, we can safely assume they have the same index
            lvDownloadableFiles.Items[i].Delete;
        end;
    end;
0
 
hibbidijiAuthor Commented:
I tihnk it would be nice if the file was deleted if the download was cancelled - but this is not a 100% requirement.
0
 
hibbidijiAuthor Commented:
One additional comment:
I get acccess violations when closing the app when there are active downloads. - Are you seeing this same result?
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
TheRealLokiSenior DeveloperCommented:
ok, I've added the "cancel selected" and the "cancel all" by using the "selected" property of the listview.
during that I am checking the "state" property
I've also added pause/resume to the demo, so others can see how to do that in Indy. (setting the range properties of idhttp1.request)
There aren'e many examples of doing this, so I thought I'd add it.

And I am keeping track of the IdHTTP thread now, so you can see how I am cancelling it in the OnWork event.
I've also used a TActionList for the user commands
The access violations were just because teh indy thread was not being terminated. That has been changed by adding a Destroy method to the object. When the TObjectList frees its' objects, the destroy of each object gets called.

The tricky part is how to get the "filename" of an irregular url
e.g.
http://someserver.com/somefile.zip    is easy but
http://someserver.com/download.php?fileid=123   is not obvious.
I think I'll ask a question about that myself :-)
demo is here btw V1.1
https://sourceforge.net/projects/internetdemos/
0
 
hibbidijiAuthor Commented:
Loki,
I really appreciate the code, it is terrific - Is it possible to add CANCEL all to the list?  one where it will KILL the downloads and remove them from the downloads list?- the pause is fantastic and where it works it works very well - I just want to make sure I give my users the Cancel option.
0
 
hibbidijiAuthor Commented:
Loki,
Just for the sake of completeness, a clean up button would be very nice - something that would remove all the completed downloads  - I apologize if this is blatantly obvious to you - I'm a delphi newbie :)
0
 
hibbidijiAuthor Commented:
thankyou! I will keep an eye out for updates and implement this
Would you like the points now or after you're finished with your filename code?
0
 
TheRealLokiSenior DeveloperCommented:
If your question's answered, may as well close it off.
Hope you've learnt enough about indy, threads, and objects to keep you busy with your project.
Thanks for the Q's btw :-)
0
 
hibbidijiAuthor Commented:
Loki,
As you seem to be both brilliant at the delphi stuff and willing to tackle big problems, perhaps you might be interested in my latest issue:
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21873740.html

Hopefully you'll have time to look into it- I fear most people don't have the d2005 platform to work with though it seems you do.

0
 
TheRealLokiSenior DeveloperCommented:
sadly no. my current employer "Ol' Gorse Pockets" is afraid of spending money, so I'm stuck on older versions
(fyi: gorse is a weed with spikey thistles on it...). I'll have a poke at your question with a wildly blind stab in the dark though
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.