Exemplo n.º 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();
            }
        }
Exemplo n.º 2
0
        protected void DirectoryCopy(string sourceDirName, string destDirName, ICorrespondingPath correspondingPath, bool isRecursive = true)
        {
            DirectoryInfo dir = new DirectoryInfo(sourceDirName);

            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException(
                          $"Source directory does not exist or could not be found: {sourceDirName}");
            }

            if (BlackList.IsDirBlackListed(dir.FullName))
            {
                return;
            }

            DirectoryInfo[] dirs = dir.GetDirectories();

            if (Directory.Exists(destDirName))
            {
                ClearDirectory(destDirName);
            }

            if (isRecursive)
            {
                foreach (DirectoryInfo subdir in dirs)
                {
                    string temppath = Path.Combine(destDirName, subdir.Name);
                    DirectoryCopy(subdir.FullName, temppath, correspondingPath);
                }
            }

            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                FileCopy(file, Path.Combine(destDirName, file.Name), correspondingPath);
            }

            if (isRecursive)
            {
                foreach (DirectoryInfo subdir in dirs)
                {
                    string        temppath = Path.Combine(destDirName, subdir.Name);
                    DirectoryInfo tempdir  = new DirectoryInfo(temppath);

                    if (Directory.Exists(destDirName) && tempdir.GetFileSystemInfos().Length == 0)
                    {
                        Directory.Delete(temppath, true);
                        Console.WriteLine($"Cleaned up empty folder:       {temppath}");

                        var dirmeta = temppath + ".meta";
                        if (File.Exists(dirmeta))
                        {
                            File.Delete(dirmeta);
                            Console.WriteLine($"Cleaned up empty folder .meta: {dirmeta}");
                        }
                    }
                }
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args).WithParsed(o =>
            {
                var externalFolderPath = Path.Combine(o.coreRootPath, "External/MirroredPackageSources/com.unity.ui.builder/");
                var jsonRootDir        = Path.Combine(Directory.GetCurrentDirectory(), "JsonFiles");

                BlackList.Initialize(Path.Combine(jsonRootDir, "blacklist.json"), o);

                var generalPathsConverter   = new PathsConverter(Path.Combine(jsonRootDir, "general.json"));
                var shaderPathsConverter    = new ShaderPathConverter(Path.Combine(jsonRootDir, "shaders.json"));
                var projectPathsConverter   = new PathsConverter(Path.Combine(jsonRootDir, "projects.json"));
                var resourcesPathsConverter = new PathsConverter(Path.Combine(jsonRootDir, "resources.json"));

                var pathConverterList = new List <IPathsConverter>()
                {
                    generalPathsConverter, shaderPathsConverter, projectPathsConverter
                };

                var hashValidator = new HashValidator(o, externalFolderPath);
                if (o.validate && !o.syncCoreToPackage && !hashValidator.IsHashValid(pathConverterList))
                {
                    throw new Exception("Some files have change since last code drop");
                }

                var fileDropperList = new List <FileDropper>()
                {
                    new GeneralFileDropper(o, generalPathsConverter),
                    new ShaderFileDropper(o, shaderPathsConverter),
                    new ProjectFileDropper(o, projectPathsConverter),
                    new ResourcesFileDropper(o, resourcesPathsConverter)
                };

                foreach (var fileDropper in fileDropperList)
                {
                    fileDropper.Run();
                }

                if (!o.syncCoreToPackage)
                {
                    hashValidator.RegenerateHashes(pathConverterList);
                }
            });
        }