From 0a14115c94a98546be1c2528b9ccc32ce2a61e5a Mon Sep 17 00:00:00 2001
From: Tank_Master <tank.master@phoenixviewer.com>
Date: Sat, 14 Feb 2015 00:15:35 -0800
Subject: [PATCH] Rearrange the order of sections to better follow
 un/installation procedure

---
 .../installers/windows/installer_template.nsi | 1208 ++++++++---------
 1 file changed, 602 insertions(+), 606 deletions(-)

diff --git a/indra/newview/installers/windows/installer_template.nsi b/indra/newview/installers/windows/installer_template.nsi
index 73e5b8cf74a..36a8d7216bb 100755
--- a/indra/newview/installers/windows/installer_template.nsi
+++ b/indra/newview/installers/windows/installer_template.nsi
@@ -91,6 +91,7 @@ AutoCloseWindow true					# After all files install, close window
 
 InstallDir "$PROGRAMFILES\${INSTNAME}"
 InstallDirRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\${INSTNAME}" ""
+UninstallText $(UninstallTextMsg)
 DirText $(DirectoryChooseTitle) $(DirectoryChooseSetup)
 Page directory dirPre
 Page instfiles
@@ -117,34 +118,6 @@ Var DO_UNINSTALL_V2     # If non-null, path to a previous Viewer 2 installation
 !insertmacro GetOptions
 !include WinVer.nsh			# For OS and SP detection
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; After install completes, launch app
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function .onInstSuccess
-Call CheckWindowsServPack		# Warn if not on the latest SP before asking to launch.
-    Push $R0					# Option value, unused
-
-    StrCmp $SKIP_DIALOGS "true" label_launch 
-
-    ${GetOptions} $COMMANDLINE "/AUTOSTART" $R0
-    # If parameter was there (no error) just launch
-    # Otherwise ask
-    IfErrors label_ask_launch label_launch
-    
-label_ask_launch:
-    # Don't launch by default when silent
-    IfSilent label_no_launch
-	MessageBox MB_YESNO $(InstSuccesssQuestion) \
-        IDYES label_launch IDNO label_no_launch
-        
-label_launch:
-# Assumes SetOutPath $INSTDIR
-	Exec '"$INSTDIR\$INSTEXE" $SHORTCUT_LANG_PARAM'
-label_no_launch:
-	Pop $R0
-
-FunctionEnd
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Pre-directory page callback
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -155,96 +128,74 @@ Function dirPre
 FunctionEnd    
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Make sure this computer meets the minimum system requirements.
-;; Currently: Windows Vista SP2
+;; Prep Installer Section
+;;
+;; Note: to add new languages, add a language file include to the list 
+;; at the top of this file, add an entry to the menu and then add an 
+;; entry to the language ID selector below
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function CheckWindowsVersion
-  ${If} ${AtMostWin2003}
-    MessageBox MB_OK $(CheckWindowsVersionMB)
-    Quit
-  ${EndIf}
-
-  ${If} ${IsWinVista}
-  ${AndIfNot} ${IsServicePack} 2
-    MessageBox MB_OK $(CheckWindowsVersionMB)
-    Quit
-  ${EndIf}
+Function .onInit
+Call CheckCPUFlags							# Make sure we have SSE2 support
+Call CheckWindowsVersion					# Don't install On unsupported systems
+    Push $0
+    ${GetParameters} $COMMANDLINE			# Get our command line
 
-  ${If} ${IsWin2008}
-  ${AndIfNot} ${IsServicePack} 2
-    MessageBox MB_OK $(CheckWindowsVersionMB)
-    Quit
-  ${EndIf}
+    ${GetOptions} $COMMANDLINE "/SKIP_DIALOGS" $0   
+    IfErrors +2 0	# If error jump past setting SKIP_DIALOGS
+        StrCpy $SKIP_DIALOGS "true"
 
-FunctionEnd
+    ${GetOptions} $COMMANDLINE "/LANGID=" $0	# /LANGID=1033 implies US English
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Recommend Upgrading to Service Pack 1 for Windows 7, if not present
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function CheckWindowsServPack
-  ${If} ${IsWin7}
-  ${AndIfNot} ${IsServicePack} 1
-    MessageBox MB_OK $(CheckWindowsServPackMB)
-    DetailPrint $(UseLatestServPackDP)
-    Return
-  ${EndIf}
+# If no language (error), then proceed
+    IfErrors lbl_configure_default_lang
+# No error means we got a language, so use it
+    StrCpy $LANGUAGE $0
+    Goto lbl_return
 
-  ${If} ${IsWin2008R2}
-  ${AndIfNot} ${IsServicePack} 1
-    MessageBox MB_OK $(CheckWindowsServPackMB)
-    DetailPrint $(UseLatestServPackDP)
-    Return
-  ${EndIf}
+lbl_configure_default_lang:
+# If we currently have a version of SL installed, default to the language of that install
+# Otherwise don't change $LANGUAGE and it will default to the OS UI language.
+    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\${INSTNAME}" "InstallerLanguage"
+    IfErrors +2 0	# If error skip the copy instruction 
+	StrCpy $LANGUAGE $0
 
-FunctionEnd
+# For silent installs, no language prompt, use default
+    IfSilent lbl_return
+    StrCmp $SKIP_DIALOGS "true" lbl_return
+  
+lbl_build_menu:
+	Push ""
+# Use separate file so labels can be UTF-16 but we can still merge changes into this ASCII file. JC
+    !include "%%SOURCE%%\installers\windows\language_menu.nsi"
+    
+	Push A	# A means auto count languages for the auto count to work the first empty push (Push "") must remain
+	LangDLL::LangDialog $(InstallerLanguageTitle) $(SelectInstallerLanguage)
+	Pop $0
+	StrCmp $0 "cancel" 0 +2
+		Abort
+    StrCpy $LANGUAGE $0
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Make sure the user can install
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function CheckIfAdministrator
-    DetailPrint $(CheckAdministratorInstDP)
-    UserInfo::GetAccountType
-    Pop $R0
-    StrCmp $R0 "Admin" lbl_is_admin
-        MessageBox MB_OK $(CheckAdministratorInstMB)
-        Quit
-lbl_is_admin:
+# save language in registry		
+	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\${INSTNAME}" "InstallerLanguage" $LANGUAGE
+lbl_return:
+    Pop $0
     Return
 
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Make sure the user can uninstall
+;; Prep Uninstaller Section
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function un.CheckIfAdministrator
-    DetailPrint $(CheckAdministratorUnInstDP)
-    UserInfo::GetAccountType
-    Pop $R0
-    StrCmp $R0 "Admin" lbl_is_admin
-        MessageBox MB_OK $(CheckAdministratorUnInstMB)
-        Quit
-lbl_is_admin:
+Function un.onInit
+# Read language from registry and set for uninstaller. Key will be removed on successful uninstall
+	ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\${INSTNAME}" "InstallerLanguage"
+    IfErrors lbl_end
+	StrCpy $LANGUAGE $0
+lbl_end:
     Return
 
 FunctionEnd
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Checks to see if the current version has already been installed (according to the registry).
-;; If it has, allow user to bail out of install process.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function CheckIfAlreadyCurrent
-    Push $0
-    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG" "Version"
-    StrCmp $0 ${VERSION_LONG} 0 continue_install
-    StrCmp $SKIP_DIALOGS "true" continue_install
-    MessageBox MB_OKCANCEL $(CheckIfCurrentMB) /SD IDOK IDOK continue_install
-    Quit
-continue_install:
-    Pop $0
-    Return
-
-FunctionEnd
-	
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Checks for CPU valid (must have SSE2 support)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -262,333 +213,356 @@ Function CheckCPUFlags
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Close the program, if running. Modifies no variables.
-;; Allows user to bail out of install process.
+;; Make sure this computer meets the minimum system requirements.
+;; Currently: Windows Vista SP2
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function CloseSecondLife
-  Push $0
-  FindWindow $0 "Second Life" ""
-  IntCmp $0 0 DONE
-  
-  StrCmp $SKIP_DIALOGS "true" CLOSE
-    MessageBox MB_OKCANCEL $(CloseSecondLifeInstMB) IDOK CLOSE IDCANCEL CANCEL_INSTALL
-
-  CANCEL_INSTALL:
+Function CheckWindowsVersion
+  ${If} ${AtMostWin2003}
+    MessageBox MB_OK $(CheckWindowsVersionMB)
     Quit
