Example #1
0
        public ExportResult Export(string path)
        {
            ExportResult result = new ExportResult();

            Logger.Current.Log(LogCategory.Configuration, Settings);

            if (!Directory.Exists(path))
            {
                Logger.Current.Log(LogCategory.CreateDirectory, path);
                Directory.CreateDirectory(path);
            }

            foreach (string srcPath in GetFiles(_srcPath))
            {
                string relativePath = GetRelativePath(srcPath);
                relativePath = ApplyReplacements(relativePath);
                string dstPath = Path.Combine(path, relativePath);
                if (Directory.Exists(srcPath))
                {
                    result.Directories++;

                    if (ReparsePoint.IsSymbolicLink(srcPath))
                    {
                        if (Settings.KeepSymbolicLinks)
                        {
                            string link = ReparsePoint.GetTargetDir(new DirectoryInfo(srcPath));
                            ReparsePoint.CreateSymbolicLink(dstPath, link, SymbolicLinkType.Directory);
                            continue;
                        }
                    }

                    if (!Directory.Exists(dstPath))
                    {
                        Directory.CreateDirectory(dstPath);
                    }
                }
                else
                {
                    result.Files++;

                    if (ReparsePoint.IsSymbolicLink(srcPath))
                    {
                        if (Settings.KeepSymbolicLinks)
                        {
                            string link = ReparsePoint.GetTargetDir(new FileInfo(srcPath));
                            ReparsePoint.CreateSymbolicLink(dstPath, link, SymbolicLinkType.File);
                            continue;
                        }
                    }

                    CopyFile(srcPath, dstPath);
                }
            }

            return(result);
        }
Example #2
0
        private IEnumerable <string> GetFiles(string path)
        {
            if (!Directory.Exists(path))
            {
                yield break;
            }

            foreach (var file in Directory.GetFiles(path))
            {
                if (MustExclude(file))
                {
                    Logger.Current.Log(LogCategory.Exclude, file);
                }
                else
                {
                    Logger.Current.Log(LogCategory.Include, file);
                    yield return(file);
                }
            }

            foreach (var directory in Directory.GetDirectories(path))
            {
                if (MustExclude(directory))
                {
                    Logger.Current.Log(LogCategory.Exclude, directory);
                }
                else
                {
                    Logger.Current.Log(LogCategory.Include, directory);
                    yield return(directory);

                    if (Settings.KeepSymbolicLinks && ReparsePoint.IsSymbolicLink(directory))
                    {
                        continue;
                    }

                    foreach (var item in GetFiles(directory))
                    {
                        yield return(item);
                    }
                }
            }
        }