-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
627 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace Tgstation.Server.Api.Models | ||
{ | ||
/// <summary> | ||
/// The type of engine the codebase is using. | ||
/// </summary> | ||
public enum EngineType | ||
{ | ||
/// <summary> | ||
/// Build your own net dream, | ||
/// </summary> | ||
Byond, | ||
|
||
/// <summary> | ||
/// The OpenDream BYOND reimplementation. | ||
/// </summary> | ||
OpenDream, | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
src/Tgstation.Server.Api/Models/Internal/ByondVersion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
|
||
namespace Tgstation.Server.Api.Models.Internal | ||
{ | ||
/// <summary> | ||
/// Information about a Byond installation. | ||
/// </summary> | ||
public class ByondVersion : IEquatable<ByondVersion> | ||
{ | ||
/// <summary> | ||
/// The <see cref="EngineType"/>. | ||
/// </summary> | ||
[RequestOptions(FieldPresence.Required)] | ||
public EngineType? Engine { get; set; } | ||
|
||
/// <summary> | ||
/// The <see cref="System.Version"/> of the engine. | ||
/// </summary> | ||
[RequestOptions(FieldPresence.Required)] | ||
public Version? Version { get; set; } | ||
|
||
/// <summary> | ||
/// The git committish of the <see cref="Version"/>. On response, this will always be a commit SHA. | ||
/// </summary> | ||
[ResponseOptions] | ||
[StringLength(Limits.MaximumCommitShaLength)] | ||
public string? SourceCommittish { get; set; } | ||
|
||
/// <summary> | ||
/// Parses a stringified <see cref="ByondVersion"/>. | ||
/// </summary> | ||
/// <param name="input">The input <see cref="string"/>.</param> | ||
/// <param name="byondVersion">The output <see cref="ByondVersion"/>.</param> | ||
/// <returns><see langword="true"/> if parsing was successful, <see langword="false"/> otherwise.</returns> | ||
public static bool TryParse(string input, out ByondVersion byondVersion) | ||
{ | ||
if (input == null) | ||
throw new ArgumentNullException(nameof(input)); | ||
|
||
var splits = input.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries); | ||
byondVersion = new ByondVersion(); | ||
|
||
if (splits.Length > 2) | ||
return false; | ||
|
||
EngineType engine; | ||
if (splits.Length > 1) | ||
{ | ||
if (!Enum.TryParse(splits[0], out engine)) | ||
return false; | ||
} | ||
else | ||
engine = EngineType.Byond; | ||
|
||
byondVersion.Engine = engine; | ||
|
||
if (!Version.TryParse(splits.Last(), out var version)) | ||
return false; | ||
|
||
byondVersion.Version = version; | ||
|
||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ByondVersion"/> class. | ||
/// </summary> | ||
public ByondVersion() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ByondVersion"/> class. | ||
/// </summary> | ||
/// <param name="other">The <see cref="ByondVersion"/> to copy.</param> | ||
public ByondVersion(ByondVersion other) | ||
{ | ||
if (other == null) | ||
throw new ArgumentNullException(nameof(other)); | ||
|
||
Version = other.Version; | ||
Engine = other.Engine; | ||
SourceCommittish = other.SourceCommittish; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public bool Equals(ByondVersion other) | ||
{ | ||
// https://github.com/dotnet/roslyn-analyzers/issues/2875 | ||
#pragma warning disable CA1062 // Validate arguments of public methods | ||
return other!.Version == Version | ||
&& other.Engine == Engine; | ||
#pragma warning restore CA1062 // Validate arguments of public methods | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object obj) | ||
=> obj is ByondVersion other && Equals(other); | ||
|
||
/// <inheritdoc /> | ||
public override string ToString() => $"{(Engine != EngineType.Byond ? $"{Engine}-" : String.Empty)}{Version}"; // BYOND isn't display for backwards compatibility. SourceCommittish is not included | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() => ToString().GetHashCode(); | ||
} | ||
} |
9 changes: 3 additions & 6 deletions
9
src/Tgstation.Server.Api/Models/Request/ByondVersionDeleteRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
using System; | ||
|
||
using Tgstation.Server.Api.Models.Internal; | ||
|
||
namespace Tgstation.Server.Api.Models.Request | ||
{ | ||
/// <summary> | ||
/// A request to delete a specific <see cref="Version"/>. | ||
/// </summary> | ||
public class ByondVersionDeleteRequest | ||
public class ByondVersionDeleteRequest : ByondVersion | ||
{ | ||
/// <summary> | ||
/// The BYOND version to install. | ||
/// </summary> | ||
[RequestOptions(FieldPresence.Required)] | ||
public Version? Version { get; set; } | ||
} | ||
} |
15 changes: 12 additions & 3 deletions
15
src/Tgstation.Server.Api/Models/Request/ByondVersionRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
namespace Tgstation.Server.Api.Models.Request | ||
using System; | ||
|
||
using Tgstation.Server.Api.Models.Internal; | ||
|
||
namespace Tgstation.Server.Api.Models.Request | ||
{ | ||
/// <summary> | ||
/// A request to install a BYOND <see cref="ByondVersionDeleteRequest.Version"/>. | ||
/// A request to install a <see cref="ByondVersion"/>. | ||
/// </summary> | ||
public sealed class ByondVersionRequest : ByondVersionDeleteRequest | ||
public sealed class ByondVersionRequest : ByondVersion | ||
{ | ||
/// <summary> | ||
/// If a custom BYOND version is to be uploaded. | ||
/// </summary> | ||
public bool? UploadCustomZip { get; set; } | ||
|
||
/// <summary> | ||
/// The remote repository for non-<see cref="EngineType.Byond"/> <see cref="EngineType"/>s. By default, this is the original git repository of the target <see cref="EngineType"/>. | ||
/// </summary> | ||
public Uri? SourceRepository { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
using System; | ||
using Tgstation.Server.Api.Models.Internal; | ||
|
||
namespace Tgstation.Server.Api.Models.Response | ||
{ | ||
/// <summary> | ||
/// Represents an installed BYOND <see cref="Version"/>. | ||
/// Represents an installed <see cref="ByondVersion"/>. | ||
/// </summary> | ||
public sealed class ByondResponse | ||
public sealed class ByondResponse : ByondVersion | ||
{ | ||
/// <summary> | ||
/// The installed BYOND <see cref="System.Version"/>. BYOND itself only considers the <see cref="Version.Major"/> and <see cref="Version.Minor"/> numbers. TGS uses the <see cref="Version.Build"/> number to represent installed custom versions. | ||
/// Initializes a new instance of the <see cref="ByondResponse"/> class. | ||
/// </summary> | ||
[ResponseOptions] | ||
public Version? Version { get; set; } | ||
/// <param name="byondVersion">The <see cref="ByondVersion"/> to copy.</param> | ||
public ByondResponse(ByondVersion byondVersion) | ||
: base(byondVersion) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.