Skip to content

Commit

Permalink
Code refactoring ♻️
Browse files Browse the repository at this point in the history
  • Loading branch information
Inestic committed Oct 15, 2021
1 parent 6691c54 commit 19b1332
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 74 deletions.
3 changes: 0 additions & 3 deletions ip2email/ip2email/Actions/ConfigApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ public void Do(string internetIP, List<string> 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);
Expand Down
12 changes: 0 additions & 12 deletions ip2email/ip2email/Actions/SendMail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand All @@ -44,11 +36,7 @@ public void Do(string internetIP, List<string> localIPs, ref AppExitCodes appExi
{
try
{
<<<<<<< HEAD
SendByEmail(appConfig, internetIP);
=======
SendEmail(appConfig, internetIP);
>>>>>>> 6c0a5d048f41f68a5de63dee15f0d81e87e6ad0f
ConsoleHelper.EmailSend(senderEmail: appConfig.SenderEmail, recipientEmail: appConfig.RecipientEmail);
}
catch (Exception ex)
Expand Down
44 changes: 0 additions & 44 deletions ip2email/ip2email/Classes/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions ip2email/ip2email/Helpers/ConsoleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
13 changes: 2 additions & 11 deletions ip2email/ip2email/Helpers/TextHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 19b1332

Please sign in to comment.