Skip to content

Commit

Permalink
(chocolatey#770) Add ability to view install arguments
Browse files Browse the repository at this point in the history
This allows the viewing of the contents of the .arguments file, which
is stored on a per package version, and contains the arguments that
were passed into the choco install command for that package.

This file is encrypted, and can't be viewed directly, but this allows
decryption of the contents for viewing.

Co-authored-by: steviecoaster <[email protected]>
  • Loading branch information
gep13 and steviecoaster committed Apr 14, 2021
1 parent 2aab41b commit 1fafb45
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@
<Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="Services\IPackageArgumentsService.cs" />
<Compile Include="Services\PackageArgumentsService.cs" />
<Compile Include="Utilities\ToolTipBehavior.cs" />
<Compile Include="Bootstrapper.cs" />
<Compile Include="Commands\CommandExecutionManager.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Chocolatey" file="IPackageArgumentsService.cs">
// Copyright 2017 - Present Chocolatey Software, LLC
// Copyright 2014 - 2017 Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace ChocolateyGui.Common.Windows.Services
{
public interface IPackageArgumentsService
{
string DecryptPackageArgumentsFile(string id, string version);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Chocolatey" file="PackageArgumentsService.cs">
// Copyright 2017 - Present Chocolatey Software, LLC
// Copyright 2014 - 2017 Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

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<PackageArgumentsService>();
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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,6 +49,8 @@ protected override void Load(ContainerBuilder builder)
builder.RegisterType<ChocolateyConfigurationProvider>().As<IChocolateyConfigurationProvider>().SingleInstance();
builder.RegisterType<ChocolateyService>().As<IChocolateyService>().SingleInstance();
builder.RegisterType<DotNetFileSystem>().As<chocolatey.infrastructure.filesystem.IFileSystem>().SingleInstance();
builder.RegisterType<PackageArgumentsService>().As<IPackageArgumentsService>().SingleInstance();
builder.RegisterType<DefaultEncryptionUtility>().As<IEncryptionUtility>().SingleInstance();

// Register ViewModels
builder.RegisterAssemblyTypes(viewModelAssembly)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -119,7 +121,8 @@ public PackageViewModel(
IProgressService progressService,
IChocolateyGuiCacheService chocolateyGuiCacheService,
IConfigService configService,
IAllowedCommandsService allowedCommandsService)
IAllowedCommandsService allowedCommandsService,
IPackageArgumentsService packageArgumentsService)
{
_chocolateyService = chocolateyService;
_eventAggregator = eventAggregator;
Expand All @@ -129,6 +132,7 @@ public PackageViewModel(
_chocolateyGuiCacheService = chocolateyGuiCacheService;
_configService = configService;
_allowedCommandsService = allowedCommandsService;
_packageArgumentsService = packageArgumentsService;
}

public DateTime Created
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Source/ChocolateyGui.Common.Windows/Views/PackageView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
VerticalAlignment="Stretch"
Background="{DynamicResource MahApps.Brushes.Accent4}">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,20,10">
<Button Padding="10" Margin="5 0"
Command="{commands:DataContextCommandAdapter ShowArguments}">
<StackPanel Orientation="Horizontal">
<iconPacks:PackIconEntypo Kind="Info" Margin="0 0 5 0 " VerticalAlignment="Center" />
<TextBlock Text="{x:Static properties:Resources.PackageView_ButtonPackageArguments}" FontSize="16"/>
</StackPanel>
</Button>
<StackPanel Orientation="Horizontal"
Visibility="{Binding IsInstalled, Converter={StaticResource BooleanToVisibility}, ConverterParameter=True}">
<Button Padding="10" Margin="5 0"
Expand Down
27 changes: 27 additions & 0 deletions Source/ChocolateyGui.Common/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Source/ChocolateyGui.Common/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1058,4 +1058,15 @@ Please contact your System Administrator to enable this operation.</value>
<data name="SettingsView_SearchWatermark" xml:space="preserve">
<value>Search...</value>
</data>
<data name="Application_PackageArgumentsError" xml:space="preserve">
<value>There as an error attempting to read the contents of the .arguments file for version {0} of package '{1}'. See log file for more information.</value>
<comment>{0} = The version of the selected package {1} = The id for the currently selected package</comment>
</data>
<data name="PackageView_ButtonPackageArguments" xml:space="preserve">
<value>View Package Arguments</value>
</data>
<data name="PackageView_UnableToFindArgumentsFile" xml:space="preserve">
<value>Unable to locate .arguments file for version {0} of package '{1}'</value>
<comment>{0} = The version of the selected package {1} = The id for the currently selected package</comment>
</data>
</root>

0 comments on commit 1fafb45

Please sign in to comment.