From f6aca5c7696384ec3675bfbe2d5e73fd16915914 Mon Sep 17 00:00:00 2001 From: KitsuneSolar Date: Thu, 16 Nov 2023 22:39:01 +0000 Subject: [PATCH] 2023-11-16 22:39:01 --- PkgStore.cURL.psd1 | 1 - PkgStore.cURL.psm1 | 69 +++++++++-------------------------- Private/Start-cURL.ps1 | 26 +++++++++++++ Public/Start-cURLDownload.ps1 | 19 ++++++++++ 4 files changed, 62 insertions(+), 53 deletions(-) create mode 100644 Private/Start-cURL.ps1 create mode 100644 Public/Start-cURLDownload.ps1 diff --git a/PkgStore.cURL.psd1 b/PkgStore.cURL.psd1 index 72fb92b..b28f66c 100644 --- a/PkgStore.cURL.psd1 +++ b/PkgStore.cURL.psd1 @@ -8,7 +8,6 @@ Description = 'PowerShell module for cURL.' PowerShellVersion = '7.2' RequiredModules = @('PkgStore.Kernel') - FunctionsToExport = @('Start-cURLDownload') PrivateData = @{ PSData = @{ Tags = @('pwsh', 'curl') diff --git a/PkgStore.cURL.psm1 b/PkgStore.cURL.psm1 index d4dd859..68c4f2f 100644 --- a/PkgStore.cURL.psm1 +++ b/PkgStore.cURL.psm1 @@ -1,58 +1,23 @@ -<#PSScriptInfo - .VERSION 0.1.0 - .GUID 02d8b827-f39b-484c-8e8d-f7d6aa8e8915 - .AUTHOR Kitsune Solar - .AUTHOREMAIL mail@kitsune.solar - .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 } } diff --git a/Private/Start-cURL.ps1 b/Private/Start-cURL.ps1 new file mode 100644 index 0000000..b94f9c2 --- /dev/null +++ b/Private/Start-cURL.ps1 @@ -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 +} diff --git a/Public/Start-cURLDownload.ps1 b/Public/Start-cURLDownload.ps1 new file mode 100644 index 0000000..7aeed34 --- /dev/null +++ b/Public/Start-cURLDownload.ps1 @@ -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 + } +}