Пример #1
0
        public override sealed bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            IntPtr num1 = QuartzDisplayDeviceDriver.HandleTo(device);
            IntPtr num2 = CG.DisplayCurrentMode(num1);

            if (!this.storedModes.ContainsKey(num1))
            {
                this.storedModes.Add(num1, num2);
            }
            CFArray cfArray = new CFArray(CG.DisplayAvailableModes(num1));

            for (int index = 0; index < cfArray.Count; ++index)
            {
                CFDictionary cfDictionary = new CFDictionary(cfArray[index]);
                int          num3         = (int)cfDictionary.GetNumberValue("Width");
                int          num4         = (int)cfDictionary.GetNumberValue("Height");
                int          num5         = (int)cfDictionary.GetNumberValue("BitsPerPixel");
                double       numberValue  = cfDictionary.GetNumberValue("RefreshRate");
                if (num3 == resolution.Width && num4 == resolution.Height && (num5 == resolution.BitsPerPixel && Math.Abs(numberValue - (double)resolution.RefreshRate) < 1E-06))
                {
                    if (!this.displaysCaptured.Contains(num1))
                    {
                        int num6 = (int)CG.DisplayCapture(num1);
                    }
                    CG.DisplaySwitchToMode(num1, cfArray[index]);
                    return(true);
                }
            }
            return(false);
        }
        public float[] this [NSString key] {
            get {
                if (key == null)
                {
                    throw new ArgumentNullException(nameof(key));
                }

                var a = CFDictionary.GetValue(Dictionary.Handle, key.Handle);
                return(NSArray.ArrayFromHandle <float> (a, input => {
                    return new NSNumber(input).FloatValue;
                }));
            }
            set {
                if (key == null)
                {
                    throw new ArgumentNullException(nameof(key));
                }

                if (value == null)
                {
                    RemoveValue(key);
                }
                else
                {
                    Dictionary [key] = NSArray.From(value);
                }
            }
        }
Пример #3
0
        public IDictionary <IOHIDElement, IOHIDValue> GetValues(IOHIDElement[] elements)
        {
            ThrowIfDisposed();
            if (elements == null)
            {
                throw new ArgumentNullException("elements");
            }
            var elementArray = CFArray.FromNativeObjects(elements);

            IOHIDElement[] keys        = new IOHIDElement[elements.Length];
            IOHIDValue[]   values      = new IOHIDValue[elements.Length];
            CFDictionary   multiple    = CFDictionary.FromObjectsAndKeys(values, keys);
            var            multipleRef = multiple.Handle;
            var            result      = IOHIDDeviceCopyValueMultiple(Handle, elementArray.Handle, ref multipleRef);

            IOObject.ThrowIfError(result);
            var dict = new Dictionary <IOHIDElement, IOHIDValue> (multiple.Count);

            IntPtr[] keyRefs, valueRefs;
            multiple.GetKeysAndValues(out keyRefs, out valueRefs);
            for (int i = 0; i < multiple.Count; i++)
            {
                dict.Add(new IOHIDElement(keyRefs [i], true), new IOHIDValue(valueRefs [i], true));
            }
            CFType.Release(multiple.Handle);
            return(dict);
        }
Пример #4
0
        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();
                }
            }
        }
Пример #5
0
        static INativeObject [] QueryAsReference(CFDictionary query, out SecStatusCode result)
        {
            if (query == null)
            {
                result = SecStatusCode.Param;
                return(null);
            }

            IntPtr ptr;

            result = SecItem.SecItemCopyMatching(query.Handle, out ptr);
            if (result == SecStatusCode.Success && ptr != IntPtr.Zero)
            {
                var array = CFArray.ArrayFromHandle <INativeObject> (ptr, p => {
                    IntPtr cfType = CFType.GetTypeID(p);
                    if (cfType == SecCertificate.GetTypeID())
                    {
                        return(new SecCertificate(p, true));
                    }
                    if (cfType == SecKey.GetTypeID())
                    {
                        return(new SecKey(p, true));
                    }
                    if (cfType == SecIdentity.GetTypeID())
                    {
                        return(new SecIdentity(p, true));
                    }
                    throw new Exception(String.Format("Unexpected type: 0x{0:x}", cfType));
                });
                return(array);
            }
            return(null);
        }
