Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,732,073 Members 40,966 Now Online
XDA Developers Android and Mobile Development Forum

[DEV] AndroidCtrl.dll (AAPT/ADB/Fastboot Mini-Framework with (apk/zip) Signer)

Tip us?
 
k1ll3r8e
Old
(Last edited by k1ll3r8e; 21st June 2014 at 05:27 PM.)
#11  
Senior Member - OP
Thanks Meter 35
Posts: 102
Join Date: Mar 2011
Location: Delmenhorst

 
DONATE TO ME
Quote:
Originally Posted by squabbi View Post
Thanks again!

It worked perfectly! Another question. I'm now using a textbox to show the output like this:

Code:
MainWindow mainWin = (MainWindow)App.Current.MainWindow;
                mainWin.tBOutput.AppendText(String.Join("", "\n", Fastboot.Instance().OEM.ReadCid()[1]));
                mainWin.tBOutput.ScrollToEnd();
How can I do this but in a seperate window? Like one that is seperate from the MainWindow.

Thanks!
Hey there

There are 3 and more options how u can handle this...

1. Simple "MessageBox"
 

Code:
MessageBox.Show(string.Join("\n", Fastboot.Instance().OEM.ReadCid().ToArray()));


2. Extra Window
 

XAML
Code:
<Window x:Class="Multi_Explorer.viewmodel.android.fastboottools.htc.CidDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Show CID" Height="410" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
    <Grid>
        <RichTextBox x:Name="TokenOutput" IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Auto">
            <RichTextBox.Resources>
                <Style TargetType="{x:Type Paragraph}">
                    <Setter Property="Margin" Value="0,0,0,0"/>
                </Style>
            </RichTextBox.Resources>
            <FlowDocument>
            </FlowDocument>
        </RichTextBox>
    </Grid>
</Window>
CS
Code:
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;

namespace Multi_Explorer.viewmodel.android.fastboottools.htc
{
    /// <summary>
    /// Interaktionslogik für CidDialog.xaml
    /// </summary>
    public partial class CidDialog : Window
    {
        #region Instance

        private static CidDialog _instance = null;

        public static CidDialog Instance
        {
            get
            {
                if (_instance != null)
                {
                    return _instance;
                }
                else
                {
                    _instance = new CidDialog();
                    return _instance;
                }
            }
        }

        #endregion

        public CidDialog()
        {
            InitializeComponent();
            this.Closing += WindowClosing;
            App.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
        }

        #region WindowClosing

        ///<summary>
        /// Clean exit
        ///</summary>
        private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            _instance = null;
        }
        #endregion

        #region Add

        public void Add(List<string> msg)
        {
            foreach (string tmp in msg)
            {
                TokenOutput.Document.Blocks.Add(new Paragraph(new Run(tmp)));
            }
            TokenOutput.ScrollToEnd();
        }
        #endregion

        #region Clear

        public void Clear()
        {
            TokenOutput.Document.Blocks.Clear();
        }
        #endregion
    }
}
Usage
Code:
CidDialog ciddiag = CidDialog.Instance;
ciddiag.Add(Fastboot.Instance().OEM.ReadCid());

// As window
ciddiag.Show();

// As dialog window (this will freeze the complete application until it's closed)
ciddiag.ShowDialog();


3. Extra Window with ADB/Fastboot instance
 

XAML
Code:
<Window x:Class="Multi_Explorer.viewmodel.android.fastboottools.htc.CidDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Show CID" Height="410" Width="300" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
    <Grid>
        <RichTextBox x:Name="TokenOutput" IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Auto">
            <RichTextBox.Resources>
                <Style TargetType="{x:Type Paragraph}">
                    <Setter Property="Margin" Value="0,0,0,0"/>
                </Style>
            </RichTextBox.Resources>
            <FlowDocument>
            </FlowDocument>
        </RichTextBox>
    </Grid>
</Window>
CS
Code:
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;

using AndroidCtrl;
using AndroidCtrl.ADB;
using AndroidCtrl.Tools;
using AndroidCtrl.Fastboot;

