Closed CartBlanche closed 2 years ago
Q: Would it be better to do a PR into Mono/.NET for .NET 6 to itnroduce the change for Android?
Hi @jamesmontemagno, Hope you and your family are well during this crazy year. Yes, I had considered that but after chatting to the Android team, it seems that might not be possible as all resource/asset handling on Android is handled by the AssetManager and not via a direct directory structure, I'm told. I'm still waiting to hear back from 1 more person on the .NET side.
So in the mean time I've been working on a possible PR for Essentials, if that sort of thing is of interest and would be a different proposition to what I suggested above. Instead the API would be something like...
string[] FileSystem.AppResourceDirectories(string path)
and
string[] FileSystem.AppResourceFiles(string directoryPath)
Therefore under the hood, they would do the correct platform specific calls to return their respective string arrays.
It would also work under Android as the call to Assets.List(path)
returns a string[] too and for iOS/Mac they could use the Directory.* equivalents, that we know work.
Do you think this would be useful to Essentials, or should I keep the changes to myself?
Gotcha, that is sad. I would say send down the PR. I like our FileSystem helper class a lot :)
The real question will be how to ensure consistency with the other operating systems.
I have a draft PR here - https://github.com/xamarin/Essentials/pull/1557 Need a bit more testing before it is ready for review, I think.
I think this is part of .NET MAUI already?
@jfversluis I noticed you closed this is it part of MAUI or Essentials? One has a UI overhead the other doesn't.
Also this feature is very specifically about retrieving directory and file structures within the Resource
or equivalent, platform specific directory. Is that supported elsewhere?? Is So could you at least link to the API where the aforementioned enhancement works??
https://github.com/dotnet/maui/blob/main/src/Essentials/src/FileSystem/FileSystem.shared.cs#L14
@jfversluis this already existed in Essentials and isn't what this issue raised or was trying to address. The API you linked to does not address this issue, as far as I can tell. The intended use case is clearly listed above as the ....
need to resolve consistently to the
Resources
directory under iOS/macOS and to theAssets
folder under Android because I have a subdirectory in those locations, that vary from app to app, so I need to traverse/recurse through them to load all the required files on startup.
If this ability exists in MAUI elsewhere, then please let me know where??
Then I probably don't understand what you are trying to do :)
In any case, you probably want to see if this is an enhancement that is of interest to you for .NET MAUI. This won't be happening for Xamarin.Essentials anymore. Thanks!
@jfversluis Understood. Can I resubmit my PR(obviously after due diligence) to MAUI, if that is the only future? Is the team accepting PR from non MS folk?
Summary
On iOS and macOS the call to Directory.GetCurrentDirectory (); resolves to the Resources directory while on Android it just resolves to /.
I need all of them to resolve consistently to the Resources directory under iOS/macOS and to the Assets folder under Android because I have a subdirectory in those locations, that vary from app to app, so I need to traverse/recurse through them to load all the required files on startup.
Now Xamarin.Essentials has FileSystem.OpenAppPackageFileAsync, which is great if you know the exact name of the file you want to load, but not if you want to traverse/recurse sub-directories.
API Changes
I would like a
string FileSystem.AppResourcesDirectory
property that just resolves to Resources directory under iOS/macOS and to the Assets folder under Android and the respective equivalents under Windows, Tizen and elsewhere.Intended Use Case
I need all of them to resolve consistently to the Resources directory under iOS/macOS and to the Assets folder under Android because I have a subdirectory in those locations, that vary from app to app, so I need to traverse/recurse through them to load all the required files on startup.
If there is already a cross-platform way to do this, apologies for the waste of bandwidth :)