Skip to content

Commit

Permalink
Update Function.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
farag2 committed Apr 24, 2023
1 parent 8d661fc commit 175d393
Showing 1 changed file with 80 additions and 30 deletions.
110 changes: 80 additions & 30 deletions src/Function.ps1
Original file line number Diff line number Diff line change
@@ -1,47 +1,97 @@
if (-not (Test-Path -Path $PSScriptRoot\platform-tools\adb.exe))
# Check whether all necessary files exist in the bin folder
$Files = @(
"$PSScriptRoot\platform-tools\adb.exe",
"$PSScriptRoot\JSONs\Google.json",
"$PSScriptRoot\JSONs\Samsung.json",
"$PSScriptRoot\JSONs\Xiaomi.json"
)
if (($Files | Test-Path) -contains $false)
{
Write-Warning -Message "Place adb.exe to the folder root"
Start-Process -FilePath "https://github.com/farag2/ADB-Debloating/blob/master/src/Download_ADB.ps1"
Write-Warning -Message "Re-download archive and download ADB via Download_ADB.ps1"
Start-Process -FilePath "https://github.com/farag2/ADB-Debloating"

pause
exit
}

do
{
$Proceed = Read-Host -Prompt "Type your device vendor: Xiaomi, Google, or Samsung"
if ($Proceed -eq "Xiaomi")
{
$File = "Xiaomi"
}
<#
.SYNOPSIS
The "Show menu" function with the up/down arrow keys and enter key to make a selection
if ($Proceed -eq "Google")
{
$File = "Google"
}
.EXAMPLE
ShowMenu -Menu $ListOfItems -Default $DefaultChoice
if ($Proceed -eq "Samsung")
.LINK
https://qna.habr.com/answer?answer_id=1522379
#>
function ShowMenu
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[array]
$Menu,

[Parameter(Mandatory = $true)]
[int]
$Default
)

# https://github.com/microsoft/terminal/issues/14992
[System.Console]::BufferHeight += $Menu.Count
$minY = [Console]::CursorTop
$y = [Math]::Max([Math]::Min($Default, $Menu.Count), 0)

do
{
$File = "Samsung"
}
}
until (($Proceed -eq "Xiaomi") -or ($Proceed -eq "Google") -or ($Proceed -eq "Samsung"))
[Console]::CursorTop = $minY
[Console]::CursorLeft = 0
$i = 0
foreach ($item in $Menu)
{
if ($i -ne $y)
{
Write-Information -MessageData (' {1} ' -f ($i+1), $item) -InformationAction Continue
}
else
{
Write-Information -MessageData ('[ {1} ]' -f ($i+1), $item) -InformationAction Continue
}
$i++
}

if (Test-Path -Path "$PSScriptRoot\JSONs\$File.json")
{
$Packages = Get-Content -Path "$PSScriptRoot\JSONs\$File.json" | ConvertFrom-Json
$k = [Console]::ReadKey()
switch ($k.Key)
{
"UpArrow"
{
if ($y -gt 0)
{
$y--
}
}
"DownArrow"
{
if ($y -lt ($Menu.Count - 1))
{
$y++
}
}
"Enter"
{
return $Menu[$y]
}
}
}
while ($k.Key -notin ([ConsoleKey]::Escape, [ConsoleKey]::Enter))
}
else
{
Write-Warning -Message "$PSScriptRoot\JSONs\$File.json doesn't exist"
Start-Process -FilePath "https://github.com/farag2/ADB-Debloating"
$File = ShowMenu -Menu @("Samsung", "Xiaomi", "Google") -Default 1
$Packages = Get-Content -Path "$PSScriptRoot\JSONs\$File.json" | ConvertFrom-Json

pause
exit
}
Write-Warning -Message "Waiting your phone to be connected and allowed USB debugging"

& $PSScriptRoot\platform-tools\adb.exe wait-for-device
Write-Warning -Message "Waiting your phone to be connected and allowed USB debugging"
pause

Add-Type -AssemblyName PresentationCore, PresentationFramework
Expand Down

0 comments on commit 175d393

Please sign in to comment.