示例#1
0
        public CommandResult ListDirectory(string dir)
        {
            ADBRunner runner = new ADBRunner();
            string    sd     = dir.Replace(" ", "\\ ").Replace("(", "\\(").Replace(")", "\\)").Replace("'", "\\'").Replace("&", "\\&") + "/";

            bool   bret = runner.LaunchProcess(SelectDevice(string.Format(COMMAND_LIST_DIR, sd)), CommandDialog.ListDir);
            string sret = runner.strMessage;

            if (bret)
            {
                if (runner.strMessage.StartsWith("error: "))
                {
                    bret = false;
                    sret = runner.strMessage;
                    string sAdbErr = runner.strMessage.Replace("error: ", "");
                    if (sAdbErr.Contains("more than one device/emulator"))
                    {
                        bool bret1 = runner.LaunchProcess(COMMAND_DEVICES, CommandDialog.Devices);
                        if (bret1)
                        {
                            runner.strMessage = runner.strMessage.Replace("List of devices attached\r\n", "").Replace("\t", " ");
                            sret = sAdbErr + "--------------\r\n" + runner.strMessage;
                        }
                    }
                }
            }

            return(new CommandResult(sret, bret));
        }
示例#2
0
        public CommandResult CreateScreenShot(string dir)
        {
            string spull = string.Format("{0}\\{1}", dir,
                                         string.Format("screen-{0:yyyy-MM-dd_hh-mm-ss-tt}.png", DateTime.Now));

            ADBRunner runner = new ADBRunner();
            bool      bret   = runner.LaunchProcess(SelectDevice("shell screencap -p /sdcard/screen.png"), CommandDialog.CreateScreenShot, true);

            if (bret)
            {
                if (!runner.strMessage.Contains(MESSAGE_NODEVICE))
                {
                    CommandResult crc = Copy("/sdcard/screen.png", spull, enCopyType.Pull, true);
                    bret = crc.IsSuccess;//runner.LaunchProcess("pull /sdcard/screen.png" + " " + spull, CommandDialog.None);
                    if (bret)
                    {
                        bret = runner.LaunchProcess(SelectDevice("shell rm /sdcard/screen.png"), CommandDialog.None);
                    }
                    else
                    {
                        return(new CommandResult(crc.Message, bret));
                    }
                }
                else
                {
                    return(new CommandResult(runner.strMessage, false));
                }
            }
            else
            {
                return(new CommandResult(runner.strMessage, bret));
            }

            return(new CommandResult("ScreenShot created successfully", bret));
        }
示例#3
0
        public CommandResult Disconnect(bool bOnly = false)
        {
            ADBRunner runner = new ADBRunner();
            bool      bret   = runner.LaunchProcess(COMMAND_DISCONNECT, CommandDialog.Disconnect);
            string    sRet   = runner.strMessage;

            if (!bOnly)
            {
                bret  = runner.LaunchProcess(COMMAND_KILL_SERVER, CommandDialog.KillServer);
                sRet += runner.strMessage;
            }
            return(new CommandResult(sRet, bret));
        }
示例#4
0
        public CommandResult Devices()
        {
            ADBRunner runner = new ADBRunner();
            bool      bret   = runner.LaunchProcess(COMMAND_DEVICES, CommandDialog.Devices);

            return(new CommandResult(runner.strMessage.Replace("List of devices attached\r\n", "").Replace("\t", " "), bret));
        }
示例#5
0
        public CommandResult DeleteObject(string path)
        {
            ADBRunner runner    = new ADBRunner();
            string    pathValid = path.Replace(" ", "\\ ").Replace("(", "\\(").Replace(")", "\\)").Replace("'", "\\'").Replace("&", "\\&");
            bool      bret      = runner.LaunchProcess(SelectDevice(string.Format(COMMAND_DELETE, pathValid)), CommandDialog.None);

            return(new CommandResult(runner.strMessage, bret));
        }
示例#6
0
        public CommandResult Copy(List <FileOperation> lstItems, enCopyType ct, bool showProgress = false)
        {
            foreach (FileOperation fileOperation in lstItems)
            {
                string sourceValid      = string.Format("\"{0}\"", fileOperation.Source);
                string destinationValid =
                    fileOperation.Destination/*.Replace(":", "_")*/
                    .Replace("*", "_")
                    .Replace("?", "_")
                    .Replace("<", "_")
                    .Replace(">", "_")
                    .Replace("|", "_")
                    .Replace("\"", "_");
                string type = ct == enCopyType.Pull ? "pull" : "push";

                bool bProgress = showProgress;

                if (ct == enCopyType.Copy)
                {
                    type             = "shell cp -a";
                    bProgress        = false;
                    destinationValid = destinationValid.Replace(" ", "\\ ")
                                       .Replace("(", "\\(")
                                       .Replace(")", "\\)")
                                       .Replace("'", "\\'")
                                       .Replace("&", "\\&");
                    sourceValid = sourceValid.Replace(" ", "\\ ")
                                  .Replace("(", "\\(")
                                  .Replace(")", "\\)")
                                  .Replace("'", "\\'")
                                  .Replace("&", "\\&");
                }

                string runCommand = string.Format("{0}{1} {2}", type, bProgress ? " -p" : string.Empty, sourceValid) + " " + string.Format("\"{0}\"", destinationValid);

                if (ct == enCopyType.Push)
                {
                    if (fileOperation.IsFolder && fileOperation.IsFolderEmpty)
                    {
                        string dirValid = fileOperation.Destination.Replace(" ", "\\ ")
                                          .Replace("(", "\\(")
                                          .Replace(")", "\\)")
                                          .Replace("'", "\\'")
                                          .Replace("&", "\\&");

                        runCommand = string.Format(COMMAND_NEWDIR, dirValid);
                    }
                }

                fileOperation.Command = SelectDevice(runCommand);
            }

            ADBRunner runner = new ADBRunner();
            bool      bret   = runner.LaunchProcess(lstItems, CommandDialog.Copy, showProgress);

            return(new CommandResult(runner.strMessage, bret));
        }
