Skip to content

Commit

Permalink
初始化导入
Browse files Browse the repository at this point in the history
  • Loading branch information
MaisonWan committed Jul 23, 2016
1 parent 2c9dfa7 commit 7a909fb
Show file tree
Hide file tree
Showing 21 changed files with 1,625 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.exe

# Folder
bin/
obj/

# Generated files
20 changes: 20 additions & 0 deletions KibotController.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KibotController", "KibotController\KibotController.csproj", "{A141CC1F-ECCA-4900-84BD-B9707E78A1EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A141CC1F-ECCA-4900-84BD-B9707E78A1EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A141CC1F-ECCA-4900-84BD-B9707E78A1EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A141CC1F-ECCA-4900-84BD-B9707E78A1EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A141CC1F-ECCA-4900-84BD-B9707E78A1EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added KibotController.v11.suo
Binary file not shown.
127 changes: 127 additions & 0 deletions KibotController/AdbConnect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;

namespace KibotController
{
public class AdbConnect : IConnect
{
private Log log = null;
private Process p = null;

public AdbConnect(Log log)
{
this.log = log;
p = new Process();
}

/// <summary>
///
/// </summary>
/// <param name="keyCode"></param>
/// <returns></returns>
public bool InputKey(int keyCode)
{
string cmd = "shell input keyevent " + keyCode;
string result = executeAdb(cmd);
log.Write(result);
return true;
}

/// <summary>
/// 输入文本
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public bool InputText(string text)
{
if (text == "")
{
return false;
}
string cmd = String.Format("shell input text \"{0}\"", text);
string result = executeAdb(cmd);
log.Write("发送\"" + text + "\"成功");
return true;
}

/// <summary>
/// 执行命令
/// </summary>
/// <param name="cmd"></param>
/// <returns></returns>
public bool InputCommand(string cmd)
{
string result = executeAdb(cmd);
log.Write(result);
return true;
}

/// <summary>
/// 获取截图并且回传到本地
/// </summary>
/// <param name="localPath"></param>
/// <returns></returns>
public bool GetScreenShot(string localPath)
{
string cmdshot = "shell /system/bin/screencap -p /sdcard/screenshot.png";
string pullFile = "pull /sdcard/screenshot.png \"" + localPath + "\"";
File.Delete(localPath);
executeAdb(cmdshot);
executeAdb(pullFile);
if (File.Exists(localPath))
{
log.Write("获取屏幕截图成功");
return true;
}
return false;
}

/// <summary>
/// 安装本地apk
/// </summary>
/// <param name="apkPath">apk路径</param>
/// <returns></returns>
public bool Install(string apkPath)
{
string cmd = String.Format("install -r \"{0}\"", apkPath);
string result = executeAdb(cmd);
log.Write(result);
if (result.Contains("Success"))
{
return true;
}
return false;
}

/// <summary>
/// 卸载程序包名
/// </summary>
/// <param name="packageName"></param>
/// <returns></returns>
public bool Uninstall(string packageName)
{
string cmd = "uninstall " + packageName;
string result = executeAdb(cmd);
log.Write(result);
return false;
}

private string executeAdb(string cmd)
{
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "./adb/adb.exe";
p.StartInfo.Arguments = cmd;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string outStr = p.StandardOutput.ReadToEnd();
p.Close();
return outStr;
}
}
}
Loading

0 comments on commit 7a909fb

Please sign in to comment.