Issue #1616: force update check to overwrite old HeidiSQL_update.exe in temp directory, once through different file size, and by logic when old one is older than 30 days. Fixes still used old updater with bugs.

This commit is contained in:
Ansgar Becker
2022-11-24 07:54:40 +01:00
parent 7c6cc45437
commit 09e6d1709c
5 changed files with 26 additions and 10 deletions

View File

@@ -1,7 +1,9 @@
brcc32 res\version.rc
cgrc res\icon.rc
brcc32 res\icon-question.rc
brcc32 res\manifest.rc
brcc32 -fores\updater.res res\updater32.rc
cgrc.exe res\styles.rc
pause
brcc32 res\version.rc
cgrc res\icon.rc
brcc32 res\icon-question.rc
brcc32 res\manifest.rc
brcc32 -fores\updater.res res\updater64.rc
cgrc.exe res\styles.rc
brcc32.exe source\vcl-styles-utils\AwesomeFont.rc
brcc32.exe source\vcl-styles-utils\AwesomeFont_zip.rc
pause

View File

@@ -5,6 +5,9 @@ program updater;
{$R manifest.RES}
// (un)comment the following resource inclusion to vary the binary size. Update checker trusts the same file size before overwriting the old one.
{$R ..\icon.RES}
uses
Windows, Messages, Tlhelp32, psapi;

View File

Binary file not shown.

View File

Binary file not shown.

View File

@@ -5,7 +5,7 @@ interface
uses
Windows, Messages, SysUtils, Classes, Forms, StdCtrls, IniFiles, Controls, Graphics,
apphelpers, gnugettext, ExtCtrls, extra_controls, System.StrUtils, Vcl.Dialogs,
Vcl.Menus, Vcl.Clipbrd, generic_types;
Vcl.Menus, Vcl.Clipbrd, generic_types, System.DateUtils;
type
TfrmUpdateCheck = class(TExtForm)
@@ -255,6 +255,8 @@ var
ResPointer: PChar;
Stream: TMemoryStream;
BuildSizeDownloaded: Int64;
DoOverwrite: Boolean;
UpdaterAge: TDateTime;
begin
Download := THttpDownload.Create(Self);
Download.URL := BuildURL;
@@ -289,11 +291,20 @@ begin
Stream.WriteBuffer(ResPointer[0], SizeOfResource(HInstance, ResInfoblockHandle));
Stream.Position := 0;
UpdaterFilename := GetTempDir + AppName+'_updater.exe';
if FileExists(UpdaterFilename) and (Stream.Size = _GetFileSize(UpdaterFilename)) then
DoOverwrite := True;
if FileExists(UpdaterFilename) and (Stream.Size = _GetFileSize(UpdaterFilename)) then begin
// 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
FileAge(UpdaterFilename, UpdaterAge);
if Abs(DaysBetween(Now, UpdaterAge)) < 30 then
DoOverwrite := False;
end;
if DoOverwrite then begin
Stream.SaveToFile(UpdaterFilename);
end;
// Calling the script will now post a WM_CLOSE this running exe...
ShellExec(UpdaterFilename, '', '"'+ParamStr(0)+'" "'+DownloadFilename+'"');
finally