reformat & cleanup

This commit is contained in:
Ell 2022-08-17 21:51:38 +02:00
parent b3218532e8
commit 1142252015
6 changed files with 287 additions and 287 deletions

View file

@ -2,7 +2,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using CommandLine; using CommandLine;
namespace GameBundle { namespace GameBundle;
public class Options { public class Options {
[Option('s', "source", HelpText = "The location of the .csproj file that should be built and bundled. By default, the current directory is scanned for one")] [Option('s', "source", HelpText = "The location of the .csproj file that should be built and bundled. By default, the current directory is scanned for one")]
@ -66,4 +67,3 @@ namespace GameBundle {
public string NameAddition { get; set; } public string NameAddition { get; set; }
} }
}

View file

@ -7,24 +7,25 @@ using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using CommandLine; using CommandLine;
namespace GameBundle { namespace GameBundle;
internal static class Program { internal static class Program {
private static int Main(string[] args) { private static int Main(string[] args) {
return new Parser(c => { return new Parser(c => {
c.HelpWriter = Console.Error; c.HelpWriter = Console.Error;
c.EnableDashDash = true; c.EnableDashDash = true;
}).ParseArguments<Options>(args).MapResult(Run, _ => -1); }).ParseArguments<Options>(args).MapResult(Program.Run, _ => -1);
} }
private static int Run(Options options) { private static int Run(Options options) {
// make sure all of the required tools are installed // make sure all of the required tools are installed
if (RunProcess(options, "dotnet", "tool restore", AppDomain.CurrentDomain.BaseDirectory) != 0) { if (Program.RunProcess(options, "dotnet", "tool restore", AppDomain.CurrentDomain.BaseDirectory) != 0) {
Console.WriteLine("dotnet tool restore failed, aborting"); Console.WriteLine("dotnet tool restore failed, aborting");
return -1; return -1;
} }
var proj = GetProjectFile(options); var proj = Program.GetProjectFile(options);
if (proj == null || !proj.Exists) { if (proj == null || !proj.Exists) {
Console.WriteLine("Project file not found, aborting"); Console.WriteLine("Project file not found, aborting");
return -1; return -1;
@ -36,16 +37,16 @@ namespace GameBundle {
// regular builds // regular builds
new("windows", "win", options.WindowsRid, options.BuildWindows), new("windows", "win", options.WindowsRid, options.BuildWindows),
new("linux", "linux", options.LinuxRid, options.BuildLinux), new("linux", "linux", options.LinuxRid, options.BuildLinux),
new("mac", "mac", options.MacRid, options.BuildMac, false, d => options.MacBundle ? CreateMacBundle(options, d) : 0), new("mac", "mac", options.MacRid, options.BuildMac, false, d => options.MacBundle ? Program.CreateMacBundle(options, d) : 0),
// arm builds // arm builds
new("windows arm", "win-arm", options.WindowsArmRid, options.BuildWindowsArm, true), new("windows arm", "win-arm", options.WindowsArmRid, options.BuildWindowsArm, true),
new("linux arm", "linux-arm", options.LinuxArmRid, options.BuildLinuxArm, true), new("linux arm", "linux-arm", options.LinuxArmRid, options.BuildLinuxArm, true),
new("mac arm", "mac-arm", options.MacArmRid, options.BuildMacArm, true, d => options.MacBundle ? CreateMacBundle(options, d) : 0) new("mac arm", "mac-arm", options.MacArmRid, options.BuildMacArm, true, d => options.MacBundle ? Program.CreateMacBundle(options, d) : 0)
}; };
foreach (var config in toBuild) { foreach (var config in toBuild) {
if (config.ShouldBuild) { if (config.ShouldBuild) {
Console.WriteLine($"Bundling for {config.DisplayName}"); Console.WriteLine($"Bundling for {config.DisplayName}");
var res = Publish(options, proj, config); var res = Program.Publish(options, proj, config);
if (res != 0) if (res != 0)
return res; return res;
builtAnything = true; builtAnything = true;
@ -59,8 +60,8 @@ namespace GameBundle {
} }
private static int Publish(Options options, FileInfo proj, BuildConfig config) { private static int Publish(Options options, FileInfo proj, BuildConfig config) {
var buildDir = GetBuildDir(options, config.DirectoryName); var buildDir = Program.GetBuildDir(options, config.DirectoryName);
var publishResult = RunProcess(options, "dotnet", $"publish \"{proj.FullName}\" -o \"{buildDir.FullName}\" -r {config.Rid} --self-contained -c {options.BuildConfig} /p:PublishTrimmed={options.Trim} {options.BuildArgs}"); var publishResult = Program.RunProcess(options, "dotnet", $"publish \"{proj.FullName}\" -o \"{buildDir.FullName}\" -r {config.Rid} --self-contained -c {options.BuildConfig} /p:PublishTrimmed={options.Trim} {options.BuildArgs}");
if (publishResult != 0) if (publishResult != 0)
return publishResult; return publishResult;
@ -68,14 +69,14 @@ namespace GameBundle {
if (!options.SkipLib && !config.SkipLib) { if (!options.SkipLib && !config.SkipLib) {
var excludes = $"\"{string.Join(";", options.ExcludedFiles)}\""; var excludes = $"\"{string.Join(";", options.ExcludedFiles)}\"";
var log = options.Verbose ? "Detail" : "Error"; var log = options.Verbose ? "Detail" : "Error";
var beautyResult = RunProcess(options, "dotnet", $"ncbeauty --loglevel={log} --force=True --noflag=True \"{buildDir.FullName}\" \"{options.LibFolder}\" {excludes}", AppDomain.CurrentDomain.BaseDirectory); var beautyResult = Program.RunProcess(options, "dotnet", $"ncbeauty --loglevel={log} --force=True --noflag=True \"{buildDir.FullName}\" \"{options.LibFolder}\" {excludes}", AppDomain.CurrentDomain.BaseDirectory);
if (beautyResult != 0) if (beautyResult != 0)
return beautyResult; return beautyResult;
} }
// Rename build folder if named builds are enabled // Rename build folder if named builds are enabled
if (options.NameBuilds) { if (options.NameBuilds) {
var name = GetBuildName(options, buildDir); var name = Program.GetBuildName(options, buildDir);
if (name == null) { if (name == null) {
Console.WriteLine("Couldn't determine build name, aborting"); Console.WriteLine("Couldn't determine build name, aborting");
return -1; return -1;
@ -133,13 +134,13 @@ namespace GameBundle {
} }
private static int CreateMacBundle(Options options, DirectoryInfo buildDir) { private static int CreateMacBundle(Options options, DirectoryInfo buildDir) {
var buildName = GetBuildName(options, buildDir); var buildName = Program.GetBuildName(options, buildDir);
var app = buildDir.CreateSubdirectory($"{buildName}.app"); var app = buildDir.CreateSubdirectory($"{buildName}.app");
var contents = app.CreateSubdirectory("Contents"); var contents = app.CreateSubdirectory("Contents");
var resources = contents.CreateSubdirectory("Resources"); var resources = contents.CreateSubdirectory("Resources");
var macOs = contents.CreateSubdirectory("MacOS"); var macOs = contents.CreateSubdirectory("MacOS");
var resRegex = options.MacBundleResources.Select(GlobRegex).ToArray(); var resRegex = options.MacBundleResources.Select(Program.GlobRegex).ToArray();
var ignoreRegex = options.MacBundleIgnore.Select(GlobRegex).ToArray(); var ignoreRegex = options.MacBundleIgnore.Select(Program.GlobRegex).ToArray();
if (options.Verbose) if (options.Verbose)
Console.WriteLine($"Creating app bundle {app}"); Console.WriteLine($"Creating app bundle {app}");
@ -216,4 +217,3 @@ namespace GameBundle {
} }
} }
}

View file

@ -2,19 +2,20 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Graphics;
using MLEM.Startup; using MLEM.Startup;
namespace Test { namespace Test;
public class GameImpl : MlemGame { public class GameImpl : MlemGame {
public static GameImpl Instance { get; private set; } public static GameImpl Instance { get; private set; }
private Texture2D texture; private Texture2D texture;
public GameImpl() { public GameImpl() {
Instance = this; GameImpl.Instance = this;
} }
protected override void LoadContent() { protected override void LoadContent() {
base.LoadContent(); base.LoadContent();
this.texture = LoadContent<Texture2D>("Textures/Test"); this.texture = MlemGame.LoadContent<Texture2D>("Textures/Test");
} }
protected override void DoDraw(GameTime gameTime) { protected override void DoDraw(GameTime gameTime) {
@ -26,4 +27,3 @@ namespace Test {
} }
} }
}

View file

@ -1,7 +1,8 @@
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Misc; using MLEM.Misc;
namespace Test { namespace Test;
public static class Program { public static class Program {
public static void Main() { public static void Main() {
@ -11,4 +12,3 @@ namespace Test {
} }
} }
}