How the Q sample application was redesigned to support Media Center Extenders
The Windows Media Center SDK for Windows Vista was released yesterday. One of the changes that was made since the RC2 release that I didn't mention in my previous blog post is a rewrite of large portions of the Q podcast and video blog sample application. I wanted to briefly explain one of the key reasons why we decided to partially rewrite Q, and also give an overview of the design used in the final release of the Media Center SDK.
Around the time that Windows Vista RC2 was released, we put together a sample application CD for people on the Media Center team to try out at home. That CD included the Q application and an early preview version of the Z application along with a build of the SDK for folks on the team interested in developing their own Media Center applications.
When putting this CD together, we wanted to make it as easy as possible for people to start using Q, and back at that time you had to manually add feed sources to the Internet Explorer 7 feed store in order for Q to display anything in its UI. Charlie asked Stephen Toub (the developer who originally wrote most of the Q application) to create a simple script that we could pass in an OPML file and have it automatically add feed sources.
While working on this script, we quickly realized that RSS feeds are registered on a per-user basis in Windows Vista. This prevented us from automatically registering RSS feeds for the user account that is used for Windows Media Center extender sessions because extender sessions connect to Windows Media Center across the netowrk via special user accounts that do not allow interactive login. Therefore, the Q application could not be used on an extender without the user manually copying feed registration information into the extender user account folder under c:\Users from some other user account on the system.
As a result of this experience, we decided to add a feature to Q to populate RSS feeds the first time each user account launches Windows Media Center after installing the Q sample application. This feature works as follows:
The Q sample application now registers an additional Windows Media Center entry point. It is a background application that runs as soon as the user launches Windows Media Center. This new background application attempts to read a registry value under HKEY_LOCAL_MACHINE. This registry value specifies a path to an OPML file that contains a list of RSS feeds to register on the system.
If the background application finds the registry value, it then looks for a second registry value under HKEY_CURRENT_USER that specifies a file hash for the OPML file. Because the second registry value is located under HKEY_CURRENT_USER, it is possible to register RSS feeds for each user account on the system the first time that Windows Media Center is launched for each account.
If the file hash registry value does not exist under HKEY_CURRENT_USER, the background application assumes that the OPML file has not yet been parsed, and it proceeds to register the feeds listed in the OPML file that are not yet registered for the current user. When it is done, it calculates the hash of the OPML file and writes that value to the registry under HKEY_CURRENT_USER.
If the file hash registry value already exists, the background application calculates the file hash for the the OPML file pointed to by the HKEY_LOCAL_MACHINE registry value. If the calculated file hash matches the file hash stored in the registry, the background application assumes that the OPML file has already been parsed and silently exits.
If the file hash value in the registry does not match the calculated file hash, the background application parses the OPML file and registers any RSS feeds that are not yet registered for the current user.
While the background application is adding RSS feeds, it blocks the main Q entry point from launching and displays a dialog telling the user to try back in a couple of minutes. Once the background application is done adding feeds from the OPML file, it displays a toast dialog telling the user that they can now launch the Q sample application and start viewing podcasts and video blogs.
The Q sample application includes WiX source files and a script to allow you to easily build an MSI to install Q (similar to the information described in this blog post). This MSI includes steps to install a sample OPML file to a location that is readable by all users and create a registry value under HKEY_LOCAL_MACHINE that points to the location that the MSI installs the OPML file to.
If we had more time, we would have created some nice UI in MCML to allow users to configure RSS feeds from within Windows Media Center. Maybe someone will be interested in adding a feature like this to Q in the future? :-)
I also want to take this opportunity to say a big thank you to Stephen Toub, who did most of the development work for the Q application (and in his spare time no less). His responsiveness to questions and debugging requests were a huge help and we couldn't have shipped the Q sample application without his effort and enthusiasm.