remotes/origin/master
syneffort 3 years ago
parent 2e2d2b7487
commit 37a840cf3f
  1. 47
      WoL/Waker/MainForm.cs

@ -8,6 +8,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using WakeOnLan; using WakeOnLan;
using System.Configuration;
namespace Waker namespace Waker
{ {
@ -24,32 +25,31 @@ namespace Waker
private void InitInstance() 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; ip = Settings.Default.ip;
if (string.IsNullOrEmpty(Settings.Default.mac)) if (!string.IsNullOrEmpty(Settings.Default.mac))
mac = Settings.Default.mac; mac = Settings.Default.mac;
FillInformation();
AddressTextBox.KeyUp += TextBox_KeyUp; AddressTextBox.KeyUp += TextBox_KeyUp;
MacTextBox.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() private bool GetInformation()
{ {
ip = AddressTextBox.Text; ip = AddressTextBox.Text.Replace(" ", "");
mac = MacTextBox.Text; mac = MacTextBox.Text.Replace(" ", "");
if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(mac)) if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(mac))
return false; return false;
AddressTextBox.Text = ip;
MacTextBox.Text = mac;
Settings.Default.ip = ip; Settings.Default.ip = ip;
Settings.Default.mac = mac; Settings.Default.mac = mac;
Settings.Default.Save(); Settings.Default.Save();
@ -57,6 +57,15 @@ namespace Waker
return true; 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) private void WakeButton_Click(object sender, EventArgs e)
{ {
if (!GetInformation()) if (!GetInformation())
@ -65,7 +74,21 @@ namespace Waker
return; return;
} }
try
{
WoL.Wake(ip, mac); 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);
} }
} }
} }

Loading…
Cancel
Save