You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
2.7 KiB
131 lines
2.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using WakeOnLan;
|
|
using System.Configuration;
|
|
|
|
namespace Waker
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
private string ip;
|
|
private string mac;
|
|
private string ports;
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
InitInstance();
|
|
}
|
|
|
|
private void InitInstance()
|
|
{
|
|
string path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
|
|
|
|
if (!string.IsNullOrEmpty(Settings.Default.ip))
|
|
ip = Settings.Default.ip;
|
|
|
|
if (!string.IsNullOrEmpty(Settings.Default.mac))
|
|
mac = Settings.Default.mac;
|
|
|
|
if (!string.IsNullOrEmpty(Settings.Default.ports))
|
|
ports = Settings.Default.ports;
|
|
|
|
FillInformation();
|
|
|
|
AddressTextBox.KeyUp += TextBox_KeyUp;
|
|
MacTextBox.KeyUp += TextBox_KeyUp;
|
|
PortTextBox.KeyUp += TextBox_KeyUp;
|
|
}
|
|
|
|
private bool GetInformation()
|
|
{
|
|
ip = AddressTextBox.Text.Replace(" ", "");
|
|
mac = MacTextBox.Text.Replace(" ", "");
|
|
ports = PortTextBox.Text.Replace(" ", "");
|
|
|
|
if (string.IsNullOrEmpty(ip) || string.IsNullOrEmpty(mac))
|
|
return false;
|
|
|
|
AddressTextBox.Text = ip;
|
|
MacTextBox.Text = mac;
|
|
PortTextBox.Text = ports;
|
|
|
|
Settings.Default.ip = ip;
|
|
Settings.Default.mac = mac;
|
|
Settings.Default.ports = ports;
|
|
|
|
Settings.Default.Save();
|
|
|
|
return true;
|
|
}
|
|
|
|
private void FillInformation()
|
|
{
|
|
if (!string.IsNullOrEmpty(ip))
|
|
AddressTextBox.Text = ip;
|
|
|
|
if (!string.IsNullOrEmpty(mac))
|
|
MacTextBox.Text = mac;
|
|
|
|
if (!string.IsNullOrEmpty(ports))
|
|
PortTextBox.Text = ports;
|
|
}
|
|
|
|
private void WakeButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (!GetInformation())
|
|
{
|
|
MessageBox.Show("Invalid information");
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
string portsString = ports.Replace(" ", "");
|
|
|
|
if (string.IsNullOrEmpty(portsString))
|
|
{
|
|
WoL.Wake(ip, mac);
|
|
return;
|
|
}
|
|
|
|
|
|
string[] portStringArray = portsString.Split(',');
|
|
if (portStringArray == null || portStringArray.Length < 1 || string.IsNullOrEmpty(portStringArray[0]))
|
|
{
|
|
WoL.Wake(ip, mac);
|
|
return;
|
|
}
|
|
|
|
|
|
int[] portArray = portStringArray.Select(int.Parse).ToArray();
|
|
if (portArray == null || portArray.Length< 1)
|
|
{
|
|
WoL.Wake(ip, mac);
|
|
return;
|
|
}
|
|
|
|
|
|
WoL.Wake(ip, mac, portArray);
|
|
} 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);
|
|
}
|
|
}
|
|
}
|
|
|