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.
(chocolatey#770) Begins to scaffold a Package Arguments button
* Adds PackageArgumentsService Interface * Adds button to PackageViewModel * Adds method for decrypting .arguments file
- Loading branch information
1 parent
7c94a89
commit 3503989
Showing
6 changed files
with
108 additions
and
1 deletion.
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
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <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; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ChocolateyGui.Common.Windows.Services | ||
{ | ||
public interface IPackageArgumentsService | ||
{ | ||
string Decrypt(string id, string version); | ||
|
||
string Encrypt(string id, string version); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
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,64 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <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 System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Security.Cryptography; | ||
using System.Threading.Tasks; | ||
using chocolatey; | ||
|
||
namespace ChocolateyGui.Common.Windows.Services | ||
{ | ||
public class PackageArgumentsService : IPackageArgumentsService | ||
{ | ||
private static readonly byte[] EntropyBytes = Encoding.UTF8.GetBytes("Chocolatey"); | ||
|
||
public string Decrypt(string id, string version) | ||
{ | ||
var packageFolder = "{0}.{1}"; | ||
var packageId = id; | ||
var packageVersion = version; | ||
var chocolateyPath = @"C:\ProgramData\chocolatey\.chocolatey"; | ||
var argumentsPath = Path.Combine(chocolateyPath, packageFolder.format_with(id, version)); | ||
var argumentsFile = Path.Combine(argumentsPath, ".arguments"); | ||
|
||
// Get the arguments decrypted in here and return them | ||
try | ||
{ | ||
if (File.Exists(argumentsFile)) | ||
{ | ||
string fileName = argumentsFile; | ||
var encryptedBytes = Convert.FromBase64String(File.ReadAllText(fileName)); | ||
var decryptedBytes = ProtectedData.Unprotect(encryptedBytes, EntropyBytes, DataProtectionScope.LocalMachine); | ||
string decryptedChocoArgs = Encoding.UTF8.GetString(decryptedBytes); | ||
return decryptedChocoArgs; | ||
} | ||
else | ||
{ | ||
throw new FileNotFoundException(); | ||
} | ||
} | ||
catch (FileNotFoundException) | ||
{ | ||
return "Chocolatey argument file not found"; | ||
} | ||
catch (Exception ex) | ||
{ | ||
return ex.Message; | ||
} | ||
|
||
} | ||
|
||
public string Encrypt(string id, string version) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
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