public void save(Stream os) { // write database file try { DataWriter outw = new DataWriter(os, Encoding.ASCII); // write header outw.writeInt(FILE_FORMAT); // create node writer VersionInfo versionInfo = new VersionInfo(); versionInfo.assetVersion = NODE_FORMAT; TypeNodeWriter nodeWriter = new TypeNodeWriter(versionInfo); // write field node table List <TypeNode> nodesTmp = new List <TypeNode>(new HashSet <TypeNode>(getNodeSet())); outw.writeInt(nodesTmp.Count); foreach (TypeNode typeNode in nodesTmp) { nodeWriter.write(outw, typeNode); } // write version string table List <UnityVersion> versionsTmp = new List <UnityVersion>(new HashSet <UnityVersion>(getVersionSet())); outw.writeInt(versionsTmp.Count); foreach (UnityVersion version in versionsTmp) { outw.writeStringNull(version.ToString()); } // write mapping data outw.writeInt(entries.Count); foreach (TypeTreeDatabaseEntry entry in entries) { UnityClass unityClass = entry.unityClass; UnityVersion unityVersion = entry.unityVersion; TypeNode node = entry.typeNode; int nodeIndex = nodesTmp.IndexOf(node); int classID = unityClass.ID(); int versionIndex = versionsTmp.IndexOf(unityVersion); outw.writeInt(nodeIndex); outw.writeInt(classID); outw.writeInt(versionIndex); } } catch (IOException ex) { Logger.Log("Can't write type database" + ex); } }
//throws IOException public void write(DataWriter outw) { // revision/version for newer formats if (versionInfo.assetVersion > 6) { outw.writeStringNull(versionInfo.unityRevision.ToString()); outw.writeInt(attributes); } TypeNodeWriter nodeWriter = new TypeNodeWriter(versionInfo); if (versionInfo.assetVersion > 13) { // TODO throw new Exception(); } else { int numBaseClasses = embeddedTypeMap.Count; outw.writeInt(numBaseClasses); foreach (KeyValuePair <int, EmbeddedTypeInfo> pair in embeddedTypeMap) { EmbeddedTypeInfo etinfo = pair.Value; int classID = etinfo.classID; outw.writeInt(classID); TypeNode node = etinfo.typeTree; nodeWriter.write(outw, node); } // padding if (versionInfo.assetVersion > 6) { outw.writeInt(0); } } }