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 has always the following structure:
116 # C:\Documents and Settings\username\Application Data
117 # this macro saves the "C:\Documents and Settings\" substring into the variable "AppPre"
118 # and the "Application Data" substring into the variable "AppSuff"
120 StrCpy $String "$APPDATA"
122 Call StrPoint # search for the first "\"
123 IntOp $Pointer $Pointer + 1 # jump after the "\"
124 StrCpy $String $String "" $Pointer # cut off the part before the first "\"
126 Call StrPoint # search for the second "\"
127 IntOp $0 $0 + $Pointer # $0 is now the pointer to the second "\" in the APPDATA string
128 StrCpy ${AppPre} $APPDATA $0 # save the part before the second "\"
129 IntOp $Pointer $Pointer + 1 # jump after the "\"
130 StrCpy $String $String "" $Pointer # cut off the part before the second "\"
131 Call StrPoint # search for the third "\"
132 IntOp $Pointer $Pointer + 1 # jump after the "\"
133 StrCpy ${AppSuff} $String "" $Pointer # save the part after the third "\"
137 #--------------------------------
140 # deletes a subfolder of the APPDATA path for all users
141 # used by the function "un.getUsers"
151 IntCmp $R1 $R2 get 0 get
152 StrCpy $R3 $R0 1 -$R1
164 #--------------------------------
167 # reads the subfolders of the "Documents and Settings" folder to get a list of the users
174 FindFirst $R0 $R1 "$R2\*"
175 StrCmp $R1 "" findend 0
177 IfFileExists "$R2\$R1\*.*" 0 notDir
178 StrCmp $R1 "." notDir
179 StrCmp $R1 ".." notDir
180 StrCmp $R1 "All Users" notDir
181 StrCmp $R1 "Default User" notDir
182 StrCmp $R1 "All Users.WINNT" notDir
183 StrCmp $R1 "Default User.WINNT" notDir
187 StrCmp $R1 "" findend 0
194 #--------------------------------
196 Function un.GetParentA
197 # deletes a subfolder of the APPDATA path for all users
198 # used by the function "un.getUsers"
208 IntCmp $R1 $R2 get 0 get
209 StrCpy $R3 $R0 1 -$R1
221 #--------------------------------
224 # reads the subfolders of the "Documents and Settings" folder to get a list of the users
231 FindFirst $R0 $R1 "$R2\*"
232 StrCmp $R1 "" findend 0
234 IfFileExists "$R2\$R1\*.*" 0 notDir
235 StrCmp $R1 "." notDir
236 StrCmp $R1 ".." notDir
237 StrCmp $R1 "All Users" notDir
238 StrCmp $R1 "Default User" notDir
239 StrCmp $R1 "All Users.WINNT" notDir
240 StrCmp $R1 "Default User.WINNT" notDir
244 StrCmp $R1 "" findend 0
251 #--------------------------------
254 !insertmacro StrPointer $String $Search $Pointer
257 #--------------------------------
259 !macro UnAppPreSuff AppPre AppSuff
260 # the APPDATA path has always the following structure:
261 # C:\Documents and Settings\username\Application Data
262 # this macro saves the "C:\Documents and Settings\" substring into the variable "AppPre"
263 # and the "Application Data" substring into the variable "AppSuff"
265 StrCpy $String "$APPDATA"
267 Call un.StrPoint # search for the first "\"
268 IntOp $Pointer $Pointer + 1 # jump after the "\"
269 StrCpy $String $String "" $Pointer # cut off the part before the first "\"
271 Call un.StrPoint # search for the second "\"
272 IntOp $0 $0 + $Pointer # $0 is now the pointer to the second "\" in the APPDATA string
273 StrCpy ${AppPre} $APPDATA $0 # save the part before the second "\"
274 IntOp $Pointer $Pointer + 1 # jump after the "\"
275 StrCpy $String $String "" $Pointer # cut off the part before the second "\"
276 Call un.StrPoint # search for the third "\"
277 IntOp $Pointer $Pointer + 1 # jump after the "\"
278 StrCpy ${AppSuff} $String "" $Pointer # save the part after the third "\"
282 #--------------------------------
284 Function un.DelAppPathSub
285 # deletes a subfolder of the APPDATA path for all users
287 # get list of all users
293 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
299 # the usernames in the list of all users is separated by "|"
301 StrCpy $String "$UserList"
303 Call un.StrPoint # search for the "|"
304 StrCmp $Pointer "-1" ready
305 StrCpy $0 $UserList $Pointer # $0 contains now the username
306 IntOp $Pointer $Pointer + 1 # jump after the "|"
307 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
308 # generate the string for the current user
309 # AppPre and AppSuff are generated in the macro "AppPreSuff"
310 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
311 RMDir /r $AppPath # delete the folder
315 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
316 RMDir /r $AppPath # delete the folder
320 #--------------------------------
322 !if ${INSTALLER_TYPE} == "NotUpdate" # only for Small and Complete installer
324 Function CreateAppPathSub
325 # creates a subfolder of the APPDATA path for all users
328 !insertmacro AppPreSuff $AppPre $AppSuff
330 # get list of all users
336 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
342 # the usernames in the list of all users is separated by "|"
344 StrCpy $String "$UserList"
346 Call StrPoint # search for the "|"
347 StrCmp $Pointer "-1" ready # the loop is finished when no "|" could be found
348 StrCpy $0 $UserList $Pointer # $0 contains now the username
349 IntOp $Pointer $Pointer + 1 # jump after the "|"
350 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
351 # generate the string for the current user
352 # AppPre and AppSuff are generated in the macro "AppPreSuff"
353 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
354 CreateDirectory $AppPath # create the folder
355 CopyFiles "$INSTDIR\Resources\session" "$AppPath"
358 # now do the same for the last user name
360 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
361 CreateDirectory $AppPath # create the folder
362 CopyFiles "$INSTDIR\Resources\session" "$AppPath"
363 Delete "$INSTDIR\Resources\session" # delete the session file in the INSTDIR because it is unneeded there
367 !endif # endif ${INSTALLER_TYPE} == "NotUpdate"
369 #--------------------------------
371 !if ${INSTALLER_TYPE} == "Update" # only for Update installer
373 Function ReplaceLineContent
374 # replaces "$OldString" with "LyX $NewString"
376 ${WordReplace} '$R9' "$OldString" "$NewString" "+" '$R9' # macro from WordFunc.nsh
381 !endif # endif ${INSTALLER_TYPE} == "Update"
383 #--------------------------------
385 !if ${INSTALLER_TYPE} == "Update" # only for Update installer
387 Function CheckAppPathPreferences
388 # replaces a string "$OldString" with "$NewString" in a file "$FileName"
391 !insertmacro AppPreSuff $AppPre $AppSuff
393 # get list of all users
399 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
405 # the usernames in the list of all users is separated by "|"
407 StrCpy $String "$UserList"
409 Call StrPoint # search for the "|"
410 StrCmp $Pointer "-1" ready # the loop is finished when no "|" could be found
411 StrCpy $0 $UserList $Pointer # $0 contains now the username
412 IntOp $Pointer $Pointer + 1 # jump after the "|"
413 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
414 # generate the string for the current user
415 # AppPre and AppSuff are generated in the macro "AppPreSuff"
416 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
417 # read the preferences file to test if it exists
418 FileOpen $R1 "$AppPath\$FileName" r
421 # search for "$OldString" and replace it with "$NewString"
422 ${LineFind} "$AppPath\$FileName" "" "1:-1" "ReplaceLineContent" # macro from TextFunc.nsh # calls Function ReplaceLineContent
426 # now do the same for the last user name
428 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
429 FileOpen $R1 "$AppPath\$FileName" r
432 ${LineFind} "$AppPath\$FileName" "" "1:-1" "ReplaceLineContent"
437 !endif # endif ${INSTALLER_TYPE} == "Update"
439 #--------------------------------
441 !macro IsUserAdmin Result Name
448 UserInfo::GetAccountType
451 StrCpy ${Result} "yes"
453 StrCpy ${Result} "no"
458 StrCpy ${Result} "yes"
463 #--------------------------------
465 !macro FileCheck Result FileName FilePath
466 # checks if a file exists, returns "True" or "False"
472 FileOpen $0 "${Filepath}\${FileName}" r
485 #------------------------------------------
487 !if ${INSTALLER_TYPE} == "NotUpdate" # only for Small and Complete installer
490 # searches the string "$Search" in the string "$String" and extracts the path around it
491 # the extracted path is checked if the file "latex.exe" is in it
496 ${if} $Pointer == "-1" # if nothing was found
500 IntOp $3 $3 - $Pointer
501 StrCpy $4 $String $3 "-$3" # $4 is now the part behind the $Search string
502 StrCpy $String $String $Pointer # $String is now the part before the $Search string
503 StrCpy $Search ":" # search for the ":" after the first previous drive letter
505 IntOp $Pointer $Pointer - 1 # jump before the ":" to the drive letter
506 StrCpy $Pointer $Pointer "" 1 # cut of the "-" sign
507 StrCpy $LatexPath $String $Pointer "-$Pointer"
509 StrCpy $Search ";" # search for the following ";" that separates the different paths
511 ${if} $Pointer != "-1" # if something was found
512 StrCpy $String $String $Pointer
514 StrCpy $LatexPath "$LatexPath$String"
515 # check if the latex.exe exists in the $LatexPath folder
516 !insertmacro FileCheck $5 "latex.exe" "$LatexPath"
517 ${if} $5 == "False" # delete the entry with the wrong path to the latex.exe and try again
520 StrCpy $String $4 "" $3
521 ${if} $2 == "TeXLive"
522 StrCpy $Search "TeXLive"
524 StrCpy $Search "miktex"
531 !endif # endif ${INSTALLER_TYPE} == "NotUpdate"