示例#7
0
        public CommandResult Rename(string source, string destination)
        {
            ADBRunner runner           = new ADBRunner();
            string    sourceValid      = source.Replace(" ", "\\ ").Replace("(", "\\(").Replace(")", "\\)").Replace("'", "\\'").Replace("&", "\\&");
            string    destinationValid = destination.Replace(" ", "\\ ").Replace("(", "\\(").Replace(")", "\\)").Replace("'", "\\'").Replace("&", "\\&");
            bool      bret             = runner.LaunchProcess(SelectDevice(string.Format(COMMAND_RENAME, sourceValid, destinationValid)), CommandDialog.None);

            return(new CommandResult(runner.strMessage, bret));
        }
示例#8
0
        public CommandResult DeleteObjects(List <FileOperation> lstItems, bool showProgress = false)
        {
            foreach (FileOperation fileOperation in lstItems)
            {
                string pathValid = fileOperation.Source.Replace(" ", "\\ ").Replace("(", "\\(").Replace(")", "\\)").Replace("'", "\\'").Replace("&", "\\&");
                fileOperation.Command = SelectDevice(string.Format(COMMAND_DELETE, pathValid));
            }

            ADBRunner runner = new ADBRunner();
            bool      bret   = runner.LaunchProcess(lstItems, CommandDialog.Delete, showProgress);

            return(new CommandResult(runner.strMessage, bret));
        }
示例#9
0
        public CommandResult CreateDirectory(string dir)
        {
            string dirValid = dir.Replace(" ", "\\ ")
                              .Replace("(", "\\(")
                              .Replace(")", "\\)")
                              .Replace("'", "\\'")
                              .Replace("&", "\\&");
            ADBRunner runner = new ADBRunner();
            bool      bret   = runner.LaunchProcess(SelectDevice(string.Format(COMMAND_NEWDIR, dirValid)), CommandDialog.None);

            if (runner.strMessage.Contains("Read-only file system") || runner.strMessage.Contains("Permission denied"))
            {
                bret = false;
            }
            return(new CommandResult(runner.strMessage, bret));
        }
示例#10
0
        public CommandResult Connect()
        {
            DeviseAddr addr = new DeviseAddr();

            if (addr.IsValid())
            {
                ADBRunner runner   = new ADBRunner();
                string    sCommand = string.Format(COMMAND_CONNECT, addr.Address);
                if (!string.IsNullOrEmpty(addr.ConnectionType) && addr.ConnectionType.Equals("usb") && !string.IsNullOrEmpty(addr.UsbDevice))
                {
                    sCommand = string.Format(COMMAND_CONNECT_DEV, addr.UsbDevice);
                    return(new CommandResult("You select '" + addr.UsbDevice + "' device", true));
                }
                else
                {
                    bool bret = runner.LaunchProcess(sCommand, CommandDialog.Connect, true);
                    return(new CommandResult(runner.strMessage, bret));
                }
            }
            return(new CommandResult(MESSAGE_CONNECT_ERROR, false));
        }
示例#11
0
        public CommandResult Install(string sApk)
        {
            CommandResult rez = Devices();

            if (!rez.IsSuccess)
            {
                return(rez);
            }
            else
            {
                if (!string.IsNullOrEmpty(rez.Message))
                {
                    ADBRunner runner = new ADBRunner();
                    bool      bret   = runner.LaunchProcess(SelectDevice(string.Format(COMMAND_INSTALL, sApk)), CommandDialog.Install, true);
                    return(new CommandResult(runner.strMessage, bret));
                }
                else
                {
                    return(new CommandResult("No connected devices.\r\n" + "Please click `Connect` in Context Menu", false));
                }
            }
        }
示例#12
0
        public CommandResult Copy(string source, string destination, enCopyType ct, bool showProgress = false)
        {
            ADBRunner runner           = new ADBRunner();
            string    sourceValid      = string.Format("\"{0}\"", source);
            string    destinationValid =
                destination /*.Replace(":", "_")
                             * .Replace("*", "_")
                             * .Replace("?", "_")
                             * .Replace("<", "_")
                             * .Replace(">", "_")
                             * .Replace("|", "_")
                             * .Replace("\"", "_")*/;
            string type = ct == enCopyType.Pull ? "pull" : "push";

            if (ct == enCopyType.Copy)
            {
                type         = "shell cp";
                showProgress = false;
            }
            string runCommand = string.Format("{0} {1} {2}", type, showProgress ? "-p" : string.Empty, sourceValid) + " " + string.Format("\"{0}\"", destinationValid);
            bool   bret       = runner.LaunchProcess(SelectDevice(runCommand), CommandDialog.Copy, showProgress, destination);

            return(new CommandResult(runner.strMessage, bret));
        }