/ windows / setup.nsi
setup.nsi
  1  ###################################################################################################
  2  # setup.nsi
  3  #
  4  # This file contains the NSIS setup script for the Windows version of POV-Ray.
  5  #
  6  # Compiling this file requires the Nullsoft Scriptable Install System. It has only been tested with
  7  # NSIS v2.46.
  8  #
  9  # Before compiling please read "Customization Notes" below. Once you have set up your distribution
 10  # tree and updated the variable definitions in this file, you may execute "makensis setup.nsi" to
 11  # build the output file.
 12  #
 13  ###################################################################################################
 14  #
 15  # Persistence of Vision Ray Tracer ('POV-Ray') version 3.7.
 16  # Copyright 1991-2013 Persistence of Vision Raytracer Pty. Ltd.
 17  # 
 18  # POV-Ray is free software: you can redistribute it and/or modify
 19  # it under the terms of the GNU Affero General Public License as
 20  # published by the Free Software Foundation, either version 3 of the
 21  # License, or (at your option) any later version.
 22  # 
 23  # POV-Ray is distributed in the hope that it will be useful,
 24  # but WITHOUT ANY WARRANTY; without even the implied warranty of
 25  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 26  # GNU Affero General Public License for more details.
 27  #
 28  # You should have received a copy of the GNU Affero General Public License
 29  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 30  #
 31  ###################################################################################################
 32  #
 33  # $File: //depot/public/povray/3.x/windows/setup.nsi $
 34  # $Revision: #1 $
 35  # $Change: 6069 $
 36  # $DateTime: 2013/11/06 11:59:40 $
 37  # $Author: chrisc $
 38  #
 39  ###################################################################################################
 40  #
 41  # Customization Notes:
 42  #
 43  # Please read these instructions in order to customize this install script for your use. Doing so
 44  # involves two main steps: firstly, setting up a install tree containing the files in a particular
 45  # layout, and secondly changing various variables, such as adding your name to the 'Company' field,
 46  # choosing the default destination (please do not use the same default as official POV-Ray), and so
 47  # on. Once you have done all of this you should comment-out the '!error' directive below.
 48  #
 49  # You must set INSTROOT to point at a tree containing a set of files in the layout expected by this 
 50  # script. Basically the tree as presented here is almost identical to what will end up on the target
 51  # system's drive, divided into two sections: core files (usable by everyone) and user-specific files
 52  # (need to be installed for each user). This looks something like the following:
 53  #
 54  #   ./agpl-3.0.txt
 55  #   ./changes.txt
 56  #   ./revision.txt
 57  #   ./core
 58  #     ./core/bin
 59  #     ./core/help
 60  #     ./core/sounds
 61  #     ./core/tiles
 62  #   ./user
 63  #     ./user/include
 64  #     ./user/ini
 65  #     ./user/Insert Menu
 66  #     ./user/scenes
 67  #
 68  # Note in particular that within the ./core/bin directory you must re-name any files that contain
 69  # 'POV-Ray' to contain ${MYABBREV} as defined below; e.g. using the example 'Laser-Ray' abbreviation
 70  # "POV-Ray.Scene.ico" would become "Laser-Ray.Scene.ico". Additionally any files prefixed with
 71  # "pvengine" (e.g. all default EXE's) must have that prefix replaced with ${MYEXEPREFIX}.
 72  #
 73  # Additionally some files not part of the build are added to ./core/bin allow for supporting dumps;
 74  # these are dbghelp.dll and submitminidump.exe. The former is available from Microsoft and may be
 75  # omitted if you do not wish to support writing minidumps if the program crashes, and the latter
 76  # (which uploads minidumps to the POV-Ray bug tracker) is only part of official distributions and
 77  # should never be part of a custom install.
 78  #
 79  # Apart from the above extra DLL's, the only other files needed in ./core/bin are the icons used for
 80  # shortcuts; you may copy these from distribution/platform-specific/windows/icons/ (but be sure to
 81  # re-name them as discussed above).
 82  #
 83  # NB: The path 'distribution/' refers to the directory of that name in the standard POV-Ray source
 84  # tree (on the same level as 'libraries', 'source', 'vfe', 'unix', etc). 
 85  #
 86  #   ./agpl-3.0.txt       copied from distribution/
 87  #   ./changes.txt        copied from the top-level of the source tree
 88  #   ./revision.txt       copied from the top-level of the source tree
 89  #
 90  #   ./core/help/         copied from distribution/platform-specific/windows/help/
 91  #   ./core/sounds/       copied from distribution/platform-specific/windows/sounds/
 92  #   ./core/tiles/        copied from distribution/platform-specific/windows/tiles/
 93  #
 94  # It is safe to omit ./core/sounds/ and ./core/tiles/ if you wish. in particular the tiles are
 95  # rarely used nowadays (defaulting to being off - they are a feature from the mid 1990's).
 96  #
 97  #   ./user/include/      copied from distribution/include/
 98  #   ./user/ini/          copied from distribution/ini/ and distribution/platform-specific/windows/ini/
 99  #   ./user/Insert Menu/  copied from distribution/platform-specific/windows/Insert Menu/
