From e343a8232f42dc21830f109ee3b497da63101d95 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 12 Feb 2023 17:39:04 +0000 Subject: [PATCH] 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 --- .../lazmapviewer/source/mvdownloadengine.pas | 19 +++++-------------- components/lazmapviewer/source/mvengine.pas | 4 ++-- .../lazmapviewer/source/mvmapviewer.pas | 2 +- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/components/lazmapviewer/source/mvdownloadengine.pas b/components/lazmapviewer/source/mvdownloadengine.pas index 33829a89e..91513d800 100644 --- a/components/lazmapviewer/source/mvdownloadengine.pas +++ b/components/lazmapviewer/source/mvdownloadengine.pas @@ -24,7 +24,6 @@ type 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 @@ -35,28 +34,20 @@ type implementation uses - StrUtils; - -const - FILE_SCHEME = 'file://'; + URIParser; { TMvCustomDownloadEngine } procedure TMvCustomDownloadEngine.DownloadFile(const Url: string; AStream: TStream); +var + fn: String; begin - if AnsiStartsText(FILE_SCHEME, Url) then - LoadFromLocalFile(GetLocalFileName(Url), AStream) + if URIToFileName(Url, fn) then + LoadFromLocalFile(fn, 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 diff --git a/components/lazmapviewer/source/mvengine.pas b/components/lazmapviewer/source/mvengine.pas index a740baf82..8720f84c3 100644 --- a/components/lazmapviewer/source/mvengine.pas +++ b/components/lazmapviewer/source/mvengine.pas @@ -487,7 +487,7 @@ begin Env := TEnvTile(Data); Id := Env.Tile; MapO := Env.Win.MapProvider; - if Assigned(MapO) then + if Assigned(MapO) and Assigned(Cache) then begin if not Cache.InCache(MapO, Id) then begin @@ -500,7 +500,7 @@ begin try try FDownloadEngine.DownloadFile(Url, lStream); - Cache.Add(MapO, Id, lStream); + if Assigned(Cache) then Cache.Add(MapO, Id, lStream); except end; finally diff --git a/components/lazmapviewer/source/mvmapviewer.pas b/components/lazmapviewer/source/mvmapviewer.pas index aaaa34e48..680f4ce67 100644 --- a/components/lazmapviewer/source/mvmapviewer.pas +++ b/components/lazmapviewer/source/mvmapviewer.pas @@ -61,7 +61,7 @@ Type function GetCachePath: String; function GetCenter: TRealPoint; function GetDownloadEngine: TMvCustomDownloadEngine; - function GetDrawingEngine: TMvCustoMDrawingEngine; + function GetDrawingEngine: TMvCustomDrawingEngine; function GetMapProvider: String; function GetOnCenterMove: TNotifyEvent; function GetOnChange: TNotifyEvent;