Installer: Early check whether the installation directory is writable
[msysgit.git] / share / WinGit / helpers.inc.iss
blob0377dc521b176d60686ef2f100b3e9a338d19c2d
1 // Copies a NULL-terminated array of characters to a string.
2 function ArrayToString(Chars:array of Char):String;
3 var
4 Len,i:Longint;
5 begin
6 Len:=GetArrayLength(Chars);
7 SetLength(Result,Len);
9 i:=0;
10 while (i<Len) and (Chars[i]<>#0) do begin
11 Result[i+1]:=Chars[i];
12 Inc(i);
13 end;
15 SetLength(Result,i);
16 end;
18 // Copies a string to a NULL-terminated array of characters.
19 function StringToArray(Str:String):array of Char;
20 var
21 Len,i:Longint;
22 begin
23 Len:=Length(Str);
24 SetArrayLength(Result,Len+1);
26 i:=0;
27 while i<Len do begin
28 Result[i]:=Str[i+1];
29 Inc(i);
30 end;
32 Result[i]:=#0;
33 end;
35 // Returns the path to the common or user shell folder as specified in "Param".
36 function GetShellFolder(Param:string):string;
37 begin
38 if IsAdminLoggedOn then begin
39 Param:='{common'+Param+'}';
40 end else begin
41 Param:='{user'+Param+'}';
42 end;
43 Result:=ExpandConstant(Param);
44 end;
46 // As IsComponentSelected() is not supported during uninstall, this work-around
47 // simply checks the Registry. This is unreliable if the user runs the installer
48 // twice, the first time selecting the component, the second deselecting it.
49 function IsComponentInstalled(Component:String):Boolean;
50 var
51 UninstallKey,UninstallValue:String;
52 Value:String;
53 begin
54 Result:=False;
56 UninstallKey:='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#APP_NAME}_is1';
57 UninstallValue:='Inno Setup: Selected Components';
59 if RegQueryStringValue(HKEY_LOCAL_MACHINE,UninstallKey,UninstallValue,Value) then begin
60 Result:=(Pos(Component,Value)>0);
61 end;
62 end;
64 // Checks whether the specified directory can be created and written to.
65 // Note that the created dummy file is not explicitly deleted here, so that
66 // needs to be done as part of the uninstall process.
67 function IsDirWritable(DirName:String):Boolean;
68 var
69 FileName:String;
70 begin
71 Result:=False;
73 if not ForceDirectories(DirName) then begin
74 Exit;
75 end;
77 FileName:=DirName+'\setup.ini';
79 if not SetIniBool('Dummy','Writable',true,FileName) then begin
80 Exit;
81 end;
83 Result:=GetIniBool('Dummy','Writable',false,FileName);
84 end;