+  ${EndIf}
 
-  CLOSE:
-    DetailPrint $(CloseSecondLifeInstDP)
-    SendMessage $0 16 0 0
-
-  LOOP:
-	  FindWindow $0 "Second Life" ""
-	  IntCmp $0 0 DONE
-	  Sleep 500
-	  Goto LOOP
+  ${If} ${IsWinVista}
+  ${AndIfNot} ${IsServicePack} 2
+    MessageBox MB_OK $(CheckWindowsVersionMB)
+    Quit
+  ${EndIf}
 
-  DONE:
-    Pop $0
-    Return
+  ${If} ${IsWin2008}
+  ${AndIfNot} ${IsServicePack} 2
+    MessageBox MB_OK $(CheckWindowsVersionMB)
+    Quit
+  ${EndIf}
 
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Test our connection to secondlife.com
-;; Also allows us to count attempted installs by examining web logs.
-;; *TODO: Return current SL version info and have installer check
-;; if it is up to date.
+;; Install Section
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function CheckNetworkConnection
-    Push $0
-    Push $1
-    Push $2	# Option value for GetOptions
-    DetailPrint $(CheckNetworkConnectionDP)
-# Look for a tag value from the stub installer, used for statistics to correlate installs.
-# Default to "" if not found on command line.
-    StrCpy $2 ""
-    ${GetOptions} $COMMANDLINE "/STUBTAG=" $2
-    GetTempFileName $0
-    !define HTTP_TIMEOUT 5000		# milliseconds
-# Don't show secondary progress bar, this will be quick.
-    NSISdl::download_quiet \
-        /TIMEOUT=${HTTP_TIMEOUT} \
-        "http://install.secondlife.com/check/?stubtag=$2&version=${VERSION_LONG}" \
-        $0
-    Pop $1		# Return value, either "success", "cancel" or an error message
-    ; MessageBox MB_OK "Download result: $1"
-    ; Result ignored for now
-	; StrCmp $1 "success" +2
-	;	DetailPrint "Connection failed: $1"
-    Delete $0	# temporary file
-    Pop $2
-    Pop $1
-    Pop $0
-    Return
+Section ""
 
-FunctionEnd
+SetShellVarContext all			# Install for all users (if you change this, change it in the uninstall as well)
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Function CheckOldExeName
-;; Viewer versions < 3.6.12 used the name 'SecondLife.exe'
-;; If that name is found in the install folder, delete it to invalidate any
-;;  old shortcuts to it that may be in non-standard locations. This is to prevent
-;;  the userpotentially getting caught in an infinite update loop). See MAINT-3575
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+# Start with some default values.
+StrCpy $INSTPROG "${INSTNAME}"
+StrCpy $INSTEXE "${INSTEXE}"
+StrCpy $INSTSHORTCUT "${SHORTCUT}"
 
-Function CheckOldExeName
-  IfFileExists "$INSTDIR\SecondLife.exe" CHECKOLDEXE_FOUND CHECKOLDEXE_DONE
+Call CheckIfAdministrator		# Make sure the user can install/uninstall
+Call CheckIfAlreadyCurrent		# Make sure this version is not already installed
+Call CloseSecondLife			# Make sure Second Life not currently running
+Call CheckNetworkConnection		# Ping secondlife.com
+Call CheckWillUninstallV2		# Check if SecondLife is already installed
+Call CheckOldExeName            # Clean up a previous version of the exeicutable
 
-CHECKOLDEXE_FOUND:
-  Delete "$INSTDIR\SecondLife.exe"
-CHECKOLDEXE_DONE:
+StrCmp $DO_UNINSTALL_V2 "" PRESERVE_DONE
+  Call PreserveUserFiles
+PRESERVE_DONE:
 
-FunctionEnd
+# Don't remove cache files during a regular install,
+# removing the inventory cache on upgrades results in lots of damage to the servers.
+;Call RemoveCacheFiles			# Installing over removes potentially corrupted VFS and cache files.
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Function CheckWillUninstallV2               
-;;
-;; If called through auto-update, need to uninstall any existing V2 installation.
-;; Don't want to end up with SecondLifeViewer2 and SecondLifeViewer installations
-;;  existing side by side with no indication on which to use.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function CheckWillUninstallV2
+# Need to clean out shader files from previous installs to fix DEV-5663
+Call RemoveOldShaders
 
-  StrCpy $DO_UNINSTALL_V2 ""
+# Need to clean out old XUI files that predate skinning
+Call RemoveOldXUI
 
-  StrCmp $SKIP_DIALOGS "true" 0 CHECKV2_DONE
-  StrCmp $INSTDIR "$PROGRAMFILES\SecondLifeViewer2" CHECKV2_DONE	# Don't uninstall our own install dir.
-  IfFileExists "$PROGRAMFILES\SecondLifeViewer2\uninst.exe" CHECKV2_FOUND CHECKV2_DONE
+# Clear out old releasenotes.txt files. These are now on the public wiki.
+Call RemoveOldReleaseNotes
 
-CHECKV2_FOUND:
-  StrCpy $DO_UNINSTALL_V2 "true"
+# This placeholder is replaced by the complete list of all the files in the installer, by viewer_manifest.py
+%%INSTALL_FILES%%
 
-CHECKV2_DONE:
+# Pass the installer's language to the client to use as a default
+StrCpy $SHORTCUT_LANG_PARAM "--set InstallLanguage $(LanguageCode)"
 
-FunctionEnd
+# Shortcuts in start menu
+CreateDirectory	"$SMPROGRAMS\$INSTSHORTCUT"
+SetOutPath "$INSTDIR"
+CreateShortCut	"$SMPROGRAMS\$INSTSHORTCUT\$INSTSHORTCUT.lnk" \
+				"$INSTDIR\$INSTEXE" "$SHORTCUT_LANG_PARAM"
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Save user files to temp location
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function PreserveUserFiles
 
-Push $0
-Push $1
-Push $2
+WriteINIStr		"$SMPROGRAMS\$INSTSHORTCUT\SL Create Account.url" \
+				"InternetShortcut" "URL" \
+				"http://join.secondlife.com/"
+WriteINIStr		"$SMPROGRAMS\$INSTSHORTCUT\SL Your Account.url" \
+				"InternetShortcut" "URL" \
+				"http://www.secondlife.com/account/"
+WriteINIStr		"$SMPROGRAMS\$INSTSHORTCUT\SL Scripting Language Help.url" \
+				"InternetShortcut" "URL" \
+                "http://wiki.secondlife.com/wiki/LSL_Portal"
+CreateShortCut	"$SMPROGRAMS\$INSTSHORTCUT\Uninstall $INSTSHORTCUT.lnk" \
+				'"$INSTDIR\uninst.exe"' ''
 
