diff --git a/build-res.bat b/build-res.bat index 1e69faa2..ef7cd504 100644 --- a/build-res.bat +++ b/build-res.bat @@ -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 diff --git a/res/updater/updater.dpr b/res/updater/updater.dpr index 8a3aa39f..687d411f 100644 --- a/res/updater/updater.dpr +++ b/res/updater/updater.dpr @@ -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; diff --git a/res/updater32.exe b/res/updater32.exe index fc1e10de..0ed65d41 100644 Binary files a/res/updater32.exe and b/res/updater32.exe differ diff --git a/res/updater64.exe b/res/updater64.exe index 5e1f0e60..d0c3b7a1 100644 Binary files a/res/updater64.exe and b/res/updater64.exe differ diff --git a/source/updatecheck.pas b/source/updatecheck.pas index c8663ab9..746e7a7c 100644 --- a/source/updatecheck.pas +++ b/source/updatecheck.pas @@ -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