コード例 #1
0
ファイル: PhotoDatabase.cs プロジェクト: dstaley/ipod-sharp
        public void Reload(bool createFresh)
        {
            photos.Clear();
            albums.Clear();

            CloseTempFile();

            dfr = new DataFileRecord(device.IsBE);

            if (isPhoto)
            {
                // create a default master album if this is a photo database
                masterAlbum                 = CreateAlbum();
                masterAlbum.Name            = "My Pictures";
                masterAlbum.Record.IsMaster = true;
            }

            if (createFresh || !File.Exists(PhotoDbPath))
            {
                return;
            }

            using (BinaryReader reader = new BinaryReader(File.OpenRead(PhotoDbPath))) {
                dfr.Read(reader);

                PhotoDataSetRecord albumSet  = dfr[PhotoDataSetIndex.AlbumList];
                ImageListRecord    imageList = dfr[PhotoDataSetIndex.ImageList].Data as ImageListRecord;

                foreach (ImageItemRecord item in imageList.Items)
                {
                    Photo photo = new Photo(item, this);
                    photos[item.Id] = photo;

                    if (item.TrackId != 0)
                    {
                        trackPhotos[item.TrackId] = photo;
                    }
                }

                foreach (AlbumRecord albumRecord in (albumSet.Data as AlbumListRecord).Albums)
                {
                    Album album = new Album(albumRecord, this);

                    if (album.IsMaster)
                    {
                        masterAlbum = album;
                    }
                    else
                    {
                        albums.Add(album);
                    }
                }
            }
        }
コード例 #2
0
ファイル: PhotoDatabase.cs プロジェクト: dstaley/ipod-sharp
        public void RemovePhoto(Photo photo)
        {
            photos.Remove(photo.Id);
            trackPhotos.Remove(photo.Record.TrackId);
            addedPhotos.Remove(photo);
            removedPhotos.Add(photo);

            foreach (Album album in albums)
            {
                album.Remove(photo);
            }

            if (masterAlbum != null)
            {
                masterAlbum.Remove(photo);
            }

            ImageListRecord imageList = dfr[PhotoDataSetIndex.ImageList].Data as ImageListRecord;

            imageList.RemoveItem(photo.Record);
        }
コード例 #3
0
ファイル: PhotoDatabase.cs プロジェクト: dstaley/ipod-sharp
        public Photo CreatePhoto()
        {
            ImageListRecord imageList = dfr[PhotoDataSetIndex.ImageList].Data as ImageListRecord;
            ImageItemRecord item      = new ImageItemRecord(device.IsBE);

            item.Id = dfr.NextId++;

            imageList.AddItem(item);

            Photo photo = new Photo(item, this);

            photos[photo.Id] = photo;

            if (masterAlbum != null)
            {
                masterAlbum.Add(photo);
            }

            addedPhotos.Add(photo);

            return(photo);
        }
コード例 #4
0
ファイル: PhotoDatabase.cs プロジェクト: dstaley/ipod-sharp
        private void SaveThumbnails()
        {
            foreach (ArtworkFormat format in device.ArtworkFormats)
            {
                List <ImageNameRecord> existingNames = new List <ImageNameRecord> ();
                List <ImageNameRecord> removedNames  = new List <ImageNameRecord> ();
                List <ImageNameRecord> newNames      = new List <ImageNameRecord> ();

                ImageListRecord imageList = dfr[PhotoDataSetIndex.ImageList].Data as ImageListRecord;

                FindThumbnails(imageList.Items, existingNames, newNames, removedNames, format);
                existingNames.Sort(new ImageNameRecordSorter());

                FindThumbnails(imageList.RemovedItems, removedNames, null, removedNames, format);

                if (existingNames.Count == 0 && newNames.Count == 0 && removedNames.Count == 0)
                {
                    continue;
                }

                SaveThumbnails(existingNames, newNames, removedNames, format);
            }
        }