private void MenuInstall_Click(object sender, RoutedEventArgs e) { List <string> pkgs = new List <string>(); foreach (var item in PortsList.SelectedItems) { var port = item as Port; var features = CheckedFeatures?.Where(feat => feat.CoreName == port.Name) ?? Enumerable.Empty <FeatureParagraph>(); if (features.Count() == 0) { pkgs.Add($"{port.Name}:{CheckedTriplet}"); } else { var featstr = string.Join(",", features.Select(feat => feat.Name)); pkgs.Add($"{port.Name}[core,{featstr}]:{CheckedTriplet}"); } } if (MessageBox.Show("Installing following packages:\n" + string.Join("\n", pkgs) + "\nAre you sure?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { // TODO: rebuild check. "--recursive" flag is needed for rebuild var code = ExecutionDialog.RunVcpkg("install " + string.Join(" ", pkgs), out string result, true); } }
/// <summary> /// Run vcpkg tool with certain arguments /// </summary> /// <param name="arguments">The arguments passed to vcpkg</param> /// <param name="output">The output of the execution (<c>null</c> if wait is <c>false</c>)</param> /// <param name="useShell">Whether the output of the exection is catched into a shell</param> /// <param name="wait">Whether wait until the exection ends</param> /// <returns>The exit code of the execution</returns> public static int RunVcpkg(string arguments, out string output, bool useShell = false, bool wait = true) { if ((Application.Current as App).DebugVcpkg) { arguments += " --debug"; } if ((Application.Current as App).DryRun) { if (arguments.StartsWith("install") || arguments.StartsWith("remove") || arguments.StartsWith("export")) { arguments += " --dry-run"; } } ProcessStartInfo info = new ProcessStartInfo() { FileName = Path.Combine(Properties.Settings.Default.vcpkg_path, "vcpkg.exe"), Arguments = arguments, WorkingDirectory = Properties.Settings.Default.vcpkg_path, UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = true, RedirectStandardError = true }; var process = new Process() { StartInfo = info }; if (wait) { if (useShell) { var dialog = new ExecutionDialog(process, true); dialog.ShowDialog(); output = null; return(dialog.ExitCode); } else { process.Start(); process.WaitForExit(); output = process.StandardOutput.ReadToEnd(); return(process.ExitCode); } } else { if (useShell) { new ExecutionDialog(process, false).Show(); } else { process.Start(); } output = null; return(0); } }
private void ParseTriplets() { ExecutionDialog.RunVcpkg("help triplet", out string output); foreach (var line in output.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Skip(1)) { Dispatcher.Invoke(new Action <string>(AddTriplet), line.Trim()); } }
private void MenuRemove_Click(object sender, RoutedEventArgs e) { var pkgs = GetSelectedPackageNames(); if (MessageBox.Show("Removing following packages:\n" + pkgs.Replace(' ', '\n') + "\nAre you sure?", "Confirm", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { var code = ExecutionDialog.RunVcpkg("remove " + pkgs, out string result, true); } }
private void IntegratePowerShell_Click(object sender, RoutedEventArgs e) { if (ExecutionDialog.RunVcpkg("integrate powershell", out string output) == 0) { MessageBox.Show(output, "Success", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Failed to integrate PowerShell tab completion for this vcpkg root!", "Failure", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void IntegrateRemove_Click(object sender, RoutedEventArgs e) { if (ExecutionDialog.RunVcpkg("integrate remove", out string output) == 0) { MessageBox.Show(output, "Success", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Failed to remove user-wide integration for this vcpkg root!", "Failure", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void MenuGenerateGraph_Click(object sender, RoutedEventArgs e) { var dialog = new CommonSaveFileDialog("Save graph (.dot) file") { DefaultExtension = ".dot" }; dialog.Filters.Add(new CommonFileDialogFilter("GraphViz Graph", ".dot")); if (dialog.ShowDialog(new WindowInteropHelper(this).Handle) == CommonFileDialogResult.Ok) { ExecutionDialog.RunVcpkg("search --graph", out string graph); // TODO: the process will block here if not using shell File.WriteAllText(dialog.FileName, graph); } }
private void ParseVersion() { ExecutionDialog.RunVcpkg("version", out string output); var vEnd = output.IndexOf(Environment.NewLine); var vStart = output.LastIndexOf(' ', vEnd); var vstr = output.Substring(vStart, vEnd - vStart).Trim(); var splitHead = vstr.IndexOf('-'); var splitEnd = vstr.LastIndexOf('-'); Version = vstr.Substring(0, splitHead); if (splitHead != splitEnd) // "unknownhash" { BuildDate = vstr.Substring(splitHead + 1, splitEnd - splitHead - 1); } BuildHash = vstr.Substring(splitEnd + 1); }
private void MenuHash_Click(object sender, RoutedEventArgs e) { var dialog = new CommonOpenFileDialog("Select file to hash") { EnsureFileExists = true }; var result = dialog.ShowDialog(new WindowInteropHelper(this).Handle); if (result != CommonFileDialogResult.Ok) { return; } ExecutionDialog.RunVcpkg("hash " + dialog.FileName.Replace('\\', '/'), out string hash); Clipboard.SetDataObject(hash, true); MessageBox.Show("SHA512 Hash result is copied to clipboard:\n" + hash, "Hash Result", MessageBoxButton.OK, MessageBoxImage.Information); }
private void Confirm_Click(object sender, RoutedEventArgs e) { var code = ExecutionDialog.RunVcpkg($"create {PortName.Text} {ArchiveLink.Text} {ArchiveName.Text}", out string message); if (code == 0) { MessageBox.Show("Successfully create port " + PortName.Text, "Success", MessageBoxButton.OK, MessageBoxImage.Information); Close(); // TODO: Refresh port list and add prompt to open editor. } else { MessageBox.Show($"Failed to create port {PortName.Text}, message:\r\n{message}", "Failed", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void ParseInstalledPackages() { ExecutionDialog.RunVcpkg("list png", out string _); // XXX: Run vcpkg list to execute database_load_check() method in order to update list. PackageStatus = Parser.ParseStatus(Path.Combine(Properties.Settings.Default.vcpkg_path, "installed", "vcpkg", "status")); }
private void MenuEdit_Click(object sender, RoutedEventArgs e) { var pkg = (PortsList.SelectedItem as Port).Name; var code = ExecutionDialog.RunVcpkg("edit " + pkg, out string _, wait: false); }
private void MenuRemoveOutdated_Click(object sender, RoutedEventArgs e) { // TODO: need run --dry-run first to check whether --recurse is needed here var code = ExecutionDialog.RunVcpkg("remove --outdated", out string result, true); }
private void MenuPackageEditBT_Click(object sender, RoutedEventArgs e) { var pkg = (PackagesList.SelectedItem as StatusParagraph).Package; var code = ExecutionDialog.RunVcpkg("edit " + pkg + " --buildtrees", out string _, wait: false); }