Get directories included in Windows Media Center libraries

自作多情 提交于 2019-12-07 04:41:17

问题


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#)?


回答1:


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);



回答2:


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.



来源:https://stackoverflow.com/questions/5269983/get-directories-included-in-windows-media-center-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!