1
2${MementoSection} "-Start menu Change Log" SecStartMenuChangeLog
3    CreateDirectory $SMPROGRAMS\$StartMenuGroup
4    !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
5    SetOutPath $INSTDIR
6    CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Change Log ${CORE_VERSION}.lnk" "$INSTDIR\ChangeLog.html"
7    !insertmacro MUI_STARTMENU_WRITE_END
8${MementoSectionEnd}
9
10
11${MementoSection} "-Start menu Qt" SecStartMenuQt
12    CreateDirectory $SMPROGRAMS\$StartMenuGroup
13    !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
14    SetOutPath $INSTDIR
15    CreateShortcut "$SMPROGRAMS\$StartMenuGroup\${SHORTCUT_NAME}.lnk" $INSTDIR\avidemux.exe
16    CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Avidemux job control (${BUILD_BITS} Bits).lnk" $INSTDIR\avidemux_jobs.exe
17    !insertmacro MUI_STARTMENU_WRITE_END
18${MementoSectionEnd}
19
20#${MementoSection} "-Start menu AVS Proxy GUI" SecStartMenuAvsProxyGui
21    #CreateDirectory $SMPROGRAMS\$StartMenuGroup
22    #!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
23    #SetOutPath $INSTDIR
24    #CreateShortcut "$SMPROGRAMS\$StartMenuGroup\AVS Proxy GUI ${CORE_VERSION}.lnk" "$INSTDIR\avsproxy_gui.exe"
25    #CreateShortcut "$SMPROGRAMS\$StartMenuGroup\VS Proxy GUI ${CORE_VERSION}.lnk" "$INSTDIR\vsProxy_gui_qt5.exe"
26    #!insertmacro MUI_STARTMENU_WRITE_END
27#${MementoSectionEnd}
28
29
30${MementoSection} "-Quick Launch Qt" SecQuickLaunchQt
31    SetOutPath $INSTDIR
32    CreateShortcut "$QUICKLAUNCH\${SHORTCUT_NAME}.lnk" $INSTDIR\avidemux.exe
33${MementoSectionEnd}
34
35
36${MementoSection} "-Desktop Qt" SecDesktopQt
37    SetOutPath $INSTDIR
38    CreateShortcut "$DESKTOP\${SHORTCUT_NAME}.lnk" $INSTDIR\avidemux.exe
39${MementoSectionEnd}
40
41${MementoSectionDone}
42
43Section -post SecUninstaller
44    SectionIn 1 2
45    WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
46    WriteRegStr HKLM "${REGKEY}" Version ${PRODUCT_VERSION}
47    SetOutPath $INSTDIR
48    WriteUninstaller $INSTDIR\uninstall.exe
49    WriteRegStr HKLM "${UNINST_REGKEY}" DisplayName "${SHORTCUT_NAME}"
50    WriteRegStr HKLM "${UNINST_REGKEY}" DisplayVersion "${PRODUCT_VERSION}"
51    WriteRegStr HKLM "${UNINST_REGKEY}" DisplayIcon $INSTDIR\uninstall.exe
52    WriteRegStr HKLM "${UNINST_REGKEY}" UninstallString $INSTDIR\uninstall.exe
53    WriteRegDWORD HKLM "${UNINST_REGKEY}" NoModify 1
54    WriteRegDWORD HKLM "${UNINST_REGKEY}" NoRepair 1
55SectionEnd
56
57Section -CloseLogFile
58	FileClose $UninstallLogHandle
59	SetFileAttributes ${UninstallLogPath} HIDDEN
60SectionEnd
61
62Section Uninstall
63	!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuGroup
64
65
66    Delete /REBOOTOK "$QUICKLAUNCH\${SHORTCUT_NAME}.lnk"
67    Delete /REBOOTOK "$DESKTOP\${SHORTCUT_NAME}.lnk"
68    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\${SHORTCUT_NAME}.lnk"
69    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Avidemux job control (${BUILD_BITS} Bits).lnk"
70    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Change Log ${CORE_VERSION}.lnk"
71    Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\AVS Proxy GUI ${CORE_VERSION}.lnk"
72    RmDir /REBOOTOK $SMPROGRAMS\$StartMenuGroup
73    DeleteRegValue HKLM "${REGKEY}" StartMenuGroup
74
75    DeleteRegKey HKLM "${UNINST_REGKEY}"
76    DeleteRegValue HKLM "${REGKEY}" Path
77	DeleteRegValue HKLM "${REGKEY}" CreateDesktopIcon
78	DeleteRegValue HKLM "${REGKEY}" CreateStartMenuGroup
79	DeleteRegValue HKLM "${REGKEY}" CreateQuickLaunchIcon
80    DeleteRegKey /IfEmpty HKLM "${REGKEY}"
81
82	FileOpen $UninstallLogHandle "${UninstallLogPath}" r
83UninstallLoop:
84    ClearErrors
85    FileRead $UninstallLogHandle $R0
86    IfErrors UninstallEnd
87	Push $R0
88    Call un.TrimNewLines
89    Pop $R0
90    Delete "$R0"
91    Goto UninstallLoop
92UninstallEnd:
93	FileClose $UninstallLogHandle
94	Delete "${UninstallLogPath}"
95	Delete "$INSTDIR\uninstall.exe"
96	Push "\"
97	Call un.RemoveEmptyDirs
98	RMDir "$INSTDIR"
99SectionEnd
100
101##########################
102# Installer functions
103##########################
104Function .onInit
105UAC_Elevate:
106	!insertmacro UAC_RunElevated
107	StrCmp 1223 $0 UAC_ElevationAborted
108	StrCmp 0 $0 0 UAC_Err
109	StrCmp 1 $1 0 UAC_Success
110	Quit
111
112UAC_Err:
113	MessageBox MB_ICONSTOP "Unable to elevate, error $0"
114	Abort
115
116UAC_ElevationAborted:
117	Abort
118
119UAC_Success:
120	StrCmp 1 $3 +4
121	StrCmp 3 $1 0 UAC_ElevationAborted
122	MessageBox MB_ICONSTOP "This installer requires admin access."
123	Goto UAC_Elevate
124
125	Call LoadPreviousSettings
126	ReadRegStr $PreviousVersion HKLM "${REGKEY}" Version
127
128	${If} $PreviousVersion != ""
129		${VersionCompare} ${PRODUCT_VERSION} $PreviousVersion $PreviousVersionState
130	${EndIf}
131
132    InitPluginsDir
133    SetShellVarContext all
134FunctionEnd
135
136Function .onInstSuccess
137	${MementoSectionSave}
138FunctionEnd
139
140Function LoadPreviousSettings
141    ${MementoSectionRestore}
142	!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuGroup
143
144	ReadRegStr $CreateStartMenuGroup HKLM "${REGKEY}" CreateStartMenuGroup
145
146	${If} $CreateStartMenuGroup == ""
147		StrCpy $CreateStartMenuGroup 1
148	${EndIf}
149
150	ReadRegStr $CreateDesktopIcon HKLM "${REGKEY}" CreateDesktopIcon
151
152	${If} $CreateDesktopIcon == ""
153		StrCpy $CreateDesktopIcon 1
154	${EndIf}
155
156	${If} ${AtMostWinVista}
157		ReadRegStr $CreateQuickLaunchIcon HKLM "${REGKEY}" CreateQuickLaunchIcon
158
159		${If} $CreateQuickLaunchIcon == ""
160			StrCpy $CreateQuickLaunchIcon 1
161		${EndIf}
162	${EndIf}
163
164FunctionEnd
165
166Function RunUninstaller
167    ReadRegStr $R1  HKLM "${UNINST_REGKEY}" "UninstallString"
168
169	${If} $R1 == ""
170		Return
171	${EndIf}
172
173	;Run uninstaller
174	HideWindow
175	ClearErrors
176
177	${If} $PreviousVersionState == 0
178	${AndIf} $ReinstallUninstall == 1
179		ExecWait '$R1 _?=$INSTDIR'
180	${Else}
181		ExecWait '$R1 /frominstall _?=$INSTDIR'
182	${EndIf}
183
184	IfErrors NoRemoveUninstaller
185	IfFileExists "$INSTDIR\uninstall.exe" 0 NoRemoveUninstaller
186		Delete "$R1"
187		RMDir $INSTDIR
188
189NoRemoveUninstaller:
190FunctionEnd
191
192Function CheckSelectedUIs
193	!insertmacro SectionFlagIsSet ${SecGrpUI} ${SF_SELECTED} end checkPartial
194checkPartial:
195	!insertmacro SectionFlagIsSet ${SecGrpUI} ${SF_PSELECTED} end displayError
196displayError:
197    MessageBox MB_OK|MB_ICONSTOP "At least one User Interface must be selected."
198    Abort
199end:
200FunctionEnd
201
202LangString INSTALL_OPTS_PAGE_TITLE ${LANG_ENGLISH} "Choose Install Options"
203LangString INSTALL_OPTS_PAGE_SUBTITLE ${LANG_ENGLISH} "Choose where to install Avidemux icons."
204Var dlgInstallOptions
205Var lblCreateIcons
206Var chkDesktop
207Var chkStartMenu
208Var chkQuickLaunch
209
210Function InstallOptionsPage
211	Call IsInstallOptionsRequired
212	!insertmacro MUI_HEADER_TEXT "$(INSTALL_OPTS_PAGE_TITLE)" "$(INSTALL_OPTS_PAGE_SUBTITLE)"
213
214	nsDialogs::Create 1018
215	Pop $dlgInstallOptions
216
217	${If} $dlgInstallOptions == error
218		Abort
219	${EndIf}
220
221	${NSD_CreateLabel} 0 0u 100% 12u "Create icons for Avidemux:"
222	Pop $lblCreateIcons
223
224	${NSD_CreateCheckBox} 0 18u 100% 12u "On my &Desktop"
225	Pop $chkDesktop
226	${NSD_SetState} $chkDesktop $CreateDesktopIcon
227	${NSD_OnClick} $chkDesktop UpdateInstallOptions
228
229	${NSD_CreateCheckBox} 0 36u 100% 12u "In my &Start Menu Programs folder"
230	Pop $chkStartMenu
231	${NSD_SetState} $chkStartMenu $CreateStartMenuGroup
232	${NSD_OnClick} $chkStartMenu UpdateInstallOptions
233
234	${If} ${AtMostWinVista}
235		${NSD_CreateCheckBox} 0 54u 100% 12u "In my &Quick Launch bar"
236		Pop $chkQuickLaunch
237		${NSD_SetState} $chkQuickLaunch $CreateQuickLaunchIcon
238		${NSD_OnClick} $chkQuickLaunch UpdateInstallOptions
239	${EndIf}
240  	#${If} ${IsWin2003}
241		#WriteRegStr HKCU "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\avidemux.exe" "WIN2000"
242	#${EndIf}
243  	#${If} ${IsWinXp}
244		#WriteRegStr HKCU "Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\avidemux.exe" "WIN2000"
245	#${EndIf}
246	nsDialogs::Show
247FunctionEnd
248
249Function UpdateInstallOptions
250	${NSD_GetState} $chkDesktop $CreateDesktopIcon
251	${NSD_GetState} $chkStartMenu $CreateStartMenuGroup
252	${NSD_GetState} $chkQuickLaunch $CreateQuickLaunchIcon
253FunctionEnd
254
255Function IsInstallOptionsRequired
256#Goto end
257	#!insertmacro SectionFlagIsSet ${SecDesktopQt} ${SF_SELECTED} end resetOptions
258#resetOptions:
259
260    #StrCpy $CreateDesktopIcon 0
261    #StrCpy $CreateStartMenuGroup 0
262    #StrCpy $CreateQuickLaunchIcon 0
263    #Abort
264
265end:
266FunctionEnd
267
268Function IsStartMenuRequired
269    StrCmp $CreateStartMenuGroup 1 +2
270        Abort
271FunctionEnd
272
273Function ActivateInternalSections
274    #AVS Proxy GUI shortcut:
275    SectionGetFlags ${SecDesktopQt} $0 # Was SecAvsProxy
276    IntOp $0 $0 & ${SF_SELECTED}
277    IntOp $0 $0 & $CreateStartMenuGroup
278    SectionSetFlags ${SecDesktopQt} $0
279
280    #Change Log shortcut:
281    SectionSetFlags ${SecStartMenuChangeLog} $CreateStartMenuGroup
282
283    #Qt shortcuts:
284    SectionGetFlags ${SecDesktopQt} $0
285    IntOp $0 $0 & ${SF_SELECTED}
286
287    IntOp $1 $0 & $CreateDesktopIcon
288    SectionSetFlags ${SecDesktopQt} $1
289
290    IntOp $1 $0 & $CreateQuickLaunchIcon
291    SectionSetFlags ${SecQuickLaunchQt} $1
292
293    IntOp $1 $0 & $CreateStartMenuGroup
294    SectionSetFlags ${SecStartMenuQt} $1
295FunctionEnd
296
297Function InstFilesPageShow
298	${If} $ReinstallUninstall != ""
299		Call RunUninstaller
300		BringToFront
301	${EndIf}
302FunctionEnd
303
304Function InstFilesPageLeave
305	; Don't advance automatically if details expanded
306	FindWindow $R0 "#32770" "" $HWNDPARENT
307	GetDlgItem $R0 $R0 1016
308	System::Call user32::IsWindowVisible(i$R0)i.s
309	Pop $R0
310
311	StrCmp $R0 0 +2
312	SetAutoClose false
313FunctionEnd
314
315Function ConfigureFinishPage
316
317    SectionGetFlags ${SecDesktopQt} $0
318    IntOp $0 $0 & ${SF_SELECTED}
319    StrCmp $0 ${SF_SELECTED} end
320
321    DeleteINISec "$PLUGINSDIR\ioSpecial.ini" "Field 4"
322
323end:
324FunctionEnd
325
326Function RunAvidemux
327    SetOutPath $INSTDIR
328
329    SectionGetFlags ${SecDesktopQt} $0
330    IntOp $0 $0 & ${SF_SELECTED}
331
332	!insertmacro UAC_AsUser_ExecShell "" "$INSTDIR\avidemux.exe" "" "" ""
333
334    Goto end
335
336
337end:
338FunctionEnd
339
340Var ReinstallUninstallButton
341
342Function ReinstallPage
343	${If} $PreviousVersion == ""
344		Abort
345	${EndIf}
346
347	nsDialogs::Create /NOUNLOAD 1018
348	Pop $0
349
350	${If} $PreviousVersionState == 1
351		!insertmacro MUI_HEADER_TEXT "Already Installed" "Choose how you want to install ${PRODUCT_FULLNAME}."
352		nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 0 0 100% 40 "An older version of Avidemux is installed on your system.  Select the operation you want to perform and click Next to continue."
353		Pop $R0
354		nsDialogs::CreateItem /NOUNLOAD BUTTON ${BS_AUTORADIOBUTTON}|${BS_VCENTER}|${BS_MULTILINE}|${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${WS_GROUP}|${WS_TABSTOP} 0 10 55 100% 30 "Upgrade Avidemux using previous settings (recommended)"
355		Pop $ReinstallUninstallButton
356		nsDialogs::CreateItem /NOUNLOAD BUTTON ${BS_AUTORADIOBUTTON}|${BS_TOP}|${BS_MULTILINE}|${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 10 85 100% 50 "Change settings (advanced)"
357		Pop $R0
358
359		${If} $ReinstallUninstall == ""
360			StrCpy $ReinstallUninstall 1
361		${EndIf}
362	${ElseIf} $PreviousVersionState == 2
363		!insertmacro MUI_HEADER_TEXT "Already Installed" "Choose how you want to install ${PRODUCT_FULLNAME}."
364		nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 0 0 100% 40 "A newer version of Avidemux is already installed! It is not recommended that you downgrade to an older version. Select the operation you want to perform and click Next to continue."
365		Pop $R0
366		nsDialogs::CreateItem /NOUNLOAD BUTTON ${BS_AUTORADIOBUTTON}|${BS_VCENTER}|${BS_MULTILINE}|${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${WS_GROUP}|${WS_TABSTOP} 0 10 55 100% 30 "Downgrade Avidemux using previous settings (recommended)"
367		Pop $ReinstallUninstallButton
368		nsDialogs::CreateItem /NOUNLOAD BUTTON ${BS_AUTORADIOBUTTON}|${BS_TOP}|${BS_MULTILINE}|${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 10 85 100% 50 "Change settings (advanced)"
369		Pop $R0
370
371		${If} $ReinstallUninstall == ""
372			StrCpy $ReinstallUninstall 1
373		${EndIf}
374	${ElseIf} $PreviousVersionState == 0
375		!insertmacro MUI_HEADER_TEXT "Already Installed" "Choose the maintenance option to perform."
376		nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 0 0 100% 40 "${PRODUCT_FULLNAME} is already installed. Select the operation you want to perform and click Next to continue."
377		Pop $R0
378		nsDialogs::CreateItem /NOUNLOAD BUTTON ${BS_AUTORADIOBUTTON}|${BS_VCENTER}|${BS_MULTILINE}|${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${WS_GROUP}|${WS_TABSTOP} 0 10 55 100% 30 "Add/Remove/Reinstall components"
379		Pop $R0
380		nsDialogs::CreateItem /NOUNLOAD BUTTON ${BS_AUTORADIOBUTTON}|${BS_TOP}|${BS_MULTILINE}|${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 10 85 100% 50 "Uninstall Avidemux"
381		Pop $ReinstallUninstallButton
382
383		${If} $ReinstallUninstall == ""
384			StrCpy $ReinstallUninstall 2
385		${EndIf}
386	${Else}
387		MessageBox MB_ICONSTOP "Unknown value of PreviousVersionState, aborting" /SD IDOK
388		Abort
389	${EndIf}
390
391	${If} $ReinstallUninstall == "1"
392		SendMessage $ReinstallUninstallButton ${BM_SETCHECK} 1 0
393	${Else}
394		SendMessage $R0 ${BM_SETCHECK} 1 0
395	${EndIf}
396
397	nsDialogs::Show
398FunctionEnd
399
400Function ReinstallPageLeave
401	SendMessage $ReinstallUninstallButton ${BM_GETCHECK} 0 0 $R0
402
403	${If} $R0 == 1
404		; Option to uninstall old version selected
405		StrCpy $ReinstallUninstall 1
406	${Else}
407		; Custom up/downgrade or add/remove/reinstall
408		StrCpy $ReinstallUninstall 2
409	${EndIf}
410
411	${If} $ReinstallUninstall == 1
412		${If} $PreviousVersionState == 0
413			Call RunUninstaller
414			Quit
415		${Else}
416			; Need to reload defaults. User could have
417			; chosen custom, change something, went back and selected
418			; the express option.
419			Call LoadPreviousSettings
420		${EndIf}
421	${EndIf}
422FunctionEnd
423
424
425##########################
426# Uninstaller functions
427##########################
428Function un.onInit
429	SetShellVarContext all
430
431UAC_Elevate:
432	!insertmacro UAC_RunElevated
433	StrCmp 1223 $0 UAC_ElevationAborted
434	StrCmp 0 $0 0 UAC_Err
435	StrCmp 1 $1 0 UAC_Success
436	Quit
437
438UAC_Err:
439	MessageBox MB_ICONSTOP "Unable to elevate, error $0"
440	Abort
441
442UAC_ElevationAborted:
443	Abort
444
445UAC_Success:
446	StrCmp 1 $3 +4
447	StrCmp 3 $1 0 UAC_ElevationAborted
448	MessageBox MB_ICONSTOP "This installer requires admin access."
449	Goto UAC_Elevate
450FunctionEnd
451
452; TrimNewlines (copied from NSIS documentation)
453; input, top of stack  (e.g. whatever$/r$/n)
454; output, top of stack (replaces, with e.g. whatever)
455; modifies no other variables.
456Function un.TrimNewlines
457	Exch $R0
458	Push $R1
459	Push $R2
460	StrCpy $R1 0
461
462loop:
463	IntOp $R1 $R1 - 1
464	StrCpy $R2 $R0 1 $R1
465	StrCmp $R2 "$\r" loop
466	StrCmp $R2 "$\n" loop
467	IntOp $R1 $R1 + 1
468	IntCmp $R1 0 no_trim_needed
469	StrCpy $R0 $R0 $R1
470
471no_trim_needed:
472	Pop $R2
473	Pop $R1
474	Exch $R0
475FunctionEnd
476
477Function un.RemoveEmptyDirs
478	Pop $9
479	!define Index 'Line${__LINE__}'
480	FindFirst $0 $1 "$INSTDIR$9*"
481	StrCmp $0 "" "${Index}-End"
482"${Index}-Loop:"
483	StrCmp $1 "" "${Index}-End"
484	StrCmp $1 "." "${Index}-Next"
485	StrCmp $1 ".." "${Index}-Next"
486	Push $0
487	Push $1
488	Push $9
489	Push "$9$1\"
490	Call un.RemoveEmptyDirs
491	Pop $9
492	Pop $1
493	Pop $0
494;"${Index}-Remove:"
495	RMDir "$INSTDIR$9$1"
496"${Index}-Next:"
497	FindNext $0 $1
498	Goto "${Index}-Loop"
499"${Index}-End:"
500	FindClose $0
501	!undef Index
502FunctionEnd
503
504Function un.ConfirmPagePre
505	${un.GetParameters} $R0
506	${un.GetOptions} $R0 "/frominstall" $R1
507	${Unless} ${Errors}
508		Abort
509	${EndUnless}
510FunctionEnd
511
512Function un.FinishPagePre
513	${un.GetParameters} $R0
514	${un.GetOptions} $R0 "/frominstall" $R1
515	${Unless} ${Errors}
516		SetRebootFlag false
517		Abort
518	${EndUnless}
519FunctionEnd
520