From 5ac15ed5b7d8feef0c4ae105762b66154c04eb96 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 16 Oct 2021 18:11:34 +0200 Subject: [PATCH] added the ability to exclude some files from the mac bundle --- GameBundle/Options.cs | 4 +++- GameBundle/Program.cs | 9 ++++++--- Test/Bundle.bat | 2 +- Test/Test.csproj | 1 + Test/macmain.txt | 1 + 5 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 Test/macmain.txt diff --git a/GameBundle/Options.cs b/GameBundle/Options.cs index f4d339e..6fd0234 100644 --- a/GameBundle/Options.cs +++ b/GameBundle/Options.cs @@ -21,6 +21,8 @@ namespace GameBundle { public bool MacBundle { get; set; } [Option("mac-bundle-resources", Default = new[] {"Content", "*.icns"}, HelpText = "When creating an app bundle for mac, things that should go into the Resources folder rather than the MacOS folder")] public IEnumerable MacBundleResources { get; set; } + [Option("mac-bundle-ignore", Default = new string[0], HelpText = "When creating an app bundle for mac, things that should be left out of the mac bundle and stay in the output folder")] + public IEnumerable MacBundleIgnore { get; set; } [Option('z', "zip", HelpText = "Store the build results in zip files instead of folders")] public bool Zip { get; set; } [Option('e', "exclude", HelpText = "Files that should not be moved to the library folder")] @@ -35,7 +37,7 @@ namespace GameBundle { public string LibFolder { get; set; } [Option('n', "name-builds", HelpText = "Name the build output directories by the project's name")] public bool NameBuilds { get; set; } - [Option('d', "display-name", HelpText = "The name that should be used for --name-builds and the app bundle instead of the project's name")] + [Option('d', "display-name", HelpText = "The name that should be used for named builds and the mac app bundle instead of the project's name")] public string DisplayName { get; set; } [Option('a', "build-args", HelpText = "Additional arguments that should be passed to the dotnet publish command")] public string BuildArgs { get; set; } diff --git a/GameBundle/Program.cs b/GameBundle/Program.cs index 96568e1..b29d3c4 100644 --- a/GameBundle/Program.cs +++ b/GameBundle/Program.cs @@ -68,9 +68,9 @@ namespace GameBundle { return publishResult; // Run beauty - var excludes = '"' + string.Join(";", options.ExcludedFiles) + '"'; + var excludes = $"\"{string.Join(";", options.ExcludedFiles)}\""; var log = options.Verbose ? "Detail" : "Error"; - var beautyResult = RunProcess(options, "dotnet", $"ncbeauty --loglevel={log} --force=True {path} {options.LibFolder} {excludes}", AppDomain.CurrentDomain.BaseDirectory); + var beautyResult = RunProcess(options, "dotnet", $"ncbeauty --loglevel={log} --force=True \"{path}\" \"{options.LibFolder}\" {excludes}", AppDomain.CurrentDomain.BaseDirectory); if (beautyResult != 0) return beautyResult; @@ -122,14 +122,17 @@ namespace GameBundle { var resources = contents.CreateSubdirectory("Resources"); var macOs = contents.CreateSubdirectory("MacOS"); var resRegex = options.MacBundleResources.Select(GlobRegex).ToArray(); + var ignoreRegex = options.MacBundleIgnore.Select(GlobRegex).ToArray(); foreach (var file in dir.GetFiles()) { + if (ignoreRegex.Any(r => r.IsMatch(file.Name))) + continue; var destDir = resRegex.Any(r => r.IsMatch(file.Name)) ? resources : macOs; if (file.Name.EndsWith("plist")) destDir = app; file.MoveTo(Path.Combine(destDir.FullName, file.Name), true); } foreach (var sub in dir.GetDirectories()) { - if (sub.Name == app.Name) + if (sub.Name == app.Name || ignoreRegex.Any(r => r.IsMatch(sub.Name))) continue; var destDir = resRegex.Any(r => r.IsMatch(sub.Name)) ? resources : macOs; var dest = new DirectoryInfo(Path.Combine(destDir.FullName, sub.Name)); diff --git a/Test/Bundle.bat b/Test/Bundle.bat index 53c1a42..8b44769 100644 --- a/Test/Bundle.bat +++ b/Test/Bundle.bat @@ -1 +1 @@ -"../GameBundle/bin/Debug/net5.0/GameBundle.exe" -wlm -bzn -s Test.csproj -o bin/Bundled -v -d "Test Project" \ No newline at end of file +"../GameBundle/bin/Debug/net5.0/GameBundle.exe" -wlm -bzn -s Test.csproj -o bin/Bundled -v -d "Test Project" --mac-bundle-ignore macmain.txt \ No newline at end of file diff --git a/Test/Test.csproj b/Test/Test.csproj index 9966a7d..e056db3 100644 --- a/Test/Test.csproj +++ b/Test/Test.csproj @@ -17,5 +17,6 @@ + \ No newline at end of file diff --git a/Test/macmain.txt b/Test/macmain.txt new file mode 100644 index 0000000..97e06b8 --- /dev/null +++ b/Test/macmain.txt @@ -0,0 +1 @@ +This file should not be added to the mac bundle \ No newline at end of file