예제 #1
0
파일: Cocoa.cs 프로젝트: mohemohe/Cocoa
        public static void Version()
        {
            Console.WriteLine(
                @"Cocoa v" +
                Assembly.GetExecutingAssembly().GetName().Version.ToString());

            using (var choco = new ChocolateyHost())
            {
                choco.Exec();
            }
        }
예제 #2
0
파일: Cocoa.cs 프로젝트: mohemohe/Cocoa
        public static void Upgrade(IEnumerable<string> packages)
        {
            var sb = new StringBuilder();
            sb.Append(@"upgrade");
            packages.ToList().ForEach(x => sb.Append(@" " + x));

            using (var choco = new ChocolateyHost())
            {
                choco.ExecInteractive(sb.ToString());
            }
        }
예제 #3
0
파일: Cocoa.cs 프로젝트: mohemohe/Cocoa
        public static void ShowPackagesList(IEnumerable<string> packages, bool isLocalPackages = false)
        {
            var sb = new StringBuilder();
            sb.Append(@"list");
            packages.ToList().ForEach(x => sb.Append(@" " + x));
            if (isLocalPackages)
            {
                sb.Append(@" --localonly");
            }

            using (var choco = new ChocolateyHost())
            {
                choco.ExecInteractive(sb.ToString());
            }
        }
예제 #4
0
파일: Cocoa.cs 프로젝트: mohemohe/Cocoa
        public static async Task InstallNonApprovedPackages(IEnumerable<string> packages)
        {
            var tempDir = Path.Combine(Path.GetTempPath(), @"cocoa");
            if (!Directory.Exists(tempDir))
            {
                Directory.CreateDirectory(tempDir);
            }

            var availablePackages = new List<string>();
            var args = new List<string>();

            foreach(var package in packages)
            {
                if (package.StartsWith(@"-"))
                {
                    args.Add(package);
                    continue;
                }

                var packageInfos = Crawler.GetPackageInfos(package);
                if (packageInfos == null || !packageInfos.Any())
                {
                    Console.WriteLine(@"'" + package + @"' was not found.");
                    continue;
                }

                availablePackages.Add(package);

                var packageInfo = packageInfos.ToList()[0];
                string fileName;
                string filePath;
                using (var hc = new HttpClient())
                {
                    var res = hc.GetAsync(packageInfo.DownloadUri, HttpCompletionOption.ResponseHeadersRead).Result;
                    fileName = Path.GetFileName(res.RequestMessage.RequestUri.ToString());
                    filePath = Path.Combine(tempDir, fileName);

                    using (var fs = File.Create(filePath))
                    {
                        using (var s = res.Content.ReadAsStreamAsync().Result)
                        {
                            s.CopyTo(fs);
                            fs.Flush();
                        }
                    }
                }
            }

            if (availablePackages.Count != 0)
            {
                var sb = new StringBuilder();
                sb.Append(@"install");
                availablePackages.ForEach(x => sb.Append(@" " + x));
                args.ForEach(x => sb.Append(@" " + x));
                sb.Append(@" -source " + tempDir);

                using (var choco = new ChocolateyHost())
                {
                    choco.ExecInteractive(sb.ToString());
                }
            }
        }