77 lines
2.4 KiB
C#
77 lines
2.4 KiB
C#
using System.Diagnostics;
|
|
|
|
namespace Password_Manager
|
|
{
|
|
sealed public partial class MainForm : Form
|
|
{
|
|
public event DataRequest PathRequest;
|
|
public event DataRequest? RecipientRequest;
|
|
|
|
public MainForm(DataRequest PathRequest, DataRequest RecipientRequest = null)
|
|
{
|
|
this.PathRequest = PathRequest;
|
|
this.RecipientRequest = RecipientRequest;
|
|
InitializeComponent();
|
|
|
|
ResultList.SearchQueryRequest += () => SearchBox.Text;
|
|
ResultList.ReloadResults();
|
|
}
|
|
|
|
private void ReloadResults(object? sender, EventArgs? e) //proxy method for SearchBox.TextChanged
|
|
{
|
|
ResultList.ReloadResults();
|
|
}
|
|
|
|
private void OpenPasswordGenerator(object sender, EventArgs e)
|
|
{
|
|
if (RecipientRequest != null)
|
|
{
|
|
GeneratePassword gp = new GeneratePassword(SearchBox.Text, PathRequest(), RecipientRequest());
|
|
gp.ShowDialog();
|
|
}
|
|
else
|
|
{
|
|
throw new InvalidOperationException("You cannot use the OpenPasswordGenerator method if you instantiated this form without a RecipientRequest event handler.");
|
|
}
|
|
}
|
|
|
|
private void CancelPressed(object sender, EventArgs e)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
private void Decrypt(object sender, EventArgs e)
|
|
{
|
|
string fileName = ResultList.Text;
|
|
try
|
|
{
|
|
Process proc = new Process()
|
|
{
|
|
StartInfo = new ProcessStartInfo
|
|
{
|
|
FileName = "gpg.exe",
|
|
Arguments = $"--quiet --decrypt {PathRequest()}\\{fileName}",
|
|
UseShellExecute = false,
|
|
RedirectStandardOutput = true,
|
|
CreateNoWindow = true
|
|
}
|
|
};
|
|
|
|
proc.Start();
|
|
while (!proc.StandardOutput.EndOfStream)
|
|
{
|
|
string line = proc.StandardOutput.ReadLine();
|
|
Clipboard.SetText(line);
|
|
Process.Start("./ToastNotification.exe", $"\"{fileName} decrypted\" \"Password copied to clipboard\"");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
|
|
Close();
|
|
}
|
|
}
|
|
}
|