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:
wp_xxyyzz
2023-02-12 13:28:53 +00:00
parent df81462d09
commit f083df12eb
3 changed files with 42 additions and 7 deletions

View File

@ -29,8 +29,8 @@ type
FProxyPort: Integer; FProxyPort: Integer;
FProxyUsername: string; FProxyUsername: string;
FUseProxy: Boolean; FUseProxy: Boolean;
public protected
procedure DownloadFile(const Url: string; str: TStream); override; procedure InternalDownloadFile(const Url: string; str: TStream); override;
published published
property UseProxy: Boolean read FUseProxy write FUseProxy default false; property UseProxy: Boolean read FUseProxy write FUseProxy default false;
@ -55,7 +55,7 @@ end;
{ TMvDESynapse } { TMvDESynapse }
procedure TMvDESynapse.DownloadFile(const Url: string; str: TStream); procedure TMvDESynapse.InternalDownloadFile(const Url: string; str: TStream);
var var
FHttp: THTTPSend; FHttp: THTTPSend;
realURL: String; realURL: String;

View File

@ -37,8 +37,9 @@ type
FProxyUserName: String; FProxyUserName: String;
FProxyPassWord: String; FProxyPassWord: String;
{$IFEND} {$IFEND}
protected
procedure InternalDownloadFile(const Url: string; AStream: TStream); override;
public public
procedure DownloadFile(const Url: string; AStream: TStream); override;
{$IF FPC_FullVersion >= 30101} {$IF FPC_FullVersion >= 30101}
published published
property UseProxy: Boolean read FUseProxy write FUseProxy default false; property UseProxy: Boolean read FUseProxy write FUseProxy default false;
@ -63,7 +64,7 @@ uses
{ TMVDEFPC } { TMVDEFPC }
procedure TMVDEFPC.DownloadFile(const Url: string; AStream: TStream); procedure TMVDEFPC.InternalDownloadFile(const Url: string; AStream: TStream);
var var
http: TFpHttpClient; http: TFpHttpClient;
begin begin

View File

@ -23,18 +23,52 @@ type
{ TMvCustomDownloadEngine } { TMvCustomDownloadEngine }
TMvCustomDownloadEngine = class(TComponent) 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 public
procedure DownloadFile(const {%H-}Url: string; {%H-}AStream: TStream); virtual; procedure DownloadFile(const Url: string; AStream: TStream); virtual;
end; end;
implementation implementation
uses
StrUtils;
const
FILE_SCHEME = 'file://';
{ TMvCustomDownloadEngine } { TMvCustomDownloadEngine }
procedure TMvCustomDownloadEngine.DownloadFile(const Url: string; AStream: TStream); procedure TMvCustomDownloadEngine.DownloadFile(const Url: string; AStream: TStream);
begin 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;
end. end.