Exemple #1
0
        /// <exception cref="ChocolateyException"></exception>
        public static string FetchInfo(ChocolateyPackage package)
        {
            StringBuilder rtn = new StringBuilder();

            // launch process
            ChocolateyProcess p = new ChocolateyProcess($"info {package.Name}");

            p.ExecuteHidden();

            // parse
            List <string[]> sections = p.OutputBySection;

            foreach (string[] section in sections)
            {
                if (section.Length > 0)
                {
                    for (int i = 0; i < section.Length; i++)
                    {
                        rtn.AppendLine(section[i].Trim());
                    }
                }
            }

            return(rtn.ToString());
        }
Exemple #2
0
        /// <exception cref="ChocolateyException"></exception>
        public static List <ChocolateyPackage> FetchOutdated()
        {
            Log.Debug("Fetching outdated packages from Chocolatey...");

            List <ChocolateyPackage> packages = new List <ChocolateyPackage>();

            // launch process
            ChocolateyProcess p = new ChocolateyProcess("outdated");

            p.ExecuteHidden();

            // TODO throw exceptions for parsing errors
            // account for optional extra sections at the start
            // and end of sections header, package list and summary

            // parse (find header section, followed by package section, followed by summary section)
            List <string[]> sections = p.OutputBySection;

            for (int i = 0; i < sections.Count; i++)
            {
                // find header section
                if (sections[i].Length == 2 &&
                    sections[i][0].Equals("Outdated Packages") &&
                    sections[i][1].Equals(" Output is package name | current version | available version | pinned?") &&
                    i + 2 < sections.Count)
                {
                    string[] packageList = sections[i + 1];
                    string[] summary     = sections[i + 2];

                    // check summary
                    if (summary.Length > 0 &&
                        summary[0].StartsWith("Chocolatey has determined ") &&
                        summary[0].EndsWith(" package(s) are outdated. "))
                    {
                        /* Do NOT check if count of outdated packages in summary
                         * equals package list size, because they are not equal
                         * in case of faulty Chocolatey packages (which are not
                         * counted towards outdated packages)!
                         * Thanks to Valentin for helping with this issue. */

                        // check packages
                        foreach (string line in packageList)
                        {
                            // retrieve package
                            string[] entry = line.Split('|');
                            if (entry.Length == 4)
                            {
                                ChocolateyPackage pckg = new ChocolateyPackage
                                {
                                    Name     = entry[0],
                                    CurrVer  = entry[1],
                                    AvailVer = entry[2],
                                    Pinned   = entry[3].Equals("true")
                                };
                                packages.Add(pckg);
                            }
                        }
                    }
                }
            }

            return(GuessMetaPackages(packages));
        }
Exemple #3
0
 /// <exception cref="ChocolateyException"></exception>
 public static async Task <string> FetchInfoAsync(ChocolateyPackage package)
 {
     return(await Task.Run(() => FetchInfo(package)));
 }