public void AddReader(D2OReader d2oFile) { var classes = d2oFile.Classes; foreach (var @class in classes) { if (m_ignoredTyes.Contains(@class.Value.ClassType)) { continue; } if (m_readers.ContainsKey(@class.Value.ClassType)) { // this classes are not bound to a single file, so we ignore them m_ignoredTyes.Add(@class.Value.ClassType); m_readers.Remove(@class.Value.ClassType); } else { m_readers.Add(@class.Value.ClassType, d2oFile); } } logger.Info("File added : {0}", Path.GetFileName(d2oFile.FilePath)); }
private void OnSave(object parameter) { m_reader.Close(); var filePath = m_reader.FilePath; PerformSave(filePath); m_reader = new D2OReader(filePath); }
public void AddReaders(string directory) { foreach (var d2oFile in Directory.EnumerateFiles(directory).Where(entry => entry.EndsWith(".d2o"))) { var reader = new D2OReader(d2oFile); AddReader(reader); } }
public void readType(D2OReader reader) { GameDataTypeEnum fieldType = (GameDataTypeEnum)reader.ReadInt(); this.fieldType = fieldType; if (fieldType == GameDataTypeEnum.Vector) { innerField = new GameDataField(reader); } }
private void Open() { m_reader = new D2OReader(m_filePath); foreach (var dataObject in m_reader.EnumerateObjects()) { m_rows.Add(dataObject); } m_distinctTypes = m_rows.Select(x => x.GetType()).Distinct().ToArray(); var properties = m_distinctTypes.SelectMany(x => x.GetProperties()).Distinct(); var d2oProperties = m_reader.Classes.SelectMany(x => x.Value.Fields.Values).Distinct(); foreach (var property in properties) { var d2oProperty = d2oProperties.FirstOrDefault( x => x.Name.Equals(property.Name, StringComparison.InvariantCultureIgnoreCase)); if (m_searchProperties.Contains(property.Name)) { continue; } if (!property.PropertyType.IsPrimitive && property.PropertyType != typeof(string)) { continue; } var del = (Func <object, object>)property.GetGetMethod().CreateFuncDelegate(typeof(object)); m_searchProperties.Add(property.Name); m_propertiesGetters.Add(property.Name, del); var binding = new System.Windows.Data.Binding(property.Name); var column = new DataGridTemplateColumn(); FrameworkElementFactory element; if (property.PropertyType == typeof(bool)) { element = new FrameworkElementFactory(typeof(CheckBox)); element.SetBinding(ToggleButton.IsCheckedProperty, binding); element.SetValue(CheckBox.MarginProperty, new Thickness(1)); element.SetValue(CheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Center); element.SetValue(CheckBox.IsEnabledProperty, false); } else { element = new FrameworkElementFactory(typeof(TextBlock)); if (d2oProperty != null && d2oProperty.TypeId == D2OFieldType.I18N) { binding.Converter = new IdToI18NTextConverter(); column.Width = 120; } element.SetBinding(TextBlock.TextProperty, binding); element.SetValue(TextBlock.MarginProperty, new Thickness(1)); } column.CellTemplateSelector = new CellTemplateSelector() { Template = new DataTemplate(property.PropertyType) { VisualTree = element }, DefaultTemplate = new DataTemplate(), ExpectedType = property.ReflectedType, }; column.Header = property.Name; m_columns.Add(column); m_editor.ObjectsGrid.Columns.Add(column); } NewObjectTypes.AddRange(m_distinctTypes.Where(x => x.GetConstructor(Type.EmptyTypes) != null)); }
public GameDataField(D2OReader reader) { fieldName = reader.ReadUtf8(); readType(reader); }