Exemplo n.º 1
0
        protected static void EnumerateContents(ref IPortableDeviceContent content,
            PortableDeviceFolder parent)
        {
            // Get the properties of the object
            IPortableDeviceProperties properties;
            content.Properties(out properties);

            // Enumerate the items contained by the current object
            IEnumPortableDeviceObjectIDs objectIds;
            content.EnumObjects(0, parent.Id, null, out objectIds);

            uint fetched = 0;
            do
            {
                string objectId;

                objectIds.Next(1, out objectId, ref fetched);
                if (fetched > 0)
                {
                    var currentObject = WrapObject(properties, objectId);

                    parent.Files.Add(currentObject);

                    if (currentObject is PortableDeviceFolder)
                    {
                        EnumerateContents(ref content, (PortableDeviceFolder) currentObject);
                    }
                }
            } while (fetched > 0);
        }
Exemplo n.º 2
0
        public static bool sendFileToDevice(PortableDevice device, String deviceFolder, String localPath, String localFile, String newNameFile)
        {
            bool status = false;

            try
            {
                String phoneDir             = deviceFolder;
                PortableDeviceFolder root   = device.Root();
                PortableDeviceFolder result = root.FindDir(phoneDir);
                if (null == result)
                {
                    status = false;
                }
                else
                {
                    device.TransferContentToDevice(result, localPath + localFile);
                    status = true;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                status = false;
            }
            return(status);
        }
Exemplo n.º 3
0
        public static bool getFileFromDevice(PortableDevice device, String deviceFolder, String localPath, String file)
        {
            bool status = false;

            try
            {
                String phoneDir             = deviceFolder;
                PortableDeviceFolder root   = device.Root();
                PortableDeviceFolder result = root.FindDir(phoneDir);
                if (null == result)
                {
                    //Console.Error.WriteLine(phoneDir + " no encontrado!");
                    status = false;
                }
                else
                {
                    PortableDeviceFile deviceFile = ((PortableDeviceFolder)result).FindFile(file);
                    device.TransferContentFromDevice(deviceFile, localPath, file);
                    status = true;
                }
            }
            catch (Exception)
            {
                //Console.Error.WriteLine(ex.Message);
                status = false;
            }
            return(status);
        }
Exemplo n.º 4
0
 private void cleanupInDir(PortableDevice device, PortableDeviceFolder folder)
 {
     foreach (var item in folder.Files)
     {
         device.DeleteFile((PortableDeviceFile)item);
     }
 }
Exemplo n.º 5
0
 //To_Fileは"/Android/data"や"/Download/"などから始める
 public void Upload_File(string From_File, string To_File)
 {
     if (!IsDeviceExsist || !File.Exists(From_File))
     {
         return;
     }
     try
     {
         string phoneDir           = "内部ストレージ" + To_File;
         PortableDeviceFolder root = Device.Root();
         foreach (PortableDeviceObject Name_Now in root.Files)
         {
             MessageBox.Show(Name_Now.Name);
         }
         PortableDeviceFolder result = root.FindDir(phoneDir);
         if (null == result)
         {
             result   = Device.Root().FindDir("Tablet" + To_File);
             phoneDir = "Tablet" + To_File;
             MessageBox.Show("");
         }
         if (null == result)
         {
             return;
         }
         Device.TransferContentToDevice(result, From_File);
     }
     catch (Exception ex)
     {
         Sub_Code.Error_Log_Write(ex.Message);
     }
 }
Exemplo n.º 6
0
        private static (int?, PortableDeviceFolder) GetDirectory(PortableDeviceFolder rootDirectory, string directoryPath)
        {
            if (string.IsNullOrEmpty(directoryPath) || (directoryPath[0] != Path.PathSeparator && directoryPath[0] != Path.AltDirectorySeparatorChar))
            {
                Console.WriteLine($"[{nameof(EXIT_CODE_INVALID_DIRECTORY_PATH)}]");
                return(EXIT_CODE_INVALID_DIRECTORY_PATH, null);
            }

            var endsWithPathSeparator = directoryPath[directoryPath.Length - 1] == Path.PathSeparator || directoryPath[directoryPath.Length - 1] == Path.AltDirectorySeparatorChar;
            var directoryPathParts    = (endsWithPathSeparator ? directoryPath.Substring(0, directoryPath.Length - 1) : directoryPath)
                                        .Split(Path.PathSeparator, Path.AltDirectorySeparatorChar);

            var directory = rootDirectory;

            foreach (var directoryPathPart in directoryPathParts.Skip(1))
            {
                directory = directory.Files
                            .OfType <PortableDeviceFolder>()
                            .SingleOrDefault(entry => string.Equals(entry.Name, directoryPathPart, StringComparison.Ordinal));

                if (directory == null)
                {
                    Console.WriteLine($"[{nameof(EXIT_CODE_DEVICE_DIRECTORY_NOT_FOUND)}]");
                    return(EXIT_CODE_DEVICE_DIRECTORY_NOT_FOUND, null);
                }
            }

            return(null, directory);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public static void NavigateFolderContentsForDelete(PortableDevice device, PortableDeviceFolder folder)
        {
            var item = folder.Files.FirstOrDefault(x => x.Name.ToLower().Equals("vincapture"));

            var itemSub = (PortableDeviceFolder)item;

            DeleteFolderVincapture(device, itemSub);
        }
Exemplo n.º 9
0
 private static void PrintDirectory(PortableDeviceFolder directory)
 {
     Console.WriteLine("[Directory]");
     Console.WriteLine($"{directory.Name}/\t{directory.Id}");
     foreach (var entry in directory.Files)
     {
         Console.WriteLine($"\t{entry.Name}{(entry is PortableDeviceFolder ? "/" : string.Empty)}\t{entry.Id}");
     }
 }
Exemplo n.º 10
0
 public static void DisplayFolderContents(PortableDeviceFolder folder)
 {
     foreach (var item in folder.Files)
     {
         Console.WriteLine(item.Name);
         if (item is PortableDeviceFolder)
         {
             DisplayFolderContents((PortableDeviceFolder)item);
         }
     }
 }
Exemplo n.º 11
0
 private void downloadFiles(PortableDevice device, PortableDeviceFolder folder, String outputFolder)
 {
     foreach (var item in folder.Files)
     {
         if (item is PortableDeviceFile)
         {
             Console.WriteLine("\tDownloading: " + item.Name);
             device.DownloadFile((PortableDeviceFile)item, outputFolder);
         }
     }
 }
Exemplo n.º 12
0
        public Form1()
        {
            InitializeComponent();

            SetupList();

            SetupDevice();

            this.Root = GetRootFolder();
            ShowFolder(this.Root);
        }
Exemplo n.º 13
0
        private PortableDeviceFolder GetRootFolder()
        {
            this.Device.Connect();
            this.Device.Prepare();

            PortableDeviceFolder root = this.Device.GetRootContent(false);

            this.Device.Disconnect();

            return(root);
        }
Exemplo n.º 14
0
        private PortableDeviceFolder GetFolderContents(PortableDeviceFolder folder)
        {
            this.Device.Connect();
            this.Device.Prepare();

            var contents = this.Device.GetContents(folder, false);

            this.Device.Disconnect();

            return(contents);
        }
Exemplo n.º 15
0
        private long EnumerateContents(PortableDevice portableDevice, PortableDeviceFolder deviceFolder)
        {
            if (System.Threading.Thread.CurrentThread.IsBackground)
            {
                Utility.LogMessage("[EnumerateContents] [IsBackground]");
            }
            else
            {
                Utility.LogMessage("[EnumerateContents] [Foreground]");
            }

            try
            {
                foreach (var fileObject in deviceFolder.Files)
                {
                    if (_activeDevice != null && _activeDevice.ImportOption == DeviceImportOption.Never)
                    {
                        break;
                    }

                    if (fileObject is PortableDeviceFile)
                    {
                        //if (Common.Utilities.Utility.FileExtensions.IsValidFileExtension(Path.GetExtension(fileObject.Name.ToLower())))
                        if (Utility.ListValidImageExtensions.Contains(Path.GetExtension(fileObject.Name).ToLower()))
                        {
                            _totalFileCounter++;

                            string str = (string.IsNullOrEmpty(fileObject.Name) ? Path.GetFileName(fileObject.Id)
                                : Path.GetFileName(fileObject.Name));

                            if (!File.Exists(Path.Combine(_defaultMediaBackupPath, str)))
                            {
                                //Utility.LogMessage("{0} {1}", fileObject.Id, fileObject.Name);
                                _validFileCounter++;
                            }
                        }
                    }
                    else
                    {
                        //recursive call to enumerate contents
                        EnumerateContents(portableDevice, (PortableDeviceFolder)fileObject);
                    }
                }
                return(_totalFileCounter);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 16
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.º 17
0
 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);
         }
     }
 }
 private void FindFolders(PortableDeviceFolder folder, string currentPath)
 {
     if (folder.Name.Contains("Camera Roll"))
     {
         foundFolders.Add(folder);
         FoldersListBox.Items.Add(currentPath + "\\" + folder.Name);
     }
     foreach (var item in folder.Files)
     {
         if (item is PortableDeviceFolder)
         {
             FindFolders((PortableDeviceFolder)item, currentPath + "\\" + folder.Name);
         }
     }
 }
