mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 07:04:57 +01:00
Improve dme modifications
This commit is contained in:
@@ -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<string>(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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace Tgstation.Server.Host.Components
|
||||
/// </summary>
|
||||
/// <param name="destination">Path to the destination folder</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> resultin in a <see cref="IReadOnlyList{T}"/> of #include lines for the .dm files copied</returns>
|
||||
Task<IReadOnlyList<string>> CopyDMFilesTo(string destination, CancellationToken cancellationToken);
|
||||
/// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="ServerSideModifications"/> if any</returns>
|
||||
Task<ServerSideModifications> CopyDMFilesTo(string destination, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Symlinks all directories in the GameData directory to <paramref name="destination"/>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
|
||||
namespace Tgstation.Server.Host.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents code modifications via configuration
|
||||
/// </summary>
|
||||
sealed class ServerSideModifications
|
||||
{
|
||||
/// <summary>
|
||||
/// If the target dme was completely overwitten
|
||||
/// </summary>
|
||||
public bool TotalDmeOverwrite { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The #include line which should be added to the beginning of the .dme if any
|
||||
/// </summary>
|
||||
public string HeadIncludeLine { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The #include line which should be added to the end of the .dme if any
|
||||
/// </summary>
|
||||
public string TailIncludeLine { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Construct <see cref="ServerSideModifications"/>
|
||||
/// </summary>
|
||||
/// <param name="headIncludeLine">The value of <see cref="HeadIncludeLine"/></param>
|
||||
/// <param name="tailIncludeLine">The value of <see cref="TailIncludeLine"/></param>
|
||||
/// <param name="totalDmeOverwrite">The value of <see cref="TotalDmeOverwrite"/></param>
|
||||
public ServerSideModifications(string headIncludeLine, string tailIncludeLine, bool totalDmeOverwrite)
|
||||
{
|
||||
HeadIncludeLine = headIncludeLine;
|
||||
TailIncludeLine = tailIncludeLine;
|
||||
TotalDmeOverwrite = totalDmeOverwrite;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user