2 Commits
Author SHA1 Message Date
omgitsalexl 159e12c79a Fixes failure with extracting *.tpz 2026-08-29 07:33:17 -07:00
omgitsalexl dae0123a17 Refactored directory check function 2026-08-29 06:21:03 -07:00
+24 -3
View File
@@ -17,6 +17,26 @@ function Require-Environment([string]$Name) {
return $value return $value
} }
function Test-PathIsWithinDirectory([string]$ParentDirectory, [string]$CandidateDirectory) {
# [IO.Path]::GetRelativePath is not available in Windows PowerShell 5.1.
# Compare complete paths with a separator boundary so, for example,
# C:\workspace-other is not considered a child of C:\workspace.
$parentPath = [IO.Path]::GetFullPath($ParentDirectory)
$candidatePath = [IO.Path]::GetFullPath($CandidateDirectory)
$directorySeparator = [IO.Path]::DirectorySeparatorChar.ToString()
$alternateSeparator = [IO.Path]::AltDirectorySeparatorChar.ToString()
if ($candidatePath.Equals($parentPath, [StringComparison]::OrdinalIgnoreCase)) {
return $true
}
if (-not $parentPath.EndsWith($directorySeparator) -and -not $parentPath.EndsWith($alternateSeparator)) {
$parentPath += $directorySeparator
}
return $candidatePath.StartsWith($parentPath, [StringComparison]::OrdinalIgnoreCase)
}
function Get-ActualArchitecture { function Get-ActualArchitecture {
$architecture = $env:PROCESSOR_ARCHITEW6432 $architecture = $env:PROCESSOR_ARCHITEW6432
if ([string]::IsNullOrWhiteSpace($architecture)) { if ([string]::IsNullOrWhiteSpace($architecture)) {
@@ -98,8 +118,7 @@ if ($HostArch -ne (Get-ActualArchitecture)) { Fail "host-arch '$HostArch' does n
$workspaceDirectory = [IO.Path]::GetFullPath($Workspace) $workspaceDirectory = [IO.Path]::GetFullPath($Workspace)
if ([IO.Path]::IsPathRooted($ProjectPath)) { Fail 'project-path must be relative to the checked-out workspace.' } if ([IO.Path]::IsPathRooted($ProjectPath)) { Fail 'project-path must be relative to the checked-out workspace.' }
$ProjectDirectory = [IO.Path]::GetFullPath((Join-Path $workspaceDirectory $ProjectPath)) $ProjectDirectory = [IO.Path]::GetFullPath((Join-Path $workspaceDirectory $ProjectPath))
$projectRelativePath = [IO.Path]::GetRelativePath($workspaceDirectory, $ProjectDirectory) if (-not (Test-PathIsWithinDirectory $workspaceDirectory $ProjectDirectory)) { Fail 'project-path must remain inside the checked-out workspace.' }
if ($projectRelativePath -eq '..' -or $projectRelativePath.StartsWith("..$([IO.Path]::DirectorySeparatorChar)") -or [IO.Path]::IsPathRooted($projectRelativePath)) { Fail 'project-path must remain inside the checked-out workspace.' }
if (-not (Test-Path -LiteralPath (Join-Path $ProjectDirectory 'project.godot') -PathType Leaf)) { Fail "No project.godot was found in project-path '$ProjectPath'." } if (-not (Test-Path -LiteralPath (Join-Path $ProjectDirectory 'project.godot') -PathType Leaf)) { Fail "No project.godot was found in project-path '$ProjectPath'." }
$PresetFile = Join-Path $ProjectDirectory 'export_presets.cfg' $PresetFile = Join-Path $ProjectDirectory 'export_presets.cfg'
if (-not (Test-Path -LiteralPath $PresetFile -PathType Leaf)) { Fail "No export_presets.cfg was found in project-path '$ProjectPath'." } if (-not (Test-Path -LiteralPath $PresetFile -PathType Leaf)) { Fail "No export_presets.cfg was found in project-path '$ProjectPath'." }
@@ -143,6 +162,7 @@ if (-not $editorExecutable) {
$manifestPath = Join-Path $cacheDirectory 'SHA512-SUMS.txt' $manifestPath = Join-Path $cacheDirectory 'SHA512-SUMS.txt'
$editorArchive = Join-Path $cacheDirectory $editorAsset $editorArchive = Join-Path $cacheDirectory $editorAsset
$templatesArchive = Join-Path $cacheDirectory $templatesAsset $templatesArchive = Join-Path $cacheDirectory $templatesAsset
$templatesZipArchive = Join-Path $cacheDirectory ($templatesAsset -replace '\.tpz$', '.zip')
$templatesStagingDirectory = Join-Path $cacheDirectory 'templates-staging' $templatesStagingDirectory = Join-Path $cacheDirectory 'templates-staging'
Invoke-WebRequest -Uri "$script:BaseUrl/SHA512-SUMS.txt" -OutFile $manifestPath Invoke-WebRequest -Uri "$script:BaseUrl/SHA512-SUMS.txt" -OutFile $manifestPath
$editorChecksum = Get-Checksum $manifestPath $editorAsset $editorChecksum = Get-Checksum $manifestPath $editorAsset
@@ -150,7 +170,8 @@ if (-not $editorExecutable) {
Download-AndVerify $editorAsset $editorArchive $editorChecksum Download-AndVerify $editorAsset $editorArchive $editorChecksum
Download-AndVerify $templatesAsset $templatesArchive $templatesChecksum Download-AndVerify $templatesAsset $templatesArchive $templatesChecksum
Expand-Archive -LiteralPath $editorArchive -DestinationPath $editorDirectory -Force Expand-Archive -LiteralPath $editorArchive -DestinationPath $editorDirectory -Force
Expand-Archive -LiteralPath $templatesArchive -DestinationPath $templatesStagingDirectory -Force Move-Item -LiteralPath $templatesArchive -Destination $templatesZipArchive
Expand-Archive -LiteralPath $templatesZipArchive -DestinationPath $templatesStagingDirectory -Force
Install-ExportTemplates $templatesStagingDirectory $templateDirectory $templatesAsset $templateVersion Install-ExportTemplates $templatesStagingDirectory $templateDirectory $templatesAsset $templateVersion
$editorExecutable = Find-Editor $editorDirectory $editorExecutable = Find-Editor $editorDirectory
if (-not $editorExecutable) { Fail 'The Godot editor archive did not contain an executable.' } if (-not $editorExecutable) { Fail 'The Godot editor archive did not contain an executable.' }