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