Commit 1ff0b28
authored
Improve repair (#3886)
This PR makes some improvements to the `Microsoft.WinGet.Client` module
**Use stub preference for AppInstaller**
The default behavior for `Add-AppxPackage` is to install the full
package regardless of the preference. This PR adds `-StubPreference
UsePreference` (if the cmdlet supports it) when installing the
AppInstaller bundle. I originally want to allow the user to set the
preference, but I realized I would have to blindly call `winget
configure --enable|disable` since I don't know the state. I believe this
should be done differently with perhaps different cmdlets and add
something like `winget config --info` that prints a json with some
information like if its enabled or not and the processor info.
**Add -Force to Repair-WinGetPackage**
On some occasions, `Add-AppxPackage` failed because AppInstaller files
were in use. I added a `-Force` switch to the cmdlet that just sets
`-ForceTargetApplicationShutdown` on the add appx package call.
**Module async friendly**
All async functions in the module required to be waited. Now that we can
start an async context via `RunOnMTA`, I removed all the synchronous
wrappers calls from GitHubClient and make it such as only the top-level
cmdlet need to wait on the Task. This caused a lot of functions to be
awaited, but at the end only the top-level cmdlet should care about
manually waiting for the task which I believe is the right thing to do.
**Bring back synchronization with main PowerShell thread**
AppxModuleHelper requires its Appx Module calls to be executed in the
main PowerShell thread otherwise a new runtime would need to be created
for every cmdlet that uses this class. I brought back the old
synchronization mechanism of `Microsoft.WinGet.Configure` to do this.
Now any cmdlet that runs asynchronously and requires PowerShell Host can
do it without creating its runspace.
**Redo progress for Install/Update/Uninstall-WinGetPackage**
I was not a huge fan of how progress was handled in these cmdlets. Given
that I can now create an asynchronous context, I simplify how progress
is done and follow a similar pattern as `Microsoft.WinGet.Configure`.
The `IAsyncOperationWithProgress` is executed, set its Progress handler,
converted to a Task and awaited all in one common method. I also fixed
how the progress was calculated so it reflects almost the same as
winget. .NET rounded the number so for some package I was 92.3 MB in
winget and 92.4 the module (before it was like 97or something).
**Add proper can cancellation support**
Modify the Install/Update/Uninstall cmdlets to properly use PowerShell's
`StopProcessing` for cancellation. The Task from
`IAsyncOperationWithProgress` uses the PowerShellCmdlet
CancellationToken, so everything is handled correctly. Also add
cancellation to `Repair-WinGetPackage`. The repair state machine sees if
the token is cancelled as the first thing on the loop.
**Download URL with progress.**
The module attempts to install a package using `Add-AppxPackage` with
the url of the package. In the case it fails, like in Windows Sandbox,
the package is downloaded to disk and then installed via the same
cmdlet. Depending on the network, the download could take a while and
there's no indication that work is being performed without `-Verbose`.
This PR adds a PowerShell progress bar for the download when the
response contains a Content-Length property. If cancellation is request
during url download, the async calls will be cancelled the file will be
deleted.1 parent fb540a2 commit 1ff0b28
27 files changed
Lines changed: 901 additions & 485 deletions
File tree
- src/PowerShell
- CommonFiles
- Microsoft.WinGet.Client.Cmdlets/Cmdlets
- Microsoft.WinGet.Client.Engine
- Commands
- Common
- Common
- Extensions
- Helpers
- Properties
- Microsoft.WinGet.Configuration.Engine/Extensions
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
37 | 40 | | |
| 41 | + | |
38 | 42 | | |
39 | 43 | | |
| 44 | + | |
| 45 | + | |
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
| |||
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
60 | | - | |
| 66 | + | |
61 | 67 | | |
62 | 68 | | |
63 | 69 | | |
| |||
81 | 87 | | |
82 | 88 | | |
83 | 89 | | |
84 | | - | |
| 90 | + | |
85 | 91 | | |
86 | 92 | | |
87 | 93 | | |
| |||
134 | 140 | | |
135 | 141 | | |
136 | 142 | | |
137 | | - | |
| 143 | + | |
138 | 144 | | |
139 | 145 | | |
140 | 146 | | |
| |||
186 | 192 | | |
187 | 193 | | |
188 | 194 | | |
189 | | - | |
| 195 | + | |
190 | 196 | | |
191 | 197 | | |
192 | 198 | | |
| |||
229 | 235 | | |
230 | 236 | | |
231 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
232 | 258 | | |
233 | 259 | | |
234 | 260 | | |
| |||
239 | 265 | | |
240 | 266 | | |
241 | 267 | | |
242 | | - | |
| 268 | + | |
243 | 269 | | |
244 | 270 | | |
245 | 271 | | |
246 | 272 | | |
247 | 273 | | |
248 | 274 | | |
249 | | - | |
| 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 | + | |
250 | 316 | | |
251 | 317 | | |
252 | 318 | | |
253 | 319 | | |
254 | 320 | | |
255 | 321 | | |
256 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
257 | 329 | | |
258 | 330 | | |
259 | 331 | | |
| |||
269 | 341 | | |
270 | 342 | | |
271 | 343 | | |
272 | | - | |
273 | 344 | | |
274 | | - | |
| 345 | + | |
275 | 346 | | |
276 | | - | |
| 347 | + | |
277 | 348 | | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
278 | 352 | | |
279 | 353 | | |
280 | | - | |
| 354 | + | |
281 | 355 | | |
282 | 356 | | |
283 | 357 | | |
| |||
311 | 385 | | |
312 | 386 | | |
313 | 387 | | |
314 | | - | |
| 388 | + | |
| 389 | + | |
315 | 390 | | |
316 | 391 | | |
317 | 392 | | |
318 | 393 | | |
319 | 394 | | |
320 | 395 | | |
321 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
322 | 419 | | |
323 | 420 | | |
324 | 421 | | |
325 | 422 | | |
326 | 423 | | |
327 | | - | |
| 424 | + | |
328 | 425 | | |
329 | 426 | | |
330 | 427 | | |
331 | 428 | | |
332 | 429 | | |
333 | | - | |
| 430 | + | |
334 | 431 | | |
335 | 432 | | |
336 | 433 | | |
| |||
399 | 496 | | |
400 | 497 | | |
401 | 498 | | |
402 | | - | |
| 499 | + | |
403 | 500 | | |
404 | 501 | | |
405 | 502 | | |
| |||
430 | 527 | | |
431 | 528 | | |
432 | 529 | | |
433 | | - | |
| 530 | + | |
434 | 531 | | |
435 | 532 | | |
436 | 533 | | |
| |||
485 | 582 | | |
486 | 583 | | |
487 | 584 | | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
488 | 607 | | |
489 | 608 | | |
490 | 609 | | |
| |||
Lines changed: 15 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
45 | 47 | | |
46 | | - | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
62 | 74 | | |
63 | 75 | | |
64 | 76 | | |
Lines changed: 22 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
36 | | - | |
| 44 | + | |
37 | 45 | | |
38 | 46 | | |
39 | | - | |
| 47 | + | |
40 | 48 | | |
41 | 49 | | |
42 | 50 | | |
43 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
44 | 63 | | |
45 | 64 | | |
46 | 65 | | |
| |||
0 commit comments