This repository has been archived on 2025-09-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Password-Manager-Legacy/Password Manager/MainForm.cs

82 lines
2.5 KiB
C#
Raw Normal View History

2023-03-27 22:13:40 +02:00
using System.Diagnostics;
2023-03-24 10:17:54 +01:00
namespace Password_Manager
{
sealed public partial class MainForm : Form
2023-03-24 10:17:54 +01:00
{
public event DataRequest PathRequest;
2023-03-28 10:35:23 +02:00
public event DataRequest? RecipientRequest;
2023-03-24 11:14:49 +01:00
2023-03-28 10:35:23 +02:00
public MainForm(DataRequest PathRequest, DataRequest RecipientRequest = null)
2023-03-24 11:14:49 +01:00
{
this.PathRequest = PathRequest;
2023-03-28 10:35:23 +02:00
this.RecipientRequest = RecipientRequest;
InitializeComponent();
2023-03-27 09:30:41 +02:00
2023-03-27 22:13:40 +02:00
ResultList.SearchQueryRequest += () => SearchBox.Text;
ResultList.ReloadResults();
}
private void ReloadResults(object? sender, EventArgs? e) //proxy method for SearchBox.TextChanged
{
ResultList.ReloadResults();
2023-03-27 09:30:41 +02:00
}
2023-03-28 13:26:30 +02:00
private void ReloadResults()
{
ResultList.ReloadResults();
}
private void OpenPasswordGenerator(object sender, EventArgs e)
2023-03-27 09:30:41 +02:00
{
2023-03-28 10:35:23 +02:00
if (RecipientRequest != null)
{
2023-03-28 13:26:30 +02:00
GeneratePassword gp = new GeneratePassword(PathRequest(), RecipientRequest(), ReloadResults, SearchBox.Text);
2023-03-28 10:35:23 +02:00
gp.ShowDialog();
}
else
{
2023-03-28 12:53:59 +02:00
throw new InvalidOperationException("You cannot use the OpenPasswordGenerator method if you instantiated this form without a RecipientRequest event handler.");
2023-03-28 10:35:23 +02:00
}
2023-03-27 09:30:41 +02:00
}
2023-03-27 22:13:40 +02:00
2023-03-28 08:22:08 +02:00
private void CancelPressed(object sender, EventArgs e)
{
Close();
}
2023-03-27 22:13:40 +02:00
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);
}
2023-03-28 08:22:08 +02:00
Close();
2023-03-27 22:13:40 +02:00
}
2023-03-24 10:17:54 +01:00
}
2023-03-28 10:35:23 +02:00
}