Skip to content

Commit 7e9ebb7

Browse files
authored
Merge pull request #44 from jwittner/dev/findInstallerUpgrades
Search all known hosts, support multiple template patterns
2 parents b1da70c + 06bd49d commit 7e9ebb7

File tree

1 file changed

+57
-33
lines changed

1 file changed

+57
-33
lines changed

UnitySetup/UnitySetup.psm1

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,30 @@ function Find-UnitySetupInstaller
157157
[UnitySetupComponentType] $Components = [UnitySetupComponentType]::All
158158
)
159159

160+
$unitySetupRegEx = "^(.+)\/([a-z0-9]+)\/Windows64EditorInstaller\/UnitySetup64-(\d+)\.(\d+)\.(\d+)([fpb])(\d+).exe$"
161+
$knownBaseUrls = @(
162+
"https://download.unity3d.com/download_unity",
163+
"https://netstorage.unity3d.com/unity",
164+
"https://beta.unity3d.com/download"
165+
)
166+
160167
$installerTemplates = @{
161-
[UnitySetupComponentType]::Setup = "Windows64EditorInstaller/UnitySetup64-$Version.exe";
162-
[UnitySetupComponentType]::Documentation = "WindowsDocumentationInstaller/UnityDocumentationSetup-$Version.exe";
163-
[UnitySetupComponentType]::StandardAssets = "WindowsStandardAssetsInstaller/UnityStandardAssetsSetup-$Version.exe";
164-
[UnitySetupComponentType]::ExampleProject = "WindowsExampleProjectInstaller/UnityExampleProjectSetup-$Version.exe";
165-
[UnitySetupComponentType]::Metro = "TargetSupportInstaller/UnitySetup-Metro-Support-for-Editor-$Version.exe";
166-
[UnitySetupComponentType]::UWP_IL2CPP = "TargetSupportInstaller/UnitySetup-UWP-IL2CPP-Support-for-Editor-$Version.exe";
167-
[UnitySetupComponentType]::Android = "TargetSupportInstaller/UnitySetup-Android-Support-for-Editor-$Version.exe";
168-
[UnitySetupComponentType]::iOS = "TargetSupportInstaller/UnitySetup-iOS-Support-for-Editor-$Version.exe";
169-
[UnitySetupComponentType]::AppleTV = "TargetSupportInstaller/UnitySetup-AppleTV-Support-for-Editor-$Version.exe";
170-
[UnitySetupComponentType]::Facebook = "TargetSupportInstaller/UnitySetup-Facebook-Games-Support-for-Editor-$Version.exe";
171-
[UnitySetupComponentType]::Linux = "TargetSupportInstaller/UnitySetup-Linux-Support-for-Editor-$Version.exe";
172-
[UnitySetupComponentType]::Mac = "TargetSupportInstaller/UnitySetup-Mac-Mono-Support-for-Editor-$Version.exe";
173-
[UnitySetupComponentType]::Vuforia = "TargetSupportInstaller/UnitySetup-Vuforia-AR-Support-for-Editor-$Version.exe";
174-
[UnitySetupComponentType]::WebGL = "TargetSupportInstaller/UnitySetup-WebGL-Support-for-Editor-$Version.exe";
175-
[UnitySetupComponentType]::Windows_IL2CPP = "TargetSupportInstaller/UnitySetup-Windows-IL2CPP-Support-for-Editor-$Version.exe";
168+
[UnitySetupComponentType]::Setup = ,"Windows64EditorInstaller/UnitySetup64-$Version.exe";
169+
[UnitySetupComponentType]::Documentation = ,"WindowsDocumentationInstaller/UnityDocumentationSetup-$Version.exe";
170+
[UnitySetupComponentType]::StandardAssets = ,"WindowsStandardAssetsInstaller/UnityStandardAssetsSetup-$Version.exe";
171+
[UnitySetupComponentType]::ExampleProject = ,"WindowsExampleProjectInstaller/UnityExampleProjectSetup-$Version.exe";
172+
[UnitySetupComponentType]::Metro = ,"TargetSupportInstaller/UnitySetup-Metro-Support-for-Editor-$Version.exe";
173+
[UnitySetupComponentType]::UWP_IL2CPP = ,"TargetSupportInstaller/UnitySetup-UWP-IL2CPP-Support-for-Editor-$Version.exe";
174+
[UnitySetupComponentType]::Android = ,"TargetSupportInstaller/UnitySetup-Android-Support-for-Editor-$Version.exe";
175+
[UnitySetupComponentType]::iOS = ,"TargetSupportInstaller/UnitySetup-iOS-Support-for-Editor-$Version.exe";
176+
[UnitySetupComponentType]::AppleTV = ,"TargetSupportInstaller/UnitySetup-AppleTV-Support-for-Editor-$Version.exe";
177+
[UnitySetupComponentType]::Facebook = ,"TargetSupportInstaller/UnitySetup-Facebook-Games-Support-for-Editor-$Version.exe";
178+
[UnitySetupComponentType]::Linux = ,"TargetSupportInstaller/UnitySetup-Linux-Support-for-Editor-$Version.exe";
179+
[UnitySetupComponentType]::Mac = "TargetSupportInstaller/UnitySetup-Mac-Support-for-Editor-$Version.exe",
180+
"TargetSupportInstaller/UnitySetup-Mac-Mono-Support-for-Editor-$Version.exe";
181+
[UnitySetupComponentType]::Vuforia = ,"TargetSupportInstaller/UnitySetup-Vuforia-AR-Support-for-Editor-$Version.exe";
182+
[UnitySetupComponentType]::WebGL = ,"TargetSupportInstaller/UnitySetup-WebGL-Support-for-Editor-$Version.exe";
183+
[UnitySetupComponentType]::Windows_IL2CPP = ,"TargetSupportInstaller/UnitySetup-Windows-IL2CPP-Support-for-Editor-$Version.exe";
176184
}
177185

