@@ -23,10 +23,13 @@ internal static class ProcessOutputReader
2323 /// <param name="action">
2424 /// Sets info about the action that is executet.
2525 /// </param>
26+ /// <param name="sourceName">
27+ /// Name of the source used in the search by source action.
28+ /// </param>
2629 /// <returns>
2730 /// A <see cref="System.Collections.Generic.List{T}"/> of <see cref="WGetNET.WinGetPackage"/>'s.
2831 /// </returns>
29- public static List < WinGetPackage > ToPackageList ( string [ ] output , PackageAction action = PackageAction . Default )
32+ public static List < WinGetPackage > ToPackageList ( string [ ] output , PackageAction action = PackageAction . Default , string ? sourceName = null )
3033 {
3134 //Get top line index.
3235 //The array should always contain this line.
@@ -39,7 +42,7 @@ public static List<WinGetPackage> ToPackageList(string[] output, PackageAction a
3942 //Remove unneeded output Lines
4043 output = ArrayManager . RemoveRange ( output , 0 , labelLine + 2 ) ;
4144
42- return CreatePackageListFromOutput ( output , columnList , action ) ;
45+ return CreatePackageListFromOutput ( output , columnList , action , sourceName ) ;
4346 }
4447
4548 /// <summary>
@@ -54,14 +57,17 @@ public static List<WinGetPackage> ToPackageList(string[] output, PackageAction a
5457 /// <param name="action">
5558 /// Sets info about the action that is executet.
5659 /// </param>
60+ /// <param name="sourceName">
61+ /// Name of the source used in the search by source action.
62+ /// </param>
5763 /// <returns>
5864 /// A <see cref="System.Collections.Generic.List{T}"/> of <see cref="WGetNET.WinGetPackage"/>'s.
5965 /// </returns>
60- private static List < WinGetPackage > CreatePackageListFromOutput ( string [ ] output , int [ ] columnList , PackageAction action = PackageAction . Default )
66+ private static List < WinGetPackage > CreatePackageListFromOutput ( string [ ] output , int [ ] columnList , PackageAction action = PackageAction . Default , string ? sourceName = null )
6167 {
6268 List < WinGetPackage > resultList = new List < WinGetPackage > ( ) ;
6369
64- if ( columnList . Length < 4 )
70+ if ( columnList . Length < 3 )
6571 {
6672 return resultList ;
6773 }
@@ -79,11 +85,22 @@ private static List<WinGetPackage> CreatePackageListFromOutput(string[] output,
7985 WinGetPackage package = new WinGetPackage ( )
8086 {
8187 PackageName = output [ i ] [ columnList [ 0 ] ..columnList [ 1 ] ] . Trim ( ) ,
82- PackageId = output [ i ] [ columnList [ 1 ] ..columnList [ 2 ] ] . Trim ( ) ,
83- PackageVersion = output [ i ] [ columnList [ 2 ] ..columnList [ 3 ] ] . Trim ( ) ,
84- PackageAvailableVersion = output [ i ] [ columnList [ 2 ] ..columnList [ 3 ] ] . Trim ( )
88+ PackageId = output [ i ] [ columnList [ 1 ] ..columnList [ 2 ] ] . Trim ( )
8589 } ;
8690
91+ //Set version info depending on the column count.
92+ if ( columnList . Length > 3 )
93+ {
94+ package . PackageVersion = output [ i ] [ columnList [ 2 ] ..columnList [ 3 ] ] . Trim ( ) ;
95+ package . PackageAvailableVersion = output [ i ] [ columnList [ 2 ] ..columnList [ 3 ] ] . Trim ( ) ;
96+ }
97+ else
98+ {
99+ package . PackageVersion = output [ i ] [ columnList [ 2 ] ..] . Trim ( ) ;
100+ package . PackageAvailableVersion = output [ i ] [ columnList [ 2 ] ..] . Trim ( ) ;
101+ }
102+
103+ //Set information, depending on the action and the column count.
87104 if ( ( action == PackageAction . UpgradeList || action == PackageAction . InstalledList || action == PackageAction . Search ) && columnList . Length >= 5 )
88105 {
89106 string availableVersion = output [ i ] [ columnList [ 3 ] ..columnList [ 4 ] ] . Trim ( ) ;
@@ -98,6 +115,10 @@ private static List<WinGetPackage> CreatePackageListFromOutput(string[] output,
98115 {
99116 package . PackageSourceName = output [ i ] [ columnList [ 3 ] ..] . Trim ( ) ;
100117 }
118+ else if ( action == PackageAction . SearchBySource && ! string . IsNullOrWhiteSpace ( sourceName ) )
119+ {
120+ package . PackageSourceName = sourceName ;
121+ }
101122
102123 resultList . Add ( package ) ;
103124 }
0 commit comments