Exemple #1
0
        private void ReplaceInZipFile()
        {
            var entries     = _replacementOptions.SourcePath.ToFileEntryList();
            var ignoreFiles = entries.Where(x => x.Name.EndsWith(".gitignore"));

            foreach (var fileEntry in ignoreFiles)
            {
                _ignoreCopyParser.AddIgnoreFile(fileEntry.Name, fileEntry.GetLines());
            }

            foreach (var fileEntry in entries)
            {
                if (_ignoreCopyParser.IsIgnore(fileEntry.Name))
                {
                    continue;
                }

                var newEntry = Replace(fileEntry.Name, fileEntry);
                _outputFileEntryList.Add(newEntry);
            }

            var sourceFile  = new FileInfo(_replacementOptions.SourcePath);
            var newFileName = ReplacementHelper.ReplaceText(sourceFile.Name, _replacementOptions.Rules);

            if (!_outputFolderPath.EndsWith(newFileName))
            {
                _outputFolderPath = Path.Combine(_outputFolderPath, $"{newFileName}");
            }

            _outputFileEntryList.SaveToZipFile(_outputFolderPath);
        }
Exemple #2
0
        private void CopyWithIgnores(DirectoryInfo source, DirectoryInfo target, IgnoreParser parser)
        {
            Directory.CreateDirectory(target.FullName);

            foreach (var file in source.GetFiles().Where(f => !parser.IsIgnore(f, LogIgnore)))
            {
                file.CopyTo(Path.Combine(target.FullName, file.Name), true);
            }

            foreach (var subDir in source.GetDirectories().Where(d => !parser.IsIgnore(d, LogIgnore)))
            {
                CopyWithIgnores(subDir, target.CreateSubdirectory(subDir.Name), parser);
            }
        }
Exemple #3
0
        private FileEntry Replace(string sourcePath, FileEntry entry)
        {
            if (_replacementOptions.Rules.Any())
            {
                if (_ignoreReplaceParser.IsIgnore(sourcePath))
                {
                    // 它的路径还是要替换的

                    var oldPath    = entry.Name.Replace('/', Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
                    var postName   = oldPath.Split(Path.DirectorySeparatorChar).Last();
                    var newPrePath = ReplacementHelper.ReplaceText(oldPath.RemovePostFix(postName), _replacementOptions.Rules);

                    if (newPrePath != Path.DirectorySeparatorChar.ToString())
                    {
                        var newName = Path.Combine(newPrePath, postName);

                        if (entry.Name.EndsWith(Path.DirectorySeparatorChar))
                        {
                            newName = newName.EnsureEndsWith(Path.DirectorySeparatorChar);
                        }

                        entry.SetName(newName);
                        WriteLine($"{entry}");
                    }
                }
                else
                {
                    ReplacementHelper.Replace(entry, _replacementOptions.Rules);
                    WriteLine($"{entry}");
                }
            }

            return(entry);
        }