You've already forked lazarus-ccr
LazMapViewer: Extend download engines to be able to handle local files (https://www.lazarusforum.de/viewtopic.php?f=18&t=14790).
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8701 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -29,8 +29,8 @@ type
|
||||
FProxyPort: Integer;
|
||||
FProxyUsername: string;
|
||||
FUseProxy: Boolean;
|
||||
public
|
||||
procedure DownloadFile(const Url: string; str: TStream); override;
|
||||
protected
|
||||
procedure InternalDownloadFile(const Url: string; str: TStream); override;
|
||||
|
||||
published
|
||||
property UseProxy: Boolean read FUseProxy write FUseProxy default false;
|
||||
@ -55,7 +55,7 @@ end;
|
||||
|
||||
{ TMvDESynapse }
|
||||
|
||||
procedure TMvDESynapse.DownloadFile(const Url: string; str: TStream);
|
||||
procedure TMvDESynapse.InternalDownloadFile(const Url: string; str: TStream);
|
||||
var
|
||||
FHttp: THTTPSend;
|
||||
realURL: String;
|
||||
|
@ -37,8 +37,9 @@ type
|
||||
FProxyUserName: String;
|
||||
FProxyPassWord: String;
|
||||
{$IFEND}
|
||||
protected
|
||||
procedure InternalDownloadFile(const Url: string; AStream: TStream); override;
|
||||
public
|
||||
procedure DownloadFile(const Url: string; AStream: TStream); override;
|
||||
{$IF FPC_FullVersion >= 30101}
|
||||
published
|
||||
property UseProxy: Boolean read FUseProxy write FUseProxy default false;
|
||||
@ -63,7 +64,7 @@ uses
|
||||
|
||||
{ TMVDEFPC }
|
||||
|
||||
procedure TMVDEFPC.DownloadFile(const Url: string; AStream: TStream);
|
||||
procedure TMVDEFPC.InternalDownloadFile(const Url: string; AStream: TStream);
|
||||
var
|
||||
http: TFpHttpClient;
|
||||
begin
|
||||
|
@ -23,18 +23,52 @@ type
|
||||
{ TMvCustomDownloadEngine }
|
||||
|
||||
TMvCustomDownloadEngine = class(TComponent)
|
||||
protected
|
||||
function GetLocalFileName(const Url: String): String;
|
||||
procedure InternalDownloadFile(const Url: String; AStream: TStream); virtual; abstract;
|
||||
procedure LoadFromLocalFile(const AFileName: String; AStream: TStream);
|
||||
public
|
||||
procedure DownloadFile(const {%H-}Url: string; {%H-}AStream: TStream); virtual;
|
||||
procedure DownloadFile(const Url: string; AStream: TStream); virtual;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
StrUtils;
|
||||
|
||||
const
|
||||
FILE_SCHEME = 'file://';
|
||||
|
||||
{ TMvCustomDownloadEngine }
|
||||
|
||||
procedure TMvCustomDownloadEngine.DownloadFile(const Url: string; AStream: TStream);
|
||||
begin
|
||||
// to be overridden...
|
||||
if AnsiStartsText(FILE_SCHEME, Url) then
|
||||
LoadFromLocalFile(GetLocalFileName(Url), AStream)
|
||||
else
|
||||
InternalDownloadFile(Url, AStream);
|
||||
end;
|
||||
|
||||
// Chops the "file://" off of a local file name.
|
||||
// Note: Does not check whether the Url really begins with "file://".
|
||||
function TMvCustomDownloadEngine.GetLocalFileName(const Url: String): String;
|
||||
begin
|
||||
Result := Copy(Url, Length(FILE_SCHEME) + 1, MaxInt);
|
||||
end;
|
||||
|
||||
procedure TMvCustomDownloadEngine.LoadFromLocalFile(const AFileName: String;
|
||||
AStream: TStream);
|
||||
var
|
||||
fs: TFileStream;
|
||||
begin
|
||||
fs := TFileStream.Create(AFileName, fmOpenRead or fmShareDenyWrite);
|
||||
try
|
||||
AStream.CopyFrom(fs, fs.Size);
|
||||
AStream.Position := 0;
|
||||
finally
|
||||
fs.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Reference in New Issue
Block a user