From: <kro...@us...> - 2010-10-30 18:34:07
|
Revision: 3877 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=3877&view=rev Author: kroko_koenig Date: 2010-10-30 18:34:00 +0000 (Sat, 30 Oct 2010) Log Message: ----------- initial check-in Added Paths: ----------- trunk/plugins/WakeOnLan/ trunk/plugins/WakeOnLan/Release/ trunk/plugins/WakeOnLan/Release/WakeOnLan.zip trunk/plugins/WakeOnLan/Source/ trunk/plugins/WakeOnLan/Source/WakeOnLan/ trunk/plugins/WakeOnLan/Source/WakeOnLan/Properties/ trunk/plugins/WakeOnLan/Source/WakeOnLan/Properties/AssemblyInfo.cs trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.Designer.cs trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.cs trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.resx trunk/plugins/WakeOnLan/Source/WakeOnLan/WOL.cs trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.cs trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.csproj trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.csproj.user trunk/plugins/WakeOnLan/Source/WakeOnLan/bin/ trunk/plugins/WakeOnLan/Source/WakeOnLan/bin/Debug/ trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/ trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/ trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/Refactor/ trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/ResolveAssemblyReference.cache trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/TempPE/ trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.Setup.resources trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.csproj.FileListAbsolute.txt trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.csproj.GenerateResource.Cache trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.dll trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.pdb trunk/plugins/WakeOnLan/Source/WakeOnLan/wake.png trunk/plugins/WakeOnLan/Source/WakeOnLan/wakeOff.png trunk/plugins/WakeOnLan/Source/WakeOnLan.sln trunk/plugins/WakeOnLan/Source/WakeOnLan.suo trunk/plugins/WakeOnLan/setup.jpg Added: trunk/plugins/WakeOnLan/Release/WakeOnLan.zip =================================================================== (Binary files differ) Property changes on: trunk/plugins/WakeOnLan/Release/WakeOnLan.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/Properties/AssemblyInfo.cs =================================================================== --- trunk/plugins/WakeOnLan/Source/WakeOnLan/Properties/AssemblyInfo.cs (rev 0) +++ trunk/plugins/WakeOnLan/Source/WakeOnLan/Properties/AssemblyInfo.cs 2010-10-30 18:34:00 UTC (rev 3877) @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die mit einer Assembly verknüpft sind. +[assembly: AssemblyTitle("WakeOnLan")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("HP")] +[assembly: AssemblyProduct("WakeOnLan")] +[assembly: AssemblyCopyright("Copyright © HP 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar +// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von +// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("add60110-5a5b-4f4b-95f2-93741677a0e9")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.Designer.cs =================================================================== --- trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.Designer.cs (rev 0) +++ trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.Designer.cs 2010-10-30 18:34:00 UTC (rev 3877) @@ -0,0 +1,217 @@ +namespace WakeOnLan +{ + partial class Setup + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + System.Windows.Forms.Timer tUpdate; + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.txtIp = new System.Windows.Forms.TextBox(); + this.txtMac = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.btnStart = new System.Windows.Forms.Button(); + this.chkRunning = new System.Windows.Forms.CheckBox(); + this.btnSave = new System.Windows.Forms.Button(); + this.btnCancel = new System.Windows.Forms.Button(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.infoTxt = new System.Windows.Forms.ToolStripStatusLabel(); + tUpdate = new System.Windows.Forms.Timer(this.components); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.txtIp); + this.groupBox1.Controls.Add(this.txtMac); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.label1); + this.groupBox1.Location = new System.Drawing.Point(18, 14); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(306, 93); + this.groupBox1.TabIndex = 0; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Server"; + // + // txtIp + // + this.txtIp.Location = new System.Drawing.Point(98, 53); + this.txtIp.Name = "txtIp"; + this.txtIp.Size = new System.Drawing.Size(164, 20); + this.txtIp.TabIndex = 3; + this.txtIp.Text = "192.168.10.20"; + // + // txtMac + // + this.txtMac.Location = new System.Drawing.Point(98, 26); + this.txtMac.Name = "txtMac"; + this.txtMac.Size = new System.Drawing.Size(164, 20); + this.txtMac.TabIndex = 2; + this.txtMac.Text = "12-34-56-78-90-12"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(19, 56); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(51, 13); + this.label2.TabIndex = 1; + this.label2.Text = "Server IP"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(19, 29); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(64, 13); + this.label1.TabIndex = 0; + this.label1.Text = "Server MAC"; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.btnStart); + this.groupBox2.Controls.Add(this.chkRunning); + this.groupBox2.Location = new System.Drawing.Point(18, 121); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(306, 75); + this.groupBox2.TabIndex = 2; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Test"; + // + // btnStart + // + this.btnStart.Location = new System.Drawing.Point(22, 30); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(97, 23); + this.btnStart.TabIndex = 1; + this.btnStart.Text = "Start Server"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.btnStart_Click); + // + // chkRunning + // + this.chkRunning.AutoSize = true; + this.chkRunning.Location = new System.Drawing.Point(172, 36); + this.chkRunning.Name = "chkRunning"; + this.chkRunning.Size = new System.Drawing.Size(105, 17); + this.chkRunning.TabIndex = 0; + this.chkRunning.Text = "Server is running"; + this.chkRunning.UseVisualStyleBackColor = true; + // + // btnSave + // + this.btnSave.Location = new System.Drawing.Point(18, 202); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(95, 33); + this.btnSave.TabIndex = 3; + this.btnSave.Text = "Save"; + this.btnSave.UseVisualStyleBackColor = true; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // btnCancel + // + this.btnCancel.Location = new System.Drawing.Point(229, 202); + this.btnCancel.Name = "btnCancel"; + this.btnCancel.Size = new System.Drawing.Size(95, 33); + this.btnCancel.TabIndex = 4; + this.btnCancel.Text = "Cancel"; + this.btnCancel.UseVisualStyleBackColor = true; + this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); + // + // statusStrip1 + // + this.statusStrip1.AutoSize = false; + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.infoTxt}); + this.statusStrip1.Location = new System.Drawing.Point(0, 252); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Size = new System.Drawing.Size(344, 22); + this.statusStrip1.SizingGrip = false; + this.statusStrip1.TabIndex = 5; + this.statusStrip1.Text = "statusStrip1"; + // + // infoTxt + // + this.infoTxt.Name = "infoTxt"; + this.infoTxt.Size = new System.Drawing.Size(96, 17); + this.infoTxt.Text = "nothing send yet"; + // + // tUpdate + // + tUpdate.Enabled = true; + tUpdate.Interval = 300; + tUpdate.Tick += new System.EventHandler(this.tUpdate_Tick); + // + // Setup + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(344, 274); + this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.btnCancel); + this.Controls.Add(this.btnSave); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "Setup"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Setup WakeOnLan"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Setup_FormClosing); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.TextBox txtIp; + private System.Windows.Forms.TextBox txtMac; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.CheckBox chkRunning; + private System.Windows.Forms.Button btnSave; + private System.Windows.Forms.Button btnCancel; + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripStatusLabel infoTxt; + } +} \ No newline at end of file Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.cs =================================================================== --- trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.cs (rev 0) +++ trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.cs 2010-10-30 18:34:00 UTC (rev 3877) @@ -0,0 +1,152 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +using System.Net; +using System.Net.Sockets; +using System.Net.NetworkInformation; +using System.Threading; + +namespace WakeOnLan +{ + public partial class Setup : Form + { + private Thread aPing; + private bool serverAvailable; + + public Setup() + { + InitializeComponent(); + LoadSettings(); + + aPing = new Thread(testServer); + aPing.Start(); + } + private void Setup_FormClosing(object sender, FormClosingEventArgs e) + { + aPing.Interrupt(); + aPing.Abort(); + } + + private void LoadSettings() + { + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MediaPortal.xml")) + { + txtMac.Text = xmlreader.GetValueAsString("wakeOnLan", "macId", "12-34-56-12-34-56"); + txtIp.Text = xmlreader.GetValueAsString("wakeOnLan", "ip", "192.168.0.50"); + } + } + private void SaveSettings() + { + using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings("MediaPortal.xml")) + { + xmlwriter.SetValue("wakeOnLan", "macId", txtMac.Text); + xmlwriter.SetValue("wakeOnLan", "ip", txtIp.Text); + } + + MediaPortal.Profile.Settings.SaveCache(); + } + + private void btnSave_Click(object sender, EventArgs e) + { + if (!WOL.CheckIp(txtIp.Text)) + { + MessageBox.Show("Enter a correct IP", "Error IP Adress"); + return; + } + if (WOL.GetMacId(txtMac.Text) == null) + { + MessageBox.Show("Enter a correct MAC ID", "Error MAC ID"); + return; + } + + SaveSettings(); + this.Close(); + } + private void btnCancel_Click(object sender, EventArgs e) + { + this.Close(); + } + private void btnStart_Click(object sender, EventArgs e) + { + byte[] myMac = WOL.GetMacId(txtMac.Text); + if (myMac != null) + { + if (WOL.CheckIp(txtIp.Text)) + { + IPAddress myIp = IPAddress.Parse(txtIp.Text); + IPAddress[] a = Dns.GetHostEntry(Dns.GetHostName()).AddressList; + + for (int i = 0; i < a.Length; i++) + { + byte[] myBytes = myIp.GetAddressBytes(); + byte[] othBytes = a[i].GetAddressBytes(); + if ((myBytes[0] == othBytes[0]) && + (myBytes[1] == othBytes[1]) && + (myBytes[2] == othBytes[2])) + { + infoTxt.Text = DateTime.Now.ToLongTimeString() + " : WOL to " + txtMac.Text; + WOL.WakeOnLan(myMac, a[i]); + return; + } + } + MessageBox.Show("Could not find matching sub-net", "Subnet ???"); + return; + } + else + { + MessageBox.Show("Enter a correct IP", "Error IP Adress"); + return; + } + } + else + { + MessageBox.Show("Enter a correct MAC ID", "Error MAC ID"); + return; + } + } + + private void testServer() + { + try + { + while (true) + { + try + { + if (WOL.CheckIp(txtIp.Text)) + { + IPAddress ip = IPAddress.Parse(txtIp.Text); + + Ping p = new Ping(); + PingReply rep = p.Send(ip, 2000); + + if (rep.Status == IPStatus.Success) + { + serverAvailable = true; + } + else + { + serverAvailable = false; + } + } + } + catch + { + serverAvailable = false; + } + } + } + catch { } + } + + private void tUpdate_Tick(object sender, EventArgs e) + { + chkRunning.Checked = serverAvailable; + } + } +} Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.resx =================================================================== --- trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.resx (rev 0) +++ trunk/plugins/WakeOnLan/Source/WakeOnLan/Setup.resx 2010-10-30 18:34:00 UTC (rev 3877) @@ -0,0 +1,129 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>17, 17</value> + </metadata> + <metadata name="tUpdate.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>133, 17</value> + </metadata> + <metadata name="tUpdate.GenerateMember" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> + <value>False</value> + </metadata> +</root> \ No newline at end of file Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/WOL.cs =================================================================== --- trunk/plugins/WakeOnLan/Source/WakeOnLan/WOL.cs (rev 0) +++ trunk/plugins/WakeOnLan/Source/WakeOnLan/WOL.cs 2010-10-30 18:34:00 UTC (rev 3877) @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using System.Net; +using System.Net.Sockets; + +namespace WakeOnLan +{ + public class WOL + { + public static void WakeOnLan(byte[] mac, IPAddress ip) + { + IPEndPoint myIp = new IPEndPoint(ip, 0); + + UdpClient client = new UdpClient(myIp); + client.Connect(IPAddress.Broadcast, 40000); + + // WOL packet contains a 6-bytes trailer and 16 times a 6-bytes sequence containing the MAC address. + byte[] packet = new byte[17 * 6]; + + // Trailer of 6 times 0xFF. + for (int i = 0; i < 6; i++) + packet[i] = 0xFF; + + // Body of magic packet contains 16 times the MAC address. + for (int i = 1; i <= 16; i++) + for (int j = 0; j < 6; j++) + packet[i * 6 + j] = mac[j]; + + // Send WOL packet. + client.Send(packet, packet.Length); + } + + public static byte[] GetMacId(string Input) + { + try + { + string[] val = Input.Split('-'); + if (val.Length == 6) + { + byte[] erg = new byte[6]; + for (int i = 0; i < 6; i++) + { + erg[i] = byte.Parse(val[i], System.Globalization.NumberStyles.HexNumber); + } + return erg; + } + } + catch { } + return null; + } + public static bool CheckIp(string Input) + { + try + { + IPAddress ip = IPAddress.Parse(Input); + return true; + } + catch { } + + return false; + } + } +} Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.cs =================================================================== --- trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.cs (rev 0) +++ trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.cs 2010-10-30 18:34:00 UTC (rev 3877) @@ -0,0 +1,205 @@ +#region Copyright (C) 2005-2010 Team MediaPortal + +/* + * Copyright (C) 2005-2010 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.Collections.Generic; +using System.Text; + +using MediaPortal.GUI.Library; +using MediaPortal.Configuration; + +using System.Net; +using System.Threading; +using System.Net.NetworkInformation; + +namespace WakeOnLan +{ + [PluginIcons("WakeOnLan.wake.png", "WakeOnLan.wakeOff.png")] + + public class WakeOnLan : IPlugin, ISetupForm + { + private string ip; + private string mac; + private bool serverAvailable = false; + + private Thread thread; + + #region IPlugin Member + + public void Start() + { + LoadSettings(); + + Log.Info("WakeOnLan : Start plugin"); + + Log.Info("WakeOnLan : Start keep alive thread"); + thread = new Thread(testServer); + thread.Start(); + + if (mac.Split('-').Length == 6) + { + Log.Info("WakeOnLan : Mac Id = " + mac); + + byte[] myMac = WOL.GetMacId(mac); + if (myMac != null) + { + Log.Info("WakeOnLan : IP Server = " + ip); + + IPAddress myIp = IPAddress.Parse(ip); + + if (myIp != null) + { + IPAddress[] lst = Dns.GetHostEntry(Dns.GetHostName()).AddressList; + + for (int i = 0; i < lst.Length; i++) + { + byte[] myBytes = myIp.GetAddressBytes(); + byte[] othBytes = lst[i].GetAddressBytes(); + + if ((myBytes[0] == othBytes[0]) && + (myBytes[1] == othBytes[1]) && + (myBytes[2] == othBytes[2])) + { + Log.Info("WakeOnLan : wake up server " + mac); + WOL.WakeOnLan(myMac, lst[i]); + return; + } + } + } + } + } + } + + public void Stop() + { + thread.Interrupt(); + thread.Abort(); + + Log.Info("WakeOnLan : Stop plugin"); + } + + #endregion + + #region ISetupForm Member + + public string Author() + { + return "Mark Koenig (kroko) 2010"; + } + + public bool CanEnable() + { + return true; + } + + public bool DefaultEnabled() + { + return true; + } + + public string Description() + { + return "Switch on the server via WOL and keep him running."; + } + + public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) + { + strButtonText = "WakeOnLan"; + strButtonImage = String.Empty; + strButtonImageFocus = String.Empty; + strPictureImage = "hover_WakeOnLan.png"; + return true; + } + + public int GetWindowId() + { + return 43873038; + } + + public bool HasSetup() + { + return true; + } + + public string PluginName() + { + return "WakeOnLan"; + } + + public void ShowPlugin() + { + Setup setup = new Setup(); + setup.ShowDialog(); + } + + #endregion + + private void LoadSettings() + { + using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings("MediaPortal.xml")) + { + mac = xmlreader.GetValueAsString("wakeOnLan", "macId", "12-34-56-12-34-56"); + ip = xmlreader.GetValueAsString("wakeOnLan", "ip", "192.168.0.50"); + } + } + + private void testServer() + { + try + { + while (true) + { + try + { + if (WOL.CheckIp(ip)) + { + IPAddress myIP = IPAddress.Parse(ip); + + Log.Info("WakeOnLan : ping IP Server = " + ip); + + Ping p = new Ping(); + PingReply rep = p.Send(myIP, 2000); + + if (rep.Status == IPStatus.Success) + { + this.serverAvailable = true; + } + else + { + this.serverAvailable = false; + } + } + Thread.Sleep(60000); + } + catch + { + this.serverAvailable = false; + } + } + } + catch { } + } + } +} Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.csproj =================================================================== --- trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.csproj (rev 0) +++ trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.csproj 2010-10-30 18:34:00 UTC (rev 3877) @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>9.0.21022</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{2E574157-D8EA-458E-B0FE-4CA9DF471445}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>WakeOnLan</RootNamespace> + <AssemblyName>WakeOnLan</AssemblyName> + <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>..\..\..\Program Files\Team MediaPortal\MediaPortal\plugins\process\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <UseVSHostingProcess>false</UseVSHostingProcess> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Core, Version=1.1.1.11854, Culture=neutral, processorArchitecture=x86"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\Program Files\Team MediaPortal\MediaPortal\Core.dll</HintPath> + <Private>False</Private> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Data" /> + <Reference Include="System.Drawing" /> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Xml" /> + <Reference Include="Utils, Version=2.2.7.11849, Culture=neutral, processorArchitecture=x86"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\Program Files\Team MediaPortal\MediaPortal\Utils.dll</HintPath> + <Private>False</Private> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="Setup.cs"> + <SubType>Form</SubType> + </Compile> + <Compile Include="Setup.Designer.cs"> + <DependentUpon>Setup.cs</DependentUpon> + </Compile> + <Compile Include="WakeOnLan.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="WOL.cs" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Setup.resx"> + <DependentUpon>Setup.cs</DependentUpon> + </EmbeddedResource> + <EmbeddedResource Include="wake.png" /> + <EmbeddedResource Include="wakeOff.png" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project> \ No newline at end of file Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.csproj.user =================================================================== --- trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.csproj.user (rev 0) +++ trunk/plugins/WakeOnLan/Source/WakeOnLan/WakeOnLan.csproj.user 2010-10-30 18:34:00 UTC (rev 3877) @@ -0,0 +1,9 @@ +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <StartAction>Program</StartAction> + <StartProgram>C:\Program Files\Team MediaPortal\MediaPortal\MediaPortal.exe</StartProgram> + </PropertyGroup> + <PropertyGroup> + <ProjectView>ProjectFiles</ProjectView> + </PropertyGroup> +</Project> \ No newline at end of file Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/ResolveAssemblyReference.cache =================================================================== (Binary files differ) Property changes on: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/ResolveAssemblyReference.cache ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.Setup.resources =================================================================== (Binary files differ) Property changes on: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.Setup.resources ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.csproj.FileListAbsolute.txt =================================================================== --- trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.csproj.FileListAbsolute.txt (rev 0) +++ trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.csproj.FileListAbsolute.txt 2010-10-30 18:34:00 UTC (rev 3877) @@ -0,0 +1,7 @@ +C:\Program Files\Team MediaPortal\MediaPortal\plugins\process\WakeOnLan.dll +C:\Program Files\Team MediaPortal\MediaPortal\plugins\process\WakeOnLan.pdb +C:\AAA\WakeOnLan\WakeOnLan\obj\Debug\ResolveAssemblyReference.cache +C:\AAA\WakeOnLan\WakeOnLan\obj\Debug\WakeOnLan.dll +C:\AAA\WakeOnLan\WakeOnLan\obj\Debug\WakeOnLan.pdb +C:\AAA\WakeOnLan\WakeOnLan\obj\Debug\WakeOnLan.Setup.resources +C:\AAA\WakeOnLan\WakeOnLan\obj\Debug\WakeOnLan.csproj.GenerateResource.Cache Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.csproj.GenerateResource.Cache =================================================================== (Binary files differ) Property changes on: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.csproj.GenerateResource.Cache ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.dll =================================================================== (Binary files differ) Property changes on: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.dll ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.pdb =================================================================== (Binary files differ) Property changes on: trunk/plugins/WakeOnLan/Source/WakeOnLan/obj/Debug/WakeOnLan.pdb ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/wake.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/WakeOnLan/Source/WakeOnLan/wake.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WakeOnLan/Source/WakeOnLan/wakeOff.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/WakeOnLan/Source/WakeOnLan/wakeOff.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WakeOnLan/Source/WakeOnLan.sln =================================================================== --- trunk/plugins/WakeOnLan/Source/WakeOnLan.sln (rev 0) +++ trunk/plugins/WakeOnLan/Source/WakeOnLan.sln 2010-10-30 18:34:00 UTC (rev 3877) @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WakeOnLan", "WakeOnLan\WakeOnLan.csproj", "{2E574157-D8EA-458E-B0FE-4CA9DF471445}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2E574157-D8EA-458E-B0FE-4CA9DF471445}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E574157-D8EA-458E-B0FE-4CA9DF471445}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E574157-D8EA-458E-B0FE-4CA9DF471445}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E574157-D8EA-458E-B0FE-4CA9DF471445}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal Added: trunk/plugins/WakeOnLan/Source/WakeOnLan.suo =================================================================== (Binary files differ) Property changes on: trunk/plugins/WakeOnLan/Source/WakeOnLan.suo ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/plugins/WakeOnLan/setup.jpg =================================================================== (Binary files differ) Property changes on: trunk/plugins/WakeOnLan/setup.jpg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |