@craft_eco/craft-mcp 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +3 -3
  2. package/dist-server/engines/unreal/artifacts.mjs +7 -3
  3. package/dist-server/engines/unreal/check.mjs +56 -7
  4. package/dist-server/engines/unreal/export.mjs +3 -3
  5. package/dist-server/engines/unreal/external-environment.mjs +7 -1
  6. package/dist-server/engines/unreal/preview-project.mjs +2 -2
  7. package/dist-server/engines/unreal/project.mjs +44 -12
  8. package/dist-server/mcp/server.mjs +3 -2
  9. package/package.json +2 -2
  10. package/resources/targets/claude/unreal/target.json +6 -6
  11. package/resources/targets/claude/unreal/unreal/bundle.json +10 -10
  12. package/resources/targets/claude/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  13. package/resources/targets/codebuddy/unreal/target.json +6 -6
  14. package/resources/targets/codebuddy/unreal/unreal/bundle.json +10 -10
  15. package/resources/targets/codebuddy/unreal/unreal/context/web/knowledge/WebBuild.md +9 -7
  16. package/resources/targets/codex/unreal/target.json +6 -6
  17. package/resources/targets/codex/unreal/unreal/bundle.json +10 -10
  18. package/resources/targets/codex/unreal/unreal/context/web/knowledge/WebBuild.md +9 -7
  19. package/resources/targets/comate/unreal/target.json +6 -6
  20. package/resources/targets/comate/unreal/unreal/bundle.json +10 -10
  21. package/resources/targets/comate/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  22. package/resources/targets/cursor/unreal/target.json +6 -6
  23. package/resources/targets/cursor/unreal/unreal/bundle.json +10 -10
  24. package/resources/targets/cursor/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  25. package/resources/targets/dsh/unreal/target.json +6 -6
  26. package/resources/targets/dsh/unreal/unreal/bundle.json +10 -10
  27. package/resources/targets/dsh/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  28. package/resources/targets/index.json +28 -28
  29. package/resources/targets/kimi/unreal/target.json +6 -6
  30. package/resources/targets/kimi/unreal/unreal/bundle.json +10 -10
  31. package/resources/targets/kimi/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  32. package/resources/targets/opencode/unreal/target.json +6 -6
  33. package/resources/targets/opencode/unreal/unreal/bundle.json +10 -10
  34. package/resources/targets/opencode/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  35. package/resources/targets/qoder/unreal/target.json +6 -6
  36. package/resources/targets/qoder/unreal/unreal/bundle.json +10 -10
  37. package/resources/targets/qoder/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  38. package/resources/targets/qoder-cn/unreal/target.json +6 -6
  39. package/resources/targets/qoder-cn/unreal/unreal/bundle.json +10 -10
  40. package/resources/targets/qoder-cn/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  41. package/resources/targets/qwen/unreal/target.json +6 -6
  42. package/resources/targets/qwen/unreal/unreal/bundle.json +10 -10
  43. package/resources/targets/qwen/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  44. package/resources/targets/trae/unreal/target.json +6 -6
  45. package/resources/targets/trae/unreal/unreal/bundle.json +10 -10
  46. package/resources/targets/trae/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  47. package/resources/targets/workbuddy/unreal/target.json +6 -6
  48. package/resources/targets/workbuddy/unreal/unreal/bundle.json +11 -11
  49. package/resources/targets/workbuddy/unreal/unreal/context/web/knowledge/WebBuild.md +7 -11
  50. package/resources/targets/workbuddy/unreal/unreal/context/web/skills/unreal-verify/SKILL.md +1 -1
  51. package/resources/targets/zcode/unreal/target.json +6 -6
  52. package/resources/targets/zcode/unreal/unreal/bundle.json +10 -10
  53. package/resources/targets/zcode/unreal/unreal/context/web/knowledge/WebBuild.md +6 -6
  54. package/resources/templates/unreal/project/Config/DefaultWebPublisher.ini +27 -21
  55. package/resources/templates/unreal/project/Config/README.md +10 -1
  56. package/resources/templates/unreal/project/Plugins/WebPublisher/Source/WebPublisher/Private/WebPublisherModule.cpp +13 -0
  57. package/resources/templates/unreal/project/template.json +33 -33
  58. package/resources/unreal-websdk/Setup-WebSDK.ps1 +2 -1
  59. package/resources/unreal-websdk/WebSDK-Packages.ps1 +143 -33
  60. package/resources/unreal-websdk/websdk-release.json +1 -5
