/// <summary> /// Get the REPO and REF property from portfile.cmake and return it as a RepoRef /// </summary> public async Task <RepoRef> GetRepoAndRef(string portName) { RepoRef repoRef = new RepoRef(); try { string portFileUrl = GetPortFileCMake(portName); HtmlWeb htmlWeb = new HtmlWeb(); htmlWeb.UsingCache = false; HtmlDocument htmlDocument = new HtmlDocument(); htmlDocument = await htmlWeb.LoadFromWebAsync(portFileUrl); List <HtmlNode> htmlNodeList = htmlDocument.DocumentNode.SelectNodes("//td") .Where(node => node.GetAttributeValue("class", "") .Equals("blob-code blob-code-inner js-file-line")).ToList(); foreach (HtmlNode node in htmlNodeList) { // Find REPO and REF lines if (node.InnerText.Contains(" REPO ")) { repoRef.Repo = node.InnerText.Replace(" ", "").Substring(4); } else if (node.InnerText.Contains(" REF ")) { repoRef.Ref = node.InnerText.Replace(" ", "").Substring(3); } if (repoRef.Repo != null && repoRef.Ref != null) { break; } } } catch (Exception) { return(null); } return(repoRef); }
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"); } } }
/// <summary> /// Check a port has both REPO and REF property /// </summary> public bool HasRepoAndRef(RepoRef port) { return((port.Repo != null && port.Ref != null) ? true : false); }