]> git.lyx.org Git - features.git/blob - development/Win32/packaging/installer/LyXWinInstaller/Uninstall.nsh
adbb52eda4563a107a42a39ef2fda14ba572e9af
[features.git] / development / Win32 / packaging / installer / LyXWinInstaller / Uninstall.nsh
1 # Uninstaller
2
3 # this function is called at first after starting the uninstaller
4 Function un.onInit
5
6   # Check that LyX is not currently running
7   FindProcDLL::FindProc "lyx.exe"
8   ${if} $R0 == "1"
9    MessageBox MB_OK|MB_ICONSTOP "$(UnInstallRunning)"
10    Abort
11   ${endif}
12
13   # set registry root key
14   StrCpy $Answer ""
15   !insertmacro IsUserAdmin $Answer $UserName # macro from LyXUtils.nsh
16   ${if} $Answer == "yes"
17     SetShellVarContext all
18   ${else}
19    SetShellVarContext current
20   ${endif}
21
22   # Ascertain whether the user has sufficient privileges to uninstall.
23   # abort when LyX was installed with admin permissions but the user doesn't have administrator privileges
24   ReadRegStr $0 HKLM "${PRODUCT_UNINST_KEY}" "RootKey"
25   ${if} $0 != ""
26   ${andif} $Answer != "yes"
27    MessageBox MB_OK|MB_ICONSTOP "$(UnNotAdminLabel)"
28    Abort
29   ${endif}
30   # abort when LyX couldn't be found in the registry
31   ${if} $0 == "" # check in HKCU
32    ReadRegStr $0 HKCU "${PRODUCT_UNINST_KEY}" "RootKey"
33    ${if} $0 == ""
34      MessageBox MB_OK|MB_ICONEXCLAMATION "$(UnNotInRegistryLabel)"
35    ${endif}
36   ${endif}
37
38   # Macro to investigate name of LyX's preferences folders to be able remove them
39   !insertmacro UnAppPreSuff $AppPre $AppSuff # macro from LyXUtils.nsh
40
41   # test if Aspell was installed together with LyX
42   ReadRegStr $0 SHCTX "Software\Aspell" "OnlyWithLyX" # special entry to test if it was installed with LyX
43   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
44    SectionSetText 2 "Aspell" # names the corersponding uninstaller section (has the index "2" as it is the third section in Uninstall.nsh)
45    StrCpy $AspellInstallYes "Aspell"
46   ${else}
47    SectionSetText 2 "" # hides the corresponding uninstaller section
48   ${endif}
49
50   # test if MiKTeX was installed together with LyX
51   ReadRegStr $0 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX"
52   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
53    SectionSetText 3 "MiKTeX" # names the corersponding uninstaller section
54    StrCpy $MiKTeXInstalled "MiKTeX"
55   ${else}
56    SectionSetText 3 "" # hides the corresponding uninstaller section
57   ${endif}
58
59   # test if JabRef was installed together with LyX
60   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$JabRefVersionVar" "OnlyWithLyX"
61   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
62    SectionSetText 4 "JabRef" # names the corersponding uninstaller section
63    StrCpy $JabRefInstalled "JabRef"
64   ${else}
65    SectionSetText 4 "" # hides the corresponding uninstaller section
66   ${endif}
67
68   # question message if the user really wants to uninstall LyX
69   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "$(UnReallyRemoveLabel)" IDYES +2 # continue if yes
70   Abort
71
72 FunctionEnd
73
74 # ----------------------------------
75
76 Function un.onUninstSuccess
77   HideWindow
78   MessageBox MB_ICONINFORMATION|MB_OK "$(UnRemoveSuccessLabel)"
79   
80 FunctionEnd
81
82 # ----------------------------------
83 # Uninstall sections
84
85 Section "un.LyX" un.SecUnProgramFiles
86
87   SectionIn RO
88
89   # delete LaTeX class files that were installed together with LyX
90   FileOpen $R5 "$INSTDIR\Resources\uninstallPaths.dat" r
91   FileRead $R5 $LatexPath
92   FileClose $R5
93   StrCpy $String $LatexPath
94   StrCpy $Search "miktex\bin"
95   StrLen $3 $String
96   Call un.StrPoint # search the LaTeXPath for the phrase "miktex\bin" (function from LyXUtils.nsh)
97   ${if} $Pointer != "-1" # if something was found
98    IntOp $Pointer $Pointer - 1 # jump before the first "\" of "\miktex\bin"
99    StrCpy $String $String "$Pointer" # $String is now the part before "\miktex\bin"
100    Delete "$String\tex\latex\cv.cls"
101    RMDir /r "$String\tex\latex\lyx"
102    RMDir /r "$String\tex\latex\revtex"
103    RMDir /r "$String\tex\latex\hollywood"
104    RMDir /r "$String\tex\latex\broadway"
105    ExecWait "$LatexPath\initexmf --update-fndb"
106   ${endif}
107
108   # delete LyX's installation folder
109   RMDir /r $INSTDIR
110   # delete start menu folder
111   ReadRegStr $0 SHCTX "${PRODUCT_UNINST_KEY}" "StartMenu"
112   RMDir /r "$0"
113   # delete desktop icon
114   Delete "$DESKTOP\LyX ${PRODUCT_VERSION}.lnk"
115   # delete registry entries
116   DeleteRegKey HKCU "${PRODUCT_UNINST_KEY}"
117   DeleteRegKey SHCTX "${PRODUCT_UNINST_KEY}"
118   DeleteRegKey SHCTX "${PRODUCT_DIR_REGKEY}"
119   DeleteRegKey HKCR "Applications\lyx.exe"
120   DeleteRegKey HKCR "Applications\lyx.bat"
121
122   # Aiksaurus
123   !insertmacro FileCheck $5 "meanings.dat" "${AiksaurusDir}" # macro from LyXUtils.nsh
124   ${if} $5 == "True"
125    RMDir /r "${AiksaurusDir}"
126   ${endif}
127   ReadRegStr $0 SHCTX "Software\Aiksaurus" "OnlyWithLyX" # special entry to test if it was installed with LyX
128   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
129    # unregister Aiksaurus
130    ReadRegStr $1 SHCTX "Software\Aiksaurus" "Data Path"
131    RMDir /r "$1"
132    DeleteRegKey SHCTX "SOFTWARE\Aiksaurus"
133   ${endif}
134
135   # remove file extension .lyx
136   ReadRegStr $R0 SHCTX "Software\Classes\${PRODUCT_EXT}" ""
137   ${if} $R0 == "${PRODUCT_REGNAME}"
138    DeleteRegKey SHCTX "Software\Classes\${PRODUCT_EXT}"
139    DeleteRegKey SHCTX "Software\Classes\${PRODUCT_REGNAME}"
140   ${endif}
141
142   # the following can only be done with admin permissions
143   ${if} $Answer == "yes" # if admin
144   
145    # ImageMagick
146    ReadRegStr $0 SHCTX "Software\ImageMagick" "OnlyWithLyX" # special entry to test if it was installed with LyX
147    ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
148     # unregister ImageMagick
149     DeleteRegValue SHCTX "SOFTWARE\Classes\Applications" "AutoRun"
150     DeleteRegKey SHCTX "SOFTWARE\ImageMagick"
151    ${endif}
152   
153    # Ghostscript and GSview
154    ReadRegStr $0 HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX" # special entry to test if it was installed with LyX
155    ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
156     # unregister Ghostscript
157     DeleteRegKey HKLM "SOFTWARE\GPL Ghostscript"
158     # test if GSview is installed
159     StrCpy $5 ""
160     EnumRegValue $5 HKLM "Software\Ghostgum\GSview" 0
161     ${if} $5 != ""
162      # unregister GSview
163      MessageBox MB_ICONINFORMATION|MB_OK "$(UnGSview)"
164      ReadRegStr $3 HKLM "Software\Ghostgum\GSview" "$5"
165      ReadRegStr $4 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GSview $5" "UninstallString"
166      ExecWait "$4"
167     ${endif}
168    ${endif}
169    
170    # MiKTeX specific LyX setting 
171    DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MIKTEX_AUTOINSTALL"
172    DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MIKTEX_REPOSITORY"
173    
174   ${endif} # end if Answer (if admin)
175   
176   SetAutoClose true
177
178 SectionEnd
179
180 #---------------------------------
181 # user preferences
182 Section "un.$(UnLyXPreferencesTitle)" un.SecUnPreferences
183
184  # remove LyX's config files
185  Call un.DelAppPathSub # function from LyXUtils.nsh
186   
187 SectionEnd
188
189 #---------------------------------
190 # Aspell
191 Section "un.Aspell" un.SecUnAspell
192
193  ${if} $AspellInstallYes == "Aspell" # only uninstall Aspell when it was installed together with LyX 
194   Call un.UninstAspell # Function from Aspell.nsh
195  ${endif}
196
197 SectionEnd
198
199 #---------------------------------
200 # MiKTeX
201 Section "un.MiKTeX" un.SecUnMiKTeX
202
203  ${if} $MiKTeXInstalled == "MiKTeX" # only uninstall MiKTeX when it was installed together with LyX 
204   ReadRegStr $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$MiKTeXVersionVar" "UninstallString"
205   ExecWait "$1" # run MiKTeX's uninstaller
206  ${endif}
207
208 SectionEnd
209
210 #---------------------------------
211 # JabRef
212 Section "un.JabRef" un.SecUnJabRef
213
214  ${if} $JabRefInstalled == "JabRef" # only uninstall JabRef when it was installed together with LyX 
215   ReadRegStr $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$JabRefVersionVar" "UninstallString"
216   ExecWait "$1" # run JabRef's uninstaller
217  ${endif}
218
219 SectionEnd
220
221 #---------------------------------
222 # Section descriptions
223 !insertmacro MUI_UNFUNCTION_DESCRIPTION_BEGIN
224 !insertmacro MUI_DESCRIPTION_TEXT ${un.SecUnAspell} "$(SecUnAspellDescription)"
225 !insertmacro MUI_DESCRIPTION_TEXT ${un.SecUnMiKTeX} "$(SecUnMiKTeXDescription)"
226 !insertmacro MUI_DESCRIPTION_TEXT ${un.SecUnJabRef} "$(SecUnJabRefDescription)"
227 !insertmacro MUI_DESCRIPTION_TEXT ${un.SecUnPreferences} "$(SecUnPreferencesDescription)"
228 !insertmacro MUI_DESCRIPTION_TEXT ${un.SecUnProgramFiles} "$(SecUnProgramFilesDescription)"
229 !insertmacro MUI_UNFUNCTION_DESCRIPTION_END
230