@@ -1,18 +1,36 @@
1
1
  # Dot-source this file to resolve a matching SDK and WebStarter pair on Windows.
2
2
  $script:WebSdkDefaultReleaseManifest = Join-Path $PSScriptRoot 'websdk-release.json'
3
3
 
4
+ function Stop-WebSdkInvalidArchive {
5
+ param([string]$Message)
6
+ $error = [IO.InvalidDataException]::new($Message)
7
+ $error.Data['WebSdkArchiveInvalid'] = $true
8
+ throw $error
9
+ }
10
+
4
11
  function Read-WebSdkJson {
5
- param([string]$Path, [int64]$MaxBytes = 8MB)
12
+ param([string]$Path, [int64]$MaxBytes = 8MB, [switch]$ArchiveMetadata)
6
13
  $file = Get-Item -LiteralPath $Path -ErrorAction Stop
14
+ if ($ArchiveMetadata -and !$file.PSIsContainer -and
15
+ !($file.Attributes -band [IO.FileAttributes]::ReparsePoint) -and $file.Length -eq 0) {
16
+ Stop-WebSdkInvalidArchive "Empty Web SDK archive metadata file: $Path"
17
+ }
7
18
  if ($file.PSIsContainer -or ($file.Attributes -band [IO.FileAttributes]::ReparsePoint) -or
8
19
  $file.Length -le 0 -or $file.Length -gt $MaxBytes) {
9
20
  throw "Invalid Web SDK metadata file: $Path"
10
21
  }
11
22
  try {
12
- $document = Get-Content -LiteralPath $file.FullName -Raw -Encoding UTF8 | ConvertFrom-Json -ErrorAction Stop
23
+ # Read failures must keep the completed download available for a later retry.
24
+ $content = Get-Content -LiteralPath $file.FullName -Raw -Encoding UTF8 -ErrorAction Stop
25
+ } catch {
26
+ throw "Could not read Web SDK metadata '$Path': $($_.Exception.Message)"
27
+ }
28
+ try {
29
+ $document = $content | ConvertFrom-Json -ErrorAction Stop
13
30
  if ($document -isnot [pscustomobject]) { throw 'Expected a JSON object.' }
14
31
  return $document
15
32
  } catch {
33
+ if ($ArchiveMetadata) { Stop-WebSdkInvalidArchive "Invalid Web SDK archive metadata '$Path': $($_.Exception.Message)" }
16
34
  throw "Could not read Web SDK metadata '$Path': $($_.Exception.Message)"
17
35
  }
18
36
  }
