コード例 #1
0
        private void ReadParameters()
        {
            byte[] parameters = new byte[4];
            int    nb         = _reader.Read(parameters, 0, 4);
            // TODO we should not ignore first 4 bytes as it is now

            int nextItem;

            do
            {
                sbyte  nameLen  = ParameterModel.ReadNameLength(_reader);
                bool   isLocked = nameLen < 0;
                sbyte  id       = ParameterModel.ReadGroupID(_reader);
                string name     = ParameterModel.ReadName(_reader, Math.Abs(nameLen));
                nextItem = ParameterModel.ReadNextItemOffset(_reader);

                ParameterModel param             = null;
                int            parameterDataSize = 0;
                if (id > 0) //if id > 0 then it is parameter, otherwise it is group
                {
                    param             = new Parameter(_reader);
                    parameterDataSize = (param as Parameter).C3DParameterSize;
                }
                else
                {
                    param = new ParameterGroup();
                }

                byte   descLen = ParameterModel.ReadDescLength(_reader);
                string desc    = ParameterModel.ReadName(_reader, descLen);

                // general assignment
                param.Name        = name;
                param.Id          = id;
                param.Description = desc;


                if (param is Parameter)
                {
                    _allParameters.Add(param as Parameter);
                }
                else
                {
                    _nameToGroups.Add(param.Name, param as ParameterGroup);
                    _idToGroups.Add(param.Id, param as ParameterGroup);
                }

                // if next item is more far read unknown data
                // I assume that there will be no more than 512 bytes of unknown data

                if (nextItem > (descLen + 3 + parameterDataSize)) // If the C3D file is correct this will never happen, but real life is far from perfect
                {
                    int toRead = nextItem - (descLen + 1);
                    _reader.Read(parameters, 0, toRead);
                }
                //else if (nextItem < (descLen + 3 + parameterDataSize)) {
                //    Console.Error.WriteLine("Error");
                //}
            } while (nextItem > 0);

            foreach (Parameter p in _allParameters)
            {
                if (_idToGroups.ContainsKey(-p.Id))
                {
                    _idToGroups[-p.Id].Parameters.Add(p);
                }
            }
        }
コード例 #2
0
 public static string ReadDesc(BinaryReader reader, int length)
 {
     return(ParameterModel.ReadString(reader, length));
 }