-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedbackstart.psm1
373 lines (302 loc) · 12.2 KB
/
feedbackstart.psm1
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
function feedbackstart([string]$para1,[string]$para2,[string]$para3,[string]$para4){
#region import functions
function Set-WindowState {
<#
.LINK
https://gist.github.com/Nora-Ballard/11240204
#>
[CmdletBinding(DefaultParameterSetName = 'InputObject')]
param(
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[Object[]] $InputObject,
[Parameter(Position = 1)]
[ValidateSet('FORCEMINIMIZE', 'HIDE', 'MAXIMIZE', 'MINIMIZE', 'RESTORE',
'SHOW', 'SHOWDEFAULT', 'SHOWMAXIMIZED', 'SHOWMINIMIZED',
'SHOWMINNOACTIVE', 'SHOWNA', 'SHOWNOACTIVATE', 'SHOWNORMAL')]
[string] $State = 'SHOW'
)
Begin {
$WindowStates = @{
'FORCEMINIMIZE' = 11
'HIDE' = 0
'MAXIMIZE' = 3
'MINIMIZE' = 6
'RESTORE' = 9
'SHOW' = 5
'SHOWDEFAULT' = 10
'SHOWMAXIMIZED' = 3
'SHOWMINIMIZED' = 2
'SHOWMINNOACTIVE' = 7
'SHOWNA' = 8
'SHOWNOACTIVATE' = 4
'SHOWNORMAL' = 1
}
$Win32ShowWindowAsync = Add-Type -MemberDefinition @'
[DllImport("user32.dll")]
public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
'@ -Name "Win32ShowWindowAsync" -Namespace Win32Functions -PassThru
if (!$global:MainWindowHandles) {
$global:MainWindowHandles = @{ }
}
}
Process {
foreach ($process in $InputObject) {
if ($process.MainWindowHandle -eq 0) {
if ($global:MainWindowHandles.ContainsKey($process.Id)) {
$handle = $global:MainWindowHandles[$process.Id]
} else {
Write-Error "Main Window handle is '0'"
continue
}
} else {
$handle = $process.MainWindowHandle
$global:MainWindowHandles[$process.Id] = $handle
}
$Win32ShowWindowAsync::ShowWindowAsync($handle, $WindowStates[$State]) | Out-Null
Write-Verbose ("Set Window State '{1} on '{0}'" -f $MainWindowHandle, $State)
}
}
}
#endregion
if($PSScriptRoot.length -eq 0){
$scriptRoot="C:\testing_AI\modules"
}
else{
$scriptRoot=$PSScriptRoot
}
Add-Type -AssemblyName System.Windows.Forms
$nonlog_flag=$para4
$action="FeedbackHub_start"
$tcpath=(Split-Path -Parent $scriptRoot)+"\currentjob\TC.txt"
$tcnumber=((get-content $tcpath).split(","))[0]
$tcstep=((get-content $tcpath).split(","))[1]
$picpath=(Split-Path -Parent $scriptRoot)+"\logs\$($tcnumber)\"
if(-not(test-path $picpath)){new-item -ItemType directory -path $picpath |out-null}
$actionss ="screenshot"
Get-Module -name $actionss|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actionss\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue
$actionpcai ="pcai"
Get-Module -name $actionpcai|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actionpcai\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue
$actionclick ="mouse_action"
Get-Module -name $actionclick|remove-module
$mdpath=(Get-ChildItem -path $scriptRoot -r -file |Where-object{$_.name -match "^$actionclick\b" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue
# 打开反馈中心应用程序
<## reference ##
Start-Process "feedback-hub:" -WindowStyle Maximized
do{
start-sleep -s 5
$settingfile=Get-ChildItem "$env:USERPROFILE\AppData\Local\Packages\Microsoft.WindowsFeedbackHub_*\LocalState\content\FeedbackCategories.json"
}until( $settingfile)
$contentFeed = Get-Content $settingfile
$cataindex = $contentFeed.IndexOf("$para1")
$cata = $contentFeed.Substring($cataindex)
$cataPropertyIndex = $cata.IndexOf("sortOrder")
$property = $cata.Substring($cataPropertyIndex)
$catacolonindex = $property.IndexOf(":")
$savecontent = $contentFeed.Substring(0,$cataindex+$cataPropertyIndex+$catacolonindex+1) + "0" + $contentFeed.Substring($cataindex+$cataPropertyIndex+$catacolonindex+2)
Set-Content -Path "$env:USERPROFILE\AppData\Local\Packages\Microsoft.WindowsFeedbackHub_8wekyb3d8bbwe\LocalState\content\FeedbackCategories.json" -Value $savecontent
$contentFeed = Get-Content "$env:USERPROFILE\AppData\Local\Packages\Microsoft.WindowsFeedbackHub_8wekyb3d8bbwe\LocalState\content\FeedbackCategories.json" | ConvertFrom-Json
$id = 0
for($i=0;$i -lt $contentFeed.L1CategoryData.displayCategory.Length;$i++){
if($contentFeed.L1CategoryData.displayCategory[$i].categoryName -match "$para1"){
$id = $contentFeed.L1CategoryData.displayCategory[$i].id
}
}
for($i=0;$i -lt $contentFeed.L2CategoryData.uifContext.Length;$i++){
if($contentFeed.L2CategoryData.uifContext[$i].displayFeature -eq "$para2" -and $contentFeed.L2CategoryData.uifContext[$i].displayCategoryId -eq $id){
$contentFeed.L2CategoryData.uifContext[$i].sortOrder = 0
}
}
$json = ConvertTo-Json $contentFeed -Depth 100 -Compress
Set-Content -Path "$env:USERPROFILE\AppData\Local\Packages\Microsoft.WindowsFeedbackHub_8wekyb3d8bbwe\LocalState\content\FeedbackCategories.json" -Value $json
#$contentFeed = Get-Content "$env:USERPROFILE\AppData\Local\Packages\Microsoft.WindowsFeedbackHub_8wekyb3d8bbwe\LocalState\content\FeedbackCategories.json"
#$cataindex = $contentFeed.IndexOf("Gaming and Xbox")
#$cata = $contentFeed.Substring($cataindex)
#$cataPropertyIndex = $cata.IndexOf("sortOrder")
#$property = $cata.Substring($cataPropertyIndex)
#$catacolonindex = $property.IndexOf(":")
#$savecontent = $contentFeed.Substring(0,$cataindex+$cataPropertyIndex+$catacolonindex+1) + "0" + $contentFeed.Substring($cataindex+$cataPropertyIndex+$catacolonindex+2)
#Set-Content -Path "$env:USERPROFILE\AppData\Local\Packages\Microsoft.WindowsFeedbackHub_8wekyb3d8bbwe\LocalState\content\FeedbackCategories.json" -Value $savecontent
##>
# 打开反馈中心应用程序
if(get-process -name PilotshubApp -ea SilentlyContinue){
stop-process -name PilotshubApp -ea SilentlyContinue
start-sleep -s 10
}
$winv= ([System.Environment]::OSVersion.Version).Build
$fbver=(Get-AppxPackage -AllUsers | Where-Object { $_.Name -match "feedback" }).version
Start-Process "feedback-hub:"
start-sleep -s 60
Get-Process -id (get-process -name ApplicationFrameHost).Id | Set-WindowState -State MAXIMIZE
&$actionpcai -para1 "FeedbackHub" -para4 "nc" -para5 "nolog"
#region replaced by pcai action
<#
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("+{TAB}")
[System.Windows.Forms.SendKeys]::SendWait("+{TAB}")
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{TAB 3}")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait(" ")
[System.Windows.Forms.SendKeys]::SendWait("{+}")
start-sleep -s 5
[System.Windows.Forms.SendKeys]::SendWait("+{tab}")
[System.Windows.Forms.SendKeys]::SendWait("+{tab}")
[System.Windows.Forms.SendKeys]::SendWait("+{tab}")
[System.Windows.Forms.SendKeys]::SendWait("+{tab}")
[System.Windows.Forms.SendKeys]::SendWait("+{tab}")
if($winv -lt 22000 -and $fbver -ne "1.2304.1243.0"){[System.Windows.Forms.SendKeys]::SendWait("{UP}")}
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
start-sleep -s 2
#>
#endregion
<#Enter Advanced Diagnostics Interface
$hashfortabcount = @{
"Display Issues" = 1
"General" = 1
"Hardware Buttons and USB" = 1
"Media Issues" = 1
"Mixed Reality Performance" = 2
"Networking" = 1
"Performance" = 1
"Power" = 2
}
#third para
$count = 0
$typeofproblem = "$para3"
$top = $typeofproblem.Substring(0,1)
foreach($list in $hashfortabcount.Keys){
if($list -eq $typeofproblem){
$count = $($hashfortabcount[$list])
}
}
##>
$cSource3 = @'
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class Clicker3
{
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646270(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
struct INPUT
{
public int type; // 0 = INPUT_MOUSE,
// 1 = INPUT_KEYBOARD
// 2 = INPUT_HARDWARE
public MOUSEINPUT mi;
}
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646273(v=vs.85).aspx
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT
{
public int dx ;
public int dy ;
public int mouseData ;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
//This covers most use cases although complex mice may have additional buttons
//There are additional constants you can use for those cases, see the msdn page
const int MOUSEEVENTF_MOVED = 0x0001 ;
const int MOUSEEVENTF_LEFTDOWN = 0x0002 ;
const int MOUSEEVENTF_LEFTUP = 0x0004 ;
const int MOUSEEVENTF_RIGHTDOWN = 0x0008 ;
const int MOUSEEVENTF_RIGHTUP = 0x0010 ;
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020 ;
const int MOUSEEVENTF_MIDDLEUP = 0x0040 ;
const int MOUSEEVENTF_WHEEL = 0x0080 ;
const int MOUSEEVENTF_XDOWN = 0x0100 ;
const int MOUSEEVENTF_XUP = 0x0200 ;
const int MOUSEEVENTF_ABSOLUTE = 0x8000 ;
const int screen_length = 0x10000 ;
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx
[System.Runtime.InteropServices.DllImport("user32.dll")]
extern static uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
public static void LeftClickAtPoint(int x, int y)
{
//Move the mouse
INPUT[] input = new INPUT[3];
input[0].mi.dx = x*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width);
input[0].mi.dy = y*(65535/System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
input[0].mi.dwFlags = MOUSEEVENTF_MOVED | MOUSEEVENTF_ABSOLUTE;
//Left mouse button down
input[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
//Left mouse button up
input[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(3, input, Marshal.SizeOf(input[0]));
}
}
'@
Add-Type -TypeDefinition $cSource3 -ReferencedAssemblies System.Windows.Forms,System.Drawing
$clickx=[int64]([System.Windows.Forms.Cursor]::Position.X)
$clicky=[int64]([System.Windows.Forms.Cursor]::Position.Y)
[Clicker3]::LeftClickAtPoint($clickx, $clicky)
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("$para1")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("$para2")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{TAB}")
#choose type of problem
if($para3.Length -ne 0){
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("$para3")
start-sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
}
<##
if($count -ne 0){
for($i=0;$i -lt $count;$i++){
[System.Windows.Forms.SendKeys]::SendWait($top)
start-sleep -s 3
}
}
##>
######### write log #######
$results="check screenshot"
$index=""
if($nonlog_flag.Length -eq 0){
Get-Module -name "outlog"|remove-module
$mdpath=(Get-ChildItem -path "C:\testing_AI\modules\" -r -file |Where-object{$_.name -match "outlog" -and $_.name -match "psm1"}).fullname
Import-Module $mdpath -WarningAction SilentlyContinue -Global
#write-host "Do $action!"
outlog $action $results $tcnumber $tcstep $index
}
#[System.Windows.Forms.SendKeys]::SendWait(" ")
&$actionpcai -para1 "FeedbackHubstartrec" -para4 "nc" -para5 "nolog"
&$actionss -para3 non_log -para5 "start_recording"
<### hide window ##
[System.Windows.Forms.SendKeys]::SendWait("% ")
[System.Windows.Forms.SendKeys]::SendWait("n")
start-sleep -s 1
##>
#echo "Script wait 3min for user to reproduce issue"
#$ws = New-Object -ComObject WScript.Shell
#$wsr = $ws.popup("Start recording with 3 minutes, Please reproduce issue",0,"Information",1 + 64)
write-output "start recording"
}
Export-ModuleMember -Function feedbackstart