Exemplo n.º 19
0
        private void ShowFileCountNotification(Device connectedDevice)
        {
            PortableDevice portableDevice = null;

            try
            {
                if (_connectedDeviceCollection != null &&
                    _connectedDeviceCollection.Count > 0)
                {
                    //get the connect device of same Id
                    portableDevice = _connectedDeviceCollection.
                                     SingleOrDefault(p => p.DeviceId.Equals(connectedDevice.Id));

                    if (portableDevice != null)
                    {
                        portableDevice.Connect();

                        //set active device to curren-device
                        _activeDevice = connectedDevice;

                        PortableDeviceFolder deviceFolder = portableDevice.GetContents();

                        var fileCount = EnumerateContents(portableDevice, deviceFolder);
                        Console.WriteLine("Total number of files found {0}", fileCount);

                        if (_fileCounter > 0)
                        {
                            SystemTrayManager.ShowBalloonTip(balloonTipText: string.Format("{0} files found in - {1} "
                                                                                           , _fileCounter, connectedDevice.DisplayName));
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (portableDevice != null)
                {
                    portableDevice.Disconnect();
                }

                _activeDevice = null;
                _fileCounter  = 0;
            }
        }
Exemplo n.º 20
0
        public static void NavigateFolderContents(PortableDevice device, PortableDeviceFolder folder)
        {
            var folderPath = _copyPath + "\\" + "VinCapture";

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }


            var item = folder.Files.FirstOrDefault(x => x.Name.ToLower().Equals("vincapture"));

            var itemSub = (PortableDeviceFolder)item;

            CopyFolderInsideVincapture(device, itemSub, folderPath);
        }
Exemplo n.º 21
0
        private void FetchContents(PortableDevice portableDevice, PortableDeviceFolder deviceFolder)
        {
            try
            {
                foreach (var fileObject in deviceFolder.Files)
                {
                    if (_activeDevice != null && _activeDevice.ImportOption == DeviceImportOption.Never)
                    {
                        break;
                    }

                    if (_activeDevice != null && StoredDevices.SingleOrDefault(p => p.Id.Equals(_activeDevice.Id)) == null)
                    {
                        break;
                    }

                    if (fileObject is PortableDeviceFile)
                    {
                        //if (Common.Utilities.Utility.FileExtensions.IsValidFileExtension(Path.GetExtension(fileObject.Name.ToLower())))
                        if (Utility.ListValidImageExtensions.Contains(Path.GetExtension(fileObject.Name).ToLower()))
                        {
                            //validFile
                            //Utility.LogMessage("{0} {1}", fileObject.Id, fileObject.Name);

                            string str = (string.IsNullOrEmpty(fileObject.Name) ? Path.GetFileName(fileObject.Id) : Path.GetFileName(fileObject.Name));
                            if (!File.Exists(Path.Combine(_defaultMediaBackupPath, str)))
                            {
                                //copy the file to device
                                Utility.LogMessage("[FetchContents] [Copy] [{0} {1}]", fileObject.Id, fileObject.Name);
                                portableDevice.CopyFilefromDevice((PortableDeviceFile)fileObject, DefaultMediaBackupPath);
                                //System.Threading.Thread.Sleep(2000);
                            }
                        }
                    }
                    else
                    {
                        FetchContents(portableDevice, (PortableDeviceFolder)fileObject);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 22
0
        private void CopyDeviceContents(Device device)
        {
            //if (System.Threading.Thread.CurrentThread.IsBackground)
            //    Utility.LogMessage("[CopyDeviceContents] [Task] [IsBackground][Device::{0}]",device.DisplayName);

            PortableDevice portableDevice = null;

            try
            {
                if (_connectedDeviceCollection != null &&
                    _connectedDeviceCollection.Count > 0)
                {
                    //get the connect device of same Id
                    portableDevice = _connectedDeviceCollection.
                                     SingleOrDefault(p => p.DeviceId.Equals(device.Id));

                    if (portableDevice != null)
                    {
                        portableDevice.Connect();

                        //set active device to current-device
                        Utility.LogMessage(@"[CopyDeviceContents] [Setting_ActiveDevice] [{0}]", device.DisplayName);
                        _activeDevice = device;

                        PortableDeviceFolder deviceFolder = portableDevice.GetContents();
                        FetchContents(portableDevice, deviceFolder);
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.LogException(ex);
            }
            finally
            {
                if (portableDevice != null)
                {
                    portableDevice.Disconnect();
                }

                Utility.LogMessage(@"[CopyDeviceContents] [Finally] [Setting_ActiveDevice][NULL]");
                _activeDevice = null;
            }
        }
Exemplo n.º 23
0
 private void ShowFolder(PortableDeviceFolder folder)
 {
     // カレントディレクトリ保存
     this.CurFolder = folder;
     // 行アイテム削除
     while (this.ListView.Items.Count > 0)
     {
         this.ListView.Items.RemoveAt(0);
     }
     // 行アイテムに情報追加
     foreach (PortableDeviceObject obj in folder.Files)
     {
         ListViewItem item = this.ListView.Items.Add(obj.Name);
         item.Selected = true;
         item.Focused  = true;
         item.SubItems.Add((obj is PortableDeviceFolder) ? "フォルダ" : "ファイル");
         item.SubItems.Add("" + obj.Size);
     }
 }
Exemplo n.º 24
0
        private void LoadFiles()
        {
            PortableDeviceManager deviceManager = new PortableDeviceManager();

            deviceManager.RefreshDeviceList();
            uint numberOfDevices = 1;

            deviceManager.GetDevices(null, ref numberOfDevices);
            string[] deviceIds;
            string   temp1 = "";

            deviceIds = new string[numberOfDevices];
            deviceManager.GetDevices(ref temp1, ref numberOfDevices);
            PortableDevices.PortableDevice Drive = null;
            try
            {
                if (temp1 != "")
                {
                    PortableDevices.PortableDevice Device = new PortableDevices.PortableDevice(temp1);
                    try
                    {
                        Device.Connect();
                        string temp = Device.FriendlyName;
                        PortableDeviceFolder root   = Device.GetContents();
                        PortableDeviceFolder folder = root.Files.First() as PortableDeviceFolder;
                        foreach (string file in Directory.EnumerateFiles("Files"))
                        {
                            Device.TransferContentToDeviceFromStream(Path.GetFileName(file), new MemoryStream(File.ReadAllBytes(file)), folder.Id);
                        }
                    }
                    catch (Exception ex)
                    {
                        Device.Disconnect();
                        MessageBox.Show("Unable to load files Has this one already been loaded?");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hit Exception:" + ex.ToString());
            }
            MessageBox.Show("Offload Complete! please unplug drive");
        }
        private async void Step4NextButton_Click(object sender, RoutedEventArgs e)
        {
            ProgressLabel.Content = "Copying...";
            Progress.Visibility   = Visibility.Visible;
            ProgressR.Visibility  = Visibility.Collapsed;
            ProgressB.Visibility  = Visibility.Visible;
            Step4.Visibility      = Visibility.Collapsed;


            var device = collection[DevicesListBox.SelectedIndex];


            PortableDeviceFolder f = foundFolders[FoldersListBox.SelectedIndex];


            ProgressLabel.Content = "Copying photos...";
            var photos = from b in f.Files
                         where (((System.IO.Path.GetExtension(b.Name).ToLower().Contains("jpg")) && (!b.Name.ToLower().Contains("highres"))) || (System.IO.Path.GetExtension(b.Name).ToLower().Contains("nar")) || (System.IO.Path.GetExtension(b.Name).ToLower().Contains("thm")) || (System.IO.Path.GetExtension(b.Name).ToLower().Contains("tnl")))
                         select b;

            await CopyFiles(device, photos, Properties.Settings.Default.Path1, Properties.Settings.Default.DeletePhotos, "", DateMethod.JpegData, "");

            ProgressLabel.Content = "Copying high resolution photos...";
            var hrphotos = from b in f.Files
                           where ((System.IO.Path.GetExtension(b.Name).ToLower().Contains("jpg")) && (b.Name.ToLower().Contains("highres")))
                           select b;

            await CopyFiles(device, hrphotos, Properties.Settings.Default.Path1, Properties.Settings.Default.DeleteHighResPhotos, "highres", DateMethod.JpegData, "");

            DestPathes.Clear(); //Avoid copying videos to photos folder.
            ProgressLabel.Content = "Copying videos...";
            // For some odd reason, videos doesn't have extension!!
            var videos = from b in f.Files
                         where !((System.IO.Path.GetExtension(b.Name).ToLower().Contains("jpg")) || (System.IO.Path.GetExtension(b.Name).ToLower().Contains("nar")) || (System.IO.Path.GetExtension(b.Name).ToLower().Contains("thm")) || (System.IO.Path.GetExtension(b.Name).ToLower().Contains("tnl")))
                         select b;


            await CopyFiles(device, videos, Properties.Settings.Default.Path2, Properties.Settings.Default.DeleteVideos, "", DateMethod.FileName, ".mp4");

            Progress.Visibility = Visibility.Collapsed;
            Step5.Visibility    = Visibility.Visible;
        }
Exemplo n.º 26
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);
                }
            }
        }
Exemplo n.º 27
0
        private void FetchContents(PortableDevice portableDevice, PortableDeviceFolder deviceFolder)
        {
            try
            {
                foreach (var fileObject in deviceFolder.Files)
                {
                    if (_activeDevice != null && _activeDevice.ImportOption == DeviceImportOption.Never)
                    {
                        break;
                    }

                    if (_activeDevice != null && StoredDevices.SingleOrDefault(p => p.Id.Equals(_activeDevice.Id)) == null)
                    {
                        break;
                    }

                    if (fileObject is PortableDeviceFile)
                    {
                        if (Common.Utilities.Utility.FileExtensions.IsValidFileExtension(Path.GetExtension(fileObject.Name.ToLower())))
                        {
                            Console.WriteLine("{0} {1}", fileObject.Id, fileObject.Name);

                            string str = (string.IsNullOrEmpty(fileObject.Name) ? Path.GetFileName(fileObject.Id) : Path.GetFileName(fileObject.Name));
                            if (!File.Exists(Path.Combine(_defaultMediaBackupPath, str)))
                            {
                                Console.WriteLine("{0} {1}", fileObject.Id, fileObject.Name);
                                portableDevice.CopyFilefromDevice((PortableDeviceFile)fileObject, DefaultMediaBackupPath);
                            }
                        }
                    }
                    else
                    {
                        FetchContents(portableDevice, (PortableDeviceFolder)fileObject);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 28
0
        public static (int?, PortableDevice, PortableDeviceFolder) ConnectAndGetDeviceAndDirectory(
            string deviceId,
            string directoryPath)
        {
            int?           exitCode;
            PortableDevice device;

            (exitCode, device) = GetDevice(deviceId);
            if (exitCode.HasValue)
            {
                return(exitCode.Value, null, null);
            }

            PortableDeviceFolder directory = default;

            Spinner.Start("Connecting to device ...", spinner =>
            {
                device.Connect();

                spinner.Text      = "Listing contents ...";
                var rootDirectory = device.GetContents();

                (exitCode, directory) = GetDirectory(rootDirectory, directoryPath);

                if (exitCode.HasValue)
                {
                    spinner.Fail("Failed to list contents");
                }
                else
                {
                    spinner.Succeed("Connected and contents listed");
                }
            });

            if (exitCode.HasValue)
            {
                return(exitCode.GetValueOrDefault(EXIT_CODE_UNKNOWN_COMMAND), null, null);
            }

            return(null, device, directory);
        }
Exemplo n.º 29
0
        private async Task CopyDeviceContents(Device device)
        {
            Task.Run(() =>
            {
                PortableDevice portableDevice = null;
                try
                {
                    if (_connectedDeviceCollection != null &&
                        _connectedDeviceCollection.Count > 0)
                    {
                        //get the connect device of same Id
                        portableDevice = _connectedDeviceCollection.
                                         SingleOrDefault(p => p.DeviceId.Equals(device.Id));

                        if (portableDevice != null)
                        {
                            portableDevice.Connect();

                            //set active device to curren-device
                            _activeDevice = device;
                            PortableDeviceFolder deviceFolder = portableDevice.GetContents();
                            FetchContents(portableDevice, deviceFolder);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //log exception
                }
                finally
                {
                    if (portableDevice != null)
                    {
                        portableDevice.Disconnect();
                    }
                    _activeDevice = null;
                }
            });
        }
Exemplo n.º 30
0
        public static void CopyFolderInsideVincapture(PortableDevice device, PortableDeviceFolder vinFolder,
                                                      string baseUrl)
        {
            foreach (var tmp in vinFolder.Files)
            {
                if (tmp is PortableDeviceFolder)
                {
                    var folderPath = baseUrl + "\\" + tmp.Name;
                    if (!Directory.Exists(folderPath))
                    {
                        Directory.CreateDirectory(folderPath);
                    }
                    CopyFolderInsideVincapture(device, (PortableDeviceFolder)tmp, folderPath);
                }
                if (tmp is PortableDeviceFile)
                {
                    var tmpFile = (PortableDeviceFile)tmp;

                    device.DownloadFile(tmpFile, baseUrl);
                }
            }
        }
Exemplo n.º 31
0
        private long EnumerateContents(PortableDevice portableDevice, PortableDeviceFolder deviceFolder)
        {
            try
            {
                foreach (var fileObject in deviceFolder.Files)
                {
                    if (_activeDevice != null && _activeDevice.ImportOption == DeviceImportOption.Never)
                    {
                        break;
                    }

                    if (fileObject is PortableDeviceFile)
                    {
                        if (Common.Utilities.Utility.FileExtensions.IsValidFileExtension(Path.GetExtension(fileObject.Name.ToLower())))
                        {
                            string str = (string.IsNullOrEmpty(fileObject.Name)? Path.GetFileName(fileObject.Id)
                                : Path.GetFileName(fileObject.Name));

                            if (!File.Exists(Path.Combine(_defaultMediaBackupPath, str)))
                            {
                                Console.WriteLine("{0} {1}", fileObject.Id, fileObject.Name);
                                _fileCounter++;
                            }
                        }
                    }
                    else
                    {
                        EnumerateContents(portableDevice, (PortableDeviceFolder)fileObject);
                    }
                }
                return(_fileCounter);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 32
0
        private string DisplayFolderContents(PortableDeviceFolder folder)
        {
            bool first = true;
            string output = "";

            foreach (var item in folder.Files)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    output += Environment.NewLine;
                }

                output += item.Id;
                if (item is PortableDeviceFolder)
                {
                    output +=
                        DisplayFolderContents((PortableDeviceFolder)item);
                }

                if (item is PortableDeviceFile)
                {
                    if (_currentDevice != null)
                    {
                        PortableDeviceFile pdf = (PortableDeviceFile)item;

                        _currentDevice.DownloadFile(pdf, @"c:\kindle\");
                        output += "downloaded " + pdf.Name;
                    }
                }
            }

            return output;
        }
Exemplo n.º 33
0
        public override void RefreshContents()
        {
            var root = new PortableDeviceFolder("DEVICE", "DEVICE");

            IPortableDeviceContent content;
            this.portableDevice.Content(out content);
            EnumerateContents(ref content, root);

            deviceContents = root;
        }
Exemplo n.º 34
0
 /*
  * Checking DCIM folder for photos and adding this photos to LinkedList
  * Recursive
  * @param PortableDeviceFolder
  * */
 private void CheckFolderContents(PortableDeviceFolder folder)
 {
     foreach (var item in folder.Files)
     {
         if (item is PortableDeviceFolder) CheckFolderContents((PortableDeviceFolder)item);
         else if (item is PortableDeviceFile)
         {
             string extension = System.IO.Path.GetExtension(item.Name);
             string[] popularPhotosExtensions = { ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".raw", ".tif", "tiff" };
             string[] anotherRawExtensions = { ".crw", ".cr2", ".dcs",".dcr", ".drf", ".k25", ".kdc",
                     ".dng", ".bay", ".erf", ".raf", ".3fr", ".fff", ".mos", ".pnx", ".mef",
                     ".mrw", ".nef", ".nrw", ".orf", ".rw2", ".ptx", ".pef", ".cap", ".iiq",
                     ".eip", ".rwz", ".r3d", ".x3f", ".arw", ".srf", ".srz" };
             string[] videosExtensions = { ".avi", ".mov", ".mp4", "m4v", ".mxf", ".wmv", ".3gp", ".flv" };
             if (popularPhotosExtensions.Contains(extension.ToLower())) photos.AddLast((PortableDeviceFile)item);
             else if (videosExtensions.Contains(extension.ToLower())) photos.AddLast((PortableDeviceFile)item);
             else if (anotherRawExtensions.Contains(extension.ToLower())) photos.AddLast((PortableDeviceFile)item);
         }
     }
 }
Exemplo n.º 35
0
        public PortableDeviceFolder GetContents()
        {
            var root = new PortableDeviceFolder("DEVICE", "DEVICE");

            IPortableDeviceContent content;

            this._device.Content(out content);
            EnumerateContents(ref content, root);

            return root;
        }
Exemplo n.º 36
0
 /*
  * Checking foder for DCIM folder
  * This function don't add photos to LinkedList of PortableDeviceFile
  * Recursive
  * @param PortableDeviceFolder
  * */
 private void CheckFolderContentsNDCIM(PortableDeviceFolder folder)
 {
     foreach (var item in folder.Files)
     {
         if (item is PortableDeviceFolder)
         {
             if (item.Name.Equals("DCIM")) CheckFolderContents((PortableDeviceFolder)item);
             else CheckFolderContentsNDCIM((PortableDeviceFolder)item);
         }
     }
 }