@@ -16,14 +16,6 @@ namespace WGetNET
1616 /// </summary>
1717 public class WinGet
1818 {
19- private protected ProcessManager ProcessManager
20- {
21- get
22- {
23- return _processManager ;
24- }
25- }
26-
2719 private const string _infoCmd = "--info" ;
2820 private const string _versionCmd = "--version" ;
2921 private const string _exportSettingsCmd = "settings export" ;
@@ -126,10 +118,7 @@ public WinGet()
126118 /// </exception>
127119 public string ExportSettings ( )
128120 {
129- ThrowIfNotInstalled ( ) ;
130-
131- ProcessResult result =
132- _processManager . ExecuteWingetProcess ( _exportSettingsCmd ) ;
121+ ProcessResult result = Execute ( _exportSettingsCmd ) ;
133122
134123 return ProcessOutputReader . ExportOutputToString ( result ) ;
135124 }
@@ -146,10 +135,7 @@ public string ExportSettings()
146135 /// </exception>
147136 public async Task < string > ExportSettingsAsync ( )
148137 {
149- ThrowIfNotInstalled ( ) ;
150-
151- ProcessResult result =
152- await _processManager . ExecuteWingetProcessAsync ( _exportSettingsCmd ) ;
138+ ProcessResult result = await ExecuteAsync ( _exportSettingsCmd ) ;
153139
154140 return ProcessOutputReader . ExportOutputToString ( result ) ;
155141 }
@@ -197,9 +183,7 @@ public void ExportSettingsToFile(string file)
197183 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( file , "file" ) ;
198184 ArgsHelper . ThrowIfPathIsInvalid ( file ) ;
199185
200- ThrowIfNotInstalled ( ) ;
201-
202- ProcessResult result = _processManager . ExecuteWingetProcess ( _exportSettingsCmd ) ;
186+ ProcessResult result = Execute ( _exportSettingsCmd ) ;
203187
204188 FileHandler . ExportOutputToFile ( file , result ) ;
205189 }
@@ -247,9 +231,7 @@ public async Task ExportSettingsToFileAsync(string file)
247231 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( file , "file" ) ;
248232 ArgsHelper . ThrowIfPathIsInvalid ( file ) ;
249233
250- ThrowIfNotInstalled ( ) ;
251-
252- ProcessResult result = await _processManager . ExecuteWingetProcessAsync ( _exportSettingsCmd ) ;
234+ ProcessResult result = await ExecuteAsync ( _exportSettingsCmd ) ;
253235
254236 await FileHandler . ExportOutputToFileAsync ( file , result ) ;
255237 }
@@ -265,10 +247,7 @@ public async Task ExportSettingsToFileAsync(string file)
265247 /// </exception>
266248 public WinGetInfo GetInfo ( )
267249 {
268- ThrowIfNotInstalled ( ) ;
269-
270- ProcessResult result =
271- _processManager . ExecuteWingetProcess ( _infoCmd ) ;
250+ ProcessResult result = Execute ( _infoCmd ) ;
272251
273252 InfoActionVersionId actionVersionId = InfoActionVersionId . VersionRange1 ;
274253 if ( CheckWinGetVersion ( new Version ( 1 , 4 , 3531 ) , new Version ( 1 , 5 , 101 ) ) )
@@ -299,10 +278,7 @@ public WinGetInfo GetInfo()
299278 /// </exception>
300279 public async Task < WinGetInfo > GetInfoAsync ( )
301280 {
302- ThrowIfNotInstalled ( ) ;
303-
304- ProcessResult result =
305- await _processManager . ExecuteWingetProcessAsync ( _infoCmd ) ;
281+ ProcessResult result = await ExecuteAsync ( _infoCmd ) ;
306282
307283 InfoActionVersionId actionVersionId = InfoActionVersionId . VersionRange1 ;
308284 if ( CheckWinGetVersion ( new Version ( 1 , 4 , 3531 ) , new Version ( 1 , 5 , 101 ) ) )
@@ -345,13 +321,52 @@ protected bool CheckWinGetVersion(Version minVersion, Version? maxVersion = null
345321 return false ;
346322 }
347323
324+ /// <summary>
325+ /// Exectutes a WinGet action from the given cmd.
326+ /// </summary>
327+ /// <param name="args">
328+ /// A <see cref="System.String"/> containing the arguments for the WinGet process.
329+ /// </param>
330+ /// <returns>
331+ /// The <see cref="WGetNET.Models.ProcessResult"/> for the process.
332+ /// </returns>
333+ /// <exception cref="WinGetNotInstalledException">
334+ /// WinGet is not installed or not found on the system.
335+ /// </exception>
336+ private protected ProcessResult Execute ( string args )
337+ {
338+ ThrowIfNotInstalled ( ) ;
339+
340+ return _processManager . ExecuteWingetProcess ( args ) ;
341+ }
342+
343+ /// <summary>
344+ /// Asynchronously exectutes a WinGet action from the given cmd.
345+ /// </summary>
346+ /// <param name="args">
347+ /// A <see cref="System.String"/> containing the arguments for the WinGet process.
348+ /// </param>
349+ /// <returns>
350+ /// A <see cref="System.Threading.Tasks.Task"/>, containing the result.
351+ /// The result is the <see cref="WGetNET.Models.ProcessResult"/> for the process.
352+ /// </returns>
353+ /// <exception cref="WinGetNotInstalledException">
354+ /// WinGet is not installed or not found on the system.
355+ /// </exception>
356+ private protected async Task < ProcessResult > ExecuteAsync ( string args )
357+ {
358+ ThrowIfNotInstalled ( ) ;
359+
360+ return await _processManager . ExecuteWingetProcessAsync ( args ) ;
361+ }
362+
348363 /// <summary>
349364 /// Throws a <see cref="WGetNET.Exceptions.WinGetNotInstalledException"/> if winget installation could not be found.
350365 /// </summary>
351366 /// <exception cref="WinGetNotInstalledException">
352367 /// WinGet is not installed or not found on the system.
353368 /// </exception>
354- protected void ThrowIfNotInstalled ( )
369+ private void ThrowIfNotInstalled ( )
355370 {
356371 if ( ! IsInstalled )
357372 {
@@ -372,8 +387,7 @@ private string CheckWinGetVersion()
372387 return string . Empty ;
373388 }
374389
375- ProcessResult result =
376- _processManager . ExecuteWingetProcess ( _versionCmd ) ;
390+ ProcessResult result = Execute ( _versionCmd ) ;
377391
378392 for ( int i = 0 ; i < result . Output . Length ; i ++ )
379393 {
0 commit comments