-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathModLinks.cs
More file actions
98 lines (81 loc) · 2.35 KB
/
ModLinks.cs
File metadata and controls
98 lines (81 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace ModlinksShaVerifier;
public static class SerializationConstants
{
public const string Namespace =
"https://github.com/HollowKnight-Modding/HollowKnight.ModLinks/HollowKnight.ModManager";
}
[Serializable]
[XmlRoot(Namespace = SerializationConstants.Namespace)]
public record Manifest
{
// Internally handle the Link/Links either-or divide
private Links? _links;
private Link? _link;
// The name is required on all manifests *except* for ApiLinks, so default to it.
public string Name { get; set; } = "ApiLinks";
[XmlElement]
public Link? Link
{
get => throw new NotImplementedException("This is only for XML Serialization!");
set => _link = value;
}
public Links Links
{
get => _links ??= new Links { Windows = _link ?? throw new InvalidOperationException("Object missing links!") };
set => _links = value;
}
public override string ToString()
{
return "{\n"
+ $"\t{nameof(Name)}: {Name},\n"
+ $"\t{nameof(Links)}: {(object?) _link ?? Links},\n"
+ "}";
}
}
public record Links
{
public Link Windows = null!;
public Link? Mac;
public Link? Linux;
public override string ToString()
{
return "Links {"
+ $"\t{nameof(Windows)} = {Windows},\n"
+ $"\t{nameof(Mac)} = {Mac},\n"
+ $"\t{nameof(Linux)} = {Linux}\n"
+ "}";
}
public IEnumerable<Link> AsEnumerable()
{
yield return Windows;
if (Mac is not null)
yield return Mac;
if (Linux is not null)
yield return Linux;
}
}
public record Link : IXmlSerializable
{
[XmlAttribute]
public string SHA256 = null!;
[XmlText]
public string URL = null!;
public override string ToString()
{
return $"[Link: {nameof(SHA256)} = {SHA256}, {nameof(URL)}: {URL}]";
}
public XmlSchema? GetSchema() => null;
public void ReadXml(XmlReader reader)
{
SHA256 = reader.GetAttribute(nameof(SHA256)) ?? throw new XmlException("Missing SHA256 attribute!");
URL = reader.ReadElementContentAsString().Trim();
}
public void WriteXml(XmlWriter writer)
{
}
}