1 # This script contains the following functions:
3 # - LaTeXCheck (check installed LaTeX-system),
4 # (only used by Small and Complete installer), uses:
10 # - PATHCheck (checks for a path in a semicolon separated path list like the PATH variable), uses:
16 # - un.DelAppPathSub and UnAppPreSuff,
17 # (delete the folder ~\Documents and Settings\username\Application Data\LyX for all users), uses:
25 # - CheckAppPathPreferences (replaces the old install folder name with the new one in the preferences files)
26 # (used by Update installer), uses:
29 # - IsUserAdmin (checks if user is admin)
31 # - FileCheck (checks if a given file exists)
33 #--------------------------
35 !macro StrPointer FindStr SearchStr Pointer
36 # searches for a string/character (SearchStr) in another string (FindStr)
37 # and returns the number of the character in the FindStr where the SearchStr was found (Pointer)
38 # if nothing was found or the search is impossible the Pointer is set to -1
40 StrLen $R2 ${SearchStr}
47 IntCmp $R4 $R2 loopA NotFound
49 StrCpy $R3 ${FindStr} $R2 $R5
50 StrCmp $R3 ${SearchStr} Found
52 IntCmp $R4 $R5 loopA NotFound
58 StrCpy ${Pointer} "-1"
63 #--------------------------------
66 !insertmacro StrPointer $String $Search $Pointer
69 #--------------------------------
71 !macro RevStrPointer FindStr SearchStr Pointer
72 # searches for a string/character (SearchStr) in another string (FindStr) in reverse order
73 # and returns the number of the character in the FindStr where the SearchStr was found (Pointer)
74 # if nothing was found or the search is impossible the Pointer is set to +1
76 StrLen $R2 ${SearchStr}
82 IntCmp $R4 $R2 loopA NotFound
85 StrCpy $R3 ${FindStr} $R2 $R5
86 StrCmp $R3 ${SearchStr} Found
88 IntCmp "$R5" "-$R4" loopA NotFound
94 StrCpy ${Pointer} "+1"
99 #--------------------------------
102 !insertmacro RevStrPointer $String $Search $Pointer
105 #--------------------------------
107 !macro AppPreSuff AppPre AppSuff
108 # the APPDATA path for a local user has for WinXP and 2000 the following structure:
109 # C:\Documents and Settings\username\Application Data
110 # for Win Vista the structure is:
111 # C:\Users\username\AppData\Roaming
112 # this macro saves the "C:\Documents and Settings\" substring into the variable "AppPre"
113 # and the "Application Data" substring into the variable "AppSuff"
115 # switch temporarily to local user because the all users application data path is in
116 # Vista only C:\ProgramData
117 SetShellVarContext current
118 StrCpy $String "$APPDATA"
119 Var /GLOBAL APPDATemp
120 StrCpy $APPDATemp "$APPDATA"
121 ${If} $MultiUser.Privileges == "Admin"
122 ${OrIf} $MultiUser.Privileges == "Power"
123 SetShellVarContext all # move back to all users
126 Call StrPoint # search for the first "\"
127 IntOp $Pointer $Pointer + 1 # jump after the "\"
128 StrCpy $String $String "" $Pointer # cut off the part before the first "\"
130 Call StrPoint # search for the second "\"
131 IntOp $0 $0 + $Pointer # $0 is now the pointer to the second "\" in the APPDATA string
132 StrCpy ${AppPre} $APPDATemp $0 # save the part before the second "\"
133 IntOp $Pointer $Pointer + 1 # jump after the "\"
134 StrCpy $String $String "" $Pointer # cut off the part before the second "\"
135 Call StrPoint # search for the third "\"
136 IntOp $Pointer $Pointer + 1 # jump after the "\"
137 StrCpy ${AppSuff} $String "" $Pointer # save the part after the third "\"
141 #--------------------------------
143 Function un.GetParentA
144 # deletes a subfolder of the APPDATA path for all users
145 # used by the function "un.getUsers"
155 IntCmp $R1 $R2 get 0 get
156 StrCpy $R3 $R0 1 -$R1
168 #--------------------------------
171 # reads the subfolders of the "Documents and Settings" folder to get a list of the users
178 FindFirst $R0 $R1 "$R2\*"
179 StrCmp $R1 "" findend 0
181 IfFileExists "$R2\$R1\*.*" 0 notDir
182 StrCmp $R1 "." notDir
183 StrCmp $R1 ".." notDir
184 StrCmp $R1 "All Users" notDir
185 StrCmp $R1 "Default User" notDir
186 StrCmp $R1 "All Users.WINNT" notDir
187 StrCmp $R1 "Default User.WINNT" notDir
191 StrCmp $R1 "" findend 0
198 #--------------------------------
201 !insertmacro StrPointer $String $Search $Pointer
204 #--------------------------------
206 !macro UnAppPreSuff AppPre AppSuff
207 # the APPDATA path for a local user has for WinXP and 2000 the following structure:
208 # C:\Documents and Settings\username\Application Data
209 # for Win Vista the structure is:
210 # C:\Users\username\AppData\Roaming
211 # this macro saves the "C:\Documents and Settings\" substring into the variable "AppPre"
212 # and the "Application Data" substring into the variable "AppSuff"
214 SetShellVarContext current # switch temoprarily to local user
215 StrCpy $String "$APPDATA"
216 StrCpy $APPDATemp "$APPDATA"
217 ${if} $MultiUser.Privileges == "Admin"
218 ${orif} $MultiUser.Privileges == "Power"
219 SetShellVarContext all # move back to all users
222 Call un.StrPoint # search for the first "\"
223 IntOp $Pointer $Pointer + 1 # jump after the "\"
224 StrCpy $String $String "" $Pointer # cut off the part before the first "\"
226 Call un.StrPoint # search for the second "\"
227 IntOp $0 $0 + $Pointer # $0 is now the pointer to the second "\" in the APPDATA string
228 StrCpy ${AppPre} $APPDATemp $0 # save the part before the second "\"
229 IntOp $Pointer $Pointer + 1 # jump after the "\"
230 StrCpy $String $String "" $Pointer # cut off the part before the second "\"
231 Call un.StrPoint # search for the third "\"
232 IntOp $Pointer $Pointer + 1 # jump after the "\"
233 StrCpy ${AppSuff} $String "" $Pointer # save the part after the third "\"
237 #--------------------------------
239 Function un.DelAppPathSub
240 # deletes a subfolder of the APPDATA path for all users
242 # get list of all users
248 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
254 # the usernames in the list of all users is separated by "|"
256 StrCpy $String "$UserList"
258 Call un.StrPoint # search for the "|"
259 StrCmp $Pointer "-1" ready
260 StrCpy $0 $UserList $Pointer # $0 contains now the username
261 IntOp $Pointer $Pointer + 1 # jump after the "|"
262 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
263 # generate the string for the current user
264 # AppPre and AppSuff are generated in the macro "AppPreSuff"
265 RMDir /r "$AppPre\$0\$AppSuff\$AppSubfolder" # delete the folder
269 RMDir /r "$AppPre\$0\$AppSuff\$AppSubfolder" # delete the folder
273 #--------------------------------
275 !macro FileCheck Result FileName FilePath
276 # checks if a file exists, returns "True" or "False"
282 FileOpen $0 "${FilePath}\${FileName}" r
295 #------------------------------------------
298 # searches the string "$Search" in the string "$String" and extracts the path around it
299 # it is checked if the file "latex.exe" exists in the extracted path
304 ${if} $Pointer == "-1" # if nothing was found
308 IntOp $3 $3 - $Pointer
309 StrCpy $4 $String $3 "-$3" # $4 is now the part behind the $Search string
310 StrCpy $String $String $Pointer # $String is now the part before the $Search string
311 StrCpy $Search ":" # search for the ":" after the first previous drive letter
313 IntOp $Pointer $Pointer - 1 # jump before the ":" to the drive letter
314 StrCpy $Pointer $Pointer "" 1 # cut of the "-" sign
315 StrCpy $PathLaTeX $String $Pointer "-$Pointer"
317 StrCpy $Search ";" # search for the following ";" that separates the different paths
319 ${if} $Pointer != "-1" # if something was found
320 StrCpy $String $String $Pointer
322 StrCpy $PathLaTeX "$PathLaTeX$String"
323 # check if the latex.exe exists in the $PathLaTeX folder
324 !insertmacro FileCheck $5 "latex.exe" "$PathLaTeX"
325 ${if} $5 == "False" # delete the entry with the wrong path to the latex.exe and try again
328 StrCpy $String $4 "" $3
329 ${if} $2 == "TeXLive"
330 StrCpy $Search "TeXLive"
332 StrCpy $Search "miktex"
339 #------------------------------------------
341 !macro PATHCheck PathResult FileName
342 # searches the string "$Search" in the string "$String" and extracts the path around it
343 # it is checked if the given filename exists
345 !define ID ${__LINE__}
348 ${if} $Pointer == "-1" # if nothing was found
349 StrCpy ${PathResult} "False"
350 Goto EndPATHCheck_${ID}
352 IntOp $3 $3 - $Pointer
353 StrCpy $4 $String $3 "-$3" # $4 is now the part behind the $Search string
354 StrCpy $String $String $Pointer # $String is now the part before the $Search string
355 StrCpy $Search ":" # search for the ":" after the first previous drive letter
357 IntOp $Pointer $Pointer - 1 # jump before the ":" to the drive letter
358 StrCpy $Pointer $Pointer "" 1 # cut of the "-" sign
359 StrCpy ${PathResult} $String $Pointer "-$Pointer"
361 StrCpy $Search ";" # search for the following ";" that separates the different paths
363 ${if} $Pointer != "-1" # if something was found
364 StrCpy $String $String $Pointer
366 StrCpy ${PathResult} "${PathResult}$String"
367 # check if the FileName exists in the ${Result} folder
368 !insertmacro FileCheck $Tmp ${FileName} ${PathResult}
369 ${if} $Tmp == "False"
370 StrCpy ${PathResult} "False"