-    RMDir /r "$TEMP\SecondLifeSettingsBackup"		# Clear out any old data that might be there
-    CreateDirectory "$TEMP\SecondLifeSettingsBackup"
-    StrCpy $0 0		# Index number used to iterate via EnumRegKey
+# Other shortcuts
+SetOutPath "$INSTDIR"
+CreateShortCut "$DESKTOP\$INSTSHORTCUT.lnk" \
+        "$INSTDIR\$INSTEXE" "$SHORTCUT_LANG_PARAM"
+CreateShortCut "$INSTDIR\$INSTSHORTCUT.lnk" \
+        "$INSTDIR\$INSTEXE" "$SHORTCUT_LANG_PARAM"
+CreateShortCut "$INSTDIR\Uninstall $INSTSHORTCUT.lnk" \
+				'"$INSTDIR\uninst.exe"' ''
 
-  LOOP:
-    EnumRegKey $1 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $0
-    StrCmp $1 "" DONE               # no more users
+# Write registry
+WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG" "" "$INSTDIR"
+WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG" "Version" "${VERSION_LONG}"
+WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG" "Shortcut" "$INSTSHORTCUT"
+WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG" "Exe" "$INSTEXE"
+WriteRegStr HKEY_LOCAL_MACHINE "Software\Microsoft\Windows\CurrentVersion\Uninstall\$INSTPROG" "DisplayName" "$INSTPROG (remove only)"
+WriteRegStr HKEY_LOCAL_MACHINE "Software\Microsoft\Windows\CurrentVersion\Uninstall\$INSTPROG" "UninstallString" '"$INSTDIR\uninst.exe"'
 
-    ReadRegStr $2 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$1" "ProfileImagePath" 
-    StrCmp $2 "" CONTINUE 0         # "ProfileImagePath" value is missing
+# Write URL registry info
+WriteRegStr HKEY_CLASSES_ROOT "${URLNAME}" "(default)" "URL:Second Life"
+WriteRegStr HKEY_CLASSES_ROOT "${URLNAME}" "URL Protocol" ""
+WriteRegStr HKEY_CLASSES_ROOT "${URLNAME}\DefaultIcon" "" '"$INSTDIR\$INSTEXE"'
 
-# Required since ProfileImagePath is of type REG_EXPAND_SZ
-    ExpandEnvStrings $2 $2
+# URL param must be last item passed to viewer, it ignores subsequent params to avoid parameter injection attacks.
+WriteRegExpandStr HKEY_CLASSES_ROOT "${URLNAME}\shell\open\command" "" '"$INSTDIR\$INSTEXE" -url "%1"'
+WriteRegStr HKEY_CLASSES_ROOT "x-grid-location-info"(default)" "URL:Second Life"
+WriteRegStr HKEY_CLASSES_ROOT "x-grid-location-info" "URL Protocol" ""
+WriteRegStr HKEY_CLASSES_ROOT "x-grid-location-info\DefaultIcon" "" '"$INSTDIR\$INSTEXE"'
 
-    CreateDirectory "$TEMP\SecondLifeSettingsBackup\$0"
-    CopyFiles /SILENT "$2\Application Data\SecondLife\*" "$TEMP\SecondLifeSettingsBackup\$0"
+# URL param must be last item passed to viewer, it ignores subsequent params to avoid parameter injection attacks.
+WriteRegExpandStr HKEY_CLASSES_ROOT "x-grid-location-info\shell\open\command" "" '"$INSTDIR\$INSTEXE" -url "%1"'
 
-  CONTINUE:
-    IntOp $0 $0 + 1
-    Goto LOOP
-  DONE:
+# Write out uninstaller
+WriteUninstaller "$INSTDIR\uninst.exe"
 
-Pop $2
-Pop $1
-Pop $0
+# Uninstall existing "Second Life Viewer 2" install if needed.
+StrCmp $DO_UNINSTALL_V2 "" REMOVE_SLV2_DONE
+  ExecWait '"$PROGRAMFILES\SecondLifeViewer2\uninst.exe" /S _?=$PROGRAMFILES\SecondLifeViewer2'
+  Delete "$PROGRAMFILES\SecondLifeViewer2\uninst.exe"	# with _? option above, uninst.exe will be left behind.
+  RMDir "$PROGRAMFILES\SecondLifeViewer2"	# will remove only if empty.
 
-# Copy files in Documents and Settings\All Users\SecondLife
-Push $0
-    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common AppData"
-    StrCmp $0 "" +2
-    CreateDirectory "$TEMP\SecondLifeSettingsBackup\AllUsers\"
-    CopyFiles /SILENT "$2\Application Data\SecondLife\*" "$TEMP\SecondLifeSettingsBackup\AllUsers\"
-Pop $0
+  Call RestoreUserFiles
+  Call RemoveTempUserFiles
+REMOVE_SLV2_DONE:
 
-FunctionEnd
+SectionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Restore user files from temp location
+;; Uninstall Section
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function RestoreUserFiles
+Section Uninstall
 
-Push $0
-Push $1
-Push $2
+# Start with some default values.
+StrCpy $INSTPROG "${INSTNAME}"
+StrCpy $INSTEXE "${INSTEXE}"
+StrCpy $INSTSHORTCUT "${SHORTCUT}"
 
-    StrCpy $0 0		# Index number used to iterate via EnumRegKey
+# Make sure the user can install/uninstall
+Call un.CheckIfAdministrator		
 
-  LOOP:
-    EnumRegKey $1 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $0
-    StrCmp $1 "" DONE               # no more users
+# Uninstall for all users (if you change this, change it in the install as well)
+SetShellVarContext all			
 
-    ReadRegStr $2 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$1" "ProfileImagePath" 
-    StrCmp $2 "" CONTINUE 0         # "ProfileImagePath" value is missing
+# Make sure we're not running
+Call un.CloseSecondLife
 
-# Required since ProfileImagePath is of type REG_EXPAND_SZ
-    ExpandEnvStrings $2 $2
+# Clean up registry keys and subkeys (these should all be !defines somewhere)
+DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG"
+DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$INSTPROG"
 
-    CreateDirectory "$2\Application Data\SecondLife\"
-    CopyFiles /SILENT "$TEMP\SecondLifeSettingsBackup\$0\*" "$2\Application Data\SecondLife\" 
+# Clean up shortcuts
+Delete "$SMPROGRAMS\$INSTSHORTCUT\*.*"
+RMDir  "$SMPROGRAMS\$INSTSHORTCUT"
 
-  CONTINUE:
-    IntOp $0 $0 + 1
-    Goto LOOP
-  DONE:
+Delete "$DESKTOP\$INSTSHORTCUT.lnk"
+Delete "$INSTDIR\$INSTSHORTCUT.lnk"
+Delete "$INSTDIR\Uninstall $INSTSHORTCUT.lnk"
 
-Pop $2
-Pop $1
-Pop $0
+# Clean up cache and log files, but leave them in-place for non AGNI installs.
 
-# Copy files in Documents and Settings\All Users\SecondLife
-Push $0
-    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common AppData"
-    StrCmp $0 "" +2
-    CreateDirectory "$2\Application Data\SecondLife\"
-    CopyFiles /SILENT "$TEMP\SecondLifeSettingsBackup\AllUsers\*" "$2\Application Data\SecondLife\" 
-Pop $0
+!ifdef UNINSTALL_SETTINGS
+Call un.DocumentsAndSettingsFolder
+!endif
 