Пример #6
0
        private IntPtr[] GrabTheData(string Response)
        {
            IntPtr[] ret = new IntPtr[5];
            string   temp;

            temp = Response.Remove(0, Response.IndexOf("<plist version") - 1);
            temp = temp.Remove((temp.IndexOf(@"</Protocol>")), temp.Length - ((temp.IndexOf(@"</Protocol>"))));
            string headers = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">";

            temp = headers + "\r\n" + temp;
            if (File.Exists(Environment.CurrentDirectory + @"\wildcard.ticket") == true)
            {
                File.Delete(Environment.CurrentDirectory + @"\wildcard.ticket");
            }
            System.IO.File.AppendAllText(Environment.CurrentDirectory + @"\wildcard.ticket", temp);
            CFPropertyList plist             = new CFPropertyList(Environment.CurrentDirectory + @"\wildcard.ticket");
            CFDictionary   plist_to_dict     = (IntPtr)plist;
            CFDictionary   iphone_activation = (IntPtr)plist_to_dict.GetValue("iphone-activation");
            CFDictionary   dict = (IntPtr)iphone_activation.GetValue("activation-record");

            ret[0] = dict.GetValue("AccountTokenCertificate");
            ret[1] = dict.GetValue("AccountToken");
            ret[2] = dict.GetValue("FairPlayKeyData");
            ret[3] = dict.GetValue("DeviceCertificate");
            ret[4] = dict.GetValue("AccountTokenSignature");
            if (File.Exists(Environment.CurrentDirectory + @"\wildcard.ticket") == true)
            {
                File.Delete(Environment.CurrentDirectory + @"\wildcard.ticket");
            }
            return(ret);
        }
        public static T[] GetNativeArray <T> (NSDictionary dictionary, NSObject key, Converter <IntPtr, T> converter)
        {
            var cfArrayRef = CFDictionary.GetValue(dictionary.Handle, key.Handle);

            if (cfArrayRef == IntPtr.Zero || CFArray.GetCount(cfArrayRef) == 0)
            {
                return(new T [0]);
            }
            return(NSArray.ArrayFromHandle(cfArrayRef, converter));
        }
Пример #8
0
 protected virtual void Dispose(bool disposing)
 {
     if (queryDict != null)
     {
         if (disposing)
         {
             queryDict.Dispose();
             queryDict = null;
         }
     }
 }
        protected T[]? GetArray <T> (NSString key) where T : NSObject
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            var value = CFDictionary.GetValue(Dictionary.Handle, key.Handle);

            return(NSArray.ArrayFromHandle <T> (value));
        }
Пример #10
0
        protected T[]? GetArray <T> (NSString key, Func <NativeHandle, T> creator)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            var value = CFDictionary.GetValue(Dictionary.Handle, key.Handle);

            return(NSArray.ArrayFromHandleFunc <T> (value, creator));
        }
Пример #11
0
        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)));
            }
        }
Пример #12
0
        public void SetValueMultiple(IDictionary <IOHIDElement, IOHIDValue> dictonary)
        {
            ThrowIfDisposed();
            if (dictonary == null)
            {
                throw new ArgumentNullException("multiple");
            }
            var multiple = CFDictionary.FromObjectsAndKeys(dictonary.Values.ToArray(), dictonary.Keys.ToArray());
            var result   = IOHIDDeviceSetValueMultiple(Handle, multiple.Handle);

            CFType.Release(multiple.Handle);
            IOObject.ThrowIfError(result);
        }
        void SetBaseline(CTBaselineClass baselineClass, double offset, NSString infoKey)
        {
            var ptr  = CFDictionary.GetValue(Dictionary.Handle, infoKey.Handle);
            var dict = ptr == IntPtr.Zero ? new NSMutableDictionary() : new NSMutableDictionary(ptr);

            var key = CTBaselineClassID.ToNSString(baselineClass);

            Adapter.SetValue(dict, key, new NSNumber(offset));

            if (ptr == IntPtr.Zero)
            {
                Adapter.SetNativeValue(Dictionary, infoKey, (INativeObject)dict);
            }
        }
