diff --git a/WoL/Waker/MainForm.cs b/WoL/Waker/MainForm.cs index 27088dd..78140f4 100644 --- a/WoL/Waker/MainForm.cs +++ b/WoL/Waker/MainForm.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WakeOnLan; +using System.Configuration; namespace Waker { @@ -24,32 +25,31 @@ namespace Waker private void InitInstance() { - if (string.IsNullOrEmpty(Settings.Default.ip)) + string path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath; + + if (!string.IsNullOrEmpty(Settings.Default.ip)) ip = Settings.Default.ip; - if (string.IsNullOrEmpty(Settings.Default.mac)) + if (!string.IsNullOrEmpty(Settings.Default.mac)) mac = Settings.Default.mac; + FillInformation(); + AddressTextBox.KeyUp += TextBox_KeyUp; MacTextBox.KeyUp += TextBox_KeyUp; } - private void TextBox_KeyUp(object sender, KeyEventArgs e) - { - if (e.KeyCode != Keys.Enter) - return; - - WakeButton_Click(sender, e); - } - private bool GetInformation() { - ip = AddressTextBox.Text; - mac = MacTextBox.Text; + ip = AddressTextBox.Text.Replace(" ", ""); + mac = MacTextBox.Text.Replace(" ", ""); if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(mac)) return false; + AddressTextBox.Text = ip; + MacTextBox.Text = mac; + Settings.Default.ip = ip; Settings.Default.mac = mac; Settings.Default.Save(); @@ -57,6 +57,15 @@ namespace Waker return true; } + private void FillInformation() + { + if (!string.IsNullOrEmpty(ip)) + AddressTextBox.Text = ip; + + if (!string.IsNullOrEmpty(mac)) + MacTextBox.Text = mac; + } + private void WakeButton_Click(object sender, EventArgs e) { if (!GetInformation()) @@ -65,7 +74,21 @@ namespace Waker return; } - WoL.Wake(ip, mac); + try + { + WoL.Wake(ip, mac); + } catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + + private void TextBox_KeyUp(object sender, KeyEventArgs e) + { + if (e.KeyCode != Keys.Enter) + return; + + WakeButton_Click(sender, e); } } }