Beispiel #1
0
        public static void ClearDirectory(string dirFullPath)
        {
            if (!Directory.Exists(dirFullPath))
            {
                throw new DirectoryNotFoundException(
                          $"Source directory does not exist or could not be found: {dirFullPath}");
            }

            var directory = new DirectoryInfo(dirFullPath);

            foreach (var file in directory.EnumerateFiles())
            {
                if (!BlackList.IsFileBlackListed(file.FullName))
                {
                    file.Delete();
                }
            }

            foreach (var dir in directory.EnumerateDirectories())
            {
                if (!BlackList.IsFileBlackListed(dir.FullName))
                {
                    ClearDirectory(dir.FullName);
                }
            }

            if (directory.GetFiles().Length == 0 && directory.GetDirectories().Length == 0)
            {
                directory.Delete();
            }
        }
Beispiel #2
0
        protected bool FileCopy(FileInfo srcFile, string destFullPath, ICorrespondingPath correspondingPath)
        {
            var directoryName = Path.GetDirectoryName(destFullPath);

            Directory.CreateDirectory(directoryName);

            if (BlackList.IsFileBlackListed(srcFile.FullName))
            {
                return(false);
            }

            var ignoreExtension = correspondingPath.GetIgnoreExtension();

            if (!string.IsNullOrEmpty(ignoreExtension) && (srcFile.FullName.EndsWith(ignoreExtension) || srcFile.FullName.EndsWith(ignoreExtension + ".meta")))
            {
                return(false);
            }
            var ignoreExtensions = correspondingPath.GetIgnoreExtensions();

            foreach (var ext in ignoreExtensions)
            {
                if (!string.IsNullOrEmpty(ext) && (srcFile.FullName.EndsWith(ext) || srcFile.FullName.EndsWith(ext + ".meta")))
                {
                    return(false);
                }
            }

            if (srcFile.FullName.EndsWith(".meta") && !ShouldCopyMetaFile())
            {
                return(false);
            }

            if (ShouldModifyFile(srcFile.Name))
            {
                FileCopyAndModify(srcFile, destFullPath);
            }
            else if (srcFile.FullName.EndsWith(".cs") || srcFile.FullName.EndsWith(".uss") || srcFile.FullName.EndsWith(".uxml") || srcFile.FullName.EndsWith(".meta"))
            {
                FileCopy(srcFile, destFullPath);
            }
            else
            {
                srcFile.CopyTo(destFullPath, true);
            }

            return(true);
        }