Compare commits
2 commits
96c6ba3d3c
...
1ed0e6e7ec
Author | SHA1 | Date | |
---|---|---|---|
1ed0e6e7ec | |||
b7dbfcdd0c |
1 changed files with 72 additions and 71 deletions
143
revanced.ps1
143
revanced.ps1
|
@ -80,85 +80,84 @@ function renderForm([String[]]$items, [String]$label, [String]$title, [System.Wi
|
|||
}
|
||||
|
||||
class config {
|
||||
[String]$patches = "none"
|
||||
[String]$integrations = "none"
|
||||
[String]$cli = "none"
|
||||
[hashtable]$version = @{}
|
||||
[System.Collections.ArrayList]$excluded = (New-Object System.Collections.ArrayList)
|
||||
}
|
||||
|
||||
[void] load($Path) {
|
||||
$fileContent = ConvertFrom-Json ((Get-Content $Path) -Join ' ').ToString()
|
||||
|
||||
$this.patches = $fileContent.patches
|
||||
$this.integrations = $fileContent.integrations
|
||||
$this.cli = $fileContent.cli
|
||||
$this.excluded = $fileContent.excluded
|
||||
class configFile {
|
||||
[String]$path = ".\config.json"
|
||||
[config]$config = [config]::new()
|
||||
|
||||
[void] load() {
|
||||
$fileContent = ConvertFrom-Json ((Get-Content $this.path) -Join ' ').ToString()
|
||||
|
||||
$version = @{}
|
||||
foreach ($prop in $fileContent.version.PsObject.Properties) {
|
||||
$version.Add($prop.Name, $prop.Value)
|
||||
}
|
||||
$fileContent.version = $null
|
||||
|
||||
$this.config = $fileContent
|
||||
$this.config.version = $version
|
||||
}
|
||||
|
||||
[void] save($Path) {
|
||||
Out-File $Path -InputObject (ConvertTo-Json $this)
|
||||
[void] save() {
|
||||
Out-File $this.path -InputObject (ConvertTo-Json $this.config)
|
||||
}
|
||||
}
|
||||
|
||||
function main {
|
||||
|
||||
$config = New-Object config
|
||||
|
||||
# Get latest releases
|
||||
function UpdateFromGithub {
|
||||
param (
|
||||
[Parameter(Mandatory)][String]$Repository,
|
||||
[Parameter(Mandatory)][configFile]$Config,
|
||||
[scriptblock]$AssetsFilter = {$true},
|
||||
[Parameter(Mandatory)][String]$OutFile
|
||||
)
|
||||
|
||||
[String]$InstalledTag = $Config.config.version[$Repository]
|
||||
$LatestRelease
|
||||
try {
|
||||
$patchesRelease = ConvertFrom-Json (Invoke-WebRequest https://api.github.com/repos/revanced/revanced-patches/releases/latest).Content
|
||||
$integrationsRelease = ConvertFrom-Json (Invoke-WebRequest https://api.github.com/repos/revanced/revanced-integrations/releases/latest).Content
|
||||
$cliRelease = ConvertFrom-Json (Invoke-WebRequest https://api.github.com/repos/revanced/revanced-cli/releases/latest).Content
|
||||
|
||||
# Check versions
|
||||
|
||||
[Bool[]]$install = $true, $true, $true
|
||||
|
||||
try {
|
||||
$config.load(".\config.json")
|
||||
|
||||
if ($config.patches -eq $patchesRelease.tag_name) {$install[0] = $false}
|
||||
if ($config.integrations -eq $integrationsRelease.tag_name) {$install[1] = $false}
|
||||
if ($config.cli -eq $cliRelease.tag_name) {$install[2] = $false}
|
||||
}
|
||||
catch [System.Management.Automation.ItemNotFoundException] {
|
||||
Write-Output "currentVersion.json not found, downloading everything"
|
||||
}
|
||||
|
||||
# Download latest releases
|
||||
|
||||
New-Item -type Directory -Path ".\app" -ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
# TODO: use where-object to search for filename
|
||||
|
||||
if ($install[0]) {
|
||||
Write-Output "Downloading Patches ($($config.patches) -> $($patchesRelease.tag_name))"
|
||||
Write-Output "changelog: https://github.com/revanced/revanced-patches/compare/$($config.patches)...$($patchesRelease.tag_name)"
|
||||
Invoke-WebRequest $patchesRelease.assets[1].browser_download_url -OutFile ".\app\revanced-patches.jar"
|
||||
$config.patches = $patchesRelease.tag_name
|
||||
}
|
||||
else {Write-Output "Patches up to date $($config.patches)"}
|
||||
if ($install[1]) {
|
||||
Write-Output "Downloading Integrations ($($config.integrations) -> $($integrationsRelease.tag_name))"
|
||||
Write-Output "changelog: https://github.com/revanced/revanced-patches/compare/$($config.integrations)...$($integrationsRelease.tag_name)"
|
||||
Invoke-WebRequest $integrationsRelease.assets[0].browser_download_url -OutFile ".\app\app-release-unsigned.apk"
|
||||
$config.integrations = $integrationsRelease.tag_name
|
||||
}
|
||||
else {Write-Output "Integrations up to date $($config.integrations)"}
|
||||
if ($install[2]) {
|
||||
Write-Output "Downloading cli ($($config.cli) -> $($cliRelease.tag_name))"
|
||||
Write-Output "changelog: https://github.com/revanced/revanced-patches/compare/$($config.cli)...$($cliRelease.tag_name)"
|
||||
Invoke-WebRequest $cliRelease.assets[0].browser_download_url -OutFile ".\app\revanced-cli.jar"
|
||||
$config.cli = $cliRelease.tag_name
|
||||
}
|
||||
else {Write-Output "cli up to date! $($config.cli)"}
|
||||
|
||||
$config.save(".\config.json")
|
||||
$LatestRelease = ConvertFrom-Json (Invoke-WebRequest "https://api.github.com/repos/$Repository/releases/latest").Content
|
||||
}
|
||||
catch [System.Net.WebException] {
|
||||
Write-Output "Couldn't get newest files, using locals"
|
||||
Write-Host "Couldn't check for update $Repository"
|
||||
return $false
|
||||
}
|
||||
|
||||
[String]$UpdateTag = $LatestRelease.tag_name
|
||||
|
||||
if ($InstalledTag -eq $UpdateTag) {
|
||||
Write-Host "$Repository up to date! ($InstalledTag)"
|
||||
return $false
|
||||
}
|
||||
|
||||
$Assets = $LatestRelease.assets | Where-Object -FilterScript $AssetsFilter
|
||||
|
||||
Write-Host "Downloading $Repository ($InstalledTag -> $UpdateTag)"
|
||||
Write-Host "Changelog: https://github.com/$Repository/compare/$InstalledTag...$UpdateTag"
|
||||
Invoke-WebRequest $Assets[0].browser_download_url -OutFile $OutFile
|
||||
$Config.config.version[$Repository] = $UpdateTag
|
||||
$Config.save()
|
||||
|
||||
return $true
|
||||
}
|
||||
|
||||
function main {
|
||||
$config = [configFile]::new()
|
||||
try {
|
||||
$config.load()
|
||||
}
|
||||
catch [System.IO.FileNotFoundException] {
|
||||
Write-Host ".\config.json not found"
|
||||
$config.save()
|
||||
}
|
||||
|
||||
# Update
|
||||
|
||||
UpdateFromGithub -Repository "revanced/revanced-patches" -Config $config -AssetsFilter {$_.content_type -like "application/*"} -OutFile ".\app\revanced-patches.jar" | Out-Null
|
||||
UpdateFromGithub -Repository "revanced/revanced-integrations" -Config $config -AssetsFilter {$_.content_type -like "application/*"} -OutFile ".\app\app-release-unsigned.apk" | Out-Null
|
||||
UpdateFromGithub -Repository "revanced/revanced-cli" -Config $config -AssetsFilter {$_.content_type -like "application/*"} -OutFile ".\app\revanced-cli.jar" | Out-Null
|
||||
|
||||
if ($NoDeploy) {return}
|
||||
|
||||
# Select Youtube app
|
||||
|
@ -200,7 +199,7 @@ function main {
|
|||
|
||||
$excludedIntegrations = New-Object System.Collections.ArrayList
|
||||
[System.Collections.ArrayList]$savedExclusions = New-Object System.Collections.ArrayList
|
||||
$savedExclusionsNames = $config.excluded
|
||||
$savedExclusionsNames = $config.config.excluded
|
||||
foreach ($i in $integrationsList) {
|
||||
if (($savedExclusionsNames.Count -gt 1) -and $savedExclusionsNames.Contains($i.id)) {
|
||||
[void] $savedExclusions.Add($true)
|
||||
|
@ -215,17 +214,19 @@ function main {
|
|||
[void] $excludedIntegrations.Add($i.Split(' ')[0]) #FIXME: hacky way to do this, but it works
|
||||
}
|
||||
|
||||
$config.excluded = $excludedIntegrations
|
||||
$config.save(".\config.json")
|
||||
$config.config.excluded = $excludedIntegrations
|
||||
$config.save()
|
||||
|
||||
# devices
|
||||
|
||||
$devices = adb devices
|
||||
if ($devices.Length -eq 2) {
|
||||
throw "No devices found"
|
||||
}
|
||||
$devices = $devices[1..($devices.length-2)]
|
||||
|
||||
[String]$selectedDevice = ''
|
||||
if ($devices.Length -eq 0) {throw "No devices found"}
|
||||
elseif ($devices.Length -eq 1) {
|
||||
if ($devices.Length -eq 1) {
|
||||
$selectedDevice = ($devices | ForEach-Object {$_.split()[0]})[0]
|
||||
}
|
||||
else {
|
||||
|
|
Reference in a new issue