@@ -1332,6 +1332,137 @@ 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 and every .meta file an associated item.
1340
+ . PARAMETER Project
1341
+ Unity Project Instance(s) to test the meta file integrity of.
1342
+ . PARAMETER PassThru
1343
+ Output the meta file integrity issues rather than $true (no issues) or $false (at least one issue).
1344
+ . EXAMPLE
1345
+ Test-UnityProjectInstanceMetaFileIntegrity
1346
+ . EXAMPLE
1347
+ Test-UnityProjectInstanceMetaFileIntegrity -PassThru
1348
+ . EXAMPLE
1349
+ Test-UnityProjectInstanceMetaFileIntegrity .\MyUnityProject
1350
+ . EXAMPLE
1351
+ Test-UnityProjectInstanceMetaFileIntegrity -Project .\MyUnityProject
1352
+ . EXAMPLE
1353
+ Get-UnityProjectInstance -Recurse | Test-UnityProjectInstanceMetaFileIntegrity
1354
+ . EXAMPLE
1355
+ Get-UnityProjectInstance -Recurse | Test-UnityProjectInstanceMetaFileIntegrity -PassThru
1356
+ #>
1357
+ function Test-UnityProjectInstanceMetaFileIntegrity {
1358
+ [CmdletBinding (DefaultParameterSetName = " Context" )]
1359
+ param (
1360
+ [Parameter (Mandatory = $true , ValueFromPipeline = $true , Position = 0 , ParameterSetName = " Projects" )]
1361
+ [ValidateNotNullOrEmpty ()]
1362
+ [UnityProjectInstance []] $Project ,
1363
+ [switch ] $PassThru
1364
+ )
1365
+
1366
+ process {
1367
+
1368
+ switch ( $PSCmdlet.ParameterSetName ) {
1369
+ ' Context' {
1370
+ $currentFolderProject = Get-UnityProjectInstance $PWD.Path
1371
+ if ($null -ne $currentFolderProject ) {
1372
+ $Project = @ ($currentFolderProject )
1373
+ }
1374
+ }
1375
+ }
1376
+
1377
+ foreach ( $p in $Project ) {
1378
+
1379
+ $testResult = $true
1380
+
1381
+ Write-Verbose " Getting meta file integrity for project at $ ( $p.path ) "
1382
+ $assetDir = Join-Path $p.Path " Assets"
1383
+
1384
+ # get all the directories under assets
1385
+ [System.IO.DirectoryInfo []]$dirs = Get-ChildItem - Path " $assetDir /*" - Recurse - Directory - Exclude ' .*'
1386
+
1387
+ Write-Verbose " Testing asset directories for missing meta files..."
1388
+ foreach ($dir in $dirs ) {
1389
+ $testPath = " $ ( $dir.FullName ) .meta" ;
1390
+ if (Test-Path - PathType Leaf - Path $testPath ) { continue }
1391
+
1392
+ if ($PassThru ) {
1393
+ [PSCustomObject ]@ {
1394
+ ' Item' = $dir
1395
+ ' Issue' = " Directory is missing associated meta file."
1396
+ }
1397
+ }
1398
+ else {
1399
+ $testResult = $false ;
1400
+ break ;
1401
+ }
1402
+ }
1403
+
1404
+ if (-not $testResult ) { $false ; continue ; }
1405
+
1406
+ # get all the non-meta files under assets
1407
+ [System.IO.FileInfo []]$files = Get-ChildItem - Path " $assetDir /*" - Exclude ' .*' , ' *.meta' - File
1408
+ foreach ($dir in $dirs ) {
1409
+ $files += Get-ChildItem - Path " $ ( $dir.FullName ) /*" - Exclude ' .*' , ' *.meta' - File
1410
+ }
1411
+
1412
+ Write-Verbose " Testing asset files for missing meta files..."
1413
+ foreach ( $file in $files ) {
1414
+ $testPath = " $ ( $file.FullName ) .meta" ;
1415
+ if (Test-Path - PathType Leaf - Path $testPath ) { continue }
1416
+
1417
+ if ($PassThru ) {
1418
+ [PSCustomObject ]@ {
1419
+ ' Item' = $file
1420
+ ' Issue' = " File is missing associated meta file."
1421
+ }
1422
+ }
1423
+ else {
1424
+ $testResult = $false ;
1425
+ break ;
1426
+ }
1427
+ }
1428
+
1429
+ if (-not $testResult ) { $false ; continue ; }
1430
+
1431
+ $metaFileSearchArgs = @ {
1432
+ ' Exclude' = ' .*'
1433
+ ' Include' = ' *.meta'
1434
+ ' File' = $true
1435
+ ' Force' = $true # Ensure we include hidden meta files
1436
+ }
1437
+
1438
+ # get all the meta files under assets
1439
+ [System.IO.FileInfo []]$metaFiles = Get-ChildItem - Path " $assetDir /*" @metaFileSearchArgs
1440
+ foreach ($dir in $dirs ) {
1441
+ $metaFiles += Get-ChildItem - Path " $ ( $dir.FullName ) /*" @metaFileSearchArgs
1442
+ }
1443
+
1444
+ Write-Verbose " Testing meta files for missing assets..."
1445
+ foreach ($metaFile in $metaFiles ) {
1446
+ $testPath = $metaFile.FullName.SubString (0 , $metaFile.FullName.Length - $metaFile.Extension.Length );
1447
+ if (Test-Path - Path $testPath ) { continue }
1448
+
1449
+ if ($PassThru ) {
1450
+ [PSCustomObject ]@ {
1451
+ ' Item' = $metaFile
1452
+ ' Issue' = " Meta file is missing associated item."
1453
+ }
1454
+ }
1455
+ else {
1456
+ $testResult = $false ;
1457
+ break ;
1458
+ }
1459
+ }
1460
+
1461
+ if (-not $PassThru ) { $testResult ; }
1462
+ }
1463
+ }
1464
+ }
1465
+
1335
1466
<#
1336
1467
. Synopsis
1337
1468
Starts the Unity Editor
0 commit comments