Exemple #1
0
        private void ExploreDeviceDirectory(PortableDeviceContainerObject container, SynchronizedDirectory parentDirectory, int remaingDepthToIgnore)
        {
            if (remaingDepthToIgnore == 0)
            {
                parentDirectory.ObjectOnDevice = container;
            }

            foreach (var child in container.Childs)
            {
                var fileObject = child as PortableDeviceFileObject;
                if (fileObject != null)
                {
                    if (remaingDepthToIgnore > 0)
                    {
                        continue;
                    }

                    var file = new SynchronizedFile();
                    file.Parent = parentDirectory;
                    file.Name   = fileObject.FileName;
                    file.ComputePath();
                    file.SizeOnDevice   = fileObject.Size;
                    file.IsOnDevice     = true;
                    file.ObjectOnDevice = fileObject;

                    parentDirectory.Files.Add(file);
                }
                else
                {
                    var containerObject = child as PortableDeviceContainerObject;
                    if (containerObject != null)
                    {
                        if (remaingDepthToIgnore > 0)
                        {
                            ExploreDeviceDirectory(containerObject, parentDirectory, remaingDepthToIgnore - 1);
                        }
                        else
                        {
                            var directory = new SynchronizedDirectory();
                            directory.Parent = parentDirectory;
                            directory.Name   = containerObject.Name;
                            directory.ComputePath();
                            directory.IsOnDevice     = true;
                            directory.ObjectOnDevice = containerObject;

                            ExploreDeviceDirectory(containerObject, directory, remaingDepthToIgnore - 1);

                            parentDirectory.Directories.Add(directory);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private bool ExploreComputerDirectory(DirectoryInfo container, SynchronizedDirectory parentDirectory)
        {
            var shouldBeSynchronized = container.GetFiles(_options.SynchronizationMarkerFileName).Length > 0;

            if (shouldBeSynchronized)
            {
                foreach (var child in container.GetFiles())
                {
                    if (child.Name == _options.SynchronizationMarkerFileName)
                    {
                        continue;
                    }
                    var file = parentDirectory.Files.FirstOrDefault(x => x.Name.ToLower() == child.Name.ToLower());
                    if (file == null)
                    {
                        file        = new SynchronizedFile();
                        file.Parent = parentDirectory;
                        file.Name   = child.Name;
                        file.ComputePath();
                        parentDirectory.Files.Add(file);
                    }
                    file.IsOnComputer     = true;
                    file.SizeOnComputer   = child.Length;
                    file.ObjectOnComputer = child;
                }
            }

            foreach (var child in container.GetDirectories())
            {
                var directory = parentDirectory.Directories.FirstOrDefault(x => x.Name.ToLower() == child.Name.ToLower());
                if (directory == null)
                {
                    directory        = new SynchronizedDirectory();
                    directory.Parent = parentDirectory;
                    directory.Name   = child.Name;
                    directory.ComputePath();
                    parentDirectory.Directories.Add(directory);
                }

                var childShouldBeSynchronized = ExploreComputerDirectory(child, directory);
                shouldBeSynchronized = shouldBeSynchronized || childShouldBeSynchronized;
            }

            parentDirectory.IsOnComputer     = shouldBeSynchronized;
            parentDirectory.ObjectOnComputer = container;
            return(shouldBeSynchronized);
        }