mirror of
https://github.com/Ellpeck/GameBundle.git
synced 2024-11-22 08:43:28 +01:00
added the ability to include the version in the final output
This commit is contained in:
parent
4d686a3169
commit
5ebbd8e46b
4 changed files with 46 additions and 16 deletions
|
@ -2,7 +2,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using CommandLine;
|
using CommandLine;
|
||||||
|
|
||||||
namespace GameBundle;
|
namespace GameBundle;
|
||||||
|
|
||||||
public class Options {
|
public class Options {
|
||||||
|
|
||||||
|
@ -65,5 +65,7 @@ public class Options {
|
||||||
public bool NameBuilds { get; set; }
|
public bool NameBuilds { get; set; }
|
||||||
[Option('N', "name-addition", HelpText = "An additional string of text that should be included in the names of the output directories")]
|
[Option('N', "name-addition", HelpText = "An additional string of text that should be included in the names of the output directories")]
|
||||||
public string NameAddition { get; set; }
|
public string NameAddition { get; set; }
|
||||||
|
[Option('V', "include-version", HelpText = "Include the project's version in the names of the output directories")]
|
||||||
|
public bool IncludeVersion { get; set; }
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ 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 {
|
||||||
|
|
||||||
|
@ -74,19 +74,26 @@ internal static class Program {
|
||||||
return beautyResult;
|
return beautyResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add version if named builds are enabled
|
||||||
|
if (options.IncludeVersion) {
|
||||||
|
var version = Program.GetBuildVersion(buildDir);
|
||||||
|
if (version == null) {
|
||||||
|
Console.WriteLine("Couldn't determine build version, aborting");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var dest = Path.Combine(buildDir.Parent.FullName, $"{version}-{buildDir.Name}");
|
||||||
|
Program.MoveDirectory(options, buildDir, dest);
|
||||||
|
}
|
||||||
|
|
||||||
// Rename build folder if named builds are enabled
|
// Rename build folder if named builds are enabled
|
||||||
if (options.NameBuilds) {
|
if (options.NameBuilds) {
|
||||||
var name = Program.GetBuildName(options, buildDir);
|
var name = Program.GetBuildName(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;
|
||||||
}
|
}
|
||||||
var dest = Path.Combine(buildDir.Parent.FullName, $"{name}-{buildDir.Name}");
|
var dest = Path.Combine(buildDir.Parent.FullName, $"{name}-{buildDir.Name}");
|
||||||
if (Directory.Exists(dest))
|
Program.MoveDirectory(options, buildDir, dest);
|
||||||
Directory.Delete(dest, true);
|
|
||||||
buildDir.MoveTo(dest);
|
|
||||||
if (options.Verbose)
|
|
||||||
Console.WriteLine($"Moved build directory to {buildDir.FullName}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run any additional actions like creating the mac bundle
|
// Run any additional actions like creating the mac bundle
|
||||||
|
@ -134,7 +141,7 @@ internal static class Program {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int CreateMacBundle(Options options, DirectoryInfo buildDir) {
|
private static int CreateMacBundle(Options options, DirectoryInfo buildDir) {
|
||||||
var buildName = Program.GetBuildName(options, buildDir);
|
var buildName = Program.GetBuildName(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");
|
||||||
|
@ -183,19 +190,38 @@ internal static class Program {
|
||||||
return new DirectoryInfo(Path.Combine(Path.GetFullPath(options.OutputDirectory), name));
|
return new DirectoryInfo(Path.Combine(Path.GetFullPath(options.OutputDirectory), name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetBuildName(Options options, DirectoryInfo buildDir) {
|
private static string GetBuildName(DirectoryInfo buildDir) {
|
||||||
// determine build name based on the names of the exe or binary that have a matching dll file
|
return Path.GetFileNameWithoutExtension(Program.GetAssemblyFile(buildDir)?.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetBuildVersion(DirectoryInfo buildDir) {
|
||||||
|
var assemblyFile = Program.GetAssemblyFile(buildDir);
|
||||||
|
if (assemblyFile == null)
|
||||||
|
return null;
|
||||||
|
var version = FileVersionInfo.GetVersionInfo(assemblyFile.FullName);
|
||||||
|
return version.ProductVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static FileInfo GetAssemblyFile(DirectoryInfo buildDir) {
|
||||||
var files = buildDir.GetFiles();
|
var files = buildDir.GetFiles();
|
||||||
foreach (var file in files) {
|
foreach (var file in files) {
|
||||||
if (file.Extension != ".exe" && file.Extension != string.Empty)
|
if (file.Extension != ".dll")
|
||||||
continue;
|
continue;
|
||||||
var name = Path.GetFileNameWithoutExtension(file.Name);
|
// the assembly is (most likely) the dll file that has a matching binary or exe file in the same location
|
||||||
if (files.Any(f => f.Extension == ".dll" && Path.GetFileNameWithoutExtension(f.Name) == name))
|
if (files.Any(f => f.Extension is ".exe" or "" && Path.GetFileNameWithoutExtension(f.Name) == Path.GetFileNameWithoutExtension(file.Name)))
|
||||||
return name;
|
return file;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void MoveDirectory(Options options, DirectoryInfo dir, string dest) {
|
||||||
|
if (Directory.Exists(dest))
|
||||||
|
Directory.Delete(dest, true);
|
||||||
|
dir.MoveTo(dest!);
|
||||||
|
if (options.Verbose)
|
||||||
|
Console.WriteLine($"Moved build directory to {dir.FullName}");
|
||||||
|
}
|
||||||
|
|
||||||
private readonly struct BuildConfig {
|
private readonly struct BuildConfig {
|
||||||
|
|
||||||
public readonly string DisplayName;
|
public readonly string DisplayName;
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
"../GameBundle/bin/Debug/net6.0/GameBundle.exe" -wlmWL -bzn -s Test.csproj -o bin/Bundled -v --mac-bundle-ignore macmain.txt -N 1.0.0
|
rmdir /S /Q "bin/Bundled"
|
||||||
|
"../GameBundle/bin/Debug/net6.0/GameBundle.exe" -wlmWL -bznV -s Test.csproj -o bin/Bundled -v --mac-bundle-ignore macmain.txt -N beta
|
|
@ -6,6 +6,7 @@
|
||||||
<PublishReadyToRun>false</PublishReadyToRun>
|
<PublishReadyToRun>false</PublishReadyToRun>
|
||||||
<TieredCompilation>false</TieredCompilation>
|
<TieredCompilation>false</TieredCompilation>
|
||||||
<AssemblyName>Test Project</AssemblyName>
|
<AssemblyName>Test Project</AssemblyName>
|
||||||
|
<Version>1.2.3</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Reference in a new issue