コード例 #1
0
        public void Execute()
        {
            var powerShell = new ProcessStartInfo
            {
                FileName         = "powershell",
                WorkingDirectory = passwordStore.Location,
                UseShellExecute  = false
            };

            var gpgExe = installation.GpgExecutable.FullName;

            var homeDir = string.Empty;

            if (homedirResolver.GetConfiguredHomeDir() != null)
            {
                homeDir = $" --homedir \"{fileSystem.Path.GetFullPath(homedirResolver.GetConfiguredHomeDir())}\"";
            }
            powerShell.Arguments =
                $"-NoExit -Command \"function gpg() {{ & '{gpgExe}'{homeDir} $args }};" +
                $"echo '\n" +
                $"    ╔══════════════════════════════════════════════════════════╗\n" +
                $"    ║ In this  shell, you can execute  arbitrary GPG commands. ║\n" +
                $"    ║ The ''gpg'' command  has been aliased  to the same version ║\n" +
                $"    ║ of GPG  used by pass-winmenu, and configured to make use ║\n" +
                $"    ║ of the  same  home  directory, so  you can  access  your ║\n" +
                $"    ║ password store GPG keys from here.                       ║\n" +
                $"    ╚══════════════════════════════════════════════════════════╝\n" +
                $"'\"";
            processes.Start(powerShell);
        }
コード例 #2
0
        /// <summary>
        /// Generates a ProcessStartInfo object that can be used to spawn a GPG process.
        /// </summary>
        private ProcessStartInfo CreateGpgProcessStartInfo(string arguments, bool redirectStdin)
        {
            // Maybe use --display-charset utf-8?
            var argList = new List <string>
            {
                "--batch",                      // Ensure GPG does not ask for input or user action
                "--no-tty",                     // Let GPG know we're not a TTY
                "--status-fd 2",                // Write status messages to stderr
                "--with-colons",                // Use colon notation for displaying keys
                "--exit-on-status-write-error", //  Exit if status messages cannot be written
            };
            var homedirOverride = homedirResolver.GetConfiguredHomeDir();

            if (homedirOverride != null)
            {
                argList.Add($"--homedir \"{homedirOverride}\"");
            }

            var psi = new ProcessStartInfo
            {
                FileName               = installation.GpgExecutable.FullName,
                Arguments              = $"{string.Join(" ", argList)} {arguments}",
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                RedirectStandardInput  = redirectStdin,
                CreateNoWindow         = true
            };

            return(psi);
        }