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

[mono] Implement Environment.GetFolderPath on iOS #34022

Merged
merged 18 commits into from
Mar 31, 2020

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Mar 24, 2020

Implements #34007

Now Environment.GetFolderPath(...) is fully compatible with Xamarin.iOS, e.g. on my device:

ApplicationData:         /var/mobile/Containers/Data/Application/%guid%/Documents/.config
CommonApplicationData:   /usr/share
CommonTemplates:         /usr/share/templates
Desktop:                 /var/mobile/Containers/Data/Application/%guid%/Documents/Desktop
DesktopDirectory:        /var/mobile/Containers/Data/Application/%guid%/Documents/Desktop
Favorites:               /var/mobile/Containers/Data/Application/%guid%/Library/Favorites
Fonts:                   /var/mobile/Containers/Data/Application/%guid%/Documents/.fonts
InternetCache:           /var/mobile/Containers/Data/Application/%guid%/Library/Caches
LocalApplicationData:    /var/mobile/Containers/Data/Application/%guid%/Documents
MyDocuments:             /var/mobile/Containers/Data/Application/%guid%/Documents
MyDocuments:             /var/mobile/Containers/Data/Application/%guid%/Documents
MyMusic:                 /var/mobile/Containers/Data/Application/%guid%/Documents/Music
MyPictures:              /var/mobile/Containers/Data/Application/%guid%/Documents/Pictures
MyVideos:                /var/mobile/Containers/Data/Application/%guid%/Documents/Videos
ProgramFiles:            /Applications
Resources:               /var/mobile/Containers/Data/Application/%guid%/Library
Templates:               /var/mobile/Containers/Data/Application/%guid%/Documents/Templates
UserProfile:             /private/var/mobile/Containers/Data/Application/%guid%

(other folders are empty)

fully matches with what I get via current Xamarin.iOS.

In theory it's possible to implement it on top of getenv("HOME") but our ios team insisted we should keep using the native API (NSFileManager) since Apple tends to change things.

Also, fix Environment.GetEnvironmentVariable for iOS, it used to return "" always.

/cc @rolfbjarne

@marek-safar marek-safar added the os-ios Apple iOS label Mar 24, 2020
# Conflicts:
#	src/mono/netcore/System.Private.CoreLib/src/System/Environment.Unix.Mono.cs
Copy link
Member

@akoeplinger akoeplinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion, looks fine otherwise :)

while (pos < line.Length && char.IsWhiteSpace(line[pos])) pos++;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the code here was modified, it just moved files, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Could you please approve it if it looks ok, thanks

internal static partial class Sys
{
[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SearchPath")]
internal static extern string SearchPath(NSSearchPathDirectory folderId);
Copy link
Member

@stephentoub stephentoub Mar 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's this can return null, it should be string?. Same for other places it might propagate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephentoub should I also add #nullability enable ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if Interlocked.CompareExchange(ref s_specialFolders, new Dictionary<SpecialFolder, string>(), null); tells Roslyn it's not null anymore

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should I also add #nullability enable ?

You shouldn't need to.

Wonder if Interlocked.CompareExchange(ref s_specialFolders, new Dictionary<SpecialFolder, string>(), null); tells Roslyn it's not null anymore

That will inform the compiler that, immediately after this call, s_specialFolders isn't null.

Unfortunately it looks like mono's Corelib.csproj is disabling all nullability warnings:

<!-- Disable nullability-related warnings -->
<NoWarn>$(NoWarn),CS8597,CS8600,CS8601,CS8602,CS8603,CS8604,CS8609,CS8611,CS8618,CS8620,CS8625,CS8631,CS8632,CS8634</NoWarn>
<NoWarn>$(NoWarn),618,67</NoWarn>

I'll take a look at fixing that.

@stephentoub stephentoub merged commit 372bf42 into dotnet:master Mar 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants