shears.sh: introduce the 'rewind' shortcut
[msysgit.git] / share / WinGit / helpers.inc.iss
blob4b8244239bac247ba36a238706fb8e8e1e716de4
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 i:=i+1;
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 i:=i+1;
32 end;
34 Result[i]:=#0;
35 end;
37 // Deletes the currently processed file as part of Check, BeforeInstall or AfterInstall
38 // from the user's virtual store to ensure the installed file is used.
39 procedure DeleteFromVirtualStore;
40 var
41 VirtualStore,FileName:String;
42 DriveChars:Integer;
43 begin
44 VirtualStore:=AddBackslash(ExpandConstant('{localappdata}'))+'VirtualStore';
45 FileName:=ExpandConstant(CurrentFileName);
46 DriveChars:=Length(ExtractFileDrive(FileName));
47 if DriveChars>0 then begin
48 Delete(FileName,1,DriveChars);
49 FileName:=VirtualStore+FileName;
50 if FileExists(FileName) and (not DeleteFile(FileName)) then begin
51 // This is not a critical error, so just notify the user and continue.
52 Log('Line {#__LINE__}: Unable delete "'+FileName+'".');
53 end;
54 end;
55 end;
57 // Returns the path to the common or user shell folder as specified in "Param".
58 function GetShellFolder(Param:string):string;
59 begin
60 if IsAdminLoggedOn then begin
61 Param:='{common'+Param+'}';
62 end else begin
63 Param:='{user'+Param+'}';
64 end;
65 Result:=ExpandConstant(Param);
66 end;
68 // As IsComponentSelected() is not supported during uninstall, this work-around
69 // simply checks the Registry. This is unreliable if the user runs the installer
70 // twice, the first time selecting the component, the second deselecting it.
71 function IsComponentInstalled(Component:String):Boolean;
72 var
73 UninstallKey,UninstallValue:String;
74 Value:String;
75 begin
76 Result:=False;
78 UninstallKey:='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#APP_NAME}_is1';
79 UninstallValue:='Inno Setup: Selected Components';
81 if RegQueryStringValue(HKEY_LOCAL_MACHINE,UninstallKey,UninstallValue,Value) then begin
82 Result:=(Pos(Component,Value)>0);
83 end;
84 end;
86 // Checks whether the specified directory can be created and written to
87 // by creating all intermediate directories and a temporary file.
88 function IsDirWritable(DirName:String):Boolean;
89 var
90 AbsoluteDir,FirstExistingDir,FirstCreatedDir,FileName:String;
91 begin
92 Result:=True;
94 AbsoluteDir:=ExpandFileName(DirName);
96 FirstExistingDir:=AbsoluteDir;
97 while not DirExists(FirstExistingDir) do begin
98 FirstCreatedDir:=FirstExistingDir;
99 FirstExistingDir:=ExtractFileDir(FirstExistingDir);
100 end;
101 Log('Line {#__LINE__}: First directory in hierarchy that already exists is "' + FirstExistingDir + '".')
103 if Length(FirstCreatedDir)>0 then begin
104 Log('Line {#__LINE__}: First directory in hierarchy needs to be created is "' + FirstCreatedDir + '".')
106 if ForceDirectories(DirName) then begin
107 FileName:=GenerateUniqueName(DirName,'.txt');
108 Log('Line {#__LINE__}: Trying to write to temporary file "' + Filename + '".')
110 if SaveStringToFile(FileName,'This file is writable.',False) then begin
111 if not DeleteFile(FileName) then begin
112 Result:=False;
113 end;
114 end else begin
115 Result:=False;
116 end;
117 end else begin
118 Result:=False;
119 end;
121 if not DelTree(FirstCreatedDir,True,False,True) then begin
122 Result:=False;
123 end;
124 end;
125 end;