Example #1
0
 /// <summary>
 /// Extracts the specified file.
 /// </summary>
 /// <param name="file">The file to extract.</param>
 /// <returns>The file data.</returns>
 public byte[] Extract(VFileInfo file)
 {
     if (file.Offset < 0 || file.Offset >= Data.Length)
         throw new ArgumentException("Invalid file");
     var result = new byte[file.Size];
     Buffer.BlockCopy(Data, file.Offset, result, 0, file.Size);
     return result;
 }
Example #2
0
        /// <summary>
        /// Extracts the specified file.
        /// </summary>
        /// <param name="file">The file to extract.</param>
        /// <returns>The file data.</returns>
        public byte[] Extract(VFileInfo file)
        {
            if (file.Offset < 0 || file.Offset >= Data.Length)
            {
                throw new ArgumentException("Invalid file");
            }
            var result = new byte[file.Size];

            Buffer.BlockCopy(Data, file.Offset, result, 0, file.Size);
            return(result);
        }
Example #3
0
        /// <summary>
        /// Adds a new file to the tag.
        /// </summary>
        /// <param name="name">The name of the file to add.</param>
        /// <param name="folder">The folder the file is located in.</param>
        /// <param name="fileData">The file data.</param>
        public void Insert(string name, string folder, byte[] fileData)
        {
            // Insert a file of size 0 and then replace it
            var fileInfo = new VFileInfo
            {
                Name   = name,
                Folder = folder,
                Offset = Data.Length,
                Size   = 0
            };

            Files.Add(fileInfo);
            Replace(fileInfo, fileData);
        }
Example #4
0
        /// <summary>
        /// Replaces the specified file.
        /// </summary>
        /// <param name="file">The file to replace.</param>
        /// <param name="newData">The data to replace it with.</param>
        public void Replace(VFileInfo file, byte[] newData)
        {
            // Replace the file's data in the data array
            var sizeDelta = newData.Length - file.Size;

            Data = ArrayUtil.Replace(Data, file.Offset, file.Size, newData);

            // Adjust file offsets
            foreach (var adjustFile in Files)
            {
                if (adjustFile.Offset > file.Offset)
                {
                    adjustFile.Offset += sizeDelta;
                }
            }
            file.Size = newData.Length;
        }
Example #5
0
 /// <summary>
 /// Adds a new file to the tag.
 /// </summary>
 /// <param name="name">The name of the file to add.</param>
 /// <param name="folder">The folder the file is located in.</param>
 /// <param name="fileData">The file data.</param>
 public void Insert(string name, string folder, byte[] fileData)
 {
     // Insert a file of size 0 and then replace it
     var fileInfo = new VFileInfo
     {
         Name = name,
         Folder = folder,
         Offset = Data.Length,
         Size = 0
     };
     Files.Add(fileInfo);
     Replace(fileInfo, fileData);
 }
Example #6
0
        /// <summary>
        /// Replaces the specified file.
        /// </summary>
        /// <param name="file">The file to replace.</param>
        /// <param name="newData">The data to replace it with.</param>
        public void Replace(VFileInfo file, byte[] newData)
        {
            // Replace the file's data in the data array
            var sizeDelta = newData.Length - file.Size;
            Data = ArrayUtil.Replace(Data, file.Offset, file.Size, newData);

            // Adjust file offsets
            foreach (var adjustFile in Files)
            {
                if (adjustFile.Offset > file.Offset)
                    adjustFile.Offset += sizeDelta;
            }
            file.Size = newData.Length;
        }
Example #7
0
 /// <summary>
 /// Removes a file from the tag.
 /// </summary>
 /// <param name="file">The file to remove.</param>
 public void Remove(VFileInfo file)
 {
     // Replace the file with an empty byte array and then remove its entry
     Replace(file, new byte[0]);
     Files.Remove(file);
 }
Example #8
0
 /// <summary>
 /// Removes a file from the tag.
 /// </summary>
 /// <param name="file">The file to remove.</param>
 public void Remove(VFileInfo file)
 {
     // Replace the file with an empty byte array and then remove its entry
     Replace(file, new byte[0]);
     Files.Remove(file);
 }