public string CurrentDevice() { DeviseAddr addr = new DeviseAddr(); string sDev = string.Empty; if (!string.IsNullOrEmpty(addr.ConnectionType) && addr.ConnectionType.Equals("usb") && !string.IsNullOrEmpty(addr.UsbDevice)) { sDev = addr.UsbDevice; } else { sDev = addr.ToString(); } return(sDev); }
public bool LaunchProcess(string args, CommandDialog cd, bool bShowProgress = false, string sDestination = "") { try { strMessage = string.Empty; Process build = new Process(); Thread thDialog = null; if (bShowProgress) { if (cd == CommandDialog.Copy) { if (pf == null) { pf = new ProgressForm(); } pf.SetProcess(build); pf.SetProgress(string.Empty, 0, sDestination); thDialog = new Thread(() => ThreadProcCopy()); thDialog.Start(); } else if (cd == CommandDialog.Connect) { if (cf == null) { cf = new ConnectForm(); } DeviseAddr addr = new DeviseAddr(); if (!string.IsNullOrEmpty(addr.ConnectionType) && addr.ConnectionType.Equals("usb") && !string.IsNullOrEmpty(addr.UsbDevice)) { cf.SetIP(addr.UsbDevice); } else { cf.SetIP(addr.ToString()); } thDialog = new Thread(() => ThreadProcConnect()); thDialog.Start(); } else if (cd == CommandDialog.CreateScreenShot) { if (of == null) { of = new OperationForm(OperationForm.TypeOp.CreateScreenShot); } of.SetOperation("Creating ScreenShot"); thDialog = new Thread(() => ThreadProcOperation()); thDialog.Start(); } else if (cd == CommandDialog.Install) { if (of == null) { of = new OperationForm(OperationForm.TypeOp.Install); } of.SetOperation("Install " + args.Substring(args.LastIndexOf("\\") + 1).TrimEnd('\"')); thDialog = new Thread(() => ThreadProcOperation()); thDialog.Start(); } else if (cd == CommandDialog.Delete) { if (of == null) { of = new OperationForm(OperationForm.TypeOp.Delete); } of.SetOperation("Deleting"); thDialog = new Thread(() => ThreadProcOperation()); thDialog.Start(); } } build.StartInfo.WorkingDirectory = Path.GetDirectoryName(FindADB()); if (string.IsNullOrEmpty(build.StartInfo.WorkingDirectory)) { if (bShowProgress && pf != null) { pf.SetProgress(string.Empty, 0); pf.InternalCloseDialog(); pf = null; } if (bShowProgress && cf != null) { cf.InternalCloseDialog(); cf = null; } if (bShowProgress && of != null) { of.InternalCloseDialog(); of = null; } strMessage = "Can not find adb.exe"; return(false); } build.StartInfo.FileName = FindADB(); build.StartInfo.Arguments = args; build.StartInfo.UseShellExecute = false; build.StartInfo.RedirectStandardOutput = true; build.StartInfo.RedirectStandardError = true; build.StartInfo.CreateNoWindow = true; build.ErrorDataReceived += build_ErrorDataReceived; build.OutputDataReceived += build_ErrorDataReceived; build.EnableRaisingEvents = true; build.Start(); build.BeginOutputReadLine(); build.BeginErrorReadLine(); build.WaitForExit(); if (bShowProgress) { if (cd == CommandDialog.Copy) { if (build.ExitCode < 0) { if (!string.IsNullOrEmpty(sDestination)) { if (File.Exists(sDestination)) { File.Delete(sDestination); } else if (Directory.Exists(sDestination)) { //Directory.Delete(sDestination, true); } } } if (pf != null) { pf.SetProgress(string.Empty, 0); pf.InternalCloseDialog(); pf = null; } } else if (cd == CommandDialog.Connect) { cf.InternalCloseDialog(); cf = null; } else if (cd == CommandDialog.CreateScreenShot || cd == CommandDialog.Delete || cd == CommandDialog.Install) { of.InternalCloseDialog(); of = null; } } return(true); } catch (Exception e) { if (bShowProgress) { if (cd == CommandDialog.Copy) { if (pf != null) { pf.SetProgress(string.Empty, 0); pf.InternalCloseDialog(); pf = null; } } else if (cd == CommandDialog.Connect) { cf.InternalCloseDialog(); cf = null; } else if (cd == CommandDialog.CreateScreenShot || cd == CommandDialog.Delete) { of.InternalCloseDialog(); of = null; } } strMessage = e.Message; return(false); } }