Commits

Matthew Moses  committed 25207e4

Don't assume applications are installed.

When updating the environment for PowerShell, look up paths for applications
in the registry first. If the value does not exist assume the application is
not installed and skip the associated environment updates.

  • Participants
  • Parent commits 5ad8cdd

Comments (0)

Files changed (1)

File Microsoft.PowerShell_profile.ps1

-$Env:ANDROID_HOME = (
-    Get-ItemProperty 'HKLM:\SOFTWARE\Wow6432Node\Android SDK Tools' Path).Path
-# JAVA_HOME needs to be set outside of PowerShell so the Android SDK Tools
-# can find the 64-bit JDK properly.
-#$Env:JAVA_HOME = (
-#    Get-ItemProperty 'HKLM:\SOFTWARE\JavaSoft\Java Development Kit\1.7' JavaHome).JavaHome
-$Env:PYTHON_HOME = (
-    Get-ItemProperty 'HKLM:\SOFTWARE\Python\PythonCore\3.3\InstallPath').'(default)'
-$Env:PATH = (
-    $Env:PATH,
-    (Get-ItemProperty 'HKCU:\Software\Mercurial\InstallDir').'(default)',
-    (Join-Path $Env:PYTHON_HOME Scripts),
-    (Join-Path $Env:APPDATA (Join-Path Python Scripts)),
-    (Join-Path $Env:JAVA_HOME bin),
-    (Join-Path $Env:ANDROID_HOME tools),
-    (Join-Path $Env:ANDROID_HOME platform-tools) -join ';')
-
 Set-Variable -Description 'Whether we have administrator privileges.' `
     -Option Constant `
     -Name 'isAdministrator' `
 
     '> '
 }
+
+function Update-Environment {
+    $list = New-Object System.Collections.Generic.List[String]
+    $list.Add($Env:PATH)
+
+    $temp = (Get-ItemProperty -ErrorAction SilentlyContinue 'HKCU:\Software\Mercurial\InstallDir').'(default)'
+    if ($temp) {
+        $list.Add($temp)
+    } else {
+        Write-Warning 'Mercurial is not installed.'
+    }
+
+    $temp = (Get-ItemProperty -ErrorAction SilentlyContinue 'HKLM:\SOFTWARE\Python\PythonCore\3.3\InstallPath').'(default)'
+    if ($temp) {
+        $list.Add((Join-Path $temp Scripts))
+        $list.Add((Join-Path $Env:APPDATA (Join-Path Python Scripts)))
+    } else {
+        Write-Warning 'Python 3.3 is not installed.'
+    }
+
+    $temp = (Get-ItemProperty -ErrorAction SilentlyContinue 'HKLM:\SOFTWARE\JavaSoft\Java Development Kit\1.7' JavaHome).JavaHome
+    if ($temp) {
+        $Env:JAVA_HOME = $temp
+        $list.Add((Join-Path $temp bin))
+    } else {
+        Write-Warning 'Version 1.7 of the JDK is not installed.'
+    }
+
+    $temp = (Get-ItemProperty -ErrorAction SilentlyContinue 'HKLM:\SOFTWARE\Wow6432Node\Android SDK Tools' Path).Path
+    if ($temp) {
+        $Env:ANDROID_HOME = $temp
+        $list.Add((Join-Path $temp tools))
+        $list.Add((Join-Path $temp platform-tools))
+    } else {
+        Write-Warning 'The Android SDK is not installed.'
+    }
+
+    if ($list.Count -gt 1) {
+        $Env:PATH = $list -join ';'
+    }
+}
+
+Update-Environment