forked from chocolatey/ChocolateyGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request chocolatey#834 from steviecoaster/gh770
(chocolatey#770) Provide ability to "see" saved installation parameters
- Loading branch information
Showing
8 changed files
with
369 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Source/ChocolateyGui.Common.Windows/Services/IPackageArgumentsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <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> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace ChocolateyGui.Common.Windows.Services | ||
{ | ||
public interface IPackageArgumentsService | ||
{ | ||
IEnumerable<string> DecryptPackageArgumentsFile(string id, string version); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
Source/ChocolateyGui.Common.Windows/Services/PackageArgumentsService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <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 System.Collections.Generic; | ||
using chocolatey; | ||
using chocolatey.infrastructure.adapters; | ||
using chocolatey.infrastructure.app.utility; | ||
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; | ||
private readonly IDialogService _dialogService; | ||
|
||
public PackageArgumentsService( | ||
IEncryptionUtility encryptionUtility, | ||
IFileSystem fileSystem, | ||
IChocolateyConfigurationProvider chocolateyConfigurationProvider, | ||
IDialogService dialogService) | ||
{ | ||
_encryptionUtility = encryptionUtility; | ||
_fileSystem = fileSystem; | ||
_chocolateyConfigurationProvider = chocolateyConfigurationProvider; | ||
_dialogService = dialogService; | ||
} | ||
|
||
public IEnumerable<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"); | ||
|
||
string arguments = string.Empty; | ||
|
||
// Get the arguments decrypted in here and return them | ||
try | ||
{ | ||
if (_fileSystem.file_exists(argumentsFile)) | ||
{ | ||
arguments = _fileSystem.read_file(argumentsFile); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
var message = Resources.Application_PackageArgumentsError.format_with(version, id); | ||
Logger.Error(ex, message); | ||
} | ||
|
||
if (string.IsNullOrEmpty(arguments)) | ||
{ | ||
_dialogService.ShowMessageAsync( | ||
string.Empty, | ||
Resources.PackageView_UnableToFindArgumentsFile.format_with(version, id)); | ||
yield break; | ||
} | ||
|
||
// The following code is borrowed from the Chocolatey codebase, should | ||
// be extracted to a separate location in choco executable so we can re-use it. | ||
var packageArgumentsUnencrypted = arguments.contains(" --") && arguments.to_string().Length > 4 | ||
? arguments | ||
: _encryptionUtility.decrypt_string(arguments); | ||
|
||
var sensitiveArgs = ArgumentsUtility.arguments_contain_sensitive_information(packageArgumentsUnencrypted); | ||
|
||
var packageArgumentsSplit = | ||
packageArgumentsUnencrypted.Split(new[] { " --" }, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
foreach (var packageArgument in packageArgumentsSplit.or_empty_list_if_null()) | ||
{ | ||
var packageArgumentSplit = | ||
packageArgument.Split(new[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries); | ||
var optionName = packageArgumentSplit[0].to_string(); | ||
var optionValue = string.Empty; | ||
|
||
if (packageArgumentSplit.Length == 2) | ||
{ | ||
optionValue = packageArgumentSplit[1].to_string().remove_surrounding_quotes(); | ||
if (optionValue.StartsWith("'")) | ||
{ | ||
optionValue.remove_surrounding_quotes(); | ||
} | ||
} | ||
|
||
yield return "--{0}{1}".format_with( | ||
optionName, | ||
string.IsNullOrWhiteSpace(optionValue) ? string.Empty : "=" + optionValue); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.