|
@@ -16,12 +16,12 @@ Type
|
|
FBackupFile : Boolean;
|
|
FBackupFile : Boolean;
|
|
Protected
|
|
Protected
|
|
// Needs overriding.
|
|
// Needs overriding.
|
|
- Procedure FTPDownload(Const URL : String; Dest : TStream); Virtual;
|
|
|
|
- Procedure HTTPDownload(Const URL : String; Dest : TStream); Virtual;
|
|
|
|
- Procedure FileDownload(Const URL : String; Dest : TStream); Virtual;
|
|
|
|
|
|
+ function FTPDownload(Const URL : String; Dest : TStream): Boolean; Virtual;
|
|
|
|
+ function HTTPDownload(Const URL : String; Dest : TStream): Boolean; Virtual;
|
|
|
|
+ function FileDownload(Const URL : String; Dest : TStream): Boolean; Virtual;
|
|
Public
|
|
Public
|
|
- Procedure Download(Const URL,DestFileName : String);
|
|
|
|
- Procedure Download(Const URL : String; Dest : TStream);
|
|
|
|
|
|
+ function Download(Const URL,DestFileName : String): Boolean;
|
|
|
|
+ function Download(Const URL : String; Dest : TStream): Boolean;
|
|
Property BackupFiles : Boolean Read FBackupFile Write FBackupFile;
|
|
Property BackupFiles : Boolean Read FBackupFile Write FBackupFile;
|
|
end;
|
|
end;
|
|
TBaseDownloaderClass = Class of TBaseDownloader;
|
|
TBaseDownloaderClass = Class of TBaseDownloader;
|
|
@@ -36,7 +36,7 @@ Type
|
|
procedure RegisterDownloader(const AName:string;Downloaderclass:TBaseDownloaderClass);
|
|
procedure RegisterDownloader(const AName:string;Downloaderclass:TBaseDownloaderClass);
|
|
function GetDownloader(const AName:string):TBaseDownloaderClass;
|
|
function GetDownloader(const AName:string):TBaseDownloaderClass;
|
|
|
|
|
|
-procedure DownloadFile(const RemoteFile,LocalFile:String; PackageManager: TpkgFPpkg);
|
|
|
|
|
|
+function DownloadFile(const RemoteFile,LocalFile:String; PackageManager: TpkgFPpkg): Boolean;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
implementation
|
|
@@ -72,14 +72,14 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-procedure DownloadFile(const RemoteFile,LocalFile:String; PackageManager: TpkgFPpkg);
|
|
|
|
|
|
+function DownloadFile(const RemoteFile,LocalFile:String; PackageManager: TpkgFPpkg): Boolean;
|
|
var
|
|
var
|
|
DownloaderClass : TBaseDownloaderClass;
|
|
DownloaderClass : TBaseDownloaderClass;
|
|
begin
|
|
begin
|
|
DownloaderClass:=GetDownloader(PackageManager.Options.GlobalSection.Downloader);
|
|
DownloaderClass:=GetDownloader(PackageManager.Options.GlobalSection.Downloader);
|
|
with DownloaderClass.Create(nil) do
|
|
with DownloaderClass.Create(nil) do
|
|
try
|
|
try
|
|
- Download(RemoteFile,LocalFile);
|
|
|
|
|
|
+ Result := Download(RemoteFile,LocalFile);
|
|
finally
|
|
finally
|
|
Free;
|
|
Free;
|
|
end;
|
|
end;
|
|
@@ -88,72 +88,81 @@ end;
|
|
|
|
|
|
{ TBaseDownloader }
|
|
{ TBaseDownloader }
|
|
|
|
|
|
-procedure TBaseDownloader.FTPDownload(const URL: String; Dest: TStream);
|
|
|
|
|
|
+function TBaseDownloader.FTPDownload(Const URL: String; Dest: TStream): Boolean;
|
|
begin
|
|
begin
|
|
Error(SErrNoFTPDownload);
|
|
Error(SErrNoFTPDownload);
|
|
|
|
+ Result := False;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TBaseDownloader.HTTPDownload(const URL: String; Dest: TStream);
|
|
|
|
|
|
+function TBaseDownloader.HTTPDownload(Const URL: String; Dest: TStream): Boolean;
|
|
begin
|
|
begin
|
|
Error(SErrNoHTTPDownload);
|
|
Error(SErrNoHTTPDownload);
|
|
|
|
+ Result := False;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TBaseDownloader.FileDownload(const URL: String; Dest: TStream);
|
|
|
|
|
|
+function TBaseDownloader.FileDownload(Const URL: String; Dest: TStream): Boolean;
|
|
|
|
|
|
Var
|
|
Var
|
|
FN : String;
|
|
FN : String;
|
|
F : TFileStream;
|
|
F : TFileStream;
|
|
|
|
|
|
begin
|
|
begin
|
|
|
|
+ Result := False;
|
|
URIToFilename(URL,FN);
|
|
URIToFilename(URL,FN);
|
|
If Not FileExists(FN) then
|
|
If Not FileExists(FN) then
|
|
Error(SErrNoSuchFile,[FN]);
|
|
Error(SErrNoSuchFile,[FN]);
|
|
F:=TFileStream.Create(FN,fmOpenRead);
|
|
F:=TFileStream.Create(FN,fmOpenRead);
|
|
Try
|
|
Try
|
|
Dest.CopyFrom(F,0);
|
|
Dest.CopyFrom(F,0);
|
|
|
|
+ Result := True;
|
|
Finally
|
|
Finally
|
|
F.Free;
|
|
F.Free;
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TBaseDownloader.Download(const URL, DestFileName: String);
|
|
|
|
|
|
+function TBaseDownloader.Download(Const URL, DestFileName: String): Boolean;
|
|
|
|
|
|
Var
|
|
Var
|
|
F : TFileStream;
|
|
F : TFileStream;
|
|
|
|
|
|
begin
|
|
begin
|
|
|
|
+ Result := False;
|
|
If FileExists(DestFileName) and BackupFiles then
|
|
If FileExists(DestFileName) and BackupFiles then
|
|
BackupFile(DestFileName);
|
|
BackupFile(DestFileName);
|
|
try
|
|
try
|
|
F:=TFileStream.Create(DestFileName,fmCreate);
|
|
F:=TFileStream.Create(DestFileName,fmCreate);
|
|
try
|
|
try
|
|
- Download(URL,F);
|
|
|
|
|
|
+ Result := Download(URL,F);
|
|
finally
|
|
finally
|
|
F.Free;
|
|
F.Free;
|
|
end;
|
|
end;
|
|
- except
|
|
|
|
- DeleteFile(DestFileName);
|
|
|
|
- raise;
|
|
|
|
|
|
+ finally
|
|
|
|
+ if not Result then
|
|
|
|
+ DeleteFile(DestFileName);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TBaseDownloader.Download(const URL: String; Dest: TStream);
|
|
|
|
|
|
+function TBaseDownloader.Download(Const URL: String; Dest: TStream): Boolean;
|
|
|
|
|
|
Var
|
|
Var
|
|
URI : TURI;
|
|
URI : TURI;
|
|
P : String;
|
|
P : String;
|
|
|
|
|
|
begin
|
|
begin
|
|
|
|
+ Result := False;
|
|
URI:=ParseURI(URL);
|
|
URI:=ParseURI(URL);
|
|
P:=URI.Protocol;
|
|
P:=URI.Protocol;
|
|
If CompareText(P,'ftp')=0 then
|
|
If CompareText(P,'ftp')=0 then
|
|
- FTPDownload(URL,Dest)
|
|
|
|
|
|
+ Result := FTPDownload(URL,Dest)
|
|
else if (CompareText(P,'http')=0) or (CompareText(P,'https')=0) then
|
|
else if (CompareText(P,'http')=0) or (CompareText(P,'https')=0) then
|
|
- HTTPDownload(URL,Dest)
|
|
|
|
|
|
+ Result := HTTPDownload(URL,Dest)
|
|
else if CompareText(P,'file')=0 then
|
|
else if CompareText(P,'file')=0 then
|
|
- FileDownload(URL,Dest)
|
|
|
|
|
|
+ Result := FileDownload(URL,Dest)
|
|
else
|
|
else
|
|
- Error(SErrUnknownProtocol,[P, URL]);
|
|
|
|
|
|
+ begin
|
|
|
|
+ Error(SErrUnknownProtocol,[P, URL]);
|
|
|
|
+ Result := False;
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|