178186
# By default Tls12 protocol is not enabled, but is what backs Unity's website, so enable it
@@ -217,30 +225,46 @@ function Find-UnitySetupInstaller
217225
throw "Could not find archives for Unity version $Version"
218226
}
219227

220-
$prototypeLink = $prototypeLink.Replace("$($installerTemplates[[UnitySetupComponentType]::Setup])", '')
228+
$linkComponents = $prototypeLink -split $unitySetupRegEx -ne ""
229+
230+
if($knownBaseUrls -notcontains $linkComponents[0]) {
231+
$knownBaseUrls = $linkComponents[0], $knownBaseUrls
232+
}
233+
else {
234+
$knownBaseUrls = $knownBaseUrls | Sort-Object -Property @{ Expression={[math]::Abs(($_.CompareTo($linkComponents[0])))}; Ascending=$true}
235+
}
221236

222237
$installerTemplates.Keys |
223238
Where-Object { $Components -band $_ } |
224239
ForEach-Object {
225-
$template = $installerTemplates.Item($_);
226-
$endpoint = [System.IO.Path]::Combine($prototypeLink, $template);
227-
try
228-
{
229-
$testResult = Invoke-WebRequest $endpoint -Method HEAD
230-
New-Object UnitySetupInstaller -Property @{
231-
'ComponentType' = $_;
232-
'Version' = $Version;
233-
'DownloadUrl' = $endpoint;
234-
'Length' = [int64]$testResult.Headers['Content-Length'];
235-
'LastModified' = ([System.DateTime]$testResult.Headers['Last-Modified']);
240+
$templates = $installerTemplates.Item($_);
241+
$result = $null
242+
foreach ($template in $templates ) {
243+
foreach ( $baseUrl in $knownBaseUrls) {
244+
$endpoint = [uri][System.IO.Path]::Combine($baseUrl, $linkComponents[1], $template);
245+
try {
246+
$testResult = Invoke-WebRequest $endpoint -Method HEAD
247+
$result = New-Object UnitySetupInstaller -Property @{
248+
'ComponentType' = $_;
249+
'Version' = $Version;
250+
'DownloadUrl' = $endpoint;
251+
'Length' = [int64]$testResult.Headers['Content-Length'];
252+
'LastModified' = ([System.DateTime]$testResult.Headers['Last-Modified']);
253+
}
254+
255+
break
256+
}
257+
catch {
258+
Write-Verbose "$endpoint failed: $_"
259+
}
260+
}
261+
262+
if( $result ) {
263+
$result
264+
break
236265
}
237266
}
238-
catch
239-
{
240-
Write-Verbose "$endpoint failed: $_"
241-
}
242-
} |
243-
Sort-Object -Property ComponentType
267+
} | Sort-Object -Property ComponentType
244268
}
245269

246270
<#

0 commit comments

Comments
 (0)