Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Try support for GnuPG2/GPG2.exe (Issue #25), cleanup _binaryPath (Issue

#22).
  • Loading branch information...
commit bc4c9104bfaef096afd9e8151155dc846dd81224 1 parent 3c06f00
@twalrant authored
Showing with 13 additions and 17 deletions.
  1. +0 −10 OutlookGnuPG/OutlookGnuPG.cs
  2. +13 −7 References/OpenPGP/src/GnuPG.cs
View
10 OutlookGnuPG/OutlookGnuPG.cs
@@ -1215,12 +1215,7 @@ internal void Settings()
#region Key Management
internal IList<GnuKey> GetPrivateKeys()
{
- string gnuPath = _gnuPg.BinaryPath;
- if (!gnuPath.EndsWith("gpg.exe"))
- _gnuPg.BinaryPath = Path.Combine(gnuPath, "gpg.exe");
-
GnuPGKeyCollection privateKeys = _gnuPg.GetSecretKeys();
- _gnuPg.BinaryPath = gnuPath;
List<GnuKey> keys = new List<GnuKey>();
foreach (GnuPGKey privateKey in privateKeys)
@@ -1250,12 +1245,7 @@ internal IList<GnuKey> GetPrivateKeys(string gnuPgPath)
public IList<GnuKey> GetKeys()
{
- string gnuPath = _gnuPg.BinaryPath;
- if (!gnuPath.EndsWith("gpg.exe"))
- _gnuPg.BinaryPath = Path.Combine(gnuPath, "gpg.exe");
-
GnuPGKeyCollection privateKeys = _gnuPg.GetKeys();
- _gnuPg.BinaryPath = gnuPath;
List<GnuKey> keys = new List<GnuKey>();
foreach (GnuPGKey privateKey in privateKeys)
View
20 References/OpenPGP/src/GnuPG.cs
@@ -134,6 +134,7 @@ public class GnuPG : IDisposable
private Stream _errorStream;
private const string GPG_EXECUTABLE = "gpg.exe";
+ private const string GPG2_EXECUTABLE = "gpg2.exe";
private const string GPG_REGISTRY_KEY_UNINSTALL = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\GnuPG";
private const string GPG_REGISTRY_VALUE_INSTALLLOCATION = "InstallLocation";
private const string GPG_REGISTRY_VALUE_DISPLAYVERSION = "DisplayVersion";
@@ -427,10 +428,14 @@ private StreamReader GetCommand(string command)
options.Append(command);
- string gpgPath = string.IsNullOrEmpty(_binaryPath) ? Path.Combine(GetGPGInstallLocation(), GPG_EXECUTABLE) : _binaryPath;
+ string gpgExe = Path.Combine(GetGPGInstallLocation(), GPG2_EXECUTABLE);
+ if (!File.Exists(gpgExe))
+ gpgExe = Path.Combine(GetGPGInstallLocation(), GPG_EXECUTABLE);
+ if (!File.Exists(gpgExe))
+ throw new GnuPGException(String.Format(CultureInfo.InvariantCulture, "Unable to find GPG.EXE. The path '{0}' does not contain the GPG(2).EXE executable program. If this path is incorrect, please set the binary path on the GnuPG object to the correct GnuPG directory", GetGPGInstallLocation()));
// create a process info object with command line options
- ProcessStartInfo procInfo = new ProcessStartInfo(gpgPath, options.ToString());
+ ProcessStartInfo procInfo = new ProcessStartInfo(gpgExe, options.ToString());
// init the procInfo object
procInfo.CreateNoWindow = true;
@@ -587,13 +592,14 @@ private void ExecuteGPG(ActionTypes action, Stream inputStream, Stream outputStr
{
string gpgErrorText = string.Empty;
- string gpgPath = Path.Combine(GetGPGInstallLocation(), GPG_EXECUTABLE);
-
- if (!File.Exists(gpgPath))
+ string gpgExe = Path.Combine(GetGPGInstallLocation(), GPG2_EXECUTABLE);
+ if (!File.Exists(gpgExe))
+ gpgExe = Path.Combine(GetGPGInstallLocation(), GPG_EXECUTABLE);
+ if (!File.Exists(gpgExe))
throw new GnuPGException(String.Format(CultureInfo.InvariantCulture, "Unable to find GPG.EXE. The path '{0}' does not contain the GPG.EXE executable program. If this path is incorrect, please set the binary path on the GnuPG object to the correct GnuPG directory", GetGPGInstallLocation()));
// create a process info object with command line options
- ProcessStartInfo procInfo = new ProcessStartInfo(gpgPath, GetCmdLineSwitches(action));
+ ProcessStartInfo procInfo = new ProcessStartInfo(gpgExe, GetCmdLineSwitches(action));
// init the procInfo object
procInfo.CreateNoWindow = true;
@@ -673,7 +679,7 @@ private void ExecuteGPG(ActionTypes action, Stream inputStream, Stream outputStr
private string GetGPGInstallLocation()
{
// test to see if the binary path is set
- if (_binaryPath != null && _binaryPath.Length > 0)
+ if (string.IsNullOrEmpty(_binaryPath) != true)
return _binaryPath;
RegistryKey hKeyLM = Registry.LocalMachine;
Please sign in to comment.
Something went wrong with that request. Please try again.