@@ -14,6 +14,7 @@ namespace WGetNET
1414 /// </summary>
1515 public class WinGetInfo
1616 {
17+ private const string _infoCmd = "--info" ;
1718 private const string _versionCmd = "--version" ;
1819 private const string _exportSettingsCmd = "settings export" ;
1920
@@ -219,6 +220,98 @@ public async Task<bool> ExportSettingsToFileAsync(string file)
219220 }
220221 }
221222
223+ /// <summary>
224+ /// Gets all WinGet related data provided by the WinGet info action.
225+ /// </summary>
226+ /// <returns>
227+ /// A <see cref="WGetNET.WinGetData"/> containing winget related information.
228+ /// </returns>
229+ /// <exception cref="WGetNET.WinGetNotInstalledException">
230+ /// WinGet is not installed or not found on the system.
231+ /// </exception>
232+ /// <exception cref="WGetNET.WinGetActionFailedException">
233+ /// The current action failed for an unexpected reason.
234+ /// Please see inner exception.
235+ /// </exception>
236+ public WinGetData GetWinGetData ( )
237+ {
238+ try
239+ {
240+ ProcessResult result =
241+ _processManager . ExecuteWingetProcess ( _infoCmd ) ;
242+
243+ InfoActionVersionId actionVersionId = InfoActionVersionId . VersionRange1 ;
244+ if ( CheckWinGetVersion ( new Version ( 1 , 4 , 3531 ) , new Version ( 1 , 5 , 101 ) ) )
245+ {
246+ actionVersionId = InfoActionVersionId . VersionRange2 ;
247+ }
248+ else if ( CheckWinGetVersion ( new Version ( 1 , 5 , 441 ) , new Version ( 1 , 5 , 441 ) ) )
249+ {
250+ actionVersionId = InfoActionVersionId . VersionRange3 ;
251+ }
252+ else if ( CheckWinGetVersion ( new Version ( 1 , 5 , 1081 ) ) )
253+ {
254+ actionVersionId = InfoActionVersionId . VersionRange4 ;
255+ }
256+
257+ return ProcessOutputReader . ToWingetData ( result . Output , actionVersionId ) ;
258+ }
259+ catch ( Win32Exception )
260+ {
261+ throw new WinGetNotInstalledException ( ) ;
262+ }
263+ catch ( Exception e )
264+ {
265+ throw new WinGetActionFailedException ( "Getting data failed." , e ) ;
266+ }
267+ }
268+
269+ /// <summary>
270+ /// Asynchronous gets all WinGet related data provided by the WinGet info action.
271+ /// </summary>
272+ /// <returns>
273+ /// A <see cref="WGetNET.WinGetData"/> containing winget related information.
274+ /// </returns>
275+ /// <exception cref="WGetNET.WinGetNotInstalledException">
276+ /// WinGet is not installed or not found on the system.
277+ /// </exception>
278+ /// <exception cref="WGetNET.WinGetActionFailedException">
279+ /// The current action failed for an unexpected reason.
280+ /// Please see inner exception.
281+ /// </exception>
282+ public async Task < WinGetData > GetWinGetDataAsync ( )
283+ {
284+ try
285+ {
286+ ProcessResult result =
287+ await _processManager . ExecuteWingetProcessAsync ( _infoCmd ) ;
288+
289+ InfoActionVersionId actionVersionId = InfoActionVersionId . VersionRange1 ;
290+ if ( CheckWinGetVersion ( new Version ( 1 , 4 , 3531 ) , new Version ( 1 , 5 , 101 ) ) )
291+ {
292+ actionVersionId = InfoActionVersionId . VersionRange2 ;
293+ }
294+ else if ( CheckWinGetVersion ( new Version ( 1 , 5 , 441 ) , new Version ( 1 , 5 , 441 ) ) )
295+ {
296+ actionVersionId = InfoActionVersionId . VersionRange3 ;
297+ }
298+ else if ( CheckWinGetVersion ( new Version ( 1 , 5 , 1081 ) ) )
299+ {
300+ actionVersionId = InfoActionVersionId . VersionRange4 ;
301+ }
302+
303+ return ProcessOutputReader . ToWingetData ( result . Output , actionVersionId ) ;
304+ }
305+ catch ( Win32Exception )
306+ {
307+ throw new WinGetNotInstalledException ( ) ;
308+ }
309+ catch ( Exception e )
310+ {
311+ throw new WinGetActionFailedException ( "Getting data failed." , e ) ;
312+ }
313+ }
314+
222315 /// <summary>
223316 /// Checks if the installed WinGet version is between the given versions or the same.
224317 /// </summary>
@@ -233,8 +326,10 @@ public async Task<bool> ExportSettingsToFileAsync(string file)
233326 protected bool CheckWinGetVersion ( Version minVersion , Version ? maxVersion = null )
234327 {
235328 Version winGetVersion = WinGetVersionObject ;
236- if ( ( winGetVersion . Major >= minVersion . Major && winGetVersion . Minor >= minVersion . Minor && winGetVersion . Build >= minVersion . Build ) &&
237- ( ( maxVersion == null ) || ( winGetVersion . Major <= maxVersion . Major && winGetVersion . Minor <= maxVersion . Minor && winGetVersion . Build <= maxVersion . Build ) ) )
329+ if ( ( winGetVersion . Major >= minVersion . Major && winGetVersion . Minor >= minVersion . Minor &&
330+ ( ( winGetVersion . Minor != minVersion . Minor ) || ( winGetVersion . Minor == minVersion . Minor && winGetVersion . Build >= minVersion . Build ) ) ) &&
331+ ( ( maxVersion == null ) || ( winGetVersion . Major <= maxVersion . Major && winGetVersion . Minor <= maxVersion . Minor &&
332+ ( ( winGetVersion . Minor != maxVersion . Minor ) || ( winGetVersion . Minor == maxVersion . Minor && winGetVersion . Build <= maxVersion . Build ) ) ) ) )
238333 {
239334 return true ;
240335 }
0 commit comments