2018-04-16 22:10:14 +00:00
|
|
|
{ Map Viewer Download Engine
|
2018-04-16 13:59:19 +00:00
|
|
|
Copyright (C) 2011 Maciej Kaczkowski / keit.co
|
|
|
|
|
2020-04-09 11:06:15 +00:00
|
|
|
License: modified LGPL with linking exception (like RTL, FCL and LCL)
|
2018-04-16 13:59:19 +00:00
|
|
|
|
2020-04-09 11:06:15 +00:00
|
|
|
See the file COPYING.modifiedLGPL.txt, included in the Lazarus distribution,
|
|
|
|
for details about the license.
|
2018-04-16 13:59:19 +00:00
|
|
|
|
2020-04-09 11:06:15 +00:00
|
|
|
See also: https://wiki.lazarus.freepascal.org/FPC_modified_LGPL
|
2018-04-16 13:59:19 +00:00
|
|
|
}
|
2020-04-09 11:06:15 +00:00
|
|
|
|
2018-04-16 13:59:19 +00:00
|
|
|
unit mvDownloadEngine;
|
|
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
Classes, SysUtils;
|
|
|
|
|
2018-04-16 15:15:27 +00:00
|
|
|
type
|
2018-04-16 13:59:19 +00:00
|
|
|
|
2018-04-16 15:15:27 +00:00
|
|
|
{ TMvCustomDownloadEngine }
|
|
|
|
|
|
|
|
TMvCustomDownloadEngine = class(TComponent)
|
2023-02-12 13:28:53 +00:00
|
|
|
protected
|
|
|
|
procedure InternalDownloadFile(const Url: String; AStream: TStream); virtual; abstract;
|
|
|
|
procedure LoadFromLocalFile(const AFileName: String; AStream: TStream);
|
2018-04-16 13:59:19 +00:00
|
|
|
public
|
2023-02-12 13:28:53 +00:00
|
|
|
procedure DownloadFile(const Url: string; AStream: TStream); virtual;
|
2018-04-16 13:59:19 +00:00
|
|
|
end;
|
|
|
|
|
2018-04-16 22:10:14 +00:00
|
|
|
|
2018-04-16 13:59:19 +00:00
|
|
|
implementation
|
|
|
|
|
2023-02-12 13:28:53 +00:00
|
|
|
uses
|
2023-02-12 17:39:04 +00:00
|
|
|
URIParser;
|
2023-02-12 13:28:53 +00:00
|
|
|
|
2018-04-16 15:15:27 +00:00
|
|
|
{ TMvCustomDownloadEngine }
|
2018-04-16 13:59:19 +00:00
|
|
|
|
2018-04-16 15:15:27 +00:00
|
|
|
procedure TMvCustomDownloadEngine.DownloadFile(const Url: string; AStream: TStream);
|
2023-02-12 17:39:04 +00:00
|
|
|
var
|
|
|
|
fn: String;
|
2018-04-16 13:59:19 +00:00
|
|
|
begin
|
2023-02-12 17:39:04 +00:00
|
|
|
if URIToFileName(Url, fn) then
|
|
|
|
LoadFromLocalFile(fn, AStream)
|
2023-02-12 13:28:53 +00:00
|
|
|
else
|
|
|
|
InternalDownloadFile(Url, AStream);
|
|
|
|
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;
|
2018-04-16 13:59:19 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
|
|
|
|