예제 #1
0
        /*
         * Fills the given string collection with data from the field in the given packed file.
         */
        public static void FillFromPacked(SortedSet <string> result, PackedFile packed, string fieldName)
        {
            DBFile dbFile = PackedFileDbCodec.Decode(packed);

            foreach (DBRow entry in dbFile.Entries)
            {
                string toAdd = entry[fieldName].Value;
                if (toAdd != null)
                {
                    result.Add(toAdd);
                }
            }
        }
        // this could do with an update; since the transition to schema.xml,
        // we also know obsolete fields and can remove them,
        // and we can add fields in the middle instead of assuming they got appended.
        public void UpdatePackedFile(PackedFile packedFile)
        {
            string key = DBFile.Typename(packedFile.FullPath);

            if (DBTypeMap.Instance.IsSupported(key))
            {
                PackedFileDbCodec codec = PackedFileDbCodec.FromFilename(packedFile.FullPath);
                int          maxVersion = DBTypeMap.Instance.MaxVersion(key);
                DBFileHeader header     = PackedFileDbCodec.readHeader(packedFile);
                if (header.Version < maxVersion)
                {
                    // found a more recent db definition; read data from db file
                    DBFile updatedFile = PackedFileDbCodec.Decode(packedFile);

                    TypeInfo dbFileInfo = updatedFile.CurrentType;
                    TypeInfo targetInfo = GetTargetTypeInfo(key, maxVersion);
                    if (targetInfo == null)
                    {
                        throw new Exception(string.Format("Can't decide new structure for {0} version {1}.", key, maxVersion));
                    }

                    // identify FieldInstances missing in db file
                    for (int i = 0; i < targetInfo.Fields.Count; i++)
                    {
                        FieldInfo oldField = dbFileInfo[targetInfo.Fields[i].Name];
                        if (oldField == null)
                        {
                            foreach (List <FieldInstance> entry in updatedFile.Entries)
                            {
                                entry.Insert(i, targetInfo.Fields[i].CreateInstance());
                            }
                        }
                    }
                    //updatedFile.Header.GUID = guid;
                    updatedFile.Header.Version = maxVersion;
                    packedFile.Data            = codec.Encode(updatedFile);
                }
            }
        }
예제 #3
0
        /*
         * Create DBFile from the given PackedFile.
         */
        public static DBFile Decode(PackedFile file)
        {
            PackedFileDbCodec codec = FromFilename(file.FullPath);

            return(codec.Decode(file.Data));
        }