示例#1
0
        public Album(DirectoryInfo sourceDirectory, IProgress progress, CancellationToken cancellationToken, Session session, Context context)
            : this(session, context)
        {
            var discDirectories = new List<DirectoryInfo>();
            discDirectories.Add(sourceDirectory);
            discDirectories.AddRange(sourceDirectory.GetDirectories());

            progress.Begin(discDirectories.Sum(directory => directory.GetFiles("*.mp3").Length));

            foreach (var directory in discDirectories)
            {
                var disc = new Disc(this, _session, _context);

                foreach (var file in directory.GetFiles("*.mp3"))
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    progress.Advance(file.Name);

                    var track = new Track(file, disc, _session, _context);
                    disc.Tracks.Add(track);
                }

                if (disc.Tracks.Count > 0)
                    Discs.Add(disc);
            }

            SourceDirectory = sourceDirectory;
        }
示例#2
0
        public Track(FileInfo sourceFile, Disc disc, Session session, Context context)
            : this(session, context)
        {
            SourceFile = sourceFile;
            Disc = disc;

            // Find tags
            using (var stream = new BufferedStream(sourceFile.Open(FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                _mpegDataOffset = 0;
                _mpegDataSize = stream.Length;
                Stream dataStream;

                // Better be sorted from outer to inner
                Type[] tagTypes = {
                    typeof(Id3v2Tag),
                    typeof(Id3v1Tag),
                    typeof(Lyrics3v2Tag),
                    typeof(ApeTag)
                };

                while (true)
                {
                    dataStream = new SubStream(stream, _mpegDataOffset, _mpegDataSize);

                    var anyTagFound = false;

                    foreach (var tagType in tagTypes)
                    {
                        var tag = (ITag)Activator.CreateInstance(tagType);

                        if (!tag.Read(dataStream))
                            continue;

                        if (tag.Position == TagPosision.Beginning)
                        {
                            _mpegDataOffset += tag.Size;
                            _mpegDataSize -= tag.Size;
                        }
                        else
                        {
                            _mpegDataSize -= tag.Size;
                        }

                        Tags.Add(tag);
                        anyTagFound = true;
                        break;
                    }

                    if (!anyTagFound)
                        break;
                }

                MpegFileInfo = new MpegFileInfo(dataStream);
            }
        }
示例#3
0
        public static void Main()
        {
            if (!Settings.Default.Upgraded)
            {
                Settings.Default.Upgrade();
                Settings.Default.Upgraded = true;
            }

            var context = new Context();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainForm(context));
        }
示例#4
0
 private Disc(Session session, Context context)
     : this()
 {
     _session = session;
     _context = context;
 }
示例#5
0
 public Disc(Album album, Session session, Context context)
     : this(session, context)
 {
     Album = album;
 }
示例#6
0
 private Album(Session session, Context context)
     : this()
 {
     _session = session;
     _context = context;
 }
示例#7
0
 private Track(Session session, Context context)
     : this()
 {
     _session = session;
     _context = context;
 }
示例#8
0
 public MainForm(Context context)
     : this()
 {
     _context = context;
 }