uses WinINet;
const
AppVersion = '
1.00';
DllVersion = '
1.01';
DatVersion = '
3.10';
URL = '
http:\\www.MyPage.com\MyApps\MyAppVersion.vif';
function CopyFileFromURLToStream(
const URL:
string; MS: TMemoryStream): Boolean;
const
BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer:
array[0..BufferSize - 1]
of Char;
BufferLength: DWORD;
begin
hSession := InternetOpen(PChar(Application.Title),
INTERNET_OPEN_TYPE_PRECONFIG,
nil,
nil, 0);
try
Result := False;
if Assigned(hSession)
then
begin
hURL := InternetOpenURL(hSession, PChar(
URL),
nil, 0, 0, 0);
try
if Assigned(hURL)
then
begin
MS.Position := 0;
repeat
InternetReadFile(hURL, @Buffer, BufferSize, BufferLength);
MS.WriteBuffer(Buffer, BufferLength);
{ Application.ProcessMessages; }
until BufferLength = 0;
Result := True;
end;
finally
InternetCloseHandle(hURL);
end;
end;
finally
InternetCloseHandle(hSession);
end;
end;
function GetVerEntryString(MS: TMemoryStream; Key:
String):
String;
var
i, p: Integer;
sl: TStringList;
begin
Result := '
';
if Assigned(MS)
then
begin
sl := TStringList.Create;
try
sl.LoadFromStream(MS);
for i := 0
to sl.Count - 1
do
begin
p := Pos(UpperCase(Key), UpperCase(sl.Strings[i]));
if p > 0
then
begin
Result := Copy(sl.Strings[i], pos('
=',sl.Strings[i])+1,
length(sl.Strings[i])-pos('
=',sl.Strings[i]));
break;
end;
end;
finally
sl.Free;
end;
end;
end;
procedure CheckOnlineFileUpdate;
var
MemStream: TMemoryStream;
begin
MemStream := TMemoryStream.Create;
try
CopyFileFromURLToStream(
URL, MemStream);
if Assigned(MemStream)
then
begin
if GetVerEntryString(MemStream, '
MyAppVersion') = AppVersion
then //...;
if GetVerEntryString(MemStream, '
MyDllVersion') = DllVersion
then //...;
if GetVerEntryString(MemStream, '
MyDatVersion') = DatVersion
then //...;
end;
finally
MemStream.Free;
end;
end;