dotnet / docs-maui

This repository contains documentation for .NET Multi-platform App UI (MAUI).
https://docs.microsoft.com/dotnet/maui
Creative Commons Attribution 4.0 International
227 stars 200 forks source link

Bundle filePath missing concrete example `filePath` for a concrete file #2459

Closed Michal-MK closed 2 months ago

Michal-MK commented 2 months ago

Type of issue

Missing information

Description

I arrived at this page looking for the filePath format, the documentation here has an example of loading a file from the bundle but it is a parameter and not a real path.

A concrete example would be a project structure image and a concrete path of how to obtain the file in the image. Eg. a font from "Resrouces/Fonts/MyFont.ttf".

Page URL

https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/storage/file-system-helpers?view=net-maui-8.0&tabs=android

Content source URL

https://github.com/dotnet/docs-maui/blob/main/docs/platform-integration/storage/file-system-helpers.md

Document Version Independent Id

5b7e12aa-3c09-0f82-2fa2-a39c2c8065d8

Article author

@davidbritch

Metadata


Associated WorkItem - 303969

Michal-MK commented 2 months ago

Going to https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.storage.filesystem.openapppackagefileasync?view=net-maui-8.0 shows that just the name should be used. So the parameter name is misleading? Trying it now.

davidbritch commented 2 months ago

Hi @Michal-MK

There isn't an example for reading from a file from its project location (e.g. Resources/Fonts/MyFont.ttf), from your app package/bundle because the app package/bundle has no concept of the file layout within the single project. Instead, the single project file resources are placed in different locations in the app package on each platform.

Michal-MK commented 2 months ago

@davidbritch not sure what that means, I used one path for both AN and iOS and it opened the file in the bundle. I also never mentioned single project but yes we are using a single project approach.

await using var standardFont = await FileSystem.OpenAppPackageFileAsync(FontName);
await using var iconFont = await FileSystem.OpenAppPackageFileAsync(iconFontName);

Names literally being:

const string FontName = VariantService.IsVariantHu
    ? "MuseoSansCyrl_300-1.0.0.ttf"
    : "Gotham-Book-1.0.0.ttf";

string iconFontName = $"IconsFont-{DeviceInfo.Platform}-{MauiProgram.IconsFontVersion}.ttf";

So either I do not understand what you were saying or the paths are in fact platform agnostic. And just the file name is necessary (as I said in the first comment). So feel free to correct me or use the sample I provided here since it works for me.

Michal-MK commented 2 months ago

Tested on MAUI 8.0.21 btw.

davidbritch commented 2 months ago

Hi @Michal-MK

Thanks for your response. So yeah, we're on the same page now - I've got your meaning so will get the doc updated. Thanks!

Michal-MK commented 2 months ago

@davidbritch I feel like the docs should also mention the fact that the filesystem is flattened, and directories as such do not exist. (That is the important info, they way people work with the Stream is up to them and unrelated to the issue I had) Also what happens when there are two files with the same name in different directories?