Пример #1
0
        void workerDeploy_DoWork(object sender, DoWorkEventArgs e)
        {
            if (File.Exists("./adb/adb.exe"))
            {
            }
            else
            {
                _count++;
            }
            if (File.Exists("./adb/fastboot.exe"))
            {
            }
            else
            {
                _count++;
            }
            if (File.Exists("./adb/aapt.exe"))
            {
            }
            else
            {
                _count++;
            }
            if (File.Exists("./adb/AdbWinApi.dll"))
            {
            }
            else
            {
                _count++;
            }
            if (File.Exists("./adb/AdbWinUsbApi.dll"))
            {
            }
            else
            {
                _count++;
            }

            if (_count > 0)
            {
                MessageBoxResult result = MessageBox.Show("The ADB and Fastboot files have not been deployed correctly. \nWould you like to deploy now? \nNot deploying will make this kit useless.", "Deployment Issue", MessageBoxButton.YesNo, MessageBoxImage.Error);
                if (result == MessageBoxResult.Yes)
                {
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        Start start = new Start();
                        start.ShowDialog();
                    }));
                }
                else
                {
                    // Cancel code here
                    MessageBox.Show("You must deploy the ADB and Fastboot utilities, otherwise the application will NOT work!", "Not Operable", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                ADB.Start();

                // Here we initiate the BASE Fastboot instance
                Fastboot.Instance();

                //This will starte a thread which checks every 10 sec for connected devices and call the given callback
                if (Fastboot.DeviceConnectionMonitor(true))
                {
                    //Here we define our callback function which will be raised if a device connects or disconnects
                    Fastboot.SetDeviceConnectionMonitorCallback = (CallbackDeviceConnectionMonitor)CheckDeviceState;
                }

                // Here we check if ADB is running and initiate the BASE ADB instance (IsStarted() will everytime check if the BASE ADB class exists, if not it will create it)
                if (ADB.IsStarted())
                {
                    //Here we check for connected devices
                    SetDeviceList();

                    //This will starte a thread which checks every 10 sec for connected devices and call the given callback
                    if (ADB.DeviceConnectionMonitor(true))
                    {
                        //Here we define our callback function which will be raised if a device connects or disconnects
                        ADB.SetDeviceConnectionMonitorCallback = (CallbackDeviceConnectionMonitor)CheckDeviceState;
                    }
                }
            }
        }