2 #define APP_VERSION
'%APPVERSION%'
3 #define APP_URL
'http://code.google.com/p/msysgit/'
4 #define APP_BUILTINS
'etc\fileList-builtins.txt'
8 InternalCompressLevel
=max
9 OutputBaseFilename
={#emit APP_NAME+'-'+APP_VERSION}
15 AppName
={#emit APP_NAME}
16 AppPublisherURL
={#emit APP_URL}
17 AppVersion
={#emit APP_VERSION}
18 AppVerName
={#emit APP_NAME+' '+APP_VERSION}
19 ChangesEnvironment
=yes
20 DefaultDirName
={pf}\
{#emit APP_NAME}
21 DefaultGroupName
={#emit APP_NAME}
23 LicenseFile
=gpl
-2.0.rtf
24 PrivilegesRequired
=none
25 UninstallDisplayIcon
=etc\git
.ico
28 SetupIconFile
=etc\git
.ico
29 WizardSmallImageFile
=git
.bmp
32 Name
: quicklaunchicon; Description
: "Create a &Quick Launch icon"; GroupDescription
: "Additional icons:"; Flags
: checkedonce
33 Name
: desktopicon; Description
: "Create a &Desktop icon"; GroupDescription
: "Additional icons:"; Flags
: checkedonce
34 Name
: shellextension
; Description
: "Add ""Git &Bash Here"""; GroupDescription
: "Windows Explorer integration:"; Flags
: checkedonce
35 Name
: guiextension
; Description
: "Add ""Git &GUI Here"""; GroupDescription
: "Windows Explorer integration:"; Flags
: checkedonce
38 Source
: "*"; DestDir
: "{app}"; Excludes
: "\*.bmp, gpl-2.0.txt, \install.*, \tmp.*, \bin\*install*"; Flags
: recursesubdirs
41 Name
: "{group}\Git GUI"; Filename
: "{app}\bin\wish.exe"; Parameters
: """{app}\bin\git-gui"""; WorkingDir
: "%USERPROFILE%"; IconFilename
: "{app}\etc\git.ico"
42 Name
: "{group}\Git Bash"; Filename
: "{app}\bin\sh.exe"; Parameters
: "--login -i"; WorkingDir
: "%USERPROFILE%"; IconFilename
: "{app}\etc\git.ico"
43 Name
: "{group}\Uninstall Git"; Filename
: "{uninstallexe}"
44 Name
: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\Git Bash"; Filename
: "{app}\bin\sh.exe"; Parameters
: "--login -i"; WorkingDir
: "%USERPROFILE%"; IconFilename
: "{app}\etc\git.ico"; Tasks
: quicklaunchicon
45 Name
: "{code:GetShellFolder|desktop}\Git Bash"; Filename
: "{app}\bin\sh.exe"; Parameters
: "--login -i"; WorkingDir
: "%USERPROFILE%"; IconFilename
: "{app}\etc\git.ico"; Tasks
: desktopicon
48 BeveledLabel
={#emit APP_URL}
51 Type: files; Name
: "{app}\bin\git-*.exe"
52 Type: dirifempty; Name
: "{app}\home\{username}"
53 Type: dirifempty; Name
: "{app}\home"
60 function GetShellFolder(Param
:string):string;
62 if IsAdminLoggedOn
then begin
63 Param
:='{common'+Param
+'}';
65 Param
:='{user'+Param
+'}';
67 Result
:=ExpandConstant(Param
);
70 function CreateHardLink(lpFileName
,lpExistingFileName
:string;lpSecurityAttributes
:Integer):Boolean;
71 external 'CreateHardLinkA@Kernel32.dll';
73 function GetEnvStrings(VarName
:string;AllUsers
:Boolean):TArrayOfString
;
81 // See http
://www
.jrsoftware
.org
/isfaq
.php#env
82 if AllUsers
then begin
83 RegQueryStringValue(HKEY_LOCAL_MACHINE
,'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',VarName
,Path
);
85 RegQueryStringValue(HKEY_CURRENT_USER
,'Environment',VarName
,Path
);
88 // Make sure we have at least one semicolon
.
91 // Split the directories
in PATH into an
array of strings
.
93 SetArrayLength(Result
,0);
97 SetArrayLength(Result
,i
+1);
99 Result
[i
]:=Copy(Path
,1,p
-1);
102 Path
:=Copy(Path
,p
+1,Length(Path
));
107 function SetEnvStrings(VarName
:string;AllUsers
,DeleteIfEmpty
:Boolean;DirStrings
:TArrayOfString
):Boolean;
112 // Merge all non
-empty directory strings into a PATH variable
.
114 for i
:=0 to GetArrayLength(DirStrings
)-1 do begin
115 if Length(DirStrings
[i
])>0 then begin
116 if Length(Path
)>0 then begin
117 Path
:=Path
+';'+DirStrings
[i
];
124 // See http
://www
.jrsoftware
.org
/isfaq
.php#env
125 if AllUsers
then begin
126 KeyName
:='SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
127 if DeleteIfEmpty
and (Length(Path
)=0) then begin
128 Result
:=(not RegValueExists(HKEY_LOCAL_MACHINE
,KeyName
,VarName
))
129 or RegDeleteValue(HKEY_LOCAL_MACHINE
,KeyName
,VarName
);
131 Result
:=RegWriteStringValue(HKEY_LOCAL_MACHINE
,KeyName
,VarName
,Path
);
134 KeyName
:='Environment';
135 if DeleteIfEmpty
and (Length(Path
)=0) then begin
136 Result
:=(not RegValueExists(HKEY_CURRENT_USER
,KeyName
,VarName
))
137 or RegDeleteValue(HKEY_CURRENT_USER
,KeyName
,VarName
);
139 Result
:=RegWriteStringValue(HKEY_CURRENT_USER
,KeyName
,VarName
,Path
);
150 RdbGitBash
,RdbGitCmd
,RdbGitCmdTools
:TRadioButton
;
152 procedure InitializeWizard
;
154 LblGitBash
,LblGitCmd
,LblGitCmdTools
,LblGitCmdToolsWarn
:TLabel
;
156 // Create a custom page
for modifying the environment
.
157 EnvPage
:=CreateCustomPage(
159 'Adjusting your PATH environment',
160 'How would you like to use Git from the command line?'
164 RdbGitBash
:=TRadioButton
.Create(EnvPage
);
165 with RdbGitBash
do begin
166 Parent
:=EnvPage
.Surface
;
167 Caption
:='Use Git Bash only';
172 Font
.Style
:=[fsBold
];
176 LblGitBash
:=TLabel
.Create(EnvPage
);
177 with LblGitBash
do begin
178 Parent
:=EnvPage
.Surface
;
180 'This is the most conservative choice if you are concerned about the' + #
13 +
181 'stability of your system. Your PATH will not be modified.';
189 RdbGitCmd
:=TRadioButton
.Create(EnvPage
);
190 with RdbGitCmd
do begin
191 Parent
:=EnvPage
.Surface
;
192 Caption
:='Run Git from the Windows Command Prompt';
197 Font
.Style
:=[fsBold
];
200 LblGitCmd
:=TLabel
.Create(EnvPage
);
201 with LblGitCmd
do begin
202 Parent
:=EnvPage
.Surface
;
204 'This option is considered safe and no conflicts with other tools are' + #
13 +
205 'known. Only Git will be added to your PATH.';
213 RdbGitCmdTools
:=TRadioButton
.Create(EnvPage
);
214 with RdbGitCmdTools
do begin
215 Parent
:=EnvPage
.Surface
;
216 Caption
:='Run Git and included Unix tools from the Windows Command Prompt';
221 Font
.Style
:=[fsBold
];
224 LblGitCmdTools
:=TLabel
.Create(EnvPage
);
225 with LblGitCmdTools
do begin
226 Parent
:=EnvPage
.Surface
;
227 Caption
:='Both Git and the Unix tools will be added to your PATH.';
233 LblGitCmdToolsWarn
:=TLabel
.Create(EnvPage
);
234 with LblGitCmdToolsWarn
do begin
235 Parent
:=EnvPage
.Surface
;
237 'Warning: This will override Windows tools like find.exe and' + #
13 +
238 'sort.exe. Select this option only if you understand the implications.';
244 Font
.Style
:=[fsBold
];
248 procedure CurStepChanged(CurStep
:TSetupStep
);
250 AppDir
,FileName
:string;
251 BuiltIns
,EnvPath
,EnvHome
:TArrayOfString
;
256 if CurStep
<>ssPostInstall
then begin
260 AppDir
:=ExpandConstant('{app}');
266 // Load the built
-ins from a
text file.
267 FileName
:=ExpandConstant('{app}\'+'{#emit APP_BUILTINS}');
268 if not LoadStringsFromFile(FileName,BuiltIns) then begin
269 MsgBox('Unable
to read file "{#emit APP_BUILTINS}".',mbError,MB_OK);
273 // Check if we are running on NTFS.
275 if SetNTFSCompression(AppDir+'\bin\git
.exe
',true) then begin
276 IsNTFS:=SetNTFSCompression(AppDir+'\bin\git
.exe
',false);
279 Count:=GetArrayLength(BuiltIns)-1;
281 // Map the built-ins to git.exe.
283 for i:=0 to Count do begin
284 FileName:=AppDir+'\'+BuiltIns
[i
];
286 // On non
-NTFS partitions
, create hard links
.
287 CreateHardLink(FileName
,AppDir
+'\bin\git.exe',0);
290 for i
:=0 to GetArrayLength(BuiltIns
)-1 do begin
291 FileName
:=AppDir
+'\'+BuiltIns[i];
293 // On non-NTFS partitions, copy simply the files.
294 FileCopy(AppDir+'\bin\git
.exe
',FileName,false);
299 Modify the environment
301 This must happen no later than ssPostInstall to make
302 "ChangesEnvironment=yes" not happend before the change!
305 // Get the current user's directories
in PATH
.
306 EnvPath
:=GetEnvStrings('PATH',IsAdminLoggedOn
);
308 // First
, remove the installation directory from PATH
in any
case.
309 for i
:=0 to GetArrayLength(EnvPath
)-1 do begin
310 if Pos(AppDir
,EnvPath
[i
])=1 then begin
315 // Delete HOME
if a previous installation modified it
.
316 EnvHome
:=GetEnvStrings('HOME',IsAdminLoggedOn
);
317 if (GetArrayLength(EnvHome
)=1) and
318 (CompareStr(EnvHome
[0],GetIniString('Environment','HOME','',AppDir
+'\setup.ini'))=0) then begin
319 if not SetEnvStrings('HOME',IsAdminLoggedOn
,True,[]) then begin
320 MsgBox('Unable to reset HOME prior to install.',mbError
,MB_OK
);
324 // Modify the PATH variable
as requested by the user
.
325 if RdbGitCmd
.Checked
or RdbGitCmdTools
.Checked
then begin
326 i
:=GetArrayLength(EnvPath
);
327 SetArrayLength(EnvPath
,i
+1);
329 // List \cmd before
\bin so \cmd has higher priority
and programs
in
330 // there will be called
in favor
of those
in \bin
.
331 EnvPath
[i
]:=ExpandConstant('{app}\cmd');
333 if RdbGitCmdTools
.Checked
then begin
334 SetArrayLength(EnvPath
,i
+2);
335 EnvPath
[i
+1]:=ExpandConstant('{app}\bin');
337 // Set HOME
for the Windows Command Prompt
.
338 EnvHome
:=GetEnvStrings('HOME',IsAdminLoggedOn
);
339 i
:=GetArrayLength(EnvHome
);
340 if (i
=0) or ((i
=1) and (Length(EnvHome
[0])=0)) then begin
341 SetArrayLength(EnvHome
,1);
342 EnvHome
[0]:=ExpandConstant('{%USERPROFILE}');
343 SetEnvStrings('HOME',IsAdminLoggedOn
,True,EnvHome
);
345 // Mark that we have changed HOME
.
346 SetIniString('Environment','HOME',EnvHome
[0],AppDir
+'\setup.ini');
351 // Set the current user
's directories in PATH.
352 SetEnvStrings('PATH
',IsAdminLoggedOn,True,EnvPath);
355 Create the Windows Explorer shell extensions
358 if IsAdminLoggedOn then begin
359 RootKey:=HKEY_LOCAL_MACHINE;
361 RootKey:=HKEY_CURRENT_USER;
364 if IsTaskSelected('shellextension
') then begin
365 RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_shell
','','Git
&Bash Here
');
366 RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_shell\command
','','cmd
.exe
/c
"pushd "%1" && "'+AppDir+'\bin\sh
.exe
" --login -i"');
369 if IsTaskSelected('guiextension
') then begin
370 RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_gui
','','Git
&GUI Here
');
371 RegWriteStringValue(RootKey,'SOFTWARE\Classes\Directory\shell\git_gui\command
','','"'+AppDir+'\bin\wish.exe" "'+AppDir+'\bin\git-gui" "--working-dir" "%1"');
379 function InitializeUninstall:Boolean;
381 Result:=DeleteFile(ExpandConstant('{app}')+'\bin\ssh
-agent
.exe
');
382 if not Result then begin
383 MsgBox('Please stop all ssh
-agent processes
and run uninstall again
.',mbError,MB_OK);
387 procedure CurUninstallStepChanged(CurUninstallStep:TUninstallStep);
389 AppDir,Command:string;
390 EnvPath,EnvHome:TArrayOfString;
394 if CurUninstallStep<>usUninstall then begin
399 Modify the environment
401 This must happen no later than usUninstall to make
402 "ChangesEnvironment=yes" not happend before the change!
405 AppDir:=ExpandConstant('{app}');
407 // Get the current user's directories
in PATH
.
408 EnvPath
:=GetEnvStrings('PATH',IsAdminLoggedOn
);
410 // Remove the installation directory from PATH
in any
case, even
if it
411 // was
not added by the installer
.
412 for i
:=0 to GetArrayLength(EnvPath
)-1 do begin
413 if Pos(AppDir
,EnvPath
[i
])=1 then begin
418 // Reset the current user
's directories in PATH.
419 if not SetEnvStrings('PATH
',IsAdminLoggedOn,True,EnvPath) then begin
420 MsgBox('Unable
to revert any possible changes
to PATH
.',mbError,MB_OK);
423 // Reset the current user's HOME
if we modified it
.
424 EnvHome
:=GetEnvStrings('HOME',IsAdminLoggedOn
);
425 if (GetArrayLength(EnvHome
)=1) and
426 (CompareStr(EnvHome
[0],GetIniString('Environment','HOME','',AppDir
+'\setup.ini'))=0) then begin
427 if not SetEnvStrings('HOME',IsAdminLoggedOn
,True,[]) then begin
428 MsgBox('Unable to revert any possible changes to HOME.',mbError
,MB_OK
);
431 DeleteFile(AppDir
+'\setup.ini');
434 Delete the Windows Explorer shell extensions
437 if IsAdminLoggedOn
then begin
438 RootKey
:=HKEY_LOCAL_MACHINE
;
440 RootKey
:=HKEY_CURRENT_USER
;
444 RegQueryStringValue(RootKey
,'SOFTWARE\Classes\Directory\shell\git_shell\command','',Command
);
445 if Pos(AppDir
,Command
)>0 then begin
446 RegDeleteKeyIncludingSubkeys(RootKey
,'SOFTWARE\Classes\Directory\shell\git_shell');
450 RegQueryStringValue(RootKey
,'SOFTWARE\Classes\Directory\shell\git_gui\command','',Command
);
451 if Pos(AppDir
,Command
)>0 then begin
452 RegDeleteKeyIncludingSubkeys(RootKey
,'SOFTWARE\Classes\Directory\shell\git_gui');