Skip to content

Commit

Permalink
Fix issue with pretty printing package metadata when the console is r…
Browse files Browse the repository at this point in the history
…edirected to a text file. Pretty printing directly manipulates the console cursor location in order to indent text; cursor manipulation is not allowed when redirecting console output to a file. The fix is to maintaint text indenting on the console by printing the required amount of white space instead of direct console cursor manipulation.
  • Loading branch information
Almost-Done committed Sep 19, 2022
1 parent a3263de commit 542f6c4
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/tools/upsync/PackageMetadataPrint/MicrosoftUpdateMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,25 @@ static void PrintHandlerMetadata(HandlerMetadata handler)
}
}

static void PrintBundleChainRecursive(SoftwareUpdate softwareUpdate, IMetadataStore source, int recursionIndex)
static void PrintBundleChainRecursive(SoftwareUpdate softwareUpdate, IMetadataStore source, string recursiveWhiteSpaceIndent)
{
const int indentSize = 4;
const string localWhiteSpaceIndent = " ";

if (softwareUpdate.BundledWithUpdates != null)
{
foreach (var parentBundleID in softwareUpdate.BundledWithUpdates)
{
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.CursorLeft = indentSize * recursionIndex + indentSize;
Console.WriteLine($" Bundled with :");
Console.WriteLine($"{recursiveWhiteSpaceIndent}{localWhiteSpaceIndent}Bundled with :");
Console.ResetColor();
Console.CursorLeft = indentSize * recursionIndex + indentSize + 8;
Console.WriteLine(parentBundleID);
Console.CursorLeft = indentSize * recursionIndex + indentSize + 8;

Console.WriteLine($"{recursiveWhiteSpaceIndent}{localWhiteSpaceIndent}{localWhiteSpaceIndent}{parentBundleID}");

if (source.ContainsPackage(parentBundleID))
{
var parentBundle = source.GetPackage(parentBundleID);
Console.WriteLine(parentBundle.Title);
PrintBundleChainRecursive(parentBundle as SoftwareUpdate, source, recursionIndex + 1);
Console.WriteLine($"{recursiveWhiteSpaceIndent}{localWhiteSpaceIndent}{localWhiteSpaceIndent}{parentBundle.Title}");
PrintBundleChainRecursive(parentBundle as SoftwareUpdate, source, recursiveWhiteSpaceIndent + localWhiteSpaceIndent);

Console.WriteLine();
}
Expand Down Expand Up @@ -362,7 +360,7 @@ static void PrintBundledUpdates(SoftwareUpdate softwareUpdate, IMetadataStore so
}
}

PrintBundleChainRecursive(softwareUpdate, source, 0);
PrintBundleChainRecursive(softwareUpdate, source, "");
}

static void PrintPrerequisites(MicrosoftUpdatePackage update, ILookup<Guid, MicrosoftUpdatePackage> updatesLookup)
Expand Down

0 comments on commit 542f6c4

Please sign in to comment.