Example #1
0
        public ListingType FileOrDirectory(string location)
        {
            if (!_device.BusyBox.IsInstalled)
            {
                return(ListingType.ERR);
            }

            AdbCommand isFile = Adb.FormAdbShellCommand(_device, false, string.Format(IS_FILE, location));
            AdbCommand isDir  = Adb.FormAdbShellCommand(_device, false, string.Format(IS_DIRECTORY, location));

            string _isFile = Adb.ExecuteAdbCommand(isFile);
            string _isDir  = Adb.ExecuteAdbCommand(isDir);

            if (_isFile.Contains("1"))
            {
                return(ListingType.FILE);
            }
            else if (_isDir.Contains("1"))
            {
                return(ListingType.DIRECTORY);
            }

            return(ListingType.NONE);
        }
Example #2
0
        public Dictionary <string, ListingType> GetFilesAndDirectories(string location)
        {
            if (location == null || string.IsNullOrEmpty(location) || Regex.IsMatch(location, "\\s"))
            {
                throw new ArgumentException("rootDir must not be null or empty!");
            }

            Dictionary <string, ListingType> filesAndDirs = new Dictionary <string, ListingType>();
            AdbCommand cmd = null;

            if (_device.BusyBox.IsInstalled)
            {
                cmd = Adb.FormAdbShellCommand(_device, true, "busybox", "ls", "-a", "-p", "l", location);
            }
            else
            {
                cmd = Adb.FormAdbShellCommand(_device, true, "ls", "-a", "-p", "-l", location);
            }

            using (StringReader reader = new StringReader(Adb.ExecuteAdbCommand(cmd)))
            {
                string line = null;

                while (reader.Peek() != -1)
                {
                    line = reader.ReadLine();

                    if (!string.IsNullOrEmpty(line) && !Regex.IsMatch(line, "\\s"))
                    {
                        filesAndDirs.Add(line, line.EndsWith("/") ? ListingType.DIRECTORY : ListingType.FILE);
                    }
                }
            }

            return(filesAndDirs);
        }
Example #3
0
 public static string RunAdbShellCommand(Device dev, bool root, string cmd, params object[] args)
 {
     return(Adb.ExecuteAdbCommand(Adb.FormAdbShellCommand(dev, root, cmd, args)));
 }