Esempio n. 1
0
        public static void WriteTagV2(Tag tag, FileInfo file, Rewriter.Strategy strategy = Rewriter.Strategy.Exact)
        {
            Debug.Assert(tag.DescriptionMap.Version != Version.v1_0);

            using (VirtualDriveLock fileLock = new VirtualDriveLock(file.FullName, AccessObserver.AccessType.Write))
            {
                int tagSize = TagSize(tag);
                tag.Codec.Header.Size = tagSize - tag.Codec.Header.HeaderSize;

                if (VirtualDrive.ExistsFile(file.FullName))
                {
                    Rewriter rewriter = new Rewriter(strategy);
                    int      padding  = rewriter.Rewrite(tagSize, file);

                    if (padding != tagSize)
                    {
                        tag.Codec.Header.Size = padding - tag.Codec.Header.HeaderSize;
                    }
                }

                using (Writer writer = new Writer(file))
                {
                    tag.Write(writer);
                }
            }
        }
Esempio n. 2
0
        public static byte[] TagToRaw(Tag tag)
        {
            tag.Codec.Header.Size = TagSize(tag) - tag.Codec.Header.HeaderSize;

            using (Writer writer = new Writer())
            {
                tag.Write(writer);
                return(writer.OutData);
            }
        }
Esempio n. 3
0
        public static int TagSize(Tag tag)
        {
            using (Writer memWriter = new Writer())
            {
                tag.Codec.Header.Size = TagHeader.sizeUnitinialized;

                tag.Write(memWriter);

                return(memWriter.OutData.Length);
            }
        }
Esempio n. 4
0
        public static void WriteTagV1(Tag tag, FileInfo file)
        {
            using (VirtualDriveLock fileLock = new VirtualDriveLock(file.FullName, AccessObserver.AccessType.Write))
            {
                bool existingTag = HasTagV1(file);
                long fileLength  = VirtualDrive.FileLength(file.FullName);

                using (Writer writer = new Writer(file))
                {
                    if (existingTag)
                    {
                        writer.Seek(fileLength - HeaderV1.totalSize, SeekOrigin.Begin);
                    }
                    else
                    {
                        writer.Seek(fileLength, SeekOrigin.Begin);
                    }
                    tag.Write(writer);
                }
            }
        }