/// <summary> /// insert item after /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public void insert_item_after(int x, int y, item_data_type type, byte[] data) { if (this.type == container_types.MULT) { this.MULT_root.items[x].items.Insert(y, new item(type, data)); } if (this.type == container_types.NORM) { this.NORM_root.items.Insert(y, new item(type, data)); } if (this.type == container_types.indexed) { this.INDX_root.items.Insert(y, new item(type, data)); } }
/// <summary> /// returns list of items of type t /// </summary> /// <param name="t"></param> /// <returns></returns> public List <item_match> find_items_ofType(item_data_type t) { List <item_match> matches = new List <item_match>(); if (this.type == container_types.MULT) { for (int x = 0; x < this.MULT_root.items.Count; x++) { for (int y = 0; y < this.MULT_root.items[x].items.Count; y++) { if (this.MULT_root.items[x].items[y].type == t) { matches.Add(new item_match(this.MULT_root.items[x].items[y], x, y)); } } } } if (this.type == container_types.NORM) { for (int x = 0; x < this.NORM_root.items.Count - 1; x++) { if (this.NORM_root.items[x].type == t) { matches.Add(new item_match(this.NORM_root.items[x], x, -1)); } } } if (this.type == container_types.indexed) { for (int x = 0; x < this.INDX_root.items.Count - 1; x++) { if (this.INDX_root.items[x].type == t) { matches.Add(new item_match(this.INDX_root.items[x], x, -1)); } } } return(matches); }
public File_Containers(string filepath = "") { if (filepath == "") { return; } if (!File.Exists(filepath)) { return; } this.filepath = filepath; this.file_data = Parsing.FileToByteArray(filepath, 0); if (this.file_data.Length == 0) { MessageBox.Show("File is empty"); return; } byte[] type = new byte[4]; Array.Copy(this.file_data, 0, type, 0, 4); string header_type = System.Text.Encoding.UTF8.GetString(type); this.type = container_types.unknown; if (header_type == "MULT") { this.type = container_types.MULT; byte[] childs_buffer = new byte[file_data.Length]; //file_data.Length - 16] Array.Copy(file_data, 0, childs_buffer, 0, file_data.Length); //Array.Copy(file_data, 16, childs_buffer, 0, file_data.Length); List <byte[]> NORMs_buffers = get_children(childs_buffer); List <NORM> NORM_list = new List <NORM>(); // for each NORM contained in the MULT // get the children data foreach (var NORM_buff in NORMs_buffers) { List <byte[]> items_data = get_children(NORM_buff); NORM n = new NORM(); // for each item contained in the NORM // get the children data foreach (var item_data in items_data) { // add item to NORM n n.items.Add(new item(get_item_data_type(item_data), item_data)); } NORM_list.Add(n); } this.MULT_root = new MULT(); this.MULT_root.items = NORM_list; } if (header_type == "NORM") { this.type = container_types.NORM; byte[] childs_buffer = new byte[file_data.Length]; //file_data.Length - 16] Array.Copy(file_data, 0, childs_buffer, 0, file_data.Length); //Array.Copy(file_data, 16, childs_buffer, 0, file_data.Length); List <byte[]> items_data = get_children(childs_buffer); List <NORM> NORM_list = new List <NORM>(); NORM n = new NORM(); // for each item contained in the NORM // get the children data foreach (var item_data in items_data) { // add item to NORM n n.items.Add(new item(get_item_data_type(item_data), item_data)); } this.NORM_root = new NORM(); this.NORM_root = n; } // indexed (no header name) if ((file_data[0] == 1 & file_data[1] == 0 & file_data[2] == 0 & file_data[3] == 0) || (file_data[0] == 0 & file_data[1] == 0 & file_data[2] == 0 & file_data[3] == 0)) { this.type = container_types.indexed; File_Headers.Indexed_container indexed_items = new File_Headers.Indexed_container(); indexed_items.get_Indexed(file_data, 0, file_data.Length); INDX_root = new INDEXED(); INDX_root.items = new List <item>(); for (int i = 0; i < indexed_items.childs.Count; i++) { item indx_item; if (indexed_items.childs[i].block_end < 0) { MessageBox.Show("Error: invalid file structure."); break; } byte[] childs_buffer = new byte[indexed_items.childs[i].block_end - indexed_items.childs[i].block_start]; Array.Copy(file_data, indexed_items.childs[i].block_start, childs_buffer, 0, indexed_items.childs[i].block_end - indexed_items.childs[i].block_start); item_data_type t = get_item_data_type(childs_buffer); if (t == item_data_type.Texture) { // byte[] tex_buff = new byte[indexed_items.childs[i].block_end - indexed_items.childs[i].block_start]; Array.Copy(file_data, indexed_items.childs[i].block_start + 8, childs_buffer, 0, indexed_items.childs[i].block_end - indexed_items.childs[i].block_start); indx_item = new item(t, childs_buffer); } else { indx_item = new item(t, childs_buffer); } INDX_root.items.Add(indx_item); } } }
public item(item_data_type _type, byte[] _data) { this.type = _type; this.data = _data; }