示例#1
0
    private static async Task <object> ReadArguments(string[] args)
    {
        if (args == null || !args.Any())
        {
            return(null);
        }

#if DEBUG
        Console.WriteLine($">> {args.QuickJoin()}".AddColor(Color.Beige));
#endif
        Trace.WriteLine($">> {args.QuickJoin()}");

        // var argEnum = args.GetEnumerator().Cast<string>();

        for (int i = 0; i < args.Length; i++)
        {
            var current = args[i];

            switch (current)
            {
            case "sh":
                string input = null;

                var ps = AdbDevice.GetShell(AdbDevice.ADB_SHELL);

                while ((input = Console.ReadLine()) != null)
                {
                    input = input.Trim();

                    ps.StandardInput.WriteLine(input);
                    ps.StandardInput.Flush();
                    Trace.WriteLine($">>{input}");
                    string b = null;

                    ps.ErrorDataReceived += (sender, eventArgs) =>
                    {
                        Console.Error.WriteLine(eventArgs.Data);
                    };

                    ps.OutputDataReceived += (sender, eventArgs) =>
                    {
                        Console.WriteLine(eventArgs.Data);
                    };

                    if (input == "exit")
                    {
                        break;
                    }
                }

                break;

            case "gi":
                // return _device.GetItems(args[++i..]);
                var c = AdbCommand.find.Build(args2: args[++i..]);
示例#2
0
    public static async Task Main(string[] args)
    {
#if TEST
        if (!args.Any())
        {
            args = new[] { APP_SENDTO, OP_ADD, APP_CTX, OP_ADD };

            // args = new[] { PULL_ALL, "sdcard/dcim/snapchat", @"C:\users\deci\downloads" };
            // args = new[] { PULL_ALL, "sdcard/dcim/snapchat" };
        }
#endif

#if DEBUG
        // KillAdb();
#endif
        RuntimeHelpers.RunClassConstructor(typeof(AppIntegration).TypeHandle);

        /*
         * Setup
         */

        Console.Title = Resources.Name;

        /*
         *
         */

        _device = AdbDevice.First;

        Console.WriteLine($">> {_device.ToString().AddColor(Color.Aquamarine)}");

        object data;
        string input;
        data = await ReadArguments(args) !;

        Print(data);

        while ((input = Console.ReadLine()) != null)
        {
            input = input.Trim();

            var inputArgs = input.Split(' ');
            data = await ReadArguments(inputArgs) !;

            Print(data);
            continue;
        }

        // ConsoleManager.WaitForInput();
    }
示例#3
0
        public List <AdbDevice> GetDevices()
        {
            var devices = new List <AdbDevice>();

            //adb devices -l
            var builder = new ProcessArgumentBuilder();

            builder.Append("devices");
            builder.Append("-l");

            var r = runner.RunAdb(AndroidSdkHome, builder);

            if (r.StandardOutput.Count > 1)
            {
                foreach (var line in r.StandardOutput?.Skip(1))
                {
                    var parts = Regex.Split(line, "\\s+");

                    var d = new AdbDevice
                    {
                        Serial = parts[0].Trim()
                    };

                    if (parts.Length > 1 && (parts[1]?.ToLowerInvariant() ?? "offline") == "offline")
                    {
                        continue;
                    }

                    if (parts.Length > 2)
                    {
                        foreach (var part in parts.Skip(2))
                        {
                            var bits = part.Split(new[] { ':' }, 2);
                            if (bits == null || bits.Length != 2)
                            {
                                continue;
                            }

                            switch (bits[0].ToLower())
                            {
                            case "usb":
                                d.Usb = bits[1];
                                break;

                            case "product":
                                d.Product = bits[1];
                                break;

                            case "model":
                                d.Model = bits[1];
                                break;

                            case "device":
                                d.Device = bits[1];
                                break;
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(d?.Serial))
                    {
                        devices.Add(d);
                    }
                }
            }

            return(devices);
        }