On Jan 29, 2008, at 4:39 PM, Jan Hudec wrote:


Hello,

I'd like to call git (msysGit) from another application. And I would like to
avoid asking the user where it is installed.

My best idea so far is reading:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion \Uninstall\Git_is1\InstallLocation
(I can also use DisplayName there for showing git version)

However, question is whether that key (Git_is1) can be considered stable enough for this purpose. Is there -- or will there be in future -- some
definedly reliable source of this information?

qgit does exactly what you propose. Below is the git from qgit4.git's master.

        Steffen

commit 97cd7033a3a997bee0e19dfaba55f32cf12468cd
Author: Marco Costalba <[EMAIL PROTECTED]>
Date:   Wed Jan 2 09:08:54 2008 +0100

    InnoSetup: Read msysgit location from registry

The installer could try to read the correct msysgit installation path from the registry before falling back to "C:\Program Files\Git". This could be
    done by reading the "InstallLocation" string value from this key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion \Uninstall\Git
    _is1]

    With the help of Sebastian Schuberth.

    Signed-off-by: Marco Costalba <[EMAIL PROTECTED]>

diff --git a/qgit_inno_setup.iss b/qgit_inno_setup.iss
index 6883d2c..d8904e7 100644
--- a/qgit_inno_setup.iss
+++ b/qgit_inno_setup.iss
@@ -46,43 +46,53 @@ Name: "{commondesktop}\QGit"; Filename: "{app} \qgit.exe"; WorkingDir: "{app}"; T
 [Code]
 var
   MSysGitDirPage: TInputDirWizardPage;
-
+
 procedure InitializeWizard;
+var
+  Key, Val: String;
+
 begin
   // Create msysgit directory find page
   MSysGitDirPage := CreateInputDirPage(wpSelectProgramGroup,
'Select MSYSGIT Location', 'Where is MSYSGIT directory located?',
       'Select where MSYSGIT directory is located, then click Next.',
       False, '');
-
+
   // Add item (with an empty caption)
   MSysGitDirPage.Add('');
-
+
   // Set initial value
-  MSysGitDirPage.Values[0] := ExpandConstant('{pf}\Git');
+  Key := 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1';
+
+ if RegQueryStringValue(HKEY_LOCAL_MACHINE, Key, 'InstallLocation', Val) then begin
+    MSysGitDirPage.Values[0] := Val;
+  end else
+    MSysGitDirPage.Values[0] := ExpandConstant('{pf}\Git');
+
 end;

 function NextButtonClick(CurPageID: Integer): Boolean;
 var
   BaseDir: String;
+
 begin
   // Validate pages before allowing the user to proceed }
   if CurPageID = MSysGitDirPage.ID then begin
-
+
       BaseDir := MSysGitDirPage.Values[0];
-
+
if FileExists(ExpandFileName(BaseDir + '\bin\git.exe')) then begin
         Result := True;
-
+
end else if FileExists(ExpandFileName(BaseDir + '\..\bin \git.exe')) then begin // sub dir selected
         MSysGitDirPage.Values[0] := ExpandFileName(BaseDir + '\..');
         Result := True;
-
+
       end else begin
MsgBox('Directory ''' + BaseDir + ''' does not seem the msysgit one, retry', mbError, MB_OK);
         Result := False;
       end;
-
+
   end else
     Result := True;
 end;
@@ -91,4 +101,3 @@ function GetMSysGitExecDir(Param: String): String;
 begin
   Result := MSysGitDirPage.Values[0] + '\bin'; // already validated
 end;
-

Reply via email to