2023-04-02 22:10:42 +02:00
namespace GUI ;
sealed public partial class MainForm : Form
2023-03-24 10:17:54 +01:00
{
2023-04-02 22:10:42 +02: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-04-02 22:10:42 +02:00
public MainForm ( DataRequest PathRequest , DataRequest ? RecipientRequest = null )
{
this . PathRequest = PathRequest ;
2023-03-28 10:35:23 +02:00
this . RecipientRequest = RecipientRequest ;
2023-04-02 22:10:42 +02:00
InitializeComponent ( ) ;
2023-03-27 09:30:41 +02:00
2023-04-02 22:10:42 +02:00
ResultList . SearchQueryRequest + = ( ) = > SearchBox . Text ;
ResultList . ReloadResults ( ) ;
}
2023-03-27 22:13:40 +02:00
2023-04-02 22:10:42 +02:00
private void ReloadResults ( object? sender , EventArgs ? e ) //proxy method for SearchBox.TextChanged
{
ResultList . ReloadResults ( ) ;
}
2023-03-27 09:30:41 +02:00
2023-04-02 22:10:42 +02:00
private void ReloadResults ( )
{
ResultList . ReloadResults ( ) ;
}
2023-03-28 13:26:30 +02:00
2023-04-02 22:10:42 +02:00
private void OpenPasswordGenerator ( object sender , EventArgs e )
{
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-04-02 22:10:42 +02:00
}
2023-03-27 22:13:40 +02:00
2023-04-02 22:10:42 +02:00
private void CancelPressed ( object sender , EventArgs e )
{
Close ( ) ;
}
2023-03-28 08:22:08 +02:00
2023-03-31 07:28:55 +02:00
private void CopyAndNotify ( string? line , string fileName )
2023-03-29 14:38:59 +02:00
{
2023-04-02 22:10:42 +02:00
ProcessBuilder pb = new ProcessBuilder ( ) ;
pb . ProcessFailed + = ( e ) = > MessageBox . Show ( e . ToString ( ) , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
if ( line ! = null )
{
Clipboard . SetText ( line ) ;
pb . Run ( "./ToastNotification.exe" , $"\" { fileName } decrypted \ " \"Password copied to clipboard\"" ) ;
}
else
{
pb . Run ( "./ToastNotification.exe" , "\"Error\" \"No password copied\"" ) ;
}
2023-03-29 14:38:59 +02:00
}
2023-04-02 22:10:42 +02:00
private void Decrypt ( object sender , EventArgs e )
{
ProcessBuilder pb = new ProcessBuilder ( ) ;
2023-03-31 07:28:55 +02:00
pb . ProcessFailed + = ( e ) = > MessageBox . Show ( e . ToString ( ) , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
CopyAndNotify ( pb . GetOutput ( "gpg.exe" , $"--quiet --decrypt {PathRequest()}\\{ResultList.Text}" ) , ResultList . Text ) ;
2023-04-02 22:10:42 +02:00
Close ( ) ;
2023-03-24 10:17:54 +01:00
}
2023-03-28 10:35:23 +02:00
}