Skip to content

Commit 0bc612b

Browse files
Update to include the new JSON Structure with Explicit and TrustLevel
1 parent 7d7e5d3 commit 0bc612b

4 files changed

Lines changed: 492 additions & 75 deletions

File tree

src/WGet.NET/Data/WinGetSource.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using WGetNET.Models;
77
using WGetNET.Helper;
8+
using System.Collections.Generic;
89

910
namespace WGetNET
1011
{
@@ -82,6 +83,29 @@ public string Identifier
8283
}
8384
}
8485

86+
/// <summary>
87+
/// Gets whether the source was explicitly added.
88+
/// </summary>
89+
public bool Explicit
90+
{
91+
get
92+
{
93+
return _explicit;
94+
}
95+
}
96+
97+
/// <summary>
98+
/// Gets the trust level of the source.
99+
/// </summary>
100+
public List<string> TrustLevel
101+
{
102+
get
103+
{
104+
return _trustLevel;
105+
}
106+
}
107+
108+
85109
/// <inheritdoc/>
86110
public bool IsEmpty
87111
{
@@ -105,6 +129,8 @@ public bool IsEmpty
105129
private readonly string _type;
106130
private readonly string _data;
107131
private readonly string _identifier;
132+
private readonly bool _explicit;
133+
private readonly List<string> _trustLevel;
108134

109135
/// <summary>
110136
/// Initializes a new instance of the <see cref="WGetNET.WinGetSource"/> class.
@@ -115,13 +141,17 @@ public bool IsEmpty
115141
/// <param name="type">Type identifier of the source.</param>
116142
/// <param name="data">Data of the source source. This field is only used by some sources.</param>
117143
/// <param name="identifier">The identifier of the package</param>
118-
internal WinGetSource(string name, string arg, Uri? uri, string type, string identifier, string? data = null)
144+
/// <param name="explicitSource">Indicates if the source was explicitly added.</param>
145+
/// <param name="trustLevel">Trust level of the source.</param>
146+
internal WinGetSource(string name, string arg, Uri? uri, string type, string identifier, bool explicitSource = false, List<string>? trustLevel = default, string? data = null)
119147
{
120148
_name = name;
121149
_arg = arg;
122150
_uri = uri;
123151
_type = type;
124152
_identifier = identifier;
153+
_explicit = explicitSource;
154+
_trustLevel = trustLevel;
125155

126156
if (data != null)
127157
{
@@ -188,7 +218,7 @@ public static WinGetSource Create(string name, string identifier, string arg, st
188218

189219
Uri.TryCreate(arg, UriKind.Absolute, out Uri? uri);
190220

191-
return new WinGetSource(name, arg, uri, type, identifier, data);
221+
return new WinGetSource(name, arg, uri, type, identifier,data: data);
192222
}
193223

194224
/// <summary>
@@ -202,7 +232,7 @@ internal static WinGetSource FromSourceModel(SourceModel model)
202232
{
203233
Uri.TryCreate(model.Arg, UriKind.Absolute, out Uri? uri);
204234

205-
return new WinGetSource(model.Name, model.Arg, uri, model.Type, model.Identifier, model.Data);
235+
return new WinGetSource(model.Name, model.Arg, uri, model.Type, model.Identifier,model.Explicit, model.TrustLevel, model.Data);
206236
}
207237

208238
/// <inheritdoc/>
@@ -214,6 +244,8 @@ public object Clone()
214244
_uri,
215245
_type,
216246
_identifier,
247+
_explicit,
248+
_trustLevel,
217249
_data
218250
);
219251
}

src/WGet.NET/Models/SourceModel.cs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
// Created by basicx-StrgV //
33
// https://github.com/basicx-StrgV/ //
44
//--------------------------------------------------//
5+
using System.Collections.Generic;
6+
57
namespace WGetNET.Models
68
{
79
/// <summary>
8-
/// Represents a winget source for json parsing.
10+
/// Represents a winget source for JSON parsing.
911
/// </summary>
1012
internal class SourceModel
1113
{
@@ -54,7 +56,7 @@ public string Arg
5456
}
5557

5658
/// <summary>
57-
/// Gets sets the type of the source.
59+
/// Gets or sets the type of the source.
5860
/// </summary>
5961
public string Type
6062
{
@@ -119,18 +121,57 @@ public string Identifier
119121
}
120122
}
121123

124+
/// <summary>
125+
/// Gets or sets whether the source was explicitly added.
126+
/// </summary>
127+
public bool Explicit
128+
{
129+
get
130+
{
131+
return _explicit;
132+
}
133+
set
134+
{
135+
_explicit = value;
136+
}
137+
}
138+
139+
/// <summary>
140+
/// Gets or sets the trust level of the source.
141+
/// </summary>
142+
public List<string> TrustLevel
143+
{
144+
get
145+
{
146+
return _trustLevel;
147+
}
148+
set
149+
{
150+
if (value != null)
151+
{
152+
_trustLevel = value;
153+
}
154+
else
155+
{
156+
_trustLevel = new List<string>();
157+
}
158+
}
159+
}
160+
122161
private string _name = string.Empty;
123162
private string _arg = string.Empty;
124163
private string _type = string.Empty;
125164
private string _data = string.Empty;
126165
private string _identifier = string.Empty;
166+
private bool _explicit;
167+
private List<string> _trustLevel = new List<string>();
127168

128169
/// <summary>
129170
/// Initializes a new instance of the <see cref="WGetNET.Models.SourceModel"/> class.
130171
/// </summary>
131172
internal SourceModel()
132173
{
133-
// Empty constructor for json parsing.
174+
// Empty constructor for JSON parsing.
134175
}
135176

136177
/// <summary>
@@ -148,7 +189,9 @@ public static SourceModel FromWinGetSource(WinGetSource source)
148189
Arg = source.Arg,
149190
Type = source.Type,
150191
Data = source.Data,
151-
Identifier = source.Identifier
192+
Identifier = source.Identifier,
193+
Explicit = source.Explicit,
194+
TrustLevel = source.TrustLevel
152195
};
153196
}
154197
}

0 commit comments

Comments
 (0)