-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScreenCopyUpdate.ps1
More file actions
45 lines (32 loc) · 2.16 KB
/
Copy pathScreenCopyUpdate.ps1
File metadata and controls
45 lines (32 loc) · 2.16 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
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
# run with admin access.
if (!$isAdmin) { return Write-Host "Please run this function with admin access." }
# fetch the HTML from the latest release page
$html = Invoke-RestMethod -Uri "https://github.com/Genymobile/scrcpy/releases/latest"
# use Regex to extract the tag name from the page content (e.g., "v4.0")
$latestTag = [regex]::Match($html, 'releases/tag/(v[\d\.]+)').Groups[1].Value
# construct the filename and the exact direct download link
$filename = "scrcpy-win64-${latestTag}.zip"
$directLink = "https://github.com/Genymobile/scrcpy/releases/download/${latestTag}/${filename}"
if (Test-Path -Path "$env:HOMEDRIVE\scrcpy" -ErrorAction SilentlyContinue) {
Write-Host "Stoping adb.exe process..."
taskkill /im adb.exe /f # stop 'adb.exe' process because sometimes it causes error
Write-Host "Get out from scrcpy directory by changing directory to C:\ drive..."
Set-Location $env:HOMEDRIVE # set location to $HOME to avoid "directory is being use" error
Write-Host "Removing old scrcpy directory..."
Remove-Item "$env:HOMEDRIVE\scrcpy" -Force -Recurse -ErrorAction SilentlyContinue # remove the old scrcpy folder
}
Write-Host "Downloading .zip file from github..."
Invoke-WebRequest -Uri "$directLink" -OutFile "$env:HOMEDRIVE\$filename" # download
Write-Host "Extracting .zip file to C:\ drive..."
Expand-Archive -Path "$env:HOMEDRIVE\$filename" -DestinationPath "$env:HOMEDRIVE\" -Force # extract .zip
Write-Host "Removing .zip file..."
Remove-Item "$env:HOMEDRIVE\$filename" -Force # remove .zip
Write-Host "Renaming extracted .zip file to to something simpler like scrcpy..."
Rename-Item "$env:HOMEDRIVE\scrcpy-win64-$latestTag" -NewName "scrcpy" -Force # rename extracted folder
Write-Host "Go inside the scrcpy direcory..."
Set-Location "$env:HOMEDRIVE\scrcpy" # target folder
Write-Host "Listing all files and folders in scrcpy directory..."
Get-ChildItem # list content inside that folder