;NSIS Modern User Interface ;Basic Example Script ;Written by Joost Verburg ;-------------------------------- ;Include Modern UI !include "MUI.nsh" !include "Sections.nsh" ;-------------------------------- ;General ;Name and file Name "Modern UI Test" OutFile "Basic.exe" BrandingText "test v1.0 Full Installer" Var hl2Check Var sourceModsCheck Function getParent Push $8 Exch $0 Push $1 Push $2 StrCpy $1 -1 loop: StrCpy $2 $0 1 $1 StrCmp $2 "" exit StrCmp $2 "\" exit IntOp $1 $1 - 2 Goto loop exit: StrCpy $0 $0 $1 Pop $2 Pop $1 Exch $0 FunctionEnd Function findSteam ReadRegStr $8 HKCU \ "Software\Valve\Steam" \ "ModInstallPath" Push $8 Call getParent Pop $8 StrCmp $8 "" skip checkInstall checkInstall: StrCpy $hl2Check "$8" GoTo skip2 skip: MessageBox MB_OK|MB_ICONSTOP "Unable to find Steam installation.$\r$\nPlease install Steam and try again." abort skip2: Call checkHl2 FunctionEnd Function checkHl2 IfFileExists "$hl2Check\source engine.gcf" exist notexist exist: StrCpy $sourceModsCheck "$hl2Check" Goto skip notexist: MessageBox MB_OK|MB_ICONSTOP "Unable to find Half-Life 2 installation.$\r$\nPlease install Half-Life 2 and try again." abort skip: Call checkSourceMods FunctionEnd Function checkSourceMods IfFileExists "$sourceModsCheck\SourceMods" exist notexist exist: StrCpy $INSTDIR "$sourceModsCheck\SourceMods" Goto skip notexist: StrCpy $INSTDIR "Unable to find SourceMods folder. Please browse manually..." skip: FunctionEnd Function .onInit !insertmacro MUI_LANGDLL_DISPLAY Call findSteam FunctionEnd Function .onVerifyInstDir StrCmp $INSTDIR "$sourceModsCheck\SourceMods" PathGood Abort PathGood: FunctionEnd Function checkOld IfFileExists "$INSTDIR" OldInst NoInst OldInst: MessageBox MB_OK|MB_ICONEXCLAMATION "A previous installation of test has been found.$\r$\nPlease run the uninstaller and try again." Call KillOld NoInst: FunctionEnd Function KillOld MessageBox MB_YESNO|MB_ICONQUESTION "Would you like to run the uninstaller now?" IDNO Kill Exec "$INSTDIR\Uninstall.exe" Quit Kill: Quit FunctionEnd ;-------------------------------- ;Interface Settings !define MUI_ABORTWARNING ; !define MUI_ABORTWARNING_TEXT ;-------------------------------- ;Pages !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Contrib\Modern UI\License.txt" !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_WELCOME !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES !insertmacro MUI_UNPAGE_FINISH ;-------------------------------- ;Languages !define MUI_LANGDLL_REGISTRY_ROOT "HKCU" !define MUI_LANGDLL_REGISTRY_KEY "Software\test" !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language" !insertmacro MUI_LANGUAGE "English" !insertmacro MUI_LANGUAGE "Spanish" !insertmacro MUI_LANGUAGE "French" !insertmacro MUI_RESERVEFILE_LANGDLL ;-------------------------------- ;Installer Sections Var UninstLog !macro File FileName File "${FileName}" FileWrite $UninstLog "$INSTDIR\${FileName}$\r$\n" !macroend !define File "!insertmacro File" Section -addtest StrCpy $INSTDIR "$INSTDIR\test" SectionEnd Section -checkold Call checkOld SectionEnd Section -openlogfile SetOutPath "$INSTDIR" File "uninstall.log" FileOpen $UninstLog "$INSTDIR\uninstall.log" w FileWrite $UninstLog "DO NOT DELETE THIS FILE!!!$\r$\n" FileWrite $UninstLog "$\r$\n" SectionEnd Section -Uninstaller WriteUninstaller "$INSTDIR\Uninstall.exe" SectionEnd SubSection /e "Group 1" SecDummy Section "Option 1" SecDummy1 SetOutPath "$INSTDIR" IfFileExists "$INSTDIR\uninstall.log" 0 +2 Rename "$INSTDIR\test.txt" "$INSTDIR\test.txt.old" ${File} "test.txt" ; CreateShortCut "$INSTDIR\test.lnk" "http://google.com/" SectionEnd Section -closelogfile FileClose $UninstLog SectionEnd ;-------------------------------- ;Descriptions ;Language strings LangString DESC_SecDummy ${LANG_ENGLISH} "A test English section." LangString DESC_SecDummy1 ${LANG_ENGLISH} "A test English subsection." LangString DESC_SecDummy ${LANG_FRENCH} "A test French section." LangString DESC_SecDummy1 ${LANG_FRENCH} "A test French subsection." LangString DESC_SecDummy ${LANG_SPANISH} "A test Spanish section." LangString DESC_SecDummy1 ${LANG_SPANISH} "A test Spanish subsection." ;Assign language strings to sections !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SecDummy} $(DESC_SecDummy) !insertmacro MUI_DESCRIPTION_TEXT ${SecDummy1} $(DESC_SecDummy1) !insertmacro MUI_FUNCTION_DESCRIPTION_END ;-------------------------------- ;Uninstaller Section Function un.TrimNewlines Exch $R0 Push $R1 Push $R2 StrCpy $R1 0 loop: IntOp $R1 $R1 - 1 StrCpy $R2 $R0 1 $R1 StrCmp $R2 "$\r" loop StrCmp $R2 "$\n" loop IntOp $R1 $R1 + 1 IntCmp $R1 0 no_trim_needed StrCpy $R0 $R0 $R1 no_trim_needed: Pop $R2 Pop $R1 Exch $R0 FunctionEnd SectionGroupEnd Section Uninstall IfFileExists "$INSTDIR\uninstall.log" +3 MessageBox MB_OK|MB_ICONSTOP "uninstall.log not found!$\r$\nUninstallation cannot be done!" Abort Push $R0 FileOpen $UninstLog "$INSTDIR\uninstall.log" r LoopRead: ClearErrors FileRead $UninstLog $R0 IfErrors LoopDone Push $R0 Call un.TrimNewLines Pop $R0 Delete $R0 Rename $R0.old $R0 Goto LoopRead LoopDone: FileClose $UninstLog Pop $R0 Call un.instmisc SectionEnd Function un.onInit !insertmacro MUI_UNGETLANGUAGE FunctionEnd function un.instmisc ; DeleteRegValue HKCU "Software\Valve\Steam\Apps\10" "LaunchOptions" ; DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" "DisplayName" ; DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" "Publisher" ; DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" "HelpLink" ; DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" "URLInfoAbout" ; DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" "DisplayVersion" ; DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" "LogFile" ; DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" "UninstallString" ; DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" "NoModify" ; DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" "NoRepair" ; DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" "InstallLocation" ; DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\test" DeleteRegKey HKCU "Software\test" Delete "$INSTDIR\Uninstall.exe" Delete "$INSTDIR\Uninstall.log" ; Delete "$SMPROGRAMS\test\*.*" RMDir "$INSTDIR" FunctionEnd