@@ -22,12 +22,6 @@ namespace WGetNET
2222 /// </summary>
2323 public class WinGet
2424 {
25- private const string _infoCmd = "--info" ;
26- private const string _versionCmd = "--version" ;
27- private const string _exportSettingsCmd = "settings export" ;
28- private const string _settingsEnableCmd = "settings --enable \" {0}\" " ;
29- private const string _settingsDisableCmd = "settings --disable \" {0}\" " ;
30-
3125 private ProcessManager _processManager ;
3226 private string _wingetExePath ;
3327 private DateTime _wingetExeModificationDate ;
@@ -154,7 +148,11 @@ public WinGet()
154148 /// </exception>
155149 public string ExportSettings ( )
156150 {
157- ProcessResult result = Execute ( _exportSettingsCmd ) ;
151+ ProcessResult result =
152+ Execute (
153+ WinGetArguments
154+ . SettingsExport ( )
155+ . ToString ( ) ) ;
158156
159157 return ProcessOutputReader . ExportOutputToString ( result ) ;
160158 }
@@ -174,7 +172,12 @@ public string ExportSettings()
174172 /// </exception>
175173 public async Task < string > ExportSettingsAsync ( CancellationToken cancellationToken = default )
176174 {
177- ProcessResult result = await ExecuteAsync ( _exportSettingsCmd , false , cancellationToken ) ;
175+ ProcessResult result =
176+ await ExecuteAsync (
177+ WinGetArguments
178+ . SettingsExport ( )
179+ . ToString ( ) ,
180+ false , cancellationToken ) ;
178181
179182 return ProcessOutputReader . ExportOutputToString ( result ) ;
180183 }
@@ -222,7 +225,11 @@ public void ExportSettingsToFile(string file)
222225 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( file , "file" ) ;
223226 ArgsHelper . ThrowIfPathIsInvalid ( file ) ;
224227
225- ProcessResult result = Execute ( _exportSettingsCmd ) ;
228+ ProcessResult result =
229+ Execute (
230+ WinGetArguments
231+ . SettingsExport ( )
232+ . ToString ( ) ) ;
226233
227234 FileHelper . WriteTextToFile ( file , ProcessOutputReader . ExportOutputToString ( result ) ) ;
228235 }
@@ -273,7 +280,12 @@ public async Task ExportSettingsToFileAsync(string file, CancellationToken cance
273280 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( file , "file" ) ;
274281 ArgsHelper . ThrowIfPathIsInvalid ( file ) ;
275282
276- ProcessResult result = await ExecuteAsync ( _exportSettingsCmd , false , cancellationToken ) ;
283+ ProcessResult result =
284+ await ExecuteAsync (
285+ WinGetArguments
286+ . SettingsExport ( )
287+ . ToString ( ) ,
288+ false , cancellationToken ) ;
277289
278290 await FileHelper . WriteTextToFileAsync ( file , ProcessOutputReader . ExportOutputToString ( result ) , cancellationToken ) ;
279291 }
@@ -396,9 +408,13 @@ public bool EnableAdminSetting(string settingName)
396408 {
397409 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( settingName , "settingName" ) ;
398410
399- string cmd = string . Format ( _settingsEnableCmd , settingName ) ;
400-
401- ProcessResult result = Execute ( cmd , true ) ;
411+ ProcessResult result =
412+ Execute (
413+ WinGetArguments
414+ . Settings ( )
415+ . Enable ( settingName )
416+ . ToString ( ) ,
417+ true ) ;
402418
403419 return result . Success ;
404420 }
@@ -460,9 +476,13 @@ public async Task<bool> EnableAdminSettingAsync(string settingName, Cancellation
460476 {
461477 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( settingName , "settingName" ) ;
462478
463- string cmd = string . Format ( _settingsEnableCmd , settingName ) ;
464-
465- ProcessResult result = await ExecuteAsync ( cmd , true , cancellationToken ) ;
479+ ProcessResult result =
480+ await ExecuteAsync (
481+ WinGetArguments
482+ . Settings ( )
483+ . Enable ( settingName )
484+ . ToString ( ) ,
485+ true , cancellationToken ) ;
466486
467487 return result . Success ;
468488 }
@@ -524,9 +544,13 @@ public bool DisableAdminSetting(string settingName)
524544 {
525545 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( settingName , "settingName" ) ;
526546
527- string cmd = string . Format ( _settingsDisableCmd , settingName ) ;
528-
529- ProcessResult result = Execute ( cmd , true ) ;
547+ ProcessResult result =
548+ Execute (
549+ WinGetArguments
550+ . Settings ( )
551+ . Disable ( settingName )
552+ . ToString ( ) ,
553+ true ) ;
530554
531555 return result . Success ;
532556 }
@@ -588,9 +612,13 @@ public async Task<bool> DisableAdminSettingAsync(string settingName, Cancellatio
588612 {
589613 ArgsHelper . ThrowIfStringIsNullOrWhiteSpace ( settingName , "settingName" ) ;
590614
591- string cmd = string . Format ( _settingsDisableCmd , settingName ) ;
592-
593- ProcessResult result = await ExecuteAsync ( cmd , true , cancellationToken ) ;
615+ ProcessResult result =
616+ await ExecuteAsync (
617+ WinGetArguments
618+ . Settings ( )
619+ . Disable ( settingName )
620+ . ToString ( ) ,
621+ true , cancellationToken ) ;
594622
595623 return result . Success ;
596624 }
@@ -640,7 +668,12 @@ public async Task<bool> DisableAdminSettingAsync(WinGetAdminSetting setting, Can
640668 /// </exception>
641669 public WinGetInfo GetInfo ( )
642670 {
643- ProcessResult result = Execute ( _infoCmd ) ;
671+ ProcessResult result =
672+ Execute (
673+ WinGetArguments
674+ . WinGet ( )
675+ . Info ( )
676+ . ToString ( ) ) ;
644677
645678 InfoActionVersionId actionVersionId = InfoActionVersionId . VersionRange1 ;
646679 if ( CheckWinGetVersion ( new Version ( 1 , 4 , 3531 ) , new Version ( 1 , 5 , 101 ) ) )
@@ -674,7 +707,13 @@ public WinGetInfo GetInfo()
674707 /// </exception>
675708 public async Task < WinGetInfo > GetInfoAsync ( CancellationToken cancellationToken = default )
676709 {
677- ProcessResult result = await ExecuteAsync ( _infoCmd , false , cancellationToken ) ;
710+ ProcessResult result =
711+ await ExecuteAsync (
712+ WinGetArguments
713+ . WinGet ( )
714+ . Info ( )
715+ . ToString ( ) ,
716+ false , cancellationToken ) ;
678717
679718 // Check the version range the action should be performed for
680719 InfoActionVersionId actionVersionId = InfoActionVersionId . VersionRange1 ;
@@ -837,7 +876,12 @@ private string CheckWinGetVersion()
837876 return string . Empty ;
838877 }
839878
840- ProcessResult result = Execute ( _versionCmd ) ;
879+ ProcessResult result =
880+ Execute (
881+ WinGetArguments
882+ . WinGet ( )
883+ . Version ( )
884+ . ToString ( ) ) ;
841885
842886 for ( int i = 0 ; i < result . Output . Length ; i ++ )
843887 {
0 commit comments