Skip to content

Commit 82dc628

Browse files
committed
Merge branch 'no-downgrade'
This topic branch teaches the installer to detect and discourage downgrades: In the case that a newer Git for Windows version is already installed, the user will be asked whether a downgrade is intended, defaulting to "No". Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 parents 8f16942 + ae32f65 commit 82dc628

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

installer/install.iss

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,67 @@ end;
515515
Setup event functions
516516
}
517517
518+
function NextNumber(Str:String;var Pos:Integer):Integer;
519+
var
520+
From:Integer;
521+
begin
522+
From:=Pos;
523+
while (Pos<=Length(Str)) and (Str[Pos]>=#48) and (Str[Pos]<=#57) do
524+
Pos:=Pos+1;
525+
if Pos>From then
526+
Result:=StrToInt(Copy(Str,From,Pos-From))
527+
else
528+
Result:=-1;
529+
end;
530+
531+
function IsDowngrade(CurrentVersion,PreviousVersion:String):Boolean;
532+
var
533+
i,j,Current,Previous:Integer;
534+
begin
535+
Result:=False;
536+
i:=1;
537+
j:=1;
538+
while True do begin
539+
if j>Length(PreviousVersion) then
540+
Exit;
541+
if i>Length(CurrentVersion) then begin
542+
Result:=True;
543+
Exit;
544+
end;
545+
Previous:=NextNumber(PreviousVersion,j);
546+
if Previous<0 then
547+
Exit;
548+
Current:=NextNumber(CurrentVersion,i);
549+
if Current<0 then begin
550+
Result:=True;
551+
Exit;
552+
end;
553+
if Current>Previous then
554+
Exit;
555+
if Current<Previous then begin
556+
Result:=True;
557+
Exit;
558+
end;
559+
if j>Length(PreviousVersion) then
560+
Exit;
561+
if i>Length(CurrentVersion) then begin
562+
Result:=True;
563+
Exit;
564+
end;
565+
if CurrentVersion[i]<>PreviousVersion[j] then begin
566+
Result:=PreviousVersion[j]='.';
567+
Exit;
568+
end;
569+
if CurrentVersion[i]<>'.' then
570+
Exit;
571+
i:=i+1;
572+
j:=j+1;
573+
end;
574+
end;
575+
518576
function InitializeSetup:Boolean;
577+
var
578+
CurrentVersion,PreviousVersion:String;
519579
begin
520580
UpdateInfFilenames;
521581
#if BITNESS=='32'
@@ -528,6 +588,13 @@ begin
528588
Result:=True;
529589
end;
530590
#endif
591+
#if APP_VERSION!='0-test'
592+
if Result and not ParamIsSet('ALLOWDOWNGRADE') and RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\GitForWindows','CurrentVersion',PreviousVersion) then begin
593+
CurrentVersion:=ExpandConstant('{#APP_VERSION}');
594+
if (IsDowngrade(CurrentVersion,PreviousVersion)) and (SuppressibleMsgBox('Git for Windows '+PreviousVersion+' is currently installed.'+#13+'Do you really want to downgrade to Git for Windows '+CurrentVersion+'?',mbConfirmation,MB_YESNO or MB_DEFBUTTON2,IDNO)=IDNO) then
595+
Result:=False;
596+
end;
597+
#endif
531598
end;
532599
533600
procedure RecordChoice(PreviousDataKey:Integer;Key,Data:String);

installer/release.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@ do
2222
--skip-files)
2323
skip_files=t
2424
;;
25-
--debug-wizard-page=*)
25+
-d=*|--debug-wizard-page=*)
26+
page="${1#*=}"
27+
case "$page" in *Page);; *)page=${page}Page;; esac
2628
test_installer=t
29+
if ! grep "^ *$page:TWizardPage;$" install.iss >/dev/null
30+
then
31+
echo "Unknown page '$page'. Known pages:" >&2
32+
sed -n 's/:TWizardPage;$//p' <install.iss >&2
33+
exit 1
34+
fi
2735
inno_defines="$(printf "%s\n%s\n%s" "$inno_defines" \
28-
"#define DEBUG_WIZARD_PAGE '${1#*=}'" \
36+
"#define DEBUG_WIZARD_PAGE '$page'" \
2937
"#define OUTPUT_TO_TEMP ''")"
3038
skip_files=t
3139
;;

0 commit comments

Comments
 (0)