From 19b133215510b8d03c337927c4349e1d08d6279e Mon Sep 17 00:00:00 2001 From: Inestic <50652175+Inestic@users.noreply.github.com> Date: Fri, 15 Oct 2021 16:33:01 +0300 Subject: [PATCH] Code refactoring :recycle: --- ip2email/ip2email/Actions/ConfigApp.cs | 3 -- ip2email/ip2email/Actions/SendMail.cs | 12 ------ ip2email/ip2email/Classes/AppConfig.cs | 44 ---------------------- ip2email/ip2email/Helpers/ConsoleHelper.cs | 4 -- ip2email/ip2email/Helpers/TextHelper.cs | 13 +------ 5 files changed, 2 insertions(+), 74 deletions(-) diff --git a/ip2email/ip2email/Actions/ConfigApp.cs b/ip2email/ip2email/Actions/ConfigApp.cs index 1ec1f6d..088c88d 100644 --- a/ip2email/ip2email/Actions/ConfigApp.cs +++ b/ip2email/ip2email/Actions/ConfigApp.cs @@ -16,10 +16,7 @@ public void Do(string internetIP, List localIPs, ref AppExitCodes appExi appConfig.RecipientEmail = ConsoleHelper.SetOption("Recipient email address . . . : "); appConfig.SenderEmail = ConsoleHelper.SetOption("Sender email address. . . . . : "); appConfig.SenderPassword = ConsoleHelper.SetOption("Sender email password . . . . : "); -<<<<<<< HEAD -======= appConfig.EmailBody = ConsoleHelper.SetOption("Email body. . . . . . . . . . : "); ->>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f appConfig.EmailServer = ConsoleHelper.SetOption("Sender SMTP Server (for gmail.com use smtp.gmail.com) . . . : "); appConfig.EmailServerPort = ConsoleHelper.SetOption("Sender SMTP Port (for gmail.com use 587). . . . . . . . . . : "); ConsoleHelper.EmailSettingsSave(true); diff --git a/ip2email/ip2email/Actions/SendMail.cs b/ip2email/ip2email/Actions/SendMail.cs index c4843fe..bbc1ea2 100644 --- a/ip2email/ip2email/Actions/SendMail.cs +++ b/ip2email/ip2email/Actions/SendMail.cs @@ -9,21 +9,13 @@ namespace IP2Email.Classes { internal class SendMail : IArgsAction { -<<<<<<< HEAD - private void SendByEmail(AppConfig config, string ip) -======= private void SendEmail(AppConfig config, string ip) ->>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f { MailMessage message = new MailMessage(from: new MailAddress(config.SenderEmail, TextHelper.SenderDisplayName), to: new MailAddress(config.RecipientEmail)) { Subject = TextHelper.EmailSubject, -<<<<<<< HEAD - Body = $"{TextHelper.EmailBody}: {ip}", -======= Body = $"{TextHelper.EmailBody}: {ip}. {config.EmailBody}", ->>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f IsBodyHtml = false }; @@ -44,11 +36,7 @@ public void Do(string internetIP, List localIPs, ref AppExitCodes appExi { try { -<<<<<<< HEAD - SendByEmail(appConfig, internetIP); -======= SendEmail(appConfig, internetIP); ->>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f ConsoleHelper.EmailSend(senderEmail: appConfig.SenderEmail, recipientEmail: appConfig.RecipientEmail); } catch (Exception ex) diff --git a/ip2email/ip2email/Classes/AppConfig.cs b/ip2email/ip2email/Classes/AppConfig.cs index d5d9523..78d9367 100644 --- a/ip2email/ip2email/Classes/AppConfig.cs +++ b/ip2email/ip2email/Classes/AppConfig.cs @@ -13,10 +13,7 @@ internal AppConfig() SetIsConfiguredState(); } -<<<<<<< HEAD -======= internal string EmailBody { get => DecodeFromRegistry("EBO"); set => EncodeToRegistry("EBO", value); } ->>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f internal string EmailServer { get => DecodeFromRegistry("ESE"); set => EncodeToRegistry("ESE", value); } internal string EmailServerPort { get => DecodeFromRegistry("ESP"); set => EncodeToRegistry("ESP", value); } internal bool IsConfigured { get; set; } @@ -27,33 +24,6 @@ internal AppConfig() private string DecodeFromRegistry(string regKeyName) { string plaintext = null; -<<<<<<< HEAD - - try - { - byte[] regKeyValue = Registry.CurrentUser.OpenSubKey(TextHelper.RegistryKeySoftware, false) - .OpenSubKey(TextHelper.RegistryKeyAuthor) - .OpenSubKey(TextHelper.RegistryAppName) - .GetValue(regKeyName) as byte[]; - - if (regKeyValue != null) - { - using (Aes aes = Aes.Create()) - { - aes.Key = Encoding.UTF8.GetBytes(TextHelper.SecurityKey); - aes.IV = Encoding.UTF8.GetBytes(TextHelper.SecurityKey); - - ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, aes.IV); - - using (MemoryStream msDecrypt = new MemoryStream(regKeyValue)) - { - using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) - { - using (StreamReader srDecrypt = new StreamReader(csDecrypt)) - { - plaintext = srDecrypt.ReadToEnd(); - } -======= byte[] regKeyValue = Registry.CurrentUser.OpenSubKey(TextHelper.RegistryAppPath)?.GetValue(regKeyName) as byte[]; if (regKeyValue != null) @@ -72,19 +42,11 @@ private string DecodeFromRegistry(string regKeyName) using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { plaintext = srDecrypt.ReadToEnd(); ->>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f } } } } } -<<<<<<< HEAD - catch - { - return null; - } -======= ->>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f return plaintext; } @@ -109,15 +71,9 @@ private void EncodeToRegistry(string regKeyName, string regKeyValue) } Registry.CurrentUser.OpenSubKey(TextHelper.RegistryKeySoftware, true) -<<<<<<< HEAD - .CreateSubKey(TextHelper.RegistryKeyAuthor, true) - .CreateSubKey(TextHelper.RegistryAppName, true) - .SetValue(regKeyName, msEncrypt.ToArray()); -======= .CreateSubKey(TextHelper.RegistryKeyAuthor, true) .CreateSubKey(TextHelper.RegistryAppName, true) .SetValue(regKeyName, msEncrypt.ToArray()); ->>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f } } } diff --git a/ip2email/ip2email/Helpers/ConsoleHelper.cs b/ip2email/ip2email/Helpers/ConsoleHelper.cs index 126c003..bb6b69b 100644 --- a/ip2email/ip2email/Helpers/ConsoleHelper.cs +++ b/ip2email/ip2email/Helpers/ConsoleHelper.cs @@ -46,11 +46,7 @@ internal static void ShowAppBanner() Console.WriteLine(); Console.WriteLine("IP2Email sends an email with your public IP address got by https://ifconfig.me"); Console.WriteLine("Copyright (C) 2020 — 2021, Inestic"); -<<<<<<< HEAD - Console.WriteLine("https://github.com/inestic/ip2email"); -======= Console.WriteLine("https://github.com/Inestic/ip2email"); ->>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f Console.WriteLine(); } diff --git a/ip2email/ip2email/Helpers/TextHelper.cs b/ip2email/ip2email/Helpers/TextHelper.cs index 08f1b30..e57181d 100644 --- a/ip2email/ip2email/Helpers/TextHelper.cs +++ b/ip2email/ip2email/Helpers/TextHelper.cs @@ -10,19 +10,10 @@ internal static class TextHelper internal static readonly string FailedGetLocalIP = "Failed to obtain local IP address"; internal static readonly string InternetIpSite = "https://ifconfig.me/ip"; internal static readonly string RegistryAppName = "IP2Email"; -<<<<<<< HEAD - internal static readonly string RegistryKeyAuthor = "Inestic"; - internal static readonly string RegistryKeySoftware = "Software"; - internal static readonly string SecurityKey = ""; - internal static readonly string SenderDisplayName = "IP2Email"; - } -} -======= internal static readonly string RegistryAppPath = $@"{RegistryKeySoftware}\{RegistryKeyAuthor}\{RegistryAppName}"; internal static readonly string RegistryKeyAuthor = "Inestic"; internal static readonly string RegistryKeySoftware = "Software"; - internal static readonly string SecurityKey = "1234567812345678"; + internal static readonly string SecurityKey = ""; internal static readonly string SenderDisplayName = "IP2Email"; } -} ->>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f +} \ No newline at end of file