-FunctionEnd
+# Remove stored password on uninstall
+Call un.RemovePassword
+
+Call un.ProgramFiles
+
+SectionEnd 				
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Remove temp directories
+;; Make sure the user can install
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function RemoveTempUserFiles
+Function CheckIfAdministrator
+    DetailPrint $(CheckAdministratorInstDP)
+    UserInfo::GetAccountType
+    Pop $R0
+    StrCmp $R0 "Admin" lbl_is_admin
+        MessageBox MB_OK $(CheckAdministratorInstMB)
+        Quit
+lbl_is_admin:
+    Return
 
-Push $0
-Push $1
-Push $2
+FunctionEnd
 
-    StrCpy $0 0		# Index number used to iterate via EnumRegKey
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Make sure the user can uninstall
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+Function un.CheckIfAdministrator
+    DetailPrint $(CheckAdministratorUnInstDP)
+    UserInfo::GetAccountType
+    Pop $R0
+    StrCmp $R0 "Admin" lbl_is_admin
+        MessageBox MB_OK $(CheckAdministratorUnInstMB)
+        Quit
+lbl_is_admin:
+    Return
 
-  LOOP:
-    EnumRegKey $1 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $0
-    StrCmp $1 "" DONE               # no more users
+FunctionEnd
 
-    ReadRegStr $2 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$1" "ProfileImagePath" 
-    StrCmp $2 "" CONTINUE 0         # "ProfileImagePath" value is missing
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Checks to see if the current version has already been installed (according to the registry).
+;; If it has, allow user to bail out of install process.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+Function CheckIfAlreadyCurrent
+    Push $0
+    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG" "Version"
+    StrCmp $0 ${VERSION_LONG} 0 continue_install
+    StrCmp $SKIP_DIALOGS "true" continue_install
+    MessageBox MB_OKCANCEL $(CheckIfCurrentMB) /SD IDOK IDOK continue_install
+    Quit
+continue_install:
+    Pop $0
+    Return
 
-# Required since ProfileImagePath is of type REG_EXPAND_SZ
-    ExpandEnvStrings $2 $2
+FunctionEnd
+	
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Function CheckWillUninstallV2               
+;;
+;; If called through auto-update, need to uninstall any existing V2 installation.
+;; Don't want to end up with SecondLifeViewer2 and SecondLifeViewer installations
+;;  existing side by side with no indication on which to use.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+Function CheckWillUninstallV2
 
-    RMDir /r "$TEMP\SecondLifeSettingsBackup\$0\*"
+  StrCpy $DO_UNINSTALL_V2 ""
 
-  CONTINUE:
-    IntOp $0 $0 + 1
-    Goto LOOP
-  DONE:
+  StrCmp $SKIP_DIALOGS "true" 0 CHECKV2_DONE
+  StrCmp $INSTDIR "$PROGRAMFILES\SecondLifeViewer2" CHECKV2_DONE	# Don't uninstall our own install dir.
+  IfFileExists "$PROGRAMFILES\SecondLifeViewer2\uninst.exe" CHECKV2_FOUND CHECKV2_DONE
 
-Pop $2
-Pop $1
-Pop $0
+CHECKV2_FOUND:
+  StrCpy $DO_UNINSTALL_V2 "true"
 
-# Copy files in Documents and Settings\All Users\SecondLife
-Push $0
-    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common AppData"
-    StrCmp $0 "" +2
-    RMDir /r "$TEMP\SecondLifeSettingsBackup\AllUsers\*"
-Pop $0
+CHECKV2_DONE:
 
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Clobber user files - TEST ONLY
-;; This is here for testing, DO NOT USE UNLESS YOU KNOW WHAT YOU ARE TESTING FOR!
+;; Close the program, if running. Modifies no variables.
+;; Allows user to bail out of install process.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;Function ClobberUserFilesTESTONLY
+Function CloseSecondLife
+  Push $0
+  FindWindow $0 "Second Life" ""
+  IntCmp $0 0 DONE
+  
+  StrCmp $SKIP_DIALOGS "true" CLOSE
+    MessageBox MB_OKCANCEL $(CloseSecondLifeInstMB) IDOK CLOSE IDCANCEL CANCEL_INSTALL
 
-;Push $0
-;Push $1
-;Push $2
-;
-;    StrCpy $0 0	# Index number used to iterate via EnumRegKey
-;
-;  LOOP:
-;    EnumRegKey $1 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $0
-;    StrCmp $1 "" DONE               # no more users
-;
-;    ReadRegStr $2 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$1" "ProfileImagePath" 
-;    StrCmp $2 "" CONTINUE 0         # "ProfileImagePath" value is missing
-;
-;# Required since ProfileImagePath is of type REG_EXPAND_SZ
-;    ExpandEnvStrings $2 $2
-;
-;    RMDir /r "$2\Application Data\SecondLife\"
-;
-;  CONTINUE:
-;    IntOp $0 $0 + 1
-;    Goto LOOP
-;  DONE:
-;
-;Pop $2
-;Pop $1
-;Pop $0
-;
-;# Copy files in Documents and Settings\All Users\SecondLife
-;Push $0
-;    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common AppData"
-;    StrCmp $0 "" +2
-;    RMDir /r "$2\Application Data\SecondLife\"
-;Pop $0
-;
-;FunctionEnd
+  CANCEL_INSTALL:
+    Quit
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Delete the installed shader files
-;; Since shaders are in active development, we'll likely need to shuffle them
-;;  around a bit from build to build.  This ensures that shaders that were removed
-;;  or renamed don't get left behind in the install directory.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function RemoveOldShaders
+  CLOSE:
+    DetailPrint $(CloseSecondLifeInstDP)
+    SendMessage $0 16 0 0
 
-;; Remove old shader files first so fallbacks will work. see DEV-5663
-RMDir /r "$INSTDIR\app_settings\shaders\*"
+  LOOP:
+	  FindWindow $0 "Second Life" ""
+	  IntCmp $0 0 DONE
+	  Sleep 500
+	  Goto LOOP
+
+  DONE:
+    Pop $0
+    Return
 
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Delete the installed XUI files
-;; We've changed the directory hierarchy for skins, putting all XUI and texture
-;; files under a specific skin directory, i.e. skins/default/xui/en-us as opposed
-;; to skins/xui/en-us.  Need to clean up the old path when upgrading.
+;; Close the program, if running. Modifies no variables.
+;; Allows user to bail out of uninstall process.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function RemoveOldXUI
+Function un.CloseSecondLife
+  Push $0
+  FindWindow $0 "Second Life" ""
+  IntCmp $0 0 DONE
+  MessageBox MB_OKCANCEL $(CloseSecondLifeUnInstMB) IDOK CLOSE IDCANCEL CANCEL_UNINSTALL
 
