WGet.NET 4.4.1
A WinGet wrapper library for .Net.
Loading...
Searching...
No Matches
WinGetPackage.cs
1//--------------------------------------------------//
2// Created by basicx-StrgV //
3// https://github.com/basicx-StrgV/ //
4//--------------------------------------------------//
5using System;
8
9namespace WGetNET
10{
14 public class WinGetPackage : IWinGetObject, ICloneable
15 {
19 public string Name
20 {
21 get
22 {
23 return _name;
24 }
25 }
26
30 public string Id
31 {
32 get
33 {
34 return _id;
35 }
36 }
37
41 public string VersionString
42 {
43 get
44 {
45 return _versionString;
46 }
47 }
48
53 {
54 get
55 {
56 return _version;
57 }
58 }
59
64 {
65 get
66 {
67 return _availableVersionString;
68 }
69 }
70
75 {
76 get
77 {
78 return _availableVersion;
79 }
80 }
81
85 public string SourceName
86 {
87 get
88 {
89 return _sourceName;
90 }
91 }
92
99 public bool HasShortenedId
100 {
101 get
102 {
103 return _hasShortenedId;
104 }
105 }
106
114 public bool HasNoId
115 {
116 get
117 {
118 if (string.IsNullOrWhiteSpace(_id))
119 {
120 return true;
121 }
122
123 return false;
124 }
125 }
126
130 public bool HasUpgrade
131 {
132 get
133 {
134 if (_availableVersion > _version)
135 {
136 return true;
137 }
138
139 return false;
140 }
141 }
142
150 public bool IsEmpty
151 {
152 get
153 {
154 if (string.IsNullOrWhiteSpace(_id) && string.IsNullOrWhiteSpace(_name))
155 {
156 return true;
157 }
158 return false;
159 }
160 }
161
162 // \cond PRIVATE
163 private protected readonly string _name;
164 private protected readonly string _id;
165 private protected readonly string _versionString;
166 private protected readonly Version _version;
167 private protected readonly string _availableVersionString;
168 private protected readonly Version _availableVersion;
169 private protected readonly string _sourceName;
170
171 private protected readonly bool _hasShortenedId = false;
172 // \endcond
173
185 internal WinGetPackage(
186 string name,
187 string id,
188 string versionString,
189 Version version,
190 string availableVersionString,
191 Version availableVersion,
192 string sourceName,
193 bool hasShortenedId)
194 {
195 _name = name;
196 _id = id;
197
198 _versionString = versionString;
199 _version = version;
200
201 _availableVersionString = availableVersionString;
202 _availableVersion = availableVersion;
203
204 _sourceName = sourceName;
205
206 _hasShortenedId = hasShortenedId;
207 }
208
225 public static WinGetPackage Create(string name, string id, string version, string sourceName = "")
226 {
227 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name, "name");
228 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(id, "id");
229 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(version, "version");
230 ArgsHelper.ThrowIfObjectIsNull(sourceName, "sourceName");
231
232 WinGetPackageBuilder builder = new();
233
234 builder.AddName(name);
235 builder.AddId(id);
236 builder.AddVersion(version);
237 builder.AddSourceName(sourceName);
238
239 return builder.GetInstance();
240 }
241
259 public static WinGetPackage Create(string name, string id, string version, string availableVersion, string sourceName = "")
260 {
261 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name, "name");
262 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(id, "id");
263 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(version, "version");
264 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(availableVersion, "availableVersion");
265 ArgsHelper.ThrowIfObjectIsNull(sourceName, "sourceName");
266
267 WinGetPackageBuilder builder = new();
268
269 builder.AddName(name);
270 builder.AddId(id);
271 builder.AddVersion(version);
272 builder.AddAvailableVersion(availableVersion);
273 builder.AddSourceName(sourceName);
274
275 return builder.GetInstance();
276 }
277
294 public static WinGetPackage Create(string name, string id, Version version, string sourceName = "")
295 {
296 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name, "name");
297 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(id, "id");
298 ArgsHelper.ThrowIfObjectIsNull(version, "version");
299 ArgsHelper.ThrowIfObjectIsNull(sourceName, "sourceName");
300
301 WinGetPackageBuilder builder = new();
302
303 builder.AddName(name);
304 builder.AddId(id);
305 builder.AddVersion(version);
306 builder.AddSourceName(sourceName);
307
308 return builder.GetInstance();
309 }
310
328 public static WinGetPackage Create(string name, string id, Version version, Version availableVersion, string sourceName = "")
329 {
330 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(name, "name");
331 ArgsHelper.ThrowIfStringIsNullOrWhiteSpace(id, "id");
332 ArgsHelper.ThrowIfObjectIsNull(version, "version");
333 ArgsHelper.ThrowIfObjectIsNull(availableVersion, "availableVersion");
334 ArgsHelper.ThrowIfObjectIsNull(sourceName, "sourceName");
335
336 WinGetPackageBuilder builder = new();
337
338 builder.AddName(name);
339 builder.AddId(id);
340 builder.AddVersion(version);
341 builder.AddAvailableVersion(availableVersion);
342 builder.AddSourceName(sourceName);
343
344 return builder.GetInstance();
345 }
346
359 public bool SamePackage(WinGetPackage other, bool sameVersion = false)
360 {
361 if (other == null)
362 {
363 return false;
364 }
365
366 if (ReferenceEquals(this, other))
367 {
368 return true;
369 }
370
371 if (_id.Equals(other.Id) && _sourceName.Equals(other.SourceName) &&
372 (!sameVersion || (_versionString.Equals(other.VersionString) && _version.Equals(other.Version))))
373 {
374 return true;
375 }
376
377 return false;
378 }
379
381 public virtual object Clone()
382 {
383 return new WinGetPackage(
384 _name,
385 _id,
386 _versionString,
387 _version,
388 _availableVersionString,
389 _availableVersion,
390 _sourceName,
391 _hasShortenedId
392 );
393 }
394
396 public override string ToString()
397 {
398 return $"{_name} {_versionString}";
399 }
400 }
401}
Represents a winget package.
static WinGetPackage Create(string name, string id, Version version, string sourceName="")
Creates a new instance of the WGetNET.WinGetPackage class and returns it.
string VersionString
Gets the version of the package.
bool HasUpgrade
Gets if the package can be upgraded.
bool IsEmpty
Gets if the object is empty.
virtual object Clone()
override string ToString()
string Id
Gets the id of the package.
static WinGetPackage Create(string name, string id, Version version, Version availableVersion, string sourceName="")
Creates a new instance of the WGetNET.WinGetPackage class and returns it.
string Name
Gets the name of the package.
static WinGetPackage Create(string name, string id, string version, string sourceName="")
Creates a new instance of the WGetNET.WinGetPackage class and returns it.
string AvailableVersionString
Gets the newest available version of the package.
bool SamePackage(WinGetPackage other, bool sameVersion=false)
Checks if two packages are the same and optionally if they also have the same version.
string SourceName
Gets the source name for the package.
static WinGetPackage Create(string name, string id, string version, string availableVersion, string sourceName="")
Creates a new instance of the WGetNET.WinGetPackage class and returns it.
Version AvailableVersion
Gets the newest available version of the package.
bool HasShortenedId
Gets if id of the package is shortened.
Version Version
Gets the version of the package.
bool HasNoId
Gets if the package does not provide an id.
Interface for all winget related objects.