/* ---------------------------------------------------------
* LiveW Serial Finder Addon
* ---------------------------------------------------------
*
* Created : 08/12/2009 (dd/mm/yyyy)
* By : Hyperz
* For Site : www.serialnumber.in
*
* ---------------------------------------------------------
*
* Additional credits :
*
* - HtmlAgilityPack V1.0
* Simon Mourier
* <simon underscore mourier at hotmail dot com>
*
* ---------------------------------------------------------
*
* References linked in the CSharpCodeProvider are :
* - System.dll
* - System.Data.dll
* - System.Deployment.dll
* - System.Drawing.dll
* - System.Web.dll
* - System.Windows.Forms.dll
* - System.Xml.dll
* - lsf.exe
*
* ---------------------------------------------------------
* (c) 2008 - Hyperz [hyperz.2007@gmail.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 of the License, 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 this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
//#define DEBUG
#region Namespaces
using System;
using System.Collections.Generic;
//using System.Data;
//using System.IO;
using System.Net;
//using System.Text;
//using System.Text.RegularExpressions;
using System.Web;
using Hyperz.LSF;
using HtmlAgilityPack;
#endregion
namespace Hyperz.LSF.Addons
{
public class SerialNumber_In : Grabber
{
public SerialNumber_In()
{
// Set up the required properties.
this.Name = "SerialNumber.In";
this.SearchUrl = "http://serialnumber.in/";
this.SerialUrl = "http://serialnumber.in/includes/serial.php?id=";
}
public override string GetSerial(string id)
{
string serial = "";
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml((new WebClient()).DownloadString(this.SerialUrl + id));
try
{
// Grab serial.
serial = doc.DocumentNode.SelectNodes("//textarea")[0].InnerText;
}
catch (Exception e)
{
#if DEBUG
System.Windows.Forms.MessageBox.Show(e.Message, this.Name + " Addon Error [GetSerial() Method]");
#endif
}
// Return our serial.
return HttpUtility.HtmlDecode(serial.Replace("\n", "\r\n"));
}
public override System.Windows.Forms.DataGridViewRow[] SearchFor(string search, System.Windows.Forms.DataGridView grid)
{
List<System.Windows.Forms.DataGridViewRow> results = new List<System.Windows.Forms.DataGridViewRow>();
search = "q=" + Uri.EscapeDataString(search) + "&btnsearch=Search";
string postResult = this.HttpPost(this.SearchUrl, search);
// Did we get something?
if (postResult == null) return results.ToArray();
try
{
System.Windows.Forms.DataGridViewRow result;
//string idAttr = "";
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(postResult);
// Loop trough all elements that contain serials.
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("/html/body/div/div[2]/div/div/div/table/tbody/tr"))
{
result = new System.Windows.Forms.DataGridViewRow();
result.CreateCells(grid);
string[] id = node.ChildNodes[1].ChildNodes[0].GetAttributeValue("href", "").Split('/');
// Setup the values:
// --------------------------
// 0 => the unique id, leave this to null. The backend will automaticly set it ;)
// 1 => website name
// 2 => serial key title
// 3 => OS platform, set as "N/A" when the site doesn't give this info.
// 4 => the ID we're going to need to call the right page for this serial (this cell is hidden).
result.Cells[0].Value = null;
result.Cells[1].Value = this.Name;
result.Cells[2].Value = node.ChildNodes[1].ChildNodes[0].InnerText + " " +
"[" + node.ChildNodes[0].InnerText + "] " +
"[" + node.ChildNodes[2].InnerText + "]";
result.Cells[3].Value = "N/A";
result.Cells[4].Value = id[id.Length - 1].Trim();
// Add to the result to the list.
results.Add(result);
}
}
catch (Exception e)
{
#if DEBUG
System.Windows.Forms.MessageBox.Show(e.Message, this.Name + " Addon Error [SearchFor() Method]");
#endif
}
// Convert list to an array and return it.
return results.ToArray();
}
}
}