OSDN Git Service

Small installer fix.
[lamexp/LameXP.git] / etc / NSIS / setup.nsi
1 ; ///////////////////////////////////////////////////////////////////////////////
2 ; // LameXP - Audio Encoder Front-End
3 ; // Copyright (C) 2004-2016 LoRd_MuldeR <MuldeR2@GMX.de>
4 ; //
5 ; // This program is free software; you can redistribute it and/or modify
6 ; // it under the terms of the GNU General Public License as published by
7 ; // the Free Software Foundation; either version 2 of the License, or
8 ; // (at your option) any later version.
9 ; //
10 ; // This program is distributed in the hope that it will be useful,
11 ; // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ; // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ; // GNU General Public License for more details.
14 ; //
15 ; // You should have received a copy of the GNU General Public License along
16 ; // with this program; if not, write to the Free Software Foundation, Inc.,
17 ; // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 ; //
19 ; // http://www.gnu.org/licenses/gpl-2.0.txt
20 ; ///////////////////////////////////////////////////////////////////////////////
21
22
23 ;--------------------------------
24 ;Basic Defines
25 ;--------------------------------
26
27 !ifndef NSIS_UNICODE
28   !error "NSIS_UNICODE is undefined, please compile with Unicode NSIS !!!"
29 !endif
30
31 !ifndef LAMEXP_VERSION
32   !error "LAMEXP_VERSION is not defined !!!"
33 !endif
34 !ifndef LAMEXP_BUILD
35   !error "LAMEXP_BUILD is not defined !!!"
36 !endif
37 !ifndef LAMEXP_INSTTYPE
38   !error "LAMEXP_INSTTYPE is not defined !!!"
39 !endif
40 !ifndef LAMEXP_PATCH
41   !error "LAMEXP_PATCH is not defined !!!"
42 !endif
43 !ifndef LAMEXP_DATE
44   !error "LAMEXP_DATE is not defined !!!"
45 !endif
46 !ifndef LAMEXP_OUTPUT_FILE
47   !error "LAMEXP_OUTPUT_FILE is not defined !!!"
48 !endif
49 !ifndef LAMEXP_SOURCE_PATH
50   !error "LAMEXP_SOURCE_PATH is not defined !!!"
51 !endif
52
53 ;UUID
54 !define MyRegPath "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FBD7A67D-D700-4043-B54F-DD106D00F308}"
55
56 ;App Paths
57 !define AppPaths "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
58
59 ;Web-Site
60 !define MyWebSite "http://muldersoft.com/"
61
62
63 ;--------------------------------
64 ;Check for Pre-Release
65 ;--------------------------------
66
67 !define LAMEXP_IS_PRERELEASE
68
69 !if '${LAMEXP_INSTTYPE}' == 'Final'
70   !undef LAMEXP_IS_PRERELEASE
71 !endif
72 !if '${LAMEXP_INSTTYPE}' == 'Hotfix'
73   !undef LAMEXP_IS_PRERELEASE
74 !endif
75
76
77 ;--------------------------------
78 ;Manifest
79 ;--------------------------------
80
81 !tempfile PACKHDRTEMP
82 !packhdr "${PACKHDRTEMP}" '"..\..\..\Prerequisites\MSVC\redist\bin\mt.exe" -manifest "setup.manifest" -outputresource:"${PACKHDRTEMP};1" && "..\..\..\Prerequisites\UPX\upx.exe" --brute "${PACKHDRTEMP}"'
83
84
85 ;--------------------------------
86 ;Includes
87 ;--------------------------------
88
89 !include `MUI2.nsh`
90 !include `WinVer.nsh`
91 !include `x64.nsh`
92 !include `StdUtils.nsh`
93
94
95 ;--------------------------------
96 ;Installer Attributes
97 ;--------------------------------
98
99 RequestExecutionLevel admin
100 ShowInstDetails show
101 ShowUninstDetails show
102 Name "LameXP v${LAMEXP_VERSION} ${LAMEXP_INSTTYPE}-${LAMEXP_PATCH} [Build #${LAMEXP_BUILD}]"
103 OutFile "${LAMEXP_OUTPUT_FILE}"
104 BrandingText "Date created: ${LAMEXP_DATE} [Build #${LAMEXP_BUILD}]"
105 InstallDir "$PROGRAMFILES\MuldeR\LameXP"
106 InstallDirRegKey HKLM "${MyRegPath}" "InstallLocation"
107
108
109 ;--------------------------------
110 ;Compressor
111 ;--------------------------------
112
113 SetCompressor /SOLID LZMA
114 SetCompressorDictSize 64
115
116
117 ;--------------------------------
118 ;Reserved Files
119 ;--------------------------------
120
121 ReserveFile "${NSISDIR}\Plugins\Aero.dll"
122 ReserveFile "${NSISDIR}\Plugins\LangDLL.dll"
123 ReserveFile "${NSISDIR}\Plugins\LockedList.dll"
124 ReserveFile "${NSISDIR}\Plugins\LockedList64.dll"
125 ReserveFile "${NSISDIR}\Plugins\nsDialogs.dll"
126 ReserveFile "${NSISDIR}\Plugins\nsExec.dll"
127 ReserveFile "${NSISDIR}\Plugins\StartMenu.dll"
128 ReserveFile "${NSISDIR}\Plugins\StdUtils.dll"
129 ReserveFile "${NSISDIR}\Plugins\System.dll"
130 ReserveFile "${NSISDIR}\Plugins\UserInfo.dll"
131
132
133 ;--------------------------------
134 ;Variables
135 ;--------------------------------
136
137 Var StartMenuFolder
138
139
140 ;--------------------------------
141 ;Version Info
142 ;--------------------------------
143
144 !searchreplace PRODUCT_VERSION_DATE "${LAMEXP_DATE}" "-" "."
145 VIProductVersion "${PRODUCT_VERSION_DATE}.${LAMEXP_BUILD}"
146
147 VIAddVersionKey "Author" "LoRd_MuldeR <mulder2@gmx.de>"
148 VIAddVersionKey "Comments" "This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version."
149 VIAddVersionKey "CompanyName" "Free Software Foundation"
150 VIAddVersionKey "FileDescription" "LameXP v${LAMEXP_VERSION} ${LAMEXP_INSTTYPE}-${LAMEXP_PATCH} [Build #${LAMEXP_BUILD}]"
151 VIAddVersionKey "FileVersion" "${PRODUCT_VERSION_DATE}.${LAMEXP_BUILD} (${LAMEXP_VERSION})"
152 VIAddVersionKey "LegalCopyright" "Copyright 2004-2016 LoRd_MuldeR"
153 VIAddVersionKey "LegalTrademarks" "GNU"
154 VIAddVersionKey "OriginalFilename" "LameXP.${LAMEXP_DATE}.exe"
155 VIAddVersionKey "ProductName" "LameXP - Audio Encoder Frontend"
156 VIAddVersionKey "ProductVersion" "${LAMEXP_VERSION}, Build #${LAMEXP_BUILD} (${LAMEXP_DATE})"
157 VIAddVersionKey "Website" "${MyWebSite}"
158
159
160 ;--------------------------------
161 ;MUI2 Interface Settings
162 ;--------------------------------
163
164 !define MUI_ABORTWARNING
165 !define MUI_STARTMENUPAGE_REGISTRY_ROOT HKLM
166 !define MUI_STARTMENUPAGE_REGISTRY_KEY "${MyRegPath}"
167 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "StartmenuFolder"
168 !define MUI_LANGDLL_REGISTRY_ROOT HKLM
169 !define MUI_LANGDLL_REGISTRY_KEY "${MyRegPath}"
170 !define MUI_LANGDLL_REGISTRY_VALUENAME "SetupLanguage"
171 !define MUI_STARTMENUPAGE_DEFAULTFOLDER "LameXP v${LAMEXP_VERSION}"
172 !define MUI_FINISHPAGE_NOAUTOCLOSE
173 !define MUI_UNFINISHPAGE_NOAUTOCLOSE
174 !define MUI_FINISHPAGE_RUN
175 !define MUI_FINISHPAGE_RUN_FUNCTION RunAppFunction
176 !define MUI_FINISHPAGE_SHOWREADME
177 !define MUI_FINISHPAGE_SHOWREADME_FUNCTION ShowReadmeFunction
178 !define MUI_FINISHPAGE_LINK ${MyWebSite}
179 !define MUI_FINISHPAGE_LINK_LOCATION ${MyWebSite}
180 !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install.ico"
181 !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall.ico"
182 !define MUI_WELCOMEFINISHPAGE_BITMAP "wizard.bmp"
183 !define MUI_UNWELCOMEFINISHPAGE_BITMAP "wizard-un.bmp"
184 !define MUI_HEADERIMAGE
185 !define MUI_HEADERIMAGE_BITMAP "header.bmp"
186 !define MUI_HEADERIMAGE_UNBITMAP "header-un.bmp"
187 !define MUI_LANGDLL_ALLLANGUAGES
188 !define MUI_CUSTOMFUNCTION_GUIINIT MyGuiInit
189 !define MUI_CUSTOMFUNCTION_UNGUIINIT un.MyGuiInit
190 !define MUI_LANGDLL_ALWAYSSHOW
191
192
193 ;--------------------------------
194 ;MUI2 Pages (Installer)
195 ;--------------------------------
196
197 ;Welcome
198 !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfUnattended
199 !define MUI_PAGE_CUSTOMFUNCTION_LEAVE CheckForPreRelease
200 !define MUI_WELCOMEPAGE_TITLE_3LINES
201 !define MUI_FINISHPAGE_TITLE_3LINES
202 !insertmacro MUI_PAGE_WELCOME
203
204 ;License
205 !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfUnattended
206 !insertmacro MUI_PAGE_LICENSE "license.rtf"
207
208 ;Directory
209 !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfUnattended
210 !define MUI_PAGE_CUSTOMFUNCTION_SHOW CheckForUpdate
211 !insertmacro MUI_PAGE_DIRECTORY
212
213 ;Startmenu
214 !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfUnattended
215 !insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
216
217 ;LockedList
218 Page Custom LockedListShow
219
220 ;Install Files
221 !insertmacro MUI_PAGE_INSTFILES
222
223 ;Finish
224 !define MUI_PAGE_CUSTOMFUNCTION_PRE SkipIfUnattended
225 !insertmacro MUI_PAGE_FINISH
226
227
228 ;--------------------------------
229 ;MUI2 Pages (Uninstaller)
230 ;--------------------------------
231
232 ;Welcome
233 !define MUI_WELCOMEPAGE_TITLE_3LINES
234 !define MUI_FINISHPAGE_TITLE_3LINES
235 !define MUI_PAGE_CUSTOMFUNCTION_PRE un.CheckForcedUninstall
236 !insertmacro MUI_UNPAGE_WELCOME
237
238 ;Confirm
239 !define MUI_PAGE_CUSTOMFUNCTION_PRE un.CheckForcedUninstall
240 !insertmacro MUI_UNPAGE_CONFIRM
241
242 ;LockedList
243 UninstPage Custom un.LockedListShow
244
245 ;Uninstall
246 !insertmacro MUI_UNPAGE_INSTFILES
247
248 ;Finish
249 !define MUI_PAGE_CUSTOMFUNCTION_PRE un.CheckForcedUninstall
250 !insertmacro MUI_UNPAGE_FINISH
251
252
253 ;--------------------------------
254 ;Languages
255 ;--------------------------------
256  
257 !insertmacro MUI_LANGUAGE "English" ;first language is the default language
258 !insertmacro MUI_LANGUAGE "German"
259 !insertmacro MUI_LANGUAGE "Spanish"
260 !insertmacro MUI_LANGUAGE "Russian"
261 !insertmacro MUI_LANGUAGE "Ukrainian"
262 !insertmacro MUI_LANGUAGE "Polish"
263 !insertmacro MUI_LANGUAGE "Hungarian"
264
265 ; !insertmacro MUI_LANGUAGE "French"
266 ; !insertmacro MUI_LANGUAGE "SpanishInternational"
267 ; !insertmacro MUI_LANGUAGE "SimpChinese"
268 ; !insertmacro MUI_LANGUAGE "TradChinese"
269 ; !insertmacro MUI_LANGUAGE "Japanese"
270 ; !insertmacro MUI_LANGUAGE "Italian"
271 ; !insertmacro MUI_LANGUAGE "Dutch"
272 ; !insertmacro MUI_LANGUAGE "Greek"
273 ; !insertmacro MUI_LANGUAGE "Romanian"
274 ; !insertmacro MUI_LANGUAGE "Serbian"
275 ; !insertmacro MUI_LANGUAGE "SerbianLatin"
276 ; !insertmacro MUI_LANGUAGE "Arabic"
277 ; !insertmacro MUI_LANGUAGE "Portuguese"
278 ; !insertmacro MUI_LANGUAGE "Afrikaans"
279 ; !insertmacro MUI_LANGUAGE "Malay"
280 ; !insertmacro MUI_LANGUAGE "Indonesian"
281
282
283 ;--------------------------------
284 ;Translation
285 ;--------------------------------
286
287 ;English
288 !include "..\Translation\Blank.nsh"
289
290 ;German
291 !include "..\Translation\LameXP_DE.nsh"
292
293 ;Spanish
294 !include "..\Translation\LameXP_ES.nsh"
295
296 ;Russian
297 !include "..\Translation\LameXP_RU.nsh"
298
299 ;Ukrainian
300 !include "..\Translation\LameXP_UK.nsh"
301
302 ;Polish
303 !include "..\Translation\LameXP_PL.nsh"
304
305 ;Hungarian
306 !include "..\Translation\LameXP_HU.nsh"
307
308
309 ;--------------------------------
310 ;LogicLib Extensions
311 ;--------------------------------
312
313 !macro _UnattendedMode _a _b _t _f
314         !insertmacro _LOGICLIB_TEMP
315         ${StdUtils.TestParameter} $_LOGICLIB_TEMP "Update"
316         StrCmp "$_LOGICLIB_TEMP" "true" `${_t}` `${_f}`
317 !macroend
318 !define UnattendedMode `"" UnattendedMode ""`
319
320 !macro _ForcedMode _a _b _t _f
321         !insertmacro _LOGICLIB_TEMP
322         ${StdUtils.TestParameter} $_LOGICLIB_TEMP "Force"
323         StrCmp "$_LOGICLIB_TEMP" "true" `${_t}` `${_f}`
324 !macroend
325 !define ForcedMode `"" ForcedMode ""`
326
327 !macro _ValidFileName _a _b _t _f
328         !insertmacro _LOGICLIB_TEMP
329         ${StdUtils.ValidFileName} $_LOGICLIB_TEMP `${_b}`
330         StrCmp "$_LOGICLIB_TEMP" "ok" `${_t}` `${_f}`
331 !macroend
332 !define ValidFileName `"" ValidFileName`
333
334
335 ;--------------------------------
336 ;Installer initialization
337 ;--------------------------------
338
339 Function .onInit
340         InitPluginsDir
341
342         ; --------
343
344         System::Call 'kernel32::CreateMutexA(i 0, i 0, t "{2B3D1EBF-B3B6-4E93-92B9-6853029A7162}") i .r1 ?e'
345         Pop $0
346         ${If} $0 <> 0
347                 MessageBox MB_ICONSTOP|MB_TOPMOST "Sorry, the installer is already running!"
348                 Quit
349         ${EndIf}
350
351         ; --------
352         
353         # Running on Windows NT family?
354         ${IfNot} ${IsNT}
355                 MessageBox MB_TOPMOST|MB_ICONSTOP "Sorry, this application does *not* support Windows 9x or Windows ME!"
356                 ExecShell "open" "http://windows.microsoft.com/"
357                 Quit
358         ${EndIf}
359
360         # Running on Windows XP or later?
361         ${If} ${AtMostWin2000}
362                 MessageBox MB_TOPMOST|MB_ICONSTOP "Sorry, but your operating system is *not* supported anymore.$\nInstallation will be aborted!$\n$\nThe minimum required platform is Windows XP (Service Pack 3)."
363                 ExecShell "open" "http://windows.microsoft.com/"
364                 Quit
365         ${EndIf}
366
367         # If on Windows XP, is the required Service Pack installed?
368         ${If} ${IsWinXP}
369                 ${IfNot} ${RunningX64} # Windows XP 32-Bit, requires Service Pack 3
370                 ${AndIf} ${AtMostServicePack} 2
371                         MessageBox MB_TOPMOST|MB_ICONEXCLAMATION "This application requires Windows XP with Service Pack 3 installed!"
372                         ${If} ${Cmd} `MessageBox MB_TOPMOST|MB_ICONQUESTION|MB_YESNO "Do you want to download Service Pack 3 for Windows XP now?" IDYES`
373                                 ExecShell "open" "http://www.microsoft.com/en-us/download/details.aspx?id=24"
374                         ${Else}
375                                 ExecShell "open" "http://windowsupdate.microsoft.com/"
376                         ${EndIf}
377                         Quit
378                 ${EndIf}
379                 ${If} ${RunningX64} # Windows XP 64-Bit, requires Service Pack 2
380                 ${AndIf} ${AtMostServicePack} 1
381                         MessageBox MB_TOPMOST|MB_ICONEXCLAMATION "This application requires Windows XP x64 Edition with Service Pack 2 installed!"
382                         ${If} ${Cmd} `MessageBox MB_TOPMOST|MB_ICONQUESTION|MB_YESNO "Do you want to download Service Pack 2 for Windows XP x64 Edition now?" IDYES`
383                                 ExecShell "open" "http://www.microsoft.com/en-us/download/details.aspx?id=17791"
384                         ${Else}
385                                 ExecShell "open" "http://windowsupdate.microsoft.com/"
386                         ${EndIf}
387                         Quit
388                 ${EndIf}
389         ${EndIf}
390
391         ; --------
392
393         ${IfNot} ${UnattendedMode}
394                 !insertmacro MUI_LANGDLL_DISPLAY
395         ${EndIf}
396
397         ; --------
398
399         UserInfo::GetAccountType
400         Pop $0
401         ${If} $0 != "Admin"
402                 MessageBox MB_ICONSTOP|MB_TOPMOST "Your system requires administrative permissions in order to install this software."
403                 SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
404                 Quit
405         ${EndIf}
406 FunctionEnd
407
408 Function un.onInit
409         System::Call 'kernel32::CreateMutexA(i 0, i 0, t "{2B3D1EBF-B3B6-4E93-92B9-6853029A7162}") i .r1 ?e'
410         Pop $0
411         ${If} $0 <> 0
412                 MessageBox MB_ICONSTOP|MB_TOPMOST "Sorry, the un-installer is already running!"
413                 Quit
414         ${EndIf}
415
416         ${IfNot} ${ForcedMode}
417                 !insertmacro MUI_LANGDLL_DISPLAY
418         ${EndIf}
419         
420         ; --------
421
422         UserInfo::GetAccountType
423         Pop $0
424         ${If} $0 != "Admin"
425                 MessageBox MB_ICONSTOP|MB_TOPMOST "Your system requires administrative permissions in order to install this software."
426                 SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
427                 Quit
428         ${EndIf}
429 FunctionEnd
430
431
432 ;--------------------------------
433 ;GUI initialization
434 ;--------------------------------
435
436 Function MyGuiInit
437         StrCpy $0 $HWNDPARENT
438         System::Call "user32::SetWindowPos(i r0, i -1, i 0, i 0, i 0, i 0, i 3)"
439         Aero::Apply
440 FunctionEnd
441
442 Function un.MyGuiInit
443         StrCpy $0 $HWNDPARENT
444         System::Call "user32::SetWindowPos(i r0, i -1, i 0, i 0, i 0, i 0, i 3)"
445         Aero::Apply
446 FunctionEnd
447
448
449 ;--------------------------------
450 ;Macros & Auxiliary Functions
451 ;--------------------------------
452
453 !macro PrintProgress Text
454         SetDetailsPrint textonly
455         DetailPrint '${Text}'
456         SetDetailsPrint listonly
457         Sleep 1000
458 !macroend
459
460 !macro CreateWebLink ShortcutFile TargetURL
461         Push $0
462         Push $1
463         StrCpy $0 "${ShortcutFile}"
464         StrCpy $1 "${TargetURL}"
465         Call _CreateWebLink
466         Pop $1
467         Pop $0
468 !macroend
469
470 Function _CreateWebLink
471         FlushINI "$0"
472         SetFileAttributes "$0" FILE_ATTRIBUTE_NORMAL
473         DeleteINISec "$0" "DEFAULT"
474         DeleteINISec "$0" "InternetShortcut"
475         WriteINIStr "$0" "DEFAULT" "BASEURL" "$1"
476         WriteINIStr "$0" "InternetShortcut" "ORIGURL" "$1"
477         WriteINIStr "$0" "InternetShortcut" "URL" "$1"
478         WriteINIStr "$0" "InternetShortcut" "IconFile" "$SYSDIR\SHELL32.dll"
479         WriteINIStr "$0" "InternetShortcut" "IconIndex" "150"
480         FlushINI "$0"
481         SetFileAttributes "$0" FILE_ATTRIBUTE_READONLY
482 FunctionEnd
483
484 !macro GetExecutableName OutVar
485         ${StdUtils.GetParameter} ${OutVar} "Update" ""
486         ${StdUtils.TrimStr} ${OutVar}
487         ${If} "${OutVar}" == ""
488         ${OrIfNot} ${ValidFileName} "${OutVar}"
489                 StrCpy ${OutVar} "LameXP.exe"
490         ${EndIf}
491 !macroend
492
493 !macro DisableNextButton TmpVar
494         GetDlgItem ${TmpVar} $HWNDPARENT 1
495         EnableWindow ${TmpVar} 0
496 !macroend
497
498 !macro DisableBackButton TmpVar
499         GetDlgItem ${TmpVar} $HWNDPARENT 3
500         EnableWindow ${TmpVar} 0
501 !macroend
502
503 !macro CleanUpFiles options
504         Delete ${options} "$INSTDIR\Changelog.htm"
505         Delete ${options} "$INSTDIR\Changelog.html"
506         Delete ${options} "$INSTDIR\Contributors.txt"
507         Delete ${options} "$INSTDIR\Copying.txt"
508         Delete ${options} "$INSTDIR\FAQ.html"
509         Delete ${options} "$INSTDIR\Howto.html"
510         Delete ${options} "$INSTDIR\LameEnc.sys"
511         Delete ${options} "$INSTDIR\LameXP.exe"
512         Delete ${options} "$INSTDIR\LameXP.exe.sig"
513         Delete ${options} "$INSTDIR\LameXP-Portable.exe"
514         Delete ${options} "$INSTDIR\License.txt"
515         Delete ${options} "$INSTDIR\Manual.html"
516         Delete ${options} "$INSTDIR\Readme.htm"
517         Delete ${options} "$INSTDIR\ReadMe.txt"
518         Delete ${options} "$INSTDIR\PRE_RELEASE_INFO.txt"
519         Delete ${options} "$INSTDIR\Settings.cfg"
520         Delete ${options} "$INSTDIR\Translate.html"
521         Delete ${options} "$INSTDIR\Uninstall.exe"
522         Delete ${options} "$INSTDIR\Qt*.dll"
523         Delete ${options} "$INSTDIR\MUtils*.dll"
524         Delete ${options} "$INSTDIR\msvcr*.dll"
525         Delete ${options} "$INSTDIR\msvcp*.dll"
526         Delete ${options} "$INSTDIR\concrt*.dll"
527         Delete ${options} "$INSTDIR\vcruntime*.dll"
528         Delete ${options} "$INSTDIR\vccorlib*.dll"
529         Delete ${options} "$INSTDIR\api-ms-*.dll"
530         Delete ${options} "$INSTDIR\ucrtbase.dll"
531         
532         RMDir /r ${options} "$INSTDIR\cache"
533         RMDir /r ${options} "$INSTDIR\img"
534         RMDir /r ${options} "$INSTDIR\imageformats"
535         RMDir /r ${options} "$INSTDIR\redist"
536 !macroend
537
538 ;--------------------------------
539 ;Install Files
540 ;--------------------------------
541
542 Section "-PreInit"
543         SetShellVarContext all
544         SetOutPath "$INSTDIR"
545 SectionEnd
546
547 Section "-Clean Up Old Cruft"
548         !insertmacro PrintProgress "$(LAMEXP_LANG_STATUS_CLEANUP)"
549         !insertmacro CleanUpFiles ""
550 SectionEnd
551
552 Section "!Install Files"
553         !insertmacro PrintProgress "$(LAMEXP_LANG_STATUS_INSTFILES)"
554         
555         DeleteOldBinary:
556         !insertmacro GetExecutableName $R0
557         ClearErrors
558         Delete "$INSTDIR\$R0"
559         
560         ${If} ${Errors}
561                 MessageBox MB_TOPMOST|MB_ICONSTOP|MB_RETRYCANCEL 'Could not delete old "$R0" file. Is LameXP still running?' IDRETRY DeleteOldBinary
562                 Abort "Could not delete old binary!"
563         ${EndIf}
564         
565         File /a `/oname=$R0` `${LAMEXP_SOURCE_PATH}\LameXP.exe`
566         File /nonfatal /a /r `${LAMEXP_SOURCE_PATH}\*.dll`
567         
568         File /a /r `${LAMEXP_SOURCE_PATH}\*.txt`
569         File /a /r `${LAMEXP_SOURCE_PATH}\*.html`
570         File /a /r `${LAMEXP_SOURCE_PATH}\*.png`
571 SectionEnd
572
573 # Section "-Install VCRedist"
574 #       !insertmacro PrintProgress "$(LAMEXP_LANG_STATUS_VCREDIST)"
575 #       File /a `/oname=$PLUGINSDIR\vcredist_x86.exe` `${LAMEXP_SOURCE_PATH}\redist\vcredist_x86.exe`
576 #       ExecWait '"$PLUGINSDIR\vcredist_x86.exe" /install /passive /norestart'
577 # SectionEnd
578
579 Section "-Write Uninstaller"
580         !insertmacro PrintProgress "$(LAMEXP_LANG_STATUS_MAKEUNINST)"
581         WriteUninstaller "$INSTDIR\Uninstall.exe"
582 SectionEnd
583
584 Section "-Create Shortcuts"
585         !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
586                 !insertmacro PrintProgress "$(LAMEXP_LANG_STATUS_SHORTCUTS)"
587                 CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
588                 
589                 SetShellVarContext current
590                 
591                 Delete "$SMPROGRAMS\$StartMenuFolder\*.lnk"
592                 Delete "$SMPROGRAMS\$StartMenuFolder\*.pif"
593                 Delete "$SMPROGRAMS\$StartMenuFolder\*.url"
594                 
595                 SetShellVarContext all
596                 
597                 Delete "$SMPROGRAMS\$StartMenuFolder\*.lnk"
598                 Delete "$SMPROGRAMS\$StartMenuFolder\*.pif"
599                 Delete "$SMPROGRAMS\$StartMenuFolder\*.url"
600
601                 !insertmacro GetExecutableName $R0
602                 
603                 CreateShortCut "$SMPROGRAMS\$StartMenuFolder\LameXP.lnk"                        "$INSTDIR\$R0" "" "$INSTDIR\$R0" 0
604                 CreateShortCut "$SMPROGRAMS\$StartMenuFolder\$(LAMEXP_LANG_LINK_LICENSE).lnk"   "$INSTDIR\License.txt"
605                 CreateShortCut "$SMPROGRAMS\$StartMenuFolder\$(LAMEXP_LANG_LINK_CHANGELOG).lnk" "$INSTDIR\Changelog.html"
606                 CreateShortCut "$SMPROGRAMS\$StartMenuFolder\$(LAMEXP_LANG_LINK_TRANSLATE).lnk" "$INSTDIR\Translate.html"
607                 CreateShortCut "$SMPROGRAMS\$StartMenuFolder\$(LAMEXP_LANG_LINK_MANUAL).lnk"    "$INSTDIR\Manual.html"
608                 CreateShortCut "$SMPROGRAMS\$StartMenuFolder\$(LAMEXP_LANG_LINK_UNINSTALL).lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0
609                 
610                 !insertmacro CreateWebLink "$SMPROGRAMS\$StartMenuFolder\Official LameXP Homepage.url" "${MyWebSite}"
611                 !insertmacro CreateWebLink "$SMPROGRAMS\$StartMenuFolder\Doom9's Forum.url"            "http://forum.doom9.org/"
612                 !insertmacro CreateWebLink "$SMPROGRAMS\$StartMenuFolder\Bug Tracker.url"              "https://github.com/lordmulder/LameXP/issues"
613                 !insertmacro CreateWebLink "$SMPROGRAMS\$StartMenuFolder\RareWares.org.url"            "http://rarewares.org/"
614                 !insertmacro CreateWebLink "$SMPROGRAMS\$StartMenuFolder\Hydrogenaudio Forums.url"     "http://www.hydrogenaudio.org/"
615
616                 ${If} ${FileExists} "$SMPROGRAMS\$StartMenuFolder\LameXP.lnk"
617                         ${StdUtils.InvokeShellVerb} $R1 "$SMPROGRAMS\$StartMenuFolder" "LameXP.lnk" ${StdUtils.Const.ShellVerb.PinToTaskbar}
618                         DetailPrint 'Pin: "$SMPROGRAMS\$StartMenuFolder\LameXP.lnk" -> $R1'
619                 ${EndIf}
620         !insertmacro MUI_STARTMENU_WRITE_END
621 SectionEnd
622
623 Section "-Update Registry"
624         !insertmacro PrintProgress "$(LAMEXP_LANG_STATUS_REGISTRY)"
625
626         !insertmacro GetExecutableName $R0
627         WriteRegStr HKLM "${MyRegPath}" "InstallLocation" "$INSTDIR"
628         WriteRegStr HKLM "${MyRegPath}" "ExecutableName" "$R0"
629         WriteRegStr HKLM "${MyRegPath}" "DisplayIcon" "$INSTDIR\$R0,0"
630         WriteRegStr HKLM "${MyRegPath}" "UninstallString" '"$INSTDIR\Uninstall.exe"'
631         WriteRegStr HKLM "${MyRegPath}" "DisplayName" "LameXP v${LAMEXP_VERSION}"
632         WriteRegStr HKLM "${MyRegPath}" "Publisher" "LoRd_MuldeR <mulder2@gmx.de>"
633         WriteRegStr HKLM "${MyRegPath}" "DisplayVersion" "${LAMEXP_VERSION} ${LAMEXP_INSTTYPE}-${LAMEXP_PATCH} [Build #${LAMEXP_BUILD}]"
634         WriteRegStr HKLM "${MyRegPath}" "URLInfoAbout" "${MyWebSite}"
635         WriteRegStr HKLM "${MyRegPath}" "URLUpdateInfo" "${MyWebSite}"
636         
637         DeleteRegKey HKCU "${AppPaths}\LameXP.exe"
638         WriteRegStr HKLM "${AppPaths}\LameXP.exe" "" "$INSTDIR\$R0"
639         WriteRegStr HKLM "${AppPaths}\LameXP.exe" "Path" "$INSTDIR"
640 SectionEnd
641
642 Section "-Finished"
643         !insertmacro PrintProgress "$(MUI_TEXT_FINISH_TITLE)."
644
645 !ifdef LAMEXP_IS_PRERELEASE
646         ${If} ${FileExists} "$INSTDIR\PRE_RELEASE_INFO.txt"
647                 ${StdUtils.ExecShellAsUser} $R1 "$INSTDIR\PRE_RELEASE_INFO.txt" "open" ""
648         ${EndIf}
649 !endif
650
651         ${IfThen} ${UnattendedMode} ${|} SetAutoClose true ${|}
652 SectionEnd
653
654
655 ;--------------------------------
656 ;Uninstaller
657 ;--------------------------------
658
659 Section "Uninstall"
660         SetOutPath "$EXEDIR"
661         !insertmacro PrintProgress "$(LAMEXP_LANG_STATUS_UNINSTALL)"
662
663         ; --------------
664         ; Startmenu
665         ; --------------
666         
667         !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
668         ${IfNot} "$StartMenuFolder" == ""
669                 SetShellVarContext current
670                 ${If} ${FileExists} "$SMPROGRAMS\$StartMenuFolder\LameXP.lnk"
671                         ${StdUtils.InvokeShellVerb} $R1 "$SMPROGRAMS\$StartMenuFolder" "LameXP.lnk" ${StdUtils.Const.ShellVerb.UnpinFromTaskbar}
672                         DetailPrint 'Unpin: "$SMPROGRAMS\$StartMenuFolder\LameXP.lnk" -> $R1'
673                 ${EndIf}
674                 ${If} ${FileExists} "$SMPROGRAMS\$StartMenuFolder\*.*"
675                         Delete /REBOOTOK "$SMPROGRAMS\$StartMenuFolder\*.lnk"
676                         Delete /REBOOTOK "$SMPROGRAMS\$StartMenuFolder\*.url"
677                         RMDir "$SMPROGRAMS\$StartMenuFolder"
678                 ${EndIf}
679                 
680                 SetShellVarContext all
681                 ${If} ${FileExists} "$SMPROGRAMS\$StartMenuFolder\LameXP.lnk"
682                         ${StdUtils.InvokeShellVerb} $R1 "$SMPROGRAMS\$StartMenuFolder" "LameXP.lnk" ${StdUtils.Const.ShellVerb.UnpinFromTaskbar}
683                         DetailPrint 'Unpin: "$SMPROGRAMS\$StartMenuFolder\LameXP.lnk" -> $R1'
684                 ${EndIf}
685                 ${If} ${FileExists} "$SMPROGRAMS\$StartMenuFolder\*.*"
686                         Delete /REBOOTOK "$SMPROGRAMS\$StartMenuFolder\*.lnk"
687                         Delete /REBOOTOK "$SMPROGRAMS\$StartMenuFolder\*.url"
688                         RMDir "$SMPROGRAMS\$StartMenuFolder"
689                 ${EndIf}
690         ${EndIf}
691
692         ; --------------
693         ; Files
694         ; --------------
695
696         ReadRegStr $R0 HKLM "${MyRegPath}" "ExecutableName"
697         ${IfThen} "$R0" == "" ${|} StrCpy $R0 "LameXP.exe" ${|}
698         ExecWait '"$INSTDIR\$R0" --uninstall'
699
700         Delete /REBOOTOK "$INSTDIR\$R0"
701         !insertmacro CleanUpFiles /REBOOTOK
702         RMDir "$INSTDIR"
703
704         ; --------------
705         ; Registry
706         ; --------------
707         
708         DeleteRegKey HKLM "${MyRegPath}"
709         DeleteRegKey HKCU "${MyRegPath}"
710
711         DeleteRegKey HKLM "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{54dcbccb-c905-46dc-b6e6-48563d0e9e55}"
712         DeleteRegKey HKCU "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{54dcbccb-c905-46dc-b6e6-48563d0e9e55}"
713         
714         DeleteRegKey HKLM "${AppPaths}\LameXP.exe"
715         DeleteRegKey HKCU "${AppPaths}\LameXP.exe"
716
717         MessageBox MB_YESNO|MB_TOPMOST "$(LAMEXP_LANG_UNINST_PERSONAL)" IDNO +3
718         Delete "$LOCALAPPDATA\LoRd_MuldeR\LameXP - Audio Encoder Front-End\config.ini"
719         Delete "$INSTDIR\*.ini"
720
721         !insertmacro PrintProgress "$(MUI_UNTEXT_FINISH_TITLE)."
722 SectionEnd
723
724
725 ;--------------------------------
726 ;Check For Update Mode
727 ;--------------------------------
728
729 Function SkipIfUnattended
730         ${IfThen} ${UnattendedMode} ${|} Abort ${|}
731 FunctionEnd
732
733 Function CheckForUpdate
734         ${If} "$INSTDIR" == ""
735         ${OrIf} "$INSTDIR" == "$EXEDIR"
736         ${OrIfNot} ${FileExists} "$INSTDIR\LameXP.exe"
737                 Return
738         ${EndIf}
739
740         FindWindow $R0 "#32770" "" $HWNDPARENT
741         GetDlgItem $R1 $R0 1019
742         EnableWindow $R1 0
743
744         FindWindow $R0 "#32770" "" $HWNDPARENT
745         GetDlgItem $R1 $R0 1001
746         EnableWindow $R1 0
747 FunctionEnd
748
749 Function un.CheckForcedUninstall
750         ${IfThen} ${ForcedMode} ${|} Abort ${|}
751 FunctionEnd
752
753
754 ;--------------------------------
755 ;Check For Pre-Release
756 ;--------------------------------
757
758 Function CheckForPreRelease
759         !ifdef LAMEXP_IS_PRERELEASE
760                 ${IfNot} ${UnattendedMode}
761                         MessageBox MB_TOPMOST|MB_ICONEXCLAMATION|MB_OKCANCEL "$(LAMEXP_LANG_PRERELEASE_WARNING)" /SD IDOK IDOK +2
762                         Quit
763                 ${EndIf}
764         !endif
765 FunctionEnd
766
767
768 ;--------------------------------
769 ;Locked List
770 ;--------------------------------
771
772 !macro _LockedListShow uinst
773         !insertmacro MUI_HEADER_TEXT "$(LAMEXP_LANG_LOCKEDLIST_HEADER)" "$(LAMEXP_LANG_LOCKEDLIST_TEXT)"
774         ${If} ${UnattendedMode}
775                 !insertmacro DisableBackButton $R0
776         ${EndIf}
777         ${If} ${RunningX64}
778                 InitPluginsDir
779                 File /oname=$PLUGINSDIR\LockedList64.dll `${NSISDIR}\Plugins\LockedList64.dll`
780         ${EndIf}
781         !insertmacro GetExecutableName $R0
782         LockedList::AddModule "\$R0"
783         ${If} "$R0" != "LameXP.exe"
784                 LockedList::AddModule "\LameXP.exe"
785         ${EndIf}
786         LockedList::AddModule "\Uninstall.exe"
787         !if ${uinst} < 1
788                 LockedList::AddModule "\Au_.exe"
789         !endif
790         #LockedList::AddFolder "$INSTDIR"
791         LockedList::Dialog /autonext /heading "$(LAMEXP_LANG_LOCKEDLIST_HEADING)" /noprograms "$(LAMEXP_LANG_LOCKEDLIST_NOPROG)" /searching  "$(LAMEXP_LANG_LOCKEDLIST_SEARCH)" /colheadings "$(LAMEXP_LANG_LOCKEDLIST_COLHDR1)" "$(LAMEXP_LANG_LOCKEDLIST_COLHDR2)"
792         Pop $R0
793 !macroend
794
795 Function LockedListShow
796         !insertmacro _LockedListShow 0
797 FunctionEnd
798
799 Function un.LockedListShow
800         !insertmacro _LockedListShow 1
801 FunctionEnd
802
803
804 ;--------------------------------
805 ;Install Success
806 ;--------------------------------
807
808 Function RunAppFunction
809         !insertmacro DisableNextButton $R0
810         !insertmacro GetExecutableName $R0
811         ${StdUtils.ExecShellAsUser} $R1 "$INSTDIR" "explore" ""
812         ${StdUtils.ExecShellAsUser} $R1 "$INSTDIR\$R0" "open" "--first-run"
813 FunctionEnd
814
815 Function ShowReadmeFunction
816         !insertmacro DisableNextButton $R0
817         ${StdUtils.ExecShellAsUser} $R1 "$INSTDIR\Manual.html" "open" ""
818 FunctionEnd
819
820 Function .onInstSuccess
821         ${If} ${UnattendedMode}
822                 !insertmacro GetExecutableName $R0
823                 ${StdUtils.ExecShellAsUser} $R1 "$INSTDIR\$R0" "open" "--first-run"
824         ${EndIf}
825 FunctionEnd