-RmDir /r "$INSTDIR\skins\html"
-RmDir /r "$INSTDIR\skins\xui"
-RmDir /r "$INSTDIR\skins\textures"
-Delete "$INSTDIR\skins\*.txt"
+  CANCEL_UNINSTALL:
+    Quit
+
+  CLOSE:
+    DetailPrint $(CloseSecondLifeUnInstDP)
+    SendMessage $0 16 0 0
+
+  LOOP:
+	  FindWindow $0 "Second Life" ""
+	  IntCmp $0 0 DONE
+	  Sleep 500
+	  Goto LOOP
+
+  DONE:
+    Pop $0
+    Return
 
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Remove any release notes files.
-;; We are no longer including release notes with the viewer, so remove them.
+;; Test our connection to secondlife.com
+;; Also allows us to count attempted installs by examining web logs.
+;; *TODO: Return current SL version info and have installer check
+;; if it is up to date.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function RemoveOldReleaseNotes
-
-Delete "$SMPROGRAMS\$INSTSHORTCUT\SL Release Notes.lnk"
-Delete "$INSTDIR\releasenotes.txt"
+Function CheckNetworkConnection
+    Push $0
+    Push $1
+    Push $2	# Option value for GetOptions
+    DetailPrint $(CheckNetworkConnectionDP)
+# Look for a tag value from the stub installer, used for statistics to correlate installs.
+# Default to "" if not found on command line.
+    StrCpy $2 ""
+    ${GetOptions} $COMMANDLINE "/STUBTAG=" $2
+    GetTempFileName $0
+    !define HTTP_TIMEOUT 5000		# milliseconds
+# Don't show secondary progress bar, this will be quick.
+    NSISdl::download_quiet \
+        /TIMEOUT=${HTTP_TIMEOUT} \
+        "http://install.secondlife.com/check/?stubtag=$2&version=${VERSION_LONG}" \
+        $0
+    Pop $1		# Return value, either "success", "cancel" or an error message
+    ; MessageBox MB_OK "Download result: $1"
+    ; Result ignored for now
+	; StrCmp $1 "success" +2
+	;	DetailPrint "Connection failed: $1"
+    Delete $0	# temporary file
+    Pop $2
+    Pop $1
+    Pop $0
+    Return
 
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Delete files in \Users\<User>\AppData\Roaming\SecondLife
+;; Save user files to temp location
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function un.DocumentsAndSettingsFolder
+Function PreserveUserFiles
 
-# Delete files in \Users\<User>\AppData\Roaming\SecondLife
 Push $0
 Push $1
 Push $2
 
-  DetailPrint "Deleting Second Life files"
-
-  StrCpy $0 0	# Index number used to iterate via EnumRegKey
+    RMDir /r "$TEMP\SecondLifeSettingsBackup"		# Clear out any old data that might be there
+    CreateDirectory "$TEMP\SecondLifeSettingsBackup"
+    StrCpy $0 0		# Index number used to iterate via EnumRegKey
 
   LOOP:
     EnumRegKey $1 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $0
@@ -600,15 +574,8 @@ Push $2
 # Required since ProfileImagePath is of type REG_EXPAND_SZ
     ExpandEnvStrings $2 $2
 
-# Remove all settings files but leave any other .txt files to preserve the chat logs
-;    RMDir /r "$2\Application Data\SecondLife\logs"
-    RMDir /r "$2\Application Data\SecondLife\browser_profile"
-    RMDir /r "$2\Application Data\SecondLife\user_settings"
-    Delete  "$2\Application Data\SecondLife\*.xml"
-    Delete  "$2\Application Data\SecondLife\*.bmp"
-    Delete  "$2\Application Data\SecondLife\search_history.txt"
-    Delete  "$2\Application Data\SecondLife\plugin_cookies.txt"
-    Delete  "$2\Application Data\SecondLife\typed_locations.txt"
+    CreateDirectory "$TEMP\SecondLifeSettingsBackup\$0"
+    CopyFiles /SILENT "$2\Application Data\SecondLife\*" "$TEMP\SecondLifeSettingsBackup\$0"
 
   CONTINUE:
     IntOp $0 $0 + 1
@@ -619,344 +586,373 @@ Pop $2
 Pop $1
 Pop $0
 
-# Delete files in Program Data folder
+# Copy files in Documents and Settings\All Users\SecondLife
 Push $0
-  ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common AppData"
-  StrCmp $0 "" +2
-  RMDir /r "$0\SecondLife"
+    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common AppData"
+    StrCmp $0 "" +2
+    CreateDirectory "$TEMP\SecondLifeSettingsBackup\AllUsers\"
+    CopyFiles /SILENT "$2\Application Data\SecondLife\*" "$TEMP\SecondLifeSettingsBackup\AllUsers\"
 Pop $0
 
-# Delete files in C:\Windows\Application Data\SecondLife
-# If the user is running on a pre-NT system, Application Data lives here instead of
-# in Documents and Settings.
-RMDir /r "$WINDIR\Application Data\SecondLife"
-
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Close the program, if running. Modifies no variables.
-;; Allows user to bail out of uninstall process.
+;; Restore user files from temp location
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function un.CloseSecondLife
-  Push $0
-  FindWindow $0 "Second Life" ""
-  IntCmp $0 0 DONE
-  MessageBox MB_OKCANCEL $(CloseSecondLifeUnInstMB) IDOK CLOSE IDCANCEL CANCEL_UNINSTALL
+Function RestoreUserFiles
 
-  CANCEL_UNINSTALL:
-    Quit
+Push $0
+Push $1
+Push $2
 
-  CLOSE:
-    DetailPrint $(CloseSecondLifeUnInstDP)
-    SendMessage $0 16 0 0
+    StrCpy $0 0		# Index number used to iterate via EnumRegKey
 
   LOOP:
-	  FindWindow $0 "Second Life" ""
-	  IntCmp $0 0 DONE
-	  Sleep 500
-	  Goto LOOP
+    EnumRegKey $1 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $0
+    StrCmp $1 "" DONE               # no more users
+
+    ReadRegStr $2 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$1" "ProfileImagePath" 
+    StrCmp $2 "" CONTINUE 0         # "ProfileImagePath" value is missing
+
+# Required since ProfileImagePath is of type REG_EXPAND_SZ
+    ExpandEnvStrings $2 $2
+
+    CreateDirectory "$2\Application Data\SecondLife\"
+    CopyFiles /SILENT "$TEMP\SecondLifeSettingsBackup\$0\*" "$2\Application Data\SecondLife\" 
 
+  CONTINUE:
+    IntOp $0 $0 + 1
+    Goto LOOP
   DONE:
-    Pop $0
-    Return
+
+Pop $2
+Pop $1
+Pop $0
+
+# Copy files in Documents and Settings\All Users\SecondLife
+Push $0
+    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common AppData"
+    StrCmp $0 "" +2
+    CreateDirectory "$2\Application Data\SecondLife\"
+    CopyFiles /SILENT "$TEMP\SecondLifeSettingsBackup\AllUsers\*" "$2\Application Data\SecondLife\" 
+Pop $0
 
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Delete the stored password for the current Windows user
-;; DEV-10821 -- Unauthorised user can gain access to an SL account after a real user has uninstalled
+;; Remove temp directories
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function un.RemovePassword
+Function RemoveTempUserFiles
 
-DetailPrint "Removing Second Life password"
+Push $0
+Push $1
+Push $2
 
-SetShellVarContext current
-Delete "$APPDATA\SecondLife\user_settings\password.dat"
-SetShellVarContext all
+    StrCpy $0 0		# Index number used to iterate via EnumRegKey
 
-FunctionEnd
+  LOOP:
+    EnumRegKey $1 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $0
+    StrCmp $1 "" DONE               # no more users
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Delete the installed files
-;; This deletes the uninstall executable, but it works because it is copied to temp directory before running
-;;
-;; Note:  You must list all files here, because we only want to delete our files,
-;; not things users left in the application directories.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function un.ProgramFiles
+    ReadRegStr $2 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$1" "ProfileImagePath" 
+    StrCmp $2 "" CONTINUE 0         # "ProfileImagePath" value is missing
 
-# Remove mozilla file first so recursive directory deletion doesn't get hung up
-Delete "$INSTDIR\app_settings\mozilla\components"
+# Required since ProfileImagePath is of type REG_EXPAND_SZ
+    ExpandEnvStrings $2 $2
 
