diff --git a/AdbTools.sln b/AdbTools.sln new file mode 100644 index 0000000..319e4f7 --- /dev/null +++ b/AdbTools.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.34407.143 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdbTools", "AdbTools\AdbTools.csproj", "{D80557CC-6756-4A53-BE06-2A0B21224607}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D80557CC-6756-4A53-BE06-2A0B21224607}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D80557CC-6756-4A53-BE06-2A0B21224607}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D80557CC-6756-4A53-BE06-2A0B21224607}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D80557CC-6756-4A53-BE06-2A0B21224607}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3CCE653D-C7AC-497B-8A49-23884780D1EB} + EndGlobalSection +EndGlobal diff --git a/AdbTools/AdbTools.csproj b/AdbTools/AdbTools.csproj new file mode 100644 index 0000000..5404cc3 --- /dev/null +++ b/AdbTools/AdbTools.csproj @@ -0,0 +1,122 @@ + + + + + Debug + AnyCPU + {D80557CC-6756-4A53-BE06-2A0B21224607} + WinExe + AdbTools + AdbTools + v4.0 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + x64 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x64 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + app.manifest + + + AdbTools.App + + + ico.ico + + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + + + \ No newline at end of file diff --git a/AdbTools/AdbWinApi.dll b/AdbTools/AdbWinApi.dll new file mode 100644 index 0000000..c8614a9 Binary files /dev/null and b/AdbTools/AdbWinApi.dll differ diff --git a/AdbTools/AdbWinUsbApi.dll b/AdbTools/AdbWinUsbApi.dll new file mode 100644 index 0000000..1e5a8d4 Binary files /dev/null and b/AdbTools/AdbWinUsbApi.dll differ diff --git a/AdbTools/App.config b/AdbTools/App.config new file mode 100644 index 0000000..49cc43e --- /dev/null +++ b/AdbTools/App.config @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/AdbTools/App.xaml b/AdbTools/App.xaml new file mode 100644 index 0000000..cbaddb1 --- /dev/null +++ b/AdbTools/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/AdbTools/App.xaml.cs b/AdbTools/App.xaml.cs new file mode 100644 index 0000000..440f061 --- /dev/null +++ b/AdbTools/App.xaml.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Windows; + +namespace AdbTools +{ + /// + /// App.xaml 的交互逻辑 + /// + public partial class App : Application + { + } +} diff --git a/AdbTools/CmdExecutor.cs b/AdbTools/CmdExecutor.cs new file mode 100644 index 0000000..d61ec37 --- /dev/null +++ b/AdbTools/CmdExecutor.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; + +namespace AdbTools +{ + public class CmdExecutor + { + public static string ExecuteCommandAndReturn(string command) + { + using (Process process = new Process()) + { + process.StartInfo.FileName = "cmd.exe"; + process.StartInfo.RedirectStandardInput = true; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.CreateNoWindow = true; + + process.Start(); + + process.StandardInput.WriteLine(command); + process.StandardInput.WriteLine("exit"); + + process.WaitForExit(2000); + + return process.StandardOutput.ReadToEnd(); + + } + } + + public static void ExecuteCommandByShell(string command) + { + using (Process process = new Process()) + { + process.StartInfo.FileName = "cmd.exe"; + process.StartInfo.UseShellExecute = true; + process.StartInfo.CreateNoWindow = false; + process.StartInfo.Arguments = $"/c {command}"; + process.Start(); + process.WaitForExit(); + + //process.StandardInput.WriteLine(command); + } + } + + public static void ExecuteCommandAndQuit(string command) + { + using (Process process = new Process()) + { + process.StartInfo.FileName = "cmd.exe"; + process.StartInfo.RedirectStandardInput = true; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.CreateNoWindow = true; + + process.Start(); + + process.StandardInput.WriteLine(command); + process.StandardInput.WriteLine("exit"); + + process.WaitForExit(2000); + } + } + } +} diff --git a/AdbTools/Globals.cs b/AdbTools/Globals.cs new file mode 100644 index 0000000..24107a8 --- /dev/null +++ b/AdbTools/Globals.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Windows; +using System.Windows.Media; + +namespace AdbTools +{ + public class Globals + { + + + /// + /// Config配置文件读取 + /// + public class AppSettings + { + private static string _LAST_DEVICE_ADDRESS = null; + private static List _DEVICE_ADDRESS_HISTORY = null; + /// + /// + /// + public static string LAST_DEVICE_ADDRESS + { + get + { + if (null == _LAST_DEVICE_ADDRESS) + { + _LAST_DEVICE_ADDRESS = GetKeyVlaue("LAST_DEVICE_ADDRESS"); + } + if (null == _LAST_DEVICE_ADDRESS) + { + _LAST_DEVICE_ADDRESS = ""; + } + return _LAST_DEVICE_ADDRESS; + } + set + { + UpdateAppConfig("LAST_DEVICE_ADDRESS", value); + _LAST_DEVICE_ADDRESS = value; + } + } + + /// + /// + /// + public static List DEVICE_ADDRESS_HISTORY + { + get + { + if (null == _DEVICE_ADDRESS_HISTORY) + { + string v = GetKeyVlaue("DEVICE_ADDRESS_HISTORY"); + if (!string.IsNullOrWhiteSpace(v)) + { + _DEVICE_ADDRESS_HISTORY = new List(v.Split(',')); + + } + } + if (null == _DEVICE_ADDRESS_HISTORY) + { + _DEVICE_ADDRESS_HISTORY = new List(); + } + return _DEVICE_ADDRESS_HISTORY; + } + set + { + UpdateAppConfig("DEVICE_ADDRESS_HISTORY", string.Join(",", value)); + _DEVICE_ADDRESS_HISTORY = value; + } + } + + /// + /// 获取配置的值 + /// + /// key + /// 读取错误时为null + public static string GetKeyVlaue(string key) + { + try + { + return ConfigurationManager.AppSettings[key]; + } + catch (Exception e) + { + return null; + } + } + + /// + ///在*.exe.config文件中appSettings配置节增加一对键、值对 + /// + /// + /// + public static void UpdateAppConfig(string newKey, string newValue) + { + try + { + bool isModified = false; + foreach (string key in ConfigurationManager.AppSettings) + { + if (key == newKey) + { + isModified = true; + } + } + + // Open App.Config of executable + Configuration config = + ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); + // You need to remove the old settings object before you can replace it + if (isModified) + { + config.AppSettings.Settings.Remove(newKey); + } + // Add an Application Setting. + config.AppSettings.Settings.Add(newKey, newValue); + // Save the changes in App.config file. + config.Save(ConfigurationSaveMode.Modified); + // Force a reload of a changed section. + ConfigurationManager.RefreshSection("appSettings"); + } + catch (Exception e) + { + } + } + + } + + + + + } +} diff --git a/AdbTools/MainWindow.xaml b/AdbTools/MainWindow.xaml new file mode 100644 index 0000000..2db950e --- /dev/null +++ b/AdbTools/MainWindow.xaml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + +