/**
* Universal Subscription Mechanism
* http://www.kbcafe.com/rss/usm.html
* Author: Randy Charles Morin - http://www.kbcafe.com
* No warranty. Public domain. Attribution appreciated.
**/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace kb.rss
{
///
/// Summary description for UniversalSubscriptionMechanism.
///
public class UniversalSubscriptionMechanism
{
public UniversalSubscriptionMechanism()
{
}
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string [] args)
{
if (args == null || args.Length == 0)
{
Register();
return;
}
try
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(args[0]);
System.Xml.XmlNamespaceManager nsmgr = new System.Xml.XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("atom", "http://purl.org/atom/ns#");
System.Xml.XmlNode node = doc.DocumentElement.SelectSingleNode("//atom:link[@rel='start']", nsmgr);
if (node != null)
{
string url = ((System.Xml.XmlElement)node).GetAttribute("href");
string title = url;
node = doc.DocumentElement.SelectSingleNode("//channel/title");
if (node != null)
{
title = ((System.Xml.XmlElement)node).InnerText;
}
if (System.Windows.Forms.MessageBox.Show(
string.Format("Would you like to add {0} to My Yahoo!?", title),
"Yahoo! USM", System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question,
System.Windows.Forms.MessageBoxDefaultButton.Button1)
!= System.Windows.Forms.DialogResult.Yes)
{
return;
}
System.Uri uri = new System.Uri(string.Format("http://add.my.yahoo.com/rss?url={0}", url));
System.Diagnostics.Process.Start(uri.AbsoluteUri);
return;
}
node = doc.DocumentElement.SelectSingleNode("//channel/link");
if (node != null)
{
string url = kb.rss.Discovery.AutoDiscoverRss(((System.Xml.XmlElement)node).InnerText);
if (url != null)
{
string title = url;
node = doc.DocumentElement.SelectSingleNode("//channel/title");
if (node != null)
{
title = ((System.Xml.XmlElement)node).InnerText;
}
if (System.Windows.Forms.MessageBox.Show(
string.Format("Would you like to add {0} to My Yahoo!?", title),
"Yahoo! USM", System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question,
System.Windows.Forms.MessageBoxDefaultButton.Button1)
!= System.Windows.Forms.DialogResult.Yes)
{
return;
}
System.Uri uri = new System.Uri(string.Format("http://add.my.yahoo.com/rss?url={0}", url));
System.Diagnostics.Process.Start(uri.AbsoluteUri);
return;
}
}
node = doc.DocumentElement.SelectSingleNode("//atom:feed/atom:link[@rel='alternate']", nsmgr);
if (node != null)
{
string url = kb.rss.Discovery.AutoDiscoverAtom(((System.Xml.XmlElement)node).GetAttribute("href"));
if (url != null)
{
string title = url;
node = doc.DocumentElement.SelectSingleNode("//atom:feed/atom:title", nsmgr);
if (node != null)
{
title = ((System.Xml.XmlElement)node).InnerText;
}
if (System.Windows.Forms.MessageBox.Show(
string.Format("Would you like to add {0} to My Yahoo!?", title),
"Yahoo! USM", System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question,
System.Windows.Forms.MessageBoxDefaultButton.Button1)
!= System.Windows.Forms.DialogResult.Yes)
{
return;
}
System.Uri uri = new System.Uri(string.Format("http://add.my.yahoo.com/rss?url={0}", url));
System.Diagnostics.Process.Start(uri.AbsoluteUri);
return;
}
}
}
catch(System.Exception x)
{
System.Windows.Forms.MessageBox.Show(x.Message, "Error",
System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
}
static void Register()
{
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(".rss");
if (key != null)
{
if (System.Windows.Forms.MessageBox.Show("Do you want Yahoo! USM to be your default RSS reader?",
"RSS file handler found", System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question, System.Windows.Forms.MessageBoxDefaultButton.Button1)
!= System.Windows.Forms.DialogResult.Yes)
{
return;
};
}
key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(".rss");
key.SetValue("", "rssfile");
key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("rssfile");
key = key.CreateSubKey("shell");
key = key.CreateSubKey("open");
key = key.CreateSubKey("command");
key.SetValue("", string.Format("\"{0}\" \"%1\"", typeof(UniversalSubscriptionMechanism).Assembly.Location));
key = Microsoft.Win32.Registry.ClassesRoot.CreateSubKey("MIME\\Database\\Content Type");
Microsoft.Win32.RegistryKey key2 = key.CreateSubKey("application/atom+xml");
key2.SetValue("Extension", ".rss");
key2 = key.CreateSubKey("application/rdf+xml");
key2.SetValue("Extension", ".rss");
key2 = key.CreateSubKey("application/rss+xml");
key2.SetValue("Extension", ".rss");
}
}
}