namespace Multi_Explorer.viewmodel.android.fastboottools.htc
{
    /// <summary>
    /// Interaktionslogik für CidDialog.xaml
    /// </summary>
    public partial class CidDialog : Window
    {
        public CidDialog()
        {
            InitializeComponent();
            this.Closing += WindowClosing;
            App.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;

            // If u have a selected device this will work in all sub-windows
            Add(Fastboot.Instance().OEM.ReadCid());
        }

        #region WindowClosing

        ///<summary>
        /// Clean exit
        ///</summary>
        private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            _instance = null;
        }
        #endregion

        #region Add

        public void Add(List<string> msg)
        {
            foreach (string tmp in msg)
            {
                TokenOutput.Document.Blocks.Add(new Paragraph(new Run(tmp)));
            }
            TokenOutput.ScrollToEnd();
        }
        #endregion

        #region Clear

        public void Clear()
        {
            TokenOutput.Document.Blocks.Clear();
        }
        #endregion
    }
}
Usage
Code:
CidDialog ciddiag = CidDialog.Instance;

// Optional
// ciddiag.Add(Fastboot.Instance().OEM.ReadCid());

// As window
ciddiag.Show();

// As dialog window (this will freeze the complete application until it's closed)
ciddiag.ShowDialog();

HTC-Sensation 4G (z710e)
- NanD: S-OFF
- Firmware: 3.33.401.6
- H-Boot: 1.27.1111 (juopunutbear)
- Rom: CM11 with ION and 3.0 kernel
- Recovery: 4EXT Touch & 4EXT Recovery Updater
- Battery: Anker 1900 mAh


- HTC Sensation Stock 2.3.x - 4.0.x RUUs
- HTC Sensation XE Stock 4.0.x RUUs

My Projects
- [DEV] AndroidCtrl.dll (ADB/Fastboot Mini-Framework)



My FTP links are currently down, i switch to another ISP this will take a while (7 - 21 days, starting today 10.07.2014)
 
squabbi
Old
(Last edited by squabbi; 17th June 2014 at 08:22 AM.)
#12  
squabbi's Avatar
Senior Member
Thanks Meter 835
Posts: 1,019
Join Date: Jul 2012
Location: Sydney

 
DONATE TO ME
Quote:
Originally Posted by k1ll3r8e View Post
Hey there

There are 3 and more options how u can handle this...
Thanks for clarifying! What if i want to get the identifier code? it has multiple strings? how can i choose to show all of them?

EDIT: (More questions! )

Is it possible to use:

Code:
foreach (DataModelDevicesItem device in adbDevices)
            {
                App.Current.Dispatcher.Invoke((Action)delegate
                {
                    // here goes the add command ;)
                    deviceselector.Items.Add(device);
                });
            }
            foreach (DataModelDevicesItem device in fastbootDevices)
            {
                App.Current.Dispatcher.Invoke((Action)delegate
                {
                    deviceselector.Items.Add(device);
                });
            }
to check if the device is in fastboot or adb? e.g

I press a button to flash recovery. i can have my phone in adb or fastboot and it will check to see which it is in. Then it wil lcarry out a specific command?
Check out my YouTube channel! http://www.youtube.com/maowdroid


Devices:
HTC One Mate 16GB Refurbished - Stock Telstra
 
k1ll3r8e
Old
(Last edited by k1ll3r8e; 17th June 2014 at 06:59 PM.)
#13  
Senior Member - OP
Thanks Meter 35
Posts: 102
Join Date: Mar 2011
Location: Delmenhorst

 
DONATE TO ME
Hey there

Quote:
Originally Posted by squabbi View Post
Thanks for clarifying! What if i want to get the identifier code? it has multiple strings? how can i choose to show all of them?
If u mean the HTC-Bootloader unlock code, u can use the described 2 or 3.
(Both window examples have an "foreach loop" to print out each line from the List<string> into the RichTextBox)

If u want also replace the "(bootloader) " tag u can use this line:
Code:
TokenOutput.Document.Blocks.Add(new Paragraph(new Run(tmp.Replace("(bootloader) ", ""))));
just replace it in the CS code with the one in the "foreach loop".


Quote:
Originally Posted by squabbi View Post
EDIT: (More questions! )

Is it possible to use:

