Exemplo n.º 1
0
Arquivo: Program.cs Projeto: keyou/WPD
        static void Main()
        {
            var devices = new PortableDeviceCollection();
            devices.Refresh();
            var kindle = devices.First();
            kindle.Connect();

            var root = kindle.GetContents();
            foreach (var resource in root.Files)
            {
                DisplayResourceContents(resource);
            }

            PortableDeviceFolder documents = 
                (from r in ((PortableDeviceFolder)root.Files[0]).Files
                 where r.Name.Contains("documents")
                                              select r).First() as PortableDeviceFolder;

            var books = from b in documents.Files
                        where b.Name.Contains("Kindle_Users_Guide")
                        select b;

            foreach (PortableDeviceFile book in books)
            {
                Console.WriteLine(book.Id);
                kindle.DeleteFile(book);
            }

            kindle.Disconnect();

            Console.WriteLine();
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        // public static string STORAGE_ES = "Almacenamiento interno compartido";

        public static PortableDevice getCurrentDevice()
        {
            PortableDevice currentDevice = null;

            try
            {
                var devices = new PortableDeviceCollection();
                //if (null == devices)
                //{

                //}
                //else
                //{
                devices.Refresh();
                currentDevice = devices.First();

                /*if (null == currentDevice)
                 * {
                 *  Console.Error.WriteLine("Dispositivo no encontrado!");
                 * }
                 * else
                 * {
                 *  Console.WriteLine("Dispositivo encontrado: " + currentDevice.FriendlyName);
                 * }*/
                //}
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
            return(currentDevice);
        }
Exemplo n.º 3
0
        private void SetupDevice()
        {
            var devices = new PortableDeviceCollection();

            devices.Refresh();

            this.Device = devices.First();
        }
Exemplo n.º 4
0
        public static void ConnectDevice()
        {
            var devices = new PortableDeviceCollection();
            devices.Refresh();

            gopro = devices.First();
            gopro.Connect();
            currentDeviceId = gopro.DeviceId;
        }
Exemplo n.º 5
0
        static void Main()
        {
            //Connect to MTP devices and pick up the first one
            var devices = new PortableDeviceCollection();

            devices.Refresh();

            Tablet = devices.First();
            Tablet.Connect();

            //Getting root directory
            var root = Tablet.GetContents();

            //Displayinh directory content in console
            foreach (var resource in root.Files)
            {
                DisplayResourceContents(resource);
            }

            //Finding neccessary folder inside the root
            var folder = (root.Files.FirstOrDefault() as PortableDeviceFolder).
                         Files.FirstOrDefault(x => x.Name == "Folder") as PortableDeviceFolder;

            //Finding file inside the folder
            var file = (folder as PortableDeviceFolder)?.Files?.FirstOrDefault(x => x.Name == "File");

            //Transfering file into byte array
            var fileIntoByteArr = Tablet.DownloadFileToStream(file as PortableDeviceFile);

            //Transfering file into file system
            Tablet.DownloadFile(file as PortableDeviceFile, "\\LOCALPATH");

            //Transfering file rom file system into device folder
            Tablet.TransferContentToDevice("\\LOCALPATH", folder.Id);

            //Transfering file from stream into device folder
            var imgPath = "\\LOCALPATH";
            var image   = Image.FromFile(imgPath);

            byte[] imageB;
            using (var ms = new MemoryStream())
            {
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                imageB = ms.ToArray();
            }
            Tablet.TransferContentToDeviceFromStream("FILE NAME", new MemoryStream(imageB), folder.Id);

            //Close the connection
            Tablet.Disconnect();

            Console.WriteLine();
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }
Exemplo n.º 6
0
 void Init()
 {
     Devices = new PortableDeviceCollection();
     if (null == Devices)
     {
         throw new Exception("デバイスを取得できませんでした。");
     }
     else
     {
         Devices.Refresh();
         Device = Devices.First();
     }
     //devices.Clear();
 }
Exemplo n.º 7
0
        private void connectWithDevice(object state)
        {
            if (detected)
            {
                return;
            }

            detected = true;

            Console.WriteLine("Device detected");

            var devices = new PortableDeviceCollection();

            devices.Refresh();

            device = devices.First();
            device.Connect();

            Console.WriteLine("Connected to: " + device.FriendlyName);

            var root = device.GetContents();

            servicePlatformFolder = (PortableDeviceFolder)device.getServicePlatformFolder();

            if (servicePlatformFolder == null)
            {
                Console.WriteLine("Could not find ServicePlatform folder, have you installed ServicePlatform mobile app? Disconnecting...");
                device.Disconnect();
                return;
            }

            getServicesList(device, servicePlatformFolder);

            if (!servicesFileDetected)
            {
                Console.WriteLine("Could not detect services! Disconnecting...");
                device.Disconnect();
                return;
            }

            BeginInvoke(new MethodInvoker(delegate {
                Show();
                //MessageBox.Show("Connected to: " + device.FriendlyName);
            }));

            cleanup(device, servicePlatformFolder);

            //device.Disconnect();
        }
Exemplo n.º 8
0
Arquivo: Program.cs Projeto: keyou/WPD
        static void Main()
        {
            var devices = new PortableDeviceCollection();
            devices.Refresh();
            var kindle = devices.First();
            kindle.Connect();

            kindle.TransferContentToDevice(
                @"d:\temp\Kindle_Users_Guide.azw",
                @"g:\documents");

            kindle.Disconnect();

            Console.WriteLine();
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            var  collection = new PortableDeviceCollection();
            bool another;
            int? depth      = null;
            bool folderOnly = false;

            collection.Refresh();
            var device = collection.First();

            device.Connect();
            do
            {
                //Console.Write("Enter depth: ");

                //if (int.TryParse(Console.ReadLine(), out int depthInt))
                //    depth = depthInt;

                //Console.WriteLine();
                //Console.Write("Folder Only? (y/n): ");
                //if (Console.ReadLine().ToLower().Equals("y"))
                //    folderOnly = true;

                //collection.Refresh();

                //foreach (var device in collection)
                //{
                //    device.Connect();
                //    Console.WriteLine("-------------------------\n" + device.FriendlyName + "\n-------------------------");
                //    DisplayFolderContents(device.GetContents(depth, folderOnly));
                //    device.DisConnect();
                //}
                //device.TransferToDevice(@"F:\LDPlayer\Garulea Continent.record", "o2");
                //var content = device.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android\Garulea Continent.record");
                var content = device.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android\A.txt");
                device.DeleteFile(content.Id, true);
                content = device.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android\Q.txt");
                device.DeleteFile(content.Id, true);

                Console.Write("Another? (y/n) ");
                if (!Console.ReadLine().ToLower().Equals("n"))
                {
                    another = true;
                }
                else
                {
                    another = false;
                }
            } while (another);
            device.DisConnect();
            //var device2 = collection.GetDeviceByName("HM NOTE 1LTEW");

            //device2.Connect();

            ////Console.WriteLine("Enter folder name and folder parent id");

            ////var folder = device2.NewFolder(Console.ReadLine(), Console.ReadLine());

            //var folder = device2.GetContentByPath(@"mtp:\HM NOTE 1LTEW\Internal storage\Android");

            //Console.WriteLine(folder.Id + " ||| " + folder.Name);
            //device2.DisConnect();

            //manager.CreateDirectory(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test\Test 2");

            //Console.WriteLine(manager.Exist(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test\Test 2").Id);

            //manager.Delete(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test", true);

            //Console.WriteLine(manager.Exist(@"mtp:\HM NOTE 1LTEW\Internal storage\AnkuLua\Test\Test 2")?.Id ?? "NotFound");

            Console.ReadKey(true);
        }