From 78c02a5530fa0801f8ae2f49955d7c13ed2a227f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 16 Oct 2021 17:50:59 +0200 Subject: [PATCH] allow specifying a project display name --- GameBundle/Options.cs | 5 ++--- GameBundle/Program.cs | 14 +++++++++----- Test/Bundle.bat | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/GameBundle/Options.cs b/GameBundle/Options.cs index 865ca17..f4d339e 100644 --- a/GameBundle/Options.cs +++ b/GameBundle/Options.cs @@ -11,21 +11,18 @@ namespace GameBundle { public string OutputDirectory { get; set; } [Option('v', "verbose")] public bool Verbose { get; set; } - [Option('w', "win", HelpText = "Bundle for windows")] public bool BuildWindows { get; set; } [Option('l', "linux", HelpText = "Bundle for linux")] public bool BuildLinux { get; set; } [Option('m', "mac", HelpText = "Bundle for mac")] public bool BuildMac { get; set; } - [Option('b', "mac-bundle", HelpText = "Create an app bundle for mac")] 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('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")] public IEnumerable ExcludedFiles { get; set; } [Option("32-bit", HelpText = "Publish for 32 bit instead of 64 bit. Note that this is only possible on Windows")] @@ -38,6 +35,8 @@ 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")] + 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 792b5d0..96568e1 100644 --- a/GameBundle/Program.cs +++ b/GameBundle/Program.cs @@ -49,7 +49,7 @@ namespace GameBundle { var dir = GetBuildDir(options, proj, "mac"); var res = Publish(options, proj, dir, "osx-x64", () => { if (options.MacBundle) - CreateMacBundle(options, new DirectoryInfo(dir), proj.FullName); + CreateMacBundle(options, new DirectoryInfo(dir), proj); }); if (res != 0) return res; @@ -63,7 +63,7 @@ namespace GameBundle { } private static int Publish(Options options, FileInfo proj, string path, string rid, Action additionalAction = null) { - var publishResult = RunProcess(options, "dotnet", $"publish {proj.FullName} -o {path} -r {rid} -c {options.BuildConfig} /p:PublishTrimmed={options.Trim} {options.BuildArgs}"); + var publishResult = RunProcess(options, "dotnet", $"publish \"{proj.FullName}\" -o \"{path}\" -r {rid} -c {options.BuildConfig} /p:PublishTrimmed={options.Trim} {options.BuildArgs}"); if (publishResult != 0) return publishResult; @@ -116,8 +116,8 @@ namespace GameBundle { return null; } - private static void CreateMacBundle(Options options, DirectoryInfo dir, string proj) { - var app = dir.CreateSubdirectory($"{Path.GetFileNameWithoutExtension(proj)}.app"); + private static void CreateMacBundle(Options options, DirectoryInfo dir, FileInfo proj) { + var app = dir.CreateSubdirectory($"{GetDisplayName(options, proj)}.app"); var contents = app.CreateSubdirectory("Contents"); var resources = contents.CreateSubdirectory("Resources"); var macOs = contents.CreateSubdirectory("MacOS"); @@ -146,9 +146,13 @@ namespace GameBundle { private static string GetBuildDir(Options options, FileInfo proj, string osName) { var dir = Path.GetFullPath(options.OutputDirectory); if (options.NameBuilds) - return $"{dir}/{Path.GetFileNameWithoutExtension(proj.Name)}-{osName}"; + return $"{dir}/{GetDisplayName(options, proj)}-{osName}"; return $"{dir}/{osName}"; } + private static string GetDisplayName(Options options, FileInfo proj) { + return string.IsNullOrEmpty(options.DisplayName) ? Path.GetFileNameWithoutExtension(proj.Name) : options.DisplayName; + } + } } \ No newline at end of file diff --git a/Test/Bundle.bat b/Test/Bundle.bat index 3c1ba7a..c75d2b4 100644 --- a/Test/Bundle.bat +++ b/Test/Bundle.bat @@ -1 +1 @@ -"../GameBundle/bin/Debug/netcoreapp3.1/GameBundle.exe" -wlm -bzn -s Test.csproj -o bin/Bundled -v \ No newline at end of file +"../GameBundle/bin/Debug/netcoreapp3.1/GameBundle.exe" -wlm -bzn -s Test.csproj -o bin/Bundled -v -d "Test Project" \ No newline at end of file