├── Screenshot.png ├── app.config ├── README.md ├── Properties ├── Settings.settings ├── Settings.Designer.cs ├── AssemblyInfo.cs ├── Resources.Designer.cs └── Resources.resx ├── ADBConsole.csproj.user ├── Program.cs ├── ADBConsole.sln ├── ADBConsole.csproj ├── ADBParser.cs ├── Form1.resx ├── Form1.Designer.cs └── Form1.cs /Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FredericGuo/ADBConsole/HEAD/Screenshot.png -------------------------------------------------------------------------------- /app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ADBConsole 2 | ========== 3 | 4 | A C# app to receive, save and load the message from adb console. 5 | 6 | The app is created to ease the Android development and testing. The logcat in Eclipse does not work very well. 7 | -------------------------------------------------------------------------------- /Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ADBConsole.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | en-US 11 | false 12 | 13 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | 5 | namespace ADBConsole 6 | { 7 | static class Program 8 | { 9 | /// 10 | /// The main entry point for the application. 11 | /// 12 | [STAThread] 13 | static void Main() 14 | { 15 | Application.EnableVisualStyles(); 16 | Application.SetCompatibleTextRenderingDefault(false); 17 | Application.Run(new Form1()); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /ADBConsole.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ADBConsole", "ADBConsole.csproj", "{1B0458DA-814A-40AF-89EF-C3533528EE1B}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {1B0458DA-814A-40AF-89EF-C3533528EE1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {1B0458DA-814A-40AF-89EF-C3533528EE1B}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {1B0458DA-814A-40AF-89EF-C3533528EE1B}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {1B0458DA-814A-40AF-89EF-C3533528EE1B}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.18063 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ADBConsole.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ADBConsole")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("ADBConsole")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2014")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1f91386c-7cc7-4ef8-87d9-19cc53e9197c")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.18063 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ADBConsole.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ADBConsole.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ADBConsole.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.50727 7 | 2.0 8 | {1B0458DA-814A-40AF-89EF-C3533528EE1B} 9 | WinExe 10 | Properties 11 | ADBConsole 12 | ADBConsole 13 | v4.0 14 | 15 | 16 | 17 | 18 | 2.0 19 | 20 | publish\ 21 | true 22 | Disk 23 | false 24 | Foreground 25 | 7 26 | Days 27 | false 28 | false 29 | true 30 | 0 31 | 1.0.0.%2a 32 | false 33 | false 34 | true 35 | 36 | 37 | true 38 | full 39 | false 40 | bin\Debug\ 41 | DEBUG;TRACE 42 | prompt 43 | 4 44 | 45 | 46 | pdbonly 47 | true 48 | bin\Release\ 49 | TRACE 50 | prompt 51 | 4 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | Code 64 | 65 | 66 | Form 67 | 68 | 69 | Form1.cs 70 | 71 | 72 | 73 | 74 | Designer 75 | Form1.cs 76 | 77 | 78 | ResXFileCodeGenerator 79 | Resources.Designer.cs 80 | Designer 81 | 82 | 83 | True 84 | Resources.resx 85 | True 86 | 87 | 88 | 89 | SettingsSingleFileGenerator 90 | Settings.Designer.cs 91 | 92 | 93 | True 94 | Settings.settings 95 | True 96 | 97 | 98 | 99 | 100 | False 101 | .NET Framework 3.5 SP1 Client Profile 102 | false 103 | 104 | 105 | False 106 | .NET Framework 3.5 SP1 107 | true 108 | 109 | 110 | False 111 | Windows Installer 3.1 112 | true 113 | 114 | 115 | 116 | 123 | -------------------------------------------------------------------------------- /Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /ADBParser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.IO; //for Streams 6 | using System.Diagnostics; //for Process 7 | using System.Threading; //to run commands concurrently 8 | using System.Runtime.InteropServices; 9 | 10 | namespace ADBConsole 11 | { 12 | class ADBAccess 13 | { 14 | Process processCmd; 15 | 16 | Thread CMDThread; 17 | 18 | bool m_bCMDWriting; 19 | bool m_bWinWriting; 20 | 21 | Queue m_CMDOutputQueue; 22 | Queue m_CMDOutputQueueReader; 23 | Queue m_CMDOutputQueueWriter; 24 | 25 | Queue m_WinOutputQueueReader; 26 | 27 | public Queue WinOutputQueueReader 28 | { 29 | set { m_WinOutputQueueReader = value; } 30 | } 31 | 32 | public string CMDOutputDequeue() 33 | { 34 | if (0 == m_CMDOutputQueueReader.Count) 35 | { 36 | throw new System.Exception("CMDOutputDequeue 0 size."); 37 | } 38 | 39 | return m_CMDOutputQueueReader.Dequeue().ToString(); 40 | } 41 | 42 | public bool isCMDOutputQueueEmpty() 43 | { 44 | return 0 == m_CMDOutputQueueReader.Count; 45 | } 46 | 47 | public ADBAccess() 48 | { 49 | m_bCMDWriting = false; 50 | m_bWinWriting = false; 51 | 52 | processCmd = null; 53 | 54 | m_CMDOutputQueue = new Queue(); 55 | m_CMDOutputQueueReader = Queue.Synchronized(m_CMDOutputQueue); 56 | m_CMDOutputQueueWriter = Queue.Synchronized(m_CMDOutputQueue); 57 | 58 | m_WinOutputQueueReader = null; 59 | 60 | string errorStr; 61 | 62 | CMDThread = new Thread(new ThreadStart(RunCMD)); 63 | } 64 | 65 | public void StartCMD() 66 | { 67 | if (CMDThread.ThreadState == System.Threading.ThreadState.Unstarted) 68 | { 69 | CMDThread.Start(); 70 | } 71 | } 72 | 73 | private void RunCMD() 74 | { 75 | StringBuilder strInputCMD = new StringBuilder(); 76 | processCmd = new Process(); 77 | processCmd.StartInfo.FileName = "cmd.exe"; 78 | processCmd.StartInfo.CreateNoWindow = true; 79 | processCmd.StartInfo.UseShellExecute = false; 80 | processCmd.StartInfo.RedirectStandardOutput = true; 81 | processCmd.StartInfo.RedirectStandardInput = true; 82 | processCmd.StartInfo.RedirectStandardError = true; 83 | processCmd.OutputDataReceived += new DataReceivedEventHandler(CmdOutputDataHandler); 84 | processCmd.ErrorDataReceived += new DataReceivedEventHandler(CmdErrorDataHandler); 85 | processCmd.Start(); 86 | processCmd.BeginOutputReadLine(); 87 | 88 | while (true) 89 | { 90 | try 91 | { 92 | if (m_bWinWriting) //don't read/write concurrently 93 | continue; 94 | 95 | if (0 < m_WinOutputQueueReader.Count) 96 | { 97 | strInputCMD.Append(m_WinOutputQueueReader.Dequeue()); 98 | strInputCMD.Append("\n"); 99 | processCmd.StandardInput.WriteLine(strInputCMD); 100 | strInputCMD.Remove(0, strInputCMD.Length); 101 | } 102 | System.Threading.Thread.Sleep(400); 103 | } 104 | catch (Exception err) 105 | { 106 | Console.WriteLine("Stop CMD thread." + err.Message); 107 | Cleanup(); 108 | break; 109 | } 110 | } 111 | } 112 | 113 | public void Exit() 114 | { 115 | if ( processCmd != null && !processCmd.HasExited) 116 | { 117 | try { 118 | processCmd.Kill(); 119 | } 120 | catch (Exception err) 121 | { 122 | Console.WriteLine("Cleanup exception: " + err.Message); 123 | }; 124 | } 125 | } 126 | 127 | private void CmdOutputDataHandler(object sendingProcess, DataReceivedEventArgs outLine) 128 | { 129 | if(!String.IsNullOrEmpty(outLine.Data)) 130 | { 131 | try 132 | { 133 | m_bCMDWriting = true; 134 | m_CMDOutputQueueWriter.Enqueue(outLine.Data); 135 | m_bCMDWriting = false; 136 | } 137 | catch (Exception err) 138 | { 139 | Console.WriteLine("CMD Thread Exception: " + err.Message); 140 | } 141 | } 142 | } 143 | 144 | private void CmdErrorDataHandler(object sendingProcess, DataReceivedEventArgs outLine) 145 | { 146 | if (!String.IsNullOrEmpty(outLine.Data)) 147 | { 148 | try 149 | { 150 | Console.WriteLine("CMD Error: " + outLine.Data); 151 | } 152 | catch (Exception err) 153 | { 154 | Console.WriteLine("CMD Error Handler Exception: " + err.Message); 155 | } 156 | 157 | } 158 | } 159 | 160 | private void Cleanup() 161 | { 162 | try { processCmd.Kill(); } 163 | catch (Exception err) 164 | { 165 | Console.WriteLine("Cleanup exception: " + err.Message); 166 | }; 167 | 168 | m_CMDOutputQueue.Clear(); 169 | } 170 | } 171 | } 172 | -------------------------------------------------------------------------------- /Form1.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace ADBConsole 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.splitContainer1 = new System.Windows.Forms.SplitContainer(); 32 | this.consoleBox = new System.Windows.Forms.ListView(); 33 | this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 34 | this.groupBox1 = new System.Windows.Forms.GroupBox(); 35 | this.label1 = new System.Windows.Forms.Label(); 36 | this.TagNameBox = new System.Windows.Forms.TextBox(); 37 | this.TagEnable = new System.Windows.Forms.CheckBox(); 38 | this.fileLocationMsg = new System.Windows.Forms.Label(); 39 | this.ExitBtn = new System.Windows.Forms.Button(); 40 | this.ADBStopBtn = new System.Windows.Forms.Button(); 41 | this.ADBStartBtn = new System.Windows.Forms.Button(); 42 | ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); 43 | this.splitContainer1.Panel1.SuspendLayout(); 44 | this.splitContainer1.Panel2.SuspendLayout(); 45 | this.splitContainer1.SuspendLayout(); 46 | this.groupBox1.SuspendLayout(); 47 | this.SuspendLayout(); 48 | // 49 | // splitContainer1 50 | // 51 | this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; 52 | this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel2; 53 | this.splitContainer1.Location = new System.Drawing.Point(0, 0); 54 | this.splitContainer1.Name = "splitContainer1"; 55 | this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal; 56 | // 57 | // splitContainer1.Panel1 58 | // 59 | this.splitContainer1.Panel1.Controls.Add(this.consoleBox); 60 | // 61 | // splitContainer1.Panel2 62 | // 63 | this.splitContainer1.Panel2.Controls.Add(this.groupBox1); 64 | this.splitContainer1.Panel2.Controls.Add(this.fileLocationMsg); 65 | this.splitContainer1.Panel2.Controls.Add(this.ExitBtn); 66 | this.splitContainer1.Panel2.Controls.Add(this.ADBStopBtn); 67 | this.splitContainer1.Panel2.Controls.Add(this.ADBStartBtn); 68 | this.splitContainer1.Size = new System.Drawing.Size(1041, 506); 69 | this.splitContainer1.SplitterDistance = 440; 70 | this.splitContainer1.SplitterWidth = 1; 71 | this.splitContainer1.TabIndex = 0; 72 | // 73 | // consoleBox 74 | // 75 | this.consoleBox.BackColor = System.Drawing.Color.Black; 76 | this.consoleBox.BorderStyle = System.Windows.Forms.BorderStyle.None; 77 | this.consoleBox.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 78 | this.columnHeader1}); 79 | this.consoleBox.Dock = System.Windows.Forms.DockStyle.Fill; 80 | this.consoleBox.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; 81 | this.consoleBox.Location = new System.Drawing.Point(0, 0); 82 | this.consoleBox.MultiSelect = false; 83 | this.consoleBox.Name = "consoleBox"; 84 | this.consoleBox.Size = new System.Drawing.Size(1041, 440); 85 | this.consoleBox.TabIndex = 0; 86 | this.consoleBox.UseCompatibleStateImageBehavior = false; 87 | this.consoleBox.View = System.Windows.Forms.View.Details; 88 | this.consoleBox.VirtualMode = true; 89 | this.consoleBox.RetrieveVirtualItem += new System.Windows.Forms.RetrieveVirtualItemEventHandler(this.consoleBox_RetrieveVirtualItem); 90 | // 91 | // columnHeader1 92 | // 93 | this.columnHeader1.Width = 200; 94 | // 95 | // groupBox1 96 | // 97 | this.groupBox1.Controls.Add(this.label1); 98 | this.groupBox1.Controls.Add(this.TagNameBox); 99 | this.groupBox1.Controls.Add(this.TagEnable); 100 | this.groupBox1.Location = new System.Drawing.Point(127, 3); 101 | this.groupBox1.Name = "groupBox1"; 102 | this.groupBox1.Size = new System.Drawing.Size(398, 59); 103 | this.groupBox1.TabIndex = 6; 104 | this.groupBox1.TabStop = false; 105 | // 106 | // label1 107 | // 108 | this.label1.AutoSize = true; 109 | this.label1.Location = new System.Drawing.Point(29, 35); 110 | this.label1.Name = "label1"; 111 | this.label1.Size = new System.Drawing.Size(63, 13); 112 | this.label1.TabIndex = 6; 113 | this.label1.Text = "Tag Name :"; 114 | // 115 | // TagNameBox 116 | // 117 | this.TagNameBox.Location = new System.Drawing.Point(98, 33); 118 | this.TagNameBox.MaxLength = 40; 119 | this.TagNameBox.Name = "TagNameBox"; 120 | this.TagNameBox.Size = new System.Drawing.Size(284, 20); 121 | this.TagNameBox.TabIndex = 5; 122 | // 123 | // TagEnable 124 | // 125 | this.TagEnable.AutoSize = true; 126 | this.TagEnable.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; 127 | this.TagEnable.Location = new System.Drawing.Point(4, 12); 128 | this.TagEnable.Margin = new System.Windows.Forms.Padding(1); 129 | this.TagEnable.Name = "TagEnable"; 130 | this.TagEnable.Size = new System.Drawing.Size(109, 17); 131 | this.TagEnable.TabIndex = 4; 132 | this.TagEnable.Text = "Enable Tag filter :"; 133 | this.TagEnable.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 134 | this.TagEnable.UseVisualStyleBackColor = true; 135 | this.TagEnable.CheckedChanged += new System.EventHandler(this.TagEnable_CheckedChanged); 136 | // 137 | // fileLocationMsg 138 | // 139 | this.fileLocationMsg.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 140 | this.fileLocationMsg.Location = new System.Drawing.Point(531, 22); 141 | this.fileLocationMsg.Name = "fileLocationMsg"; 142 | this.fileLocationMsg.Size = new System.Drawing.Size(296, 17); 143 | this.fileLocationMsg.TabIndex = 3; 144 | this.fileLocationMsg.Text = "The log file is saved at : .\\AdbMessage.log"; 145 | // 146 | // ExitBtn 147 | // 148 | this.ExitBtn.Location = new System.Drawing.Point(12, 7); 149 | this.ExitBtn.Name = "ExitBtn"; 150 | this.ExitBtn.Size = new System.Drawing.Size(84, 44); 151 | this.ExitBtn.TabIndex = 2; 152 | this.ExitBtn.Text = "Exit"; 153 | this.ExitBtn.UseVisualStyleBackColor = true; 154 | this.ExitBtn.Click += new System.EventHandler(this.ExitBtn_Click); 155 | // 156 | // ADBStopBtn 157 | // 158 | this.ADBStopBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 159 | this.ADBStopBtn.Location = new System.Drawing.Point(945, 7); 160 | this.ADBStopBtn.Name = "ADBStopBtn"; 161 | this.ADBStopBtn.Size = new System.Drawing.Size(84, 44); 162 | this.ADBStopBtn.TabIndex = 1; 163 | this.ADBStopBtn.Text = "Pause"; 164 | this.ADBStopBtn.UseVisualStyleBackColor = true; 165 | this.ADBStopBtn.Click += new System.EventHandler(this.ADBStopBtn_Click); 166 | // 167 | // ADBStartBtn 168 | // 169 | this.ADBStartBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 170 | this.ADBStartBtn.Location = new System.Drawing.Point(845, 9); 171 | this.ADBStartBtn.Name = "ADBStartBtn"; 172 | this.ADBStartBtn.Size = new System.Drawing.Size(84, 44); 173 | this.ADBStartBtn.TabIndex = 0; 174 | this.ADBStartBtn.Text = "Start/Resume"; 175 | this.ADBStartBtn.UseVisualStyleBackColor = true; 176 | this.ADBStartBtn.Click += new System.EventHandler(this.ADBStartBtn_Click); 177 | // 178 | // Form1 179 | // 180 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 181 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 182 | this.ClientSize = new System.Drawing.Size(1041, 506); 183 | this.ControlBox = false; 184 | this.Controls.Add(this.splitContainer1); 185 | this.Name = "Form1"; 186 | this.Text = "adb console"; 187 | this.Load += new System.EventHandler(this.Form1_Load); 188 | this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged); 189 | this.splitContainer1.Panel1.ResumeLayout(false); 190 | this.splitContainer1.Panel2.ResumeLayout(false); 191 | ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); 192 | this.splitContainer1.ResumeLayout(false); 193 | this.groupBox1.ResumeLayout(false); 194 | this.groupBox1.PerformLayout(); 195 | this.ResumeLayout(false); 196 | 197 | } 198 | 199 | #endregion 200 | 201 | private System.Windows.Forms.SplitContainer splitContainer1; 202 | private System.Windows.Forms.Button ADBStopBtn; 203 | private System.Windows.Forms.Button ADBStartBtn; 204 | private System.Windows.Forms.Button ExitBtn; 205 | private System.Windows.Forms.Label fileLocationMsg; 206 | private System.Windows.Forms.GroupBox groupBox1; 207 | private System.Windows.Forms.Label label1; 208 | private System.Windows.Forms.TextBox TagNameBox; 209 | private System.Windows.Forms.CheckBox TagEnable; 210 | private System.Windows.Forms.ListView consoleBox; 211 | private System.Windows.Forms.ColumnHeader columnHeader1; 212 | } 213 | } 214 | 215 | -------------------------------------------------------------------------------- /Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | //using System.Collections.Generic; 3 | using System.Collections; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Drawing; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using System.Threading; //to run commands concurrently 10 | using System.Text.RegularExpressions; 11 | using System.Collections.Generic; 12 | using System.Diagnostics; 13 | 14 | namespace ADBConsole 15 | { 16 | public partial class Form1 : Form 17 | { 18 | bool bTest; 19 | 20 | Thread m_adbListenThread; 21 | Queue adbOutputQueue; 22 | ADBAccess m_ADBAccess; 23 | bool m_bSuspendLogout; 24 | System.IO.StreamWriter m_logFile; 25 | 26 | String m_tagFilter; 27 | Boolean m_tagFilterEnabled; 28 | 29 | const int maxLines = 100000; 30 | List m_logList; 31 | 32 | bool m_bCMDQueuing; 33 | 34 | //This queue contains ADB commands. 35 | //Reader is for dequeue the request CMD by ADBAccess 36 | //Writer is for enqueue new CMD by this Form1 class. 37 | Queue m_ADBCommandQueue; 38 | Queue m_ADBCommandQueueReader; 39 | Queue m_ADBCommandQueueWriter; 40 | 41 | private void StartADBThread() 42 | { 43 | m_adbListenThread = new Thread(new ThreadStart(StartListen)); 44 | m_adbListenThread.Start(); 45 | } 46 | 47 | public Form1() 48 | { 49 | InitializeComponent(); 50 | 51 | m_logList = new List(5); 52 | 53 | m_bCMDQueuing = false; 54 | m_adbListenThread = null; 55 | bTest = true; 56 | m_tagFilter = ""; 57 | m_tagFilterEnabled = false; 58 | 59 | String FILE_NAME = "AdbMessage"; 60 | int suffix = 1; 61 | 62 | String fileName = @".\" + FILE_NAME + ".log"; 63 | while( System.IO.File.Exists( fileName)) 64 | { 65 | fileName = @".\" + FILE_NAME + suffix.ToString() + ".log"; 66 | ++suffix; 67 | } 68 | 69 | fileLocationMsg.Text = @"The log file is saved at : " + fileName; 70 | m_logFile = new System.IO.StreamWriter( fileName ); 71 | 72 | m_ADBCommandQueue = new Queue(); 73 | m_ADBCommandQueueReader = Queue.Synchronized(m_ADBCommandQueue); 74 | m_ADBCommandQueueWriter = Queue.Synchronized(m_ADBCommandQueue); 75 | 76 | m_ADBAccess = new ADBAccess(); 77 | m_ADBAccess.WinOutputQueueReader = m_ADBCommandQueueReader; 78 | } 79 | 80 | private void StartListen() 81 | { 82 | adbOutputQueue = new Queue(1000,2); 83 | 84 | while (true) 85 | { 86 | try 87 | { 88 | if (!m_ADBAccess.isCMDOutputQueueEmpty()) 89 | { 90 | adbOutputQueue.Enqueue(m_ADBAccess.CMDOutputDequeue() + "\r\n"); 91 | } 92 | 93 | Application.DoEvents(); 94 | 95 | if (0 == adbOutputQueue.Count) 96 | { 97 | //only flush at idle time 98 | m_logFile.Flush(); 99 | //only sleep when there is no string in the queue. 100 | System.Threading.Thread.Sleep(2); 101 | } 102 | else 103 | { 104 | if ( !m_bSuspendLogout ) 105 | { 106 | DisplayMessage(adbOutputQueue.Dequeue().ToString()); 107 | } 108 | } 109 | } 110 | catch (Exception err) 111 | { 112 | Console.WriteLine("WinListen Thread Exception: " + err.Message); 113 | //Cleanup(); 114 | break; 115 | } 116 | } 117 | } 118 | 119 | private delegate void DisplayDelegate(string message); 120 | private void DisplayMessage(string message) 121 | { 122 | if (consoleBox.InvokeRequired) 123 | { 124 | Invoke(new DisplayDelegate(DisplayMessage), new object[] { message }); 125 | } 126 | else 127 | { 128 | m_logList.Add(message); 129 | m_logFile.Write(message); 130 | this.consoleBox.VirtualListSize = m_logList.Count; 131 | 132 | int delta = 100; //to improve performance, delete 100 lines each time 133 | if ( m_logList.Count > maxLines + delta) 134 | { 135 | Console.WriteLine(" >>>>>>>>>>>>>>> delete "); 136 | m_logList.RemoveRange(m_logList.Count - 100, 100); 137 | } 138 | 139 | consoleBox.Items[m_logList.Count-1].EnsureVisible(); 140 | } 141 | } 142 | 143 | private void ADBStartBtn_Click(object sender, EventArgs e) 144 | { 145 | if (null == m_adbListenThread) 146 | { 147 | StartADBThread(); 148 | System.Threading.Thread.Sleep(100); 149 | m_ADBAccess.StartCMD(); 150 | System.Threading.Thread.Sleep(200); 151 | 152 | { 153 | string ADBCMD; 154 | ADBCMD = "adb logcat -c"; 155 | m_bCMDQueuing = true; 156 | m_ADBCommandQueueWriter.Enqueue(ADBCMD); 157 | ADBCMD = "adb logcat -v time"; 158 | m_ADBCommandQueueWriter.Enqueue(ADBCMD); 159 | m_bCMDQueuing = false; 160 | } 161 | } 162 | else 163 | { 164 | m_bSuspendLogout = false; 165 | } 166 | } 167 | 168 | private void ADBStopBtn_Click(object sender, EventArgs e) 169 | { 170 | m_bSuspendLogout = true; 171 | } 172 | 173 | private void Cleanup() 174 | { 175 | m_logFile.Close(); 176 | m_ADBCommandQueue.Clear(); 177 | } 178 | 179 | private void ExitBtn_Click(object sender, EventArgs e) 180 | { 181 | m_ADBAccess.Exit(); 182 | Cleanup(); 183 | System.Environment.Exit(System.Environment.ExitCode); 184 | } 185 | 186 | private void TagEnable_CheckedChanged(object sender, EventArgs e) 187 | { 188 | if (CheckState.Checked == this.TagEnable.CheckState) 189 | { 190 | m_tagFilter = TagNameBox.Text.ToUpper(); 191 | m_tagFilterEnabled = true; 192 | TagNameBox.Enabled = false; 193 | } 194 | else 195 | { 196 | m_tagFilterEnabled = false; 197 | m_tagFilter = ""; 198 | TagNameBox.Enabled = true; 199 | } 200 | } 201 | 202 | private void consoleBox_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e) 203 | { 204 | int itemIndex = e.ItemIndex; 205 | Color itemTextColor = Color.White; 206 | Color itemBackgroundColor = Color.Black; 207 | 208 | if( itemIndex >= m_logList.Count ) 209 | { 210 | Console.WriteLine( "Error : consoleBox_RetrieveVirtualItem() : invalid itemIndex."); 211 | Debug.Assert(false); 212 | return; 213 | } 214 | 215 | String message = m_logList[itemIndex]; 216 | 217 | try 218 | { 219 | string pattern = @"[VIDWEF][/](\w|[-.:])+\s*[(]\s*\d+[)]"; 220 | Match match = Regex.Match(message, pattern); 221 | if (match.Success) 222 | { 223 | if (m_tagFilterEnabled) 224 | { 225 | int startBracket = match.Value.IndexOf('('); 226 | if (2 <= startBracket) 227 | { 228 | string tagName = match.Value.Substring(2, startBracket - 2); 229 | 230 | //not necessary/right, just easy the debugger 231 | tagName.Trim(); 232 | tagName = tagName.ToUpper(); 233 | 234 | if (0 < tagName.Length) 235 | { 236 | if (tagName.Equals(m_tagFilter)) 237 | { 238 | itemBackgroundColor = Color.SlateGray; 239 | } 240 | } 241 | } 242 | } 243 | else 244 | { 245 | //consoleBox.SelectionBackColor = Color.SlateGray; 246 | } 247 | 248 | char tagLevel = match.Value[0]; 249 | 250 | switch (tagLevel) 251 | { 252 | case 'I': 253 | case 'V': 254 | { 255 | itemTextColor = Color.LightGreen; 256 | break; 257 | } 258 | case 'D': 259 | { 260 | itemTextColor = Color.DeepSkyBlue; 261 | break; 262 | } 263 | case 'W': 264 | { 265 | itemTextColor = Color.LightSalmon; 266 | break; 267 | } 268 | case 'E': 269 | case 'F': 270 | { 271 | itemTextColor = Color.Tomato; 272 | break; 273 | } 274 | default: 275 | { 276 | itemTextColor = Color.White; //should not go here 277 | break; 278 | } 279 | } 280 | } 281 | } 282 | catch (Exception) 283 | { 284 | Console.WriteLine("Exception from Regex"); 285 | } 286 | 287 | /* 288 | if (bTest) 289 | { 290 | consoleBox.AppendText(message); 291 | m_logFile.Write(message); 292 | }*/ 293 | 294 | ListViewItem lvi = new ListViewItem(); 295 | lvi.Text = message; 296 | lvi.BackColor = itemBackgroundColor; 297 | lvi.ForeColor = itemTextColor; 298 | e.Item = lvi; 299 | } 300 | 301 | private void Form1_SizeChanged(object sender, EventArgs e) 302 | { 303 | Control control = (Control)sender; 304 | if( control.Width != this.consoleBox.Columns[0].Width - 25 ) 305 | { 306 | this.consoleBox.Columns[0].Width = control.Width - 25; 307 | } 308 | } 309 | 310 | private void Form1_Load(object sender, EventArgs e) 311 | { 312 | this.consoleBox.VirtualMode = true; 313 | this.consoleBox.VirtualListSize = m_logList.Count; 314 | this.consoleBox.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; 315 | this.consoleBox.Columns[0].Width = this.Width - 25; 316 | 317 | //use double buffer to improve performance 318 | System.Reflection.PropertyInfo aProp = typeof(ListView).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 319 | aProp.SetValue(consoleBox, true, null); 320 | } 321 | } 322 | } --------------------------------------------------------------------------------