]> git.lyx.org Git - lyx.git/blob - development/Win32/packaging/AltInstaller/Uninstall.nsh
update installer: update also lyx.bat file (needed for new launcher)
[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   # 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    DeleteRegValue SHCTX "Software\Aspell" "OnlyWithLyX" # special entry to test if it was installed with LyX
47   ${else}
48    SectionSetText 2 "" # hides the corresponding uninstaller section
49   ${endif}
50
51   # test if MiKTeX was installed together with LyX
52   ReadRegStr $0 HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX"
53   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
54    SectionSetText 3 "MiKTeX" # names the corersponding uninstaller section
55    StrCpy $MiKTeXInstalled "MiKTeX"
56    DeleteRegValue HKLM "SOFTWARE\MiKTeX.org\MiKTeX" "OnlyWithLyX"
57   ${else}
58    SectionSetText 3 "" # hides the corresponding uninstaller section
59   ${endif}
60
61   # test if JabRef was installed together with LyX
62   ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX"
63   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
64    SectionSetText 4 "JabRef" # names the corersponding uninstaller section
65    StrCpy $JabRefInstalled "JabRef"
66    DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "OnlyWithLyX"
67   ${else}
68    SectionSetText 4 "" # hides the corresponding uninstaller section
69   ${endif}
70
71   # question message if the user really wants to uninstall LyX
72   MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "$(UnReallyRemoveLabel)" IDYES +2 # continue if yes
73   Abort
74
75 FunctionEnd
76
77 # ----------------------------------
78
79 Function un.onUninstSuccess
80   HideWindow
81   MessageBox MB_ICONINFORMATION|MB_OK "$(UnRemoveSuccessLabel)"
82   
83 FunctionEnd
84
85 # ----------------------------------
86 # Uninstall sections
87
88 Section "un.LyX" un.SecUnProgramFiles
89
90   SectionIn RO
91
92   # delete LaTeX class files that were installed together with LyX
93   FileOpen $R5 "$INSTDIR\Resources\uninstallPaths.dat" r
94   FileRead $R5 $LatexPath
95   FileClose $R5
96   StrCpy $String $LatexPath
97   StrCpy $Search "miktex\bin"
98   StrLen $3 $String
99   Call un.StrPoint # search the LaTeXPath for the phrase "miktex\bin" (function from LyXUtils.nsh)
100   ${if} $Pointer != "-1" # if something was found
101    IntOp $Pointer $Pointer - 1 # jump before the first "\" of "\miktex\bin"
102    StrCpy $String $String "$Pointer" # $String is now the part before "\miktex\bin"
103    Delete "$String\tex\latex\cv.cls"
104    RMDir /r "$String\tex\latex\lyx"
105    RMDir /r "$String\tex\latex\revtex"
106    RMDir /r "$String\tex\latex\hollywood"
107    RMDir /r "$String\tex\latex\broadway"
108    ExecWait "$LatexPath\initexmf --update-fndb"
109   ${endif}
110
111   # delete LyX's installation folder
112   RMDir /r $INSTDIR
113   # delete start menu folder
114   ReadRegStr $0 SHCTX "${PRODUCT_UNINST_KEY}" "StartMenu"
115   RMDir /r "$0"
116   # delete desktop icon
117   Delete "$DESKTOP\LyX ${PRODUCT_VERSION}.lnk"
118   # delete registry entries
119   DeleteRegKey HKCU "${PRODUCT_UNINST_KEY}"
120   DeleteRegKey SHCTX "${PRODUCT_UNINST_KEY}"
121   DeleteRegKey SHCTX "${PRODUCT_DIR_REGKEY}"
122   DeleteRegKey HKCR "Applications\lyx.exe"
123   DeleteRegKey HKCR "Applications\lyx.bat"
124
125   # Aiksaurus
126   !insertmacro FileCheck $5 "meanings.dat" "${AiksaurusDir}" # macro from LyXUtils.nsh
127   ${if} $5 == "True"
128    RMDir /r "${AiksaurusDir}"
129   ${endif}
130   ReadRegStr $0 SHCTX "Software\Aiksaurus" "OnlyWithLyX" # special entry to test if it was installed with LyX
131   ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
132    # unregister Aiksaurus
133    ReadRegStr $1 SHCTX "Software\Aiksaurus" "Data Path"
134    RMDir /r "$1"
135    DeleteRegKey SHCTX "SOFTWARE\Aiksaurus"
136   ${endif}
137
138   # remove file extension .lyx
139   ReadRegStr $R0 SHCTX "Software\Classes\${PRODUCT_EXT}" ""
140   ${if} $R0 == "${PRODUCT_REGNAME}"
141    DeleteRegKey SHCTX "Software\Classes\${PRODUCT_EXT}"
142    DeleteRegKey SHCTX "Software\Classes\${PRODUCT_REGNAME}"
143   ${endif}
144
145   # the following can only be done with admin permissions
146   ${if} $Answer == "yes" # if admin
147   
148    # ImageMagick
149    ReadRegStr $0 SHCTX "Software\ImageMagick" "OnlyWithLyX" # special entry to test if it was installed with LyX
150    ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
151     # unregister ImageMagick
152     DeleteRegValue SHCTX "SOFTWARE\Classes\Applications" "AutoRun"
153     DeleteRegKey SHCTX "SOFTWARE\ImageMagick"
154    ${endif}
155   
156    # Ghostscript and GSview
157    ReadRegStr $0 HKLM "SOFTWARE\GPL Ghostscript" "OnlyWithLyX" # special entry to test if it was installed with LyX
158    ${if} $0 == "Yes${PRODUCT_VERSION_SHORT}"
159     # unregister Ghostscript
160     DeleteRegKey HKLM "SOFTWARE\GPL Ghostscript"
161     # test if GSview is installed
162     StrCpy $5 ""
163     EnumRegValue $5 HKLM "Software\Ghostgum\GSview" 0
164     ${if} $5 != ""
165      # unregister GSview
166      MessageBox MB_ICONINFORMATION|MB_OK "$(UnGSview)"
167      ReadRegStr $3 HKLM "Software\Ghostgum\GSview" "$5"
168      ReadRegStr $4 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GSview $5" "UninstallString"
169      ExecWait "$4"
170     ${endif}
171    ${endif}
172    
173    # MiKTeX specific LyX setting !Can be deleted after LyX 1.5.0beta3!
174    DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MIKTEX_AUTOINSTALL"
175    DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "MIKTEX_REPOSITORY"
176    
177   ${endif} # end if Answer (if admin)
178   
179   SetAutoClose true
180
181 SectionEnd
182
183 #---------------------------------
184 # user preferences
185 Section "un.$(UnLyXPreferencesTitle)" un.SecUnPreferences
186
187  # remove LyX's config files
188  Call un.DelAppPathSub # function from LyXUtils.nsh
189   
190 SectionEnd
191
192 #---------------------------------
193 # Aspell
194 Section "un.Aspell" un.SecUnAspell
195
196  ${if} $AspellInstallYes == "Aspell" # only uninstall Aspell when it was installed together with LyX 
197   Call un.UninstAspell # Function from Aspell.nsh
198  ${endif}
199
200 SectionEnd
201
202 #---------------------------------
203 # MiKTeX
204 Section "un.MiKTeX" un.SecUnMiKTeX
205
206  ${if} $MiKTeXInstalled == "MiKTeX" # only uninstall MiKTeX when it was installed together with LyX 
207   ReadRegStr $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MiKTeX ${MiKTeXDeliveredVersion}" "UninstallString"
208   ExecWait $1 # run MiKTeX's uninstaller
209  ${endif}
210
211 SectionEnd
212
213 #---------------------------------
214 # JabRef
215 Section "un.JabRef" un.SecUnJabRef
216
217  ${if} $JabRefInstalled == "JabRef" # only uninstall JabRef when it was installed together with LyX 
218   ReadRegStr $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\JabRef ${JabRefVersion}" "UninstallString"
219   ExecWait "$1" # run JabRef's uninstaller
220  ${endif}
221
222 SectionEnd
223
224 #---------------------------------
225 # Section descriptions
226 !insertmacro MUI_UNFUNCTION_DESCRIPTION_BEGIN
227 !insertmacro MUI_DESCRIPTION_TEXT ${un.SecUnAspell} "$(SecUnAspellDescription)"
228 !insertmacro MUI_DESCRIPTION_TEXT ${un.SecUnMiKTeX} "$(SecUnMiKTeXDescription)"
229 !insertmacro MUI_DESCRIPTION_TEXT ${un.SecUnJabRef} "$(SecUnJabRefDescription)"
230 !insertmacro MUI_DESCRIPTION_TEXT ${un.SecUnPreferences} "$(SecUnPreferencesDescription)"
231 !insertmacro MUI_DESCRIPTION_TEXT ${un.SecUnProgramFiles} "$(SecUnProgramFilesDescription)"
232 !insertmacro MUI_UNFUNCTION_DESCRIPTION_END
233