1 # This script contains the following functions:
3 # - LaTeXCheck (check installed LaTeX-system),
4 # (only used by Small and Complete installer), uses:
10 # - un.DelAppPathSub and UnAppPreSuff,
11 # (delete the folder ~\Documents and Settings\username\Application Data\LyX for all users), uses:
19 # - CheckAppPathPreferences (replaces the old install folder name with the new one in the preferences files)
20 # (used by Update installer), uses:
23 # - IsUserAdmin (checks if user is admin)
25 # - FileCheck (checks if a given file exists)
27 #--------------------------
29 !macro StrPointer FindStr SearchStr Pointer
30 # searches for a string/character (SearchStr) in another string (FindStr)
31 # and returns the number of the character in the FindStr where the SearchStr was found (Pointer)
32 # if nothing was found or the search is impossible the Pointer is set to -1
34 StrLen $R2 ${SearchStr}
41 IntCmp $R4 $R2 loopA NotFound
43 StrCpy $R3 ${FindStr} $R2 $R5
44 StrCmp $R3 ${SearchStr} Found
46 IntCmp $R4 $R5 loopA NotFound
52 StrCpy ${Pointer} "-1"
57 #--------------------------------
60 !insertmacro StrPointer $String $Search $Pointer
63 #--------------------------------
65 !macro RevStrPointer FindStr SearchStr Pointer
66 # searches for a string/character (SearchStr) in another string (FindStr) in reverse order
67 # and returns the number of the character in the FindStr where the SearchStr was found (Pointer)
68 # if nothing was found or the search is impossible the Pointer is set to +1
70 StrLen $R2 ${SearchStr}
76 IntCmp $R4 $R2 loopA NotFound
79 StrCpy $R3 ${FindStr} $R2 $R5
80 StrCmp $R3 ${SearchStr} Found
82 IntCmp "$R5" "-$R4" loopA NotFound
88 StrCpy ${Pointer} "+1"
93 #--------------------------------
96 !insertmacro RevStrPointer $String $Search $Pointer
99 #--------------------------------
101 !macro AppPreSuff AppPre AppSuff
102 # the APPDATA path for a local user has for WinXP and 2000 the following structure:
103 # C:\Documents and Settings\username\Application Data
104 # for Win Vista the structure is:
105 # C:\Users\username\AppData\Roaming
106 # this macro saves the "C:\Documents and Settings\" substring into the variable "AppPre"
107 # and the "Application Data" substring into the variable "AppSuff"
109 # switch temporarily to local user because the all users application data path is in
110 # Vista only C:\ProgramData
111 SetShellVarContext current
112 StrCpy $String "$APPDATA"
113 Var /GLOBAL APPDATemp
114 StrCpy $APPDATemp "$APPDATA"
115 ${If} $MultiUser.Privileges == "Admin"
116 ${OrIf} $MultiUser.Privileges == "Power"
117 SetShellVarContext all # move back to all users
120 Call StrPoint # search for the first "\"
121 IntOp $Pointer $Pointer + 1 # jump after the "\"
122 StrCpy $String $String "" $Pointer # cut off the part before the first "\"
124 Call StrPoint # search for the second "\"
125 IntOp $0 $0 + $Pointer # $0 is now the pointer to the second "\" in the APPDATA string
126 StrCpy ${AppPre} $APPDATemp $0 # save the part before the second "\"
127 IntOp $Pointer $Pointer + 1 # jump after the "\"
128 StrCpy $String $String "" $Pointer # cut off the part before the second "\"
129 Call StrPoint # search for the third "\"
130 IntOp $Pointer $Pointer + 1 # jump after the "\"
131 StrCpy ${AppSuff} $String "" $Pointer # save the part after the third "\"
135 #--------------------------------
137 Function un.GetParentA
138 # deletes a subfolder of the APPDATA path for all users
139 # used by the function "un.getUsers"
149 IntCmp $R1 $R2 get 0 get
150 StrCpy $R3 $R0 1 -$R1
162 #--------------------------------
165 # reads the subfolders of the "Documents and Settings" folder to get a list of the users
172 FindFirst $R0 $R1 "$R2\*"
173 StrCmp $R1 "" findend 0
175 IfFileExists "$R2\$R1\*.*" 0 notDir
176 StrCmp $R1 "." notDir
177 StrCmp $R1 ".." notDir
178 StrCmp $R1 "All Users" notDir
179 StrCmp $R1 "Default User" notDir
180 StrCmp $R1 "All Users.WINNT" notDir
181 StrCmp $R1 "Default User.WINNT" notDir
185 StrCmp $R1 "" findend 0
192 #--------------------------------
195 !insertmacro StrPointer $String $Search $Pointer
198 #--------------------------------
200 !macro UnAppPreSuff AppPre AppSuff
201 # the APPDATA path for a local user has for WinXP and 2000 the following structure:
202 # C:\Documents and Settings\username\Application Data
203 # for Win Vista the structure is:
204 # C:\Users\username\AppData\Roaming
205 # this macro saves the "C:\Documents and Settings\" substring into the variable "AppPre"
206 # and the "Application Data" substring into the variable "AppSuff"
208 SetShellVarContext current # switch temoprarily to local user
209 StrCpy $String "$APPDATA"
210 StrCpy $APPDATemp "$APPDATA"
211 ${if} $MultiUser.Privileges == "Admin"
212 ${orif} $MultiUser.Privileges == "Power"
213 SetShellVarContext all # move back to all users
216 Call un.StrPoint # search for the first "\"
217 IntOp $Pointer $Pointer + 1 # jump after the "\"
218 StrCpy $String $String "" $Pointer # cut off the part before the first "\"
220 Call un.StrPoint # search for the second "\"
221 IntOp $0 $0 + $Pointer # $0 is now the pointer to the second "\" in the APPDATA string
222 StrCpy ${AppPre} $APPDATemp $0 # save the part before the second "\"
223 IntOp $Pointer $Pointer + 1 # jump after the "\"
224 StrCpy $String $String "" $Pointer # cut off the part before the second "\"
225 Call un.StrPoint # search for the third "\"
226 IntOp $Pointer $Pointer + 1 # jump after the "\"
227 StrCpy ${AppSuff} $String "" $Pointer # save the part after the third "\"
231 #--------------------------------
233 Function un.DelAppPathSub
234 # deletes a subfolder of the APPDATA path for all users
236 # get list of all users
242 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
248 # the usernames in the list of all users is separated by "|"
250 StrCpy $String "$UserList"
252 Call un.StrPoint # search for the "|"
253 StrCmp $Pointer "-1" ready
254 StrCpy $0 $UserList $Pointer # $0 contains now the username
255 IntOp $Pointer $Pointer + 1 # jump after the "|"
256 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
257 # generate the string for the current user
258 # AppPre and AppSuff are generated in the macro "AppPreSuff"
259 RMDir /r "$AppPre\$0\$AppSuff\$AppSubfolder" # delete the folder
263 RMDir /r "$AppPre\$0\$AppSuff\$AppSubfolder" # delete the folder
267 #--------------------------------
269 !macro FileCheck Result FileName FilePath
270 # checks if a file exists, returns "True" or "False"
276 FileOpen $0 "${Filepath}\${FileName}" r
289 #------------------------------------------
292 # searches the string "$Search" in the string "$String" and extracts the path around it
293 # the extracted path is checked if the file "latex.exe" is in it
298 ${if} $Pointer == "-1" # if nothing was found
302 IntOp $3 $3 - $Pointer
303 StrCpy $4 $String $3 "-$3" # $4 is now the part behind the $Search string
304 StrCpy $String $String $Pointer # $String is now the part before the $Search string
305 StrCpy $Search ":" # search for the ":" after the first previous drive letter
307 IntOp $Pointer $Pointer - 1 # jump before the ":" to the drive letter
308 StrCpy $Pointer $Pointer "" 1 # cut of the "-" sign
309 StrCpy $PathLaTeX $String $Pointer "-$Pointer"
311 StrCpy $Search ";" # search for the following ";" that separates the different paths
313 ${if} $Pointer != "-1" # if something was found
314 StrCpy $String $String $Pointer
316 StrCpy $PathLaTeX "$PathLaTeX$String"
317 # check if the latex.exe exists in the $PathLaTeX folder
318 !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX"
319 ${if} $5 == "False" # delete the entry with the wrong path to the latex.exe and try again
322 StrCpy $String $4 "" $3
323 ${if} $2 == "TeXLive"
324 StrCpy $Search "TeXLive"
326 StrCpy $Search "miktex"