| 1 |
{%MainUnit castledownload.pas} |
| 2 |
{ |
| 3 |
Copyright 2013-2020 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{$ifdef read_interface} |
| 18 |
|
| 19 |
type |
| 20 |
TStringsHelper = class helper for TStrings |
| 21 |
{ Load the contents from URL. |
| 22 |
Uses Castle Game Engine @link(Download) to get the contents, |
| 23 |
then uses standard LoadFromStream to load them. |
| 24 |
|
| 25 |
The meaning (and default behavior) of optional AEncoding |
| 26 |
is the same as for TStrings.LoadFromFile and TStrings.LoadFromStream. } |
| 27 |
procedure LoadFromUrl(const Url: String); overload; |
| 28 |
procedure LoadFromUrl(const Url: String; const AEncoding: TEncoding); overload; |
| 29 |
|
| 30 |
{ Save the contents to URL. |
| 31 |
Uses standard SaveToStream combined with |
| 32 |
Castle Game Engine @link(UrlSaveStream) to save the contents. } |
| 33 |
procedure SaveToUrl(const Url: String); |
| 34 |
end; |
| 35 |
|
| 36 |
{$endif} |
| 37 |
|
| 38 |
{$ifdef read_implementation} |
| 39 |
|
| 40 |
{ TStringsHelper ---------------------------------------------------------- } |
| 41 |
|
| 42 |
procedure TStringsHelper.LoadFromUrl(const Url: String); |
| 43 |
var |
| 44 |
Stream: TStream; |
| 45 |
begin |
| 46 |
Stream := Download(Url); |
| 47 |
try |
| 48 |
LoadFromStream(Stream); |
| 49 |
finally FreeAndNil(Stream) end; |
| 50 |
end; |
| 51 |
|
| 52 |
procedure TStringsHelper.LoadFromUrl(const Url: String; const AEncoding: TEncoding); |
| 53 |
var |
| 54 |
Stream: TStream; |
| 55 |
begin |
| 56 |
Stream := Download(Url); |
| 57 |
try |
| 58 |
LoadFromStream(Stream {$ifndef VER3_0}, AEncoding {$endif}); |
| 59 |
finally FreeAndNil(Stream) end; |
| 60 |
end; |
| 61 |
|
| 62 |
procedure TStringsHelper.SaveToUrl(const Url: String); |
| 63 |
var |
| 64 |
Stream: TStream; |
| 65 |
begin |
| 66 |
Stream := UrlSaveStream(Url); |
| 67 |
try |
| 68 |
SaveToStream(Stream); |
| 69 |
finally FreeAndNil(Stream) end; |
| 70 |
end; |
| 71 |
|
| 72 |
{$endif} |