Reputation: 367
I want to point to a http://somesite.com/somefile.exe and check the file version of the exe server side and compare the version info to the same .exe file all ready on my computer. If the server side file is newer then I want to down load it.
I have functions to download the file and check the file version but I want to check if the file version is newer than the one i have on my computer.
I do not want to download the exe to my computer and then check the file version.
Has anyone here been able to do this?
function GetVersion(sFileName:string): string;
var
VerInfoSize: DWORD;
VerInfo: Pointer;
VerValueSize: DWORD;
VerValue: PVSFixedFileInfo;
Dummy: DWORD;
begin
VerInfoSize := GetFileVersionInfoSize(PChar(sFileName), Dummy);
GetMem(VerInfo, VerInfoSize);
GetFileVersionInfo(PChar(sFileName), 0, VerInfoSize, VerInfo);
VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
with VerValue^ do
begin
Result := IntToStr(dwFileVersionMS shr 16);
Result := Result + '.' + IntToStr(dwFileVersionMS and $FFFF);
Result := Result + '.' + IntToStr(dwFileVersionLS shr 16);
Result := Result + '.' + IntToStr(dwFileVersionLS and $FFFF);
end;
FreeMem(VerInfo, VerInfoSize);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Http: TIdHTTP;
MS: TMemoryStream;
begin
Http := TIdHTTP.Create(nil);
try
MS := TMemoryStream.Create;
try
Http.OnWork:= HttpWork;
Http.Get('http://live.sysinternals.com/ADExplorer.exe', MS);
MS.SaveToFile('C:\ADExplorer.exe');
finally
MS.Free;
end;
finally
Http.Free;
end;
end;
Upvotes: 1
Views: 2001
Reputation: 596417
You cannot access the file version remotely. You need to either download the file locally first, or you need to store the file version in a separate file that you can download, or you need to write a server-side script that your client can send a request to and have it access the file version and return it back to your client.
A better option is to use HTTP's built-in "Conditional GET" feature instead (if the server supports it). Your client can include an "If-Modified-Since" header in its request, then the server will deliver the requested file only if it has been modified on the server-side after the requested timestamp. Otherwise a 304
reply code will be sent back indicating the client already has the latest file. Read RFC 2616 Section 14.25 for more details.
Upvotes: 8
Reputation: 125708
You can't check the FileVersion
of the file without physically having it to inspect, which means you have to be able to have all the bytes available, and the file version API functions expect a physical disk file. (IOW, you can't do this without downloading the file to your local drive first.)
Besides, you're already fully downloading it to memory with the HTTP GET
anyway, so you're not saving anything in bandwidth in the first place.
The alternative (if it's an option) is to have a file on the server that contains the version number that the local file can download and read instead. If you can't do that, you're probably out of luck and will have to do the full download.
Upvotes: 6