Beispiel #1
0
        public Result ListDirecotry(string device, string path)
        {
            Result result = new Result();

            try
            {
                FileProperty property = GetProperty(device, path);
                if (property.type == Type.directory)
                {
                    result.filesName = new List <string>();
                    foreach (string file in AdbHelper.AdbHelper.ListDataFolder(device, path))
                    {
                        result.filesName.Add(file);
                    }
                    result.success = true;
                }
                else
                {
                    throw new Exception("Wrong path!");
                }
            }
            catch (Exception ex)
            {
                result.success      = false;
                result.errorMessage = ex.ToString();
            }
            return(result);
        }
Beispiel #2
0
        public Result ListDirecotryVerbose(string device, string path)
        {
            string listScript;

            if (path == "/")
            {
                listScript = System.String.Format(
                    "ls {0}|while read i;do " +
                    "echo \\\"$(stat \\\"/$i\\\")\\\";" +
                    "done", path);
            }
            else
            {
                listScript = System.String.Format(
                    "ls {0}|while read i;do " +
                    "echo \\\"$(stat \\\"{0}/$i\\\")\\\";" +
                    "done", path);
            }

            // string scriptName = "/sdcard/utils/list" + path.Replace('/', '_');
            Result result = new Result();

            try
            {
                FileProperty property = GetProperty(device, path);
                if (property.type == Type.directory)
                {
                    var properities = AdbHelper.AdbHelper.RunShell(device, listScript);
                    result.filesProperty = ParaseProperties(properities);
                    result.success       = true;
                }
                else
                {
                    throw new Exception("Wrong path!");
                }
            }
            catch (Exception ex)
            {
                result.success      = false;
                result.errorMessage = ex.ToString();
            }
            return(result);
        }
Beispiel #3
0
        FileProperty GetProperty(string device, string path)
        {
            FileProperty property = new FileProperty();

            var    items        = AdbHelper.AdbHelper.ListDataFolder(device, path);
            string errorPattern = "No such file or directory";

            if (items.Length != 0 && items[0].Contains(errorPattern))
            {
                throw new Exception("Wrong path!");
            }
            else
            {
                var rawData = AdbHelper.AdbHelper.GetProperty(device, path);
                property = ParaseProperties(rawData)[0];
            }

            return(property);
        }
Beispiel #4
0
        List <FileProperty> ParaseProperties(string[] rawData)
        {
            List <FileProperty> result = new List <FileProperty>();

            for (int i = 0; i < rawData.Length - 6; i += 7)
            {
                if (rawData[i].Contains("No such file or directory"))
                {
                    continue;
                }
                if (!rawData[i].Contains("File"))
                {
                    continue;
                }

                FileProperty property = new FileProperty();
                property.modifyTime = rawData[i + 5].Substring(8, rawData[5].Length - 8);
                property.accessTime = rawData[i + 4].Substring(8, rawData[4].Length - 8);

                if (rawData[i + 1].Contains("directory"))
                {
                    property.type = Type.directory;
                }
                if (rawData[i + 1].Contains("regular"))
                {
                    property.type = Type.file;
                }
                if (rawData[i + 1].Contains("symbol"))
                {
                    property.type = Type.link;
                }

                string sizePattern = @"(?<=Size: )\d*\b";
                property.size = Regex.Matches(rawData[i + 1], sizePattern)[0].ToString();
                string pathPattern = @"(?<=File: ).*";
                property.path = Regex.Matches(rawData[i], pathPattern)[0].ToString().Replace("'", "");

                result.Add(property);
            }
            return(result);
        }
Beispiel #5
0
        public Result CopyFileFromDevice(string device, string devicePath, string pcPath)
        {
            if (!System.IO.Directory.Exists(pcPath))
            {
                System.IO.Directory.CreateDirectory(pcPath);
            }
            Result result = new Result();

            try
            {
                FileProperty property = GetProperty(device, devicePath);
                if (property.type == Type.fne)
                {
                    throw new Exception("Wrong path");
                }
                if (property.type == Type.directory)
                {
                    string fullPath = pcPath + '/' + property.path.Replace('/', '_');
                    if (!System.IO.Directory.Exists(fullPath))
                    {
                        System.IO.Directory.CreateDirectory(fullPath);
                    }
                    AdbHelper.AdbHelper.CopyFromDevice(device, devicePath, fullPath);
                }
                else
                {
                    AdbHelper.AdbHelper.CopyFromDevice(device, devicePath, pcPath);
                }
                result.success = true;
            }
            catch (Exception ex)
            {
                result.success      = false;
                result.errorMessage = ex.ToString();
            }
            return(result);
        }