public static string ReadDesc(BinaryReader reader, int length) { return(C3DParameterModel.ReadString(reader, length)); }
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 = C3DParameterModel.ReadNameLength(_reader); bool isLocked = nameLen < 0; sbyte id = C3DParameterModel.ReadGroupID(_reader); string name = C3DParameterModel.ReadName(_reader, Math.Abs(nameLen)); nextItem = C3DParameterModel.ReadNextItemOffset(_reader); C3DParameterModel 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 = C3DParameterModel.ReadDescLength(_reader); string desc = C3DParameterModel.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); } } }