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 # - CreateAppPathSub and AppPreSuff,
20 # (creates the folder ~\Documents and Settings\username\Application Data\LyX for all users),
21 # (only used by Small and Complete installer), uses:
28 # - CheckAppPathPreferences (replaces the old install folder name with the new one in the preferences files)
29 # (used by Update installer), uses:
32 # - IsUserAdmin (checks if user is admin)
34 # - FileCheck (checks if a given file exists)
36 #--------------------------
38 !macro StrPointer FindStr SearchStr Pointer
39 # searches for a string/character (SearchStr) in another string (FindStr)
40 # and returns the number of the character in the FindStr where the SearchStr was found (Pointer)
41 # if nothing was found or the search is impossible the Pointer is set to -1
43 StrLen $R2 ${SearchStr}
50 IntCmp $R4 $R2 loopA NotFound
52 StrCpy $R3 ${FindStr} $R2 $R5
53 StrCmp $R3 ${SearchStr} Found
55 IntCmp $R4 $R5 loopA NotFound
61 StrCpy ${Pointer} "-1"
66 #--------------------------------
69 !insertmacro StrPointer $String $Search $Pointer
72 #--------------------------------
74 !macro RevStrPointer FindStr SearchStr Pointer
75 # searches for a string/character (SearchStr) in another string (FindStr) in reverse order
76 # and returns the number of the character in the FindStr where the SearchStr was found (Pointer)
77 # if nothing was found or the search is impossible the Pointer is set to +1
79 StrLen $R2 ${SearchStr}
85 IntCmp $R4 $R2 loopA NotFound
88 StrCpy $R3 ${FindStr} $R2 $R5
89 StrCmp $R3 ${SearchStr} Found
91 IntCmp "$R5" "-$R4" loopA NotFound
97 StrCpy ${Pointer} "+1"
102 #--------------------------------
104 !if ${INSTALLER_TYPE} == "NotUpdate" # only for Small and Complete installer
107 !insertmacro RevStrPointer $String $Search $Pointer
110 !endif # endif ${INSTALLER_TYPE} == "NotUpdate"
112 #--------------------------------
114 !macro AppPreSuff AppPre AppSuff
115 # the APPDATA path for a local user has for WinXP and 2000 the following structure:
116 # C:\Documents and Settings\username\Application Data
117 # for Win Vista the structure is:
118 # C:\Users\username\AppData\Roaming
119 # this macro saves the "C:\Documents and Settings\" substring into the variable "AppPre"
120 # and the "Application Data" substring into the variable "AppSuff"
122 # switch temporarily to local user because the all users application data path is in
123 # Vista only C:\ProgramData
124 SetShellVarContext current
125 StrCpy $String "$APPDATA"
126 Var /GLOBAL APPDATemp
127 StrCpy $APPDATemp "$APPDATA"
128 ${if} $ProductRootKey == "HKLM"
129 SetShellVarContext all # move back to all users
132 Call StrPoint # search for the first "\"
133 IntOp $Pointer $Pointer + 1 # jump after the "\"
134 StrCpy $String $String "" $Pointer # cut off the part before the first "\"
136 Call StrPoint # search for the second "\"
137 IntOp $0 $0 + $Pointer # $0 is now the pointer to the second "\" in the APPDATA string
138 StrCpy ${AppPre} $APPDATemp $0 # save the part before the second "\"
139 IntOp $Pointer $Pointer + 1 # jump after the "\"
140 StrCpy $String $String "" $Pointer # cut off the part before the second "\"
141 Call StrPoint # search for the third "\"
142 IntOp $Pointer $Pointer + 1 # jump after the "\"
143 StrCpy ${AppSuff} $String "" $Pointer # save the part after the third "\"
147 #--------------------------------
150 # deletes a subfolder of the APPDATA path for all users
151 # used by the function "un.getUsers"
161 IntCmp $R1 $R2 get 0 get
162 StrCpy $R3 $R0 1 -$R1
174 #--------------------------------
177 # reads the subfolders of the "Documents and Settings" folder to get a list of the users
184 FindFirst $R0 $R1 "$R2\*"
185 StrCmp $R1 "" findend 0
187 IfFileExists "$R2\$R1\*.*" 0 notDir
188 StrCmp $R1 "." notDir
189 StrCmp $R1 ".." notDir
190 StrCmp $R1 "All Users" notDir
191 StrCmp $R1 "Default User" notDir
192 StrCmp $R1 "All Users.WINNT" notDir
193 StrCmp $R1 "Default User.WINNT" notDir
197 StrCmp $R1 "" findend 0
204 #--------------------------------
206 Function un.GetParentA
207 # deletes a subfolder of the APPDATA path for all users
208 # used by the function "un.getUsers"
218 IntCmp $R1 $R2 get 0 get
219 StrCpy $R3 $R0 1 -$R1
231 #--------------------------------
234 # reads the subfolders of the "Documents and Settings" folder to get a list of the users
241 FindFirst $R0 $R1 "$R2\*"
242 StrCmp $R1 "" findend 0
244 IfFileExists "$R2\$R1\*.*" 0 notDir
245 StrCmp $R1 "." notDir
246 StrCmp $R1 ".." notDir
247 StrCmp $R1 "All Users" notDir
248 StrCmp $R1 "Default User" notDir
249 StrCmp $R1 "All Users.WINNT" notDir
250 StrCmp $R1 "Default User.WINNT" notDir
254 StrCmp $R1 "" findend 0
261 #--------------------------------
264 !insertmacro StrPointer $String $Search $Pointer
267 #--------------------------------
269 !macro UnAppPreSuff AppPre AppSuff
270 # the APPDATA path for a local user has for WinXP and 2000 the following structure:
271 # C:\Documents and Settings\username\Application Data
272 # for Win Vista the structure is:
273 # C:\Users\username\AppData\Roaming
274 # this macro saves the "C:\Documents and Settings\" substring into the variable "AppPre"
275 # and the "Application Data" substring into the variable "AppSuff"
277 SetShellVarContext current # switch temoprarily to local user
278 StrCpy $String "$APPDATA"
279 StrCpy $APPDATemp "$APPDATA"
280 ${if} $Answer == "yes" # then user has admin priviledges
281 SetShellVarContext all # move back to all users
284 Call un.StrPoint # search for the first "\"
285 IntOp $Pointer $Pointer + 1 # jump after the "\"
286 StrCpy $String $String "" $Pointer # cut off the part before the first "\"
288 Call un.StrPoint # search for the second "\"
289 IntOp $0 $0 + $Pointer # $0 is now the pointer to the second "\" in the APPDATA string
290 StrCpy ${AppPre} $APPDATemp $0 # save the part before the second "\"
291 IntOp $Pointer $Pointer + 1 # jump after the "\"
292 StrCpy $String $String "" $Pointer # cut off the part before the second "\"
293 Call un.StrPoint # search for the third "\"
294 IntOp $Pointer $Pointer + 1 # jump after the "\"
295 StrCpy ${AppSuff} $String "" $Pointer # save the part after the third "\"
299 #--------------------------------
301 Function un.DelAppPathSub
302 # deletes a subfolder of the APPDATA path for all users
304 # get list of all users
310 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
316 # the usernames in the list of all users is separated by "|"
318 StrCpy $String "$UserList"
320 Call un.StrPoint # search for the "|"
321 StrCmp $Pointer "-1" ready
322 StrCpy $0 $UserList $Pointer # $0 contains now the username
323 IntOp $Pointer $Pointer + 1 # jump after the "|"
324 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
325 # generate the string for the current user
326 # AppPre and AppSuff are generated in the macro "AppPreSuff"
327 RMDir /r "$AppPre\$0\$AppSuff\$AppSubfolder" # delete the folder
331 RMDir /r "$AppPre\$0\$AppSuff\$AppSubfolder" # delete the folder
335 #--------------------------------
337 !if ${INSTALLER_TYPE} == "NotUpdate" # only for Small and Complete installer
339 Function CreateAppPathSub
340 # creates a subfolder of the APPDATA path for all users
343 !insertmacro AppPreSuff $AppPre $AppSuff
345 # get list of all users
351 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
357 # the usernames in the list of all users is separated by "|"
359 StrCpy $String "$UserList"
361 Call StrPoint # search for the "|"
362 StrCmp $Pointer "-1" ready # the loop is finished when no "|" could be found
363 StrCpy $0 $UserList $Pointer # $0 contains now the username
364 IntOp $Pointer $Pointer + 1 # jump after the "|"
365 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
366 # generate the string for the current user
367 # AppPre and AppSuff are generated in the macro "AppPreSuff"
368 CreateDirectory "$AppPre\$0\$AppSuff\$AppSubfolder" # create the folder
369 CopyFiles "$AppFiles" "$AppPre\$0\$AppSuff\$AppSubfolder"
372 # now do the same for the last user name
374 CreateDirectory "$AppPre\$0\$AppSuff\$AppSubfolder" # create the folder
375 CopyFiles "$AppFiles" "$AppPre\$0\$AppSuff\$AppSubfolder"
379 !endif # endif ${INSTALLER_TYPE} == "NotUpdate"
381 #--------------------------------
383 !if ${INSTALLER_TYPE} == "Update" # only for Update installer
385 Function ReplaceLineContent
386 # replaces "$OldString" with "LyX $NewString"
388 ${WordReplace} '$R9' "$OldString" "$NewString" "+" '$R9' # macro from WordFunc.nsh
393 !endif # endif ${INSTALLER_TYPE} == "Update"
395 #--------------------------------
397 !if ${INSTALLER_TYPE} == "Update" # only for Update installer
399 Function CheckAppPathPreferences
400 # replaces a string "$OldString" with "$NewString" in a file "$FileName"
403 !insertmacro AppPreSuff $AppPre $AppSuff
405 # get list of all users
411 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
417 # the usernames in the list of all users is separated by "|"
419 StrCpy $String "$UserList"
421 Call StrPoint # search for the "|"
422 StrCmp $Pointer "-1" ready # the loop is finished when no "|" could be found
423 StrCpy $0 $UserList $Pointer # $0 contains now the username
424 IntOp $Pointer $Pointer + 1 # jump after the "|"
425 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
426 # generate the string for the current user
427 # AppPre and AppSuff are generated in the macro "AppPreSuff"
428 StrCpy $AppPath "$AppPre\$0\$AppSuff\$AppSubfolder"
429 # read the preferences file to test if it exists
430 FileOpen $R1 "$AppPath\$FileName" r
433 # search for "$OldString" and replace it with "$NewString"
434 ${LineFind} "$AppPath\$FileName" "" "1:-1" "ReplaceLineContent" # macro from TextFunc.nsh # calls Function ReplaceLineContent
438 # now do the same for the last user name
440 StrCpy $AppPath "$AppPre\$0\$AppSuff\$AppSubfolder"
441 FileOpen $R1 "$AppPath\$FileName" r
444 ${LineFind} "$AppPath\$FileName" "" "1:-1" "ReplaceLineContent"
449 !endif # endif ${INSTALLER_TYPE} == "Update"
451 #--------------------------------
453 !macro IsUserAdmin Result Name
460 UserInfo::GetAccountType
463 StrCpy ${Result} "yes"
465 StrCpy ${Result} "no"
470 StrCpy ${Result} "yes"
475 #--------------------------------
477 !macro FileCheck Result FileName FilePath
478 # checks if a file exists, returns "True" or "False"
484 FileOpen $0 "${Filepath}\${FileName}" r
497 #------------------------------------------
499 !if ${INSTALLER_TYPE} == "NotUpdate" # only for Small and Complete installer
502 # searches the string "$Search" in the string "$String" and extracts the path around it
503 # the extracted path is checked if the file "latex.exe" is in it
508 ${if} $Pointer == "-1" # if nothing was found
512 IntOp $3 $3 - $Pointer
513 StrCpy $4 $String $3 "-$3" # $4 is now the part behind the $Search string
514 StrCpy $String $String $Pointer # $String is now the part before the $Search string
515 StrCpy $Search ":" # search for the ":" after the first previous drive letter
517 IntOp $Pointer $Pointer - 1 # jump before the ":" to the drive letter
518 StrCpy $Pointer $Pointer "" 1 # cut of the "-" sign
519 StrCpy $LatexPath $String $Pointer "-$Pointer"
521 StrCpy $Search ";" # search for the following ";" that separates the different paths
523 ${if} $Pointer != "-1" # if something was found
524 StrCpy $String $String $Pointer
526 StrCpy $LatexPath "$LatexPath$String"
527 # check if the latex.exe exists in the $LatexPath folder
528 !insertmacro FileCheck $5 "latex.exe" "$LatexPath"
529 ${if} $5 == "False" # delete the entry with the wrong path to the latex.exe and try again
532 StrCpy $String $4 "" $3
533 ${if} $2 == "TeXLive"
534 StrCpy $Search "TeXLive"
536 StrCpy $Search "miktex"
543 !endif # endif ${INSTALLER_TYPE} == "NotUpdate"