100  #   ./user/scenes/       copied from distribution/scenes/
101  #
102  # Please keep in mind that the compiled executables will look in a particular location in the registry
103  # for the install path (so that they can find the include and INI files, for example). Generally it
104  # can work this out automatically but nevertheless it is best to ensure that the registry path compiled
105  # in is the same as the registry path constructed by this installer. The path is constructed as follows:
106  #
107  #   HKCU\SOFTWARE\${MYCOMPANY}\${MYPRODUCT}\${VERSIONSTR}
108  #
109  # e.g. given the below defaults, "HKCU\Software\Acme Space Blasters Inc.\Laser-Ray Pro\v1.1". POVWIN
110  # declares its registry path macros in PVEDIT.H, so look there to see what it is using.
111  #
112  # NOTE: If your version acts differently from the official POV-Ray sources from which it is derived
113  # you are strongly urged to change MYSCENEEXT below to something other than 'pov' (and re-name the
114  # sample scenes accordingly). Failing to do this could result in your version taking over the .POV
115  # file association on another users system (presuming that user has already installed POV-Ray). If
116  # your version is not a 1:1 direct replacement for the official version this may not be desirable.
117  # In addition, if that user ever installs an official distribution of POV-Ray after having installed
118  # your renderer, the opposite will happen: POV-Ray will take over the association (reasonable given
119  # .POV files have been the default extension for POV-Ray for more than 20 years).
120  #
121  ###################################################################################################
122  # READ THE ABOVE THEN MODIFY THE FOLLOWING VARIABLES TO SUIT YOUR INSTALLATION.
123  !error "READ INSTRUCTIONS IN SETUP.NSI TO AVOID THIS ERROR"
124  !define INSTROOT     "c:\read\setup.nsi\and\change\this"
125  !define MYCOMPANY    "Acme Space Blasters Inc."
126  !define MYPRODUCT    "Laser-Ray Pro"
127  !define MYABBREV     "Laser-Ray"
128  !define MYVER        "1.1"
129  !define MYSUBVER     "0.0"
130  !define MYURL        "http://acme-space-blasters.tycho.mars/"
131  !define MYCOPYRIGHT  "Copyright(c) 2050-2051 Acme Space Blasters. Inc."
132  !define MYEXEPREFIX  "lasray"
133  !define MYSCENEEXT   "pov"
134  !define MYHELPFILE   "povray37.chm"
135  ###################################################################################################
136  
137  RequestExecutionLevel highest
138  SetCompressor /SOLID lzma
139  Name "${MYPRODUCT}"
140  !define VERSIONSTR "v${MYVER}"
141  !define BINDEST "${MYCOMPANY}\${MYPRODUCT}\${VERSIONSTR}"
142  !define DOCDEST "$DOCUMENTS\${MYCOMPANY}\${MYPRODUCT}\${VERSIONSTR}"
143  !define REGKEY "SOFTWARE\${MYCOMPANY}\${MYPRODUCT}\${VERSIONSTR}"
144  !define UNINSTALL_REG_SUFFIX "${VERSIONSTR}"
145  !define URL ${MYURL}
146  
147  # MUI Symbol Definitions
148  !define MUI_ICON "${INSTROOT}\Core\Bin\${MYABBREV}.ico"
149  !define MUI_STARTMENUPAGE_REGISTRY_ROOT HKCU
150  !define MUI_STARTMENUPAGE_NODISABLE
151  !define MUI_STARTMENUPAGE_REGISTRY_KEY "${REGKEY}\Components"
152  !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME StartMenuGroup
153  !define MUI_STARTMENUPAGE_DEFAULTFOLDER "${MYPRODUCT} ${VERSIONSTR}"
154  !define MUI_UNICON "${INSTROOT}\Core\Bin\${MYABBREV}.ico"
155  !define MUI_UNFINISHPAGE_NOAUTOCLOSE
156  
157  !define MUI_FINISHPAGE_SHOWREADME "$DocDir\changes.txt"
158  !define MUI_FINISHPAGE_SHOWREADME_TEXT "Display change list."
159  
160  # Included files
161  !include Sections.nsh
162  !include MUI2.nsh
163  !include x64.nsh
164  !include FileFunc.nsh
165  
166  !define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the installation of $(^NameDA) ${VERSIONSTR}.$\r$\n$\r$\nPress Next to continue."
167  !define MUI_UNCONFIRMPAGE_TEXT_TOP "The following $(^NameDA) installation will be uninstalled.$\r$\n$\r$\nNOTE: The scenes, include and INI files associated with the install will not be removed."
168  
169  # Variables
170  Var StartMenuGroup
171  Var TargetEXE
172  Var BinDir
173  Var DocDir
174  var Dialog
175  
176  # Installer pages
177  !insertmacro MUI_PAGE_WELCOME
178  !insertmacro MUI_PAGE_LICENSE ${INSTROOT}\agpl-3.0.txt
179  !define MUI_PAGE_CUSTOMFUNCTION_LEAVE BinDirectoryLeave
180  !define MUI_DIRECTORYPAGE_VARIABLE $BinDir
181  !define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install the core $(^NameDA) files in the following location. Click Browse to select a different folder."
182  !insertmacro MUI_PAGE_DIRECTORY
183  !define MUI_PAGE_CUSTOMFUNCTION_LEAVE DocDirectoryLeave
184  !define MUI_DIRECTORYPAGE_VARIABLE $DocDir
185  !define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install the $(^NameDA) include and sample scene files in the following location. Click Browse to select a different folder."
186  !insertmacro MUI_PAGE_DIRECTORY
187  !insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup
188  Page custom ReadyToInstall
189  !insertmacro MUI_PAGE_INSTFILES
190  !insertmacro MUI_PAGE_FINISH
191  !insertmacro MUI_UNPAGE_CONFIRM
192  !insertmacro MUI_UNPAGE_INSTFILES
193  
194  # Installer languages
195  !insertmacro MUI_LANGUAGE English
196  
197  # Installer attributes
198  OutFile "${MYPRODUCT}.${VERSIONSTR}-setup.exe"
199  InstallDir $BinDir
200  CRCCheck on
201  XPStyle on
202  ShowInstDetails show
203  VIProductVersion ${MYVER}.${MYSUBVER}
204  VIAddVersionKey ProductName "${MYPRODUCT}"
205  VIAddVersionKey ProductVersion "${MYVER}"
206  VIAddVersionKey CompanyName "${MYCOMPANY}"
207  VIAddVersionKey CompanyWebsite "${MYURL}"
208  VIAddVersionKey FileVersion "${MYVER}"
209  VIAddVersionKey FileDescription "${MYPRODUCT} ${MYVER}"
210  VIAddVersionKey LegalCopyright "${MYCOPYRIGHT}"
211  InstallDirRegKey HKCU "${REGKEY}\Windows" Home
212  ShowUninstDetails show
213  
214  # Installer sections
215  Section -Main SEC0000
216      SetShellVarContext current
217  
218      # remove the registry key, if present
219      DeleteRegKey HKCU "${REGKEY}"
220  
221      SetOutPath "$BinDir"
222      SetOverwrite on
223      File ${INSTROOT}\agpl-3.0.txt
224      File ${INSTROOT}\revision.txt
225      File ${INSTROOT}\changes.txt
226      File /r ${INSTROOT}\Core\*
227      WriteRegStr HKCU "${REGKEY}\Components" Main 1
228  SectionEnd
229  
230  Section "User Files" SEC0001
231      SetOutPath "$DocDir"
232      SetOverwrite on
233      File ${INSTROOT}\agpl-3.0.txt
234      File ${INSTROOT}\revision.txt
235      File ${INSTROOT}\changes.txt
236      File /r ${INSTROOT}\User\*
237      WriteRegStr HKCU "${REGKEY}\Components" "User Files" 1
238  SectionEnd
239  
240  Section -post SEC0002
241      WriteRegStr HKCU "${REGKEY}\Windows" Home "$BinDir"
242      WriteRegStr HKCU "${REGKEY}\Windows" DocPath "$DocDir"
243      WriteRegDWORD HKCU "${REGKEY}\Windows" FreshInstall 1
244      SetOutPath "$BinDir"
245      WriteUninstaller $BinDir\${MYEXEPREFIX}-${MYVER}-uninstall.exe
246      !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
247      SetOutPath "$SMPROGRAMS\$StartMenuGroup"
248      CreateShortcut "$SMPROGRAMS\$StartMenuGroup\${MYPRODUCT}.lnk" "$BinDir\bin\$TargetEXE"
249      CreateShortcut "$SMPROGRAMS\$StartMenuGroup\License.lnk" "$BinDir\agpl-3.0.txt"
250      CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Documentation.lnk" "$BinDir\help\${MYHELPFILE}"
251      CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Release Notes.lnk" "$DocDir\changes.txt"
252      CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Change List.lnk" "$DocDir\revision.txt"
253      CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Sample Scenes.lnk" "$DocDir\Scenes"
254      CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Scene Previews.lnk" "$DocDir\Scenes\index.htm"
255      CreateShortcut "$Desktop\${MYABBREV} ${VERSIONSTR}.lnk" "$BinDir\bin\$TargetEXE"
256      CreateShortcut "$Desktop\${MYABBREV} ${VERSIONSTR} Examples.lnk" "$DocDir\Scenes"
257      !insertmacro MUI_STARTMENU_WRITE_END
258      WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name) ${UNINSTALL_REG_SUFFIX}" DisplayName "$(^Name) ${VERSIONSTR}"
259      WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name) ${UNINSTALL_REG_SUFFIX}" DisplayVersion "${MYVER}"
260      WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name) ${UNINSTALL_REG_SUFFIX}" Publisher "${MYCOMPANY}"
261      WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name) ${UNINSTALL_REG_SUFFIX}" URLInfoAbout "${MYURL}"
262      WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name) ${UNINSTALL_REG_SUFFIX}" DisplayIcon "$BinDir\${MYEXEPREFIX}-${MYVER}-uninstall.exe"
263      WriteRegStr HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name) ${UNINSTALL_REG_SUFFIX}" UninstallString "$BinDir\${MYEXEPREFIX}-${MYVER}-uninstall.exe"
264      WriteRegDWORD HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name) ${UNINSTALL_REG_SUFFIX}" NoModify 1
265      WriteRegDWORD HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name) ${UNINSTALL_REG_SUFFIX}" NoRepair 1
266  
267      # set up our file association, backing up previous values if present
268      ClearErrors
269      ReadRegStr $R0 HKCR ".${MYSCENEEXT}" "backup"
270      IfErrors +1 +3
271      ReadRegStr $R0 HKCR ".${MYSCENEEXT}" ""
272      WriteRegStr HKCR ".${MYSCENEEXT}" "backup" $R0
273      WriteRegStr HKCR ".${MYSCENEEXT}" "" "${MYABBREV}.Scene"
274  
275      # we don't save the perceived type as it should always be text
276      WriteRegStr HKCR ".${MYSCENEEXT}" "PerceivedType" "text"
277  
278      ClearErrors
279      ReadRegStr $R0 HKCR "${MYABBREV}.Scene" "backup"
280      IfErrors +1 +3
281      ReadRegStr $R0 HKCR "${MYABBREV}.Scene" ""
282      WriteRegStr HKCR "${MYABBREV}.Scene" "backup" $R0
283      WriteRegStr HKCR "${MYABBREV}.Scene" "" "${MYABBREV} scene source file"
284  
285      ClearErrors
286      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\open" "backup"
287      IfErrors +1 +3
288      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\open" ""
289      WriteRegStr HKCR "${MYABBREV}.Scene\shell\open" "backup" $R0
290      WriteRegStr HKCR "${MYABBREV}.Scene\shell\open" "" "Edit in ${MYABBREV} ${MYVER}"
291  
292      ClearErrors
293      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\edit" "backup"
294      IfErrors +1 +3
295      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\edit" ""
296      WriteRegStr HKCR "${MYABBREV}.Scene\shell\edit" "backup" $R0
297      WriteRegStr HKCR "${MYABBREV}.Scene\shell\edit" "" "Render with ${MYABBREV} ${MYVER}"
298  
299      ClearErrors
300      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\DefaultIcon" "backup"
301      IfErrors +1 +3
302      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\DefaultIcon" ""
303      WriteRegStr HKCR "${MYABBREV}.Scene\DefaultIcon" "backup" $R0
304      WriteRegStr HKCR "${MYABBREV}.Scene\DefaultIcon" "" "$BinDir\bin\${MYABBREV}.Scene-XP.ico"
305  
306      ClearErrors
307      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\open\command" "backup"
308      IfErrors +1 +3
309      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\open\command" ""
310      WriteRegStr HKCR "${MYABBREV}.Scene\shell\open\command" "backup" $R0
311      WriteRegStr HKCR "${MYABBREV}.Scene\shell\open\command" "" '"$BinDir\bin\$TargetEXE" /edit "%1"'
312  
313      ClearErrors
314      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\edit\command" "backup"
315      IfErrors +1 +3
316      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\edit\command" ""
317      WriteRegStr HKCR "${MYABBREV}.Scene\shell\edit\command" "backup" $R0
318      WriteRegStr HKCR "${MYABBREV}.Scene\shell\edit\command" "" '"$BinDir\bin\$TargetEXE" /render "%1"'
319  
320      System::Call 'Shell32::SHChangeNotify(i 0x8000000, i 0, i 0, i 0)'
321  SectionEnd
322  
323  # Macro for selecting uninstaller sections
324  !macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID
325      Push $R0
326      ReadRegStr $R0 HKCU "${REGKEY}\Components" "${SECTION_NAME}"
327      StrCmp $R0 1 0 next${UNSECTION_ID}
328      !insertmacro SelectSection "${UNSECTION_ID}"
329      GoTo done${UNSECTION_ID}
330  next${UNSECTION_ID}:
331      !insertmacro UnselectSection "${UNSECTION_ID}"
332  done${UNSECTION_ID}:
333      Pop $R0
334  !macroend
335  
336  Function isEmptyDir
337    # Stack ->                    # Stack: <directory>
338    Exch $0                       # Stack: $0
339    Push $1                       # Stack: $1, $0
340    FindFirst $0 $1 "$0\*.*"
341    strcmp $1 "." 0 _notempty
342      FindNext $0 $1
343      strcmp $1 ".." 0 _notempty
344        ClearErrors
345        FindNext $0 $1
346        IfErrors 0 _notempty
347          FindClose $0
348          Pop $1                  # Stack: $0
349          StrCpy $0 1
350          Exch $0                 # Stack: 1 (true)
351          goto _end
352       _notempty:
353         FindClose $0
354         ClearErrors
355         Pop $1                   # Stack: $0
356         StrCpy $0 0
357         Exch $0                  # Stack: 0 (false)
358    _end:
359  FunctionEnd
360  
361  Function BinDirectoryLeave
362    IfFileExists "$BinDir\*.*" 0 exit
363    push $BinDir
364    Call isEmptyDir
365    Pop $0
366    StrCmp $0 0 0 exit
367      MessageBox MB_YESNO|MB_ICONEXCLAMATION "The destination folder is not empty.$\r$\nWould you like to use it anyway?" IDYES exit
368      Abort
369  exit:
370  FunctionEnd
371  
372  Function DocDirectoryLeave
373    IfFileExists "$DocDir\*.*" 0 exit
374    push $DocDir
375    Call isEmptyDir
376    Pop $0
377    StrCmp $0 0 0 exit
378      MessageBox MB_YESNO|MB_ICONEXCLAMATION "The destination folder is not empty.$\r$\nWould you like to use it anyway?" IDYES exit
379      Abort
380  exit:
381  FunctionEnd
382  
383  Function ReadyToInstall
384    !insertmacro MUI_HEADER_TEXT "Ready to Install" "Press Install to begin the installation."
385    nsDialogs::Create 1018
386    Pop $Dialog
387    nsDialogs::Show
388  FunctionEnd
389  
390  # Uninstaller sections
391  Section /o "-un.User Files" UNSEC0001
392      DeleteRegValue HKCU "${REGKEY}\Components" "User Files"
393  SectionEnd
394  
395  Section /o -un.Main UNSEC0000
396      RmDir /r $INSTDIR\bin
397      RmDir /r $INSTDIR\help
398      RmDir /r $INSTDIR\sounds
399      RmDir /r $INSTDIR\tiles
400      Delete $INSTDIR\changes.txt
401      Delete $INSTDIR\revision.txt
402      Delete $INSTDIR\agpl-3.0.txt
403      RmDir $INSTDIR
404      DeleteRegValue HKCU "${REGKEY}\Components" Main
405  SectionEnd
406  
407  Section -un.post UNSEC0002
408      DeleteRegKey HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name) ${UNINSTALL_REG_SUFFIX}"
409      DeleteRegKey HKCU "${REGKEY}"
410  
411      # if our backup value exists, write it to the default value
412      ClearErrors
413      ReadRegStr $R0 HKCR ".${MYSCENEEXT}" "backup"
414      IfErrors +3
415      WriteRegStr HKCR ".${MYSCENEEXT}" "" $R0
416      DeleteRegValue HKCR ".${MYSCENEEXT}" "backup"
417      
418      ClearErrors
419      ReadRegStr $R0 HKCR "${MYABBREV}.Scene" "backup"
420      IfErrors +3
421      WriteRegStr HKCR "${MYABBREV}.Scene" "" $R0
422      DeleteRegValue HKCR "${MYABBREV}.Scene" "backup"
423  
424      ClearErrors
425      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\open" "backup"
426      IfErrors +3
427      WriteRegStr HKCR "${MYABBREV}.Scene\shell\open" "" $R0
428      DeleteRegValue HKCR "${MYABBREV}.Scene\shell\open" "backup"
429  
430      ClearErrors
431      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\edit" "backup"
432      IfErrors +3
433      WriteRegStr HKCR "${MYABBREV}.Scene\shell\edit" "" $R0
434      DeleteRegValue HKCR "${MYABBREV}.Scene\shell\edit" "backup"
435  
436      ClearErrors
437      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\DefaultIcon" "backup"
438      IfErrors +3
439      WriteRegStr HKCR "${MYABBREV}.Scene\DefaultIcon" "" $R0
440      DeleteRegValue HKCR "${MYABBREV}.Scene\DefaultIcon" "backup"
441  
442      ClearErrors
443      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\open\command" "backup"
444      IfErrors +3
445      WriteRegStr HKCR "${MYABBREV}.Scene\shell\open\command" "" $R0
446      DeleteRegValue HKCR "${MYABBREV}.Scene\shell\open\command" "backup"
447  
448      ClearErrors
449      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\edit\command" "backup"
450      IfErrors +3
451      WriteRegStr HKCR "${MYABBREV}.Scene\shell\edit\command" "" $R0
452      DeleteRegValue HKCR "${MYABBREV}.Scene\shell\edit\command" "backup"
453  
454      # if the default value is empty or does not exist, delete the key
455      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\edit\command" ""
456      StrCmp $R0 "" +1 +2
457      DeleteRegKey HKCR "${MYABBREV}.Scene\shell\edit\command"
458  
459      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\open\command" ""
460      StrCmp $R0 "" +1 +2
461      DeleteRegKey HKCR "${MYABBREV}.Scene\shell\open\command"
462  
463      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\edit" ""
464      StrCmp $R0 "" +1 +2
465      DeleteRegKey /ifempty HKCR "${MYABBREV}.Scene\shell\edit"
466  
467      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\shell\open" ""
468      StrCmp $R0 "" +1 +2
469      DeleteRegKey /ifempty HKCR "${MYABBREV}.Scene\shell\open"
470  
471      ReadRegStr $R0 HKCR "${MYABBREV}.Scene\DefaultIcon" ""
472      StrCmp $R0 "" +1 +2
473      DeleteRegKey HKCR "${MYABBREV}.Scene\DefaultIcon"
474  
475      DeleteRegKey /ifempty HKCR "${MYABBREV}.Scene\shell"
476      DeleteRegKey /ifempty HKCR "${MYABBREV}.Scene"
477  
478      ReadRegStr $R0 HKCR ".${MYSCENEEXT}" ""
479      StrCmp $R0 "" +1 +2
480      DeleteRegKey HKCR ".${MYSCENEEXT}"
481  
482      Delete "$SMPROGRAMS\$StartMenuGroup\${MYPRODUCT}.lnk"
483      Delete "$SMPROGRAMS\$StartMenuGroup\License.lnk"
484      Delete "$SMPROGRAMS\$StartMenuGroup\Documentation.lnk"
485      Delete "$SMPROGRAMS\$StartMenuGroup\Release Notes.lnk"
486      Delete "$SMPROGRAMS\$StartMenuGroup\Change List.lnk"
487      Delete "$SMPROGRAMS\$StartMenuGroup\Sample Scenes.lnk"
488      Delete "$SMPROGRAMS\$StartMenuGroup\Scene Previews.lnk"
489      Delete "$Desktop\${MYABBREV} ${VERSIONSTR}.lnk"
490      Delete "$Desktop\${MYABBREV} ${VERSIONSTR} Examples.lnk"
491      Delete $INSTDIR\${MYEXEPREFIX}-${MYVER}-uninstall.exe
492      RmDir $SMPROGRAMS\$StartMenuGroup
493      RmDir $INSTDIR
494  SectionEnd
495  
496  # Installer functions
497  Function .onInit
498      InitPluginsDir
499  
500      ${If} ${RunningX64}
501          SetRegView 64
502      ${EndIf}
503  
504      ReadRegStr $R0 HKCU "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name) ${UNINSTALL_REG_SUFFIX}" UninstallString
505      StrCmp $R0 "" Proceed
506      MessageBox MB_YESNOCANCEL|MB_ICONEXCLAMATION "A copy of $(^Name) is currently installed. Remove it before proceeding?" IDNO Proceed IDYES UninstallRC
507      Abort
508  
509  UninstallRC:
510      ClearErrors
511      ${GetParent} $R0 $R1
512      ExecWait '$R0 _?=$R1'
513      Delete $R0
514      RmDir $R1
515  
516  Proceed:
517      ${If} ${RunningX64}
518          StrCpy $INSTDIR "$PROGRAMFILES64\${BINDEST}"
519          StrCpy $TargetEXE "${MYEXEPREFIX}64.exe"
520      ${Else}
521          StrCpy $INSTDIR "$PROGRAMFILES\${BINDEST}"
522          System::Call kernel32::IsProcessorFeaturePresent(i10)i.r0
523          ${If} $0 != 0
524              StrCpy $TargetEXE "${MYEXEPREFIX}32-sse2.exe"
525          ${Else}
526              StrCpy $TargetEXE "${MYEXEPREFIX}32.exe"
527          ${EndIf}
528      ${EndIf}
529      StrCpy $BinDir "$INSTDIR"
530      StrCpy $DocDir "${DOCDEST}"
531  FunctionEnd
532  
533  # Uninstaller functions
534  Function un.onInit
535      !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuGroup
536      !insertmacro SELECT_UNSECTION Main ${UNSEC0000}
537      !insertmacro SELECT_UNSECTION "User Files" ${UNSEC0001}
538      ${If} ${RunningX64}
539          SetRegView 64
540      ${EndIf}
541  FunctionEnd
542  
543