Esempio n. 1
0
        private IEnumerable<SourceAndDestination> GetRemoteFiles(IEnumerable<string> sources, string destination, bool destinationIsFile = false)
        {
            foreach (string source in sources)
            {
                // TODO: TEST WHEN THE ROOT DIRECTORY IS SELECTED
                string lastPart = source.Substring(source.LastIndexOf(Constants.PATH_SEPARATOR) + 1, source.Length - source.LastIndexOf(Constants.PATH_SEPARATOR) - 1);

                if (_iDeviceInterface.IsFile(source))
                {
                    string newDestination = destination;
                    string filename = lastPart;

                    if (destinationIsFile)
                    {
                        newDestination = Path.GetDirectoryName(destination);
                        filename = Path.GetFileName(destination);
                    }

                    SourceAndDestination lar = new SourceAndDestination(source, newDestination, FixFilename(filename), _iDeviceInterface.FileSize(source));

                    yield return lar;
                }
                else if (_iDeviceInterface.IsDirectory(source))
                {
                    foreach (string file in _iDeviceInterface.GetFiles(source))
                    {
                        // copy all files over recursively
                        IEnumerable<SourceAndDestination> files = GetRemoteFiles(new string[] { Utilities.PathCombine(source, file) }, Path.Combine(destination, lastPart));
                        foreach (SourceAndDestination f in files)
                        {
                            yield return f;
                        }
                    }

                    foreach (string directory in _iDeviceInterface.GetDirectories(source))
                    {
                        // copy all directories over recursively
                        IEnumerable<SourceAndDestination> filesFromDirectories = GetRemoteFiles(new string[] { Utilities.PathCombine(source, directory) }, Path.Combine(destination, lastPart));
                        foreach (SourceAndDestination file in filesFromDirectories)
                        {
                            yield return file;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private IEnumerable<SourceAndDestination> GetLocalFiles(IEnumerable<string> sources, string destination)
        {
            foreach (string source in sources)
            {
                if (File.Exists(source))
                {
                    string filename = Path.GetFileName(source);
                    FileInfo fi = new FileInfo(source);
                    SourceAndDestination lar = new SourceAndDestination(source, destination, UnfixFilename(filename), (ulong)fi.Length);

                    yield return lar;
                }
                else if (Directory.Exists(source))
                {
                    DirectoryInfo directoryInfo = new DirectoryInfo(source);
                    string directoryName = directoryInfo.Name;

                    IEnumerable<SourceAndDestination> files = GetLocalFiles(Directory.GetFiles(source), Path.Combine(destination, directoryName));
                    foreach (SourceAndDestination f in files)
                    {
                        yield return f;
                    }

                    // copy all directories over recursively
                    IEnumerable<SourceAndDestination> filesFromDirectories = GetLocalFiles(Directory.GetDirectories(source), Utilities.PathCombine(destination, directoryName));
                    foreach (SourceAndDestination file in filesFromDirectories)
                    {
                        yield return file;
                    }
                }
            }
        }