diff --git a/Source/ChocolateyGui.Common.Windows/ChocolateyGui.Common.Windows.csproj b/Source/ChocolateyGui.Common.Windows/ChocolateyGui.Common.Windows.csproj index 7d04930ef..dbda920ba 100644 --- a/Source/ChocolateyGui.Common.Windows/ChocolateyGui.Common.Windows.csproj +++ b/Source/ChocolateyGui.Common.Windows/ChocolateyGui.Common.Windows.csproj @@ -220,6 +220,8 @@ Properties\SolutionInfo.cs + + diff --git a/Source/ChocolateyGui.Common.Windows/Services/IPackageArgumentsService.cs b/Source/ChocolateyGui.Common.Windows/Services/IPackageArgumentsService.cs new file mode 100644 index 000000000..873bf3434 --- /dev/null +++ b/Source/ChocolateyGui.Common.Windows/Services/IPackageArgumentsService.cs @@ -0,0 +1,14 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright 2017 - Present Chocolatey Software, LLC +// Copyright 2014 - 2017 Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ChocolateyGui.Common.Windows.Services +{ + public interface IPackageArgumentsService + { + string DecryptPackageArgumentsFile(string id, string version); + } +} \ No newline at end of file diff --git a/Source/ChocolateyGui.Common.Windows/Services/PackageArgumentsService.cs b/Source/ChocolateyGui.Common.Windows/Services/PackageArgumentsService.cs new file mode 100644 index 000000000..ef5e1e4d7 --- /dev/null +++ b/Source/ChocolateyGui.Common.Windows/Services/PackageArgumentsService.cs @@ -0,0 +1,55 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright 2017 - Present Chocolatey Software, LLC +// Copyright 2014 - 2017 Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC +// +// -------------------------------------------------------------------------------------------------------------------- + +using System; +using chocolatey; +using chocolatey.infrastructure.adapters; +using ChocolateyGui.Common.Properties; +using ChocolateyGui.Common.Providers; +using IFileSystem = chocolatey.infrastructure.filesystem.IFileSystem; +using ILogger = Serilog.ILogger; + +namespace ChocolateyGui.Common.Windows.Services +{ + public class PackageArgumentsService : IPackageArgumentsService + { + private static readonly ILogger Logger = Serilog.Log.ForContext(); + private readonly IEncryptionUtility _encryptionUtility; + private readonly IFileSystem _fileSystem; + private readonly IChocolateyConfigurationProvider _chocolateyConfigurationProvider; + + public PackageArgumentsService(IEncryptionUtility encryptionUtility, IFileSystem fileSystem, IChocolateyConfigurationProvider chocolateyConfigurationProvider) + { + _encryptionUtility = encryptionUtility; + _fileSystem = fileSystem; + _chocolateyConfigurationProvider = chocolateyConfigurationProvider; + } + + public string DecryptPackageArgumentsFile(string id, string version) + { + var argumentsPath = _fileSystem.combine_paths(_chocolateyConfigurationProvider.ChocolateyInstall, ".chocolatey", "{0}.{1}".format_with(id, version)); + var argumentsFile = _fileSystem.combine_paths(argumentsPath, ".arguments"); + + // Get the arguments decrypted in here and return them + try + { + if (_fileSystem.file_exists(argumentsFile)) + { + return _encryptionUtility.decrypt_string(_fileSystem.read_file(argumentsFile)); + } + + return Resources.PackageView_UnableToFindArgumentsFile.format_with(version, id); + } + catch (Exception ex) + { + var message = Resources.Application_PackageArgumentsError.format_with(version, id); + Logger.Error(ex, message); + return message; + } + } + } +} \ No newline at end of file diff --git a/Source/ChocolateyGui.Common.Windows/Startup/ChocolateyGuiModule.cs b/Source/ChocolateyGui.Common.Windows/Startup/ChocolateyGuiModule.cs index d3beb95b3..4fd2e23f7 100644 --- a/Source/ChocolateyGui.Common.Windows/Startup/ChocolateyGuiModule.cs +++ b/Source/ChocolateyGui.Common.Windows/Startup/ChocolateyGuiModule.cs @@ -12,9 +12,11 @@ using AutoMapper; using Caliburn.Micro; using chocolatey; +using chocolatey.infrastructure.adapters; using chocolatey.infrastructure.app.configuration; using chocolatey.infrastructure.app.nuget; using chocolatey.infrastructure.app.services; +using chocolatey.infrastructure.cryptography; using chocolatey.infrastructure.filesystem; using chocolatey.infrastructure.services; using ChocolateyGui.Common.Models; @@ -47,6 +49,8 @@ protected override void Load(ContainerBuilder builder) builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().SingleInstance(); // Register ViewModels builder.RegisterAssemblyTypes(viewModelAssembly) diff --git a/Source/ChocolateyGui.Common.Windows/ViewModels/Items/PackageViewModel.cs b/Source/ChocolateyGui.Common.Windows/ViewModels/Items/PackageViewModel.cs index fb68f9153..2f787befa 100644 --- a/Source/ChocolateyGui.Common.Windows/ViewModels/Items/PackageViewModel.cs +++ b/Source/ChocolateyGui.Common.Windows/ViewModels/Items/PackageViewModel.cs @@ -8,6 +8,7 @@ using System; using System.Diagnostics; using System.Threading.Tasks; +using System.Windows; using AutoMapper; using Caliburn.Micro; using ChocolateyGui.Common.Base; @@ -43,6 +44,7 @@ public class PackageViewModel : private readonly IChocolateyGuiCacheService _chocolateyGuiCacheService; private readonly IConfigService _configService; private readonly IAllowedCommandsService _allowedCommandsService; + private readonly IPackageArgumentsService _packageArgumentsService; private string[] _authors; @@ -119,7 +121,8 @@ public PackageViewModel( IProgressService progressService, IChocolateyGuiCacheService chocolateyGuiCacheService, IConfigService configService, - IAllowedCommandsService allowedCommandsService) + IAllowedCommandsService allowedCommandsService, + IPackageArgumentsService packageArgumentsService) { _chocolateyService = chocolateyService; _eventAggregator = eventAggregator; @@ -129,6 +132,7 @@ public PackageViewModel( _chocolateyGuiCacheService = chocolateyGuiCacheService; _configService = configService; _allowedCommandsService = allowedCommandsService; + _packageArgumentsService = packageArgumentsService; } public DateTime Created @@ -417,6 +421,12 @@ public bool IsPackageSizeAvailable get { return PackageSize != -1; } } + public void ShowArguments() + { + var decryptedArguments = _packageArgumentsService.DecryptPackageArgumentsFile(Id, Version.ToString()); + MessageBox.Show(decryptedArguments); + } + public async Task Install() { try diff --git a/Source/ChocolateyGui.Common.Windows/Views/PackageView.xaml b/Source/ChocolateyGui.Common.Windows/Views/PackageView.xaml index e4437042a..0ac11ec12 100644 --- a/Source/ChocolateyGui.Common.Windows/Views/PackageView.xaml +++ b/Source/ChocolateyGui.Common.Windows/Views/PackageView.xaml @@ -60,6 +60,13 @@ VerticalAlignment="Stretch" Background="{DynamicResource MahApps.Brushes.Accent4}"> +