|
@@ -9,10 +9,13 @@ uses
|
|
|
|
|
|
Type
|
|
Type
|
|
|
|
|
|
- { TBasePackageDownloader }
|
|
|
|
|
|
+ { TBaseDownloader }
|
|
|
|
|
|
- TBasePackageDownloader = Class(TPackageHandler)
|
|
|
|
|
|
+ TBaseDownloader = Class(TComponent)
|
|
|
|
+ Private
|
|
|
|
+ FBackupFile : Boolean;
|
|
Protected
|
|
Protected
|
|
|
|
+ Procedure BackupFile(Const FileName : String);
|
|
// Needs overriding.
|
|
// Needs overriding.
|
|
Procedure FTPDownload(Const URL : String; Dest : TStream); Virtual;
|
|
Procedure FTPDownload(Const URL : String; Dest : TStream); Virtual;
|
|
Procedure HTTPDownload(Const URL : String; Dest : TStream); Virtual;
|
|
Procedure HTTPDownload(Const URL : String; Dest : TStream); Virtual;
|
|
@@ -20,29 +23,46 @@ Type
|
|
Public
|
|
Public
|
|
Procedure Download(Const URL,DestFileName : String);
|
|
Procedure Download(Const URL,DestFileName : String);
|
|
Procedure Download(Const URL : String; Dest : TStream);
|
|
Procedure Download(Const URL : String; Dest : TStream);
|
|
|
|
+ Property BackupFiles : Boolean Read FBackupFile Write FBackupFile;
|
|
|
|
+ end;
|
|
|
|
+ TBaseDownloaderClass = Class of TBaseDownloader;
|
|
|
|
+
|
|
|
|
+ { TDownloadPackage }
|
|
|
|
+
|
|
|
|
+ TDownloadPackage = Class(TPackagehandler)
|
|
|
|
+ Public
|
|
|
|
+ Function Execute(const Args:TActionArgs):boolean;override;
|
|
end;
|
|
end;
|
|
- TBasePackageDownloaderClass = Class of TBasePackageDownloader;
|
|
|
|
|
|
|
|
Var
|
|
Var
|
|
- DownloaderClass : TBasePackageDownloaderClass;
|
|
|
|
|
|
+ DownloaderClass : TBaseDownloaderClass;
|
|
|
|
|
|
implementation
|
|
implementation
|
|
|
|
|
|
uses pkgmessages,uriparser;
|
|
uses pkgmessages,uriparser;
|
|
|
|
|
|
-{ TBasePackageDownloader }
|
|
|
|
|
|
+{ TBaseDownloader }
|
|
|
|
+
|
|
|
|
+procedure TBaseDownloader.BackupFile(const FileName: String);
|
|
|
|
+Var
|
|
|
|
+ BFN : String;
|
|
|
|
+begin
|
|
|
|
+ BFN:=FileName+'.bak';
|
|
|
|
+ If not RenameFile(FileName,BFN) then
|
|
|
|
+ Error(SErrBackupFailed,[FileName,BFN]);
|
|
|
|
+end;
|
|
|
|
|
|
-procedure TBasePackageDownloader.FTPDownload(const URL: String; Dest: TStream);
|
|
|
|
|
|
+procedure TBaseDownloader.FTPDownload(const URL: String; Dest: TStream);
|
|
begin
|
|
begin
|
|
Error(SErrNoFTPDownload);
|
|
Error(SErrNoFTPDownload);
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TBasePackageDownloader.HTTPDownload(const URL: String; Dest: TStream);
|
|
|
|
|
|
+procedure TBaseDownloader.HTTPDownload(const URL: String; Dest: TStream);
|
|
begin
|
|
begin
|
|
Error(SErrNoHTTPDownload);
|
|
Error(SErrNoHTTPDownload);
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TBasePackageDownloader.FileDownload(const URL: String; Dest: TStream);
|
|
|
|
|
|
+procedure TBaseDownloader.FileDownload(const URL: String; Dest: TStream);
|
|
|
|
|
|
Var
|
|
Var
|
|
URI : TURI;
|
|
URI : TURI;
|
|
@@ -62,7 +82,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TBasePackageDownloader.Download(const URL, DestFileName: String);
|
|
|
|
|
|
+procedure TBaseDownloader.Download(const URL, DestFileName: String);
|
|
|
|
|
|
Var
|
|
Var
|
|
F : TFileStream;
|
|
F : TFileStream;
|
|
@@ -78,7 +98,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TBasePackageDownloader.Download(const URL: String; Dest: TStream);
|
|
|
|
|
|
+procedure TBaseDownloader.Download(const URL: String; Dest: TStream);
|
|
|
|
|
|
Var
|
|
Var
|
|
URI : TURI;
|
|
URI : TURI;
|
|
@@ -97,9 +117,24 @@ begin
|
|
Error(SErrUnknownProtocol,[P]);
|
|
Error(SErrUnknownProtocol,[P]);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+
|
|
|
|
+{ TDownloadPackage }
|
|
|
|
+
|
|
|
|
+function TDownloadPackage.Execute(const Args:TActionArgs):boolean;
|
|
|
|
+begin
|
|
|
|
+ with DownloaderClass.Create(nil) do
|
|
|
|
+ try
|
|
|
|
+ Download(CurrentPackage.URL,PackageArchive);
|
|
|
|
+ finally
|
|
|
|
+ Free;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+
|
|
initialization
|
|
initialization
|
|
// Default value.
|
|
// Default value.
|
|
- DownloaderClass := TBasePackageDownloader;
|
|
|
|
|
|
+ DownloaderClass := TBaseDownloader;
|
|
|
|
|
|
|
|
+ RegisterPkgHandler('downloadpackage',TDownloadPackage);
|
|
end.
|
|
end.
|
|
|
|
|