SRL Archive - Research & Development Lounge

function DownloadRepository : boolean;


Da 0wner

2009-05-28 04:48:38

function DownloadRepository(RepositoryURL, InstallPath : string; Overwrite : boolean) : boolean;
var
s : string;
Files, Folders, Contents : TStringArray;
i, h, z : integer;
FileNum : integer;
begin
SetArrayLength(Folders, 1);
Folders[0] := RepositoryURL;
Writeln('Obtaining file list...');
repeat
s := GetPage(Folders[i]);
s := Replace(s, 'a href="../">', '');
repeat
h := High(Files);
SetArrayLength(Files, h + 2);
h := h + 1;
Files[h] := Folders[i] + Between('href="', '">', s);
s := Replace(s, 'href="' + Between('href="', '">', s) + '">', '');
if pos('http://', Copy(Files[h], 8, Length(Files[h]))) > 0 then
break;
if EndsWith('/', Files[h]) then
begin
h := high(Folders);
SetArrayLength(Folders, h + 2);
h := high(Folders);
Files[high(files)] := Replace(Files[high(files)], RepositoryURL, '');
Folders[h] := RepositoryURL + Files[high(files)];
SetArrayLength(Files, GetArrayLength(Files) - 1);
end;
until(false);
SetArrayLength(Files, GetArrayLength(Files) - 1);
inc(i);
until(i = high(Folders) + 1);
h := high(Files);
Writeln('Obtained file and folder list. There are ' + IntToStr(High(Folders)) + ' folders and ' + IntToStr(h + 1) + ' files.');
Writeln('Downloading and installing files...');
h := high(Files);
SetArrayLength(Contents, h + 1);
for i := 0 to h do
begin
if ((FileExists(InstallPath + Files[i])) and (not Overwrite)) then
Continue;
Contents[i] := GetPage(Files[i]);
Files[i] := Replace(Files[i], RepositoryURL, '') ;
Files[i] := Replace(Files[i], '/', '\');
Files[i] := Replace(Files[i], '%20', ' ');
writeln(InstallPath + Files[i]);
FileNum := RewriteFile(InstallPath + Files[i], true);
try
WriteFileString(FileNum, Contents[i]);
except
Writeln('Failed installing file ' + Files[i] + '!');
finally
CloseFile(FileNum);
end;
end;
wait(5000);
Writeln('Verifying all files and contents...');
for i := 0 to h do
begin
if Length(Contents[i]) = 0 then
Continue;
if FileExists(InstallPath + Files[i]) then
begin
FileNum := OpenFile(InstallPath + Files[i], true);
if FileSize(FileNum) <> Length(Contents[i]) then
begin
inc(z);
Writeln(Files[i] + ' was not installed successfully.');
end;
CloseFile(FileNum);
end else
begin
inc(z);
Writeln(Files[i] + ' was not installed successfully.');
end;
end;
if z <> 0 then
Writeln(IntToStr(z) + ' file(s) were/was not installed successfully!')
else
begin
Writeln('All files were installed successfully.');
result := true;
end;
end;
This is a simple downloader that installs a repository into the selected path. It should work with repositories that are similiar to Google Code.

This has only been tested by downloading Reflection by using:

DownloadRepository('http://scardevreflection.googlecode.com/svn/trunk/', AppPath + 'Includes/SRL/SRL/Reflection/', True)
However It should work with some other repositories. I would love for you people to test and tell me what you want me to improve with it etc. :) <3.

Dynamite

2009-05-28 04:50:03

Will test it now ;)

T~M

Tickyy

2009-05-28 22:32:04

wtf nub, i herd u liek mudkips…

btw nice one :D!

Nadeem

2009-05-29 03:01:05

Nice work nub :)

Tried it in SCAR 3.15b doesn't work, though, only works in SCAR 3.20+



~NS

Smartzkid

2009-05-29 04:02:05

Nice!

Suggestions: Use regexes, then you can easily make it work with all repositories

Wizzup?

2009-05-29 14:59:21

From: Smartzkid
Nice!

Suggestions: Use regexes, then you can easily make it work with all repositories


I was going to suggest that. :)

Da 0wner

2009-05-29 18:03:55

There we go. Should work with all repositories now :D. Except ones that are formatted like SRL's (with XML) :p.