-
Notifications
You must be signed in to change notification settings - Fork 809
Expand file tree
/
Copy pathSerializablePackage.cs
More file actions
81 lines (71 loc) · 2.8 KB
/
SerializablePackage.cs
File metadata and controls
81 lines (71 loc) · 2.8 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
using System.Text.Json.Nodes;
using UniGetUI.Core.Data;
using UniGetUI.PackageEngine.Serializable;
namespace UniGetUI.PackageEngine.Classes.Serializable
{
public class SerializablePackage: SerializableComponent<SerializablePackage>
{
public string Id { get; set; } = "";
public string Name { get; set; } = "";
public string Version { get; set; } = "";
public string Source { get; set; } = "";
public string ManagerName { get; set; } = "";
public InstallOptions InstallationOptions { get; set; } = new();
public SerializableUpdatesOptions Updates { get; set; } = new();
public override SerializablePackage Copy()
{
return new SerializablePackage()
{
Name = this.Name,
Id = this.Id,
Version = this.Version,
Source = this.Source,
ManagerName = this.ManagerName,
InstallationOptions = this.InstallationOptions.Copy(),
Updates = this.Updates.Copy(),
};
}
public override void LoadFromJson(JsonNode data)
{
this.Name = data[nameof(Name)]?.GetVal<string>() ?? "";
this.Id = data[nameof(Id)]?.GetVal<string>() ?? "";
this.Version = data[nameof(Version)]?.GetVal<string>() ?? "";
this.Source = data[nameof(Source)]?.GetVal<string>() ?? "";
this.ManagerName = data[nameof(ManagerName)]?.GetVal<string>() ?? "";
this.InstallationOptions = new(data[nameof(InstallationOptions)] ?? new JsonObject());
this.Updates = new(data[nameof(Updates)] ?? new JsonObject());
}
public override JsonNode AsJsonNode()
{
JsonObject obj = new();
obj.Add(nameof(Id), Id);
obj.Add(nameof(Name), Name);
obj.Add(nameof(Version), Version);
obj.Add(nameof(Source), Source);
obj.Add(nameof(ManagerName), ManagerName);
obj.Add(nameof(InstallationOptions), InstallationOptions.AsJsonNode());
obj.Add(nameof(Updates), Updates.AsJsonNode());
return obj;
}
public SerializablePackage() : base()
{
}
public SerializablePackage(JsonNode data) : base(data)
{
}
/// <summary>
/// Returns an equivalent copy of the current package as an Invalid Serializable Package.
/// The reverse operation is not possible, since data is lost.
/// </summary>
public SerializableIncompatiblePackage GetInvalidEquivalent()
{
return new SerializableIncompatiblePackage
{
Id = Id,
Name = Name,
Version = Version,
Source = Source,
};
}
}
}