Example #1
0
        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);
                }
        }
Example #2
0
        /// <summary>
        /// 获取已经安装的IPA程序Plist
        /// </summary>
        /// <returns></returns>
        public unsafe string GetInstalledList()
        {
            IntPtr result = new IntPtr();
            int    i      = MobileDevice.AMDeviceLookupApplications(this.iPhoneHandle, IntPtr.Zero, ref result);

            CoreFoundation.CFPropertyList cfPlist = new CoreFoundation.CFPropertyList(result);
            CoreFoundation.CFArray        xx      = new CoreFoundation.CFArray();
            return(cfPlist.ToString());
        }
Example #3
0
        public static string?[]? GetLocalizations(NSUrl bundle)
        {
            if (bundle is null)
            {
                throw new ArgumentNullException(nameof(bundle));
            }
            var rv = CFBundleCopyLocalizationsForURL(bundle.Handle);

            return(CFArray.StringArrayFromHandle(rv, true));
        }
Example #4
0
 public static CFBundle[] GetAll()
 {
     using (var cfBundles = new CFArray(CFBundleGetAllBundles())) {
         var managedBundles = new CFBundle [cfBundles.Count];
         for (int index = 0; index < cfBundles.Count; index++)
         {
             // follow the get rule, we do not own the object
             managedBundles [index] = new CFBundle(cfBundles.GetValue(index), false);
         }
         return(managedBundles);
     }
 }
Example #5
0
 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);
     }
 }
Example #6
0
 public static CFBundle[]? GetAll()
 {
     // as per apple documentation:
     // CFBundleGetAllBundles
     //
     //  'This function is potentially expensive and not thread-safe'
     //
     // This means, that we should not trust the size of the array, since is a get and
     // might be modified by a diff thread. We are going to clone the array and make sure
     // that Apple does not modify the array while we work with it. That avoids changes
     // in the index or in the bundles returned.
     using (var cfBundles = new CFArray(CFBundleGetAllBundles(), false))
         using (var cfBundlesCopy = cfBundles.Clone()) {
             return(CFArray.ArrayFromHandleFunc <CFBundle> (cfBundlesCopy.Handle, (handle) => new CFBundle(handle, false), false));
         }
 }
Example #7
0
 static CFProxy[] ParseProxies(IntPtr proxyList)
 {
     CFProxy[] proxies = null;
     if (proxyList != IntPtr.Zero)
     {
         // it was retained in the cbs.
         using (var array = new CFArray(proxyList, false)) {
             proxies = new CFProxy [array.Count];
             for (int i = 0; i < proxies.Length; i++)
             {
                 var dict = Runtime.GetNSObject <NSDictionary> (array.GetValue(i));
                 proxies[i] = new CFProxy(dict);
             }
         }
     }
     return(proxies);
 }
Example #8
0
        public static string?[]? GetPreferredLocalizations(string[] locArray)
        {
            if (locArray is null)
            {
                throw new ArgumentNullException(nameof(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)) {
                var rv = CFBundleCopyPreferredLocalizationsFromArray(cfLocArray.Handle);
                return(CFArray.StringArrayFromHandle(rv, true));
            }
        }
Example #9
0
        public NSUrl?[]? GetResourceUrls(string resourceType, string subDirName)
        {
            if (String.IsNullOrEmpty(resourceType))
            {
                throw new ArgumentException(nameof(resourceType));
            }

            var resourceTypeHandle = CFString.CreateNative(resourceType);
            var dirNameHandle      = CFString.CreateNative(string.IsNullOrEmpty(subDirName) ? null : subDirName);

            try {
                var rv = CFBundleCopyResourceURLsOfType(Handle, resourceTypeHandle, dirNameHandle);
                return(CFArray.ArrayFromHandleFunc(rv, (handle) => Runtime.GetNSObject <NSUrl> (handle, true), true));
            } finally {
                CFString.ReleaseNative(resourceTypeHandle);
                CFString.ReleaseNative(dirNameHandle);
            }
        }
Example #10
0
        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);
                }
        }
Example #11
0
        public static CFBundle[]? GetBundlesFromDirectory(NSUrl directoryUrl, string bundleType)
        {
            if (directoryUrl is null)             // NSUrl cannot be "" by definition
            {
                throw new ArgumentNullException(nameof(directoryUrl));
            }
            if (String.IsNullOrEmpty(bundleType))
            {
                throw new ArgumentException(nameof(bundleType));
            }
            var bundleTypeHandle = CFString.CreateNative(bundleType);

            try {
                var rv = CFBundleCreateBundlesFromDirectory(IntPtr.Zero, directoryUrl.Handle, bundleTypeHandle);
                return(CFArray.ArrayFromHandleFunc(rv, (handle) => new CFBundle(handle, true), true));
            } finally {
                CFString.ReleaseNative(bundleTypeHandle);
            }
        }
Example #12
0
 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);
         }
 }
Example #13
0
        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);
                }
        }
Example #14
0
 public static CFBundle[] GetAll()
 {
     // as per apple documentation:
     // CFBundleGetAllBundles
     //
     //  'This function is potentially expensive and not thread-safe'
     //
     // This means, that we should not trust the size of the array, since is a get and
     // might be modified by a diff thread. We are going to clone the array and make sure
     // that Apple does not modify the array while we work with it. That avoids changes
     // in the index or in the bundles returned.
     using (var cfBundles = new CFArray(CFBundleGetAllBundles()))
         using (var cfBundlesCopy = cfBundles.Clone()) {
             var bundleCount    = cfBundlesCopy.Count;          // the property is a C call, calling everytime we loop is not needed
             var managedBundles = new CFBundle [bundleCount];
             for (int index = 0; index < bundleCount; index++)
             {
                 // follow the get rule, we do not own the object
                 managedBundles [index] = new CFBundle(cfBundlesCopy.GetValue(index), false);
             }
             return(managedBundles);
         }
 }
Example #15
0
        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);
                }
        }
Example #16
0
 /// <summary>
 /// 获取已经安装的IPA程序Plist
 /// </summary>
 /// <returns></returns>
 public unsafe string GetInstalledList()
 {
     IntPtr result = new IntPtr();
     int i = MobileDevice.AMDeviceLookupApplications(this.iPhoneHandle,IntPtr.Zero,ref result);
     CoreFoundation.CFPropertyList cfPlist = new CoreFoundation.CFPropertyList(result);
     CoreFoundation.CFArray xx = new CoreFoundation.CFArray();
     return cfPlist.ToString();
 }