Пример #14
0
        static public SecStatusCode ImportPkcs12(CFData data, CFDictionary options, out CFDictionary [] array)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            IntPtr        handle;
            SecStatusCode code = SecPKCS12Import(data.Handle, options.Handle, out handle);

            array = CFArray.ArrayFromHandle <CFDictionary> (handle, h => new CFDictionary(h, false));
            CFObject.CFRelease(handle);
            return(code);
        }
Пример #15
0
        public string[] this [NSString key] {
            get {
                if (key == null)
                {
                    throw new ArgumentNullException(nameof(key));
                }

                var value = CFDictionary.GetValue(Dictionary.Handle, key.Handle);
                return(NSArray.StringArrayFromHandle(value));
            }
            set {
                SetArrayValue(key, value);
            }
        }
Пример #16
0
		static AccessoryInfo[] ExtractAccessoryInfo (IntPtr ptr, NSString id, NSString description)
		{
			using (var array = new CFArray (ptr)) {
				var res = new AccessoryInfo [array.Count];
				for (int i = 0; i < res.Length; ++i) {
					var dict = array.GetValue (i);
					var n = new NSNumber (CFDictionary.GetValue (dict, id.Handle));
					var desc = CFString.FetchString (CFDictionary.GetValue (dict, description.Handle));

					res [i] = new AccessoryInfo ((int) n, desc);
					id.Dispose ();
				}
				return res;
			}
		}
Пример #17
0
        protected string?GetStringValue(string key)
        {
            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            var keyHandle = CFString.CreateNative(key);

            try {
                return(CFString.FromHandle(CFDictionary.GetValue(Dictionary.Handle, keyHandle)));
            } finally {
                CFString.ReleaseNative(keyHandle);
            }
        }
        static SecStatusCode ImportPkcs12(CFData data, CFDictionary options, out CFDictionary[] array)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var code = SecPKCS12Import(data.Handle, options.Handle, out var handle);

            array = CFArray.ArrayFromHandle <CFDictionary> (handle, h => new CFDictionary(h, false));
            if (handle != IntPtr.Zero)
            {
                CFObject.CFRelease(handle);
            }
            return(code);
        }
Пример #19
0
        public static bool IsScreenLocked()
        {
            var h = CGSessionCopyCurrentDictionary();

            if (h == IntPtr.Zero)
            {
                throw new ApplicationException("Not running within Quartz GUI session");
            }

            using (var d = new CFDictionary(h, true))
            {
                var kCGSSessionScreenIsLocked = new CFString("CGSSessionScreenIsLocked");
                var locked = CFDictionary.GetBooleanValue(d.Handle, kCGSSessionScreenIsLocked.Handle);
                return(locked);
            }
        }
Пример #20
0
        protected bool?GetBoolValue(NSString key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var value = CFDictionary.GetValue(Dictionary.Handle, key.Handle);

            if (value == IntPtr.Zero)
            {
                return(null);
            }

            return(CFBoolean.GetValue(value));
        }
Пример #21
0
        static void Callback(IntPtr ptr)
        {
            CFDictionary dic = new CFDictionary(ptr);

            Console.WriteLine(dic.ToString());


            //CFType v1 = dic.GetValue("Status");
            //CFType v2 = dic.GetValue("PercentComplete");
            //CFType v3 = dic.GetValue("Error");

            //var status = v1.ToString();
            //var percent = v2.ToString();

            //var error = v3.ToString();
        }
Пример #22
0
        protected T[] GetArray <T> (NSString key) where T : NSObject
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var value = CFDictionary.GetValue(Dictionary.Handle, key.Handle);

            if (value == IntPtr.Zero)
            {
                return(null);
            }

            return(NSArray.ArrayFromHandle <T> (value));
        }
Пример #23
0
        protected T[] GetArray <T> (NSString key, Func <IntPtr, T> creator)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            var value = CFDictionary.GetValue(Dictionary.Handle, key.Handle);

            if (value == IntPtr.Zero)
            {
                return(null);
            }

            return(NSArray.ArrayFromHandleFunc <T> (value, creator));
        }
