コード例 #1
0
ファイル: Chocolatey.cs プロジェクト: T-Wolff/setupexpress
        public static async Task InstallPackage(ChocolateyPackage Package)
        {
            await Task.Run(() =>
            {
                ChocoLogs logs = new ChocoLogs();

                Lets.GetChocolatey().Set(x =>
                {
                    x.CommandName = "install";
                    x.PackageNames = Package.Id;
                    x.AcceptLicense = true;
                    x.Force = true;
                    x.ForceDependencies = true;
                    x.Version = Package.Version.ToString();
                    x.Sources = $"{Package.PackageFile.DirectoryName}";

                }).SetCustomLogging(logs).Run();

                if (logs.ErrorMessages.Count > 0)
                {
                    if (!logs.WarningMessages.Any(x => x.Contains("Chocolatey installed 1/1 package(s). 0 package(s) failed")))
                    {
                        throw new Exception("Installation Failed!");
                    }
                }
            });
        }
コード例 #2
0
ファイル: Chocolatey.cs プロジェクト: T-Wolff/setupexpress
        public static async Task InstallPackage(string PackageId, string PackageVersion = null)
        {
            await Task.Run(() =>
            {
                ChocoLogs logs = new ChocoLogs();

                Lets.GetChocolatey().Set(x =>
                {
                    x.CommandName = "install";
                    x.PackageNames = PackageId;
                    x.AcceptLicense = true;
                    x.Force = true;
                    x.ForceDependencies = true;
                    if(!string.IsNullOrEmpty(PackageVersion))
                    {
                        x.AllowDowngrade = true;
                        x.Version = PackageVersion;
                    }

                }).SetCustomLogging(logs).Run();

                if(logs.ErrorMessages.Count > 0)
                {
                    throw new Exception("Installation Failed!");
                }
            });
        }
コード例 #3
0
ファイル: Chocolatey.cs プロジェクト: T-Wolff/setupexpress
        public static async Task UninstallPackage(string PackageId)
        {
            await Task.Run(() =>
            {
                ChocoLogs logs = new ChocoLogs();

                Lets.GetChocolatey().Set(x =>
                {
                    x.CommandName = "uninstall";
                    x.PackageNames = PackageId;
                    x.Force = true;
                    x.ForceDependencies = true;

                }).SetCustomLogging(logs).Run();

                if (logs.ErrorMessages.Count > 0)
                {
                    throw new Exception("Uninstallation Failed!");
                }
            });
        }
コード例 #4
0
ファイル: Chocolatey.cs プロジェクト: T-Wolff/setupexpress
        public static async Task<string> GetAvailableVersion(string PackageId)
        {
            return await Task.Run(() =>
            {
                ChocoLogs logs = new ChocoLogs();

                Lets.GetChocolatey().Set(x =>
                {
                    x.CommandName = "install";
                    x.Noop = true;
                    x.PackageNames = PackageId;

                }).SetCustomLogging(logs).Run();

                if (logs.ErrorMessages.Count > 0)
                {
                    throw new Exception("GetAvailableVersion Failed!");
                }

                foreach(string message in logs.InfoMessages)
                {
                    string[] parts = message.Trim('\n', '\r').Split(' ');
                    if (parts.Length == 2 && parts[0] == PackageId)
                    {
                        return parts[1].TrimStart('v');
                    }
                }

                throw new Exception("GetAvailableVersion Failed!");
            });
        }
コード例 #5
0
ファイル: Chocolatey.cs プロジェクト: T-Wolff/setupexpress
        public static async Task<IReadOnlyDictionary<string, string>> GetInstalledPackageVersions()
        {
            return await Task.Run(() =>
            {
                ChocoLogs logs = new ChocoLogs();

                Lets.GetChocolatey().Set(x =>
                {
                    x.CommandName = "list";
                    x.ListCommand.LocalOnly = true;

                }).SetCustomLogging(logs).Run();

                if (logs.ErrorMessages.Count > 0)
                {
                    throw new Exception("GetInstalledPackageVersions() Failed!");
                }

                Dictionary<string, string> result = new Dictionary<string, string>();
                foreach(var info in logs.InfoMessages)
                {
                    string[] parts = info.Split(' ');
                    result.Add(parts[0], parts[1]);
                }
                return result;
            });
        }