Code:
foreach (DataModelDevicesItem device in adbDevices)
            {
                App.Current.Dispatcher.Invoke((Action)delegate
                {
                    // here goes the add command ;)
                    deviceselector.Items.Add(device);
                });
            }
            foreach (DataModelDevicesItem device in fastbootDevices)
            {
                App.Current.Dispatcher.Invoke((Action)delegate
                {
                    deviceselector.Items.Add(device);
                });
            }
to check if the device is in fastboot or adb? e.g
Yes, so i do it in my projects also.

Quote:
Originally Posted by squabbi View Post
I press a button to flash recovery. i can have my phone in adb or fastboot and it will check to see which it is in. Then it wil lcarry out a specific command?
For this scenario, u need a function which checks which state have the current device serial. After u have the state ADB or Fastboot, u can call 2 different methods from my dll:

ADB
Code:
// This requires Root in any case!
ADB.Instance().Device.FlashImage(IDDevicePartition partition, string localPath, bool tmpToSD = true, int timeOut = -1);
Fastboot
Code:
Fastboot.Instance().Flash(IDDevicePartition partition, string file, int timeOut = -1);
NOTE
I will build a function which will do the work in the future, next release will include it.


#EDIT:
Release it out
Code:
AndroidCtrl.Tools.General.CheckDeviceState(string deviceID);
// return is a IDDeviceState
Hope this helps

HTC-Sensation 4G (z710e)
- NanD: S-OFF
- Firmware: 3.33.401.6
- H-Boot: 1.27.1111 (juopunutbear)
- Rom: CM11 with ION and 3.0 kernel
- Recovery: 4EXT Touch & 4EXT Recovery Updater
- Battery: Anker 1900 mAh


- HTC Sensation Stock 2.3.x - 4.0.x RUUs
- HTC Sensation XE Stock 4.0.x RUUs

My Projects
- [DEV] AndroidCtrl.dll (ADB/Fastboot Mini-Framework)



My FTP links are currently down, i switch to another ISP this will take a while (7 - 21 days, starting today 10.07.2014)
The Following User Says Thank You to k1ll3r8e For This Useful Post: [ Click to Expand ]
 
squabbi
Old
#14  
squabbi's Avatar
Senior Member
Thanks Meter 835
Posts: 1,019
Join Date: Jul 2012
Location: Sydney

 
DONATE TO ME
Quote:
Originally Posted by k1ll3r8e View Post
Hey there



If u mean the HTC-Bootloader unlock code, u can use the described 2 or 3.
(Both window examples have an "foreach loop" to print out each line from the List<string> into the RichTextBox)

If u want also replace the "(bootloader) " tag u can use this line:
Code:
TokenOutput.Document.Blocks.Add(new Paragraph(new Run(tmp.Replace("(bootloader) ", ""))));
just replace it in the CS code with the one in the "foreach loop".

Yes, so i do it in my projects also.



For this scenario, u need a function which checks which state have the current device serial. After u have the state ADB or Fastboot, u can call 2 different methods from my dll:

ADB
Code:
// This requires Root in any case!
ADB.Instance().Device.FlashImage(IDDevicePartition partition, string localPath, bool tmpToSD = true, int timeOut = -1);
Fastboot
Code:
Fastboot.Instance().Flash(IDDevicePartition partition, string file, int timeOut = -1);
NOTE
I will build a function which will do the work in the future, next release will include it.


#EDIT:
Release it out
Code:
AndroidCtrl.Tools.General.CheckDeviceState(string deviceID);
// return is a IDDeviceState
Hope this helps
Hey there!

Im using this for the output:

Code:
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();
            }
            else if (state == IDDeviceState.FASTBOOT)
            {
                CidDialog ciddiag = CidDialog.Instance;
                ciddiag.Add(Fastboot.Instance().OEM.GetIdentifierToken());
                ciddiag.Show();
            }
When I first press the button the output window shows. When I close it and press the button again it gives me this error - even if I wait a couple of seconds.



Thanks for your help!
Check out my YouTube channel! http://www.youtube.com/maowdroid


Devices:
HTC One Mate 16GB Refurbished - Stock Telstra
The Following User Says Thank You to squabbi For This Useful Post: [ Click to Expand ]
 
k1ll3r8e
Old
(Last edited by k1ll3r8e; 21st June 2014 at 02:01 PM.)
#15  
Senior Member - OP
Thanks Meter 35
Posts: 102
Join Date: Mar 2011
Location: Delmenhorst

 
DONATE TO ME
Quote:
Originally Posted by squabbi View Post
Hey there!

