@@ -6,26 +6,18 @@ if($PSVersionTable.PSVersion.Major -lt 3){
66 Write-Host " I need PowerShell major version >= 3, Current is $ ( $PSVersionTable.PSVersion.Major ) " - ForegroundColor Red
77 return
88}
9+
910$installLocation = $env: ffdir
10- if ([string ]::IsNullOrEmpty($installLocation )){
11- $installLocation = (Resolve-Path .\).Path
12- }
13- Write-Host " Current install location is $installLocation "
14- if ((Test-Path $installLocation )){
15- if (-Not ((Get-ChildItem $installLocation | Measure-Object ).Count -eq 0 )){
16- Write-Host ' I need an empty folder!' - ForegroundColor Red
17- return
18- }
19- }
20- else {
21- Write-Host " Create directory $installLocation " - ForegroundColor Yellow
22- New-Item - ItemType Directory - Force - Path $installLocation | Out-Null
23- }
2411$local = $env: ffloc
12+ $arch = $env: ffarch
13+ $branch = $env: ffbranch
14+ $url = ' https://www.mozilla.org/en-US/firefox/channel/desktop/'
15+
16+ # $local check
2517if ([string ]::IsNullOrEmpty($local )){
2618 $local = (Get-UICulture ).Name
2719}
28- $arch = $ env: ffarch
20+ # $arch check
2921if ([string ]::IsNullOrEmpty($arch )){
3022 if ($ENV: PROCESSOR_ARCHITECTURE -eq ' AMD64' ){
3123 $arch = ' win64'
@@ -34,18 +26,39 @@ if ([string]::IsNullOrEmpty($arch)){
3426 $arch = ' win'
3527 }
3628}
37- $branch = $ env: ffbranch
29+ # $branch check
3830switch ($branch )
3931{
32+ ' nightly' {$branch = ' firefox-nightly-latest-l10n' }
33+ ' dev' {$branch = ' firefox-devedition-latest' }
4034 ' beta' {$branch = ' firefox-beta-latest' }
4135 ' esr' {$branch = ' firefox-esr-latest' }
4236 default {$branch = ' firefox-latest' }
4337}
4438Write-Host " Current branch is $branch " - ForegroundColor Yellow
45- $url = " https://download.mozilla.org/?product=$branch &os=$arch &lang=$local "
46- $downloadFileName = Join-Path $installLocation ' installer.exe'
39+ $url = " https://download.mozilla.org/?product=$branch -ssl&os=$arch &lang=$local "
4740if ($env: TEMP -eq $null ) {
48- $env: TEMP = Join-Path $installLocation ' temp'
41+ $env: TEMP = Join-Path $installLocation ' temp'
42+ }
43+ # $installLocation check
44+ if ([string ]::IsNullOrEmpty($installLocation )){
45+ $installLocation = (Resolve-Path .\).Path
46+ }
47+
48+ function Check-InstallLocation {
49+
50+ Write-Host " Current install location is $installLocation "
51+ if ((Test-Path $installLocation )){
52+ if (-Not ((Get-ChildItem $installLocation | Measure-Object ).Count -eq 0 )){
53+ Write-Host ' I need an empty folder!' - ForegroundColor Red
54+ return $false
55+ }
56+ }
57+ else {
58+ Write-Host " Create directory $installLocation " - ForegroundColor Yellow
59+ New-Item - ItemType Directory - Force - Path $installLocation | Out-Null
60+ }
61+ return $true
4962}
5063
5164function Get-Downloader {
@@ -161,18 +174,27 @@ param (
161174 }
162175}
163176
164- Download- File $url $downloadFileName
165- if (-Not (Test-Path $installLocation )){
166- return
177+ function Download-Firefox {
178+ $downloadFileName = Join-Path $installLocation ' installer.exe'
179+ Download- File $url $downloadFileName
180+ if (-Not (Test-Path $downloadFileName )){
181+ Write-Host ' Firefox Download Fail!' - ForegroundColor Red
182+ return
183+ }
184+ Extract- File $downloadFileName $installLocation
185+ Remove-IfExists " $installLocation \setup.exe"
186+ Move-Item " $installLocation \core\*" - Destination $installLocation
187+ Remove-IfExists " $installLocation \core"
188+ Remove-IfExists $downloadFileName
189+ Write-Host ' Firefox Download Finished' - ForegroundColor Green
167190}
168- Extract- File $downloadFileName $installLocation
169- Remove-IfExists " $installLocation \setup.exe"
170- Move-Item " $installLocation \core\*" - Destination $installLocation
171- Remove-IfExists " $installLocation \core"
172- Remove-IfExists $downloadFileName
173-
174- Write-Host ' Firefox Download Finished' - ForegroundColor Green
175191
192+ if (Check- InstallLocation) {
193+ Download- Firefox
194+ }
195+ else {
196+ Write-Host ' Firefox Download Skipped' - ForegroundColor Yellow
197+ }
176198
177199$JSON = Download- String ' https://static.pzhacm.org/shuax/fd/fd.json' | ConvertFrom-Json
178200if ([string ]::IsNullOrEmpty($JSON.description )){
0 commit comments