public string GetDescription(IntPtr handle) { if (handle == IntPtr.Zero) throw new ArgumentNullException ("handle"); using (var s = new CFString (CFCopyDescription (handle))) return s.ToString (); }
public static string ToString(IntPtr pdfString) { if (pdfString == IntPtr.Zero) return null; using (var cfs = new CFString (CGPDFStringCopyTextString (pdfString), true)) { return cfs.ToString (); } }
public static string GetRoleDescription(NSObject element) { if (element == null) { throw new ArgumentNullException("element"); } IntPtr handle = NSAccessibilityRoleDescriptionForUIElement(element.Handle); return(CFString.FromHandle(handle)); }
static string ReturnString(IntPtr newStringHandle) { if (newStringHandle == IntPtr.Zero) { return(null); } var ret = CFString.FetchString(newStringHandle); CFObject.CFRelease(newStringHandle); return(ret); }
public static string GetActionDescription(NSString action) { if (action == null) { throw new ArgumentNullException("action"); } IntPtr handle = NSAccessibilityActionDescription(action.Handle); return(CFString.FromHandle(handle)); }
public static string [] GetSelectedLanguages(MACaptionAppearanceDomain domain) { using (var langs = new CFArray(MACaptionAppearanceCopySelectedLanguages((int)domain), owns: true)) { var languages = new string [langs.Count]; for (int i = 0; i < langs.Count; i++) { languages[i] = CFString.FetchString(langs.GetValue(i)); } return(languages); } }
public void ArrayFromHandleFuncTest_bool_true() { var handle = CFArray.Create(TestArray); CFRetain(handle); var a = CFArray.ArrayFromHandleFunc <string> (handle, (v) => CFString.FromHandle(v), true); VerifyArray(a); Assert.AreEqual((nint)1, CFGetRetainCount(handle), "RC"); CFRelease(handle); }
public static PMPrinter TryCreate(string printerId) { using (var idf = new CFString(printerId)){ var h = PMPrinterCreateFromPrinterID(idf.Handle); if (h == IntPtr.Zero) { return(null); } return(new PMPrinter(h, owns: true)); } }
protected string GetStringValue(string key) { if (key == null) { throw new ArgumentNullException("key"); } using (var str = new CFString(key)) { return(CFString.FetchString(CFDictionary.GetValue(Dictionary.Handle, str.handle))); } }
public string GetMethod() { var ptr = CFHTTPAuthenticationCopyMethod(Handle); if (ptr == IntPtr.Zero) { return(null); } using (var method = new CFString(ptr)) return(method); }
public void LowlevelSetObject(string str, IntPtr key) { if (str is null) { ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(str)); } var ptr = CFString.CreateNative(str); LowlevelSetObject(ptr, key); CFString.ReleaseNative(ptr); }
public void Index() { var str = "Ab🤔日ㅁ名"; using var nativeStr = new CFString(str); var array = str.ToCharArray(); for (int i = 0; i < array.Length; i++) { Assert.AreEqual(str[i], nativeStr[i], $"{str[i]} != {nativeStr[i]}"); } }
public static CGFont CreateWithFontName(string name) { // the API accept a `nil` argument but returns `nil`, we take a shortcut (no native call) // and have a unit tests to make sure this behavior does not change over time if (name == null) { return(null); } using (CFString s = name){ return(new CGFont(CGFontCreateWithFontName(s.Handle), true)); } }
static public string ToString(IntPtr pdfString) { if (pdfString == IntPtr.Zero) { return(null); } using (var cfs = new CFString(CGPDFStringCopyTextString(pdfString), true)) { return(cfs.ToString()); } }
public bool Schedule(CFRunLoop runLoop, string mode) { if (runLoop == null) { throw new ArgumentNullException("runLoop"); } // new CFString already does a null check using (var cfstring = new CFString(mode)){ return(SCNetworkReachabilityScheduleWithRunLoop(handle, runLoop.Handle, cfstring.Handle)); } }
internal static bool PreventUserIdleDisplaySleep(CFString name, out uint id) { var result = IOPMAssertionCreateWithName( kIOPMAssertionTypePreventUserIdleDisplaySleep.Handle, kIOPMAssertionLevelOn, name.Handle, out var newId); id = result == 0 ? newId : 0; return(result == 0); }
public static string?[]? GetExtensions(AudioFileType fileType) { IntPtr ptr; var size = (uint)sizeof(IntPtr); if (AudioFileGetGlobalInfo(AudioFileGlobalProperty.ExtensionsForType, sizeof(AudioFileType), ref fileType, ref size, out ptr) != 0) { return(null); } return(NSArray.ArrayFromHandleFunc(ptr, l => CFString.FromHandle(l))); }
public PMPrinter(string printerId) { using (var idf = new CFString(printerId)){ var value = PMPrinterCreateFromPrinterID(idf.Handle); if (value == IntPtr.Zero) { throw new PMPrintException(PMStatusCode.InvalidPrinter); } handle = value; } }
static public SecPolicy CreateSslPolicy(bool server, string hostName) { CFString host = hostName == null ? null : CFString.Create(hostName); IntPtr handle = host == null ? IntPtr.Zero : host.Handle; SecPolicy policy = new SecPolicy(SecPolicyCreateSSL(server, handle), true); if (host != null) { host.Dispose(); } return(policy); }
static public string GetCaption(NSUrl url, out NSError error) { if (url == null) { throw new ArgumentNullException(nameof(url)); } var result = MAImageCaptioningCopyCaption(url.Handle, out var e); error = e == IntPtr.Zero ? null : new NSError(e); return(CFString.FromHandle(result, releaseHandle: true)); }
public static string[] GetMIMETypes(AudioFileType fileType) { IntPtr ptr; var size = (uint)sizeof(IntPtr); if (AudioFileGetGlobalInfo(AudioFileGlobalProperty.MIMETypesForType, sizeof(AudioFileType), ref fileType, ref size, out ptr) != 0) { return(null); } return(NSArray.ArrayFromHandleFunc(ptr, l => CFString.FetchString(l))); }
public void ToCFString(string stringDescription, string stringValue) { if (stringValue == null) { return; } using (var cfString = new CFString(stringValue)) { var roundTripStringValue = cfString.ToString(); Assert.Equal(stringValue, roundTripStringValue); } }
public static string GetFileTypeName(AudioFileType fileType) { IntPtr ptr; var size = (uint)sizeof(IntPtr); if (AudioFileGetGlobalInfo(AudioFileGlobalProperty.FileTypeName, sizeof(AudioFileType), ref fileType, ref size, out ptr) != 0) { return(null); } return(CFString.FetchString(ptr)); }
public static string CreatePreferredIdentifier(string tagClass, string tag, string conformingToUti) { var a = NSString.CreateNative(tagClass); var b = NSString.CreateNative(tag); var c = NSString.CreateNative(conformingToUti); var ret = CFString.FromHandle(UTTypeCreatePreferredIdentifierForTag(a, b, c)); NSString.ReleaseNative(a); NSString.ReleaseNative(b); NSString.ReleaseNative(c); return(ret); }
static PlatformHardDriveMediaType GetMediaType(string path) { IntPtr diskHandle = IntPtr.Zero; IntPtr sessionHandle = IntPtr.Zero; IntPtr charDictRef = IntPtr.Zero; uint service = 0; try { sessionHandle = DASessionCreate(IntPtr.Zero); // This seems to only work for '/' var url = CFUrl.FromFile(path); diskHandle = DADiskCreateFromVolumePath(IntPtr.Zero, sessionHandle, url.Handle); if (diskHandle == IntPtr.Zero) { return(PlatformHardDriveMediaType.Unknown); } service = DADiskCopyIOMedia(diskHandle); var cfStr = new CFString("Device Characteristics"); charDictRef = IORegistryEntrySearchCFProperty(service, "IOService", cfStr.Handle, IntPtr.Zero, 3); // CFDictionary owns the object pointed to by resultHandle, so no need to release it var resultHandle = CFDictionaryGetValue(charDictRef, new CFString("Medium Type").Handle); if (resultHandle == IntPtr.Zero) { return(PlatformHardDriveMediaType.Unknown); } var resultString = (string)NSString.FromHandle(resultHandle); if (resultString == "Solid State") { return(PlatformHardDriveMediaType.SolidState); } else if (resultString == "Rotational") { return(PlatformHardDriveMediaType.Rotational); } else { return(PlatformHardDriveMediaType.Unknown); } } finally { if (service != 0) { IOObjectRelease(service); } CFRelease(sessionHandle); CFRelease(charDictRef); } }
public static NSDictionary GetDeclaration(string uti) { if (uti is null) { ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(uti)); } var a = CFString.CreateNative(uti); var ret = Runtime.GetNSObject <NSDictionary> (UTTypeCopyDeclaration(a)); CFString.ReleaseNative(a); return(ret); }
public static string GetBundleIdentifierForClass(string className) { var classNameAsCFString = new CFString(className); var bundleIdentifierRef = IOObjectCopyBundleIdentifierForClass(classNameAsCFString.Handle); var bundleIdentifier = new CFString(bundleIdentifierRef); if (bundleIdentifierRef == IntPtr.Zero) { return(null); } CFType.Release(bundleIdentifierRef); return(bundleIdentifier.ToString()); }
public CTFontDescriptor(string name, nfloat size) { if (name == null) { throw ConstructorError.ArgumentNull(this, "name"); } using (CFString n = name) handle = CTFontDescriptorCreateWithNameAndSize(n.Handle, size); if (handle == IntPtr.Zero) { throw ConstructorError.Unknown(this); } }
public CTFont(CTFontUIFontType uiType, float size, string language) { if (language == null) { throw ConstructorError.ArgumentNull(this, "language"); } using (CFString l = language) handle = CTFontCreateUIFontForLanguage(uiType, size, l.Handle); if (handle == IntPtr.Zero) { throw ConstructorError.Unknown(this); } }
public static Class GlobalGetClass(string codedName) { if (codedName is null) { ObjCRuntime.ThrowHelper.ThrowArgumentNullException(nameof(codedName)); } var ptr = CFString.CreateNative(codedName); var result = new Class(ObjCRuntime.Messaging.IntPtr_objc_msgSend_IntPtr(class_ptr, Selector.GetHandle("classForClassName:"), ptr)); CFString.ReleaseNative(ptr); return(result); }
public static string GetDescription(string uti) { if (uti == null) { throw new ArgumentNullException("uti"); } var a = NSString.CreateNative(uti); var ret = CFString.FromHandle(UTTypeCopyDescription(a)); NSString.ReleaseNative(a); return(ret); }
public CTFont(string name, float size, ref CGAffineTransform matrix, CTFontOptions options) { if (name == null) { throw ConstructorError.ArgumentNull(this, "name"); } using (CFString n = name) handle = CTFontCreateWithNameAndOptions(n.Handle, size, ref matrix, options); if (handle == IntPtr.Zero) { throw ConstructorError.Unknown(this); } }
public string GetMethod () { ThrowIfDisposed (); var ptr = CFHTTPAuthenticationCopyMethod (Handle); if (ptr == IntPtr.Zero) return null; using (var method = new CFString (ptr)) return method; }
public void AddDestination(string name, CGPoint point) { if (name == null) throw new ArgumentNullException ("name"); using (var s = new CFString (name)) CGPDFContextAddDestinationAtPoint (Handle, s.Handle, point); }
public static extern void IOHIDDeviceScheduleWithRunLoop( IOHIDDeviceRef device, CFRunLoop inCFRunLoop, CFString inCFRunLoopMode);
public static extern void IOHIDManagerScheduleWithRunLoop( IOHIDManagerRef inIOHIDManagerRef, CFRunLoop inCFRunLoop, CFString inCFRunLoopMode);
public CFPropertyList(string plistlocation) { IntPtr inputfilename; inputfilename = new CFString(plistlocation); IntPtr ifile_IntPtr = CFURLCreateWithFileSystemPath(IntPtr.Zero, inputfilename, 2, false); IntPtr ifile_CFReadStreamRef = CFReadStreamCreateWithFile(IntPtr.Zero, ifile_IntPtr); if ((CFReadStreamOpen(ifile_CFReadStreamRef)) == false) { typeRef = IntPtr.Zero; } IntPtr PlistRef = CFPropertyListCreateFromStream(IntPtr.Zero, ifile_CFReadStreamRef, 0, 2, 0, IntPtr.Zero); CFReadStreamClose(ifile_CFReadStreamRef); typeRef = PlistRef; }
public static CFBundle[] GetBundlesFromDirectory(NSUrl directoryUrl, string bundleType) { if (directoryUrl == null) // NSUrl cannot be "" by definition throw new ArgumentNullException ("directoryUrl"); if (String.IsNullOrEmpty (bundleType)) throw new ArgumentException ("bundleType"); using (var bundleTypeCFSting = new CFString (bundleType)) using (var cfBundles = new CFArray (CFBundleCreateBundlesFromDirectory (IntPtr.Zero, directoryUrl.Handle, bundleTypeCFSting.Handle), true)) { var managedBundles = new CFBundle [cfBundles.Count]; for (int index = 0; index < cfBundles.Count; index++) { // follow the create rules, therefore we do have ownership of each of the cfbundles managedBundles [index] = new CFBundle (cfBundles.GetValue (index), true); } return managedBundles; } }
public NSUrl GetResourceUrl(string resourceName, string resourceType, string subDirName, string localizationName) { if (String.IsNullOrEmpty (resourceName)) throw new ArgumentException ("resourceName"); if (String.IsNullOrEmpty (resourceType)) throw new ArgumentException ("resourceType"); if (String.IsNullOrEmpty (localizationName)) throw new ArgumentException ("localizationName"); using (CFString cfResourceName = new CFString (resourceName), cfResourceType = new CFString (resourceType), cfSubDir = new CFString (subDirName ?? string.Empty), cfLocalization = new CFString (localizationName)) { var urlHandle = CFBundleCopyResourceURLForLocalization (handle, cfResourceName.Handle, cfResourceType.Handle, String.IsNullOrEmpty (subDirName) ? IntPtr.Zero : cfSubDir.Handle, cfLocalization.Handle); return Runtime.GetNSObject<NSUrl> (urlHandle, true); } }
static public CFUrl FromFile (string filename) { using (var str = new CFString (filename)){ IntPtr handle = CFURLCreateWithFileSystemPath (IntPtr.Zero, str.Handle, (nint)(long)CFUrlPathStyle.POSIX, false); if (handle == IntPtr.Zero) return null; return new CFUrl (handle); } }
static internal string GetFileSystemPath (IntPtr hcfurl) { using (var str = new CFString (CFURLCopyFileSystemPath (hcfurl, 0), true)) return str.ToString (); }
public override string ToString () { using (var str = new CFString (CFURLGetString (handle))) { return str.ToString (); } }
static public CFUrl FromUrlString (string url, CFUrl baseurl) { // CFString ctor will throw an ANE if null using (var str = new CFString (url)){ return FromStringHandle (str.Handle, baseurl); } }
public void ApplyCredentialDictionary (CFHTTPAuthentication auth, NetworkCredential credential) { var keys = new NSString [3]; var values = new CFString [3]; keys [0] = _AuthenticationUsername; keys [1] = _AuthenticationPassword; keys [2] = _AuthenticationAccountDomain; values [0] = (CFString)credential.UserName; values [1] = (CFString)credential.Password; values [2] = credential.Domain != null ? (CFString)credential.Domain : null; var dict = CFDictionary.FromObjectsAndKeys (values, keys); try { CFStreamError error; var ok = CFHTTPMessageApplyCredentialDictionary ( Handle, auth.Handle, dict.Handle, out error); if (ok) return; throw GetException ((ErrorHTTPAuthentication)error.code); } finally { dict.Dispose (); values [0].Dispose (); values [1].Dispose (); if (values [2] != null) values [2].Dispose (); } }
public void ApplyCredentials (CFHTTPAuthentication auth, NetworkCredential credential) { if (auth.RequiresAccountDomain) { ApplyCredentialDictionary (auth, credential); return; } var username = new CFString (credential.UserName); var password = new CFString (credential.Password); try { CFStreamError error; var ok = CFHTTPMessageApplyCredentials ( Handle, auth.Handle, username.Handle, password.Handle, out error); if (!ok) throw GetException ((ErrorHTTPAuthentication)error.code); } finally { username.Dispose (); password.Dispose (); } }
public static string[] GetPreferredLocalizations(string[] locArray) { if (locArray == null) throw new ArgumentNullException ("locArray"); var cfString = new CFString [locArray.Length]; for (int index = 0; index < locArray.Length; index++) { cfString [index] = new CFString (locArray [index]); } using (var cfLocArray = CFArray.FromNativeObjects (cfString)) using (var cfArray = new CFArray (CFBundleCopyPreferredLocalizationsFromArray (cfLocArray.Handle), true)) { var cultureInfo = new string [cfArray.Count]; for (int index = 0; index < cfArray.Count; index++) { cultureInfo [index] = CFString.FetchString (cfArray.GetValue (index)); } return cultureInfo; } }
public static string[] GetLocalizationsForPreferences(string[] locArray, string[] prefArray) { if (locArray == null) throw new ArgumentNullException ("locArray"); if (prefArray == null) throw new ArgumentNullException ("prefArray"); var cfLocal = new CFString [locArray.Length]; for (int index = 0; index < locArray.Length; index++) { cfLocal [index] = new CFString (locArray [index]); } var cfPref = new CFString [prefArray.Length]; for (int index = 0; index < prefArray.Length; index++) { cfPref [index] = new CFString (prefArray [index]); } using (CFArray cfLocalArray = CFArray.FromNativeObjects (cfLocal), cfPrefArray = CFArray.FromNativeObjects (cfPref)) using (var cfArray = new CFArray (CFBundleCopyLocalizationsForPreferences (cfLocalArray.Handle, cfPrefArray.Handle), true)) { var cultureInfo = new string [cfArray.Count]; for (int index = 0; index < cfArray.Count; index ++) { cultureInfo [index] = CFString.FetchString (cfArray.GetValue (index)); } return cultureInfo; } }
public static CFHost Create (string name) { var ptr = new CFString (name); return new CFHost (CFHostCreateWithName (IntPtr.Zero, ptr.Handle)); }
public static CFBundle Get(string bundleID) { if (String.IsNullOrEmpty (bundleID)) throw new ArgumentException ("bundleID"); using (var cfBundleId = new CFString (bundleID)) { var cfBundle = CFBundleGetBundleWithIdentifier (cfBundleId.Handle); if (cfBundle == IntPtr.Zero) return null; // follow the Get rule and retain the obj return new CFBundle (cfBundle, false); } }
public NSUrl GetResourceUrl(string resourceName, string resourceType, string subDirName) { if (String.IsNullOrEmpty (resourceName)) throw new ArgumentException ("resourceName"); if (String.IsNullOrEmpty (resourceType)) throw new ArgumentException ("resourceType"); using (CFString cfResourceName = new CFString (resourceName), cfResourceType = new CFString (resourceType), cfDirName = (subDirName == null)? new CFString ("") : new CFString (subDirName)) { // follows the create rules and therefore we do not need to retain var urlHandle = CFBundleCopyResourceURL (handle, cfResourceName.Handle, cfResourceType.Handle, String.IsNullOrEmpty (subDirName) ? IntPtr.Zero : cfDirName.Handle); return Runtime.GetNSObject<NSUrl> (urlHandle, true); } }
public static void CreatePairWithSocketToHost (string host, int port, out CFReadStream readStream, out CFWriteStream writeStream) { using (var str = new CFString (host)) { IntPtr read, write; CFStreamCreatePairWithSocketToHost ( IntPtr.Zero, str.Handle, port, out read, out write); readStream = new CFReadStream (read); writeStream = new CFWriteStream (write); } }
public string GetLocalizedString(string key, string defaultValue, string tableName) { if (String.IsNullOrEmpty (key)) throw new ArgumentException ("key"); if (String.IsNullOrEmpty (tableName)) throw new ArgumentException ("tableName"); // we do allow null and simply use an empty string to avoid the extra check if (defaultValue == null) defaultValue = string.Empty; using (CFString cfKey = new CFString (key), cfValue = new CFString (defaultValue), cfTable = new CFString (tableName)) { return CFString.FetchString (CFBundleCopyLocalizedString (handle, cfKey.Handle, cfValue.Handle, cfTable.Handle)); } }
public static extern void IOHIDManagerUnscheduleFromRunLoop( IOHIDManagerRef inIOHIDManagerRef, CFRunLoop inCFRunLoop, CFString inCFRunLoopMode);
public NSUrl GetAuxiliaryExecutableUrl(string executableName) { if (String.IsNullOrEmpty (executableName)) throw new ArgumentException ("executableName"); using (var cfExecutableName = new CFString (executableName)) { // follows the create rule no need to retain var urlHandle = CFBundleCopyAuxiliaryExecutableURL (handle, cfExecutableName.Handle); if (urlHandle == IntPtr.Zero) return null; return Runtime.GetNSObject<NSUrl> (urlHandle, true); } }
public static extern void IOHIDDeviceUnscheduleFromRunLoop( IOHIDDeviceRef device, CFRunLoop inCFRunLoop, CFString inCFRunLoopMode);
public NSUrl[] GetResourceUrls(string resourceType, string subDirName, string localizationName) { if (String.IsNullOrEmpty (resourceType)) throw new ArgumentException ("resourceType"); if (String.IsNullOrEmpty (localizationName)) throw new ArgumentException ("localizationName"); using (CFString cfType = new CFString (resourceType), cfDirName = new CFString (subDirName ?? string.Empty), cfLocalization = new CFString (localizationName)) using (var cfArray = new CFArray (CFBundleCopyResourceURLsOfTypeForLocalization (handle, cfType.Handle, String.IsNullOrEmpty (subDirName) ? IntPtr.Zero : cfDirName.Handle, cfLocalization.Handle), true)) { var urls = new NSUrl [cfArray.Count]; for (int index = 0; index < cfArray.Count; index++) { urls [index] = Runtime.GetNSObject<NSUrl> (cfArray.GetValue (index), true); } return urls; } }
public CGColor (string name) { if (name == null) throw new ArgumentNullException ("name"); using (var s = new CFString (name)){ handle = CGColorGetConstantColor (s.handle); if (handle == IntPtr.Zero) throw new ArgumentException ("name"); CGColorRetain (handle); } }
public static NSUrl GetResourceUrl(NSUrl bundleUrl, string resourceName, string resourceType, string subDirName) { if (bundleUrl == null) throw new ArgumentNullException ("bundleUrl"); if (String.IsNullOrEmpty (resourceName)) throw new ArgumentException ("resourceName"); if (String.IsNullOrEmpty (resourceType)) throw new ArgumentException ("resourceType"); // follows the create rules and therefore we do not need to retain using (CFString cfResourceName = new CFString (resourceName), cfResourceType = new CFString (resourceType), cfSubDirName = new CFString (subDirName ?? string.Empty)) { var urlHandle = CFBundleCopyResourceURLInDirectory (bundleUrl.Handle, cfResourceName.Handle, cfResourceType.Handle, String.IsNullOrEmpty (subDirName) ? IntPtr.Zero : cfSubDirName.Handle); return Runtime.GetNSObject<NSUrl> (urlHandle, true); } }
void EventsCallback(IntPtr handle, IntPtr userData, nint numEvents, IntPtr eventPaths, IntPtr eventFlags, IntPtr eventIds) { if (numEvents == 0) { return; } var events = new FSEvent[numEvents]; var pathArray = new CFArray (eventPaths); for (int i = 0; i < events.Length; i++) { events[i].Flags = (FSEventStreamEventFlags)(uint)Marshal.ReadInt32 (eventFlags, i * 4); events[i].Id = (uint)Marshal.ReadInt64 (eventIds, i * 8); using (var cfstr = new CFString (pathArray.GetValue (i))) { events[i].Path = cfstr.ToString (); } } OnEvents (events); }
public NSUrl[] GetResourceUrls(string resourceType, string subDirName) { if (String.IsNullOrEmpty (resourceType)) throw new ArgumentException ("resourceName"); using (CFString cfResourceType = new CFString (resourceType), cfSubDir = new CFString (subDirName ?? string.Empty)) using (var cfArray = new CFArray (CFBundleCopyResourceURLsOfType (handle, cfResourceType.Handle, String.IsNullOrEmpty (subDirName) ? IntPtr.Zero : cfSubDir.Handle), true)) { var result = new NSUrl [cfArray.Count]; for (int index = 0; index < cfArray.Count; index++) { result [index] = Runtime.GetNSObject<NSUrl> (cfArray.GetValue (index), true); } return result; } }