Exemple #1
0
        public static bool deleteDeviceFile(PortableDevice device, String deviceFolder, String file)
        {
            bool status = false;

            try
            {
                String phoneDir                 = deviceFolder;
                PortableDeviceFolder root       = device.Root();
                PortableDeviceFolder result     = root.FindDir(phoneDir);
                PortableDeviceFile   deviceFile = result.FindFile(file);
                if (null == result)
                {
                    //Console.Error.WriteLine(phoneDir + " no encontrado!");
                    status = false;
                }
                else
                {
                    device.DeleteFile(deviceFile);
                    status = true;
                }
            }
            catch (Exception)
            {
                //Console.Error.WriteLine(ex.Message);
                status = false;
            }
            return(status);
        }
 private void cleanupInDir(PortableDevice device, PortableDeviceFolder folder)
 {
     foreach (var item in folder.Files)
     {
         device.DeleteFile((PortableDeviceFile)item);
     }
 }
 private void cleanup(PortableDevice device, PortableDeviceFolder folder)
 {
     Console.WriteLine("Cleaning up ServicePlatform folder...");
     foreach (var item in folder.Files)
     {
         if (item is PortableDeviceFile && (item.Name.Equals("input-params") || item.Name.Equals("desktop-finished") || item.Name.Equals("mobile-finished")))
         {
             device.DeleteFile((PortableDeviceFile)item);
         }
         else if (item is PortableDeviceFolder && (item.Name.Equals("Input") || item.Name.Equals("Output")))
         {
             cleanupInDir(device, (PortableDeviceFolder)item);
         }
     }
 }
Exemple #4
0
        public static void DeleteFolderVincapture(PortableDevice device, PortableDeviceFolder vinFolder)
        {
            foreach (var tmp in vinFolder.Files)
            {
                if (tmp is PortableDeviceFolder)
                {
                    DeleteFolderVincapture(device, (PortableDeviceFolder)tmp);
                    var tmpFile = (PortableDeviceFolder)tmp;

                    device.DeleteFolder(tmpFile);
                }
                if (tmp is PortableDeviceFile)
                {
                    var tmpFile = (PortableDeviceFile)tmp;


                    device.DeleteFile(tmpFile);
                }
            }
        }
        private async Task CopyFiles(PortableDevice device, IEnumerable <PortableDeviceObject> files, string path, bool delete, string additionalPath, DateMethod dateMethod, string additionalExtension)
        {
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }

            int counter = 0;

            ProgressB.Value   = 0;
            ProgressB.Maximum = files.Count();

            DirectoryInfo di = new DirectoryInfo(path);

            firstF = di.GetDirectories("*.*", System.IO.SearchOption.TopDirectoryOnly).Count();

            string[] existingFiles = (from FileInfo f in di.GetFiles("*.*", SearchOption.AllDirectories)
                                      select f.Name).ToArray();

            PortableDevice pd = collection[DevicesListBox.SelectedIndex];

            foreach (var item in files)
            {
                if (item is PortableDeviceFile)
                {
                    PortableDeviceFile file = (PortableDeviceFile)item;
                    try
                    {
                        if (ignoreCheckBox.IsChecked == true)
                        {
                            if (existingFiles.Contains(file.Name + additionalExtension))
                            {
                                existsCounter++;
                                ProgressMessageLabel.Content = existsCounter.ToString() + " files were already existed. I ignored them.";


                                counter++;
                                ProgressB.Value = counter;
                                continue;
                            }
                        }

                        device.Connect();

                        Exception taskEx = null;
                        await Task.Factory.StartNew(() =>
                        {
                            try
                            {
                                pd.DownloadFile(file, path);
                            }
                            catch (Exception ex)
                            {
                                taskEx = ex;
                            }
                        });

                        if (taskEx != null)
                        {
                            throw taskEx;
                        }

                        device.Disconnect();

                        await CopyFile(path, file.Name, dateMethod, additionalExtension, additionalPath);


                        counter++;
                        ProgressB.Value = counter;

                        if (delete)
                        {
                            device.Connect();
                            await Task.Factory.StartNew(() =>
                            {
                                pd.DeleteFile(file);
                            });

                            device.Disconnect();
                        }
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show("Error while copying " + file.Name + "\n\n" + ex.Message);
                    }
                }
            }
        }
Exemple #6
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");

            //Deleting file device-side
            Tablet.DeleteFile(file as PortableDeviceFile);

            //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 from file system into device folder
            Tablet.TransferFileToDevice("\\LOCALPATH", folder.Id);

            //Creating folder device-side
            Tablet.CreateFolder("FOLDER NAME", folder.Id);

            //Deleting folder device-side
            Tablet.DeleteFolder(folder);

            //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.TransferFileToDeviceFromStream("FILE NAME", new MemoryStream(imageB), folder.Id);

            //Close the connection
            Tablet.Disconnect();

            Console.WriteLine();
            Console.WriteLine("Press any key to continue.");
            Console.ReadKey();
        }