Пример #24
0
        public unsafe QuartzDisplayDeviceDriver()
        {
            lock (QuartzDisplayDeviceDriver.display_lock)
            {
                IntPtr[] local_0 = new IntPtr[20];
                int      local_1;
                fixed(IntPtr *fixed_0 = local_0)
                {
                    int temp_15 = (int)CG.GetActiveDisplayList(20, fixed_0, out local_1);
                }

                for (int local_3 = 0; local_3 < local_1; ++local_3)
                {
                    IntPtr local_4 = local_0[local_3];
                    bool   local_5 = local_3 == 0;
                    CG.DisplayPixelsWide(local_4);
                    CG.DisplayPixelsHigh(local_4);
                    CFArray                  local_7  = new CFArray(CG.DisplayAvailableModes(local_4));
                    DisplayResolution        local_8  = (DisplayResolution)null;
                    List <DisplayResolution> local_9  = new List <DisplayResolution>();
                    CFDictionary             local_11 = new CFDictionary(CG.DisplayCurrentMode(local_4));
                    for (int local_12 = 0; local_12 < local_7.Count; ++local_12)
                    {
                        CFDictionary      local_13 = new CFDictionary(local_7[local_12]);
                        int               local_14 = (int)local_13.GetNumberValue("Width");
                        int               local_15 = (int)local_13.GetNumberValue("Height");
                        int               local_16 = (int)local_13.GetNumberValue("BitsPerPixel");
                        double            local_17 = local_13.GetNumberValue("RefreshRate");
                        bool              local_18 = local_11.Ref == local_13.Ref;
                        DisplayResolution local_19 = new DisplayResolution(0, 0, local_14, local_15, local_16, (float)local_17);
                        local_9.Add(local_19);
                        if (local_18)
                        {
                            local_8 = local_19;
                        }
                    }
                    HIRect        local_20 = CG.DisplayBounds(local_4);
                    Rectangle     local_21 = new Rectangle((int)local_20.Origin.X, (int)local_20.Origin.Y, (int)local_20.Size.Width, (int)local_20.Size.Height);
                    DisplayDevice local_22 = new DisplayDevice(local_8, local_5, (IEnumerable <DisplayResolution>)local_9, local_21, (object)local_4);
                    this.AvailableDevices.Add(local_22);
                    if (local_5)
                    {
                        this.Primary = local_22;
                    }
                }
            }
        }
Пример #25
0
        public void ApplyCredentialDictionary(CFHTTPAuthentication auth, NetworkCredential credential)
        {
            if (auth is null)
            {
                throw new ArgumentNullException(nameof(auth));
            }
            if (credential is null)
            {
                throw new ArgumentNullException(nameof(credential));
            }

            var length = credential.Domain is null ? 2 : 3;

            var keys   = new NSString [length];
            var values = new CFString [length];

            keys [0]   = _AuthenticationUsername;
            keys [1]   = _AuthenticationPassword;
            values [0] = credential.UserName !;
            values [1] = credential.Password !;
            if (credential.Domain is not null)
            {
                keys [2]   = _AuthenticationAccountDomain;
                values [2] = credential.Domain;
            }

            var dict = CFDictionary.FromObjectsAndKeys(values, keys);

            try {
                CFStreamError error;
                var           ok = CFHTTPMessageApplyCredentialDictionary(
                    Handle, auth.Handle, dict.Handle, out error);
                if (ok)
                {
                    return;
                }
                throw GetException((CFStreamErrorHTTPAuthentication)error.code);
            } finally {
                dict.Dispose();
                values [0]?.Dispose();
                values [1]?.Dispose();
                values [2]?.Dispose();
            }
        }
Пример #26
0
        public static bool InstallApp(IntPtr device, string appPath)
        {
            CFString path   = new CFString(appPath);
            IntPtr   appUrl = CFLibrary.CFURLCreateWithFileSystemPath(IntPtr.Zero, path.typeRef, 2, false);

            string[] k = new string[1];
            k[0] = "PackageType";
            IntPtr[] v = new IntPtr[1];
            v[0] = new CFString("Developer");
            CFDictionary opts = new CFDictionary(k, v);

            int err = AMDeviceSecureTransferPath(0, device, appUrl, opts, IntPtr.Zero, 0);

            if (err == NO_ERR)
            {
                return(AMDeviceSecureInstallApplication(0, device, appUrl, opts, IntPtr.Zero, 0) == NO_ERR);
            }
            return(err == NO_ERR);
        }
