1 # This script contains the following functions:
3 # - LaTeXCheck (check installed LaTeX-system), uses:
9 # - un.DelAppPathSub and UnAppPreSuff, (delete the folder ~\Documents and Settings\username\Application Data\LyX for all users), uses:
17 # - CreateAppPathSub and AppPreSuff, (creates the folder ~\Documents and Settings\username\Application Data\LyX for all users), uses:
24 # - CheckAppPathPreferences (replaces the old install folder name with the new one in the preferences files)
25 # (used by Update installer), uses:
28 # - IsUserAdmin (checks if user is admin)
30 # - FileCheck (checks if a given file exists)
32 #--------------------------
34 !macro StrPointer FindStr SearchStr Pointer
35 # searches for a string/character (SearchStr) in another string (FindStr)
36 # and returns the number of the character in the FindStr where the SearchStr was found (Pointer)
37 # if nothing was found or the search is impossible the Pointer is set to -1
39 StrLen $R2 ${SearchStr}
46 IntCmp $R4 $R2 loopA NotFound
48 StrCpy $R3 ${FindStr} $R2 $R5
49 StrCmp $R3 ${SearchStr} Found
51 IntCmp $R4 $R5 loopA NotFound
57 StrCpy ${Pointer} "-1"
62 #--------------------------------
65 !insertmacro StrPointer $String $Search $Pointer
68 #--------------------------------
70 !macro RevStrPointer FindStr SearchStr Pointer
71 # searches for a string/character (SearchStr) in another string (FindStr) in reverse order
72 # and returns the number of the character in the FindStr where the SearchStr was found (Pointer)
73 # if nothing was found or the search is impossible the Pointer is set to +1
75 StrLen $R2 ${SearchStr}
81 IntCmp $R4 $R2 loopA NotFound
84 StrCpy $R3 ${FindStr} $R2 $R5
85 StrCmp $R3 ${SearchStr} Found
87 IntCmp "$R5" "-$R4" loopA NotFound
93 StrCpy ${Pointer} "+1"
98 #--------------------------------
101 !insertmacro RevStrPointer $String $Search $Pointer
104 #--------------------------------
106 !macro AppPreSuff AppPre AppSuff
107 # the APPDATA path has always the following structure:
108 # C:\Documents and Settings\username\Application Data
109 # this macro saves the "C:\Documents and Settings\" substring into the variable "AppPre"
110 # and the "Application Data" substring into the variable "AppSuff"
112 StrCpy $String "$APPDATA"
114 Call StrPoint # search for the first "\"
115 IntOp $Pointer $Pointer + 1 # jump after the "\"
116 StrCpy $String $String "" $Pointer # cut off the part before the first "\"
118 Call StrPoint # search for the second "\"
119 IntOp $0 $0 + $Pointer # $0 is now the pointer to the second "\" in the APPDATA string
120 StrCpy ${AppPre} $APPDATA $0 # save the part before the second "\"
121 IntOp $Pointer $Pointer + 1 # jump after the "\"
122 StrCpy $String $String "" $Pointer # cut off the part before the second "\"
123 Call StrPoint # search for the third "\"
124 IntOp $Pointer $Pointer + 1 # jump after the "\"
125 StrCpy ${AppSuff} $String "" $Pointer # save the part after the third "\"
129 #--------------------------------
132 # deletes a subfolder of the APPDATA path for all users
133 # used by the function "un.getUsers"
143 IntCmp $R1 $R2 get 0 get
144 StrCpy $R3 $R0 1 -$R1
156 #--------------------------------
159 # reads the subfolders of the "Documents and Settings" folder to get a list of the users
166 FindFirst $R0 $R1 "$R2\*"
167 StrCmp $R1 "" findend 0
169 IfFileExists "$R2\$R1\*.*" 0 notDir
170 StrCmp $R1 "." notDir
171 StrCmp $R1 ".." notDir
172 StrCmp $R1 "All Users" notDir
173 StrCmp $R1 "Default User" notDir
174 StrCmp $R1 "All Users.WINNT" notDir
175 StrCmp $R1 "Default User.WINNT" notDir
179 StrCmp $R1 "" findend 0
186 #--------------------------------
188 Function un.GetParentA
189 # deletes a subfolder of the APPDATA path for all users
190 # used by the function "un.getUsers"
200 IntCmp $R1 $R2 get 0 get
201 StrCpy $R3 $R0 1 -$R1
213 #--------------------------------
216 # reads the subfolders of the "Documents and Settings" folder to get a list of the users
223 FindFirst $R0 $R1 "$R2\*"
224 StrCmp $R1 "" findend 0
226 IfFileExists "$R2\$R1\*.*" 0 notDir
227 StrCmp $R1 "." notDir
228 StrCmp $R1 ".." notDir
229 StrCmp $R1 "All Users" notDir
230 StrCmp $R1 "Default User" notDir
231 StrCmp $R1 "All Users.WINNT" notDir
232 StrCmp $R1 "Default User.WINNT" notDir
236 StrCmp $R1 "" findend 0
243 #--------------------------------
246 !insertmacro StrPointer $String $Search $Pointer
249 #--------------------------------
251 !macro UnAppPreSuff AppPre AppSuff
252 # the APPDATA path has always the following structure:
253 # C:\Documents and Settings\username\Application Data
254 # this macro saves the "C:\Documents and Settings\" substring into the variable "AppPre"
255 # and the "Application Data" substring into the variable "AppSuff"
257 StrCpy $String "$APPDATA"
259 Call un.StrPoint # search for the first "\"
260 IntOp $Pointer $Pointer + 1 # jump after the "\"
261 StrCpy $String $String "" $Pointer # cut off the part before the first "\"
263 Call un.StrPoint # search for the second "\"
264 IntOp $0 $0 + $Pointer # $0 is now the pointer to the second "\" in the APPDATA string
265 StrCpy ${AppPre} $APPDATA $0 # save the part before the second "\"
266 IntOp $Pointer $Pointer + 1 # jump after the "\"
267 StrCpy $String $String "" $Pointer # cut off the part before the second "\"
268 Call un.StrPoint # search for the third "\"
269 IntOp $Pointer $Pointer + 1 # jump after the "\"
270 StrCpy ${AppSuff} $String "" $Pointer # save the part after the third "\"
274 #--------------------------------
276 Function un.DelAppPathSub
277 # deletes a subfolder of the APPDATA path for all users
279 # get list of all users
285 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
291 # the usernames in the list of all users is separated by "|"
293 StrCpy $String "$UserList"
295 Call un.StrPoint # search for the "|"
296 StrCmp $Pointer "-1" ready
297 StrCpy $0 $UserList $Pointer # $0 contains now the username
298 IntOp $Pointer $Pointer + 1 # jump after the "|"
299 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
300 # generate the string for the current user
301 # AppPre and AppSuff are generated in the macro "AppPreSuff"
302 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
303 RMDir /r $AppPath # delete the folder
307 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
308 RMDir /r $AppPath # delete the folder
312 #--------------------------------
314 Function CreateAppPathSub
315 # creates a subfolder of the APPDATA path for all users
318 !insertmacro AppPreSuff $AppPre $AppSuff
320 # get list of all users
326 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
332 # the usernames in the list of all users is separated by "|"
334 StrCpy $String "$UserList"
336 Call StrPoint # search for the "|"
337 StrCmp $Pointer "-1" ready # the loop is finished when no "|" could be found
338 StrCpy $0 $UserList $Pointer # $0 contains now the username
339 IntOp $Pointer $Pointer + 1 # jump after the "|"
340 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
341 # generate the string for the current user
342 # AppPre and AppSuff are generated in the macro "AppPreSuff"
343 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
344 CreateDirectory $AppPath # create the folder
345 CopyFiles "$INSTDIR\Resources\session" "$AppPath"
348 # now do the same for the last user name
350 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
351 CreateDirectory $AppPath # create the folder
352 CopyFiles "$INSTDIR\Resources\session" "$AppPath"
353 Delete "$INSTDIR\Resources\session" # delete the session file in the INSTDIR because it is unneeded there
357 #--------------------------------
359 Function ReplaceLineContent
360 # replaces "$OldString" with "LyX $NewString"
362 ${WordReplace} '$R9' "$OldString" "$NewString" "+" '$R9' # macro from WordFunc.nsh
367 #--------------------------------
369 Function CheckAppPathPreferences
370 # replaces a string "$OldString" with "$NewString" in a file "$FileName"
373 !insertmacro AppPreSuff $AppPre $AppSuff
375 # get list of all users
381 StrCpy $UserList $R3 "" 1 # cut off the "|" at the end of the list
387 # the usernames in the list of all users is separated by "|"
389 StrCpy $String "$UserList"
391 Call StrPoint # search for the "|"
392 StrCmp $Pointer "-1" ready # the loop is finished when no "|" could be found
393 StrCpy $0 $UserList $Pointer # $0 contains now the username
394 IntOp $Pointer $Pointer + 1 # jump after the "|"
395 StrCpy $UserList $UserList "" $Pointer # cut off the first username in the list
396 # generate the string for the current user
397 # AppPre and AppSuff are generated in the macro "AppPreSuff"
398 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
399 # read the preferences file to test if it exists
400 FileOpen $R1 "$AppPath\$FileName" r
403 # search for "$OldString" and replace it with "$NewString"
404 ${LineFind} "$AppPath\$FileName" "" "1:-1" "ReplaceLineContent" # macro from TextFunc.nsh # calls Function ReplaceLineContent
408 # now do the same for the last user name
410 StrCpy $AppPath "$AppPre\$0\$AppSuff\${PRODUCT_SUBFOLDER}"
411 FileOpen $R1 "$AppPath\$FileName" r
414 ${LineFind} "$AppPath\$FileName" "" "1:-1" "ReplaceLineContent"
419 #--------------------------------
421 !macro IsUserAdmin Result Name
428 UserInfo::GetAccountType
431 StrCpy ${Result} "yes"
433 StrCpy ${Result} "no"
438 StrCpy ${Result} "yes"
443 #--------------------------------
445 !macro FileCheck Result FileName FilePath
446 # checks if a file exists, returns "True" or "False"
452 FileOpen $0 "${Filepath}\${FileName}" r
465 #------------------------------------------
468 # searches the string "$Search" in the string "$String" and extracts the path around it
469 # the extracted path is checked if the file "latex.exe" is in it
474 ${if} $Pointer == "-1" # if nothing was found
478 IntOp $3 $3 - $Pointer
479 StrCpy $4 $String $3 "-$3" # $4 is now the part behind the $Search string
480 StrCpy $String $String $Pointer # $String is now the part before the $Search string
481 StrCpy $Search ":" # search for the ":" after the first previous drive letter
483 IntOp $Pointer $Pointer - 1 # jump before the ":" to the drive letter
484 StrCpy $Pointer $Pointer "" 1 # cut of the "-" sign
485 StrCpy $LatexPath $String $Pointer "-$Pointer"
487 StrCpy $Search ";" # search for the following ";" that separates the different paths
489 ${if} $Pointer != "-1" # if something was found
490 StrCpy $String $String $Pointer
492 StrCpy $LatexPath "$LatexPath$String"
493 # check if the latex.exe exists in the $LatexPath folder
494 !insertmacro FileCheck $5 "latex.exe" "$LatexPath"
495 ${if} $5 == "False" # delete the entry with the wrong path to the latex.exe and try again
498 StrCpy $String $4 "" $3
499 ${if} $2 == "TeXLive"
500 StrCpy $Search "TeXLive"
502 StrCpy $Search "miktex"