public static DirEntry ToDirEntry(byte[] value, int startindex = 0) { if (value.Length < 28) { throw new IndexOutOfRangeException(); } DirEntry res = new DirEntry(); res.name = BitProcessor.ToInt32(value, 0 + startindex); res.strName = BitProcessor.ToString(value, 0 + startindex, 4); res.number = BitProcessor.ToInt32(value, 4 + startindex); res.elementtype = BitProcessor.ToInt16(value, 8 + startindex); res.elementsize = BitProcessor.ToInt16(value, 10 + startindex); res.numelements = BitProcessor.ToInt32(value, 12 + startindex); res.datasize = BitProcessor.ToInt32(value, 16 + startindex); res.dataoffset = BitProcessor.ToInt32(value, 20 + startindex); res.datahandle = BitProcessor.ToInt32(value, 24 + startindex); return(res); }
void PrintDataToFile(DirEntry dir) { string content = dir.ToString(); byte[] data = GetData(dir); switch ((ABIF_Type)dir.elementtype) { case ABIF_Type.BOOL: for (int i = 0; i < dir.numelements; i++) { content += (ToBoolean(data, i)); content += (" "); } content += "\r\n"; break; case ABIF_Type.BYTE: content += (BitConverter.ToString(data)); content += "\r\n"; break; case ABIF_Type.CHAR: content += new string(Encoding.ASCII.GetChars(data, 0, dir.numelements)); content += (" "); content += "\r\n"; break; case ABIF_Type.FLOAT: for (int i = 0; i < dir.numelements; i++) { content += (BitConverter.ToSingle(data, i)); content += (" "); } content += "\r\n"; break; case ABIF_Type.SHORT: for (int i = 0; i < dir.numelements; i++) { content += (ToInt16(data, i)); content += (" "); } content += "\r\n"; break; case ABIF_Type.LONG: for (int i = 0; i < dir.numelements; i++) { content += (ToInt32(data, i)); content += (" "); } content += "\r\n"; break; case ABIF_Type.WORD: for (int i = 0; i < dir.numelements; i++) { content += (ToInt32(data, i)); content += (" "); } content += "\r\n"; break; case ABIF_Type.P_STRING: content += (BitProcessor.ToString(data, 1, data[0])); break; case ABIF_Type.C_STRING: content += (BitProcessor.ToString(data, 0, dir.datasize)); break; default: content += BitConverter.ToString(data); content += "\r\n"; break; } Directory.CreateDirectory(".\\Data\\" + FileName + "\\"); File.WriteAllText(".\\Data\\" + FileName + "\\" + dir.strName.Replace('/', '_') + dir.number + ".txt", content); }
void PrintData(DirEntry dir) { byte[] data = GetData(dir); switch ((ABIF_Type)dir.elementtype) { case ABIF_Type.BOOL: for (int i = 0; i < dir.numelements; i++) { Console.Write(ToBoolean(data, i)); Console.Write(" "); } Console.WriteLine(); break; case ABIF_Type.BYTE: Console.WriteLine(data); break; case ABIF_Type.CHAR: for (int i = 0; i < dir.numelements; i++) { Console.Write(Encoding.ASCII.GetChars(data, 0, dir.numelements)); Console.Write(" "); } Console.WriteLine(); break; case ABIF_Type.FLOAT: for (int i = 0; i < dir.numelements; i++) { Console.Write(BitConverter.ToSingle(data, i)); Console.Write(" "); } Console.WriteLine(); break; case ABIF_Type.SHORT: for (int i = 0; i < dir.numelements; i++) { Console.Write(ToInt16(data, i)); Console.Write(" "); } Console.WriteLine(); break; case ABIF_Type.LONG: for (int i = 0; i < dir.numelements; i++) { Console.Write(ToInt32(data, i)); Console.Write(" "); } Console.WriteLine(); break; case ABIF_Type.WORD: for (int i = 0; i < dir.numelements; i++) { Console.Write(ToInt32(data, i)); Console.Write(" "); } Console.WriteLine(); break; case ABIF_Type.P_STRING: Console.WriteLine(BitProcessor.ToString(data, 1, data[0])); break; case ABIF_Type.C_STRING: Console.WriteLine(BitProcessor.ToString(data, 0, dir.datasize)); break; default: Console.WriteLine(data); break; } }