Пример #27
0
        public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            IntPtr display = displayMap[device];
            IntPtr currentModePtr = CG.DisplayCurrentMode(display);

            if (storedModes.ContainsKey(display) == false)
            {
                storedModes.Add(display, currentModePtr);        
            }

            IntPtr displayModesPtr = CG.DisplayAvailableModes(display);
            CFArray displayModes = new CFArray(displayModesPtr);

            for (int j = 0; j < displayModes.Count; j++)
            {
                CFDictionary dict = new CFDictionary(displayModes[j]);

                int width = (int)dict.GetNumberValue("Width");
                int height = (int)dict.GetNumberValue("Height");
                int bpp = (int)dict.GetNumberValue("BitsPerPixel");
                double freq = dict.GetNumberValue("RefreshRate");

                if (width == resolution.Width &&
                    height == resolution.Height &&
                    bpp == resolution.BitsPerPixel &&
                    System.Math.Abs(freq - resolution.RefreshRate) < 1e-6)
                {
                    if (displaysCaptured.Contains(display) == false)
                    {
                        CG.DisplayCapture(display);
                    }

                    Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq);

                    CG.DisplaySwitchToMode(display, displayModes[j]);

                    return true;
                }

            }
            return false;
        }
Пример #28
0
        public override bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            var display        = HandleTo(device);
            var currentModePtr = CG.DisplayCurrentMode(display);

            if (storedModes.ContainsKey(display) == false)
            {
                storedModes.Add(display, currentModePtr);
            }

            var displayModesPtr = CG.DisplayAvailableModes(display);
            var displayModes    = new CFArray(displayModesPtr);

            for (var j = 0; j < displayModes.Count; j++)
            {
                var dict = new CFDictionary(displayModes[j]);

                var width  = (int)dict.GetNumberValue("Width");
                var height = (int)dict.GetNumberValue("Height");
                var bpp    = (int)dict.GetNumberValue("BitsPerPixel");
                var freq   = dict.GetNumberValue("RefreshRate");

                if (width == resolution.Width && height == resolution.Height && bpp == resolution.BitsPerPixel &&
                    Math.Abs(freq - resolution.RefreshRate) < 1e-6)
                {
//                    if (displaysCaptured.Contains(display) == false)
//                    {
//                        CG.DisplayCapture(display);
//                    }

                    Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq);

                    CG.DisplaySwitchToMode(display, displayModes[j]);

                    return(true);
                }
            }

            return(false);
        }
        static SafeSecIdentityHandle ImportIdentity(byte[] data, string password)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (string.IsNullOrEmpty(password))              // SecPKCS12Import() doesn't allow empty passwords.
            {
                throw new ArgumentException(nameof(password));
            }
            Initialize();
            using (var pwstring = CFString.Create(password))
                using (var optionDict = CFDictionary.FromObjectAndKey(pwstring.Handle, ImportExportPassphase.Handle)) {
                    var result = ImportPkcs12(data, optionDict, out var array);
                    if (result != SecStatusCode.Success)
                    {
                        throw new InvalidOperationException(result.ToString());
                    }

                    return(new SafeSecIdentityHandle(array [0].GetValue(ImportItemIdentity.Handle)));
                }
        }
Пример #30
0
        public static SecIdentity Import(byte[] data, string password)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (string.IsNullOrEmpty(password))              // SecPKCS12Import() doesn't allow empty passwords.
            {
                throw new ArgumentException("password");
            }
            using (var pwstring = CFString.Create(password))
                using (var options = CFDictionary.FromObjectAndKey(pwstring.Handle, ImportExportPassphase.Handle)) {
                    CFDictionary [] array;
                    SecStatusCode   result = SecImportExport.ImportPkcs12(data, options, out array);
                    if (result != SecStatusCode.Success)
                    {
                        throw new InvalidOperationException(result.ToString());
                    }

                    return(new SecIdentity(array [0].GetValue(ImportItemIdentity.Handle)));
                }
        }
Пример #31
0
		internal static extern CFDictionaryRef CFDictionaryCreate (
			CFAllocatorRef allocator,
			CFStringRef[] keys,
			CFNumberRef[] values,
			CFIndex numValues,
			ref CFDictionary.CFDictionaryKeyCallBacks keyCallBacks,
			ref CFDictionary.CFDictionaryValueCallBacks valueCallBacks
			);
