Пример #1
0
        public FSObjectStatus GetFSObjectStatus(string pathToObject, bool inRoot)
        {
            StringBuilder cmdB = new StringBuilder();

            cmdB.AppendLine("cd " + pathToObject);
            cmdB.AppendLine("ls");

            if (pathToObject.Contains(PERM_HINT_WORDS))
            {
                return(FSObjectStatus.PermissionDenied);
            }

            ShellResponse sr = adbi.RunMultiLineCommand(device, cmdB.ToString(), inRoot);

            //if ((sr.stdOut.Contains("Not a directory") && sr.stdOut.Contains("cd: ")) || (sr.stdError.Contains("Not a directory") && sr.stdError.Contains("cd: ")))
            //    return FSObjectStatus.File;

            //if (sr.stdOut.Contains("Permission denied") && (sr.stdOut.Contains("opendir") || sr.stdOut.Contains("cd: ")))  // Permission Denied.
            //    return FSObjectStatus.PermissionDenied;

            if (ContainsStringInResopnses(sr, "Not a directory", "cd: "))
            {
                return(FSObjectStatus.File);
            }

            if (ContainsStringInResopnses(sr, "Permission denied", "") && (ContainsStringInResopnses(sr, "opendir", "") || ContainsStringInResopnses(sr, "cd: ", "")))
            {
                return(FSObjectStatus.PermissionDenied);
            }

            return(FSObjectStatus.Directory);
        }
Пример #2
0
        private bool ContainsStringInResopnses(ShellResponse r, params string[] stringShouldExistsInResponse)
        {
            string[] ss = stringShouldExistsInResponse;

            if (ss.Length < 2)
            {
                throw new InvalidDataException();
            }

            int  i    = 0;
            bool stdO = r.stdOut.Contains(ss[i]);
            bool stdE = r.stdError.Contains(ss[i]);

            foreach (string s in ss)
            {
                if (i == 0)
                {
                    i++;
                    continue;
                }

                stdO &= r.stdOut.Contains(s);   // Contains(...) && Contains(...) && ....
                stdE &= r.stdError.Contains(s);

                i++;
            }

            return(stdO || stdE);
        }
Пример #3
0
        public List <string> ListFiles(string path, bool inRoot)
        {
            StringBuilder cmdB = new StringBuilder();

            cmdB.AppendLine("cd " + path);
            cmdB.AppendLine("ls -a");
            ShellResponse sr = adbi.RunMultiLineCommand(device, cmdB.ToString(), inRoot);

            List <string> fileNames = new List <string>();
            List <string> folders   = new List <string>();
            List <string> result    = new List <string>();

            using (StringReader strR = new StringReader(sr.stdOut))
            {
                Encoding enU  = Encoding.UTF8;
                Encoding enGB = Encoding.Default;

                string line;
                while ((line = strR.ReadLine()) != null)
                {
                    if (line == "." || line == "..")
                    {
                        continue;
                    }

                    if (line.Contains(".") && line.ToCharArray()[0] != '.')   // If the filename contains dot and it is not hidden folders.
                    {
                        fileNames.Add(enU.GetString(enGB.GetBytes(line)));
                    }
                    else
                    {
                        folders.Add(enU.GetString(enGB.GetBytes(line)));   // GBK -> UTF-8, may not work in other countries.
                    }
                }
            }

            fileNames.Sort();
            folders.Sort();

            foreach (string s in folders)
            {
                result.Add(s);
            }

            foreach (string s in fileNames)
            {
                result.Add(s);
            }

            return(result);
        }