示例#1
0
        private void LoadPlaylist()
        {
            bool           loaded    = false;
            XPathDocument  xPathDoc  = null;
            XPathNavigator navigator = null;

            try
            {
                xPathDoc  = new XPathDocument(PlaylistFile);
                navigator = xPathDoc.CreateNavigator();
                loaded    = true;
            }
            catch (Exception e)
            {
                loaded = false;
                if (navigator != null)
                {
                    navigator = null;
                }

                if (xPathDoc != null)
                {
                    xPathDoc = null;
                }

                CLog.LogError("Error opening Playlist File " + PlaylistFile + ": " + e.Message);
            }

            if (loaded)
            {
                string value = String.Empty;
                if (CHelper.GetValueFromXML("//root/Info/PlaylistName", navigator, ref value, value))
                {
                    PlaylistName = value;

                    Songs = new List <CPlaylistSong>();

                    List <string> songs  = CHelper.GetValuesFromXML("Songs", navigator);
                    string        artist = String.Empty;
                    string        title  = String.Empty;
                    EGameMode     gm     = EGameMode.TR_GAMEMODE_NORMAL;

                    for (int i = 0; i < songs.Count; i++)
                    {
                        CHelper.GetValueFromXML("//root/Songs/" + songs[i] + "/Artist", navigator, ref artist, String.Empty);
                        CHelper.GetValueFromXML("//root/Songs/" + songs[i] + "/Title", navigator, ref title, String.Empty);
                        CHelper.TryGetEnumValueFromXML <EGameMode>("//root/Songs/" + songs[i] + "/GameMode", navigator, ref gm);

                        CPlaylistSong song = new CPlaylistSong();
                        song.SongID = -1;
                        CSong[] AllSongs = CSongs.AllSongs;

                        for (int s = 0; s < AllSongs.Length; s++)
                        {
                            if (AllSongs[s].Artist == artist && AllSongs[s].Title == title)
                            {
                                song.SongID = AllSongs[s].ID;
                                break;
                            }
                        }

                        if (song.SongID != -1)
                        {
                            song.GameMode = gm;
                            Songs.Add(song);
                        }
                        else
                        {
                            CLog.LogError("Can't find song '" + title + "' from '" + artist + "' in playlist file: " + PlaylistFile);
                        }
                    }
                }
                else
                {
                    CLog.LogError("Can't find PlaylistName in Playlist File: " + PlaylistFile);
                }
            }
        }