Differences
This shows you the differences between the selected revisions of the page.
| 2017-10-13 | 2017-10-13 | ||
| whitespaces (martin) | replacing url with ~~SELF~~ (martin) | ||
| Line 10: | Line 10: | ||
| <code powershell - GenerateHttpUrl.ps1> | <code powershell - GenerateHttpUrl.ps1> | ||
| # @name Generate &HTTP URL | # @name Generate &HTTP URL | ||
| - | # @command powershell.exe -ExecutionPolicy Bypass -STA -NoProfile -File "%EXTENSION_PATH%" -webRoot "%WebRoot%" -rootPath "%RootPath%" -hostName "%HostName%" -serverName "!@" -path "!/!" %Https% %Pause% %Clipboard% %Open% | + | # @command powershell.exe -ExecutionPolicy Bypass -STA -NoProfile -File "%EXTENSION_PATH%" -webRoot "%WebRoot%" -rootPath "%RootPath%" -hostName "%HostName%" -serverName "!@" -path "!/" %Https% %Pause% %Clipboard% %Open% !& |
| # @description Generates HTTP URL of the selected file | # @description Generates HTTP URL of the selected file | ||
| # @flag RemoteFiles | # @flag RemoteFiles | ||
| # @flag ShowResultsInMsgBox | # @flag ShowResultsInMsgBox | ||
| - | # @version 3 | + | # @version 4 |
| # @homepage ~~SELF~~ | # @homepage ~~SELF~~ | ||
| # @require WinSCP 5.10 | # @require WinSCP 5.10 | ||
| Line 44: | Line 44: | ||
| $clipboard, | $clipboard, | ||
| [Switch] | [Switch] | ||
| - | $open | + | $open, |
| + | [Parameter(Mandatory = $True, ValueFromRemainingArguments = $True, Position = 0)] | ||
| + | $paths | ||
| ) | ) | ||
| Line 54: | Line 56: | ||
| } | } | ||
| - | if (($path.Length -lt $webRoot.length) -or | + | $result = $Null |
| - | ·······($path.SubString(0, $webRoot.Length) -ne $webRoot)) | + | ···foreach ($filePath in $paths) |
| { | { | ||
| - | throw "**The path $path is not under web root $webRoot.**" | + | $filePath = "$path$filePath" |
| - | } | + | |
| - | ··· | + | ·······if (($filePath.Length -lt $webRoot.length) -or |
| - | ···if ($rootPath) | + | ···········($filePath.SubString(0, $webRoot.Length) -ne $webRoot)) |
| - | ···{ | + | |
| - | ·······if ($rootPath.SubString($rootPath.Length - 1) -ne "/") | + | |
| { | { | ||
| - | $rootPath += "/" | + | throw "**The path $filePath is not under web root $webRoot.**" |
| + | } | ||
| + | |||
| + | if ($rootPath) | ||
| + | { | ||
| + | if ($rootPath.SubString($rootPath.Length - 1) -ne "/") | ||
| + | { | ||
| + | ················$rootPath += "/" | ||
| + | } | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | $rootPath = "/" | ||
| } | } | ||
| - | } | ||
| - | else | ||
| - | { | ||
| - | $rootPath = "/" | ||
| - | } | ||
| - | ····$urlPath = $path.SubString($webRoot.Length) | + | ········$urlPath = $filePath.SubString($webRoot.Length) |
| - | ···$urlPath = ($urlPath -split "/" | %{ [System.Uri]::EscapeDataString($_) }) -join "/" | + | ·······$urlPath = ($urlPath -split "/" | %{ [System.Uri]::EscapeDataString($_) }) -join "/" |
| - | + | ···· | |
| - | ···if ($https) | + | ·······if ($https) |
| - | ···{ | + | ·······{ |
| - | ·······$protocol = "https://" | + | ···········$protocol = "https://" |
| - | ···} | + | ·······} |
| - | ···else | + | ·······else |
| - | ···{ | + | ·······{ |
| - | ·······$protocol = "http://" | + | ···········$protocol = "http://" |
| - | ···} | + | ·······} |
| - | ····if (!$hostName) | + | ········if (!$hostName) |
| - | ···{ | + | ·······{ |
| - | ·······$hostName = $serverName | + | ···········$hostName = $serverName |
| + | } | ||
| + | |||
| + | $url = "$protocol$hostName$rootPath$urlPath" | ||
| + | $result += $url | ||
| + | if ($paths.Count -gt 1) | ||
| + | { | ||
| + | $result += "`r`n" | ||
| + | } | ||
| + | |||
| + | if ($open) | ||
| + | { | ||
| + | Start-Process $url | ||
| + | } | ||
| } | } | ||
| - | |||
| - | $url = "$protocol$hostName$rootPath$urlPath" | ||
| if ($pause) | if ($pause) | ||
| { | { | ||
| - | Write-Host $url | + | Write-Host -NoNewline $result |
| } | } | ||
| Line 99: | Line 117: | ||
| { | { | ||
| Add-Type -Assembly PresentationCore | Add-Type -Assembly PresentationCore | ||
| - | [Windows.Clipboard]::SetText($url) | + | [Windows.Clipboard]::SetText($result) |
| - | } | + | |
| - | + | ||
| - | if ($open) | + | |
| - | { | + | |
| - | Start-Process $url | + | |
| } | } | ||