-
Notifications
You must be signed in to change notification settings - Fork 4
/
scrcpy.ps1
229 lines (210 loc) · 7.99 KB
/
scrcpy.ps1
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#MinersWin 2021
#20.01.2021
#https://miners.win
#Tutorial: https://youtube.com/minerswin
#YouTube: https://youtube.com/TheGeekFreaks
#Forum: https://forum.thegeekfreaks.de
#Website: https://thegeekfreaks.de
#Dev: https://miners.win
#Special Thanks to Joly0!
$scrcpypath = ".\scrcpy\scrcpy.exe"
$adbpath = ".\scrcpy\adb.exe"
Add-Type -AssemblyName System.Windows.Forms
. (Join-Path $PSScriptRoot 'scrcpy.designer.ps1')
$SupportClick = [System.Windows.Forms.MessageBox]::Show("Do you want to support us?`nA few browser tabs will open, you don't have to do anything.","Scrcpy Desktop Client by TGF",'YesNoCancel','Information')
if ($SupportClick -ne "NO"){
explorer "https://youtu.be/ftVBV-XmAP4"
explorer "https://amzn.to/3dX3I7x"
explorer "https://youtu.be/78DBNzVExPw"
explorer "https://paypal.me/minerswin"
}
$TextBoxWindowTitle.Text = "Scrcpy"
$Gedownloaded = Test-Path .\scrcpy\
if ($Gedownloaded) {
$ButtonDownload.ForeColor = "Green"
$ButtonDownload.Text = "Scrcpy Installiert"
$ButtonDownload.Enabled = $false
} else {
$ButtonDownload.ForeColor = "Red"
$ButtonDownload.Text = "Scrcpy Installieren"
$ButtonDownload.Enabled = $true
}
##Initial Settings
$RadioButtonNaturalOrientation.Checked = $true
#Deactivate Unneeded Objects
$TextBoxCropScreen.Enabled = $false
$ButtonCropScreen.Add_Click{
if ($TextBoxCropScreen.Enabled){
$TextBoxCropScreen.Enabled = $false
} else {
$TextBoxCropScreen.Enabled = $true
}
}
$ButtonPositionandSize.Add_Click{
if ($TextBoxWindowX.Enabled){
$TextBoxWindowX.Enabled = $false
$TextBoxWindowY.Enabled = $false
$TextBoxWindowHeight.Enabled = $false
$TextBoxWindowWidth.Enabled = $false
} else {
$TextBoxWindowX.Enabled = $true
$TextBoxWindowY.Enabled = $true
$TextBoxWindowHeight.Enabled = $true
$TextBoxWindowWidth.Enabled = $true
}
}
##############################################################################
###########################Settings auslesen##################################
##############################################################################
function Read-Settings {
[pscustomobject]@{
'IP' = $TextBoxIP.Text
'MaxSize' = $ComboBoxMaxSize.Text
'Bitrate' = $ComboBoxBitrate.Text
'FPS' = $ComboBoxMaxFPS.Text
'WindowTitle' = $TextBoxWindowTitle.Text
'CropScreen' = if ($TextBoxCropScreen.Enabled) { $TextBoxCropScreen.Text } else { '' }
'Recording' = $CheckBoxRecord.Checked
'Display' = $CheckBoxNoDisplay.Checked
'Filepath' = $TextBoxRecordFile.Text
'WindowX' = $TextBoxWindowX.Text
'WindowY' ` = $TextBoxWindowY.Text
'WindowWidth' = $TextBoxWindowWidth.Text
'WindowHeight' = $TextBoxWindowHeight.Text
'Orientation' = if ($RadioButtonNaturalOrientation.Checked) {
0
} elseif ($RadioButton90CounterClockwise.Checked) {
1
} elseif ($RadioButton180Degree.Checked) {
2
} else {
3
}
}
}
$PictureBoxLogo.Add_Click{Debug}
function Debug{
Write-Host "Debug:"
Read-Settings | Out-Host
}
#Download Scrcpy
$Internet = Test-Connection 45.142.177.78 -Count 1 -Quiet
if ($Internet) {
"$(Get-Date) Internetverbindung: Online"
} else {
"$(Get-Date) Internetverbindung: Offline"
}
function Test-Download{
$Gedownloaded = Test-Path .\scrcpy\
if ($Gedownloaded){
Write-Output "$(Get-Date) Scrcpy wurde bereits heruntergeladen"
$ButtonDownload.ForeColor = Green
} else {
if ($Internet){
Write-Output "$(Get-Date) Scrcpy muss heruntergeladen werden"
Download-Scrcpy
} else {
Write-Output "$(Get-Date) Scrcpy ist nicht Installiert, jedoch besteht keine Internetverbindung. Das Programm wird beendet."
$FormScrcpy.Close()
}
}
}
function Download-Scrcpy{
if (-not $Gedownloaded) {
Write-Host "Scrcpy Download wird vom TGF Mirror gestartet"
$url = "https://cdn.thegeekfreaks.de/Download/scrcpy.zip"
$output = Join-Path -Path "$PWD" -ChildPath "scrcpy.zip"
$start_time = Get-Date
(New-Object System.Net.WebClient).DownloadFile($url, $output)
Write-Host "Download fertiggestellt`nDownloadzeit: $((Get-Date).Subtract($start_time).Seconds) Sekunde(n)`nEntpacke Archiv ..."
Expand-Archive -Path $output -DestinationPath .\scrcpy\
Write-Host "Archiv erfolgreich entpackt, Lösche Temporäre Download Files ...."
rm $output
Write-Host "Done" -ForegroundColor Green
}
$Gedownloaded = Test-Path .\scrcpy\
if ($Gedownloaded) {
$ButtonDownload.ForeColor = "Green"
$ButtonDownload.Text = "Scrcpy Installiert"
$ButtonDownload.Enabled = $false
} else {
$ButtonDownload.ForeColor = "Red"
$ButtonDownload.Text="Scrcpy Installieren"
$ButtonDownload.Enabled = $true
}
}
function Get-ScrcpyConsoleArguments {
<#
Gets the console arguments for scrcpy
#>
$settings = Read-Settings
[array]$ConsoleArguments = @(
"-m $($settings.MaxSize)",
"--bit-rate $($settings.Bitrate)",
"--max-fps $($settings.FPS)",
"--rotation $($settings.Orientation)",
"--window-title $($settings.WindowTitle)"
)
if ($TextBoxCropScreen.Enabled) {
$ConsoleArguments += "--crop $($Settings.CropScreen)"
}
if ($Recording) {
if ($Display) {
$ConsoleArguments += "--no-display"
}
$ConsoleArguments += "--record $($settings.Filepath)"
}
if ($IP -ne $null) {
$ConsoleArguments += "--serial $($settings.IP)"
}
if ($TextBoxWindowX.Enabled) {
$ConsoleArguments += "--window-x $($settings.WindowX) --window-y $($settings.WindowY) --window-width $($settings.WindowWidth) --window-height $($settings.WindowHeight)"
}
if ($CheckBoxBorderless.Checked) {
$ConsoleArguments += "--window-borderless"
}
if ($CheckBoxAlwaysonTop.Checked) {
$ConsoleArguments += "--always-on-top"
}
if ($CheckBoxFullscreen.Checked) {
$ConsoleArguments += "--fullscreen"
}
if ($CheckBoxStayAwake.Checked){
$ConsoleArguments += "--stay-awake"
}
$LabelConnectionString.Text = "$ConsoleArguments"
return $ConsoleArguments
}
function Connect {
Start-Process -FilePath .\scrcpy\adb.exe -ArgumentList "disconnect"
Start-Process -FilePath .\scrcpy\adb.exe -ArgumentList "kill-server"
Start-Sleep 3
if ($TextBoxIP.Text -eq "") {
[System.Windows.Forms.MessageBox]::Show("Please Connect your Phone with your PC, make shure ADB is aktivated, Allow your PC if MessageBox Pops Up","Connect your Smartphone with your PC",1)
$ScrcpyArguments = Get-ScrcpyConsoleArguments
Write-Host "$ScrcpyArguments"
Start-Process -FilePath $scrcpypath -ArgumentList $ScrcpyArguments
}else{
[System.Windows.Forms.MessageBox]::Show("Please Connect your Phone with your PC, make shure ADB is aktivated, Allow your PC if MessageBox Pops Up","Connect your Smartphone with your PC",1)
$ScrcpyArguments = Get-ScrcpyConsoleArguments
Write-Host "$ScrcpyArguments"
Start $adbpath devices
.\scrcpy\adb.exe tcpip 5555
.\scrcpy\adb.exe connect (-join"$TextBoxIP.Text" + ":5555")
Start-Sleep 3
.\scrcpy\adb.exe connect $TextBoxIP.Text
[System.Windows.Forms.MessageBox]::Show("You can now safely Dissconnect your Smartphone from your PC","Connect your Smartphone with your PC",1)
Start-Process -FilePath '.\scrcpy\scrcpy.exe' -ArgumentList $ScrcpyArguments
}
}
$ButtonDownload.Add_Click{(Test-Download)}
$ButtonExit.Add_Click{
Start-Process -FilePath .\scrcpy\adb.exe -ArgumentList "disconnect"
Start-Process -FilePath .\scrcpy\adb.exe -ArgumentList "kill-server"
$FormScrcpy.Close()
}
$ButtonConnect.Add_Click{Connect}
$LabelConnectionString.Add_Click{[System.Windows.Forms.MessageBox]::Show("$ScrcpyArguments","TGF Scrcpy",1)}
Debug
#Call Form
$FormScrcpy.ShowDialog()