From ff55be0f5bb4ff1ad73cbf8853ad4a4687dbf90e Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 4 May 2018 11:33:16 -0400 Subject: [PATCH] Improve dme modifications --- .../Components/DreamMaker.cs | 11 ++++-- .../Components/IConfiguration.cs | 4 +- .../Components/ServerSideModifications.cs | 38 +++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 src/Tgstation.Server.Host/Components/ServerSideModifications.cs diff --git a/src/Tgstation.Server.Host/Components/DreamMaker.cs b/src/Tgstation.Server.Host/Components/DreamMaker.cs index 4abd5e10b5..0300c94352 100644 --- a/src/Tgstation.Server.Host/Components/DreamMaker.cs +++ b/src/Tgstation.Server.Host/Components/DreamMaker.cs @@ -181,16 +181,21 @@ namespace Tgstation.Server.Host.Components var dmeModifications = await dmeModificationsTask.ConfigureAwait(false); - if (!dmeModifications.Any()) + if (dmeModifications == null || dmeModifications.TotalDmeOverwrite) return; var dmeLines = new List(dme.Split(new[] { Environment.NewLine }, StringSplitOptions.None)); for (var I = 0; I < dmeLines.Count; ++I) { var line = dmeLines[I]; - if (line.Contains("BEGIN_INCLUDE")) + if (line.Contains("BEGIN_INCLUDE") && dmeModifications.HeadIncludeLine != null) { - dmeLines.InsertRange(I + 1, dmeModifications); + dmeLines.Insert(I + 1, dmeModifications.HeadIncludeLine); + ++I; + } + else if (line.Contains("END_INCLUDE") && dmeModifications.TailIncludeLine != null) + { + dmeLines.Insert(I - 1, dmeModifications.TailIncludeLine); break; } } diff --git a/src/Tgstation.Server.Host/Components/IConfiguration.cs b/src/Tgstation.Server.Host/Components/IConfiguration.cs index 3a6f2f0ded..3b31dda93e 100644 --- a/src/Tgstation.Server.Host/Components/IConfiguration.cs +++ b/src/Tgstation.Server.Host/Components/IConfiguration.cs @@ -16,8 +16,8 @@ namespace Tgstation.Server.Host.Components /// /// Path to the destination folder /// The for the operation - /// A resultin in a of #include lines for the .dm files copied - Task> CopyDMFilesTo(string destination, CancellationToken cancellationToken); + /// A resulting in the if any + Task CopyDMFilesTo(string destination, CancellationToken cancellationToken); /// /// Symlinks all directories in the GameData directory to diff --git a/src/Tgstation.Server.Host/Components/ServerSideModifications.cs b/src/Tgstation.Server.Host/Components/ServerSideModifications.cs new file mode 100644 index 0000000000..a9edcb1ddc --- /dev/null +++ b/src/Tgstation.Server.Host/Components/ServerSideModifications.cs @@ -0,0 +1,38 @@ +using System; + +namespace Tgstation.Server.Host.Components +{ + /// + /// Represents code modifications via configuration + /// + sealed class ServerSideModifications + { + /// + /// If the target dme was completely overwitten + /// + public bool TotalDmeOverwrite { get; } + + /// + /// The #include line which should be added to the beginning of the .dme if any + /// + public string HeadIncludeLine { get; } + + /// + /// The #include line which should be added to the end of the .dme if any + /// + public string TailIncludeLine { get; } + + /// + /// Construct + /// + /// The value of + /// The value of + /// The value of + public ServerSideModifications(string headIncludeLine, string tailIncludeLine, bool totalDmeOverwrite) + { + HeadIncludeLine = headIncludeLine; + TailIncludeLine = tailIncludeLine; + TotalDmeOverwrite = totalDmeOverwrite; + } + } +}