From cef47ee8bf94fcb183be10c8d6b56cd3360ce077 Mon Sep 17 00:00:00 2001 From: Josh Buedel Date: Fri, 29 Jan 2016 12:31:59 -0600 Subject: [PATCH] (GH-592) No Warning on Url Shortcut Do not warn about target existence if shortcut target is a url. --- .../functions/Install-ChocolateyShortcut.ps1 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 b/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 index 0af65ba76b..11b34a1696 100644 --- a/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 +++ b/src/chocolatey.resources/helpers/functions/Install-ChocolateyShortcut.ps1 @@ -51,7 +51,7 @@ Install-ChocolateyShortcut -shortcutFilePath "C:\notepad.lnk" -targetPath "C:\Wi This will create a new shortcut at the location of "C:\notepad.lnk" and link to the Notepad application. In addition, other properties are being set to specify the working -directoy, an icon to be used for the shortcut, along with a description and arguments. +directory, an icon to be used for the shortcut, along with a description and arguments. #> param( @@ -65,6 +65,12 @@ directoy, an icon to be used for the shortcut, along with a description and argu Write-Debug "Running 'Install-ChocolateyShortcut' with parameters ShortcutFilePath: `'$shortcutFilePath`', TargetPath: `'$targetPath`', WorkingDirectory: `'$workingDirectory`', Arguments: `'$arguments`', IconLocation: `'$iconLocation`', Description: `'$description`'"; + # http://powershell.com/cs/blogs/tips/archive/2009/02/05/validating-a-url.aspx + function isURIWeb($address) { + $uri = $address -as [System.URI] + $uri.AbsoluteURI -ne $null -and $uri.Scheme -match '[http|https]' + } + if(!$shortcutFilePath) { throw "Install-ChocolateyShortcut - `$shortcutFilePath can not be null." } @@ -78,7 +84,7 @@ directoy, an icon to be used for the shortcut, along with a description and argu throw "Install-ChocolateyShortcut - `$targetPath can not be null." } - if(!(Test-Path($targetPath))) { + if(!(Test-Path($targetPath)) -and !(IsURIWeb($targetPath))) { Write-Warning "'$targetPath' does not exist. If it is not created the shortcut will not be valid." } @@ -116,4 +122,5 @@ directoy, an icon to be used for the shortcut, along with a description and argu catch { Write-Warning "Unable to create shortcut. Error captured was $($_.Exception.Message)." } -} \ No newline at end of file +} +