public TypeDatabase(string filepath = null) { if (filepath == null) { filepath = TypeDatabase.GetDefaultDatabasePath(); } if (File.Exists(filepath) == false) { throw new FileNotFoundException(filepath + " does not exist."); } using (FileStream fileStream = File.Open(filepath, FileMode.Open, FileAccess.Read)) using (BinaryReader reader = new BinaryReader(fileStream)) { int max = reader.ReadInt32(); this.versions = new string[max]; for (int i = 0; i < max; ++i) { this.versions[i] = reader.ReadString(); } max = reader.ReadInt32(); this.types = new Type[max]; for (int i = 0; i < max; ++i) { Type type = new Type() { isPublic = reader.ReadBoolean(), name = reader.ReadString(), versions = reader.ReadBytes(reader.ReadInt32()), members = new Member[reader.ReadInt32()] }; this.types[i] = type; for (int j = 0, max2 = type.members.Length; j < max2; ++j) { type.members[j] = new Member() { type = (MemberTypes)reader.ReadByte(), name = reader.ReadString(), versions = reader.ReadBytes(reader.ReadInt32()), }; } } } }
public void Save(string filepath = null) { if (filepath == null) { filepath = TypeDatabase.GetDefaultDatabasePath(); } using (BinaryWriter assembliesWriter = new BinaryWriter(File.Open(filepath, FileMode.Create, FileAccess.Write))) { assembliesWriter.Write(this.versions.Length); for (int i = 0, max = this.versions.Length; i < max; ++i) { assembliesWriter.Write(this.versions[i]); } assembliesWriter.Write(this.types.Length); for (int i = 0, max = this.types.Length; i < max; ++i) { Type type = this.types[i]; assembliesWriter.Write(type.isPublic); assembliesWriter.Write(type.name); assembliesWriter.Write(type.versions.Length); for (int j = 0, max2 = type.versions.Length; j < max2; ++j) { assembliesWriter.Write(type.versions[j]); } assembliesWriter.Write(type.members.Length); for (int j = 0, max2 = type.members.Length; j < max2; ++j) { Member member = type.members[j]; assembliesWriter.Write((byte)member.type); assembliesWriter.Write(member.name); assembliesWriter.Write(member.versions.Length); for (int k = 0, max3 = member.versions.Length; k < max3; ++k) { assembliesWriter.Write(member.versions[k]); } } } } }