WGet.NET 4.4.1
A WinGet wrapper library for .Net.
Loading...
Searching...
No Matches
WinGetSource.cs
1//--------------------------------------------------//
2// Created by basicx-StrgV //
3// https://github.com/basicx-StrgV/ //
4//--------------------------------------------------//
5using System;
6using System.Collections.Generic;
9
10namespace WGetNET
11{
15 public class WinGetSource : IWinGetObject, ICloneable
16 {
20 public string Name
21 {
22 get
23 {
24 return _name;
25 }
26 }
27
31 public string Arg
32 {
33 get
34 {
35 return _arg;
36 }
37 }
38
45 public Uri? Uri
46 {
47 get
48 {
49 return _uri;
50 }
51 }
52
56 public string Type
57 {
58 get
59 {
60 return _type;
61 }
62 }
63
67 public string Data
68 {
69 get
70 {
71 return _data;
72 }
73 }
74
78 public string Identifier
79 {
80 get
81 {
82 return _identifier;
83 }
84 }
85
89 public bool Explicit
90 {
91 get
92 {
93 return _explicit;
94 }
95 }
96
100 public List<string> TrustLevel
101 {
102 get
103 {
104 return _trustLevel;
105 }
106 }
107
108
110 public bool IsEmpty
111 {
112 get
113 {
114 if (string.IsNullOrWhiteSpace(_name) &&
115 string.IsNullOrWhiteSpace(_arg) &&
116 string.IsNullOrWhiteSpace(_type) &&
117 string.IsNullOrWhiteSpace(_data) &&
118 string.IsNullOrWhiteSpace(_identifier))
119 {
120 return true;
121 }
122 return false;
123 }
124 }
125
126 private readonly string _name;
127 private readonly string _arg;
128 private readonly Uri? _uri;
129 private readonly string _type;
130 private readonly string _data;
131 private readonly string _identifier;
132 private readonly bool _explicit;
133 private readonly List<string> _trustLevel;
134
146 internal WinGetSource(string name, string arg, Uri? uri, string type, string identifier, bool explicitSource = false, List<string>? trustLevel = null, string? data = null)
147 {
148 _name = name;
149 _arg = arg;
150 _uri = uri;
151 _type = type;
152 _identifier = identifier;
153 _explicit = explicitSource;
154
155 if (trustLevel != null)
156 {
157 _trustLevel = trustLevel;
158 }
159 else
160 {
161 _trustLevel = new List<string>();
162 }
163
164 if (data != null)
165 {
166 _data = data;
167 }
168 else
169 {
170 _data = string.Empty;
171 }
172 }
173
190 public static WinGetSource Create(string name, string identifier, string arg, string type)
191 {
192 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name, "name");
193 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(identifier, "identifier");
194 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(arg, "arg");
195 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(type, "type");
196
197 Uri.TryCreate(arg, UriKind.Absolute, out Uri? uri);
198
199 return new WinGetSource(name, arg, uri, type, identifier);
200 }
201
219 public static WinGetSource Create(string name, string identifier, string arg, string type, string data)
220 {
221 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name, "name");
222 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(identifier, "identifier");
223 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(arg, "url");
224 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(type, "type");
225 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(data, "data");
226
227 Uri.TryCreate(arg, UriKind.Absolute, out Uri? uri);
228
229 return new WinGetSource(name, arg, uri, type, identifier, data: data);
230 }
231
239 internal static WinGetSource FromSourceModel(SourceModel model)
240 {
241 Uri.TryCreate(model.Arg, UriKind.Absolute, out Uri? uri);
242
243 return new WinGetSource(model.Name, model.Arg, uri, model.Type, model.Identifier, model.Explicit, model.TrustLevel, model.Data);
244 }
245
247 public object Clone()
248 {
249 return new WinGetSource(
250 _name,
251 _arg,
252 _uri,
253 _type,
254 _identifier,
255 _explicit,
256 _trustLevel,
257 _data
258 );
259 }
260
262 public override string ToString()
263 {
264 return _name;
265 }
266 }
267}
Represents a winget source.
string Name
Gets the name of the source.
bool IsEmpty
Gets if the object is empty.
string Type
Gets the type of the source.
List< string > TrustLevel
Gets the trust level of the source.
bool Explicit
Gets whether the source was explicitly added.
Uri? Uri
Gets the uri of the source.
static WinGetSource Create(string name, string identifier, string arg, string type, string data)
Creates a new instance of the WGetNET.WinGetSource class and returns it.
string Identifier
Gets the identifier of the source.
static WinGetSource Create(string name, string identifier, string arg, string type)
Creates a new instance of the WGetNET.WinGetSource class and returns it.
override string ToString()
string Arg
Gets the URL/UNC of the source.
string Data
Gets the data of the source.
Interface for all winget related objects.