Skip to content

Commit

Permalink
installer: run auto-update maybe a little later than scheduled
Browse files Browse the repository at this point in the history
When we install the Scheduled Task to trigger `git update` to run, we
did not check that checkbox "Run task as soon as possible after a
scheduled start is missed". But we should.

This is not possible via a command-line option of schtasks.exe,
therefore we have to switch to using an XML file (which would have been
a problem when we still supported Windows XP, but Vista and above accept
that XML with only a few required entries).

Pointed out by Matthew Cheetham.

While at it, we are now also able to ask the Scheduled Task only to be
run if there is a network connection (it is pointless to run it without
internet, right?).

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Oct 26, 2017
1 parent 0b6c267 commit 459b6e8
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions installer/install.iss
Original file line number Diff line number Diff line change
Expand Up @@ -1759,11 +1759,42 @@ end;
procedure InstallAutoUpdater;
var
Res:Longint;
LogPath,ErrPath:String;
LogPath,ErrPath,AppPath,XMLPath,Start:String;
begin
Start:=GetDateTimeString('yyyy-mm-dd','-',':')+'T'+GetDateTimeString('hh:nn:ss','-',':');
XMLPath:=ExpandConstant('{tmp}\auto-updater.xml');
AppPath:=ExpandConstant('{app}');
SaveStringToFile(XMLPath,
'<?xml version="1.0" encoding="UTF-16"?>'+
'<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">'+
' <Settings>'+
' <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>'+
' <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>'+
' <StartWhenAvailable>true</StartWhenAvailable>'+
' <IdleSettings>'+
' <StopOnIdleEnd>false</StopOnIdleEnd>'+
' <RestartOnIdle>false</RestartOnIdle>'+
' </IdleSettings>'+
' </Settings>'+
' <Triggers>'+
' <CalendarTrigger>'+
' <StartBoundary>'+Start+'</StartBoundary>'+
' <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>'+
' <ScheduleByDay>'+
' <DaysInterval>1</DaysInterval>'+
' </ScheduleByDay>'+
' </CalendarTrigger>'+
' </Triggers>'+
' <Actions Context="Author">'+
' <Exec>'+
' <Command>"'+AppPath+'\git-bash.exe"</Command>'+
' <Arguments>--hide --no-needs-console --command=cmd\git.exe update --gui</Arguments>'+
' </Exec>'+
' </Actions>'+
'</Task>',False);
LogPath:=ExpandConstant('{tmp}\remove-autoupdate.log');
ErrPath:=ExpandConstant('{tmp}\remove-autoupdate.err');
if not Exec(ExpandConstant('{sys}\cmd.exe'),ExpandConstant('/C schtasks /Create /F /SC DAILY /TN "Git for Windows Updater" /TR "'+#39+'{app}\git-bash.exe'+#39+' --hide --no-needs-console --command=cmd\git.exe update --gui" >"'+LogPath+'" 2>"'+ErrPath+'"'),'',SW_HIDE,ewWaitUntilTerminated,Res) or (Res<>0) then
if not Exec(ExpandConstant('{sys}\cmd.exe'),ExpandConstant('/C schtasks /Create /F /TN "Git for Windows Updater" /XML "'+XMLPath+'" >"'+LogPath+'" 2>"'+ErrPath+'"'),'',SW_HIDE,ewWaitUntilTerminated,Res) or (Res<>0) then
LogError(ExpandConstant('Line {#__LINE__}: Unable to schedule the Git for Windows updater (output: '+ReadFileAsString(LogPath)+', errors: '+ReadFileAsString(ErrPath)+').'));
end;
Expand Down

0 comments on commit 459b6e8

Please sign in to comment.