Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostBuild blacklist wildcards #303

Closed
Sshnyari opened this issue Oct 27, 2016 · 2 comments
Closed

PostBuild blacklist wildcards #303

Sshnyari opened this issue Oct 27, 2016 · 2 comments

Comments

@Sshnyari
Copy link
Contributor

Hi,

Is it possible to add suport for wildcards (*, ?) in i18n.BlackList ?

For the moment, I created a custom app setting (ExtendedBlackList) and a postbuild app that uses it to fill i18n.BlackList with the correct values, before doing the same job as i18n.PostBuild.exe

For example, it takes : "*/subfolder/" from i18n.ExtendedBlackList and puts "folder1/subfolder;folder2/subfolder" into i18n.BlackList

Here is the code portion that does that :

IEnumerable<string> blacklist = blacklistsetting.Split(';'); string editedblacklist = string.Join(";", TransformTokens(blacklist, root)); config.SetSetting("i18n.BlackList", editedblacklist);

`
private static string allToken = "*";
private static string oneToken = "?";

    private static IEnumerable<string> TransformTokens(IEnumerable<string> paths, string root)
    {
        return paths.SelectMany(p => TransformToken(p, root));
    }

    private static IEnumerable<string> TransformToken(string path, string root)
    {
        List<string> paths = new List<string>();
        if (HasSearchCharacter(path))
        {
            string[] parts = path.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            paths = GetPaths(parts, root).ToList();
        }
        else
        {
            paths.Add(path);
        }
        return paths;
    }

    private static IEnumerable<string> GetPaths(string[] parts, string root)
    {
        if (parts == null || parts.Length == 0)
        {
            return new [] { root };
        }

        List<string> paths = new List<string>();
        if (HasSearchCharacter(parts[0]))
        {
            string[] list = Directory.GetDirectories(root, parts[0]);
            foreach (string path in list)
            {
                paths.AddRange(GetPaths(parts.Skip(1).ToArray(), path));
            }
        }
        else
        {
            return GetPaths(parts.Skip(1).ToArray(), Path.Combine(root, parts[0]));
        }

        return paths;
    }

    private static string GetRootPath(AbstractSettingService settingService)
    {
        var startPath = Path.GetDirectoryName(settingService.GetConfigFileLocation());
        if (startPath != null)
            return Path.GetFullPath(startPath);
        return null;
    }

    private static bool HasSearchCharacter(string s)
    {
        return s.Contains(allToken) || s.Contains(oneToken);
    }

`

@turquoiseowl
Copy link
Owner

Sounds like a nice feature. If you would care to submit a PR (prefereably with unit tests) then we can add it.

@Sshnyari
Copy link
Contributor Author

Sshnyari commented Nov 3, 2016

Here is a patch containing changes for 303 and 304 (simpler to apply since there are new files used for both)
file.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants