Da 0wner
2009-02-11 18:44:32
Downloads an image from the internet.
Does not download if the file already exists. Returns true if file was downloaded.
{*******************************************************************************
function DownloadImage(URL, Path : string; Overwrite : boolean) : boolean;
By: Da 0wner
Description: Downloads an image to the specified path.
*******************************************************************************}
function DownloadImage(URL, Path : string; Overwrite : boolean) : boolean;
var
FileNum, i : integer;
Types : TStringArray;
s : string;
begin
Types := ['.png', '.bmp', '.gif', '.jpg', '.jpeg', '.jng', '.mng', '.pcx'];
URL := lowercase(URL);
Path := lowercase(Path);
for i := 0 to high(Types) do
begin
if ((EndsWith(Types[i], URL)) and (EndsWith(Types[i], Path))) then
begin
if ((not FileExists(Path)) or (Overwrite)) then
begin
s := GetPage(URL);
if s = '' then exit;
FileNum := RewriteFile(Path, true);
WriteFileString(FileNum, s);
CloseFile(FileNum);
if FileExists(Path) then result := true;
exit;
end;
end;
end;
end;
Does not download if the file already exists. Returns true if file was downloaded.