-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,23 @@ | ||
<#PSScriptInfo | ||
.VERSION 0.1.0 | ||
.GUID 02d8b827-f39b-484c-8e8d-f7d6aa8e8915 | ||
.AUTHOR Kitsune Solar | ||
.AUTHOREMAIL [email protected] | ||
.COMPANYNAME iHub.TO | ||
.COPYRIGHT 2023 Kitsune Solar. All rights reserved. | ||
.LICENSEURI https://github.com/pkgstore/pwsh-curl/blob/main/LICENSE | ||
.PROJECTURI https://github.com/pkgstore/pwsh-curl | ||
#> | ||
|
||
$App = @('curl.exe', 'curl-ca-bundle.crt', 'libcurl-x64.def', 'libcurl-x64.dll') | ||
$AppExe = @{LiteralPath = "${PSScriptRoot}"; Filter = "$($App[0])"; Recurse = $true; File = $true} | ||
$AppExe = ((Get-ChildItem @AppExe) | Select-Object -First 1) | ||
$NL = "$([Environment]::NewLine)" | ||
|
||
function Start-cURLDownload() { | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
#> | ||
|
||
Param( | ||
[Parameter(Mandatory)][Alias('URL')][string[]]$P_URL | ||
) | ||
|
||
# Checking cURL location. | ||
Test-cURL | ||
|
||
$P_URL | ForEach-Object { | ||
$Param = @('--location') # If the server reports that the requested page has moved to a different location. | ||
$Param += @('--remote-name') # Write output to a local file named like the remote file we get. | ||
$Param += @("${_}") # Input URL. | ||
|
||
& "${AppExe}" $Param | ||
$Aliases = @() | ||
$PrivateFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') -Include '*.ps1' -File -Recurse) | ||
$PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') -Include '*.ps1' -File -Recurse) | ||
|
||
(@($PrivateFunctions) + @($PublicFunctions)) | ForEach-Object { | ||
try { | ||
Write-Verbose "Loading '$($_.FullName)'." | ||
. $_.FullName | ||
} catch { | ||
Write-Warning $_.Exception.Message | ||
} | ||
} | ||
|
||
function Test-cURL { | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
#> | ||
|
||
# Getting 'curl.exe' directory. | ||
$Dir = "$($AppExe.DirectoryName)" | ||
@($PublicFunctions) | ForEach-Object { | ||
$Alias = (Get-Alias -Definition $_.BaseName -ErrorAction 'SilentlyContinue') | ||
|
||
# Checking the location of files. | ||
$App | ForEach-Object { | ||
if (-not (Test-Data -T 'F' -P "${Dir}\${_}")) { | ||
Write-Msg -T 'W' -A 'Stop' -M ("'${_}' not found!${NL}${NL}" + | ||
"1. Download '${_}' from 'https://curl.se/windows/'.${NL}" + | ||
"2. Extract all the contents of the archive into a directory '${PSScriptRoot}'.") | ||
} | ||
if ($Alias) { | ||
$Aliases += $Alias | ||
Export-ModuleMember -Function $_.BaseName -Alias $Alias | ||
} else { | ||
Export-ModuleMember -Function $_.BaseName | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function Start-cURL { | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
#> | ||
|
||
Param( | ||
[Alias('AD')][string[]]$AppData = @('curl.exe', 'curl-ca-bundle.crt', 'libcurl-x64.def', 'libcurl-x64.dll') | ||
) | ||
|
||
$AppPath = (Split-Path -Path "${PSScriptRoot}" -Parent) | ||
$App = @{LiteralPath = "${AppPath}"; Filter = "$($AppData[0])"; Recurse = $true; File = $true} | ||
$App = ((Get-ChildItem @App) | Select-Object -First 1) | ||
$NL = [Environment]::NewLine | ||
|
||
$AppData | ForEach-Object { | ||
if (-not (Test-Data -T 'F' -P "$($App.DirectoryName)\${_}")) { | ||
Write-Msg -T 'W' -A 'Stop' -M ("'${_}' not found!${NL}${NL}" + | ||
"1. Download '${_}' from 'https://curl.se/windows/'.${NL}" + | ||
"2. Extract all the contents of the archive into a directory '${AppPath}'.") | ||
} | ||
} | ||
|
||
$App | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function Start-cURLDownload() { | ||
<# | ||
.SYNOPSIS | ||
.DESCRIPTION | ||
#> | ||
|
||
Param( | ||
[Parameter(Mandatory)][Alias('URL')][string[]]$P_URL | ||
) | ||
|
||
$P_URL | ForEach-Object { | ||
$Param = @('--location') # If the server reports that the requested page has moved to a different location. | ||
$Param += @('--remote-name') # Write output to a local file named like the remote file we get. | ||
$Param += @("${_}") # Input URL. | ||
|
||
& $(Start-cURL) $Param | ||
} | ||
} |