예제 #1
0
        /// <summary>
        /// Initializes a new Instance from <paramref name="fileName"/>.
        /// </summary>
        /// <param name="fileName">Path to .uop file.</param>
        public MythicPackage(string fileName)
        {
            using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    int index = 0;

                    m_FileInfo = new FileInfo(fileName);
                    m_Header   = new MythicPackageHeader(reader);

                    stream.Seek(m_Header.StartAddress, SeekOrigin.Begin);

                    MythicPackageBlock block;

                    do
                    {
                        block        = new MythicPackageBlock(reader, this);
                        block.Index  = index++;
                        block.Parent = this;

                        m_Blocks.Add(block);
                    }while (stream.Seek(block.NextBlock, SeekOrigin.Begin) != 0);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance from existing Mythic package file.
        /// </summary>
        /// <param name="reader">Binary file (.uop source).</param>
        /// <param name="parent">Parent entity.</param>
        public MythicPackageFile(BinaryReader reader, MythicPackageBlock parent)
        {
            m_Parent = parent;

            m_DataBlockAddress = m_OldDataBlockAddress = reader.ReadInt64();
            m_DataBlockLength  = reader.ReadInt32();
            m_CompressedSize   = reader.ReadInt32();
            m_DecompressedSize = reader.ReadInt32();
            m_FileHash         = reader.ReadUInt64();

            if (m_FileHash != 0)
            {
                m_FileName = HashDictionary.Get(m_FileHash, true);
            }

            m_DataBlockHash = reader.ReadUInt32();

            short flag = reader.ReadInt16();

            switch (flag)
            {
            case 0x0: m_Compression = CompressionFlag.None; break;

            case 0x1: m_Compression = CompressionFlag.Zlib; break;

            default: throw new InvalidCompressionException(flag);
            }
        }
        // --------------------------------------------------------------
        #region LOCAL FUNCTIONS
        // --------------------------------------------------------------

        /// <summary>
        /// Create an empty block
        /// </summary>
        /// <returns>The new block</returns>
        private MythicPackageBlock NewBlock()
        {
            // create an empty block
            MythicPackageBlock block = new MythicPackageBlock(this);

            return(block);
        }
        /// <summary>
        /// Initializes a new Instance from <paramref name="fileName"/>.
        /// </summary>
        /// <param name="fileName">Path to .uop file.</param>
        public MythicPackage(string fileName)
        {
            // if the file doesn't exist, throw an exception
            if (!File.Exists(fileName))
            {
                throw new Exception(string.Format("Cannot find {0}!", Path.GetFileName(fileName)));
            }

            // open the uop file
            using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    // get the file info for the UOP file
                    FileInfo = new FileInfo(fileName);

                    // get the file header
                    Header = new MythicPackageHeader(reader);

                    // move to the starting point to start reading the blocks
                    stream.Seek((long)Header.StartAddress, SeekOrigin.Begin);

                    // initialize the block variable
                    MythicPackageBlock block;

                    do // load the block
                    {
                        block = new MythicPackageBlock(reader, this);
                    }
                    // keep loading until we have a next block address
                    while (stream.Seek(block.NextBlock, SeekOrigin.Begin) != 0);
                }
        }
예제 #5
0
        private MythicPackageBlock NewBlock()
        {
            MythicPackageBlock block = new MythicPackageBlock();

            block.Parent = this;
            block.Index  = m_Blocks.Count;
            block.Added  = true;
            m_Blocks.Add(block);

            return(block);
        }
예제 #6
0
        /// <summary>
        /// Removes a block from <see cref="Mythic.Package.MythicPackage.Blocks"/>.
        /// </summary>
        /// <param name="index">Index of the block to remove.</param>
        public void RemoveBlock(int index)
        {
            MythicPackageBlock block = m_Blocks[index];

            m_Modified          = true;
            m_Header.FileCount -= block.FileCount;
            m_Blocks.RemoveAt(index);

            for (int i = index; i < m_Blocks.Count; i++)
            {
                m_Blocks[i].Index -= 1;
            }
        }
        /// <summary>
        /// Removes a block from <see cref="Blocks"/>.
        /// </summary>
        /// <param name="index">Index of the block to remove.</param>
        public void RemoveBlock(int index)
        {
            // block out of range? throw an exception
            if (index < 0 || index > Blocks.Count - 1)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            // get the block at the specified index
            MythicPackageBlock block = Blocks[index];

            // flag the uop file as modified
            Modified = true;

            // get the amount of files removed
            int removedFiles = block.FileCount;

            // remove the files count of this block from the total files count
            Header.FileCount -= removedFiles;

            // remove the block
            Blocks.RemoveAt(index);

            // decrease the index of all the blocks that came after the one we removed
            for (int i = index; i < Blocks.Count; i++)
            {
                // update the block index
                Blocks[i].Index -= 1;

                // decrease the global index of all the files in the block
                foreach (MythicPackageFile f in Blocks[i].Files)
                {
                    f.GlobalIndex -= removedFiles;
                }
            }
        }