Skip to content

Commit

Permalink
Merge branch 'no-downgrade'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dscho committed Jul 13, 2016
2 parents 8f16942 + ae32f65 commit 82dc628
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
67 changes: 67 additions & 0 deletions installer/install.iss
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,67 @@ end;
Setup event functions
}
function NextNumber(Str:String;var Pos:Integer):Integer;
var
From:Integer;
begin
From:=Pos;
while (Pos<=Length(Str)) and (Str[Pos]>=#48) and (Str[Pos]<=#57) do
Pos:=Pos+1;
if Pos>From then
Result:=StrToInt(Copy(Str,From,Pos-From))
else
Result:=-1;
end;
function IsDowngrade(CurrentVersion,PreviousVersion:String):Boolean;
var
i,j,Current,Previous:Integer;
begin
Result:=False;
i:=1;
j:=1;
while True do begin
if j>Length(PreviousVersion) then
Exit;
if i>Length(CurrentVersion) then begin
Result:=True;
Exit;
end;
Previous:=NextNumber(PreviousVersion,j);
if Previous<0 then
Exit;
Current:=NextNumber(CurrentVersion,i);
if Current<0 then begin
Result:=True;
Exit;
end;
if Current>Previous then
Exit;
if Current<Previous then begin
Result:=True;
Exit;
end;
if j>Length(PreviousVersion) then
Exit;
if i>Length(CurrentVersion) then begin
Result:=True;
Exit;
end;
if CurrentVersion[i]<>PreviousVersion[j] then begin
Result:=PreviousVersion[j]='.';
Exit;
end;
if CurrentVersion[i]<>'.' then
Exit;
i:=i+1;
j:=j+1;
end;
end;
function InitializeSetup:Boolean;
var
CurrentVersion,PreviousVersion:String;
begin
UpdateInfFilenames;
#if BITNESS=='32'
Expand All @@ -528,6 +588,13 @@ begin
Result:=True;
end;
#endif
#if APP_VERSION!='0-test'
if Result and not ParamIsSet('ALLOWDOWNGRADE') and RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\GitForWindows','CurrentVersion',PreviousVersion) then begin
CurrentVersion:=ExpandConstant('{#APP_VERSION}');
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
Result:=False;
end;
#endif
end;
procedure RecordChoice(PreviousDataKey:Integer;Key,Data:String);
Expand Down
12 changes: 10 additions & 2 deletions installer/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ do
--skip-files)
skip_files=t
;;
--debug-wizard-page=*)
-d=*|--debug-wizard-page=*)
page="${1#*=}"
case "$page" in *Page);; *)page=${page}Page;; esac
test_installer=t
if ! grep "^ *$page:TWizardPage;$" install.iss >/dev/null
then
echo "Unknown page '$page'. Known pages:" >&2
sed -n 's/:TWizardPage;$//p' <install.iss >&2
exit 1
fi
inno_defines="$(printf "%s\n%s\n%s" "$inno_defines" \
"#define DEBUG_WIZARD_PAGE '${1#*=}'" \
"#define DEBUG_WIZARD_PAGE '$page'" \
"#define OUTPUT_TO_TEMP ''")"
skip_files=t
;;
Expand Down

0 comments on commit 82dc628

Please sign in to comment.