static void SaveLog() { // Reset the color Console.ResetColor(); Vcpkg vcpkg = new Vcpkg(); // Check the length of log list if (vcpkg.LogLength() > 0) { while (true) { VcpkgMessage.NormalMessage("> Do you want to save ports in a log file? (y/n) "); string answer = Console.ReadLine(); if (answer.ToLower() == "y") { VcpkgMessage.NormalMessage("> Enter the destination file path: "); string path = Console.ReadLine(); if (vcpkg.SaveLog(path)) { VcpkgMessage.NormalMessage("\n> File successfully saved!\n\n"); break; } else { VcpkgMessage.ErrorMessage("\n> Can't save the file. try again... (See EXAMPLE: C:\\ports.log)\n\n"); Console.ResetColor(); } } else if (answer.ToLower() == "n") { break; } } } }
static async Task AsyncMain() { // Initialize Vcpkg vcpkg = new Vcpkg(); vcpkg.SetHttpClient(); // Fetching ports VcpkgMessage.NormalMessage("\n\n> Fetching ports... (It may take a few seconds)\n"); IEnumerable <string> ports = await vcpkg.GetPorts(); if (ports != null) { VcpkgMessage.NormalMessage("> Ports successfully fetched\n"); // Some settings for console output int currentLine = Console.CursorTop + 1; int clearLength = 0; int percent = 0; int portsCount = ports.ToList().Count; // Looking for need-to-be-updated ports foreach (string port in ports) { if (Program.canceling) { break; } percent++; Console.SetCursorPosition(0, currentLine - 1); VcpkgMessage.NormalMessage($"> Looking for need-to-be-updated ports... ({100 * percent / portsCount}%)"); // Reset the line Console.SetCursorPosition(0, currentLine); VcpkgMessage.ClearLine(currentLine, clearLength); // Show the current port Console.SetCursorPosition(0, currentLine); VcpkgMessage.NormalMessage($"> Current port: \"{port}\""); clearLength = 18 + port.Length; // Get the port REPO and REF RepoRef portRepoRef = await vcpkg.GetRepoAndRef(port); if (vcpkg.HasRepoAndRef(portRepoRef)) { string latestRelease = await vcpkg.SearchLatestRelease(portRepoRef.Repo); // Show need-to-be-update port if (vcpkg.PortNeedToUpdate(portRepoRef.Ref, latestRelease)) { Console.SetCursorPosition(0, currentLine - 1); ++currentLine; string updatePort = $"\"{port}\" need to update from \"{portRepoRef.Ref}\" to \"{latestRelease}\" version."; VcpkgMessage.WarningMessage(updatePort); VcpkgMessage.NormalMessage(""); // Add port to the log list vcpkg.AddToLog(updatePort); } } } // Remove last port check in the currentLine Console.SetCursorPosition(0, currentLine); VcpkgMessage.ClearLine(currentLine, clearLength); Console.SetCursorPosition(0, currentLine); // Finish if (!Program.canceling) { VcpkgMessage.NormalMessage("\n> All ports checked!\n\n"); } else { VcpkgMessage.NormalMessage("\n> Task cancelled by user\n\n"); } } }