Пример #32
0
		public static CFProxy[] GetProxiesForAutoConfigurationScript (IntPtr proxyAutoConfigurationScript, CFUrl targetURL)
		{
			if (proxyAutoConfigurationScript == IntPtr.Zero)
				throw new ArgumentNullException ("proxyAutoConfigurationScript");
			
			if (targetURL == null)
				throw new ArgumentNullException ("targetURL");
			
			CFArray array = CopyProxiesForAutoConfigurationScript (proxyAutoConfigurationScript, targetURL);
			
			if (array == null)
				return null;
			
			CFProxy[] proxies = new CFProxy [array.Count];
			for (int i = 0; i < proxies.Length; i++) {
				CFDictionary dict = new CFDictionary (array[i], false);
				proxies[i] = new CFProxy (dict);
			}

			array.Dispose ();
			
			return proxies;
		}
Пример #33
0
		public CFProxySettings (CFDictionary settings)
		{
			this.settings = settings;
		}
Пример #34
0
		internal CFProxy (CFDictionary settings)
		{
			this.settings = settings;
		}
Пример #35
0
		static CFArray CopyProxiesForURL (CFUrl url, CFDictionary proxySettings)
		{
			IntPtr native = CFNetworkCopyProxiesForURL (url.Handle, proxySettings != null ? proxySettings.Handle : IntPtr.Zero);
			
			if (native == IntPtr.Zero)
				return null;
			
			return new CFArray (native, true);
		}
Пример #36
0
        static QuartzDisplayDeviceDriver()
        {
            lock (display_lock)
            {
                // To minimize the need to add static methods to OpenTK.Graphics.DisplayDevice
                // we only allow settings to be set through its constructor.
                // Thus, we save all necessary parameters in temporary variables
                // and construct the device when every needed detail is available.
                // The main DisplayDevice constructor adds the newly constructed device
                // to the list of available devices.
                const int maxDisplayCount = 20;
                IntPtr[] displays = new IntPtr[maxDisplayCount];
                int displayCount;

                unsafe
                {
                    fixed(IntPtr* displayPtr = displays)
                    {
                        CG.GetActiveDisplayList(maxDisplayCount, displayPtr, out displayCount);
                    }
                }

                Debug.Print("CoreGraphics reported {0} displays.", displayCount);
                Debug.Indent();

                for (int i = 0; i < displayCount; i++)
                {
                    IntPtr currentDisplay = displays[i];

                    // according to docs, first element in the array is always the
                    // main display.
                    bool primary = (i == 0);

                    if (primary)
                        mainDisplay = currentDisplay;

                    // gets current settings
                    int currentWidth = CG.DisplayPixelsWide(currentDisplay);
                    int currentHeight = CG.DisplayPixelsHigh(currentDisplay);
                    Debug.Print("Display {0} is at  {1}x{2}", i, currentWidth, currentHeight);

                    IntPtr displayModesPtr = CG.DisplayAvailableModes(currentDisplay);
                    CFArray displayModes = new CFArray(displayModesPtr);
                    Debug.Print("Supports {0} display modes.", displayModes.Count);

                    DisplayResolution opentk_dev_current_res = null;
                    List<DisplayResolution> opentk_dev_available_res = new List<DisplayResolution>();
                    IntPtr currentModePtr = CG.DisplayCurrentMode(currentDisplay);
                    CFDictionary currentMode = new CFDictionary(currentModePtr);

                    for (int j = 0; j < displayModes.Count; j++)
                    {
                        CFDictionary dict = new CFDictionary(displayModes[j]);

                        int width = (int) dict.GetNumberValue("Width");
                        int height = (int) dict.GetNumberValue("Height");
                        int bpp = (int) dict.GetNumberValue("BitsPerPixel");
                        double freq = dict.GetNumberValue("RefreshRate");
                        bool current = currentMode.Ref == dict.Ref;

                        //if (current) Debug.Write("  * ");
                        //else Debug.Write("    ");

                        //Debug.Print("Mode {0} is {1}x{2}x{3} @ {4}.", j, width, height, bpp, freq);

                        DisplayResolution thisRes = new DisplayResolution(0, 0, width, height, bpp, (float)freq);
                        opentk_dev_available_res.Add(thisRes);

                        if (current)
                            opentk_dev_current_res = thisRes;

                    }

                    DisplayDevice opentk_dev =
                        new DisplayDevice(opentk_dev_current_res, primary, opentk_dev_available_res);

                    displayMap.Add(opentk_dev, currentDisplay);
                }

                Debug.Unindent();
            }
        }