-# This placeholder is replaced by the complete list of files to uninstall by viewer_manifest.py
-%%DELETE_FILES%%
+    RMDir /r "$TEMP\SecondLifeSettingsBackup\$0\*"
 
-# Optional/obsolete files.  Delete won't fail if they don't exist.
-Delete "$INSTDIR\dronesettings.ini"
-Delete "$INSTDIR\message_template.msg"
-Delete "$INSTDIR\newview.pdb"
-Delete "$INSTDIR\newview.map"
-Delete "$INSTDIR\SecondLife.pdb"
-Delete "$INSTDIR\SecondLife.map"
-Delete "$INSTDIR\comm.dat"
-Delete "$INSTDIR\*.glsl"
-Delete "$INSTDIR\motions\*.lla"
-Delete "$INSTDIR\trial\*.html"
-Delete "$INSTDIR\newview.exe"
-Delete "$INSTDIR\SecondLife.exe"
+  CONTINUE:
+    IntOp $0 $0 + 1
+    Goto LOOP
+  DONE:
 
-# MAINT-3099 workaround - prevent these log files, if present, from causing a user alert
-Delete "$INSTDIR\VivoxVoiceService-*.log"
+Pop $2
+Pop $1
+Pop $0
 
-# Remove entire help directory
-Delete "$INSTDIR\help\Advanced\*"
-RMDir  "$INSTDIR\help\Advanced"
-Delete "$INSTDIR\help\basics\*"
-RMDir  "$INSTDIR\help\basics"
-Delete "$INSTDIR\help\Concepts\*"
-RMDir  "$INSTDIR\help\Concepts"
-Delete "$INSTDIR\help\welcome\*"
-RMDir  "$INSTDIR\help\welcome"
-Delete "$INSTDIR\help\*"
-RMDir  "$INSTDIR\help"
+# Copy files in Documents and Settings\All Users\SecondLife
+Push $0
+    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common AppData"
+    StrCmp $0 "" +2
+    RMDir /r "$TEMP\SecondLifeSettingsBackup\AllUsers\*"
+Pop $0
 
-Delete "$INSTDIR\uninst.exe"
-RMDir "$INSTDIR"
+FunctionEnd
 
-IfFileExists "$INSTDIR" FOLDERFOUND NOFOLDER
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Function CheckOldExeName
+;; Viewer versions < 3.6.12 used the name 'SecondLife.exe'
+;; If that name is found in the install folder, delete it to invalidate any
+;;  old shortcuts to it that may be in non-standard locations. This is to prevent
+;;  the userpotentially getting caught in an infinite update loop). See MAINT-3575
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-FOLDERFOUND:
-# Silent uninstall always removes all files (/SD IDYES)
-  MessageBox MB_YESNO $(DeleteProgramFilesMB) /SD IDYES IDNO NOFOLDER
-  RMDir /r "$INSTDIR"
+Function CheckOldExeName
+  IfFileExists "$INSTDIR\SecondLife.exe" CHECKOLDEXE_FOUND CHECKOLDEXE_DONE
 
-NOFOLDER:
+CHECKOLDEXE_FOUND:
+  Delete "$INSTDIR\SecondLife.exe"
+CHECKOLDEXE_DONE:
 
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Uninstall settings
+;; Delete the installed shader files
+;; Since shaders are in active development, we'll likely need to shuffle them
+;;  around a bit from build to build.  This ensures that shaders that were removed
+;;  or renamed don't get left behind in the install directory.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-UninstallText $(UninstallTextMsg)
+Function RemoveOldShaders
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Uninstall Section
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Section Uninstall
+;; Remove old shader files first so fallbacks will work. see DEV-5663
+RMDir /r "$INSTDIR\app_settings\shaders\*"
 
-# Start with some default values.
-StrCpy $INSTPROG "${INSTNAME}"
-StrCpy $INSTEXE "${INSTEXE}"
-StrCpy $INSTSHORTCUT "${SHORTCUT}"
+FunctionEnd
 
-# Make sure the user can install/uninstall
-Call un.CheckIfAdministrator		
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Delete the installed XUI files
+;; We've changed the directory hierarchy for skins, putting all XUI and texture
+;; files under a specific skin directory, i.e. skins/default/xui/en-us as opposed
+;; to skins/xui/en-us.  Need to clean up the old path when upgrading.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+Function RemoveOldXUI
 
-# uninstall for all users (if you change this, change it in the install as well)
-SetShellVarContext all			
+RmDir /r "$INSTDIR\skins\html"
+RmDir /r "$INSTDIR\skins\xui"
+RmDir /r "$INSTDIR\skins\textures"
+Delete "$INSTDIR\skins\*.txt"
 
-# Make sure we're not running
-Call un.CloseSecondLife
+FunctionEnd
 
-# Clean up registry keys and subkeys (these should all be !defines somewhere)
-DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG"
-DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$INSTPROG"
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Remove any release notes files.
+;; We are no longer including release notes with the viewer, so remove them.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+Function RemoveOldReleaseNotes
 
-# Clean up shortcuts
-Delete "$SMPROGRAMS\$INSTSHORTCUT\*.*"
-RMDir  "$SMPROGRAMS\$INSTSHORTCUT"
+Delete "$SMPROGRAMS\$INSTSHORTCUT\SL Release Notes.lnk"
+Delete "$INSTDIR\releasenotes.txt"
 
-Delete "$DESKTOP\$INSTSHORTCUT.lnk"
-Delete "$INSTDIR\$INSTSHORTCUT.lnk"
-Delete "$INSTDIR\Uninstall $INSTSHORTCUT.lnk"
+FunctionEnd
 
-# Clean up cache and log files, but leave them in-place for non AGNI installs.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Delete files in \Users\<User>\AppData\Roaming\SecondLife
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+Function un.DocumentsAndSettingsFolder
 
-!ifdef UNINSTALL_SETTINGS
-Call un.DocumentsAndSettingsFolder
-!endif
+# Delete files in \Users\<User>\AppData\Roaming\SecondLife
+Push $0
+Push $1
+Push $2
 
-# Remove stored password on uninstall
-Call un.RemovePassword
+  DetailPrint "Deleting Second Life files"
 
-Call un.ProgramFiles
+  StrCpy $0 0	# Index number used to iterate via EnumRegKey
 
-SectionEnd 				
+  LOOP:
+    EnumRegKey $1 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $0
+    StrCmp $1 "" DONE               # no more users
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Prep Installer Section
-;;
-;; Note: to add new languages, add a language file include to the list 
-;; at the top of this file, add an entry to the menu and then add an 
-;; entry to the language ID selector below
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function .onInit
-Call CheckWindowsVersion					# Don't install On unsupported systems
-    Push $0
-    ${GetParameters} $COMMANDLINE			# Get our command line
+    ReadRegStr $2 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$1" "ProfileImagePath" 
+    StrCmp $2 "" CONTINUE 0         # "ProfileImagePath" value is missing
 
-    ${GetOptions} $COMMANDLINE "/SKIP_DIALOGS" $0   
-    IfErrors +2 0	# If error jump past setting SKIP_DIALOGS
-        StrCpy $SKIP_DIALOGS "true"
+# Required since ProfileImagePath is of type REG_EXPAND_SZ
+    ExpandEnvStrings $2 $2
 
