Get directories included in Windows Media Center libraries

1.5k Views Asked by At

I'm writing an add-in for Media Center (the version that comes with Windows 7) and want to retrieve the list of physical directories which the user has included in the media libraries (pictures, videos, recorded tv, movies, music).

The Media Center object model (Microsoft.MediaCenter.*) does not seem to have any provision to get this information.

The registry has a key at HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Media Center\MediaFolders, however these are always empty.

There appears to be a complete list of the directories in %userprofile%\AppData\Local\Microsoft\Media Player\wmpfolders.wmdb, but there's no way to tell which media library each directory relates to and, since these are the settings for Media Player, their presence may just be coincidental.

Does anyone know how to reliably retrieve a list of these directories, preferably from within the add-in assembly (i.e. using C#)?

2

There are 2 best solutions below

2
On BEST ANSWER

I used Reflector to take a peak at how ehshell does this. For Pictures, Videos, Music, and Recorded TV it's using an imported method from ehuihlp.dll. For Movies it just pulls the list directly from HKCR\Software\Microsoft\Windows\CurrentVersion\Media Center\MediaFolders\Movie.

Here's an example of how to use the imported method:

using System.Runtime.InteropServices;

...

[DllImport(@"c:\Windows\ehome\ehuihlp.dll", CharSet = CharSet.Unicode)]
static extern int EhGetLocationsForLibrary(ref Guid knownFolderGuid, [MarshalAs(UnmanagedType.SafeArray)] out string[] locations);

...

Guid RecordedTVLibrary = new Guid("1a6fdba2-f42d-4358-a798-b74d745926c5");
Guid MusicLibrary = new Guid("2112ab0a-c86a-4ffe-a368-0de96e47012e");
Guid PicturesLibrary = new Guid("a990ae9f-a03b-4e80-94bc-9912d7504104");
Guid VideosLibrary = new Guid("491e922f-5643-4af4-a7eb-4e7a138d8174")

...

string[] locations;
EhGetLocationsForLibrary(ref PicturesLibrary, out locations);
1
On
private void ListItems(ListMakerItem listMakerItem)
{
    if (listMakerItem.MediaTypes == Microsoft.MediaCenter.ListMaker.MediaTypes.Folder)
    {
        // Recurse into Folders
        ListMakerList lml = listMakerItem.Children;
        foreach (ListMakerItem listMakerChildItem in lml)
        {
            ListItems(listMakerChildItem);
        }
     }
     else
     {
        BuildDirectoryList(listMakerItem.FileName)
     }
}

private void BuildDirectoryList(string fileName)
{
   // Parse fileName and build unique directory list
}

This is an indirect way, but would enable you to build the desired list of directories. See http://msdn.microsoft.com/en-us/library/ee525804.aspx for more info.