Skip to content

Commit 301ef1a

Browse files
authored
Merge pull request #42 from Biztactix-Ryan/main
Update to include the new JSON Structure with Explicit and TrustLevel and improving the test applications
2 parents 7d7e5d3 + 16cbd26 commit 301ef1a

5 files changed

Lines changed: 625 additions & 158 deletions

File tree

src/WGet.NET/Data/WinGetSource.cs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
// https://github.com/basicx-StrgV/ //
44
//--------------------------------------------------//
55
using System;
6-
using WGetNET.Models;
6+
using System.Collections.Generic;
77
using WGetNET.Helper;
8+
using WGetNET.Models;
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,25 @@ 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 = null, string? data = null)
119147
{
120148
_name = name;
121149
_arg = arg;
122150
_uri = uri;
123151
_type = type;
124152
_identifier = identifier;
153+
_explicit = explicitSource;
154+
155+
if (trustLevel != null)
156+
{
157+
_trustLevel = trustLevel;
158+
}
159+
else
160+
{
161+
_trustLevel = new List<string>();
162+
}
125163

126164
if (data != null)
127165
{
@@ -188,7 +226,7 @@ public static WinGetSource Create(string name, string identifier, string arg, st
188226

189227
Uri.TryCreate(arg, UriKind.Absolute, out Uri? uri);
190228

191-
return new WinGetSource(name, arg, uri, type, identifier, data);
229+
return new WinGetSource(name, arg, uri, type, identifier, data: data);
192230
}
193231

194232
/// <summary>
@@ -202,7 +240,7 @@ internal static WinGetSource FromSourceModel(SourceModel model)
202240
{
203241
Uri.TryCreate(model.Arg, UriKind.Absolute, out Uri? uri);
204242

205-
return new WinGetSource(model.Name, model.Arg, uri, model.Type, model.Identifier, model.Data);
243+
return new WinGetSource(model.Name, model.Arg, uri, model.Type, model.Identifier, model.Explicit, model.TrustLevel, model.Data);
206244
}
207245

208246
/// <inheritdoc/>
@@ -214,6 +252,8 @@ public object Clone()
214252
_uri,
215253
_type,
216254
_identifier,
255+
_explicit,
256+
_trustLevel,
217257
_data
218258
);
219259
}

src/WGet.NET/Models/SourceModel.cs

Lines changed: 36 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,46 @@ public string Identifier
119121
}
120122
}
121123

124+
/// <summary>
125+
/// Gets or sets whether the source was explicitly added.
126+
/// </summary>
127+
public bool Explicit { get; set; }
128+
129+
/// <summary>
130+
/// Gets or sets the trust level of the source.
131+
/// </summary>
132+
public List<string> TrustLevel
133+
{
134+
get
135+
{
136+
return _trustLevel;
137+
}
138+
set
139+
{
140+
if (value != null)
141+
{
142+
_trustLevel = value;
143+
}
144+
else
145+
{
146+
_trustLevel = new List<string>();
147+
}
148+
}
149+
}
150+
122151
private string _name = string.Empty;
123152
private string _arg = string.Empty;
124153
private string _type = string.Empty;
125154
private string _data = string.Empty;
126155
private string _identifier = string.Empty;
156+
private List<string> _trustLevel = new List<string>();
127157

128158
/// <summary>
129159
/// Initializes a new instance of the <see cref="WGetNET.Models.SourceModel"/> class.
130160
/// </summary>
131161
internal SourceModel()
132162
{
133-
// Empty constructor for json parsing.
163+
// Empty constructor for JSON parsing.
134164
}
135165

136166
/// <summary>
@@ -148,7 +178,9 @@ public static SourceModel FromWinGetSource(WinGetSource source)
148178
Arg = source.Arg,
149179
Type = source.Type,
150180
Data = source.Data,
151-
Identifier = source.Identifier
181+
Identifier = source.Identifier,
182+
Explicit = source.Explicit,
183+
TrustLevel = source.TrustLevel
152184
};
153185
}
154186
}

0 commit comments

Comments
 (0)