@@ -1332,6 +1332,209 @@ function Get-UnityProjectInstance {
1332
1332
}
1333
1333
}
1334
1334
1335
+ <#
1336
+ . Synopsis
1337
+ Tests the meta file integrity of the Unity Project Instance(s).
1338
+ . DESCRIPTION
1339
+ Tests if every item under assets has an associated .meta file
1340
+ and every .meta file an associated item
1341
+ and that none of the meta file guids collide.
1342
+ . PARAMETER Project
1343
+ Unity Project Instance(s) to test the meta file integrity of.
1344
+ . PARAMETER PassThru
1345
+ Output the meta file integrity issues rather than $true (no issues) or $false (at least one issue).
1346
+ . EXAMPLE
1347
+ Test-UnityProjectInstanceMetaFileIntegrity
1348
+ . EXAMPLE
1349
+ Test-UnityProjectInstanceMetaFileIntegrity -PassThru
1350
+ . EXAMPLE
1351
+ Test-UnityProjectInstanceMetaFileIntegrity .\MyUnityProject
1352
+ . EXAMPLE
1353
+ Test-UnityProjectInstanceMetaFileIntegrity -Project .\MyUnityProject
1354
+ . EXAMPLE
1355
+ Get-UnityProjectInstance -Recurse | Test-UnityProjectInstanceMetaFileIntegrity
1356
+ . EXAMPLE
1357
+ Get-UnityProjectInstance -Recurse | Test-UnityProjectInstanceMetaFileIntegrity -PassThru
1358
+ #>
1359
+ function Test-UnityProjectInstanceMetaFileIntegrity {
1360
+ [CmdletBinding (DefaultParameterSetName = " Context" )]
1361
+ param (
1362
+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , Position = 0 , ParameterSetName = " Projects" )]
1363
+ [ValidateNotNullOrEmpty ()]
1364
+ [UnityProjectInstance []] $Project ,
1365
+ [switch ] $PassThru
1366
+ )
1367
+
1368
+ process {
1369
+
1370
+ switch ( $PSCmdlet.ParameterSetName ) {
1371
+ ' Context' {
1372
+ $currentFolderProject = Get-UnityProjectInstance $PWD.Path
1373
+ if ($null -ne $currentFolderProject ) {
1374
+ $Project = @ ($currentFolderProject )
1375
+ }
1376
+ }
1377
+ }
1378
+
1379
+ foreach ( $p in $Project ) {
1380
+
1381
+ $testResult = $true
1382
+
1383
+ Write-Verbose " Getting meta file integrity for project at $ ( $p.path ) "
1384
+ $assetDir = Join-Path $p.Path " Assets"
1385
+
1386
+ # get all the directories under assets
1387
+ [System.IO.DirectoryInfo []]$dirs = Get-ChildItem - Path " $assetDir /*" - Recurse - Directory - Exclude ' .*'
1388
+
1389
+ Write-Verbose " Testing asset directories for missing meta files..."
1390
+ [float ]$progressCounter = 0
1391
+ foreach ($dir in $dirs ) {
1392
+
1393
+ $progress = @ {
1394
+ ' Activity' = " Testing directories for missing meta files"
1395
+ ' Status' = $dir
1396
+ ' PercentComplete' = (((++ $progressCounter ) / $dirs.Length ) * 100 )
1397
+ }
1398
+ Write-Progress @progress
1399
+
1400
+ $testPath = " $ ( $dir.FullName ) .meta" ;
1401
+ if (Test-Path - PathType Leaf - Path $testPath ) { continue }
1402
+
1403
+ if ($PassThru ) {
1404
+ [PSCustomObject ]@ {
1405
+ ' Item' = $dir
1406
+ ' Issue' = " Directory is missing associated meta file."
1407
+ }
1408
+ }
1409
+ else {
1410
+ $testResult = $false ;
1411
+ break ;
1412
+ }
1413
+ }
1414
+
1415
+ if (-not $testResult ) { $false ; continue ; }
1416
+
1417
+ # get all the non-meta files under assets
1418
+ [System.IO.FileInfo []]$files = Get-ChildItem - Path " $assetDir /*" - Exclude ' .*' , ' *.meta' - File
1419
+ foreach ($dir in $dirs ) {
1420
+ $files += Get-ChildItem - Path " $ ( $dir.FullName ) /*" - Exclude ' .*' , ' *.meta' - File
1421
+ }
1422
+
1423
+ Write-Verbose " Testing asset files for missing meta files..."
1424
+ $progressCounter = 0
1425
+ foreach ( $file in $files ) {
1426
+
1427
+ $progress = @ {
1428
+ ' Activity' = " Testing files for missing meta files"
1429
+ ' Status' = $file
1430
+ ' PercentComplete' = (((++ $progressCounter ) / $files.Length ) * 100 )
1431
+ }
1432
+ Write-Progress @progress
1433
+
1434
+ $testPath = " $ ( $file.FullName ) .meta" ;
1435
+ if (Test-Path - PathType Leaf - Path $testPath ) { continue }
1436
+
1437
+ if ($PassThru ) {
1438
+ [PSCustomObject ]@ {
1439
+ ' Item' = $file
1440
+ ' Issue' = " File is missing associated meta file."
1441
+ }
1442
+ }
1443
+ else {
1444
+ $testResult = $false ;
1445
+ break ;
1446
+ }
1447
+ }
1448
+
1449
+ if (-not $testResult ) { $false ; continue ; }
1450
+
1451
+ $metaFileSearchArgs = @ {
1452
+ ' Exclude' = ' .*'
1453
+ ' Include' = ' *.meta'
1454
+ ' File' = $true
1455
+ ' Force' = $true # Ensure we include hidden meta files
1456
+ }
1457
+
1458
+ # get all the meta files under assets
1459
+ [System.IO.FileInfo []]$metaFiles = Get-ChildItem - Path " $assetDir /*" @metaFileSearchArgs
1460
+ foreach ($dir in $dirs ) {
1461
+ $metaFiles += Get-ChildItem - Path " $ ( $dir.FullName ) /*" @metaFileSearchArgs
1462
+ }
1463
+
1464
+ Write-Verbose " Testing meta files for missing assets..."
1465
+ $progressCounter = 0
1466
+ foreach ($metaFile in $metaFiles ) {
1467
+
1468
+ $progress = @ {
1469
+ ' Activity' = " Testing meta files for missing assets"
1470
+ ' Status' = $metaFile
1471
+ ' PercentComplete' = (((++ $progressCounter ) / $metaFiles.Length ) * 100 )
1472
+ }
1473
+ Write-Progress @progress
1474
+
1475
+ $testPath = $metaFile.FullName.SubString (0 , $metaFile.FullName.Length - $metaFile.Extension.Length );
1476
+ if (Test-Path - Path $testPath ) { continue }
1477
+
1478
+ if ($PassThru ) {
1479
+ [PSCustomObject ]@ {
1480
+ ' Item' = $metaFile
1481
+ ' Issue' = " Meta file is missing associated item."
1482
+ }
1483
+ }
1484
+ else {
1485
+ $testResult = $false ;
1486
+ break ;
1487
+ }
1488
+ }
1489
+
1490
+ if (-not $testResult ) { $false ; continue ; }
1491
+
1492
+ Write-Verbose " Testing meta files for guid collisions..."
1493
+ $metaGuids = @ { }
1494
+ $progressCounter = 0
1495
+ foreach ($metaFile in $metaFiles ) {
1496
+
1497
+ $progress = @ {
1498
+ ' Activity' = " Testing meta files for guid collisions"
1499
+ ' Status' = $metaFile
1500
+ ' PercentComplete' = (((++ $progressCounter ) / $metaFiles.Length ) * 100 )
1501
+ }
1502
+ Write-Progress @progress
1503
+
1504
+ try {
1505
+ $guidResult = Get-Content $metaFile.FullName | Select-String - Pattern ' ^guid:\s*([a-z,A-Z,\d]+)\s*$'
1506
+ if ($guidResult.Matches.Groups.Length -lt 2 ) {
1507
+ Write-Warning " Could not find guid in meta file - $metaFile "
1508
+ continue ;
1509
+ }
1510
+
1511
+ $guid = $guidResult.Matches.Groups [1 ].Value
1512
+ if ($null -eq $metaGuids [$guid ]) {
1513
+ $metaGuids [$guid ] = $metaFile ;
1514
+ continue
1515
+ }
1516
+
1517
+ if ($PassThru ) {
1518
+ [PSCustomObject ]@ {
1519
+ ' Item' = $metaFile
1520
+ ' Issue' = " Meta file guid collision with $ ( $metaGuids [$guid ]) "
1521
+ }
1522
+ }
1523
+ else {
1524
+ $testResult = $false ;
1525
+ break ;
1526
+ }
1527
+ }
1528
+ catch {
1529
+ Write-Error " Exception testing guid of $metaFile - $_ "
1530
+ }
1531
+ }
1532
+
1533
+ if (-not $PassThru ) { $testResult ; }
1534
+ }
1535
+ }
1536
+ }
1537
+
1335
1538
<#
1336
1539
. Synopsis
1337
1540
Starts the Unity Editor
0 commit comments