@@ -44,30 +62,30 @@ function Assert-WebSdkRegularFile {
44
62
  function Read-WebSdkRelease {
45
63
  param([string]$Root)
46
64
  $file = Join-Path $Root 'release-files.json'
47
- $release = Read-WebSdkJson $file 1MB
65
+ $release = Read-WebSdkJson $file 1MB -ArchiveMetadata
48
66
  $engine = Get-WebSdkProperty $release 'engineVersion'
49
67
  $sdk = Get-WebSdkProperty $release 'sdkVersion'
50
68
  if ((Get-WebSdkProperty $release 'layout') -ne 'bundled-toolchain' -or $engine -ne '5.8.4' -or
51
69
  $sdk -isnot [string] -or $sdk -notmatch '^\d+\.\d+\.\d+$') {
52
- throw "Expected a bundled UE 5.8.4 SDK release in '$file'."
70
+ Stop-WebSdkInvalidArchive "Expected a bundled UE 5.8.4 SDK release in '$file'."
53
71
  }
54
72
  $archives = @(Get-WebSdkProperty $release 'archives')
55
- if ($archives.Count -ne 2) { throw "Expected exactly two ZIP records in '$file'." }
73
+ if ($archives.Count -ne 2) { Stop-WebSdkInvalidArchive "Expected exactly two ZIP records in '$file'." }
56
74
  $ordered = foreach ($name in @("WebSDK-UE$engine-$sdk.zip", "WebStarter-UE$engine-$sdk.zip")) {
57
75
  $matches = @($archives | Where-Object { (Get-WebSdkProperty $_ 'path') -ceq $name })
58
- if ($matches.Count -ne 1) { throw "Release manifest must contain $name." }
76
+ if ($matches.Count -ne 1) { Stop-WebSdkInvalidArchive "Release manifest must contain $name." }
59
77
  $record = $matches[0]
60
78
  $bytes = Get-WebSdkProperty $record 'bytes'
61
79
  $sha = Get-WebSdkProperty $record 'sha256'
62
80
  if (($bytes -isnot [int] -and $bytes -isnot [long]) -or $bytes -le 0 -or
63
81
  $sha -isnot [string] -or $sha -notmatch '^[0-9a-fA-F]{64}$') {
64
- throw "Release manifest contains an invalid size or SHA-256 for $name."
82
+ Stop-WebSdkInvalidArchive "Release manifest contains an invalid size or SHA-256 for $name."
65
83
  }
66
84
  [pscustomobject]@{ path = $name; bytes = [int64]$bytes; sha256 = $sha }
67
85
  }
68
86
  $sourceDigest = Get-WebSdkProperty (Get-WebSdkProperty $release 'sourceIdentity') 'digest'
69
87
  if ($null -ne $sourceDigest -and ($sourceDigest -isnot [string] -or $sourceDigest -notmatch '^[0-9a-fA-F]{64}$')) {
70
- throw "Invalid SDK source fingerprint in '$file'."
88
+ Stop-WebSdkInvalidArchive "Invalid SDK source fingerprint in '$file'."
71
89
  }
72
90
  [pscustomobject]@{
73
91
  engineVersion = $engine
@@ -173,7 +191,7 @@ public static class CraftStandaloneWebSdkZip
173
191
  report("Verifying " + Path.GetFileName(path));
174
192
  string absolute = LongPath(path);
175
193
  if ((File.GetAttributes(absolute) & (FileAttributes.ReparsePoint | FileAttributes.Directory)) != 0)
176
- throw new InvalidDataException("Archive must be a regular file: " + path);
194
+ throw new IOException("Archive must be a regular file: " + path);
177
195
  var stream = new FileStream(absolute, FileMode.Open, FileAccess.Read, FileShare.Read, 1024 * 1024, FileOptions.SequentialScan);
178
196
  try
179
197
  {
@@ -238,7 +256,7 @@ public static class CraftStandaloneWebSdkZip
238
256
  string absolute = LongPath(path);
239
257
  Directory.CreateDirectory(absolute);
240
258
  if ((File.GetAttributes(absolute) & FileAttributes.ReparsePoint) != 0)
241
- throw new InvalidDataException("ZIP destination contains a reparse point: " + path);
259
+ throw new IOException("ZIP destination contains a reparse point: " + path);
242
260
  known.Add(path);
243
261
  }
244
262
 
@@ -370,8 +388,14 @@ function Install-WebSdkZipPair {
370
388
  $null = Assert-WebSdkRegularFile $sdkZip
371
389
  $null = Assert-WebSdkRegularFile $starterZip
372
390
  $report = [Action[string]] { param($Message) Write-Host $Message }
373
- [CraftStandaloneWebSdkZip]::Install($stage, $sdkZip, $sdk.bytes, $sdk.sha256,
374
- $starterZip, $starter.bytes, $starter.sha256, $report)
391
+ try {
392
+ [CraftStandaloneWebSdkZip]::Install($stage, $sdkZip, $sdk.bytes, $sdk.sha256,
393
+ $starterZip, $starter.bytes, $starter.sha256, $report)
394
+ } catch {
395
+ $cause = $_.Exception.GetBaseException()
396
+ if ($cause -is [IO.InvalidDataException]) { $cause.Data['WebSdkArchiveInvalid'] = $true }
397
+ throw
398
+ }
375
399
  $kit = Read-WebSdkInstalledPair $stage $Release $KitVersion
376
400
  $receipt = @{ releaseDigest = $Release.digest; archiveSha256 = $ArchiveHash; kitVersion = $kit.kitVersion }
377
401
  $receipt | ConvertTo-Json -Compress | Set-Content -LiteralPath (Join-Path $stage 'receipt.json') -Encoding UTF8 -ErrorAction Stop
@@ -409,46 +433,58 @@ function Get-WebSdkFileHash {
409
433
  finally { $stream.Dispose() }
410
434
  }
411
435
 
436
+ function Invoke-WebSdkArchiveTar {
437
+ param([string]$Tar, [string[]]$Arguments, [string]$Failure)
438
+ $ErrorActionPreference = 'Continue'
439
+ $output = @(& $Tar @Arguments 2>&1)
440
+ if ($LASTEXITCODE -ne 0) {
441
+ $details = ($output | ForEach-Object { $_.ToString() }) -join "`n"
442
+ if ($details -match '(?i)\b(?:CRC|checksum) (?:error|mismatch)|(?:bad|incorrect) (?:CRC|checksum)|(?:damaged|truncated|corrupt(?:ed)?) (?:7-?Zip|archive|input)|Unrecognized archive format') {
443
+ Stop-WebSdkInvalidArchive "$Failure $details"
444
+ }
445
+ throw "$Failure $details"
446
+ }
447
+ return @($output | Where-Object { $_ -isnot [Management.Automation.ErrorRecord] })
448
+ }
449
+
412
450
  function Expand-WebSdkOuterArchive {
413
451
  param([string]$Archive, [string]$Stage)
414
452
  $tar = (Get-Command tar.exe -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1).Source
415
453
  if (!$tar) { throw 'Windows tar.exe with 7z support is required. Extract the 7z manually and pass its Packages folder using -Packages.' }
416
454
 
417
455
  Write-Host 'Checking 7z package layout'
418
- $names = @(& $tar -tf $Archive)
419
- if ($LASTEXITCODE -ne 0) { throw 'Cannot list the 7z package. Extract it with 7-Zip, then pass the Packages directory using -Packages.' }
420
- if ($names.Count -lt 3 -or $names.Count -gt 5) { throw 'Unexpected files in Web SDK 7z. Expected a Packages folder with two ZIPs and release metadata.' }
456
+ $names = @(Invoke-WebSdkArchiveTar $tar @('-tf', $Archive) 'Cannot list the 7z package.')
457
+ if ($names.Count -lt 3 -or $names.Count -gt 5) { Stop-WebSdkInvalidArchive 'Unexpected files in Web SDK 7z. Expected a Packages folder with two ZIPs and release metadata.' }
421
458
  $seen = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase)
422
459
  $sdkCount = 0
423
460
  $starterCount = 0
424
461
  foreach ($name in $names) {
425
462
  if (($name -cnotmatch '^Packages/$|^Packages/(?:release-files\.json|package-verification\.json|Web(?:SDK|Starter)-UE5\.8\.4-\d+\.\d+\.\d+\.zip)$') -or
426
463
  !$seen.Add($name)) {
427
- throw "Unexpected or unsafe path in Web SDK 7z: $name"
464
+ Stop-WebSdkInvalidArchive "Unexpected or unsafe path in Web SDK 7z: $name"
428
465
  }
429
466
  if ($name.StartsWith('Packages/WebSDK-')) { $sdkCount++ }
430
467
  if ($name.StartsWith('Packages/WebStarter-')) { $starterCount++ }
431
468
  }
432
469
  if (!$seen.Contains('Packages/release-files.json') -or $sdkCount -ne 1 -or $starterCount -ne 1) {
433
- throw 'Web SDK 7z does not contain one SDK ZIP, one WebStarter ZIP, and release-files.json.'
470
+ Stop-WebSdkInvalidArchive 'Web SDK 7z does not contain one SDK ZIP, one WebStarter ZIP, and release-files.json.'
434
471
  }
435
- $details = @(& $tar -tvf $Archive)
436
- if ($LASTEXITCODE -ne 0 -or $details.Count -ne $names.Count) { throw 'Cannot verify the Web SDK 7z entry types.' }
472
+ $details = @(Invoke-WebSdkArchiveTar $tar @('-tvf', $Archive) 'Cannot verify the Web SDK 7z entry types.')
473
+ if ($details.Count -ne $names.Count) { Stop-WebSdkInvalidArchive 'Web SDK 7z entry lists do not match.' }
437
474
  $expanded = [int64]0
438
475
  for ($i = 0; $i -lt $details.Count; $i++) {
439
476
  $line = $details[$i]
440
477
  $kind = if ($names[$i] -ceq 'Packages/') { 'd' } else { '-' }
441
478
  if (!$line.StartsWith($kind) -or !$line.EndsWith(' ' + $names[$i], [StringComparison]::Ordinal) -or
442
479
  $line -notmatch '^[d-]\S{9}\s+\d+\s+\S+\s+\S+\s+(?<bytes>\d+)\s+') {
443
- throw 'Web SDK 7z contains an unsupported entry or link.'
480
+ Stop-WebSdkInvalidArchive 'Web SDK 7z contains an unsupported entry or link.'
444
481
  }
445
482
  $expanded += [int64]$Matches.bytes
446
483
  }
447
484
  $available = [IO.DriveInfo]::new([IO.Path]::GetPathRoot($Stage)).AvailableFreeSpace
448
485
  if ($expanded -gt $available) { throw "Not enough space to unpack Web SDK 7z. Need $expanded bytes, available $available." }
449
486
  Write-Host 'Unpacking 7z release to a staging folder'
450
- & $tar -xf $Archive -C $Stage --no-same-owner --no-same-permissions
451
- if ($LASTEXITCODE -ne 0) { throw 'Windows tar could not unpack the 7z release. Use 7-Zip, then pass the Packages directory using -Packages.' }
487
+ $null = Invoke-WebSdkArchiveTar $tar @('-xf', $Archive, '-C', $Stage, '--no-same-owner', '--no-same-permissions') 'Windows tar could not unpack the 7z release.'
452
488
  $packages = Join-Path $Stage 'Packages'
453
489
  Assert-WebSdkDirectory $packages
454
490
  foreach ($name in $names) {
@@ -504,12 +540,65 @@ function Install-WebSdkFromOuterArchive {
504
540
  }
505
541
  }
506
542
 
543
+ function Get-WebSdkLatestRelease {
544
+ param($Selector)
545
+ $address = Get-WebSdkProperty $Selector 'latestVersionUrl'
546
+ if ($address -cne 'https://file.craft.qq.com/WXUPSDK/Version/LastVersion.txt') {
547
+ throw 'Use the official Web SDK latest version endpoint.'
548
+ }
549
+ $PSNativeCommandUseErrorActionPreference = $false
550
+ $curl = (Get-Command curl.exe -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1).Source
551
+ if (!$curl) { throw 'Windows curl.exe is required to discover the latest Web SDK.' }
552
+ $response = @(& $curl --disable --silent --show-error --fail --proto '=https' --connect-timeout 20 --max-time 20 --max-filesize 64 -- $address)
553
+ if ($LASTEXITCODE -ne 0) { throw "Could not read the official Web SDK latest version (curl exit $LASTEXITCODE). Retry when the connection is available." }
554
+ $version = ($response -join "`n").Trim()
555
+ if ($version.Length -gt 64 -or $version -notmatch '^\d+\.\d+\.\d+(?:\.\d+)?$') {
556
+ throw 'The official Web SDK endpoint returned an invalid release version.'
557
+ }
558
+ return [pscustomobject]@{
559
+ schemaVersion = 1; engineVersion = '5.8.4'; kitVersion = $version; latest = $true
560
+ archiveUrl = "https://file.craft.qq.com/WXUPSDK/$version/WXUPSDK_$version.7z"
561
+ }
562
+ }
563
+
564
+ function Get-WebSdkLatestPair {
565
+ param([string]$Root, [string]$KitVersion)
566
+ $candidates = @()
567
+ $current = Join-Path $Root 'current.json'
568
+ if (Test-Path -LiteralPath $current -PathType Leaf) {
569
+ $saved = Read-WebSdkJson $current 16KB
570
+ $packages = Get-WebSdkProperty $saved 'packagesRoot'
571
+ if ((Get-WebSdkProperty $saved 'kitVersion') -ceq $KitVersion -and
572
+ $packages -is [string] -and [IO.Path]::IsPathRooted($packages)) { $candidates += $packages }
573
+ }
574
+ # Recover completed installations whose final current.json update was interrupted.
575
+ $versions = Join-Path $Root 'v'
576
+ if (Test-Path -LiteralPath $versions -PathType Container) {
577
+ Assert-WebSdkDirectory $versions
578
+ foreach ($entry in (Get-ChildItem -LiteralPath $versions -Directory)) {
579
+ if ($entry.Name -match '^[0-9a-f]{16}$' -and !($entry.Attributes -band [IO.FileAttributes]::ReparsePoint)) {
580
+ $candidates += Join-Path $entry.FullName 'Packages'
581
+ }
582
+ }
583
+ }
584
+ foreach ($packages in $candidates) {
585
+ if (!(Test-Path -LiteralPath $packages -PathType Container)) { continue }
586
+ $receipt = Read-WebSdkInstallReceipt $packages
587
+ $hash = Get-WebSdkProperty $receipt 'archiveSha256'
588
+ if ((Get-WebSdkProperty $receipt 'kitVersion') -cne $KitVersion -or
589
+ $hash -isnot [string] -or $hash -notmatch '^[0-9a-fA-F]{64}$') { continue }
590
+ $pair = Get-WebSdkExistingPair $packages $null $KitVersion $hash
591
+ if ($pair) { return $pair }
592
+ }
593
+ }
594
+
507
595
  function Get-WebSdkConfiguredArchive {
508
- param([string]$Root, [uri]$Url, [string]$Hash)
596
+ param([string]$Root, [uri]$Url, [string]$Hash, [string]$KitVersion)
509
597
  $PSNativeCommandUseErrorActionPreference = $false
510
598
  $curl = (Get-Command curl.exe -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1).Source
511
599
  if (!$curl) { throw 'Windows curl.exe is required to download the configured release. Download it separately and use -Archive.' }
512
- $archive = Join-Path $Root ('.websdk-' + $Hash.ToLowerInvariant() + '.7z')
600
+ $cacheKey = if ($Hash) { $Hash.ToLowerInvariant() } else { 'version-' + $KitVersion }
601
+ $archive = Join-Path $Root ('.websdk-' + $cacheKey + '.7z')
513
602
  $partial = $archive + '.part'
514
603
  if (Test-Path -LiteralPath $archive) {
515
604
  $null = Assert-WebSdkRegularFile $archive
@@ -518,7 +607,7 @@ function Get-WebSdkConfiguredArchive {
518
607
  $resume = Test-Path -LiteralPath $partial
519
608
  if ($resume) {
520
609
  $partialFile = Assert-WebSdkRegularFile $partial
521
- if ($Hash -eq (Get-WebSdkFileHash $partial)) {
610
+ if ($Hash -and $Hash -eq (Get-WebSdkFileHash $partial)) {
522
611
  [IO.File]::Move($partial, $archive)
523
612
  return $archive
524
613
  }
@@ -537,8 +626,10 @@ function Get-WebSdkConfiguredArchive {
537
626
  }
538
627
  if ($LASTEXITCODE -ne 0) { throw "Web SDK download failed (curl exit $LASTEXITCODE). Rerun to resume, or provide a local archive with -Archive." }
539
628
  $null = Assert-WebSdkRegularFile $partial
540
- Write-Host 'Verifying the downloaded release before installation'
541
- if ($Hash -ne (Get-WebSdkFileHash $partial)) {
629
+ # Without a published outer digest, the existing installer checks the 7z and
630
+ # inner ZIP hashes. Its computed outer SHA identifies the cache, not the publisher.
631
+ Write-Host 'Checking the downloaded release before installation'
632
+ if ($Hash -and $Hash -ne (Get-WebSdkFileHash $partial)) {
542
633
  [IO.File]::Delete($partial)
543
634
  throw 'Downloaded Web SDK 7z did not match the configured SHA-256. Verify the release configuration and retry.'
544
635
  }
@@ -594,28 +685,47 @@ function Resolve-WebSdkKit {
594
685
  if ((Get-WebSdkProperty $config 'schemaVersion') -ne 1 -or (Get-WebSdkProperty $config 'engineVersion') -ne '5.8.4') {
595
686
  throw "Expected schemaVersion 1 and engineVersion 5.8.4 in '$ReleaseManifest'."
596
687
  }
688
+ if ($null -ne (Get-WebSdkProperty $config 'latestVersionUrl')) { $config = Get-WebSdkLatestRelease $config }
597
689
  $rawUrl = Get-WebSdkProperty $config 'archiveUrl'
598
690
  $hash = Get-WebSdkProperty $config 'archiveSha256'
599
691
  $kitVersion = Get-WebSdkProperty $config 'kitVersion'
692
+ $latestValue = Get-WebSdkProperty $config 'latest'
693
+ $latest = $latestValue -is [bool] -and $latestValue
600
694
  $hasRelease = $null -ne $rawUrl -or $null -ne $hash -or $null -ne $kitVersion
601
695
  $url = $null
602
696
  if ($hasRelease -and ($rawUrl -isnot [string] -or ![uri]::TryCreate($rawUrl, [UriKind]::Absolute, [ref]$url) -or
603
697
  $url.Scheme -ne 'https' -or !$url.Host -or $url.UserInfo -or
604
- $hash -isnot [string] -or $hash -notmatch '^[0-9a-fA-F]{64}$' -or
698
+ ((!$latest -or $null -ne $hash) -and ($hash -isnot [string] -or $hash -notmatch '^[0-9a-fA-F]{64}$')) -or
605
699
  $kitVersion -isnot [string] -or $kitVersion -notmatch '^\d+\.\d+\.\d+(?:\.\d+)?(?:[-+][A-Za-z0-9.-]+)?$')) {
606
700
  throw 'A download release requires a kitVersion, an HTTPS archiveUrl, and the archiveSha256 of the complete 7z.'
607
701
  }
608
- $destination = if ($hasRelease) { Get-WebSdkVersionPackagesPath $root $hash } else { $root }
609
- $installed = Get-WebSdkExistingPair $destination $null $kitVersion $hash
702
+ if ($latest -and ($kitVersion -notmatch '^\d+\.\d+\.\d+(?:\.\d+)?$' -or
703
+ $rawUrl -cne "https://file.craft.qq.com/WXUPSDK/$kitVersion/WXUPSDK_$kitVersion.7z")) {
704
+ throw 'Latest SDK releases must use the matching official versioned archive URL.'
705
+ }
706
+ $discoverHash = $latest -and !$hash
707
+ $destination = if ($hasRelease -and !$discoverHash) { Get-WebSdkVersionPackagesPath $root $hash } else { $root }
708
+ $installed = if ($discoverHash) { Get-WebSdkLatestPair $root $kitVersion }
709
+ else { Get-WebSdkExistingPair $destination $null $kitVersion $hash }
610
710
  if ($installed) { return $installed }
611
711
  if (!$hasRelease) { throw 'No compatible download release is configured. Pass an unpacked kit or ZIP directory with -Packages, or a local 7z with -Archive.' }
612
712
  if ($CheckOnly) { throw 'Web SDK still needs downloading and extraction. Run again without -CheckOnly.' }
613
713
  $lock = Enter-WebSdkInstallLock $destination
614
714
  try {
615
- $installed = Get-WebSdkExistingPair $destination $null $kitVersion $hash
715
+ $installed = if ($discoverHash) { Get-WebSdkLatestPair $root $kitVersion }
716
+ else { Get-WebSdkExistingPair $destination $null $kitVersion $hash }
616
717
  if ($installed) { return $installed }
617
- $file = Get-WebSdkConfiguredArchive $destination $url $hash
618
- $kit = Install-WebSdkFromOuterArchive $file $root $hash $kitVersion -InstallLockHeld
718
+ $file = Get-WebSdkConfiguredArchive $destination $url $hash $kitVersion
719
+ try {
720
+ $kit = Install-WebSdkFromOuterArchive $file $root $hash $kitVersion -InstallLockHeld:(!$discoverHash)
721
+ } catch {
722
+ $failure = $_
723
+ if ($discoverHash -and $failure.Exception.GetBaseException().Data['WebSdkArchiveInvalid']) {
724
+ try { [IO.File]::Delete($file) }
725
+ catch { Write-Host "Could not remove the invalid SDK download cache: $file" }
726
+ }
727
+ throw $failure
728
+ }
619
729
  try { [IO.File]::Delete($file) }
620
730
  catch { Write-Host "Web SDK installed. Could not remove the verified download cache: $file" }
621
731
  return $kit
@@ -1,9 +1,5 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "engineVersion": "5.8.4",
4
- "kitVersion": "0.1.1.13",
5
- "sdkVersion": "0.3.13",
6
- "sourceRevision": "8aeb4e10c6e6660b4d973aacd707f905a46f14be",
7
- "archiveUrl": "https://file.craft.qq.com/WXUPSDK/0.1.1.13/WXUPSDK_0.1.1.13.7z",
8
- "archiveSha256": "358edda6307e0d84d024ea2a06e6d7b6659b2897c4ce1aa6b41789eaa507fbbf"
4
+ "latestVersionUrl": "https://file.craft.qq.com/WXUPSDK/Version/LastVersion.txt"
9
5
  }