Пример #37
0
        public bool TryChangeResolution(DisplayDevice device, DisplayResolution resolution)
        {
            IntPtr display = displayMap[device];
            IntPtr currentModePtr = CG.DisplayCurrentMode(display);

            if (storedModes.ContainsKey(display) == false)
            {
                storedModes.Add(display, currentModePtr);
            }

            IntPtr displayModesPtr = CG.DisplayAvailableModes(display);
            CFArray displayModes = new CFArray(displayModesPtr);

            for (int j = 0; j < displayModes.Count; j++)
            {
                CFDictionary dict = new CFDictionary(displayModes[j]);

                int width = (int)dict.GetNumberValue("Width");
                int height = (int)dict.GetNumberValue("Height");
                int bpp = (int)dict.GetNumberValue("BitsPerPixel");
                double freq = dict.GetNumberValue("RefreshRate");

                if (width == resolution.Width &&
                    height == resolution.Height &&
                    bpp == resolution.BitsPerPixel &&
                    System.Math.Abs(freq - resolution.RefreshRate) < 1e-6)
                {
                    if (displaysCaptured.Contains(display) == false)
                    {
                        CG.DisplayCapture(display);
                    }

                    Debug.Print("Changing resolution to {0}x{1}x{2}@{3}.", width, height, bpp, freq);

                    CG.DisplaySwitchToMode(display, displayModes[j]);

                    return true;
                }

            }
            return false;
        }
Пример #38
0
		public static CFProxy[] GetProxiesForURL (CFUrl url, CFProxySettings proxySettings)
		{
			if (url == null || url.Handle == IntPtr.Zero)
				throw new ArgumentNullException ("url");
			
			if (proxySettings == null)
				proxySettings = GetSystemProxySettings ();
			
			CFArray array = CopyProxiesForURL (url, proxySettings.Dictionary);
			
			if (array == null)
				return null;

			CFProxy[] proxies = new CFProxy [array.Count];
			for (int i = 0; i < proxies.Length; i++) {
				CFDictionary dict = new CFDictionary (array[i], false);
				proxies[i] = new CFProxy (dict);
			}

			array.Dispose ();
			
			return proxies;
		}
Пример #39
0
		public static CFProxySettings GetSystemProxySettings ()
		{
			IntPtr native = CFNetworkCopySystemProxySettings ();
			
			if (native == IntPtr.Zero)
				return null;
			
			var dict = new CFDictionary (native, true);

			return new CFProxySettings (dict);
		}
Пример #40
0
		public static CFProxy[] ExecuteProxyAutoConfigurationURL (IntPtr proxyAutoConfigURL, Uri targetURL)
		{
			CFUrl url = CFUrl.Create (targetURL.AbsoluteUri);
			if (url == null)
				return null;

			CFProxy[] proxies = null;

			var runLoop = CFRunLoop.CurrentRunLoop;

			// Callback that will be called after executing the configuration script
			CFProxyAutoConfigurationResultCallback cb = delegate (IntPtr client, IntPtr proxyList, IntPtr error) {
				if (proxyList != IntPtr.Zero) {
					var array = new CFArray (proxyList, false);
					proxies = new CFProxy [array.Count];
					for (int i = 0; i < proxies.Length; i++) {
						CFDictionary dict = new CFDictionary (array[i], false);
						proxies[i] = new CFProxy (dict);
					}
					array.Dispose ();
				}
				runLoop.Stop ();
			};

			var clientContext = new CFStreamClientContext ();
			var loopSource = CFNetworkExecuteProxyAutoConfigurationURL (proxyAutoConfigURL, url.Handle, cb, ref clientContext);

			// Create a private mode
			var mode = CFString.Create ("Mono.MacProxy");

			runLoop.AddSource (loopSource, mode);
			runLoop.RunInMode (mode, double.MaxValue, false);
			runLoop.RemoveSource (loopSource, mode);

			return proxies;
		}