From ad88e3ebe16fea2ba13acc1eac58e8faa3472852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Sun, 2 Apr 2023 22:40:47 +0200 Subject: [PATCH] Switched messageboxes to custom events --- Common/ConfigFileManager.cs | 4 +++- Common/PasswordGenerator.cs | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Common/ConfigFileManager.cs b/Common/ConfigFileManager.cs index 0906764..f1403ea 100644 --- a/Common/ConfigFileManager.cs +++ b/Common/ConfigFileManager.cs @@ -2,6 +2,7 @@ namespace Common; +public delegate void Error(Exception e); public static class ConfigFileManager { #region Config flags @@ -17,6 +18,7 @@ public static class ConfigFileManager #endregion private static Config Configuration; + public static event Error? ExceptionOccured; public static void Init() { @@ -87,7 +89,7 @@ public static class ConfigFileManager } catch (Exception e) { - MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + ExceptionOccured?.Invoke(e); } } } diff --git a/Common/PasswordGenerator.cs b/Common/PasswordGenerator.cs index 44aa972..0603694 100644 --- a/Common/PasswordGenerator.cs +++ b/Common/PasswordGenerator.cs @@ -3,6 +3,7 @@ namespace Common; public static class PasswordGenerator { + public static Error? ExceptionOccured; private static string RandomStr(int length, bool no_symbols = false) { StringBuilder builder = new StringBuilder(); @@ -32,6 +33,8 @@ public static class PasswordGenerator public static string? New(string recipient, int length, bool no_symbols = false) { - return new ProcessBuilder().GetOutput("cmd.exe", $"echo {RandomStr(length, no_symbols)} | gpg --quiet --encrypt --recipient {recipient}"); + ProcessBuilder pb = new ProcessBuilder(); + pb.ProcessFailed += (e) => ExceptionOccured?.Invoke(e); + return pb.GetOutput("cmd.exe", $"echo {RandomStr(length, no_symbols)} | gpg --quiet --encrypt --recipient {recipient}"); } }