Im using this for the output:

Code:
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();
            }
            else if (state == IDDeviceState.FASTBOOT)
            {
                CidDialog ciddiag = CidDialog.Instance;
                ciddiag.Add(Fastboot.Instance().OEM.GetIdentifierToken());
                ciddiag.Show();
            }
When I first press the button the output window shows. When I close it and press the button again it gives me this error - even if I wait a couple of seconds.

Thanks for your help!
Hey there

oh yes, that is my fault

U have to add this to ur Window constructor "CidDialog(){}"
Code:
        this.Closing += WindowClosing;

And this is the "WindowClosing method"
Code:
        #region WindowClosing

        ///<summary>
        /// Clean exit
        ///</summary>
        private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            _instance = null;
        }
        #endregion
Explain

"CidDialog.Instance" create a new instance of the window. But on close the instance will not be set to null. So u can't open it again, coz the system think it's still open.

Hope this helps

#EDIT:
I updated the examples 2 and 3 also.

HTC-Sensation 4G (z710e)
- NanD: S-OFF
- Firmware: 3.33.401.6
- H-Boot: 1.27.1111 (juopunutbear)
- Rom: CM11 with ION and 3.0 kernel
- Recovery: 4EXT Touch & 4EXT Recovery Updater
- Battery: Anker 1900 mAh


- HTC Sensation Stock 2.3.x - 4.0.x RUUs
- HTC Sensation XE Stock 4.0.x RUUs

My Projects
- [DEV] AndroidCtrl.dll (ADB/Fastboot Mini-Framework)



My FTP links are currently down, i switch to another ISP this will take a while (7 - 21 days, starting today 10.07.2014)
The Following User Says Thank You to k1ll3r8e For This Useful Post: [ Click to Expand ]
 
squabbi
Old
#16  
squabbi's Avatar
Senior Member
Thanks Meter 835
Posts: 1,019
Join Date: Jul 2012
Location: Sydney

 
DONATE TO ME
Quote:
Originally Posted by k1ll3r8e View Post
Hey there

oh yes, that is my fault

U have to add this to ur Window constructor "CidDialog(){}"
Code:
        this.Closing += WindowClosing;

And this is the "WindowClosing method"
Code:
        #region WindowClosing

        ///<summary>
        /// Clean exit
        ///</summary>
        private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            _instance = null;
        }
        #endregion
Explain

"CidDialog.Instance" create a new instance of the window. But on close the instance will not be set to null. So u can't open it again, coz the system think it's still open.

Hope this helps

#EDIT:
I updated the examples 2 and 3 also.
Thanks a lot man! Time to put everything in full motion! 😃

Sent from my HTC One_M8 using Tapatalk
Check out my YouTube channel! http://www.youtube.com/maowdroid


Devices:
HTC One Mate 16GB Refurbished - Stock Telstra
The Following User Says Thank You to squabbi For This Useful Post: [ Click to Expand ]
 
k1ll3r8e
Old
#17  
Senior Member - OP
Thanks Meter 35
Posts: 102
Join Date: Mar 2011
Location: Delmenhorst

 
DONATE TO ME
Quote:
Originally Posted by squabbi View Post
Thanks a lot man! Time to put everything in full motion! 😃

Sent from my HTC One_M8 using Tapatalk
Np dude

Good Luck!

HTC-Sensation 4G (z710e)
- NanD: S-OFF
- Firmware: 3.33.401.6
- H-Boot: 1.27.1111 (juopunutbear)
- Rom: CM11 with ION and 3.0 kernel
- Recovery: 4EXT Touch & 4EXT Recovery Updater
- Battery: Anker 1900 mAh


- HTC Sensation Stock 2.3.x - 4.0.x RUUs
- HTC Sensation XE Stock 4.0.x RUUs

My Projects
- [DEV] AndroidCtrl.dll (ADB/Fastboot Mini-Framework)



My FTP links are currently down, i switch to another ISP this will take a while (7 - 21 days, starting today 10.07.2014)

The Following User Says Thank You to k1ll3r8e For This Useful Post: [ Click to Expand ]
Tags
adb, dll, fastboot, framework
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes