Skip to content

Commit

Permalink
support v24.05 or earilier
Browse files Browse the repository at this point in the history
  • Loading branch information
Fixstars-momoko committed Jul 22, 2024
1 parent 627d527 commit f5ea0fb
Showing 1 changed file with 79 additions and 4 deletions.
83 changes: 79 additions & 4 deletions installer/tools/installer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,65 @@ function Get-LatestVersion {



function CheckSDKVersion(){
param(
[string]$sdkversion
)

try {
# Write-Host "https://github.com/$repositoryName/releases/$sdkversion"
$response = Invoke-WebRequest -Uri "https://github.com/$repositoryName/releases/$sdkversion" -ErrorAction Stop

if ($response.StatusCode -ne 200){
Write-Error "Version $sdkversion does not exist"
exit 1
}

} catch {
Write-Error "Version $sdkversion does not exist"
exit 1
}
}



function InstallEarlierVersion(){
param(
[string]$sdkversion,
[bool]$InstallOpenCV,
[string]$referenceVersion = "v24.05.99"
)

$versionToCheck = $sdkversion.TrimStart('v')
$referenceVersion = $referenceVersion.TrimStart('v')

$versionParts = $versionToCheck.Split('.') | ForEach-Object { [int]$_ }
$referenceParts = $referenceVersion.Split('.') | ForEach-Object { [int]$_ }

for ($i = 0; $i -lt $versionParts.Length; $i++) {
if ($versionParts[$i] -lt $referenceParts[$i]) {
try {
$prevInstallerURL = "${baseUrl}${version}/installer.ps1"
$prevInstallerPath = "$tempWorkDir/old_installer.ps1"
Invoke-WebRequest -Uri $prevInstallerURL -OutFile $prevInstallerPath
& $prevInstallerPath -version:$sdkversion -InstallOpenCV:$InstallOpenCV -user:$Env:UserName
return $true
} catch {
Write-Error "Failed to download $sdkversion"
exit 1
}

} elseif ($versionParts[$i] -gt $referenceParts[$i]) {
return $false
}
}



}



function CheckComponentHash(){
param(
[string]$compName,
Expand Down Expand Up @@ -355,6 +414,7 @@ function Invoke-Script {
################################################################################
# Get Version & config of components
################################################################################
# mainly for debug purpose (using config_Windows.json to specify versions)
$configFileName = "config_Windows.json"
if ($configPath){
Write-Verbose "Found local $configFileName = $configPath"
Expand All @@ -372,16 +432,31 @@ function Invoke-Script {
}
}

# suggested installation (w/ or w/o version setting)
if (-not $version) {
$version = Get-LatestVersion
}else{
CheckSDKVersion -sdkversion $version
}

Write-Host "Sensing-Dev $version will be installed." -ForegroundColor Green
$installed = InstallEarlierVersion -sdkversion $version
if ( $installed ){
Write-Host "Install successfully."
}
# Exit here if earlier version is installed.

if (-not $configPath){
$configURL = "${baseUrl}${version}/$configFileName"
$configPath = "$tempWorkDir/$configFileName"
Invoke-WebRequest -Uri $configURL -OutFile $configPath
$content = Get-ConfigContent -configPath $configPath
try{
$configURL = "${baseUrl}${version}/$configFileName"
$configPath = "$tempWorkDir/$configFileName"
Invoke-WebRequest -Uri $configURL -OutFile $configPath
$content = Get-ConfigContent -configPath $configPath
} catch {
Write-Error "Failed to obtain $configFileName of $version"
exit 1
}

}

################################################################################
Expand Down

0 comments on commit f5ea0fb

Please sign in to comment.