Example #1
0
        private void DeviceDetectionService()
        {
            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.ConnectionMonitor.Start())
            {
                //Here we define our callback function which will be raised if a device connects or disconnects
                Fastboot.ConnectionMonitor.Callback += ConnectionMonitorCallback;

                // 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.ConnectionMonitor.Start())
                    {
                        ADB.ConnectionMonitor.Callback += ConnectionMonitorCallback;
                    }
                    //Here we define our callback function which will be raised if a device connects or disconnects
                }
            }
        }
Example #2
0
        private void btnHtcDev_Click(object sender, RoutedEventArgs e)
        {
            if (deviceselector.Items.Count == 0)
            {
                MessageBox.Show("A device has not been detected as of yet. Wait 10 seconds or diagnose the issue.", "No Device", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            IDDeviceState state = General.CheckDeviceState(ADB.Instance().DeviceID);

            if (state == IDDeviceState.DEVICE)
            {
                ADB.Instance().Reboot(IDBoot.BOOTLOADER);
                CidDialog ciddiag = CidDialog.Instance;
                ciddiag.Add(Fastboot.Instance().OEM.GetIdentifierToken());
                ciddiag.Show();
                MessageBox.Show("You must continue from the HTC Dev website.", "Redirecting to HTCDev.com", MessageBoxButton.OK, MessageBoxImage.Information);
                System.Diagnostics.Process.Start("http://www.htcdev.com/bootloader/");
            }
            else if (state == IDDeviceState.FASTBOOT)
            {
                CidDialog ciddiag = CidDialog.Instance;
                ciddiag.Add(Fastboot.Instance().OEM.GetIdentifierToken());
                ciddiag.Show();
                MessageBox.Show("You must continue from the HTC Dev website.", "Redirecting to HTCDev.com", MessageBoxButton.OK, MessageBoxImage.Information);
                System.Diagnostics.Process.Start("http://www.htcdev.com/bootloader/");
            }
        }
Example #3
0
 private void btnFbtGo_Click(object sender, RoutedEventArgs e)
 {
     if (cBFbtCmds.Text == "Reboot")
     {
         Fastboot.Instance().Reboot(IDBoot.REBOOT);
     }
     else if (cBFbtCmds.Text == "Reboot Bootloader")
     {
         Fastboot.Instance().Reboot(IDBoot.BOOTLOADER);
     }
     else if (cBFbtCmds.Text == "RebootRUU")
     {
         Fastboot.Instance().OEM.RebootRUU();
     }
     else if (cBFbtCmds.Text == "Read CID")
     {
         CidDialog ciddiag = CidDialog.Instance;
         ciddiag.Add(Fastboot.Instance().OEM.ReadCid());
         ciddiag.Show();
     }
     else if (cBFbtCmds.Text == "Show Identifier Token")
     {
         CidDialog ciddiag = CidDialog.Instance;
         ciddiag.Add(Fastboot.Instance().OEM.GetIdentifierToken());
         ciddiag.Show();
     }
     else if (cBFbtCmds.Text == "Relock Bootloader")
     {
         if (MessageBox.Show("Are you sure you want to relock the bootloader?", "Are you sure you want to relock?", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
         {
             CidDialog ciddiag = CidDialog.Instance;
             ciddiag.Add(Fastboot.Instance().OEM.Lock());
             ciddiag.Show();
         }
         else
         {
             //No
         }
     }
     else if (cBFbtCmds.Text == "S-On Bootloader")
     {
         if (MessageBox.Show("Are you sure you want to S-On?", "Are you sure you want to S-On?", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
         {
             CidDialog ciddiag = CidDialog.Instance;
             ciddiag.Add(Fastboot.Instance().OEM.WriteSecureFlag("3"));
             ciddiag.Show();
         }
         else
         {
             //No
         }
     }
     else
     {
         MessageBox.Show("You have not selected a command.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Example #4
0
 public static void PanicKill()
 {
     oConfigMng.SaveConfig();
     ADB.ConnectionMonitor.Stop();
     ADB.Stop();
     Fastboot.Dispose();
     ADB.Dispose();
     Application.ExitThread();
     Application.Exit();
 }
Example #5
0
 private void SelectDeviceInstance(object sender, SelectionChangedEventArgs e)
 {
     if (deviceselector.Items.Count != 0)
     {
         DataModelDevicesItem device = (DataModelDevicesItem)deviceselector.SelectedItem;
         // This will select the given device in the Fastboot and ADB class
         Fastboot.SelectDevice(device.Serial);
         ADB.SelectDevice(device.Serial);
     }
 }
Example #6
0
        private void btnUnlock_Click(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Set filter for file extension and default file extension
            dlg.DefaultExt = "*.*";
            dlg.Filter     = "All Files (*.*)|*.*";

            // Display OpenFileDialog by calling ShowDialog method
            Nullable <bool> result = dlg.ShowDialog();

            // Get the selected file name and display in a TextBox
            if (result == true)
            {
                // Open document
                string filename = dlg.FileName;
                tbToken.Text = filename;
            }

            Main m = new Main();

            IDDeviceState state = General.CheckDeviceState(ADB.Instance().DeviceID);

            if (state == IDDeviceState.DEVICE)
            {
                ADB.Instance().Reboot(IDBoot.BOOTLOADER);

                MessageBoxResult messageResult = MessageBox.Show("Unlocking the bootloader will wipe all DATA on your phone. Are you sure you want to continue?", "Erase DATA!", MessageBoxButton.YesNo, MessageBoxImage.Information);
                if (messageResult == MessageBoxResult.Yes)
                {
                    m.Add(Fastboot.Instance().Flash(IDDevicePartition.UNLOCKTOKEN, tbToken.Text));
                }
                if (messageResult == MessageBoxResult.No)
                {
                    //No
                }
            }
            else if (state == IDDeviceState.FASTBOOT)
            {
                MessageBoxResult messageResult = MessageBox.Show("Unlocking the bootloader will wipe all DATA on your phone. Are you sure you want to continue?", "Erase DATA!", MessageBoxButton.YesNo, MessageBoxImage.Information);
                if (messageResult == MessageBoxResult.Yes)
                {
                    m.Add(Fastboot.Instance().Flash(IDDevicePartition.UNLOCKTOKEN, tbToken.Text));
                }
                if (messageResult == MessageBoxResult.No)
                {
                    //No
                }
            }
            else
            {
                MessageBox.Show("A device was not detected... Please ensure that you have the correct drivers configured and that they are working!", "Device is not detected...", MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }
        }
Example #7
0
        private void btnFBTGo_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                switch (lbFastboot.SelectedValue.ToString())
                {
                case "Flash":
                {
                    var fbtsel = new FastbootSelector();
                    ToolkitM9.FastbootSelector.Settings.Selector = "Flash";
                    fbtsel.ShowDialog();
                }
                break;

                case "Erase":
                {
                    var fbtsel = new FastbootSelector();
                    ToolkitM9.FastbootSelector.Settings.Selector = "Erase";
                    fbtsel.ShowDialog();
                }
                break;

                case "Boot":
                {
                    var fbtsel = new FastbootSelector();
                    ToolkitM9.FastbootSelector.Settings.Selector = "Boot";
                    fbtsel.ShowDialog();
                }
                break;

                case "Reboot":
                {
                    this.Add(Fastboot.Instance().Reboot(IDBoot.REBOOT));
                }
                break;

                case "Reboot Bootloader":
                {
                    this.Add(Fastboot.Instance().Reboot(IDBoot.BOOTLOADER));
                }
                break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "An error has occured! A log file has been placed in the Logs folder. Please report this error, with the log file, in the toolkit thread on XDA. Links in the 'File' menu!",
                    "Critical Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                string fileDateTime = DateTime.Now.ToString("MMddyyyy") + "_" + DateTime.Now.ToString("HHmmss");
                var    file         = new StreamWriter("./Data/Logs/" + fileDateTime + ".txt");
                file.WriteLine(ex);
                file.Close();
            }
        }
Example #8
0
 private void buttonUnlockCritical_Click(object sender, EventArgs e)
 {
     if (isConnected())
     {
         cAppend("Unlocking critical...");
         string unlock = Fastboot.ExecuteFastbootCommand(Fastboot.FormFastbootCommand(" flashing unlock_critical"));
         cAppend(unlock.ToString());
         cAppend("Unlocking critical... {OK}");
     }
     else
     {
         cAppend("{UnlockCriticalBootloader} Please connect your device...");
         return;
     }
 }
Example #9
0
 private void buttonLockBootloader_Click(object sender, EventArgs e)
 {
     if (isConnected())
     {
         cAppend("Locking bootloader...");
         string locck = Fastboot.ExecuteFastbootCommand(Fastboot.FormFastbootCommand(" flashing lock"));
         cAppend(locck.ToString());
         cAppend("Locking bootloader... {OK}");
     }
     else
     {
         cAppend("{LockBootloader} Please connect your device...");
         return;
     }
 }
        public static void ExecuteRebootBootloader(object parameter)
        {
            SingleCommandParameters parameters = (SingleCommandParameters)parameter;

            Context = parameters.Context;
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += async(sender, args) =>
            {
                await Context.Dispatcher.InvokeAsync(() => { Fastboot = new FastbootTools(Context); });

                await Task.Run(async() => await Fastboot.RebootBootloader(parameters.Bool));
            };
            worker.RunWorkerCompleted += (sender, args) => worker.Dispose();
            worker.RunWorkerAsync();
        }
Example #11
0
        private void SetupAndroidCtrl()
        {
            // Extract AndroidCtrl files if none are found
            if (!ADB.IntegrityCheck())
            {
                _log.Info("ADB files missing, deploying");
                // If AndroidCtrl path is empty, deply to ./ToolkitData/adb
                if (String.IsNullOrEmpty(Settings.Default.ACtrl_Location))
                {
                    Deploy.ADB("./ToolkitData/platform-tools");
                    _log.Info("ADB deployed to ./ToolkitData/platform-tools");
                }
                else
                {
                    Deploy.ADB(Settings.Default.ACtrl_Location);
                    _log.Info($"ADB deployed to {Settings.Default.ACtrl_Location}");
                }
            }

            if (!Fastboot.IntegrityCheck())
            {
                _log.Info("fastboot files missing, deploying");
                // If AndroidCtrl path is empty, deply to ./ToolkitData/adb
                if (String.IsNullOrEmpty(Settings.Default.ACtrl_Location))
                {
                    Deploy.Fastboot("./ToolkitData/platform-tools");
                    _log.Info("ADB deployed to ./ToolkitData/platform-tools");
                }
                else
                {
                    Deploy.Fastboot(Settings.Default.ACtrl_Location);
                    _log.Info($"ADB deployed to {Settings.Default.ACtrl_Location}");
                }
            }

            // Start Monitoring services
            // Check if ADB server is already running, and check if it is mismatched

            if (!ADB.IsStarted || !ADB.IntegrityVersionCheck())
            {
                _log.Warn("ADB server outdated or not started");
                ADB.Stop();
                _log.Info("Starting ADB server...");
                ADB.Start();
            }
        }
        public static void ExecuteToken(object parameter)
        {
            UIParameters parameters = (UIParameters)parameter;

            Context = parameters.Context;
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += async(sender, args) =>
            {
                await Context.Dispatcher.InvokeAsync(() => { Fastboot = new FastbootTools(Context); });

                await
                Task.Run(
                    async() =>
                    await Fastboot.GetIdentiferToken(parameters.Context2, parameters.Bool));
            };
            worker.RunWorkerCompleted += (sender, args) => worker.Dispose();
            worker.RunWorkerAsync();
        }
Example #13
0
 public void CheckandDeploy()
 {
     if (ADB.IntegrityCheck() == false)
     {
         Deploy.ADB();
     }
     if (Fastboot.IntegrityCheck() == false)
     {
         Deploy.Fastboot();
     }
     // Check if ADB is running
     if (ADB.IsStarted)
     {
         ADB.Stop();             // Stop ADB
         ADB.Stop(true);         // Force Stop ADB
     }
     else
     {
         ADB.Start();
     }                           // Start ADB
 }
Example #14
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            args = e.Argument as Controls.NVForm.FormEventArgs;
            fb   = new Fastboot();

            try
            {
                if (args.TargetMode == UsbController.Device.DMode.DownloadVCOM)
                {
                    Log.Info("--> Flashing bootloader");
                    FlashBootloader(args.Bootloader, args.Target.Split(':')[0]);

                    Log.Info("Waiting for any device...");
                    fb.Wait();
                }

                Log.Info("--> Reading information");
                Log.Info("Connecting to fastboot device...");

                fb.Connect();
                ReadInfo();

                Log.Info("--> Updating NVME");
                WriteNVME();

                Log.Success("Update done!");
                Log.Info("Rebooting...");

                fb.Command("reboot");

                Log.Info($"Bootloader unlock code: {args.UnlockCode}");

                fb.Disconnect();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                Log.Debug(ex.StackTrace);
            }
        }
Example #15
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            args = e.Argument as Controls.NVForm.FormEventArgs;
            fb   = new Fastboot();

            try
            {
                if (args.TargetMode == UsbController.Device.DMode.DownloadVCOM)
                {
                    FlashBootloader(args.Bootloader, args.Target.Split(':')[0]);

                    Log.Info("Waiting for any device...");
                    fb.Wait();
                }

                Log.Info("Connecting...");

                fb.Connect();
                ReadInfo();
                WriteNVME();

                Log.Info("Finalizing...");
                LogResponse(fb.Command($"oem unlock {args.UnlockCode}"));

                if (args.Reboot)
                {
                    Log.Info("Rebooting...");
                    fb.Command("reboot");
                }

                Log.Info($"Bootloader unlock code: {args.UnlockCode}");

                fb.Disconnect();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
                Log.Debug(ex.StackTrace);
            }
        }
Example #16
0
        private void btnExec_Click(object sender, RoutedEventArgs e)
        {
            if (cBFbtOem.Text == "")
            {
                MessageBox.Show("You must select a command to execute!");
            }
            else if (cBFbtOem.Text == "RebootRUU")
            {
                Fastboot.Instance().OEM.RebootRUU();
            }
            else if (cBFbtOem.Text == "Lock Bootloader")
            {
                TaskDialogOptions config = new TaskDialogOptions();

                config.Owner           = this;
                config.Title           = "Are you sure?";
                config.MainInstruction = "You are about to RELOCK the bootloader.";
                config.Content         = "You will need to go through an unlocking procedure again"
                                         + "to unlock the bootloader. (Either through HTCDev or the ADB Bootloader Commands)";
                config.CommandButtons = new string[] {
                    "No", "No", "Yes"
                };
                config.MainIcon = VistaTaskDialogIcon.Information;

                TaskDialogResult res = TaskDialog.Show(config);
                if (res.CommandButtonResult == 0)
                {
                }
                else if (res.CommandButtonResult == 1)
                {
                }
                else if (res.CommandButtonResult == 2)
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().OEM.Lock());
                }
            }
        }
Example #17
0
        private void btnBoot_Click(object sender, RoutedEventArgs e)
        {
            if (tBFbtPath.Text == "")
            {
                if (MessageBox.Show("You have not selected a file. Would you like to select one now?", "Missing File", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    // Create OpenFileDialog
                    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

                    // Set filter for file extension and default file extension
                    dlg.DefaultExt = "";
                    dlg.Filter     = "All Files (*.*)|*.*";
                    dlg.Title      = "Locate Files";

                    // Display OpenFileDialog by calling ShowDialog method
                    Nullable <bool> result = dlg.ShowDialog();

                    // Get the selected file name and display in a TextBox
                    if (result == true)
                    {
                        // Open document
                        string filename = dlg.FileName;
                        tBFbtPath.Text = filename;
                    }
                }
                else
                {
                    //nothing
                }
            }
            else
            {
                CidDialog ciddiag = CidDialog.Instance;
                ciddiag.Show();
                ciddiag.Add(Fastboot.Instance().Boot(tBFbtPath.Text, "", 10));
            }
        }
Example #18
0
        private void buttonBOOTTWRP_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = exePath;
            openFileDialog1.Title            = "Select your TWRP img!";
            openFileDialog1.Filter           = @"img Files|*.img";
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string twrp = openFileDialog1.FileName.ToString();

            if (isConnected())
            {
                cAppend("Booting " + twrp + "...");
                Fastboot.ExecuteFastbootCommand(Fastboot.FormFastbootCommand(" flash boot " + twrp));
                cAppend("Booting " + twrp + "... {OK}");
                Fastboot.ExecuteFastbootCommand(Fastboot.FormFastbootCommand(" reboot recovery"));
            }
            else
            {
                cAppend("{BootTWRP} Please connect your device...");
                return;
            }
        }
Example #19
0
 private Device[] GetFastbootDevices()
 {
     return(Fastboot.GetDevices()
            .Select(x => new Device(Device.DMode.Fastboot, x))
            .ToArray());
 }
Example #20
0
        private void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            if (Settings.Recovery.ToString() == "1")
            {
                if (ADB.Instance().GetState() == IDDeviceState.DEVICE)
                {
                    MessageBoxResult messageResult = MessageBox.Show("Your phone needs to be in 'fastboot USB' mode. Would you like to reboot into it now?", "Reboot to bootloader required!", MessageBoxButton.YesNo, MessageBoxImage.Information);
                    if (messageResult == MessageBoxResult.Yes)
                    {
                        tBRecoveryStatus.Text = "Rebooting into Bootloader...";
                        ADB.Instance().Reboot(IDBoot.BOOTLOADER);
                        tBRecoveryStatus.Text = "Waiting for device...";

                        if (cbFlashDownload.IsChecked == true)
                        {
                            Task.Delay(10000).ContinueWith(_ =>
                            {
                                tBRecoveryStatus.Text = "Rebooting into Download Mode...";
                                Fastboot.Instance().OEM.RebootRUU();
                            });
                        }

                        Task.Delay(10000).ContinueWith(_ =>
                        {
                            tBRecoveryStatus.Text = "Flashing recovery...";
                            Fastboot.Instance().Flash(IDDevicePartition.RECOVERY, "./Data/Recoveries/Recovery1.img");

                            App.Current.Dispatcher.Invoke((Action) delegate
                            {
                                tBRecoveryStatus.Text = "Rebooting...";
                                Fastboot.Instance().Reboot(IDBoot.REBOOT);
                            });
                        }
                                                       );
                    }
                }
                else if (ADB.Instance().GetState() == IDDeviceState.FASTBOOT)
                {
                    tBRecoveryStatus.Text = "Flashing recovery...";
                    Fastboot.Instance().Flash(IDDevicePartition.RECOVERY, "./Data/Recoveries/Recovery1.img");

                    App.Current.Dispatcher.Invoke((Action) delegate
                    {
                        tBRecoveryStatus.Text = "Rebooting...";
                        Fastboot.Instance().Reboot(IDBoot.REBOOT);
                    });
                }
            }
            else if (Settings.Recovery.ToString() == "2")
            {
                if (ADB.Instance().GetState() == IDDeviceState.DEVICE)
                {
                    MessageBoxResult messageResult = MessageBox.Show("Your phone needs to be in 'fastboot USB' mode. Would you like to reboot into it now?", "Reboot to bootloader required!", MessageBoxButton.YesNo, MessageBoxImage.Information);
                    if (messageResult == MessageBoxResult.Yes)
                    {
                        //tBRecoveryStatus.Text = "Rebooting into Bootloader...";
                        ADB.Instance().Reboot(IDBoot.BOOTLOADER);
                        tBRecoveryStatus.Text = "Waiting for device...";

                        //Rebooting into RUU mode if cheked.
                        if (cbFlashDownload.IsChecked == true)
                        {
                            Task.Delay(10000).ContinueWith(_ =>
                            {
                                tBRecoveryStatus.Text = "Rebooting into Download Mode...";
                                Fastboot.Instance().OEM.RebootRUU();
                            });
                        }

                        Task.Delay(10000).ContinueWith(_ =>
                        {
                            //tBRecoveryStatus.Text = "Flashing recovery...";
                            Fastboot.Instance().Flash(IDDevicePartition.RECOVERY, "./Data/Recoveries/Recovery2.img");

                            App.Current.Dispatcher.Invoke((Action) delegate
                            {
                                //tBRecoveryStatus.Text = "Rebooting...";
                                Fastboot.Instance().Reboot(IDBoot.REBOOT);
                            });
                        }
                                                       );
                    }
                }
                else if (ADB.Instance().GetState() == IDDeviceState.FASTBOOT)
                {
                    //tBRecoveryStatus.Text = "Flashing recovery...";
                    Fastboot.Instance().Flash(IDDevicePartition.RECOVERY, "./Data/Recoveries/Recovery2.img");

                    App.Current.Dispatcher.Invoke((Action) delegate
                    {
                        //tBRecoveryStatus.Text = "Rebooting...";
                        Fastboot.Instance().Reboot(IDBoot.REBOOT);
                    });
                }
            }
        }
Example #21
0
        private void btnUnlockCode_Click(object sender, RoutedEventArgs e)
        {
            IDDeviceState state = General.CheckDeviceState(ADB.Instance().DeviceID);

            if (state == IDDeviceState.DEVICE)
            {
                tBUnlockStatus.Text = "Rebooting into the bootloader...";
                ADB.Instance().Reboot(IDBoot.BOOTLOADER);

                using (StreamWriter sw = File.CreateText("./Data/token.txt"))
                {
                    List <string> _token = new List <string>();
                    foreach (string line in Fastboot.Instance().OEM.GetIdentifierToken())
                    {
                        GroupCollection groups = Regex.Match(line, @"^\(bootloader\)\s{1,}(?<PART>.*?)$").Groups;
                        string          part   = groups["PART"].Value;
                        if (String.IsNullOrEmpty(part) == false && Regex.IsMatch(part, @"^<{1,}.*?>{1,}$") == false)
                        {
                            _token.Add(part);
                        }
                    }

                    tBUnlockStatus.Text = "Collecting token...";

                    //the final string which u can write to an file
                    string token = String.Join("\n", _token.ToArray());
                    sw.WriteLine(token.ToString());

                    sw.WriteLine(" ");
                    sw.WriteLine("Please copy everything above this line!");
                    sw.WriteLine(" ");
                    sw.WriteLine("Next, sign into your HTC Dev account on the webpage that just opened.");
                    sw.WriteLine("If you do not have an account, create and activate an account with your email, then come back to this link.");
                    sw.WriteLine("http://www.htcdev.com/bootloader/unlock-instructions/page-3");
                    sw.WriteLine("Then, paste the Token ID you just copied at the bottom of the webpage.");
                    sw.WriteLine("Hit submit, and wait for the email with the unlock file.");
                    sw.WriteLine(" ");
                    sw.WriteLine("Once you have received the unlock file, download it and continue on to the next step, unlocking your bootloader.");
                    sw.WriteLine("This file is saved as token.txt in the Data folder if you need it in the future.");
                    sw.Close();
                }

                MessageBox.Show("The token is saved as token.txt in the Data folder. Further instructions are there. Please press OK to dismiss...");
                //Process.Start("./Data/token.txt");

                MessageBoxResult messageResult = MessageBox.Show("The package has been secured! Your unlock code is located '/Data/token.txt'. Would you like to reboot now?", "Token Obtained!", MessageBoxButton.YesNo, MessageBoxImage.Information);
                if (messageResult == MessageBoxResult.Yes)
                {
                    Fastboot.Instance().Reboot(IDBoot.REBOOT);
                    Process.Start("http://www.htcdev.com/bootloader/unlock-instructions/page-3");
                    Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "/Data/token.txt");
                    MessageBox.Show("Next Step!", "Once you have recieved the unlock file from HTC, you can move on to the next step, unlocking your bootloader!", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                if (messageResult == MessageBoxResult.No)
                {
                    Process.Start("http://www.htcdev.com/bootloader/unlock-instructions/page-3");
                    Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "/Data/token.txt");
                    MessageBox.Show("Next Step!", "Once you have recieved the unlock file from HTC, you can move on to the next step, unlocking your bootloader! More information is also avaliable in the /Data/token.txt file.", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else if (state == IDDeviceState.FASTBOOT)
            {
                using (StreamWriter sw = File.CreateText("./Data/token.txt"))
                {
                    List <string> _token = new List <string>();
                    foreach (string line in Fastboot.Instance().OEM.GetIdentifierToken())
                    {
                        GroupCollection groups = Regex.Match(line, @"^\(bootloader\)\s{1,}(?<PART>.*?)$").Groups;
                        string          part   = groups["PART"].Value;
                        if (String.IsNullOrEmpty(part) == false && Regex.IsMatch(part, @"^<{1,}.*?>{1,}$") == false)
                        {
                            _token.Add(part);
                        }
                    }

                    tBUnlockStatus.Text = "Collecting token...";

                    //the final string which u can write to an file
                    string token = String.Join("\n", _token.ToArray());
                    sw.WriteLine(token.ToString());

                    sw.WriteLine(" ");
                    sw.WriteLine("Please copy everything above this line!");
                    sw.WriteLine(" ");
                    sw.WriteLine("Next, sign into your HTC Dev account on the webpage that just opened.");
                    sw.WriteLine("If you do not have an account, create and activate an account with your email, then come back to this link.");
                    sw.WriteLine("http://www.htcdev.com/bootloader/unlock-instructions/page-3");
                    sw.WriteLine("Then, paste the Token ID you just copied at the bottom of the webpage.");
                    sw.WriteLine("Hit submit, and wait for the email with the unlock file.");
                    sw.WriteLine(" ");
                    sw.WriteLine("Once you have received the unlock file, download it and continue on to the next step, unlocking your bootloader.");
                    sw.WriteLine("This file is saved as token.txt in the Data folder if you need it in the future.");
                    sw.Close();
                }

                MessageBoxResult messageResult = MessageBox.Show("The package has been secured! Your unlock code is located '/Data/token.txt'. Would you like to reboot now?", "Token Obtained!", MessageBoxButton.YesNo, MessageBoxImage.Information);
                if (messageResult == MessageBoxResult.Yes)
                {
                    Fastboot.Instance().Reboot(IDBoot.REBOOT);
                    Process.Start("http://www.htcdev.com/bootloader/unlock-instructions/page-3");
                    Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "/Data/token.txt");
                    MessageBox.Show("Next Step!", "Once you have recieved the unlock file from HTC, you can move on to the next step, unlocking your bootloader!", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                if (messageResult == MessageBoxResult.No)
                {
                    Process.Start("http://www.htcdev.com/bootloader/unlock-instructions/page-3");
                    Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "/Data/token.txt");
                    MessageBox.Show("Next Step!", "Once you have recieved the unlock file from HTC, you can move on to the next step, unlocking your bootloader! More information is also avaliable in the /Data/token.txt file.", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else
            {
                MessageBox.Show("A device was not detected... Please ensure that you have the correct drivers configured and that they are working!", "Device is not detected...", MessageBoxButton.OK, MessageBoxImage.Asterisk);
            }
        }
Example #22
0
        private void btnGoFlash_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                #region Flash
                if (Settings.Selector == "Flash")
                {
                    switch (cbPartition.Text)
                    {
                    case "Boot":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.BOOT, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "Cache":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.CACHE, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "Data":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.DATA, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "Hboot":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.HBOOT, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "Kernel":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.KERNEL, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "Misc":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.MISC, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "Radio":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.RADIO, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "Ramdisk":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.RAMDISK, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "Recovery":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.RECOVERY, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "System":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.SYSTEM, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "Unlock Token":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.UNLOCKTOKEN, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;

                    case "Zip":
                    {
                        if (tbFilepath.Text == "")
                        {
                            MessageBox.Show("You must browse for a file to flash! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            Fastboot.Instance().Flash(IDDevicePartition.ZIP, Quote.Text + tbFilepath.Text + Quote.Text);
                        }
                    }
                    break;
                    }
                    #endregion
                }
                #region Erase
                else if (Settings.Selector == "Erase")
                {
                    switch (cbPartition.Text)
                    {
                    case "Boot":
                    {
                        Fastboot.Instance().Erase(IDDevicePartition.BOOT);
                    }
                    break;

                    case "Cache":
                    {
                        Fastboot.Instance().Erase(IDDevicePartition.CACHE);
                    }
                    break;

                    case "Data":
                    {
                        Fastboot.Instance().Erase(IDDevicePartition.DATA);
                    }
                    break;

                    case "Hboot":
                    {
                        MessageBox.Show("You cannot erase the " + cbPartition.Text + " partition!", "Protected Partition!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    break;

                    case "Kernel":
                    {
                        Fastboot.Instance().Erase(IDDevicePartition.KERNEL);
                    }
                    break;

                    case "Misc":
                    {
                        Fastboot.Instance().Erase(IDDevicePartition.MISC);
                    }
                    break;

                    case "Radio":
                    {
                        Fastboot.Instance().Erase(IDDevicePartition.RADIO);
                    }
                    break;

                    case "Ramdisk":
                    {
                        Fastboot.Instance().Erase(IDDevicePartition.RAMDISK);
                    }
                    break;

                    case "Recovery":
                    {
                        Fastboot.Instance().Erase(IDDevicePartition.RECOVERY);
                    }
                    break;

                    case "System":
                    {
                        Fastboot.Instance().Erase(IDDevicePartition.SYSTEM);
                    }
                    break;

                    case "Unlock Token":
                    {
                        MessageBox.Show("You cannot erase the " + cbPartition.Text + " partition!", "Protected Partition!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    break;

                    case "Zip":
                    {
                        MessageBox.Show("You cannot erase the " + cbPartition.Text + " partition!", "Protected Partition!", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    break;
                    }
                    #endregion
                }
                #region boot
                else if (Settings.Selector == "Boot")
                {
                    if (tbFilepath.Text == "")
                    {
                        MessageBox.Show("You must browse for a file to boot from! Please select a file.", "Missing file!", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        Fastboot.Instance().Boot(Quote.Text + tbFilepath.Text + Quote.Text);
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    "An error has occured! A log file has been placed in the Logs folder. Please report this error, with the log file, in the toolkit thread on XDA. Links in the 'File' menu!",
                    "Critical Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                string fileDateTime = DateTime.Now.ToString("MMddyyyy") + "_" + DateTime.Now.ToString("HHmmss");
                var    file         = new StreamWriter("./Data/Logs/" + fileDateTime + ".txt");
                file.WriteLine(ex);
                file.Close();
            }
        }
Example #23
0
        private void SetDeviceList()
        {
            string active = String.Empty;

            if (deviceselector.Items.Count != 0)
            {
                active = ((DataModelDevicesItem)deviceselector.SelectedItem).Serial;
            }

            App.Current.Dispatcher.Invoke((Action) delegate
            {
                // Here we refresh our combobox
                deviceselector.Items.Clear();
            });

            // This will get the currently connected ADB devices
            IEnumerable <DataModelDevicesItem> adbDevices = ADB.Devices();

            // This will get the currently connected Fastboot devices
            IEnumerable <DataModelDevicesItem> fastbootDevices = Fastboot.Devices();

            foreach (DataModelDevicesItem device in adbDevices)
            {
                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    // here goes the add command ;)
                    deviceselector.Items.Add(device);
                    ConsoleAppend(String.Format("Device connected: {0} ({1}), State: {2}.", device.Model, device.Serial.ToString(), device.State.ToString()));
                });
            }
            foreach (DataModelDevicesItem device in fastbootDevices)
            {
                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    deviceselector.Items.Add(device);
                    ConsoleAppend(String.Format("Device connected: {0} ({1}), State: {2}.", device.Model, device.Serial.ToString(), device.State.ToString()));
                });
            }
            if (deviceselector.Items.Count != 0)
            {
                int  i     = 0;
                bool empty = true;
                foreach (DataModelDevicesItem device in deviceselector.Items)
                {
                    if (device.Serial == active)
                    {
                        empty = false;
                        deviceselector.SelectedIndex = i;
                        break;
                    }
                    i++;
                }
                if (empty)
                {
                    // This calls will select the BASE class if we have no connected devices
                    ADB.SelectDevice();
                    Fastboot.SelectDevice();

                    App.Current.Dispatcher.Invoke((Action) delegate
                    {
                        deviceselector.SelectedIndex = 0;
                    });
                }
            }
        }
Example #24
0
 private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     ADB.Dispose();
     Fastboot.Dispose();
 }
Example #25
0
 private void Window_Closed(object sender, EventArgs e)
 {
     ADB.Stop();
     ADB.Dispose(true);
     Fastboot.Dispose();
 }
Example #26
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;
                    }
                }
            }
        }
Example #27
0
 private void Window_Closing(object sender, CancelEventArgs e)
 {
     ADB.Stop();
     ADB.Dispose();
     Fastboot.Dispose();
 }
Example #28
0
        private void btnFbtFlash_Click(object sender, RoutedEventArgs e)
        {
            if (tBFbtPath.Text == "")
            {
                if (MessageBox.Show("You have not selected a file to complete the command. \nWould you like to locate one now?", "Missing File", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    // Create OpenFileDialog
                    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

                    // Set filter for file extension and default file extension
                    dlg.DefaultExt = "";
                    dlg.Filter     = "All Files (*.*)|*.*";
                    dlg.Title      = "Locate Files";

                    // Display OpenFileDialog by calling ShowDialog method
                    Nullable <bool> result = dlg.ShowDialog();

                    // Get the selected file name and display in a TextBox
                    if (result == true)
                    {
                        // Open document
                        string filename = dlg.FileName;
                        tBFbtPath.Text = filename;
                    }
                }
                else
                {
                    MessageBox.Show("You cannot continue unless you select a file.", "Missing File", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            else if (cBFbtPart.Text == "")
            {
                MessageBox.Show("You cannot continue unless you select a partition.", "Partition not Selected", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                if (cBFbtPart.Text == "Boot")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.BOOT, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "Cache")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.CACHE, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "Data")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.DATA, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "Hboot")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.HBOOT, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "Kernel")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.KERNEL, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "Misc")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.MISC, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "Radio")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.RADIO, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "Ramdisk")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.RAMDISK, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "Recovery")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.RECOVERY, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "System")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.SYSTEM, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "Unlock Token")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.UNLOCKTOKEN, tBFbtPath.Text));
                }
                else if (cBFbtPart.Text == "Zip")
                {
                    CidDialog ciddiag = CidDialog.Instance;
                    ciddiag.Show();
                    ciddiag.Add(Fastboot.Instance().Flash(IDDevicePartition.ZIP, tBFbtPath.Text));
                }
            }
        }
Example #29
0
 private void btnErase_Click(object sender, RoutedEventArgs e)
 {
     if (deviceselector.Text == "")
     {
         MessageBox.Show("A device has not been detected! Please wait 10 seconds or diagnose the issue!", "No device detected", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     else
     {
         if (cBFbtPart.Text == "")
         {
             MessageBox.Show("You cannot continue unless you select a partition.", "Partition not Selected", MessageBoxButton.OK, MessageBoxImage.Information);
         }
         else
         {
             if (cBFbtPart.Text == "Boot")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.BOOT));
             }
             else if (cBFbtPart.Text == "Cache")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.CACHE));
             }
             else if (cBFbtPart.Text == "Data")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.DATA));
             }
             else if (cBFbtPart.Text == "Hboot")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.HBOOT));
             }
             else if (cBFbtPart.Text == "Kernel")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.KERNEL));
             }
             else if (cBFbtPart.Text == "Misc")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.MISC));
             }
             else if (cBFbtPart.Text == "Radio")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.RADIO));
             }
             else if (cBFbtPart.Text == "Ramdisk")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.RAMDISK));
             }
             else if (cBFbtPart.Text == "Recovery")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.RECOVERY));
             }
             else if (cBFbtPart.Text == "System")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.SYSTEM));
             }
             else if (cBFbtPart.Text == "Unlock Token")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.UNLOCKTOKEN));
             }
             else if (cBFbtPart.Text == "Zip")
             {
                 CidDialog ciddiag = CidDialog.Instance;
                 ciddiag.Show();
                 ciddiag.Add(Fastboot.Instance().Erase(IDDevicePartition.ZIP));
             }
         }
     }
 }
