Forum > General

download multiple files

(1/2) > >>

Ericktux:
hello brothers good day, I am using the project of the friend "getmem" of the following link:
https://forum.lazarus.freepascal.org/index.php/topic,52773.0.html
it works perfect, download all files at once, but i have 2 questions:
1. how to detect when each download is finished and show in the virtualtreeview
2. how to download one at a time, then the next one and show it in the virtualtreeview


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses  Classes,  SysUtils,  Forms,  Controls,  Graphics,  uDownload,  //opensslsockets,  Dialogs, StdCtrls,  VirtualTrees; type  PData = ^TData;  TData = record    FUrl: String;    FName: String;    FState: String;  end;    { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    VST: TVirtualStringTree;    procedure Button1Click(Sender: TObject);    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);    procedure FormCreate(Sender: TObject);    procedure VSTGetNodeDataSize(Sender: TBaseVirtualTree;      var NodeDataSize: Integer);    procedure VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;      Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);  private    FDownload: TDownload;    procedure DoOnDownloadProgress(Sender: TObject; {%H-}AFrom, ATo: String; APos, ASize, AElapsed, ARemaining, ASpeed: LongInt);    procedure DoOnDownloadCompleted(Sender: TObject);  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);var  Data: Pdata;  Node: PVirtualNode;begin  VST.Clear;  VST.NodeDataSize := SizeOf(TData);   Node := VST.AddChild(nil);  Data := VST.GetNodeData(Node);  Data^.FUrl := 'https://d.winrar.es/d/103z1663045159/zqnGYe1hSuxmWneHCTGQ9Q/winrar-x64-611es.exe';  Data^.FName := 'winrar.exe';  Data^.FState := '';   Node := VST.AddChild(nil);  Data := VST.GetNodeData(Node);  Data^.FUrl := 'https://download.mozilla.org/?product=firefox-latest&os=win64&lang=es-MX';  Data^.FName := 'firefox.exe';  Data^.FState := '';   Node := VST.AddChild(nil);  Data := VST.GetNodeData(Node);  Data^.FUrl := 'https://ardownload2.adobe.com/pub/adobe/acrobat/win/AcrobatDC/2200220191/AcroRdrDCx642200220191_MUI.exe';  Data^.FName := 'adobe_reader.exe';  Data^.FState := '';   Node := VST.AddChild(nil);  Data := VST.GetNodeData(Node);  Data^.FUrl := 'https://mirror.netcologne.de/videolan.org/vlc/3.0.17.4/win64/vlc-3.0.17.4-win64.exe';  Data^.FName := 'vlc.exe';  Data^.FState := '';   Node := VST.AddChild(nil);  Data := VST.GetNodeData(Node);  Data^.FUrl := 'https://www.avast.com/es-ww/download-thank-you.php?product=FAV-AVAST&locale=es-ww&direct=1';  Data^.FName := 'avast.exe';  Data^.FState := '';   Node := VST.AddChild(nil);  Data := VST.GetNodeData(Node);  Data^.FUrl := 'https://mirrors.ucr.ac.cr/tdf/libreoffice/stable/7.4.1/win/x86_64/LibreOffice_7.4.1_Win_x64.msi';  Data^.FName := 'libre_office.msi';  Data^.FState := '';   Node := VST.AddChild(nil);  Data := VST.GetNodeData(Node);  Data^.FUrl := 'https://data-cdn.mbamupdates.com/web/mb4-setup-consumer/offline/mb4-setup-consumer-4.5.14.210-1.0.1751-1.0.59171.exe';  Data^.FName := 'malwarebytes.exe';  Data^.FState := '';   FDownload := nil;end; procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);begin    if Assigned(FDownload) then    FDownload.CancelDownoad;end; procedure TForm1.Button1Click(Sender: TObject);var   node : PVirtualNode ;   Data: PData;begin  // ShowMessage(ExtractFilePath(Application.ExeName));  node := VST.GetFirst ;  while assigned (node) do      begin      Data := VST.GetNodeData(Node);       {      ShowMessage(Data^.FUrl);      ShowMessage(Data^.FName);      ShowMessage(Data^.FState);      }       Data^.FState:='downloading';      FDownload := TDownload.Create;      FDownload.OnDownloadProgress := @DoOnDownloadProgress;      FDownload.OnDownloadCompleted := @DoOnDownloadCompleted;      FDownload.DownloadFile(Data^.FUrl, ExtractFilePath(Application.ExeName)+Data^.FName);        node := VST.GetNext(node) ;      end;      vst.setfocus;      vst.Refresh;end; procedure TForm1.VSTGetNodeDataSize(Sender: TBaseVirtualTree;  var NodeDataSize: Integer);begin  NodeDataSize := SizeOf(TData);end; procedure TForm1.VSTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;  Column: TColumnIndex; TextType: TVSTTextType; var CellText: String);var  Data: PData;begin  // si no existen estos codes, el resultado sera el texto    "NODE"  Data := VST.GetNodeData(Node);  case Column of    0: CellText := Data^.FUrl;    1: CellText := Data^.FName;    2: CellText := Data^.FState;  end;End; procedure TForm1.DoOnDownloadProgress(Sender: TObject; AFrom, ATo: String;  APos, ASize, AElapsed, ARemaining, ASpeed: LongInt);begin end; procedure TForm1.DoOnDownloadCompleted(Sender: TObject);begin     ShowMessage('Download completed!');end; end.
PD: I am using lazarus + virtualtreeview on win10x64
attached project example and image

DLL SSL 32 bit: https://packages.lazarus-ide.org/openssl-1.0.2j-i386-win32.zip
DLL SSL 64 bit: https://packages.lazarus-ide.org/openssl-1.0.2j-x64_86-win64.zip

paweld:
Something like this - in the FDownload class add the OriginalURL property (without fix the protocol), and in OnProgress and OnCopleted we only update the node for the compatible URL

Ericktux:
hello friend thanks for answering, I have tried it and in the first click of the button it downloads only the first one, but if I give it a second click it downloads all

paweld:
Try changing the line

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Data^.FState := Format('downloading (%f %%)', [APos * 100 / ASize]); to:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Data^.FState := Format('downloading (%d bytes)', [APos]);I didn't add checking if the size is different from 0

Ericktux:
hello friend, now it works thanks.  :)
One question, to be able to use the percentage "%" of the download, the variable "ASize" is used, which is the total file size, but it only appears for the first download?
is there a way to get the "ASize" value for all downloads??
Thanks for your time.

Navigation

[0] Message Index

[#] Next page

Go to full version