Skip to content

Commit

Permalink
Merge pull request #3138 from freddydk/master
Browse files Browse the repository at this point in the history
Support wildcards in CopyAppFilesToFolder
  • Loading branch information
freddydk committed Jul 29, 2023
2 parents fd3a8df + c1944d8 commit c0e4e78
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 31 deletions.
45 changes: 37 additions & 8 deletions AppHandling/Extract-AppFileToFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Extract-AppFileToFolder {

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {

Set-StrictMode -Off
if ($appFolder -eq "") {
if ($openFolder) {
$generateAppJson = $true
Expand Down Expand Up @@ -112,7 +112,6 @@ try {
}

if ($generateAppJson) {
#Set-StrictMode -Off
$manifest = [xml](Get-Content -path (Join-Path $appFolder "NavxManifest.xml") -Encoding UTF8)
$runtimeStr = "$($manifest.Package.App.Attributes | Where-Object { $_.name -eq "Runtime" } | % { $_.Value } )"
if ($runtimeStr) {
Expand Down Expand Up @@ -171,19 +170,49 @@ try {
}
else {
$manifest.Package.ChildNodes | Where-Object { $_.name -eq "ResourceExposurePolicy" } | % {
$xmlResExp = [ordered]@{}
$resExp = [ordered]@{}
"allowDebugging", "allowDownloadingSource", "includeSourceInSymbolFile" | % {
"allowDebugging", "allowDownloadingSource", "includeSourceInSymbolFile","applyToDevExtension" | % {
$prop = $_
if ($xmlResExp.PSObject.Properties.Name -eq $prop) {
if ($manifest.Package.ResourceExposurePolicy.Attributes | Where-Object { $_.name -eq $prop } | % { $_.Value -eq "true" }) {
$resExp += @{
"$prop" = $xmlResExp."$prop" -eq "true"
"$prop" = $true
}
}
}
$appJson += @{ "resourceExposurePolicy" = $resExp }
}

}
if ($runtime -ge [System.Version]"12.0") {
$manifest.Package.ChildNodes | Where-Object { $_.name -eq "Source" } | % {
$node = $_
$ht = [ordered]@{}
"repositoryUrl", "commit" | % {
$prop = $_
if ($node) {
$node.Attributes | Where-Object { $_.name -eq $prop } | % {
$ht += @{
"$prop" = $_.Value
}
}
}
}
$appJson += @{ "source" = $ht }
}
$manifest.Package.ChildNodes | Where-Object { $_.name -eq "Build" } | % {
$node = $_
$ht = [ordered]@{}
"by", "url" | % {
$prop = $_
if ($node) {
$node.Attributes | Where-Object { $_.name -eq $prop } | % {
$ht += @{
"$prop" = $_.Value
}
}
}
}
$appJson += @{ "build" = $ht }
}
}
if ($runtime -ge [System.Version]"5.0") {
$appInsightsKey = $manifest.Package.App.Attributes | Where-Object { $_.name -eq "applicationInsightsKey" } | % { $_.Value }
Expand Down Expand Up @@ -287,7 +316,6 @@ try {
}
}
$appJson | convertTo-json | Set-Content -Path (Join-Path $appFolder "app.json") -Encoding UTF8
Set-StrictMode -Version 2.0
}

if ($openFolder) {
Expand All @@ -299,6 +327,7 @@ catch {
throw
}
finally {
Set-StrictMode -Version 2.0
TrackTrace -telemetryScope $telemetryScope
}
}
Expand Down
49 changes: 26 additions & 23 deletions HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -543,33 +543,36 @@ function CopyAppFilesToFolder {
}
}
elseif (Test-Path $appFile -PathType Leaf) {
if ([string]::new([char[]](Get-Content $appFile @byteEncodingParam -TotalCount 2)) -eq "PK") {
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
$copied = $false
try {
if ($appFile -notlike "*.zip") {
$orgAppFile = $appFile
$appFile = Join-Path ([System.IO.Path]::GetTempPath()) "$([System.IO.Path]::GetFileName($orgAppFile)).zip"
Copy-Item $orgAppFile $appFile
$copied = $true
Get-ChildItem $appFile | ForEach-Object {
$appFile = $_.FullName
if ([string]::new([char[]](Get-Content $appFile @byteEncodingParam -TotalCount 2)) -eq "PK") {
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
$copied = $false
try {
if ($appFile -notlike "*.zip") {
$orgAppFile = $appFile
$appFile = Join-Path ([System.IO.Path]::GetTempPath()) "$([System.IO.Path]::GetFileName($orgAppFile)).zip"
Copy-Item $orgAppFile $appFile
$copied = $true
}
Expand-Archive $appfile -DestinationPath $tmpFolder -Force
Get-ChildItem -Path $tmpFolder -Recurse | Where-Object { $_.Name -like "*.app" -or $_.Name -like "*.zip" } | % {
CopyAppFilesToFolder -appFile $_.FullName -folder $folder
}
}
Expand-Archive $appfile -DestinationPath $tmpFolder -Force
Get-ChildItem -Path $tmpFolder -Recurse | Where-Object { $_.Name -like "*.app" -or $_.Name -like "*.zip" } | % {
CopyAppFilesToFolder -appFile $_.FullName -folder $folder
finally {
Remove-Item -Path $tmpFolder -Recurse -Force
if ($copied) { Remove-Item -Path $appFile -Force }
}
}
finally {
Remove-Item -Path $tmpFolder -Recurse -Force
if ($copied) { Remove-Item -Path $appFile -Force }
}
}
else {
$destFile = Join-Path $folder "$([System.IO.Path]::GetFileNameWithoutExtension($appFile)).app"
if (Test-Path $destFile) {
Write-Host -ForegroundColor Yellow "::WARNING::$([System.IO.Path]::GetFileName($destFile)) already exists, it looks like you have multiple app files with the same name. App filenames must be unique."
else {
$destFile = Join-Path $folder "$([System.IO.Path]::GetFileNameWithoutExtension($appFile)).app"
if (Test-Path $destFile) {
Write-Host -ForegroundColor Yellow "::WARNING::$([System.IO.Path]::GetFileName($destFile)) already exists, it looks like you have multiple app files with the same name. App filenames must be unique."
}
Copy-Item -Path $appFile -Destination $destFile -Force
$destFile
}
Copy-Item -Path $appFile -Destination $destFile -Force
$destFile
}
}
else {
Expand Down

0 comments on commit c0e4e78

Please sign in to comment.