-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvancedADBinstaller.ps1
564 lines (486 loc) · 14.9 KB
/
vancedADBinstaller.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
[CmdletBinding()]
param(
[ValidateSet('usb', 'wifi')]
$adb,
[ValidateSet('dark', 'black')]
$theme,
[ValidateSet('stable', 'beta')]
$channel,
[switch]$latest,
[switch]$uninstall,
[switch]$saveDownloads
)
$msgTable = Data {
#culture="en-US"
ConvertFrom-StringData @'
deviceÑonnected = The device is connected
attachDevice = Connect the device and enable USB debugging in the developer settings
allowÑonnection = Allow connection
unexpectedError = Unexpected error
wasWIFIused = Is there {0}:{1} in the list of connected devices?
wifiWasNotUsed = No. The device has not been paired before
wifiWasUsed = Yes. I used Wi-Fi debugging earlier
startÑonnection = Start connection
enterAddr = Enter the address
portMsg = The connection port may differ from the pairing port
enterPort = Enter the port
badAddrOrPort = Wrong IP address or port
keepOldValue = Press Enter to save the old value
badPort = Wrong port
notPaired = Paired was not performed
startPairing = Start pairing
enterPswd = Enter the password
successfullyPaired = The device is paired
selectVersion = Select a version:
installed = (installed)
latest = (latest)
failedDel = failed to uninstall
deleted = uninstall
noInternet = There is no internet connection or the server is unavailable
adbOver = Select the connection method:
adbOverUSB = via USB
adbOverWIFI = via WiFi (for Android 11 and above)
arch = Device architecture:
language = System language
installedVersion = Installed version
themeRequest = Ñhoose theme:
themeDark = Dark (default)
themeBlack = Black (recommended for AMOLED)
channelRequest = Select a channel:
channelStable = Stable
channelBeta = Beta
allowInstall = Allow installation on the device
failedInstall = Failed to install
noSuchFile = No such file or directory
uninstallAndRepeat = Try deleting and repeat
isInstalled = is installed
openLink = Vanced is default application for links to youtube.com
'@
}
Import-LocalizedData -BindingVariable msgTable
function usbADB
{
while($True)
{
Invoke-Expression ".\adb.exe get-state device" -OutVariable output -ErrorVariable errors | Out-Null
if ($output -eq "device")
{
Write-Host $msgTable.deviceÑonnected -ForegroundColor Green
break
}
else
{
if (($errors | Select-String "error: no devices/emulators found" ) -or
($errors | Select-String "error: device offline") -or
($errors | Select-String "error: no devices found"))
{
Write-Host $msgTable.attachDevice
}
elseif ($errors | Select-String "error: device unauthorized" )
{
Write-Host $msgTable.allowÑonnection
}
elseif ($errors | Select-String "error: more than one device/emulator")
{
Invoke-Expression ".\adb.exe kill-server" -OutVariable output -ErrorVariable errors | Out-Null
}
else
{
Write-Host $msgTable.unexpectedError -ForegroundColor Red
}
}
pause
}
}
function wirelessADB
{
Write-Host ($msgTable.wasWIFIused -f $env:UserName, $env:COMPUTERNAME) -ForegroundColor Yellow
Write-Host "1:"$msgTable.wifiWasNotUsed
Write-Host "2:"$msgTable.wifiWasUsed
while($True)
{
$choice = Read-Host
if($choice -eq 1)
{
$pair = 1
break
}
if($choice -eq 1)
{
$pair = 0
break
}
}
if ($pair){
pairWirelessADB(0)
}
Write-Host $msgTable.startÑonnection
if ($pair -eq 0)
{
Write-Host $msgTable.enterAddr
$addr = Read-Host
}
if ($pair)
{
Write-Host $msgTable.portMsg -ForegroundColor Green
}
Write-Host $msgTable.enterPort
$port = Read-Host
while($True)
{
$adb = ".\adb.exe connect {0}:{1}" -f $addr, $port
Invoke-Expression $adb -OutVariable output -ErrorVariable errors | Out-Null
if ($output | Select-String "connected to"){
Write-Host $msgTable.deviceÑonnected -ForegroundColor Green
break
}
else
{
if (($output | Select-String "cannot connect to") -or
($output | Select-String "cannot resolve host"))
{
Write-Host $msgTable.badAddrOrPort -ForegroundColor Red
Write-Host $msgTable.keepOldValue -ForegroundColor Green
Write-Host $msgTable.enterAddr
if ($value = Read-Host $addr) { $addr = $value }
Write-Host $msgTable.enterPort
if ($value = Read-Host $port) { $port = $value }
}
elseif ($output | Select-String "bad port number")
{
Write-Host $msgTable.badPort -ForegroundColor Red
Write-Host $msgTable.enterPort
if ($value = Read-Host $port) { $port = $value }
}
elseif ($output | Select-String "failed to connect to")
{
Write-Host $msgTable.notPaired -ForegroundColor Red
pairWirelessADB($addr)
}
else
{
Write-Host $msgTable.unexpectedError -ForegroundColor Red
exit
}
}
}
}
function pairWirelessADB($addr2)
{
Write-Host $msgTable.startPairing
if($addr2 -eq 0){
Write-Host $msgTable.enterAddr
$addr = Read-Host}
else{
$addr = $addr2
}
Write-Host $msgTable.enterPort
$port = Read-Host
Write-Host $msgTable.enterPswd
$pswd = Read-Host
while($True)
{
$adb = ".\adb.exe pair {0}:{1} {2}" -f $addr, $port, $pswd
Invoke-Expression $adb -OutVariable output -ErrorVariable errors | Out-Null
if ($output | Select-String "Successfully paired"){
Write-Host $msgTable.successfullyPaired -ForegroundColor Green
break
}
else
{
if ($output | Select-String "Failed: Unable to start pairing client.")
{
if($addr2 -eq 0)
{
Write-Host $msgTable.badAddrOrPort -ForegroundColor Red
Write-Host $msgTable.keepOldValue -ForegroundColor Green
Write-Host $msgTable.enterAddr
if ($value = Read-Host $addr) { $addr = $value }
}
else {
Write-Host $msgTable.badPort -ForegroundColor Red
Write-Host $msgTable.keepOldValue -ForegroundColor Green
}
Write-Host $msgTable.enterPort
if ($value = Read-Host $port) { $port = $value }
Write-Host $msgTable.enterPswd
if ($value = Read-Host $pswd) { $pswd = $value }
}
elseif ($output | Select-String "Failed: Wrong password or connection was dropped.")
{
Write-Host $msgTable.enterPswd
if ($value = Read-Host $pswd) { $pswd = $value }
}
else
{
Write-Host $msgTable.unexpectedError -ForegroundColor Red
exit
}
}
}
}
function GetAbi
{
return (.\adb shell getprop ro.product.cpu.abi) -replace "-","_"
}
function GetSystemLanguage
{
$locale = .\adb shell getprop persist.sys.locale
return $locale -replace '\s*-.*'
}
function CheckInstalledVersion ($pkgname)
{
$cmd = ".\adb.exe shell dumpsys package {0}" -f $pkgname
Invoke-Expression $cmd -OutVariable output -ErrorVariable errors | Out-Null
$version = $output | Select-String "versionName"
return $version -replace '.*='
}
function VancedApi
{
$response = Invoke-WebRequest -Uri "https://mirror.codebucket.de/vanced/api//v1/latest.json" #"https://api.vancedapp.com/api/v1/latest.json"
if ($response.statuscode -eq '200') {
$json = ConvertFrom-Json $response.Content
}
return $json
}
function VancedVersion ($URI)
{
$URI = $URI + "versions.json"
$response = Invoke-WebRequest -Uri $URI
if ($response.statuscode -eq '200') {
$json = ConvertFrom-Json $response.Content
}
return $json
}
function SelectVancedVersion ($list)
{
#($list.vanced | measure -Maximum).maximum
Write-Host $msgTable.selectVersion -ForegroundColor Yellow
ForEach ($item in $list.vanced)
{
$color = "White"
$temp_str = "{0}:{1}" -f ($list.vanced.IndexOf($item) + 1), $item
if ($item -eq $installedVersionVanced)
{
$temp_str = $temp_str + " " + $msgTable.installed
$color = "Yellow"
}
if ($item -eq $api.vanced.version)
{
$temp_str = $temp_str + " " + $msgTable.latest
$color = "Green"
}
Write-Host $temp_str -ForegroundColor $color
}
while($True)
{
$choice = Read-Host
if (($choice -gt 0) -and
($list.vanced.length -ge $choice))
{
break
}
}
return $list.vanced[$choice - 1]
}
function Downloader ($uri, $path)
{
Invoke-WebRequest -Uri $uri -OutFile $path -ErrorVariable errors
}
#############################################################################
#TODO is_microg_broken
$api = VancedApi
if ($api -eq $null)
{
Write-Host $msgTable.noInternet
exit
}
if ($adb -eq $null)
{
Write-Host $msgTable.adbOver -ForegroundColor Yellow
Write-Host "1:"$msgTable.adbOverUSB -ForegroundColor Green
Write-Host "2:"$msgTable.adbOverWIFI
while($adb -eq $null)
{
$choice = Read-Host
Switch($choice)
{
1{$adb = 'usb'}
2{$adb = 'wifi'}
default {}
}
}
}
Switch($adb)
{
'usb'{usbADB}
'wifi'{wirelessADB}
default {}
}
$abi = GetAbi
$language = GetSystemLanguage
Write-Host $msgTable.arch $abi
Write-Host $msgTable.language $language
$installedVersionVanced = CheckInstalledVersion("com.vanced.android.youtube")
if ($installedVersionVanced){ write-host $msgTable.installedVersion "YouTube Vanced:" $installedVersionVanced}
$installedVersionMicroG = CheckInstalledVersion("com.mgoogle.android.gms")
if ($installedVersionMicroG){ write-host $msgTable.installedVersion "microG:" $installedVersionMicroG}
$installedVersionOrig = CheckInstalledVersion("com.google.android.youtube")
if ($installedVersionOrig){ write-host $msgTable.installedVersion "Google YouTube:" $installedVersionOrig}
if ($uninstall)
{
Invoke-Expression ".\adb.exe shell pm uninstall com.vanced.android.youtube" | Out-Null
if ($LASTEXITCODE)
{
Write-Host $msgTable.failedDel"Vanced" -ForegroundColor Red
}
else
{
Write-Host "Vanced"$msgTable.deleted -ForegroundColor Green
}
Invoke-Expression ".\adb.exe shell pm uninstall com.mgoogle.android.gms" | Out-Null
if ($LASTEXITCODE)
{
Write-Host $msgTable.failedDel"microG" -ForegroundColor Red
}
else
{
Write-Host "microG"$msgTable.deleted -ForegroundColor Green
}
exit
}
if ($theme -eq $null)
{
Write-Host $msgTable.themeRequest -ForegroundColor Yellow
Write-Host "1:"$msgTable.themeDark
Write-Host "2:"$msgTable.themeBlack
while($theme -eq $null)
{
$choice = Read-Host
Switch($choice)
{
1{$theme = 'dark'}
2{$theme = 'black'}
default {}
}
}
}
if($channel -eq $null)
{
Write-Host $msgTable.channelRequest -ForegroundColor Yellow
Write-Host "1:"$msgTable.channelStable
Write-Host "2:"$msgTable.channelBeta
while($channel -eq $null)
{
$choice = Read-Host
Switch($choice)
{
1{$channel = 'stable'}
2{$channel = 'beta'}
default {}
}
}
}
$URI = "https://mirror.codebucket.de/vanced/api/"
Switch($channel)
{
'stable'{$URI = $URI + "v1/"}
'beta'{$URI = $URI + "beta/"}
default {}
}
if ($latest -and ($channel -eq 'stable'))
{
$version = $api.vanced.version
}
else
{
$versions = VancedVersion($URI)
$version = SelectVancedVersion($versions)
}
$URI = $URI + "apks/v" + $version + "/nonroot/"
$PATH = "Downloads/Vanced/" + $version + "/"
[System.Collections.ArrayList]$listURI = @()
[System.Collections.ArrayList]$listPATH = @()
$temp = "Theme/{0}.apk" -f $theme
$listURI.Add($URI + $temp)| Out-Null
$listPATH.Add($PATH + $temp)| Out-Null
$temp = "Arch/split_config.{0}.apk" -f $abi
$listURI.Add($URI + $temp)| Out-Null
$listPATH.Add($PATH + $temp)| Out-Null
$temp = "Language/split_config.{0}.apk" -f "en"
$listURI.Add($URI + $temp)| Out-Null
$listPATH.Add($PATH + $temp)| Out-Null
if (($api.vanced.langs.Contains($language)) -and ($language -ne "en"))
{
$temp = "Language/split_config.{0}.apk" -f $language
$listURI.Add($URI + $temp)| Out-Null
$listPATH.Add($PATH + $temp)| Out-Null
}
ForEach ($Uri in $listURI){
$indexPATH = $listURI.IndexOf($URI)
If(!(test-path $listPATH[$indexPATH]))
{
New-Item -Force -Path $listPATH[$indexPATH] | Out-Null
Downloader $Uri $listPATH[$indexPATH]
}
}
$cmd = ".\adb.exe install-multiple"
ForEach ($item in $listPATH){
$cmd = $cmd + " " + $item
}
Write-Host $msgTable.allowInstall -ForegroundColor Yellow
Invoke-Expression $cmd -OutVariable output -ErrorVariable errors | Out-Null
if ($LASTEXITCODE)
{
Write-Host $msgTable.failedInstall"Vanced" -ForegroundColor Red
if ($errors | Select-String "No such file or directory" )
{
Write-Host $msgTable.noSuchFile
}
if($installedVersionVanced)
{
Write-Host $msgTable.uninstallAndRepeat
}
exit
}
else
{
Write-Host "Vanced"$msgTable.isInstalled
}
if ($installedVersionOrig)
{
Invoke-Expression ".\adb.exe shell pm set-app-link --user 0 com.google.android.youtube never"
}
Invoke-Expression ".\adb.exe shell pm set-app-link --user 0 com.vanced.android.youtube always"
Write-Host $msgTable.openLink -ForegroundColor Green
$PATHmicroG = "../Downloads/microG/microG.apk"
echo $PATHmicroG $api.microg.url
If(!(test-path $PATHmicroG))
{
New-Item -Force $PATHmicroG | Out-Null
Downloader $api.microg.url $PATHmicroG
}
$cmdMicroG = ".\adb.exe install " + $PATHmicroG
Write-Host $msgTable.allowInstall -ForegroundColor Yellow
Invoke-Expression $cmdMicroG -OutVariable output -ErrorVariable errors | Out-Null
if ($LASTEXITCODE)
{
Write-Host $msgTable.failedInstall"microG" -ForegroundColor Red
if ($errors | Select-String "No such file or directory" )
{
Write-Host $msgTable.noSuchFile
}
if($installedVersionMicroG)
{
Write-Host $msgTable.uninstallAndRepeat
}
}
else
{
Write-Host "microG"$msgTable.isInstalled
}
if ($saveDownloads -eq $False)
{
Remove-Item "Downloads" -recurse
}
exit