@@ -203,7 +203,7 @@ public static List<WinGetPinnedPackage> ToPinnedPackageList(string[] output)
203203 //that will be thrown later, will be catched in the calling method.
204204 int labelLine = ArrayManager . GetEntryContains ( output , "------" ) - 1 ;
205205
206- int [ ] columnList = GetColumnList ( output [ labelLine ] ) ;
206+ int [ ] columnList = GetColumnList ( output [ labelLine ] , true ) ;
207207
208208 //Remove unneeded output Lines
209209 output = ArrayManager . RemoveRange ( output , 0 , labelLine + 2 ) ;
@@ -247,39 +247,61 @@ private static List<WinGetPinnedPackage> CreatePinnedPackageListFromOutput(strin
247247 }
248248#endif
249249
250+ string pinType = string . Empty ;
251+ string pinnedVersion = string . Empty ;
252+
250253#if NETCOREAPP3_1_OR_GREATER
251254 string packageName = output [ i ] [ columnList [ 0 ] ..columnList [ 1 ] ] . Trim ( ) ;
252255 string packageId = output [ i ] [ columnList [ 1 ] ..columnList [ 2 ] ] . Trim ( ) ;
253256 string packageVersion = output [ i ] [ columnList [ 2 ] ..columnList [ 3 ] ] . Trim ( ) ;
254257 string packageSource = output [ i ] [ columnList [ 3 ] ..columnList [ 4 ] ] . Trim ( ) ;
255- string pinType = string . Empty ;
256- string pinnedVersion = string . Empty ;
257- if ( columnList . Length > 5 )
258+
259+ #elif NETSTANDARD2_0
260+ string packageName = output [ i ] . Substring ( columnList [ 0 ] , ( columnList [ 1 ] - columnList [ 0 ] ) ) . Trim ( ) ;
261+ string packageId = output [ i ] . Substring ( columnList [ 1 ] , ( columnList [ 2 ] - columnList [ 1 ] ) ) . Trim ( ) ;
262+ string packageVersion = output [ i ] . Substring ( columnList [ 2 ] , ( columnList [ 3 ] - columnList [ 2 ] ) ) . Trim ( ) ;
263+ string packageSource = output [ i ] . Substring ( columnList [ 3 ] , ( columnList [ 4 ] - columnList [ 3 ] ) ) . Trim ( ) ;
264+ #endif
265+
266+ // Workaround for getting the pin data from the output.
267+ // The normal method will not work, because "Pin type" and "Pinned version" contain spaces.
268+ #if NETCOREAPP3_1_OR_GREATER
269+ string pinInfoString = output [ i ] [ columnList [ 4 ] ..] . TrimStart ( ) ;
270+ #elif NETSTANDARD2_0
271+ string pinInfoString = output [ i ] . Substring ( columnList [ 4 ] ) . TrimStart ( ) ;
272+ #endif
273+ int endOfTypeIndex = - 1 ;
274+ for ( int j = 0 ; j < pinInfoString . Length ; j ++ )
258275 {
259- pinType = output [ i ] [ columnList [ 4 ] ..columnList [ 5 ] ] . Trim ( ) ;
260- pinnedVersion = output [ i ] [ columnList [ 5 ] ..] . Trim ( ) ;
276+ if ( pinInfoString [ j ] == ( char ) 32 )
277+ {
278+ endOfTypeIndex = j ;
279+ break ;
280+ }
281+ }
282+
283+ #if NETCOREAPP3_1_OR_GREATER
284+ if ( endOfTypeIndex == - 1 )
285+ {
286+ pinType = pinInfoString . Trim ( ) ;
261287 }
262288 else
263289 {
264- pinType = output [ i ] [ columnList [ 4 ] ..] . Trim ( ) ;
290+ pinType = pinInfoString [ 0 ..endOfTypeIndex ] . Trim ( ) ;
291+ pinnedVersion = pinInfoString [ endOfTypeIndex ..] . Trim ( ) ;
265292 }
266293#elif NETSTANDARD2_0
267- string packageName = output [ i ] . Substring ( columnList [ 0 ] , ( columnList [ 1 ] - columnList [ 0 ] ) ) . Trim ( ) ;
268- string packageId = output [ i ] . Substring ( columnList [ 1 ] , ( columnList [ 2 ] - columnList [ 1 ] ) ) . Trim ( ) ;
269- string packageVersion = output [ i ] . Substring ( columnList [ 2 ] , ( columnList [ 3 ] - columnList [ 2 ] ) ) . Trim ( ) ;
270- string packageSource = output [ i ] . Substring ( columnList [ 3 ] , ( columnList [ 4 ] - columnList [ 3 ] ) ) . Trim ( ) ;
271- string pinType = string . Empty ;
272- string pinnedVersion = string . Empty ;
273- if ( columnList . Length > 5 )
294+ if ( endOfTypeIndex == - 1 )
274295 {
275- pinType = output [ i ] . Substring ( columnList [ 4 ] , ( columnList [ 5 ] - columnList [ 4 ] ) ) . Trim ( ) ;
276- pinnedVersion = output [ i ] . Substring ( columnList [ 5 ] ) . Trim ( ) ;
296+ pinType = pinInfoString . Trim ( ) ;
277297 }
278298 else
279299 {
280- pinType = output [ i ] . Substring ( columnList [ 4 ] ) . Trim ( ) ;
300+ pinType = pinInfoString . Substring ( 0 , endOfTypeIndex ) . Trim ( ) ;
301+ pinnedVersion = pinInfoString . Substring ( endOfTypeIndex ) ;
281302 }
282303#endif
304+ // End of workaround
283305
284306 // Check if the id is shortened
285307 bool isShortenedId = CheckShortenedId ( packageId ) ;
@@ -411,16 +433,23 @@ private static List<WinGetSource> CreateSourceListFromOutput(string[] output, in
411433 /// <param name="line">
412434 /// A <see cref="System.String"/> containing the header, for column calculation.
413435 /// </param>
436+ /// <param name="isPinnedPackageTable">Activate workaround for the pinned package list.</param>
414437 /// <returns>
415438 /// A <see cref="System.Int32"/> <see langword="array"/> containing the column start indexes.
416439 /// </returns>
417- private static int [ ] GetColumnList ( string line )
440+ private static int [ ] GetColumnList ( string line , bool isPinnedPackageTable = false )
418441 {
419442 int [ ] columns = new int [ 0 ] ;
420443
421444 bool checkForColumn = true ;
422445 for ( int i = 0 ; i < line . Length ; i ++ )
423446 {
447+ if ( isPinnedPackageTable && columns . Length >= 5 )
448+ {
449+ // Workaround for the pinned package table
450+ break ;
451+ }
452+
424453 if ( line [ i ] != ( ( char ) 32 ) && checkForColumn )
425454 {
426455 columns = ArrayManager . Add ( columns , i ) ;
0 commit comments