-    ${GetOptions} $COMMANDLINE "/LANGID=" $0	# /LANGID=1033 implies US English
+# Remove all settings files but leave any other .txt files to preserve the chat logs
+;    RMDir /r "$2\Application Data\SecondLife\logs"
+    RMDir /r "$2\Application Data\SecondLife\browser_profile"
+    RMDir /r "$2\Application Data\SecondLife\user_settings"
+    Delete  "$2\Application Data\SecondLife\*.xml"
+    Delete  "$2\Application Data\SecondLife\*.bmp"
+    Delete  "$2\Application Data\SecondLife\search_history.txt"
+    Delete  "$2\Application Data\SecondLife\plugin_cookies.txt"
+    Delete  "$2\Application Data\SecondLife\typed_locations.txt"
 
-# If no language (error), then proceed
-    IfErrors lbl_configure_default_lang
-# No error means we got a language, so use it
-    StrCpy $LANGUAGE $0
-    Goto lbl_return
+  CONTINUE:
+    IntOp $0 $0 + 1
+    Goto LOOP
+  DONE:
 
-lbl_configure_default_lang:
-# If we currently have a version of SL installed, default to the language of that install
-# Otherwise don't change $LANGUAGE and it will default to the OS UI language.
-    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\${INSTNAME}" "InstallerLanguage"
-    IfErrors +2 0	# If error skip the copy instruction 
-	StrCpy $LANGUAGE $0
+Pop $2
+Pop $1
+Pop $0
 
-# For silent installs, no language prompt, use default
-    IfSilent lbl_return
-    StrCmp $SKIP_DIALOGS "true" lbl_return
-  
-lbl_build_menu:
-	Push ""
-# Use separate file so labels can be UTF-16 but we can still merge changes into this ASCII file. JC
-    !include "%%SOURCE%%\installers\windows\language_menu.nsi"
-    
-	Push A	# A means auto count languages for the auto count to work the first empty push (Push "") must remain
-	LangDLL::LangDialog $(InstallerLanguageTitle) $(SelectInstallerLanguage)
-	Pop $0
-	StrCmp $0 "cancel" 0 +2
-		Abort
-    StrCpy $LANGUAGE $0
+# Delete files in Program Data folder
+Push $0
+  ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common AppData"
+  StrCmp $0 "" +2
+  RMDir /r "$0\SecondLife"
+Pop $0
 
-# save language in registry		
-	WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\${INSTNAME}" "InstallerLanguage" $LANGUAGE
-lbl_return:
-    Pop $0
-    Return
+# Delete files in C:\Windows\Application Data\SecondLife
+# If the user is running on a pre-NT system, Application Data lives here instead of
+# in Documents and Settings.
+RMDir /r "$WINDIR\Application Data\SecondLife"
 
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Prep Uninstaller Section
+;; Delete the stored password for the current Windows user
+;; DEV-10821 -- Unauthorised user can gain access to an SL account after a real user has uninstalled
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Function un.onInit
-# Read language from registry and set for uninstaller. Key will be removed on successful uninstall
-	ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\${INSTNAME}" "InstallerLanguage"
-    IfErrors lbl_end
-	StrCpy $LANGUAGE $0
-lbl_end:
-    Return
+Function un.RemovePassword
+
+DetailPrint "Removing Second Life password"
+
+SetShellVarContext current
+Delete "$APPDATA\SecondLife\user_settings\password.dat"
+SetShellVarContext all
 
 FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Default Section
+;; Delete the installed files
+;; This deletes the uninstall executable, but it works because it is copied to temp directory before running
+;;
+;; Note:  You must list all files here, because we only want to delete our files,
+;; not things users left in the application directories.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-Section ""
-
-SetShellVarContext all			# Install for all users (if you change this, change it in the uninstall as well)
-
-# Start with some default values.
-StrCpy $INSTPROG "${INSTNAME}"
-StrCpy $INSTEXE "${INSTEXE}"
-StrCpy $INSTSHORTCUT "${SHORTCUT}"
-
-Call CheckCPUFlags				# Make sure we have SSE2 support
-Call CheckIfAdministrator		# Make sure the user can install/uninstall
-Call CheckIfAlreadyCurrent		# Make sure this version is not already installed
-Call CloseSecondLife			# Make sure Second Life not currently running
-Call CheckNetworkConnection		# Ping secondlife.com
-Call CheckWillUninstallV2		# Check if SecondLife is already installed
-Call CheckOldExeName            # Clean up a previous version of the exeicutable
+Function un.ProgramFiles
 
-StrCmp $DO_UNINSTALL_V2 "" PRESERVE_DONE
-  Call PreserveUserFiles
-PRESERVE_DONE:
+# Remove mozilla file first so recursive directory deletion doesn't get hung up
+Delete "$INSTDIR\app_settings\mozilla\components"
 
-# Don't remove cache files during a regular install,
-# removing the inventory cache on upgrades results in lots of damage to the servers.
-;Call RemoveCacheFiles			# Installing over removes potentially corrupted VFS and cache files.
+# This placeholder is replaced by the complete list of files to uninstall by viewer_manifest.py
+%%DELETE_FILES%%
 
-# Need to clean out shader files from previous installs to fix DEV-5663
-Call RemoveOldShaders
+# Optional/obsolete files.  Delete won't fail if they don't exist.
+Delete "$INSTDIR\dronesettings.ini"
+Delete "$INSTDIR\message_template.msg"
+Delete "$INSTDIR\newview.pdb"
+Delete "$INSTDIR\newview.map"
+Delete "$INSTDIR\SecondLife.pdb"
+Delete "$INSTDIR\SecondLife.map"
+Delete "$INSTDIR\comm.dat"
+Delete "$INSTDIR\*.glsl"
+Delete "$INSTDIR\motions\*.lla"
+Delete "$INSTDIR\trial\*.html"
+Delete "$INSTDIR\newview.exe"
+Delete "$INSTDIR\SecondLife.exe"
 
-# Need to clean out old XUI files that predate skinning
-Call RemoveOldXUI
+# MAINT-3099 workaround - prevent these log files, if present, from causing a user alert
+Delete "$INSTDIR\VivoxVoiceService-*.log"
 
-# Clear out old releasenotes.txt files. These are now on the public wiki.
-Call RemoveOldReleaseNotes
+# Remove entire help directory
+Delete "$INSTDIR\help\Advanced\*"
+RMDir  "$INSTDIR\help\Advanced"
+Delete "$INSTDIR\help\basics\*"
+RMDir  "$INSTDIR\help\basics"
+Delete "$INSTDIR\help\Concepts\*"
+RMDir  "$INSTDIR\help\Concepts"
+Delete "$INSTDIR\help\welcome\*"
+RMDir  "$INSTDIR\help\welcome"
+Delete "$INSTDIR\help\*"
+RMDir  "$INSTDIR\help"
 
-# This placeholder is replaced by the complete list of all the files in the installer, by viewer_manifest.py
-%%INSTALL_FILES%%
+Delete "$INSTDIR\uninst.exe"
+RMDir "$INSTDIR"
 
-# Pass the installer's language to the client to use as a default
-StrCpy $SHORTCUT_LANG_PARAM "--set InstallLanguage $(LanguageCode)"
+IfFileExists "$INSTDIR" FOLDERFOUND NOFOLDER
 
-# Shortcuts in start menu
-CreateDirectory	"$SMPROGRAMS\$INSTSHORTCUT"
-SetOutPath "$INSTDIR"
-CreateShortCut	"$SMPROGRAMS\$INSTSHORTCUT\$INSTSHORTCUT.lnk" \
-				"$INSTDIR\$INSTEXE" "$SHORTCUT_LANG_PARAM"
+FOLDERFOUND:
+# Silent uninstall always removes all files (/SD IDYES)
+  MessageBox MB_YESNO $(DeleteProgramFilesMB) /SD IDYES IDNO NOFOLDER
+  RMDir /r "$INSTDIR"
 
