示例#1
0
        public void CorrectGroups()
        {
            for (var i = 0; i < Groups.Count; i++)
            {
                var group       = Groups[i];
                var correct     = true;
                var directories = new HashSet <string>();

                foreach (var song in group.Songs)
                {
                    if (!directories.Contains(song.Directory))
                    {
                        directories.Add(song.Directory);
                    }

                    if (song.Directory != group.Path)
                    {
                        correct = false;
                    }
                }

                // The group contains files in multiple directories, they need to be split into seperate groups.
                if (directories.Count > 1)
                {
                    var newGroups = new List <Group>();
                    foreach (var directory in directories)
                    {
                        var songs    = group.Songs.Where(x => x.Directory == directory).ToList();
                        var newGroup = new Aimp4Group(directory, songs);
                        newGroups.Add(newGroup);
                    }

                    Groups.RemoveAt(i);
                    Groups.InsertRange(i, newGroups);
                    i += directories.Count - 1;
                }
                // The group has the wrong path.
                else if (!correct)
                {
                    group.Path = directories.First();
                }
            }
        }
示例#2
0
        public Aimp4Playlist(string path)
        {
            Path     = path;
            Groups   = new List <Group>();
            Summary  = new Dictionary <string, string>();
            Settings = new Dictionary <string, string>();

            var mode = PlaylistMode.Summary;

            using (var fs = File.Open(path, FileMode.Open))
            {
                using (var r = new StreamReader(fs))
                {
                    if (!r.BaseStream.CanSeek)
                    {
                        throw new NotSupportedException("Stream doesn't support seeking, cannot load playlist.");
                    }
                    while (!r.EndOfStream)
                    {
                        var pos  = Util.GetActualPosition(r);
                        var line = r.ReadLine();
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }

                        if (line == "#-----SUMMARY-----#")
                        {
                            mode = PlaylistMode.Summary;
                            continue;
                        }
                        if (line == "#-----SETTINGS-----#")
                        {
                            mode = PlaylistMode.Settings;
                            continue;
                        }
                        if (line == "#-----CONTENT-----#")
                        {
                            mode = PlaylistMode.Content;
                            continue;
                        }

                        switch (mode)
                        {
                        case PlaylistMode.Summary:
                        {
                            var split    = line.IndexOf('=');
                            var variable = line.Substring(0, split);
                            var value    = line.Substring(split + 1);
                            Summary.Add(variable, value);
                            if (variable == "Name")
                            {
                                Name = value;
                            }
                            break;
                        }

                        case PlaylistMode.Settings:
                        {
                            var split    = line.IndexOf('=');
                            var variable = line.Substring(0, split);
                            var value    = line.Substring(split + 1);
                            Settings.Add(variable, value);
                            break;
                        }

                        case PlaylistMode.Content:
                        {
                            // Rewind stream to allow group to load group info.
                            Util.SetActualPosition(r, pos);
                            var group = new Aimp4Group(r);
                            if (group.Songs.Count > 0)
                            {
                                Groups.Add(group);
                            }
                            break;
                        }
                        }
                    }
                }
            }
        }