Rewrite config and updating
This commit is contained in:
parent
96c6ba3d3c
commit
b7dbfcdd0c
1 changed files with 68 additions and 69 deletions
137
revanced.ps1
137
revanced.ps1
|
@ -80,85 +80,84 @@ function renderForm([String[]]$items, [String]$label, [String]$title, [System.Wi
|
||||||
}
|
}
|
||||||
|
|
||||||
class config {
|
class config {
|
||||||
[String]$patches = "none"
|
[hashtable]$version = @{}
|
||||||
[String]$integrations = "none"
|
|
||||||
[String]$cli = "none"
|
|
||||||
[System.Collections.ArrayList]$excluded = (New-Object System.Collections.ArrayList)
|
[System.Collections.ArrayList]$excluded = (New-Object System.Collections.ArrayList)
|
||||||
|
}
|
||||||
|
|
||||||
[void] load($Path) {
|
class configFile {
|
||||||
$fileContent = ConvertFrom-Json ((Get-Content $Path) -Join ' ').ToString()
|
[String]$path = ".\config.json"
|
||||||
|
[config]$config = [config]::new()
|
||||||
$this.patches = $fileContent.patches
|
|
||||||
$this.integrations = $fileContent.integrations
|
[void] load() {
|
||||||
$this.cli = $fileContent.cli
|
$fileContent = ConvertFrom-Json ((Get-Content $this.path) -Join ' ').ToString()
|
||||||
$this.excluded = $fileContent.excluded
|
|
||||||
|
$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) {
|
[void] save() {
|
||||||
Out-File $Path -InputObject (ConvertTo-Json $this)
|
Out-File $this.path -InputObject (ConvertTo-Json $this.config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function main {
|
function UpdateFromGithub {
|
||||||
|
param (
|
||||||
$config = New-Object config
|
[Parameter(Mandatory)][String]$Repository,
|
||||||
|
[Parameter(Mandatory)][configFile]$Config,
|
||||||
# Get latest releases
|
[scriptblock]$AssetsFilter = {$true},
|
||||||
|
[Parameter(Mandatory)][String]$OutFile
|
||||||
|
)
|
||||||
|
|
||||||
|
[String]$InstalledTag = $Config.config.version[$Repository]
|
||||||
|
$LatestRelease
|
||||||
try {
|
try {
|
||||||
$patchesRelease = ConvertFrom-Json (Invoke-WebRequest https://api.github.com/repos/revanced/revanced-patches/releases/latest).Content
|
$LatestRelease = ConvertFrom-Json (Invoke-WebRequest "https://api.github.com/repos/$Repository/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")
|
|
||||||
}
|
}
|
||||||
catch [System.Net.WebException] {
|
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}
|
if ($NoDeploy) {return}
|
||||||
|
|
||||||
# Select Youtube app
|
# Select Youtube app
|
||||||
|
@ -200,7 +199,7 @@ function main {
|
||||||
|
|
||||||
$excludedIntegrations = New-Object System.Collections.ArrayList
|
$excludedIntegrations = New-Object System.Collections.ArrayList
|
||||||
[System.Collections.ArrayList]$savedExclusions = 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) {
|
foreach ($i in $integrationsList) {
|
||||||
if (($savedExclusionsNames.Count -gt 1) -and $savedExclusionsNames.Contains($i.id)) {
|
if (($savedExclusionsNames.Count -gt 1) -and $savedExclusionsNames.Contains($i.id)) {
|
||||||
[void] $savedExclusions.Add($true)
|
[void] $savedExclusions.Add($true)
|
||||||
|
@ -215,8 +214,8 @@ function main {
|
||||||
[void] $excludedIntegrations.Add($i.Split(' ')[0]) #FIXME: hacky way to do this, but it works
|
[void] $excludedIntegrations.Add($i.Split(' ')[0]) #FIXME: hacky way to do this, but it works
|
||||||
}
|
}
|
||||||
|
|
||||||
$config.excluded = $excludedIntegrations
|
$config.config.excluded = $excludedIntegrations
|
||||||
$config.save(".\config.json")
|
$config.save()
|
||||||
|
|
||||||
# devices
|
# devices
|
||||||
|
|
||||||
|
|
Reference in a new issue