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)); } }
public long GetInt64Value(string key) { long value = 0; using (var str = new CFString(key)) { if (!CFNumberGetValue(CFDictionaryGetValue(Handle, str.Handle), /* kCFNumberSInt64Type */ 4, out value)) { throw new System.Collections.Generic.KeyNotFoundException(string.Format("Key {0} not found", key)); } return(value); } }
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); // API not annotated (yet?) but it's safe to bet it match CFStreamCreatePairWithSocketToCFHost readStream = read == IntPtr.Zero ? null : new CFReadStream(read); writeStream = write == IntPtr.Zero ? null : new CFWriteStream(write); } }
public override string ToString() { if (copyDescription != IntPtr.Zero) { var ptr = CFReadStreamRef_InvokeCopyDescription(copyDescription, Info); if (ptr != IntPtr.Zero) { // Copy* -> so we must not retain again using (var s = new CFString(ptr, true)) return(s.ToString()); } } return(base.ToString()); }
public static string[] GetLocalizations(NSUrl bundle) { if (bundle == null) { throw new ArgumentNullException("bundle"); } using (var cfArray = new CFArray(CFBundleCopyLocalizationsForURL(bundle.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 nint GetAppIntegerValue(string key, NSString applicationId) { if (key == null) { throw new ArgumentNullException("key"); } else if (applicationId == null) { throw new ArgumentNullException("applicationId"); } using (var cfKey = new CFString(key)) { return(CFPreferencesGetAppIntegerValue(cfKey.Handle, applicationId.Handle, IntPtr.Zero)); } }
public static void RemoveSuitePreferencesFromApp(NSString applicationId, string suiteId) { if (applicationId == null) { throw new ArgumentNullException("applicationId"); } else if (suiteId == null) { throw new ArgumentNullException("suiteId"); } using (var cfSuiteId = new CFString(suiteId)) { CFPreferencesRemoveSuitePreferencesFromApp(applicationId.Handle, cfSuiteId.Handle); } }
public static bool AppValueIsForced(string key, NSString applicationId) { if (key == null) { throw new ArgumentNullException("key"); } else if (applicationId == null) { throw new ArgumentNullException("applicationId"); } using (var cfKey = new CFString(key)) { return(CFPreferencesAppValueIsForced(cfKey.Handle, applicationId.Handle)); } }
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 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 static void SetAppValue(string key, object value, NSString applicationId) { if (key == null) { throw new ArgumentNullException("key"); } else if (applicationId == null) { throw new ArgumentNullException("applicationId"); } using (var cfKey = new CFString(key)) { if (value == null) { CFPreferencesSetAppValue(cfKey.Handle, IntPtr.Zero, applicationId.Handle); } else if (value is string) { using (var valueStr = new CFString((string)value)) { CFPreferencesSetAppValue(cfKey.Handle, valueStr.Handle, applicationId.Handle); } return; } else if (value is NSString || value is CFString || value is NSData || value is CFData || value is NSArray || value is CFArray || value is NSDictionary || value is CFDictionary || value is NSNumber || value is CFBoolean) { CFPreferencesSetAppValue(cfKey.Handle, ((INativeObject)value).Handle, applicationId.Handle); return; } var nsnumber = NSNumber.FromObject(value); if (nsnumber != null) { using (nsnumber) { CFPreferencesSetAppValue(cfKey.Handle, nsnumber.Handle, applicationId.Handle); } return; } throw new ArgumentException("unsupported type: " + value.GetType(), "value"); } }
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); } }
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) { 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 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 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 string GetStringValue(string key) { using (var str = new CFString(key)) { return(CFString.FetchString(CFDictionaryGetValue(Handle, str.handle))); } }
public IntPtr GetIntPtrValue(string key) { using (var str = new CFString(key)) { return(CFDictionaryGetValue(Handle, str.handle)); } }
public bool ContainsKey(string key) { using (var str = new CFString(key)) { return(CFDictionaryContainsKey(Handle, str.handle)); } }
public override string ToString() { using (var str = new CFString(CFURLGetString(handle))) { return(str.ToString()); } }
static internal string GetFileSystemPath(IntPtr hcfurl) { using (var str = new CFString(CFURLCopyFileSystemPath(hcfurl, 0), true)) return(str.ToString()); }