+NOFOLDER:
 
-WriteINIStr		"$SMPROGRAMS\$INSTSHORTCUT\SL Create Account.url" \
-				"InternetShortcut" "URL" \
-				"http://join.secondlife.com/"
-WriteINIStr		"$SMPROGRAMS\$INSTSHORTCUT\SL Your Account.url" \
-				"InternetShortcut" "URL" \
-				"http://www.secondlife.com/account/"
-WriteINIStr		"$SMPROGRAMS\$INSTSHORTCUT\SL Scripting Language Help.url" \
-				"InternetShortcut" "URL" \
-                "http://wiki.secondlife.com/wiki/LSL_Portal"
-CreateShortCut	"$SMPROGRAMS\$INSTSHORTCUT\Uninstall $INSTSHORTCUT.lnk" \
-				'"$INSTDIR\uninst.exe"' ''
+FunctionEnd
 
-# Other shortcuts
-SetOutPath "$INSTDIR"
-CreateShortCut "$DESKTOP\$INSTSHORTCUT.lnk" \
-        "$INSTDIR\$INSTEXE" "$SHORTCUT_LANG_PARAM"
-CreateShortCut "$INSTDIR\$INSTSHORTCUT.lnk" \
-        "$INSTDIR\$INSTEXE" "$SHORTCUT_LANG_PARAM"
-CreateShortCut "$INSTDIR\Uninstall $INSTSHORTCUT.lnk" \
-				'"$INSTDIR\uninst.exe"' ''
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; After install completes, launch app
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+Function .onInstSuccess
+Call CheckWindowsServPack		# Warn if not on the latest SP before asking to launch.
+    Push $R0					# Option value, unused
 
-# Write registry
-WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG" "" "$INSTDIR"
-WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG" "Version" "${VERSION_LONG}"
-WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG" "Shortcut" "$INSTSHORTCUT"
-WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Linden Research, Inc.\$INSTPROG" "Exe" "$INSTEXE"
-WriteRegStr HKEY_LOCAL_MACHINE "Software\Microsoft\Windows\CurrentVersion\Uninstall\$INSTPROG" "DisplayName" "$INSTPROG (remove only)"
-WriteRegStr HKEY_LOCAL_MACHINE "Software\Microsoft\Windows\CurrentVersion\Uninstall\$INSTPROG" "UninstallString" '"$INSTDIR\uninst.exe"'
+    StrCmp $SKIP_DIALOGS "true" label_launch 
 
-# Write URL registry info
-WriteRegStr HKEY_CLASSES_ROOT "${URLNAME}" "(default)" "URL:Second Life"
-WriteRegStr HKEY_CLASSES_ROOT "${URLNAME}" "URL Protocol" ""
-WriteRegStr HKEY_CLASSES_ROOT "${URLNAME}\DefaultIcon" "" '"$INSTDIR\$INSTEXE"'
+    ${GetOptions} $COMMANDLINE "/AUTOSTART" $R0
+    # If parameter was there (no error) just launch
+    # Otherwise ask
+    IfErrors label_ask_launch label_launch
+    
+label_ask_launch:
+    # Don't launch by default when silent
+    IfSilent label_no_launch
+	MessageBox MB_YESNO $(InstSuccesssQuestion) \
+        IDYES label_launch IDNO label_no_launch
+        
+label_launch:
+# Assumes SetOutPath $INSTDIR
+	Exec '"$INSTDIR\$INSTEXE" $SHORTCUT_LANG_PARAM'
+label_no_launch:
+	Pop $R0
 
-# URL param must be last item passed to viewer, it ignores subsequent params to avoid parameter injection attacks.
-WriteRegExpandStr HKEY_CLASSES_ROOT "${URLNAME}\shell\open\command" "" '"$INSTDIR\$INSTEXE" -url "%1"'
-WriteRegStr HKEY_CLASSES_ROOT "x-grid-location-info"(default)" "URL:Second Life"
-WriteRegStr HKEY_CLASSES_ROOT "x-grid-location-info" "URL Protocol" ""
-WriteRegStr HKEY_CLASSES_ROOT "x-grid-location-info\DefaultIcon" "" '"$INSTDIR\$INSTEXE"'
+FunctionEnd
 
-# URL param must be last item passed to viewer, it ignores subsequent params to avoid parameter injection attacks.
-WriteRegExpandStr HKEY_CLASSES_ROOT "x-grid-location-info\shell\open\command" "" '"$INSTDIR\$INSTEXE" -url "%1"'
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Recommend Upgrading to Service Pack 1 for Windows 7, if not present
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+Function CheckWindowsServPack
+  ${If} ${IsWin7}
+  ${AndIfNot} ${IsServicePack} 1
+    MessageBox MB_OK $(CheckWindowsServPackMB)
+    DetailPrint $(UseLatestServPackDP)
+    Return
+  ${EndIf}
 
-# write out uninstaller
-WriteUninstaller "$INSTDIR\uninst.exe"
+  ${If} ${IsWin2008R2}
+  ${AndIfNot} ${IsServicePack} 1
+    MessageBox MB_OK $(CheckWindowsServPackMB)
+    DetailPrint $(UseLatestServPackDP)
+    Return
+  ${EndIf}
 
-# Uninstall existing "Second Life Viewer 2" install if needed.
-StrCmp $DO_UNINSTALL_V2 "" REMOVE_SLV2_DONE
-  ExecWait '"$PROGRAMFILES\SecondLifeViewer2\uninst.exe" /S _?=$PROGRAMFILES\SecondLifeViewer2'
-  Delete "$PROGRAMFILES\SecondLifeViewer2\uninst.exe"	# with _? option above, uninst.exe will be left behind.
-  RMDir "$PROGRAMFILES\SecondLifeViewer2"	# will remove only if empty.
+FunctionEnd
 
-  Call RestoreUserFiles
-  Call RemoveTempUserFiles
-REMOVE_SLV2_DONE:
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Clobber user files - TEST ONLY
+;; This is here for testing, DO NOT USE UNLESS YOU KNOW WHAT YOU ARE TESTING FOR!
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;Function ClobberUserFilesTESTONLY
 
-SectionEnd
+;Push $0
+;Push $1
+;Push $2
+;
+;    StrCpy $0 0	# Index number used to iterate via EnumRegKey
+;
+;  LOOP:
+;    EnumRegKey $1 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" $0
+;    StrCmp $1 "" DONE               # no more users
+;
+;    ReadRegStr $2 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$1" "ProfileImagePath" 
+;    StrCmp $2 "" CONTINUE 0         # "ProfileImagePath" value is missing
+;
+;# Required since ProfileImagePath is of type REG_EXPAND_SZ
+;    ExpandEnvStrings $2 $2
+;
+;    RMDir /r "$2\Application Data\SecondLife\"
+;
+;  CONTINUE:
+;    IntOp $0 $0 + 1
+;    Goto LOOP
+;  DONE:
+;
+;Pop $2
+;Pop $1
+;Pop $0
+;
+;# Copy files in Documents and Settings\All Users\SecondLife
+;Push $0
+;    ReadRegStr $0 HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Common AppData"
+;    StrCmp $0 "" +2
+;    RMDir /r "$2\Application Data\SecondLife\"
+;Pop $0
+;
+;FunctionEnd
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EOF  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-- 
GitLab