added the option to create an app bundle for mac

This commit is contained in:
Ellpeck 2020-04-24 00:24:39 +02:00
parent dc77203ee2
commit ee2c51e648
6 changed files with 56 additions and 4 deletions

View file

@ -13,7 +13,7 @@
<PackageIconUrl>https://raw.githubusercontent.com/Ellpeck/GameBundle/master/Logo.png</PackageIconUrl>
<PackAsTool>true</PackAsTool>
<ToolCommandName>gamebundle</ToolCommandName>
<VersionPrefix>1.1.0</VersionPrefix>
<VersionPrefix>1.1.1</VersionPrefix>
</PropertyGroup>
<ItemGroup>

View file

@ -19,6 +19,11 @@ namespace GameBundle {
[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<string> MacBundleResources { get; set; }
[Option('e', "exclude", HelpText = "Files that should not be moved to the library folder")]
public IEnumerable<string> ExcludedFiles { get; set; }
[Option("32-bit", HelpText = "Publish for 32 bit instead of 64 bit. Note that this is only possible on Windows")]

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
@ -37,7 +38,10 @@ namespace GameBundle {
}
if (options.BuildMac) {
Console.WriteLine("Bundling for mac");
Publish(options, proj, $"{bundleDir}/mac", "osx-x64");
var dir = $"{bundleDir}/mac";
Publish(options, proj, dir, "osx-x64");
if (options.MacBundle)
CreateMacBundle(options, new DirectoryInfo(dir), proj.FullName);
}
Console.WriteLine("Done");
@ -82,5 +86,32 @@ namespace GameBundle {
return null;
}
private static void CreateMacBundle(Options options, DirectoryInfo dir, string proj) {
var app = dir.CreateSubdirectory($"{Path.GetFileNameWithoutExtension(proj)}.app");
var contents = app.CreateSubdirectory("Contents");
var resources = contents.CreateSubdirectory("Resources");
var macOs = contents.CreateSubdirectory("MacOS");
var resRegex = GlobRegex(options.MacBundleResources);
foreach (var file in dir.GetFiles()) {
var destDir = resRegex.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)
continue;
var destDir = resRegex.IsMatch(sub.Name) ? resources : macOs;
var dest = new DirectoryInfo(Path.Combine(destDir.FullName, sub.Name));
if (dest.Exists)
dest.Delete(true);
sub.MoveTo(dest.FullName);
}
}
private static Regex GlobRegex(IEnumerable<string> strings) {
return new Regex('(' + string.Join("|", strings.Select(s => s.Replace(".", "[.]").Replace("*", ".*").Replace("?", "."))) + ')');
}
}
}

View file

@ -25,6 +25,6 @@ gamebundle --help
# Future features
In the future, GameBundle plans to include the following features:
- An option to create a `.app` folder for Mac
- ~~An option to create a `.app` folder for Mac~~ Implemented in `1.1.1`
- An option to create an installer for Windows
- An option to create a flatpak (or similar) installer for Linux

View file

@ -1 +1 @@
"../GameBundle/bin/Debug/netcoreapp3.1/GameBundle.exe" -wlm -s Test.csproj -o bin/Bundled -v
"../GameBundle/bin/Debug/netcoreapp3.1/GameBundle.exe" -wlm -s Test.csproj -o bin/Bundled -v -b

View file

@ -1,13 +1,29 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Startup;
namespace Test {
public class GameImpl : MlemGame {
public static GameImpl Instance { get; private set; }
private Texture2D texture;
public GameImpl() {
Instance = this;
}
protected override void LoadContent() {
base.LoadContent();
this.texture = LoadContent<Texture2D>("Textures/Test");
}
protected override void DoDraw(GameTime gameTime) {
this.GraphicsDevice.Clear(Color.Black);
base.DoDraw(gameTime);
this.SpriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: Matrix.CreateScale(10));
this.SpriteBatch.Draw(this.texture, Vector2.Zero, Color.White);
this.SpriteBatch.End();
}
}
}