From bfa6e4dca7b32e1995af78c2530265caaf2c6300 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 15 Mar 2022 10:10:14 +0100 Subject: [PATCH] installer: only warn user once about unsafe Git on PATH When the Git executable on the PATH is in an unexpected location, we want to warn the user about that. But we only want to do that once, not four times. Let's cache the result once we have it, and ask only once. Signed-off-by: Johannes Schindelin --- .../inno-setup-git-lfs-installer.iss | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/script/windows-installer/inno-setup-git-lfs-installer.iss b/script/windows-installer/inno-setup-git-lfs-installer.iss index fe5e1fa8..eccf4a20 100644 --- a/script/windows-installer/inno-setup-git-lfs-installer.iss +++ b/script/windows-installer/inno-setup-git-lfs-installer.iss @@ -101,6 +101,10 @@ begin Result := Pos(';' + UpperCase(ParamExpanded) + '\;', ';' + UpperCase(OrigPath) + ';') = 0; end; +var + CachedGitFoundInPath: boolean; + CachedGitFoundInPathInitialized: boolean; + // Verify that a Git executable is found in the PATH, and if it does not // reside in either 'C:\Program Files' or 'C:\Program Files (x86)', warn // the user in case it is not the Git installation they expected. @@ -112,7 +116,13 @@ var i,j: integer; RegisterOrDeregister: string; begin + if CachedGitFoundInPathInitialized then begin + Result := CachedGitFoundInPath; + Exit; + end; Result := False; + CachedGitFoundInPath := False; + CachedGitFoundInPathInitialized := True; if IsUninstaller then RegisterOrDeregister := 'deregister' @@ -137,6 +147,7 @@ begin if FileExists(Path + Ext) then begin if (Pos(PFiles32, Path) = 1) or (Pos(PFiles64, Path) = 1) then begin Result := True; + CachedGitFoundInPath := True; Exit; end; Log('Warning: Found Git in unexpected location: "' + Path + Ext + '"'); @@ -146,6 +157,7 @@ begin 'If this looks dubious, Git LFS should not be registered using it.' + #13+#10 + #13+#10 + 'Do you want to ' + RegisterOrDeregister + ' Git LFS using this Git program?', mbConfirmation, MB_YESNO, IDNO) = IDYES); + CachedGitFoundInPath := Result; if Result then Log('Using Git found at: "' + Path + Ext + '"') else