!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"\r
!define PRODUCT_UNINST_ROOT_KEY "HKLM"\r
\r
+;Required .NET framework\r
+!define MIN_FRA_MAJOR "3"\r
+!define MIN_FRA_MINOR "5"\r
+!define MIN_FRA_BUILD "*"\r
+\r
SetCompressor lzma\r
\r
; MUI 1.67 compatible ------\r
!insertmacro VersionCompare\r
!include LogicLib.nsh\r
\r
-; Check to see if .NET Framework 2.0 or above is Installed.\r
+InstallDir "$PROGRAMFILES\Handbrake"\r
+InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""\r
+ShowInstDetails show\r
+ShowUnInstDetails show\r
+\r
+Var InstallDotNET\r
+\r
Function .onInit\r
- Call GetDotNETVersion\r
- Pop $0\r
- ${If} $0 == "not found"\r
- MessageBox MB_OK|MB_ICONSTOP ".NET runtime library is not installed. $\r$\n You can download .Net Framework 2.0 redistributable from the microsoft website. $\r$\n Alternatively you can use google for a direct download URL"\r
- Abort\r
- ${EndIf}\r
\r
- StrCpy $0 $0 "" 1 # skip "v"\r
+ ; Begin Only allow one version\r
+ System::Call 'kernel32::CreateMutexA(i 0, i 0, t "myMutex") i .r1 ?e'\r
+ Pop $R0\r
\r
- ${VersionCompare} $0 "2.0" $1\r
- ${If} $1 == 2\r
- MessageBox MB_OK|MB_ICONSTOP ".NET runtime library v2.0 or newer is required. You have $0. $\r$\n You can download .Net Framework 2.0 redistributable from the Microsoft website. $\r$\n Alternatively you can use google for a direct download URL"\r
- Abort\r
- ${EndIf}\r
-FunctionEnd\r
+ StrCmp $R0 0 +3\r
+ MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running."\r
+ Abort\r
\r
-Function GetDotNETVersion\r
- Push $0\r
- Push $1\r
+ ;Remove previous version\r
+ ReadRegStr $R0 HKLM \\r
+ "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}\" \\r
+ "UninstallString"\r
+ StrCmp $R0 "" done\r
\r
- System::Call "mscoree::GetCORVersion(w .r0, i ${NSIS_MAX_STRLEN}, *i) i .r1 ?u"\r
- StrCmp $1 "error" 0 +2\r
- StrCpy $0 "not found"\r
+ MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \\r
+ "${PRODUCT_NAME} ${PRODUCT_VERSION} is already installed. $\n$\nClick `OK` to remove the \\r
+ previous version or `Cancel` to continue." \\r
+ IDOK uninst\r
+ goto done\r
\r
- Pop $1\r
- Exch $0\r
+ ;Run the uninstaller\r
+ uninst:\r
+ Exec $INSTDIR\uninst.exe\r
+ done:\r
FunctionEnd\r
\r
\r
-InstallDir "$PROGRAMFILES\Handbrake"\r
-InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""\r
-ShowInstDetails show\r
-ShowUnInstDetails show\r
-\r
Section "Handbrake" SEC01\r
SetOutPath "$INSTDIR"\r
SetOverwrite ifnewer\r
+ \r
+ ; Begin Check .NET version\r
+ StrCpy $InstallDotNET "No"\r
+ Call CheckFramework\r
+ StrCmp $0 "1" +3\r
+ StrCpy $InstallDotNET "Yes"\r
+ MessageBox MB_OK|MB_ICONINFORMATION "${PRODUCT_NAME} requires that the .NET Framework 3.5 SP1 is installed. The latest .NET Framework will be downloaded and installed automatically during installation of ${PRODUCT_NAME}."\r
+ Pop $0\r
+\r
+ ; Get .NET if required\r
+ ${If} $InstallDotNET == "Yes"\r
+ SetDetailsView hide\r
+ inetc::get /caption "Downloading .NET Framework 3.5" /canceltext "Cancel" "http://www.microsoft.com/downloads/info.aspx?na=90&p=&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=ab99342f-5d1a-413d-8319-81da479ab0d7&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f0%2f6%2f1%2f061f001c-8752-4600-a198-53214c69b51f%2fdotnetfx35setup.exe" "$INSTDIR\dotnetfx.exe" /end\r
+ Pop $1\r
+\r
+ ${If} $1 != "OK"\r
+ Delete "$INSTDIR\dotnetfx.exe"\r
+ Abort "Installation cancelled, ${PRODUCT_NAME} requires the .NET 3.5 Framework"\r
+ ${EndIf}\r
+\r
+ ExecWait "$INSTDIR\dotnetfx.exe"\r
+ Delete "$INSTDIR\dotnetfx.exe"\r
+\r
+ SetDetailsView show\r
+ ${EndIf}\r
+\r
+ ; Install Files\r
File "Handbrake.exe"\r
CreateDirectory "$SMPROGRAMS\Handbrake"\r
CreateShortCut "$SMPROGRAMS\Handbrake\Handbrake.lnk" "$INSTDIR\Handbrake.exe"\r
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"\r
SectionEnd\r
\r
-\r
Function un.onUninstSuccess\r
HideWindow\r
MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."\r
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"\r
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"\r
SetAutoClose true\r
-SectionEnd
\ No newline at end of file
+SectionEnd\r
+\r
+;Check for .NET framework\r
+Function CheckFrameWork\r
+\r
+ ;Save the variables in case something else is using them\r
+ Push $0\r
+ Push $1\r
+ Push $2\r
+ Push $3\r
+ Push $4\r
+ Push $R1\r
+ Push $R2\r
+ Push $R3\r
+ Push $R4\r
+ Push $R5\r
+ Push $R6\r
+ Push $R7\r
+ Push $R8\r
+\r
+ StrCpy $R5 "0"\r
+ StrCpy $R6 "0"\r
+ StrCpy $R7 "0"\r
+ StrCpy $R8 "0.0.0"\r
+ StrCpy $0 0\r
+\r
+ loop:\r
+\r
+ ;Get each sub key under "SOFTWARE\Microsoft\NET Framework Setup\NDP"\r
+ EnumRegKey $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP" $0\r
+ StrCmp $1 "" done ;jump to end if no more registry keys\r
+ IntOp $0 $0 + 1\r
+ StrCpy $2 $1 1 ;Cut off the first character\r
+ StrCpy $3 $1 "" 1 ;Remainder of string\r
+\r
+ ;Loop if first character is not a 'v'\r
+ StrCmpS $2 "v" start_parse loop\r
+\r
+ ;Parse the string\r
+ start_parse:\r
+ StrCpy $R1 ""\r
+ StrCpy $R2 ""\r
+ StrCpy $R3 ""\r
+ StrCpy $R4 $3\r
+\r
+ StrCpy $4 1\r
+\r
+ parse:\r
+ StrCmp $3 "" parse_done ;If string is empty, we are finished\r
+ StrCpy $2 $3 1 ;Cut off the first character\r
+ StrCpy $3 $3 "" 1 ;Remainder of string\r
+ StrCmp $2 "." is_dot not_dot ;Move to next part if it's a dot\r
+\r
+ is_dot:\r
+ IntOp $4 $4 + 1 ; Move to the next section\r
+ goto parse ;Carry on parsing\r
+\r
+ not_dot:\r
+ IntCmp $4 1 major_ver\r
+ IntCmp $4 2 minor_ver\r
+ IntCmp $4 3 build_ver\r
+ IntCmp $4 4 parse_done\r
+\r
+ major_ver:\r
+ StrCpy $R1 $R1$2\r
+ goto parse ;Carry on parsing\r
+\r
+ minor_ver:\r
+ StrCpy $R2 $R2$2\r
+ goto parse ;Carry on parsing\r
+\r
+ build_ver:\r
+ StrCpy $R3 $R3$2\r
+ goto parse ;Carry on parsing\r
+\r
+ parse_done:\r
+\r
+ IntCmp $R1 $R5 this_major_same loop this_major_more\r
+ this_major_more:\r
+ StrCpy $R5 $R1\r
+ StrCpy $R6 $R2\r
+ StrCpy $R7 $R3\r
+ StrCpy $R8 $R4\r
+\r
+ goto loop\r
+\r
+ this_major_same:\r
+ IntCmp $R2 $R6 this_minor_same loop this_minor_more\r
+ this_minor_more:\r
+ StrCpy $R6 $R2\r
+ StrCpy $R7 R3\r
+ StrCpy $R8 $R4\r
+ goto loop\r
+\r
+ this_minor_same:\r
+ IntCmp $R3 $R7 loop loop this_build_more\r
+ this_build_more:\r
+ StrCpy $R7 $R3\r
+ StrCpy $R8 $R4\r
+ goto loop\r
+\r
+ done:\r
+\r
+ ;Have we got the framework we need?\r
+ IntCmp $R5 ${MIN_FRA_MAJOR} max_major_same fail OK\r
+ max_major_same:\r
+ IntCmp $R6 ${MIN_FRA_MINOR} max_minor_same fail OK\r
+ max_minor_same:\r
+ IntCmp $R7 ${MIN_FRA_BUILD} OK fail OK\r
+\r
+ ;Version on machine is greater than what we need\r
+ OK:\r
+ StrCpy $0 "1"\r
+ goto end\r
+\r
+ fail:\r
+ StrCmp $R8 "0.0.0" end\r
+\r
+\r
+ end:\r
+\r
+ ;Pop the variables we pushed earlier\r
+ Pop $R8\r
+ Pop $R7\r
+ Pop $R6\r
+ Pop $R5\r
+ Pop $R4\r
+ Pop $R3\r
+ Pop $R2\r
+ Pop $R1\r
+ Pop $4\r
+ Pop $3\r
+ Pop $2\r
+ Pop $1\r
+FunctionEnd
\ No newline at end of file