62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
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 ReloadResults()
|
|
{
|
|
ResultList.ReloadResults();
|
|
}
|
|
|
|
private void OpenPasswordGenerator(object sender, EventArgs e)
|
|
{
|
|
if (RecipientRequest != null)
|
|
{
|
|
GeneratePassword gp = new GeneratePassword(PathRequest(), RecipientRequest(), ReloadResults, SearchBox.Text);
|
|
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 CopyAndNotify(string line)
|
|
{
|
|
Clipboard.SetText(line);
|
|
|
|
ProcessBuilder.ProcessFailed += (e) => MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
ProcessBuilder.Run("./ToastNotification.exe", $"\"{fileName} decrypted\" \"Password copied to clipboard\"");
|
|
}
|
|
|
|
private void Decrypt(object sender, EventArgs e)
|
|
{
|
|
ProcessBuilder.ProcessFailed += (e) => MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
CopyAndNotify(ProcessBuilder.GetOutput("gpg.exe", $"--quiet --decrypt {PathRequest()}\\{ResultList.Text}"));
|
|
Close();
|
|
}
|
|
}
|
|
}
|