Exemplo n.º 1
0
        /// <summary>
        /// Clears all parameters of this App Manager object
        /// </summary>
        private void ClearAppManager()
        {
            header   = null;
            nodes    = null;
            filename = null;

            upd_nameOffset = 0;
            datapath       = "";
        }
Exemplo n.º 2
0
        public AppManager()
        {
            header   = null;
            nodes    = null;
            filename = null;

            curNode = null;

            upd_nameOffset = 0;
            datapath       = "";
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads content from specified folder and parses it to App form
        /// </summary>
        /// <param name="foldername">Absolute path to folder from where content is loaded</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="DirectoryNotFoundException"></exception>
        /// <exception cref="PathTooLongException"></exception>
        /// <exception cref="UnauthorizedAccessException"></exception>
        public void LoadFolder(string foldername)
        {
            nodes = new List <u8node>();
            offsets offs = new offsets();

            offs.names_offset = 1;
            offs.data_offset  = 0;

            try
            {
                GetNodes(foldername, -1, offs, nodes);
            }
            catch
            {
                ClearAppManager();
                throw;
            }

            header = new u8header
            {
                tag             = 0x55AA382D,
                rootnode_offset = 0x20,
                header_size     = 12 * (uint)nodes.Count
            };

            foreach (u8node node in nodes)
            {
                header.header_size += (uint)node.name.Length + 1;
            }

            header.data_offset = Align(0x20 + header.header_size, 0x40);

            foreach (u8node node in nodes)
            {
                if (node.type == 0x0)
                {
                    node.data_offset += header.data_offset;
                }
            }

            curNode = nodes[0];
            Console.WriteLine("End!");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads content info from specified App file
        /// </summary>
        /// <param name="filen">Absolute path to App file, from which content info will be loaded</param>
        ///
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="FileNotFoundException"></exception>
        /// <exception cref="NotAppFileException"></exception>
        /// <exception cref="PathTooLongException"></exception>
        /// <exception cref="UnauthorizedAccessException"></exception>
        /// <exception cref="UncompleteAppFileException"></exception>
        public void LoadPack(string filen)
        {
            header   = new u8header();
            filename = filen;
            FileStream file = File.OpenRead(filename);

            datapath = Directory.GetParent(filename).FullName + "\\data.app";

            byte[] tempInt   = new byte[4];
            byte[] tempShort = new byte[2];

            file.Read(tempInt, 0, 4);
            header.tag = BitConverter.ToUInt32(tempInt, 0);

            if (header.tag != 0x55AA382D)
            {
                throw new NotAppFileException();
            }

            try
            {
                file.Read(tempInt, 0, 4);
                header.rootnode_offset = Be32(BitConverter.ToUInt32(tempInt, 0));
                file.Read(tempInt, 0, 4);
                header.header_size = Be32(BitConverter.ToUInt32(tempInt, 0));
                file.Read(tempInt, 0, 4);
                header.data_offset = Be32(BitConverter.ToUInt32(tempInt, 0));

                Console.WriteLine(header.tag.ToString("X"));
                Console.WriteLine(header.rootnode_offset.ToString());
                Console.WriteLine(header.header_size.ToString());
                Console.WriteLine(header.data_offset.ToString());

                file.Seek(16, SeekOrigin.Current);

                ////Reading Root Node
                file.Seek(8, SeekOrigin.Current);
                file.Read(tempInt, 0, 4);
                uint numnodes = Be32(BitConverter.ToUInt32(tempInt, 0));
                nodes = new List <u8node>();

                Console.WriteLine(numnodes.ToString());
                uint stringsize = header.data_offset - header.rootnode_offset - numnodes * 12;
                Console.WriteLine(stringsize.ToString());
                uint datasize = (uint)file.Length - header.data_offset;
                Console.WriteLine(datasize.ToString());

                file.Seek(header.rootnode_offset, SeekOrigin.Begin);

                for (int i = 0; i < numnodes; ++i)
                {
                    u8node node = new u8node();
                    nodes.Add(node);

                    file.Read(tempShort, 0, 2);
                    nodes[i].type = Be16(BitConverter.ToUInt16(tempShort, 0));
                    file.Read(tempShort, 0, 2);
                    nodes[i].name_offset = Be16(BitConverter.ToUInt16(tempShort, 0));
                    file.Read(tempInt, 0, 4);
                    nodes[i].data_offset = Be32(BitConverter.ToUInt32(tempInt, 0));
                    file.Read(tempInt, 0, 4);
                    nodes[i].size = Be32(BitConverter.ToUInt32(tempInt, 0));
                    nodes[i].name = "";

                    if (nodes[i].type == 0x0100)
                    {
                        nodes[i].children = new SortedDictionary <string, u8node>();
                    }
                    else
                    {
                        nodes[i].children = null;
                    }
                }

                file.Seek(1, SeekOrigin.Current);

                byte[]        chb = new byte[1];
                List <u8node> req = new List <u8node>
                {
                    nodes[0]
                };

                for (int i = 1; i < numnodes; ++i)
                {
                    List <byte> buff = new List <byte>();
                    file.Read(chb, 0, 1);
                    while (chb[0] != 0x0)
                    {
                        buff.Add(chb[0]);
                        file.Read(chb, 0, 1);
                    }

                    byte[] res = new byte[buff.Count];
                    for (int j = 0; j < buff.Count; ++j)
                    {
                        res[j] = buff[j];
                    }

                    nodes[i].name   = Encoding.Default.GetString(res);
                    nodes[i].parent = req[req.Count - 1];
                    nodes[i].parent.children.Add(nodes[i].name, nodes[i]);

                    Console.WriteLine("Nodes " + (i + 1) + ":");
                    Console.WriteLine(nodes[i].type.ToString("X"));
                    Console.WriteLine(nodes[i].name_offset.ToString());
                    Console.WriteLine(nodes[i].data_offset.ToString());
                    Console.WriteLine(nodes[i].size.ToString());
                    Console.WriteLine(nodes[i].name);

                    if (nodes[i].type == 0x0100)
                    {
                        req.Add(nodes[i]);
                    }

                    while (req.Count > 1 && req[req.Count - 1].size == i + 1)
                    {
                        req.RemoveAt(req.Count - 1);
                    }
                }

                file.Close();
                curNode = nodes[0];
                Console.WriteLine("End!");
            }
            catch (ArgumentOutOfRangeException)
            {
                ClearAppManager();
                throw new UncompleteAppFileException();
            }
        }