You've already forked lazarus-ccr
LazMapViewer: Improved handling of download uri protocol.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8702 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -24,7 +24,6 @@ type
|
|||||||
|
|
||||||
TMvCustomDownloadEngine = class(TComponent)
|
TMvCustomDownloadEngine = class(TComponent)
|
||||||
protected
|
protected
|
||||||
function GetLocalFileName(const Url: String): String;
|
|
||||||
procedure InternalDownloadFile(const Url: String; AStream: TStream); virtual; abstract;
|
procedure InternalDownloadFile(const Url: String; AStream: TStream); virtual; abstract;
|
||||||
procedure LoadFromLocalFile(const AFileName: String; AStream: TStream);
|
procedure LoadFromLocalFile(const AFileName: String; AStream: TStream);
|
||||||
public
|
public
|
||||||
@@ -35,28 +34,20 @@ type
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
StrUtils;
|
URIParser;
|
||||||
|
|
||||||
const
|
|
||||||
FILE_SCHEME = 'file://';
|
|
||||||
|
|
||||||
{ TMvCustomDownloadEngine }
|
{ TMvCustomDownloadEngine }
|
||||||
|
|
||||||
procedure TMvCustomDownloadEngine.DownloadFile(const Url: string; AStream: TStream);
|
procedure TMvCustomDownloadEngine.DownloadFile(const Url: string; AStream: TStream);
|
||||||
|
var
|
||||||
|
fn: String;
|
||||||
begin
|
begin
|
||||||
if AnsiStartsText(FILE_SCHEME, Url) then
|
if URIToFileName(Url, fn) then
|
||||||
LoadFromLocalFile(GetLocalFileName(Url), AStream)
|
LoadFromLocalFile(fn, AStream)
|
||||||
else
|
else
|
||||||
InternalDownloadFile(Url, AStream);
|
InternalDownloadFile(Url, AStream);
|
||||||
end;
|
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;
|
procedure TMvCustomDownloadEngine.LoadFromLocalFile(const AFileName: String;
|
||||||
AStream: TStream);
|
AStream: TStream);
|
||||||
var
|
var
|
||||||
|
@@ -487,7 +487,7 @@ begin
|
|||||||
Env := TEnvTile(Data);
|
Env := TEnvTile(Data);
|
||||||
Id := Env.Tile;
|
Id := Env.Tile;
|
||||||
MapO := Env.Win.MapProvider;
|
MapO := Env.Win.MapProvider;
|
||||||
if Assigned(MapO) then
|
if Assigned(MapO) and Assigned(Cache) then
|
||||||
begin
|
begin
|
||||||
if not Cache.InCache(MapO, Id) then
|
if not Cache.InCache(MapO, Id) then
|
||||||
begin
|
begin
|
||||||
@@ -500,7 +500,7 @@ begin
|
|||||||
try
|
try
|
||||||
try
|
try
|
||||||
FDownloadEngine.DownloadFile(Url, lStream);
|
FDownloadEngine.DownloadFile(Url, lStream);
|
||||||
Cache.Add(MapO, Id, lStream);
|
if Assigned(Cache) then Cache.Add(MapO, Id, lStream);
|
||||||
except
|
except
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
|
@@ -61,7 +61,7 @@ Type
|
|||||||
function GetCachePath: String;
|
function GetCachePath: String;
|
||||||
function GetCenter: TRealPoint;
|
function GetCenter: TRealPoint;
|
||||||
function GetDownloadEngine: TMvCustomDownloadEngine;
|
function GetDownloadEngine: TMvCustomDownloadEngine;
|
||||||
function GetDrawingEngine: TMvCustoMDrawingEngine;
|
function GetDrawingEngine: TMvCustomDrawingEngine;
|
||||||
function GetMapProvider: String;
|
function GetMapProvider: String;
|
||||||
function GetOnCenterMove: TNotifyEvent;
|
function GetOnCenterMove: TNotifyEvent;
|
||||||
function GetOnChange: TNotifyEvent;
|
function GetOnChange: TNotifyEvent;
|
||||||
|
Reference in New Issue
Block a user