63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace AndroidLauncher
|
|
{
|
|
public class AndroidADBProcess : Process
|
|
{
|
|
private static string ADB = null;
|
|
ProcessStartInfo ProcessStartInfo;
|
|
|
|
public static void SetADB(string path)
|
|
{
|
|
ADB = path;
|
|
}
|
|
|
|
public AndroidADBProcess()
|
|
{
|
|
ProcessStartInfo = new ProcessStartInfo();
|
|
ProcessStartInfo.CreateNoWindow = true;
|
|
ProcessStartInfo.RedirectStandardOutput = true;
|
|
ProcessStartInfo.RedirectStandardInput = true;
|
|
ProcessStartInfo.UseShellExecute = false;
|
|
}
|
|
|
|
public AndroidADBProcess(string args, string deviceId) : this()
|
|
{
|
|
Setup(args, deviceId);
|
|
}
|
|
|
|
public new void Kill()
|
|
{
|
|
try
|
|
{
|
|
base.Kill();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// Do nothing. If an exception is triggered then that means that the process was already finished.
|
|
}
|
|
}
|
|
|
|
public void Setup(string args, string deviceId = null)
|
|
{
|
|
if(deviceId != null)
|
|
{
|
|
args = "-s " + deviceId + " " + args;
|
|
}
|
|
|
|
ProcessStartInfo.Arguments = args;
|
|
|
|
if (ADB == null)
|
|
{
|
|
Console.WriteLine("The ADB path is not set!");
|
|
Environment.Exit(ExitCodes.AdbProblem);
|
|
}
|
|
|
|
ProcessStartInfo.FileName = ADB;
|
|
|
|
this.StartInfo = ProcessStartInfo;
|
|
}
|
|
}
|
|
|
|
}
|