Handle build download errors in update checker. Fixes issue #2512.

This commit is contained in:
Ansgar Becker
2011-08-13 05:38:20 +00:00
parent cb8c233a10
commit e58d033342

View File

@ -235,35 +235,40 @@ begin
if FileExists(Download.Filename) then
DeleteFile(Download.Filename);
// Do the download
Download.ExecuteTarget(nil);
try
// Do the download
Download.ExecuteTarget(nil);
// Check if downloaded file exists
if not FileExists(Download.Filename) then
Raise Exception.Create('Downloaded file not found: '+Download.Filename);
// Check if downloaded file exists
if not FileExists(Download.Filename) then
Raise Exception.Create('Downloaded file not found: '+Download.Filename);
Status('Update in progress ...');
ResInfoblockHandle := FindResource(HInstance, 'UPDATER', 'EXE');
ResHandle := LoadResource(HInstance, ResInfoblockHandle);
if ResHandle <> 0 then begin
Stream := TMemoryStream.Create;
try
ResPointer := LockResource(ResHandle);
Stream.WriteBuffer(ResPointer[0], SizeOfResource(HInstance, ResInfoblockHandle));
Stream.Position := 0;
UpdaterFilename := GetTempDir + AppName+'_updater.exe';
if FileExists(UpdaterFilename) and (Stream.Size = _GetFileSize(UpdaterFilename)) then
// Do not replace old updater if it's still valid. Avoids annoyance for cases in which
// user has whitelisted this .exe in his antivirus or whatever software.
else
Stream.SaveToFile(UpdaterFilename);
// Calling the script will now post a WM_CLOSE this running exe...
ShellExec(UpdaterFilename, '', '"'+ParamStr(0)+'" "'+Download.Filename+'"');
finally
UnlockResource(ResHandle);
FreeResource(ResHandle);
Stream.Free;
Status('Update in progress ...');
ResInfoblockHandle := FindResource(HInstance, 'UPDATER', 'EXE');
ResHandle := LoadResource(HInstance, ResInfoblockHandle);
if ResHandle <> 0 then begin
Stream := TMemoryStream.Create;
try
ResPointer := LockResource(ResHandle);
Stream.WriteBuffer(ResPointer[0], SizeOfResource(HInstance, ResInfoblockHandle));
Stream.Position := 0;
UpdaterFilename := GetTempDir + AppName+'_updater.exe';
if FileExists(UpdaterFilename) and (Stream.Size = _GetFileSize(UpdaterFilename)) then
// Do not replace old updater if it's still valid. Avoids annoyance for cases in which
// user has whitelisted this .exe in his antivirus or whatever software.
else
Stream.SaveToFile(UpdaterFilename);
// Calling the script will now post a WM_CLOSE this running exe...
ShellExec(UpdaterFilename, '', '"'+ParamStr(0)+'" "'+Download.Filename+'"');
finally
UnlockResource(ResHandle);
FreeResource(ResHandle);
Stream.Free;
end;
end;
except
on E:Exception do
ErrorDialog(E.Message);
end;
end;