Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature proposal:Provide BackgroundDownloader in Windows App SDK #4426

Open
Gaoyifei1011 opened this issue May 17, 2024 · 11 comments
Open

Feature proposal:Provide BackgroundDownloader in Windows App SDK #4426

Gaoyifei1011 opened this issue May 17, 2024 · 11 comments

Comments

@Gaoyifei1011
Copy link

Gaoyifei1011 commented May 17, 2024

Describe the bug

Please provide BackgroundDownloader in Windows App SDK

In the Windows UWP namespace, there is an API called BackgroundDownloader that can download files in the background, however, this API can only run in the container, which is limited in desktop applications and difficult to call. I hope the Windows App SDK team will seriously consider redesigning a BackgroundDownloader API for downloading files in the Windows App SDK. This API breaks through the limitations of UWP BackgroundDownloader and can download files smoothly. When downloading files, you can call the newly added delivery optimization interface of Windows 10 1809.

在 Windows UWP 命名空间中,有一个 API 叫 BackgroundDownloader 可以在后台下载文件,然而,这个 API 只能在容器中运行,这在桌面应用中存在限制,很难调用。希望 Windows App SDK 团队能认真考虑一下,重新设计一个在 Windows App SDK 下载文件的 BackgroundDownloader API,该 API 突破 UWP BackgroundDownloader 的限制,可以顺利下载文件,下载文件时,可以调用 Windows 10 1809 新添加的传递优化接口。

UWP BackgroundDownloader API:https://learn.microsoft.com/zh-cn/uwp/api/windows.networking.backgroundtransfer.backgrounddownloader?view=winrt-22621
Desktop app use BackgroundDownloader API problem:microsoft/microsoft-ui-xaml#6952
Delivery optimization API : https://learn.microsoft.com/zh-cn/windows/win32/api/_delivery_optimization/

Steps to reproduce the bug

See describe

Expected behavior

Provide Microsoft.Windows.Networking.Backgroundtransfer namespace and BackgroundDownloader class API

Screenshots

None

NuGet package version

Windows App SDK 1.5.3: 1.5.240428000

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022

Additional context

None

@DarranRowe
Copy link

Just to ask, is BITS not viable for you?
If you just don't like the COM API then I totally understand.

@Gaoyifei1011
Copy link
Author

Just to ask, is BITS not viable for you? If you just don't like the COM API then I totally understand.

Compared to bits, we found that delivery optimization supports p2p, and the minimum supported version of delivery optimization is the same as the minimum supported version of Windowsappsdk, and is widely used for Windows updates and store app downloads.
Also, I don't like to call the com api directly because it's a pain to write with net core comwrappers
Screenshot_2024-05-18-21-08-04-749_com tencent tim

@castorix
Copy link

castorix commented May 19, 2024

I did some tests and I could use BackgroundDownloader in an unpackaged Desktop app with CreateAppContainerProfile as explained in MSDN (https://learn.microsoft.com/en-us/windows/win32/secauthz/appcontainer-for-legacy-applications-)
But it is complicated : I added
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
otherwise I got
ERROR 0x80070490: Bootstrapper initialization failed while looking for version...
when I relaunch the app with CreateProcess and STARTUPINFOEX to start it inside the AppContainer if isAppContainer is false at startup
... and I get 0x80070005 (E_ACCESSDENIED) when I try to download a file (maybe Internet capability...)

@DarranRowe
Copy link

... and I get 0x80070005 (E_ACCESSDENIED) when I try to download a file (maybe Internet capability...)

That all depends on where you are trying to download it to. When you are running in an AppContainer, you don't have write access to the majority of your user profile. The profile is running as low integrity after all. The only guaranteed writable location you have is actually the AppContainer profile for the application.

@castorix
Copy link

... and I get 0x80070005 (E_ACCESSDENIED) when I try to download a file (maybe Internet capability...)

That all depends on where you are trying to download it to. When you are running in an AppContainer, you don't have write access to the majority of your user profile. The profile is running as low integrity after all. The only guaranteed writable location you have is actually the AppContainer profile for the application.

Yes, I tried to download to KnownFolders.PicturesLibrary (like the MSDN sample), although I added the ACL (FileSystemRights.FullControl), but useless apparently
Now I tried with GetAppContainerFolderPath and I could create a file... but it is empty with error 0x80070490, which seems to be ERROR_NOT_FOUND from Google...

@DarranRowe
Copy link

DarranRowe commented May 19, 2024

Yeah, the security principle you want is all application packages.

Screenshot 2024-05-20 004228

It is badly named because it comes from the Windows 8 days where packages and app containers were not separable.

For the HRESULT, the seven (8007) indicates that it is a Windows API error code. From the System Error Codes documentation, error 1160 (0x490) is indeed ERROR_NOT_FOUND. But that doesn't actually mean much here.

@eduardobragaxz
Copy link

BITS didn't work when trimming was enabled last time I tried.

@Gaoyifei1011
Copy link
Author

BITS didn't work when trimming was enabled last time I tried.

trimming?

@eduardobragaxz
Copy link

yes. BITS doesn't work when the property PublishTrimmed is set to true. Also, when using HttpClient to save a file in a controlled folder I get an exception and I'm unable to do so until I approve my app in windows security. Doesn't happen with BITS, so I guess anyone could save files to those folders if they want to without asking permission 😬

@Gaoyifei1011
Copy link
Author

yes. BITS doesn't work when the property PublishTrimmed is set to true. Also, when using HttpClient to save a file in a controlled folder I get an exception and I'm unable to do so until I approve my app in windows security. Doesn't happen with BITS, so I guess anyone could save files to those folders if they want to without asking permission 😬

Based on the description you provided, and based on my own use of BITS, provide a feasible solution.
You're probably using the built-in COM support, and if you need to support cropping and support AOT, you'll need to switch to ComWrappers, which is an example of my code.
https://github.com/Gaoyifei1011/GetStoreApp/blob/main/GetStoreApp/WindowsAPI/ComTypes/IBackgroundCopyCallback.cs
https://github.com/Gaoyifei1011/GetStoreApp/blob/main/GetStoreApp/WindowsAPI/ComTypes/IBackgroundCopyManager.cs
https://github.com/Gaoyifei1011/GetStoreApp/blob/main/GetStoreApp/WindowsAPI/ComTypes/IBackgroundCopyJob.cs
https://github.com/Gaoyifei1011/GetStoreApp/blob/main/GetStoreApp/WindowsAPI/ComTypes/IBackgroundCopyError.cs
https://github.com/Gaoyifei1011/GetStoreApp/blob/main/GetStoreApp/Services/Controls/Download/BitsService.cs

@eduardobragaxz
Copy link

eduardobragaxz commented May 20, 2024

Thank you!

edit: this is ridiculous. provide BackgroundDownloader in Windows App SDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants