Esempio n. 1
0
 public static void ThrowOnError(this ScreenshotrError value, string message)
 {
     if ((value != ScreenshotrError.Success))
     {
         throw new ScreenshotrException(value, message);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ScreenshotrException"/> class with a specified error code and error message.
 /// <summary>
 /// <param name="error">
 /// The error code of the error that occurred.
 /// </param>
 /// <param name="message">
 /// A message which describes the error.
 /// </param>
 public ScreenshotrException(ScreenshotrError error, string message) :
     base(string.Format("An Screenshotr error occurred. {1}. The error code was {0}", error, message))
 {
     this.errorCode = error;
 }
Esempio n. 3
0
 public static bool IsError(this ScreenshotrError value)
 {
     return(value != ScreenshotrError.Success);
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ReadOnlyCollection <string> udids;
            int count = 0;

            var idevice     = LibiMobileDevice.Instance.iDevice;
            var lockdown    = LibiMobileDevice.Instance.Lockdown;
            var screenshotr = LibiMobileDevice.Instance.Screenshotr;

            var ret = idevice.idevice_get_device_list(out udids, ref count);

            if (ret == iDeviceError.NoDevice)
            {
                // Not actually an error in our case
                Console.WriteLine("No devices found");
                return;
            }

            ret.ThrowOnError();

            // Get the device name
            foreach (var udid in udids)
            {
                iDeviceHandle deviceHandle;
                idevice.idevice_new(out deviceHandle, udid).ThrowOnError();

                LockdownClientHandle lockdownHandle;
                lockdown.lockdownd_client_new_with_handshake(deviceHandle, out lockdownHandle, "Quamotion").ThrowOnError();

                string deviceName;
                lockdown.lockdownd_get_device_name(lockdownHandle, out deviceName).ThrowOnError();


                Console.WriteLine($"{deviceName} ({udid})");

                {
                    LockdownServiceDescriptorHandle scrSvc;
                    LockdownError lde = lockdown.lockdownd_start_service(lockdownHandle, "com.apple.mobile.screenshotr", out scrSvc);
                    if (lde == LockdownError.Success)
                    {
                        ScreenshotrClientHandle client;
                        ScreenshotrError        err = screenshotr.screenshotr_client_new(deviceHandle, scrSvc, out client);
                        IntPtr           imgData    = new IntPtr();
                        ulong            imgSize    = 0;
                        ScreenshotrError result     = screenshotr.screenshotr_take_screenshot(client, ref imgData, ref imgSize);
                        if (result == ScreenshotrError.Success)
                        {
                            Console.WriteLine("截图成功!!!!");
                            String filename = GetScreenPicFileName();
                            Console.WriteLine($"filename:{filename}");

                            System.IO.FileStream file = new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                            int  written;
                            bool writeResult = WriteFile(file.Handle, imgData, (int)imgSize, out written, IntPtr.Zero);
                            file.Close();
                        }
                    }
                    else
                    {
                        Console.WriteLine("截图失败!!!");
                    }
                }

                deviceHandle.Dispose();
                lockdownHandle.Dispose();
            }
        }