From 7c8ee2a9f447a1e7de21a0cc8daa16c1e82e765e Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Wed, 3 Aug 2022 14:49:58 -1000 Subject: [PATCH 1/2] Catch json parse error, generalize to hashtable to bypass key overlap issue --- UnitySetup/UnitySetup.psm1 | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index a7cb3c8..f6ea554 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1245,16 +1245,20 @@ function Get-UnitySetupInstanceVersion { # Try to look in the modules.json file for installer paths that contain version info if ( Test-Path "$path\modules.json" -PathType Leaf ) { + try { + Write-Verbose "Searching $path\modules.json for module versions" + $table = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json -AsHashtable - Write-Verbose "Searching $path\modules.json for module versions" - $modules = (Get-Content "$path\modules.json" -Raw) | ConvertFrom-Json - - foreach ( $module in $modules ) { - Write-Verbose "`tTesting DownloadUrl $($module.DownloadUrl)" - if ( $module.DownloadUrl -notmatch "(\d+)\.(\d+)\.(\d+)([fpab])(\d+)" ) { continue; } + foreach ( $url in $table.downloadUrl ) { + Write-Debug "`tTesting DownloadUrl $url" + if ( $url -notmatch "(\d+)\.(\d+)\.(\d+)([fpab])(\d+)" ) { continue; } - Write-Verbose "`tFound version!" - return [UnityVersion]$Matches[0] + Write-Verbose "`tFound version!" + return [UnityVersion]$Matches[0] + } + } + catch { + Write-Verbose "Error parsing $path\modules.json:`n`t$_" } } From e101fff24acab7b391119647505a0faa3ed254fa Mon Sep 17 00:00:00 2001 From: Josh Wittner Date: Wed, 19 Oct 2022 17:19:15 -0700 Subject: [PATCH 2/2] Update filters for asset gathering --- UnitySetup/UnitySetup.psm1 | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/UnitySetup/UnitySetup.psm1 b/UnitySetup/UnitySetup.psm1 index f6ea554..4edaa6a 100644 --- a/UnitySetup/UnitySetup.psm1 +++ b/UnitySetup/UnitySetup.psm1 @@ -1468,6 +1468,9 @@ function Test-UnityProjectInstanceMetaFileIntegrity { } } + # Derived from https://docs.unity3d.com/Manual/SpecialFolders.html + $unityAssetExcludes = @('.*', '*~', 'cvs', '*.tmp') + foreach ( $p in $Project) { $testResult = $true @@ -1476,17 +1479,20 @@ function Test-UnityProjectInstanceMetaFileIntegrity { $assetDir = Join-Path $p.Path "Assets" # get all the directories under assets - [System.IO.DirectoryInfo[]]$dirs = Get-ChildItem -Path "$assetDir/*" -Recurse -Directory -Exclude '.*' + [System.IO.DirectoryInfo[]]$dirs = + Get-ChildItem -Path "$assetDir/*" -Recurse -Directory -Exclude $unityAssetExcludes Write-Verbose "Testing asset directories for missing meta files..." [float]$progressCounter = 0 foreach ($dir in $dirs) { + ++$progressCounter $progress = @{ 'Activity' = "Testing directories for missing meta files" - 'Status' = $dir - 'PercentComplete' = (((++$progressCounter) / $dirs.Length) * 100) + 'Status' = "$progressCounter / $($dirs.Length) - $dir" + 'PercentComplete' = (($progressCounter / $dirs.Length) * 100) } + Write-Debug $progress.Status Write-Progress @progress $testPath = "$($dir.FullName).meta"; @@ -1507,20 +1513,24 @@ function Test-UnityProjectInstanceMetaFileIntegrity { if (-not $testResult) { $false; continue; } # get all the non-meta files under assets - [System.IO.FileInfo[]]$files = Get-ChildItem -Path "$assetDir/*" -Exclude '.*', '*.meta' -File + $unityAssetFileExcludes = $unityAssetExcludes + '*.meta' + [System.IO.FileInfo[]]$files = Get-ChildItem -Path "$assetDir/*" -Exclude $unityAssetFileExcludes -File foreach ($dir in $dirs) { - $files += Get-ChildItem -Path "$($dir.FullName)/*" -Exclude '.*', '*.meta' -File + $files += Get-ChildItem -Path "$($dir.FullName)/*" -Exclude $unityAssetFileExcludes -File } Write-Verbose "Testing asset files for missing meta files..." $progressCounter = 0 foreach ( $file in $files ) { + ++$progressCounter $progress = @{ 'Activity' = "Testing files for missing meta files" - 'Status' = $file - 'PercentComplete' = (((++$progressCounter) / $files.Length) * 100) + 'Status' = "$progressCounter / $($files.Length) - $file" + 'PercentComplete' = (($progressCounter / $files.Length) * 100) + } + Write-Debug $progress.Status Write-Progress @progress $testPath = "$($file.FullName).meta"; @@ -1541,7 +1551,7 @@ function Test-UnityProjectInstanceMetaFileIntegrity { if (-not $testResult) { $false; continue; } $metaFileSearchArgs = @{ - 'Exclude' = '.*' + 'Exclude' = $unityAssetExcludes 'Include' = '*.meta' 'File' = $true 'Force' = $true # Ensure we include hidden meta files @@ -1557,11 +1567,13 @@ function Test-UnityProjectInstanceMetaFileIntegrity { $progressCounter = 0 foreach ($metaFile in $metaFiles) { + ++$progressCounter $progress = @{ 'Activity' = "Testing meta files for missing assets" - 'Status' = $metaFile - 'PercentComplete' = (((++$progressCounter) / $metaFiles.Length) * 100) + 'Status' = "$progressCounter / $($metaFiles.Length) - $metaFile" + 'PercentComplete' = (($progressCounter / $metaFiles.Length) * 100) } + Write-Debug $progress.Status Write-Progress @progress $testPath = $metaFile.FullName.SubString(0, $metaFile.FullName.Length - $metaFile.Extension.Length); @@ -1586,11 +1598,13 @@ function Test-UnityProjectInstanceMetaFileIntegrity { $progressCounter = 0 foreach ($metaFile in $metaFiles) { + ++$progressCounter $progress = @{ 'Activity' = "Testing meta files for guid collisions" - 'Status' = $metaFile - 'PercentComplete' = (((++$progressCounter) / $metaFiles.Length) * 100) + 'Status' = "$progressCounter / $($metaFiles.Length) - $metaFile" + 'PercentComplete' = (($progressCounter / $metaFiles.Length) * 100) } + Write-Debug $progress.Status Write-Progress @progress try {