Skip to content

Commit 459b6e8

Browse files
committed
installer: run auto-update maybe a little later than scheduled
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]>
1 parent 0b6c267 commit 459b6e8

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

installer/install.iss

+33-2
Original file line numberDiff line numberDiff line change
@@ -1759,11 +1759,42 @@ end;
17591759
procedure InstallAutoUpdater;
17601760
var
17611761
Res:Longint;
1762-
LogPath,ErrPath:String;
1762+
LogPath,ErrPath,AppPath,XMLPath,Start:String;
17631763
begin
1764+
Start:=GetDateTimeString('yyyy-mm-dd','-',':')+'T'+GetDateTimeString('hh:nn:ss','-',':');
1765+
XMLPath:=ExpandConstant('{tmp}\auto-updater.xml');
1766+
AppPath:=ExpandConstant('{app}');
1767+
SaveStringToFile(XMLPath,
1768+
'<?xml version="1.0" encoding="UTF-16"?>'+
1769+
'<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">'+
1770+
' <Settings>'+
1771+
' <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>'+
1772+
' <RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>'+
1773+
' <StartWhenAvailable>true</StartWhenAvailable>'+
1774+
' <IdleSettings>'+
1775+
' <StopOnIdleEnd>false</StopOnIdleEnd>'+
1776+
' <RestartOnIdle>false</RestartOnIdle>'+
1777+
' </IdleSettings>'+
1778+
' </Settings>'+
1779+
' <Triggers>'+
1780+
' <CalendarTrigger>'+
1781+
' <StartBoundary>'+Start+'</StartBoundary>'+
1782+
' <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>'+
1783+
' <ScheduleByDay>'+
1784+
' <DaysInterval>1</DaysInterval>'+
1785+
' </ScheduleByDay>'+
1786+
' </CalendarTrigger>'+
1787+
' </Triggers>'+
1788+
' <Actions Context="Author">'+
1789+
' <Exec>'+
1790+
' <Command>"'+AppPath+'\git-bash.exe"</Command>'+
1791+
' <Arguments>--hide --no-needs-console --command=cmd\git.exe update --gui</Arguments>'+
1792+
' </Exec>'+
1793+
' </Actions>'+
1794+
'</Task>',False);
17641795
LogPath:=ExpandConstant('{tmp}\remove-autoupdate.log');
17651796
ErrPath:=ExpandConstant('{tmp}\remove-autoupdate.err');
1766-
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
1797+
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
17671798
LogError(ExpandConstant('Line {#__LINE__}: Unable to schedule the Git for Windows updater (output: '+ReadFileAsString(LogPath)+', errors: '+ReadFileAsString(ErrPath)+').'));
17681799
end;
17691800

0 commit comments

Comments
 (0)