Example #30
0
        private static async Task Main()
        {
            StartServerResult serverResult;
            var server = new AdbServer();

            try
            {
                serverResult = server.StartServer(@"C:\Program Files (x86)\Essential\ADB\adb.exe", false);
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("ADB path not found!");
                await Task.Delay(1500);

                return;
            }

            Console.WriteLine(serverResult == StartServerResult.Started
                ? "ADB server started!"
                : "ADB server already started!");

            DeviceData device;
            var        fastboot  = new Fastboot();
            var        connected = false;
            var        client    = new AdbClient();

            do
            {
                device = client.GetDevices().FirstOrDefault();
                if (device == null)
                {
                    Console.WriteLine("No adb devices found! Checking if system is in fastboot and sleeping 1.5s.");

                    try
                    {
                        fastboot.Connect();
                        Console.WriteLine("Found fastboot device!");
                        connected = true;
                    }
                    catch
                    {
                        Console.WriteLine("No fastboot devices found!");
                        await Task.Delay(1500);
                    }
                }
                else
                {
                    Console.WriteLine("Device found! Rebooting to bootloader.");

                    client.ExecuteRemoteCommand("reboot bootloader", device, null);
                }
            } while (device == null && !connected);

            FileInfo file;
            var      dirInfo    = new DirectoryInfo(@"C:\Users\Kuran Kaname\Downloads");
            bool     firstCycle = true;

            do
            {
                file = (from f in dirInfo.GetFiles(PatternDownloading) orderby f.LastWriteTime descending select f)
                       .FirstOrDefault() ??
                       (from f in dirInfo.GetFiles(Pattern) orderby f.LastWriteTime descending select f)
                       .FirstOrDefault();

                if (file?.Name.Contains("crdownload") ?? true)
                {
                    if (firstCycle)
                    {
                        Console.WriteLine();
                        firstCycle = false;
                    }

                    Console.WriteLine("File is still downloading! Sleeping 1.5s.");
                    await Task.Delay(1500);
                }
            } while (file?.Name.Contains("crdownload") ?? true);

            Console.WriteLine();
            Console.WriteLine($"Found file: {file.Name}");
            Console.WriteLine();

            while (!connected)
            {
                try
                {
                    fastboot.Connect();
                    connected = true;
                    Console.WriteLine("Fastboot device found!");
                }
                catch
                {
                    Console.WriteLine("No fastboot devices found! Sleeping 1.5s.");
                    await Task.Delay(1500);
                }
            }

            var slot = fastboot.Command("getvar:current-slot");

            Console.WriteLine($"Current slot is: {slot.Payload}");

            fastboot.UploadData($@"{file.Directory}\{file.Name}");

            string flashSlot;

            if (slot.Payload.Contains("a"))
            {
                flashSlot = "flash:boot_a";
            }
            else if (slot.Payload.Contains("b"))
            {
                flashSlot = "flash:boot_b";
            }
            else
            {
                Console.WriteLine("No slot found!");
                await Task.Delay(2500);

                return;
            }

            Fastboot.Response result = fastboot.Command(flashSlot);

            if (result.Status == Fastboot.Status.Okay)
            {
                Console.WriteLine("Flash succesful! Rebooting!");
                fastboot.Command("reboot");
            }
            else
            {
                Console.WriteLine($"Flash unsuccesful! Status: {result.Status}");
            }

            await Task.Delay(2500).ConfigureAwait(false);
        }