Repository navigation
[System.Configuration] Fix settings upgrade on iOS and tvOS #132283
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
base: main
Are you sure you want to change the base?
Changes from all commits
b9afa20
f94319c
8ab2d55
b22ce05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||||||||||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||||||||||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||||||||||||||
|
|
||||||||||||||||||
| using System; | ||||||||||||||||||
| using System.Runtime.InteropServices; | ||||||||||||||||||
|
|
||||||||||||||||||
| internal static partial class Interop | ||||||||||||||||||
| { | ||||||||||||||||||
| internal static partial class CoreFoundation | ||||||||||||||||||
| { | ||||||||||||||||||
| internal const uint kCFStringEncodingUTF8 = 0x08000100; | ||||||||||||||||||
|
|
||||||||||||||||||
| [LibraryImport(Libraries.CoreFoundationLibrary)] | ||||||||||||||||||
| internal static partial IntPtr CFBundleGetIdentifier(IntPtr bundle); | ||||||||||||||||||
|
|
||||||||||||||||||
| [LibraryImport(Libraries.CoreFoundationLibrary)] | ||||||||||||||||||
| internal static partial IntPtr CFBundleGetMainBundle(); | ||||||||||||||||||
|
|
||||||||||||||||||
| [LibraryImport(Libraries.CoreFoundationLibrary)] | ||||||||||||||||||
| internal static unsafe partial byte CFStringGetCString( | ||||||||||||||||||
| IntPtr value, | ||||||||||||||||||
| byte* buffer, | ||||||||||||||||||
| IntPtr bufferSize, | ||||||||||||||||||
| uint encoding); | ||||||||||||||||||
|
|
||||||||||||||||||
| [LibraryImport(Libraries.CoreFoundationLibrary)] | ||||||||||||||||||
| internal static partial IntPtr CFStringGetLength(IntPtr value); | ||||||||||||||||||
|
|
||||||||||||||||||
| [LibraryImport(Libraries.CoreFoundationLibrary)] | ||||||||||||||||||
| internal static partial IntPtr CFStringGetMaximumSizeForEncoding(IntPtr length, uint encoding); | ||||||||||||||||||
|
Comment on lines
+27
to
+30
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same:
Suggested change
|
||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Kernel32 | ||
| { | ||
| [LibraryImport(Libraries.Kernel32)] | ||
| internal static unsafe partial int GetCurrentPackageFamilyName(uint* packageFamilyNameLength, char* packageFamilyName); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Libraries | ||
| { | ||
| internal const string CoreFoundationLibrary = "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation"; | ||
| internal const string Kernel32 = "kernel32.dll"; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||||||||||||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||||||||||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||||||||||||||
|
|
||||||||||||||||||
| using System; | ||||||||||||||||||
| using System.Text; | ||||||||||||||||||
|
|
||||||||||||||||||
| namespace System.Configuration | ||||||||||||||||||
| { | ||||||||||||||||||
| internal static class AppleApplication | ||||||||||||||||||
| { | ||||||||||||||||||
| internal static unsafe string GetMainBundleIdentifier() | ||||||||||||||||||
| { | ||||||||||||||||||
| IntPtr bundle = Interop.CoreFoundation.CFBundleGetMainBundle(); | ||||||||||||||||||
| IntPtr identifier = bundle == IntPtr.Zero | ||||||||||||||||||
| ? IntPtr.Zero | ||||||||||||||||||
| : Interop.CoreFoundation.CFBundleGetIdentifier(bundle); | ||||||||||||||||||
| if (identifier == IntPtr.Zero) | ||||||||||||||||||
| { | ||||||||||||||||||
| return null; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| IntPtr length = Interop.CoreFoundation.CFStringGetLength(identifier); | ||||||||||||||||||
| long maximumByteCount = Interop.CoreFoundation.CFStringGetMaximumSizeForEncoding( | ||||||||||||||||||
| length, | ||||||||||||||||||
| Interop.CoreFoundation.kCFStringEncodingUTF8).ToInt64(); | ||||||||||||||||||
| if (maximumByteCount < 0 || maximumByteCount >= int.MaxValue) | ||||||||||||||||||
|
Comment on lines
+23
to
+26
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that would simplify this part a bit too:
Suggested change
|
||||||||||||||||||
| { | ||||||||||||||||||
| return null; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| byte[] buffer = new byte[(int)maximumByteCount + 1]; | ||||||||||||||||||
| fixed (byte* bufferPtr = buffer) | ||||||||||||||||||
| { | ||||||||||||||||||
| if (Interop.CoreFoundation.CFStringGetCString( | ||||||||||||||||||
| identifier, | ||||||||||||||||||
| bufferPtr, | ||||||||||||||||||
| new IntPtr(buffer.Length), | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and:
Suggested change
|
||||||||||||||||||
| Interop.CoreFoundation.kCFStringEncodingUTF8) == 0) | ||||||||||||||||||
| { | ||||||||||||||||||
| return null; | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| int terminator = Array.IndexOf(buffer, (byte)0); | ||||||||||||||||||
| if (terminator < 0) | ||||||||||||||||||
| { | ||||||||||||||||||
| return null; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return Encoding.UTF8.GetString(buffer, 0, terminator); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kind of nit-picking, but
bufferSizeisn't a pointer, so: