示例#1
0
        public override void Read(BinaryReader reader)
        {
            base.Read(reader);

            byte[] body = reader.ReadBytes(this.HeaderOne - 12);

            int numChildren = ToInt32(body, 0);

            Id              = ToInt32(body, 4);
            TrackId         = ToInt64(body, 8);
            unknownOne      = ToInt32(body, 16);
            Rating          = ToInt32(body, 20);
            unknownTwo      = ToInt32(body, 24);
            OriginalDate    = Utility.MacTimeToDate(ToUInt32(body, 28));
            DigitizedDate   = Utility.MacTimeToDate(ToUInt32(body, 32));
            SourceImageSize = ToInt32(body, 36);

            recordPadding = body.Length - 40;

            for (int i = 0; i < numChildren; i++)
            {
                PhotoDetailRecord detail = new PhotoDetailRecord(IsBE);
                detail.Read(reader);

                if (detail.Type == PhotoDetailType.ThumbnailContainer)
                {
                    names.Add(detail.ImageName);
                }
                else
                {
                    FullName = detail.ImageName;
                }
            }
        }
示例#2
0
        public override void Read(BinaryReader reader)
        {
            base.Read(reader);

            byte[] body = reader.ReadBytes(this.HeaderOne - 12);
            Type = (PhotoDetailType)ToInt16(body, 0);

            switch (Type)
            {
            case PhotoDetailType.ThumbnailContainer:
            case PhotoDetailType.ImageContainer:
                ImageName = new ImageNameRecord(IsBE);
                ImageName.Read(reader);
                break;

            case PhotoDetailType.FileName:
                ReadString(reader, true);
                break;

            case PhotoDetailType.String:
                ReadString(reader, false);
                break;

            default:
                throw new DatabaseReadException("Unknown detail type: " + Type);
            }
        }
示例#3
0
        public ImageItemRecord(bool isbe) : base(isbe)
        {
            this.Name     = "mhii";
            recordPadding = 100;

            FullName = new ImageNameRecord(isbe);
        }
示例#4
0
        internal Thumbnail(Photo photo, ImageNameRecord record)
        {
            this.photo  = photo;
            this.record = record;

            if (record.CorrelationId > 0)
            {
                Format = photo.PhotoDatabase.Device.LookupArtworkFormat(record.CorrelationId);
            }
        }
示例#5
0
 private byte[] GetNameData(ImageNameRecord record, Stream stream)
 {
     if (record.Dirty)
     {
         return(record.GetData(GetTempFile()));
     }
     else
     {
         return(record.GetData(stream));
     }
 }
示例#6
0
        private ImageNameRecord Pop(List <ImageNameRecord> list)
        {
            ImageNameRecord record = Peek(list);

            if (record != null)
            {
                list.Remove(record);
            }

            return(record);
        }
示例#7
0
        public Thumbnail CreateThumbnail()
        {
            ImageNameRecord name = new ImageNameRecord(item.IsBE);

            item.AddName(name);

            Thumbnail thumbnail = new Thumbnail(this, name);

            thumbnails.Add(thumbnail);

            return(thumbnail);
        }
示例#8
0
 public void RemoveName(ImageNameRecord name)
 {
     names.Remove(name);
     removedNames.Add(name);
 }
示例#9
0
 public void AddName(ImageNameRecord name)
 {
     names.Add(name);
     newNames.Add(name);
 }
示例#10
0
 public PhotoDetailRecord(bool isbe, ImageNameRecord name, PhotoDetailType type) : this(isbe) {
     Type      = PhotoDetailType.ThumbnailContainer;
     ImageName = name;
     Type      = type;
 }
示例#11
0
        private void SaveThumbnails(List <ImageNameRecord> existingNames, List <ImageNameRecord> newNames,
                                    List <ImageNameRecord> removedNames, ArtworkFormat format)
        {
            string thumbPath = GetThumbPath(format);

            int fileLength = 0;

            if (existingNames.Count > 0)
            {
                ImageNameRecord last = Peek(existingNames);
                fileLength = last.ThumbnailOffset + last.ImageSize;
            }

            string thumbDir = Path.GetDirectoryName(thumbPath);

            if (!Directory.Exists(thumbDir))
            {
                Directory.CreateDirectory(thumbDir);
            }

            using (FileStream stream = File.Open(thumbPath, FileMode.OpenOrCreate)) {
                // process the removals, filling the gaps with new or existing records when possible
                foreach (ImageNameRecord removal in removedNames)
                {
                    // try to replace it with a new one
                    ImageNameRecord replacement = Pop(newNames);

                    if (replacement == null)
                    {
                        // no new ones, try to replace it with an existing one from the end of the file
                        ImageNameRecord record = Peek(existingNames);
                        if (record != null && record.ThumbnailOffset > removal.ThumbnailOffset)
                        {
                            replacement = record;

                            // it was the last one in the file, so we can reduce the file length
                            fileLength -= replacement.ImageSize;
                        }
                    }

                    if (replacement != null)
                    {
                        // write the replacement chunk into the old one's spot
                        byte[] data = GetNameData(replacement, stream);
                        replacement.ThumbnailOffset = removal.ThumbnailOffset;
                        replacement.SetData(stream, data);
                        replacement.Dirty = false;

                        existingNames.Sort(new ImageNameRecordSorter());
                    }
                    else if (fileLength > removal.ThumbnailOffset)
                    {
                        // we can't fill the gap, but it's ok to reduce the file length
                        fileLength = removal.ThumbnailOffset;
                    }
                }

                // process the additions by appending them to the file
                foreach (ImageNameRecord addition in newNames)
                {
                    byte[] data = GetNameData(addition, stream);
                    addition.ThumbnailOffset = fileLength;
                    addition.SetData(stream, data);
                    addition.Dirty = false;

                    fileLength += addition.ImageSize;
                }

                // lastly, flush any dirty existing records
                foreach (ImageNameRecord existing in existingNames)
                {
                    if (existing.Dirty)
                    {
                        byte[] data = GetNameData(existing, stream);
                        existing.SetData(stream, data);
                    }
                }

                stream.SetLength(fileLength);
            }
        }