-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun.php
More file actions
60 lines (43 loc) · 1.49 KB
/
run.php
File metadata and controls
60 lines (43 loc) · 1.49 KB
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
#!/usr/bin/php
<?php
/**
* Created by PhpStorm.
* User: 731MY
* Date: 7/10/18
* Time: 5:11 AM
*/
$currentVersion = cleanVersion($argv[1]);
$os = $argv[2] ?? os();
$channel = $argv[3] ?? 'release';
$updateCenter = 'https://dl.google.com/android/studio/patches/updates.xml';
$patchLink = 'https://dl.google.com/android/studio/patches/';
$doc = new DOMDocument();
@$doc->loadXML(call($updateCenter));
$xpath = new DOMXPath($doc);
$query = sprintf('//channel[@status="%s"][1]/build/patch[@from="%s"]',$channel,$currentVersion);
$patch = $xpath->query($query);
if($patch->length == 1){
$query = sprintf('//channel[@status="%s"][1]/build/@number',$channel);
$build = $xpath->query($query);
$latestVersion = cleanVersion($build->item(0)->value);
$patchUrl = sprintf("%sAI-%s-%s-patch-%s.jar%s",$patchLink,$currentVersion,$latestVersion,$os,PHP_EOL);
echo $patchUrl;
}else{
echo "You'd better download & install latest version of Android Studio from https://developer.android.com/studio/".PHP_EOL;
}
function os(){
return stripos(PHP_OS, 'win') === 0 ? 'win' : stripos(PHP_OS, 'darwin') === 0 ? 'mac' : 'unix';
}
function cleanVersion($input){
return array_reverse(explode('-',$input))[0];
}
function call($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}