Skip to content

Commit

Permalink
Move to a new OpenDreamPackageTool project
Browse files Browse the repository at this point in the history
Ran into file locking issues with OpenDreamPackaging as a dependency
  • Loading branch information
wixoaGit committed Oct 20, 2023
1 parent c5d8ad5 commit 7bb3985
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 215 deletions.
13 changes: 13 additions & 0 deletions OpenDream.sln
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDreamPackaging", "OpenD
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Robust.Serialization.Generator", "RobustToolbox\Robust.Serialization.Generator\Robust.Serialization.Generator.csproj", "{366AA569-0889-491B-AB00-F038EAEC5221}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenDreamPackageTool", "OpenDreamPackageTool\OpenDreamPackageTool.csproj", "{351729DE-F70D-4136-AD48-1E08A715C1B1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -428,6 +430,16 @@ Global
{366AA569-0889-491B-AB00-F038EAEC5221}.Release|x64.Build.0 = Release|Any CPU
{366AA569-0889-491B-AB00-F038EAEC5221}.Tools|Any CPU.ActiveCfg = Debug|Any CPU
{366AA569-0889-491B-AB00-F038EAEC5221}.Tools|Any CPU.Build.0 = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|x64.ActiveCfg = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Debug|x64.Build.0 = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|Any CPU.Build.0 = Release|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|x64.ActiveCfg = Release|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Release|x64.Build.0 = Release|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Tools|Any CPU.ActiveCfg = Debug|Any CPU
{351729DE-F70D-4136-AD48-1E08A715C1B1}.Tools|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -459,6 +471,7 @@ Global
{CBF4EBB8-A6A0-446F-82D4-B1D24FF5B3FF} = {534AFACE-24AF-4F54-B7B0-951C5D62DF34}
{F3735A7F-44A2-4BEE-ADD6-952577D4DC33} = {DBFD7471-84E2-4AAB-86E9-F8DFF917ED5B}
{D080D3FA-CE53-40D2-AC9A-940FD9EB5055} = {DBFD7471-84E2-4AAB-86E9-F8DFF917ED5B}
{366AA569-0889-491B-AB00-F038EAEC5221} = {DBFD7471-84E2-4AAB-86E9-F8DFF917ED5B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {970174FD-D22D-44D9-A410-F82A015E6F74}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;

namespace OpenDreamPackaging;
namespace OpenDreamPackageTool;

public static class ClientPackaging {
private static readonly string[] ClientIgnoredResources = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace OpenDreamPackaging;
namespace OpenDreamPackageTool;

public record PlatformReg(string RId, string TargetOs, bool BuildByDefault) {
public string RId = RId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Diagnostics;
using System.IO.Compression;

namespace OpenDreamPackaging;
namespace OpenDreamPackageTool;

public static class ServerPackaging {
public static readonly PlatformReg[] Platforms = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;

namespace OpenDreamPackaging;
namespace OpenDreamPackageTool;

public static class TgsPackaging {
public static void Package(Program.TgsOptions options) {
Expand Down
213 changes: 2 additions & 211 deletions OpenDreamPackaging/Program.cs
Original file line number Diff line number Diff line change
@@ -1,216 +1,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace OpenDreamPackaging;

public static class Program {
public class Options {
public string OutputDir = "release/";
public bool SkipBuild;
}

public class ServerOptions : Options {
public PlatformReg? Platform;
public bool HybridAcz;
public bool InPlatformSubDir = true;
public bool TgsEngineBuild;
}

public class ClientOptions : Options {
public PlatformReg? Platform;
}

public class TgsOptions : Options {
public PlatformReg? Platform;
}

public static readonly string[] SharedIgnoredResources = {
".gitignore",
".directory",
".DS_Store"
};

public static int Main(string[] args) {
if (!TryParseArgs(args, out var options))
return 1;

switch (options) {
case ServerOptions serverOptions:
ServerPackaging.Package(serverOptions);
break;
case ClientOptions clientOptions:
ClientPackaging.Package(clientOptions);
break;
case TgsOptions tgsOptions:
TgsPackaging.Package(tgsOptions);
break;
}

return 0;
}

public static void RunSubProcess(ProcessStartInfo startInfo) {
using Process process = new();

process.StartInfo = startInfo;
process.OutputDataReceived += ProcessOutputDataReceived;
process.Start();
process.WaitForExit();
if (process.ExitCode != 0) {
Environment.Exit(process.ExitCode);
}
}

public static void CopyDirectory(string src, string dest, string[]? skip = null) {
skip ??= Array.Empty<string>();

var srcDir = new DirectoryInfo(src);
if (!srcDir.Exists)
throw new Exception($"Source directory not found: {src}");

Directory.CreateDirectory(dest);

foreach (var file in srcDir.EnumerateFiles()) {
if (skip.Contains(file.Name))
continue;

file.CopyTo(Path.Combine(dest, file.Name));
}

foreach (var subDir in srcDir.EnumerateDirectories()) {
if (skip.Contains(subDir.Name))
continue;

CopyDirectory(subDir.FullName, Path.Combine(dest, subDir.Name));
}
}

private static void ProcessOutputDataReceived(object sender, DataReceivedEventArgs args) {
if (args.Data == null)
return;

Console.Write(args.Data);
}

private static bool TryParseArgs(string[] args, [NotNullWhen(true)] out Options? options) {
if (args.Contains("--server")) {
var serverOptions = new ServerOptions();

options = serverOptions;
for (int i = 0; i < args.Length; i++) {
var arg = args[i];

switch (arg) {
case "--server":
break;
case "--output":
case "-o":
serverOptions.OutputDir = args[++i];
break;
case "--skip-build":
serverOptions.SkipBuild = true;
break;
case "--platform":
case "-p":
if (i + 1 >= args.Length) {
Console.Error.WriteLine("No platform given");
return false;
}

var platformRId = args[++i];

serverOptions.Platform =
ServerPackaging.Platforms.First(p => p.RId == platformRId);
if (serverOptions.Platform == null) {
Console.Error.WriteLine($"Invalid platform '{platformRId}'");
return false;
}

break;
case "--hybrid-acz":
serverOptions.HybridAcz = true;
break;
default:
Console.Error.WriteLine($"Unknown argument '{arg}'");
return false;
}
}

return true;
} else if (args.Contains("--client")) {
var clientOptions = new ClientOptions();

options = clientOptions;
for (int i = 0; i < args.Length; i++) {
var arg = args[i];

switch (arg) {
case "--client":
break;
case "--output":
case "-o":
clientOptions.OutputDir = args[++i];
break;
case "--skip-build":
clientOptions.SkipBuild = true;
break;
default:
Console.Error.WriteLine($"Unknown argument '{arg}'");
return false;
}
}

return true;
} else if (args.Contains("--tgs")) {
var tgsOptions = new TgsOptions();

options = tgsOptions;
for (int i = 0; i < args.Length; i++) {
var arg = args[i];

switch (arg) {
case "--tgs":
break;
case "--output":
case "-o":
tgsOptions.OutputDir = args[++i];
break;
case "--skip-build":
tgsOptions.SkipBuild = true;
break;
case "--platform":
case "-p":
if (i + 1 >= args.Length) {
Console.Error.WriteLine("No platform given");
return false;
}

var platformRId = args[++i];

tgsOptions.Platform =
ServerPackaging.Platforms.First(p => p.RId == platformRId);
if (tgsOptions.Platform == null) {
Console.Error.WriteLine($"Invalid platform '{platformRId}'");
return false;
}

break;
default:
Console.Error.WriteLine($"Unknown argument '{arg}'");
return false;
}
}

if (tgsOptions.Platform == null) {
Console.Error.WriteLine("A '--platform' argument is required for a tgs package");
return false;
}

return true;
}

options = null;
Console.Error.WriteLine("One of '--server' or '--client' must be given");
return false;
public static void Main() {
throw new NotImplementedException();
}
}

0 comments on commit 7bb3985

Please sign in to comment.