Undesired behaviour of FileSystem.Current.AppDataDirectory
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 297
Description
### Description
When you use `FileSystem.Current.AppDataDirectory` it outputs a location that according to the [documentation](https://docs.microsoft.com/en-us/dotnet/maui/platform-integration/storage/file-system-helpers?tabs=android#app-data-directory) is
> ...the app's top-level directory for any files that aren't user data files. These files are backed up with the operating system syncing framework.
But the output of this on different platforms leads to confusing results.
| OS | AppDataDirectory |
|-----|------------------|
| iOS (simulator) | /Users/bradmoore/Library/Developer/CoreSimulator/Devices/7195125F-89A0-40B7-A8DB-1B343B2AF596/data/Containers/Data/Application/B6A225B4-55DE-447C-A407-6CFA3D118553/Library/ |
| macOS | /Users/beeradmoore/Library/ |
| Android | /data/user/0/com.beeradmoore.myAppName/files/ |
| Windows | C:\Users\beeradmoore\AppData\Local\Packages\52ed336e-9df8-43e1-9c04-74392cd48f3d-218743784238_fids9vfx8fwe\LocalState\ |
I believe that using `AppDataDirectory` should give a directory specific to your application. However on macOS it drops you into the root folder of where many applications place files. RIP my ~/Library/ folder which is now a mess on account of [not even being able to debug basic strings anymore](https://github.com/dotnet/maui/issues/7009).
I would propose that for macOS [PlatformAppDataDirectory](https://github.com/dotnet/maui/blob/f8936a5c62d35eecd95d4345dcb30e1db2419d2d/src/Essentials/src/FileSystem/FileSystem.ios.tvos.watchos.macos.cs#L13) created a folder with application name in either `~/User/Library//` or `~/Library/Application Support//` to give consistent behaviour across all platforms (application_name could also be bundle_id)
Additionally I don't know if these files (possibly those Windows) are backed up by the OS to any cloud.
### Steps to Reproduce
Create a MAUI app and run this on different platforms.
```
System.Diagnostics.Debug.WriteLine(FileSystem.Current.AppDataDirectory");
```
### Version with bug
6.0 (current)
### Last version that worked well
Unknown/Other
### Affected platforms
macOS
### Affected platform versions
macOS 12.4
### Did you find any workaround?
Custom handle file paths when building MAUI app for macOS.
### Relevant log output
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.