Skip to content

Commit 733e5ba

Browse files
committed
Added the WinGet download feature; Added the WinGetFeatureNotSupportedException class; Fixed typo
1 parent 630beea commit 733e5ba

9 files changed

Lines changed: 765 additions & 82 deletions

File tree

src/WGet.NET/Components/WinGetInfo.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,24 @@ public async Task<bool> ExportSettingsToFileAsync(string file)
219219
}
220220
}
221221

222+
/// <summary>
223+
/// Checks if the installed WinGet version is the same or higher as the given version.
224+
/// </summary>
225+
/// <param name="major">The major version.</param>
226+
/// <param name="minor">The minor version.</param>
227+
/// <returns>
228+
/// <see langword="true"/> if the installed WinGet version is the same or higher as the given version, or <see langword="false"/> if not.
229+
/// </returns>
230+
protected bool WinGetVersionIsMatchOrAbove(int major, int minor = 0)
231+
{
232+
Version winGetVersion = WinGetVersionObject;
233+
if (winGetVersion.Major >= major && winGetVersion.Minor >= minor)
234+
{
235+
return true;
236+
}
237+
return false;
238+
}
239+
222240
private string CheckWinGetVersion()
223241
{
224242
try

src/WGet.NET/Components/WinGetPackageManager.cs

Lines changed: 406 additions & 20 deletions
Large diffs are not rendered by default.

src/WGet.NET/Components/WinGetSourceManager.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class WinGetSourceManager : WinGetInfo
3030
/// </summary>
3131
public WinGetSourceManager()
3232
{
33-
//Provide empty constructor
33+
// Provide empty constructor for xlm docs
3434
}
3535

3636
//---List--------------------------------------------------------------------------------------
@@ -417,7 +417,7 @@ public async Task<bool> AddSourceAsync(WinGetSource source)
417417
/// This may take a while depending on the sources.
418418
/// </remarks>
419419
/// <returns>
420-
/// <see langword="true"/> if the update was successfull or <see langword="false"/> if the it failed.
420+
/// <see langword="true"/> if the update was successful or <see langword="false"/> if the it failed.
421421
/// </returns>
422422
/// <exception cref="WGetNET.WinGetNotInstalledException">
423423
/// WinGet is not installed or not found on the system.
@@ -453,7 +453,7 @@ public bool UpdateSources()
453453
/// </remarks>
454454
/// <returns>
455455
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
456-
/// The result is <see langword="true"/> if the update was successfull or <see langword="false"/> if the it failed.
456+
/// The result is <see langword="true"/> if the update was successful or <see langword="false"/> if the it failed.
457457
/// </returns>
458458
/// <exception cref="WGetNET.WinGetNotInstalledException">
459459
/// WinGet is not installed or not found on the system.
@@ -788,7 +788,7 @@ public async Task<List<WinGetSource>> ExportSourcesToObjectAsync(string sourceNa
788788
/// </summary>
789789
/// <param name="file">The file for the export.</param>
790790
/// <returns>
791-
/// <see langword="true"/> if the export was successfull or <see langword="false"/> if the it failed.
791+
/// <see langword="true"/> if the export was successful or <see langword="false"/> if the it failed.
792792
/// </returns>
793793
/// <exception cref="WGetNET.WinGetNotInstalledException">
794794
/// WinGet is not installed or not found on the system.
@@ -827,7 +827,7 @@ public bool ExportSourcesToFile(string file)
827827
/// <param name="file">The file for the export.</param>
828828
/// <param name="sourceName">The name of the source for the export.</param>
829829
/// <returns>
830-
/// <see langword="true"/> if the export was successfull or <see langword="false"/> if the it failed.
830+
/// <see langword="true"/> if the export was successful or <see langword="false"/> if the it failed.
831831
/// </returns>
832832
/// <exception cref="WGetNET.WinGetNotInstalledException">
833833
/// WinGet is not installed or not found on the system.
@@ -876,7 +876,7 @@ public bool ExportSourcesToFile(string file, string sourceName)
876876
/// The <see cref="WGetNET.WinGetSource"/> for the export.
877877
/// </param>
878878
/// <returns>
879-
/// <see langword="true"/> if the export was successfull or <see langword="false"/> if the it failed.
879+
/// <see langword="true"/> if the export was successful or <see langword="false"/> if the it failed.
880880
/// </returns>
881881
/// <exception cref="WGetNET.WinGetNotInstalledException">
882882
/// WinGet is not installed or not found on the system.
@@ -906,7 +906,7 @@ public bool ExportSourcesToFile(string file, WinGetSource source)
906906
/// <param name="file">The file for the export.</param>
907907
/// <returns>
908908
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
909-
/// The result is <see langword="true"/> if the export was successfull or <see langword="false"/> if the it failed.
909+
/// The result is <see langword="true"/> if the export was successful or <see langword="false"/> if the it failed.
910910
/// </returns>
911911
/// <exception cref="WGetNET.WinGetNotInstalledException">
912912
/// WinGet is not installed or not found on the system.
@@ -946,7 +946,7 @@ public async Task<bool> ExportSourcesToFileAsync(string file)
946946
/// <param name="sourceName">The name of the source for the export.</param>
947947
/// <returns>
948948
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
949-
/// The result is <see langword="true"/> if the export was successfull or <see langword="false"/> if the it failed.
949+
/// The result is <see langword="true"/> if the export was successful or <see langword="false"/> if the it failed.
950950
/// </returns>
951951
/// <exception cref="WGetNET.WinGetNotInstalledException">
952952
/// WinGet is not installed or not found on the system.
@@ -996,7 +996,7 @@ public async Task<bool> ExportSourcesToFileAsync(string file, string sourceName)
996996
/// </param>
997997
/// <returns>
998998
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
999-
/// The result is <see langword="true"/> if the export was successfull or <see langword="false"/> if the it failed.
999+
/// The result is <see langword="true"/> if the export was successful or <see langword="false"/> if the it failed.
10001000
/// </returns>
10011001
/// <exception cref="WGetNET.WinGetNotInstalledException">
10021002
/// WinGet is not installed or not found on the system.
@@ -1122,7 +1122,7 @@ await JsonHandler.StringToObjectAsync<WinGetSource>(jsonString.ToString())
11221122
/// A <see cref="System.Collections.Generic.List{T}"/> of <see cref="WGetNET.WinGetSource"/> objects.
11231123
/// </param>
11241124
/// <returns>
1125-
/// <see langword="true"/> if the action was successfull and <see langword="false"/> if on or more sorces failed.
1125+
/// <see langword="true"/> if the action was successful and <see langword="false"/> if on or more sorces failed.
11261126
/// </returns>
11271127
public bool ImportSource(List<WinGetSource> winGetSources)
11281128
{
@@ -1150,7 +1150,7 @@ public bool ImportSource(List<WinGetSource> winGetSources)
11501150
/// A <see cref="WGetNET.WinGetSource"/> objects.
11511151
/// </param>
11521152
/// <returns>
1153-
/// <see langword="true"/> if the action was successfull and <see langword="false"/> if it failed.
1153+
/// <see langword="true"/> if the action was successful and <see langword="false"/> if it failed.
11541154
/// </returns>
11551155
public bool ImportSource(WinGetSource winGetSource)
11561156
{
@@ -1164,7 +1164,7 @@ public bool ImportSource(WinGetSource winGetSource)
11641164
/// A <see cref="System.String"/> containing the json for ONE source.
11651165
/// </param>
11661166
/// <returns>
1167-
/// <see langword="true"/> if the action was successfull and <see langword="false"/> if it failed.
1167+
/// <see langword="true"/> if the action was successful and <see langword="false"/> if it failed.
11681168
/// </returns>
11691169
public bool ImportSource(string jsonString)
11701170
{
@@ -1183,7 +1183,7 @@ public bool ImportSource(string jsonString)
11831183
/// </param>
11841184
/// <returns>
11851185
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
1186-
/// The result is <see langword="true"/> if the action was successfull and <see langword="false"/> if on or more sorces failed.
1186+
/// The result is <see langword="true"/> if the action was successful and <see langword="false"/> if on or more sorces failed.
11871187
/// </returns>
11881188
public async Task<bool> ImportSourceAsync(List<WinGetSource> winGetSources)
11891189
{
@@ -1212,7 +1212,7 @@ public async Task<bool> ImportSourceAsync(List<WinGetSource> winGetSources)
12121212
/// </param>
12131213
/// <returns>
12141214
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
1215-
/// The result is <see langword="true"/> if the action was successfull and <see langword="false"/> if it failed.
1215+
/// The result is <see langword="true"/> if the action was successful and <see langword="false"/> if it failed.
12161216
/// </returns>
12171217
public async Task<bool> ImportSourceAsync(WinGetSource winGetSource)
12181218
{
@@ -1227,7 +1227,7 @@ public async Task<bool> ImportSourceAsync(WinGetSource winGetSource)
12271227
/// </param>
12281228
/// <returns>
12291229
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
1230-
/// The result is <see langword="true"/> if the action was successfull and <see langword="false"/> if it failed.
1230+
/// The result is <see langword="true"/> if the action was successful and <see langword="false"/> if it failed.
12311231
/// </returns>
12321232
public async Task<bool> ImportSourceAsync(string jsonString)
12331233
{
@@ -1253,7 +1253,7 @@ await JsonHandler.StringToObjectAsync<WinGetSource>(jsonString)
12531253
/// This may take a while depending on the sources.
12541254
/// </remarks>
12551255
/// <returns>
1256-
/// <see langword="true"/> if the reset was successfull or <see langword="false"/> if the it failed.
1256+
/// <see langword="true"/> if the reset was successful or <see langword="false"/> if the it failed.
12571257
/// </returns>
12581258
/// <exception cref="WGetNET.WinGetNotInstalledException">
12591259
/// WinGet is not installed or not found on the system.
@@ -1297,7 +1297,7 @@ public bool ResetSources()
12971297
/// </remarks>
12981298
/// <returns>
12991299
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
1300-
/// The result is <see langword="true"/> if the reset was successfull or <see langword="false"/> if the it failed.
1300+
/// The result is <see langword="true"/> if the reset was successful or <see langword="false"/> if the it failed.
13011301
/// </returns>
13021302
/// <exception cref="WGetNET.WinGetNotInstalledException">
13031303
/// WinGet is not installed or not found on the system.
@@ -1342,7 +1342,7 @@ public async Task<bool> ResetSourcesAsync()
13421342
/// A <see cref="System.String"/> representing the name of the source.
13431343
/// </param>
13441344
/// <returns>
1345-
/// <see langword="true"/> if the remove was successfull or <see langword="false"/> if the it failed.
1345+
/// <see langword="true"/> if the remove was successful or <see langword="false"/> if the it failed.
13461346
/// </returns>
13471347
/// <exception cref="WGetNET.WinGetNotInstalledException">
13481348
/// WinGet is not installed or not found on the system.
@@ -1390,7 +1390,7 @@ public bool RemoveSources(string name)
13901390
/// The <see cref="WGetNET.WinGetSource"/> to remove.
13911391
/// </param>
13921392
/// <returns>
1393-
/// <see langword="true"/> if the remove was successfull or <see langword="false"/> if the it failed.
1393+
/// <see langword="true"/> if the remove was successful or <see langword="false"/> if the it failed.
13941394
/// </returns>
13951395
/// <exception cref="WGetNET.WinGetNotInstalledException">
13961396
/// WinGet is not installed or not found on the system.
@@ -1425,7 +1425,7 @@ public bool RemoveSources(WinGetSource source)
14251425
/// </param>
14261426
/// <returns>
14271427
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
1428-
/// The result is <see langword="true"/> if the remove was successfull or <see langword="false"/> if the it failed.
1428+
/// The result is <see langword="true"/> if the remove was successful or <see langword="false"/> if the it failed.
14291429
/// </returns>
14301430
/// <exception cref="WGetNET.WinGetNotInstalledException">
14311431
/// WinGet is not installed or not found on the system.
@@ -1474,7 +1474,7 @@ public async Task<bool> RemoveSourcesAsync(string name)
14741474
/// </param>
14751475
/// <returns>
14761476
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
1477-
/// The result is <see langword="true"/> if the remove was successfull or <see langword="false"/> if the it failed.
1477+
/// The result is <see langword="true"/> if the remove was successful or <see langword="false"/> if the it failed.
14781478
/// </returns>
14791479
/// <exception cref="WGetNET.WinGetNotInstalledException">
14801480
/// WinGet is not installed or not found on the system.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//--------------------------------------------------//
2+
// Created by basicx-StrgV //
3+
// https://github.com/basicx-StrgV/ //
4+
//--------------------------------------------------//
5+
using System;
6+
using System.Runtime.Serialization;
7+
8+
namespace WGetNET
9+
{
10+
/// <summary>
11+
/// Exception that gets thrown if a winget feature is not supportet in the installed winget version.
12+
/// </summary>
13+
[Serializable]
14+
public class WinGetFeatureNotSupportedException : Exception
15+
{
16+
/// <summary>
17+
/// Gets a message that describes the current exception.
18+
/// </summary>
19+
public override string Message
20+
{
21+
get
22+
{
23+
if (string.IsNullOrWhiteSpace(_minVersion))
24+
{
25+
return "This feature is not supported in the installed WinGet version.";
26+
}
27+
28+
return $"This feature is not supported in the installed WinGet version. WinGet {_minVersion} or higher is needed to use this feature.";
29+
}
30+
31+
}
32+
33+
private readonly string _minVersion = "";
34+
35+
/// <summary>
36+
/// Initializes a new instance of the <see cref="WGetNET.WinGetFeatureNotSupportedException"/> class.
37+
/// </summary>
38+
/// <param name="minVersion">Min WinGet version needed for the feature</param>
39+
public WinGetFeatureNotSupportedException(string minVersion)
40+
{
41+
_minVersion = minVersion;
42+
}
43+
44+
/// <summary>
45+
/// Initializes a new instance of the <see cref="WGetNET.WinGetFeatureNotSupportedException"/> class.
46+
/// </summary>
47+
/// <param name="minVersion">Min WinGet version needed for the feature</param>
48+
/// <param name="innerException">The inner exception</param>
49+
public WinGetFeatureNotSupportedException(string minVersion, Exception innerException) : base(null, innerException)
50+
{
51+
_minVersion = minVersion;
52+
}
53+
54+
/// <summary>
55+
/// Initializes a new instance of the <see cref="WGetNET.WinGetFeatureNotSupportedException"/> class with serialized data.
56+
/// </summary>
57+
/// <param name="info">
58+
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
59+
/// that holds the serialized object data about the exception being thrown.
60+
/// </param>
61+
/// <param name="context">
62+
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
63+
/// that contains contextual information about the source or destination.
64+
/// </param>
65+
protected WinGetFeatureNotSupportedException(SerializationInfo info, StreamingContext context) : base(info, context)
66+
{
67+
}
68+
}
69+
}

src/WGet.NET/HelperClasses/FileHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal static class FileHandler
1919
/// A <see cref="System.String"/> containing the file path and name.
2020
/// </param>
2121
/// <returns>
22-
/// <see langword="true"/> if the action was successfull and <see langword="false"/> if it failed.
22+
/// <see langword="true"/> if the action was successful and <see langword="false"/> if it failed.
2323
/// </returns>
2424
public static bool ExportOutputToFile(ProcessResult result, string file)
2525
{
@@ -48,7 +48,7 @@ public static bool ExportOutputToFile(ProcessResult result, string file)
4848
/// </param>
4949
/// <returns>
5050
/// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
51-
/// The result is <see langword="true"/> if the action was successfull and <see langword="false"/> if it failed.
51+
/// The result is <see langword="true"/> if the action was successful and <see langword="false"/> if it failed.
5252
/// </returns>
5353
public static async Task<bool> ExportOutputToFileAsync(ProcessResult result, string file)
5454
{

src/WGet.NET/WGet.NET.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<Copyright>basicx-StrgV</Copyright>
1717
<SignAssembly>false</SignAssembly>
1818
<RootNamespace>WGetNET</RootNamespace>
19-
<Version>3.0.0-alpha2</Version>
19+
<Version>3.0.0</Version>
2020
<Deterministic>false</Deterministic>
2121
<AssemblyVersion>3.0.0.*</AssemblyVersion>
2222
<AssemblyName>WGet.NET</AssemblyName>

0 commit comments

Comments
 (0)