Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

best way to implement a download manager: extension #2

Posted on 2006-06-05
10
Medium Priority
?
319 Views
Last Modified: 2013-12-03
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.  

0
Comment
Question by:hibbidiji
  • 6
  • 4
10 Comments
 
LVL 1

Author Comment

by:hibbidiji
ID: 16838253
I tihnk it would be nice if the file was deleted if the download was cancelled - but this is not a 100% requirement.
0
 
LVL 1

Author Comment

by:hibbidiji
ID: 16838262
One additional comment:
I get acccess violations when closing the app when there are active downloads. - Are you seeing this same result?
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16839735
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:hibbidiji
ID: 16839803
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
 
LVL 1

Author Comment

by:hibbidiji
ID: 16839817
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
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 2000 total points
ID: 16839891
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
 
LVL 1

Author Comment

by:hibbidiji
ID: 16839897
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
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16839947
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
 
LVL 1

Author Comment

by:hibbidiji
ID: 16847697
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
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16847755
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question