program new;
function getProgDir(): string;
begin
Result := 'C:\Program Files\';
if (DirectoryExists('C:\Program Files (x86)\')) then
Result := 'C:\Program Files (x86)\';
end;
function findJava(): string;
begin
Result := getProgDir() + 'Java\jre6\';
if (DirectoryExists(Result)) then
Exit;
Result := getProgDir() + 'Java\jre7\';
if (DirectoryExists(Result)) then
Exit;
Result := '';
end;
function getDLL(out Filename, Path: string): boolean;
begin
Path := findJava();
case (Copy(Path, Length(Path) - 1, 1)) of
'6': Filename := 'msvcr71.dll';
'7': Filename := 'msvcr100.dll';
end;
Path := Path + 'bin\' + Filename;
Result := Filename <> '';
end;
function CopyFile(Src, Dest: string): boolean;
var
Stream: TFileStream;
begin
Stream := TFileStream.Create(Src, fmOpenRead);
try
with TFileStream.Create(Dest, fmCreate or fmOpenReadWrite) do
try
Result := CopyFrom(Stream, Stream.Size) = Stream.Size;
finally
Free;
end;
finally
Stream.Free;
end;
end;
var
Filename, Path: string;
begin
if (getDLL(Filename, Path)) then
if (CopyFile(Path, AppPath + Filename)) then
WriteLn(Format('File "%s" copied to the Simba directory successfully.', [Filename]));
end.