/// <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!"); }
/// <summary> /// Recursive function that creates nodes from specified directory /// </summary> /// <param name="dir">Directory from nodes are readed</param> /// <param name="recurs">Initial recursion value</param> /// <param name="offs">Initial names offset</param> /// <param name="cur_nodes">Reference to "u8node" List where nodes are saved</param> /// /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> /// <exception cref="DirectoryNotFoundException"></exception> /// <exception cref="PathTooLongException"></exception> /// <exception cref="UnauthorizedAccessException"></exception> private void GetNodes(string dir, int recurs, offsets offs, List <u8node> cur_nodes) { string[] entries = Directory.GetFileSystemEntries(dir); u8node fdcur = new u8node(); int fold_point; int last = dir.LastIndexOf("\\", dir.Length); fdcur.type = 0x0100; fdcur.children = new SortedDictionary <string, u8node>(); if (cur_nodes.Count != 0) { fdcur.name = dir.Substring(last + 1, dir.Length - last - 1); } else { fdcur.name = ""; } if (cur_nodes.Count != 0) { fdcur.parent = cur_nodes[cur_nodes.Count - 1]; } if (cur_nodes.Count != 0) { fdcur.parent.children.Add(fdcur.name, fdcur); } if (cur_nodes.Count != 0) { fdcur.data_offset = (uint)recurs; } if (cur_nodes.Count != 0) { fdcur.name_offset = (ushort)offs.names_offset; } if (cur_nodes.Count != 0) { offs.names_offset += fdcur.name.Length + 1; } cur_nodes.Add(fdcur); fold_point = cur_nodes.Count - 1; foreach (string entry in entries) { if (entry.Contains(".")) { u8node flcur = new u8node(); last = entry.LastIndexOf("\\", entry.Length); flcur.name = entry.Substring(last + 1, entry.Length - last - 1); flcur.fullname = entry; flcur.type = 0x0; flcur.size = (uint)File.OpenRead(entry).Length; flcur.name_offset = (ushort)offs.names_offset; flcur.data_offset = (uint)offs.data_offset; flcur.parent = fdcur; fdcur.children.Add(flcur.name, flcur); offs.names_offset += flcur.name.Length + 1; offs.data_offset += (int)Align(flcur.size, 32); cur_nodes.Add(flcur); } else { GetNodes(entry, recurs + 1, offs, cur_nodes); } } cur_nodes[fold_point].size = (uint)cur_nodes.Count; }