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