public DatabaseFieldEditorBase(DataCoreDatabase database, object instance, PropertyInfo property, int arrayIndex = -1) { Instance = instance; Property = property; this.ArrayIndex = arrayIndex; this.Database = database; }
public void OpenDatabaseRecord(DataCoreDatabase dataCore, DataCoreRecord record) { foreach (TabItem existing_tab in Tabs.Items) { if (record.ID == existing_tab.DataContext as Guid?) { Tabs.SelectedValue = existing_tab; return; } } TabItem tab = new TabItem(); var name = record.Name; tab.Header = name; tab.DataContext = record.ID; var closable_tab_style = this.FindResource("ClosableTab"); tab.Style = closable_tab_style as Style; tab.Content = new DatabaseStructureView(dataCore, record.Instance, true); Tabs.Items.Add(tab); Tabs.SelectedItem = tab; tab.IsSelected = true; }
internal ArrayFixupBase(DataCoreDatabase database, object instance, PropertyInfo property, int firstIndex, int arrayCount) { Database = database; Instance = instance; Property = property; FirstIndex = firstIndex; ArrayCount = arrayCount; }
public static UIElement CreateUIElement(DataCoreDatabase database, object instance, PropertyInfo property, int array_index = -1) { try { var propertyType = property.PropertyType; if (DatabaseFieldEditorBase.IsTypeArray(property.PropertyType)) { propertyType = propertyType.GenericTypeArguments[0]; } if (propertyType.IsPrimitive) { if (propertyType == typeof(bool)) { return(new DatabaseBoolField(database, instance, property, array_index)); } return(new DatabaseNumberField(database, instance, property, array_index)); } else if (propertyType == typeof(Guid)) { return(new UnsupportedField(property)); } else if (propertyType.IsEnum) { return(new DatabaseEnumField(database, instance, property, array_index)); } else if (typeof(IDataCoreString).IsAssignableFrom(propertyType)) { return(new DatabaseStringField(database, instance, property, array_index)); } else if (typeof(IDataCoreLocale).IsAssignableFrom(propertyType)) { return(new DatabaseStringField(database, instance, property, array_index)); } else if (typeof(IDataCoreStrongPointer).IsAssignableFrom(propertyType)) { return(new DatabasePointerField(database, instance, property, array_index)); } else if (typeof(IDataCoreWeakPointer).IsAssignableFrom(propertyType)) { return(new DatabasePointerField(database, instance, property, array_index)); } else if (typeof(IDataCoreStructure).IsAssignableFrom(propertyType)) { return(new DatabaseClassField(database, instance, property, array_index)); } else if (typeof(IDataCoreRecord).IsAssignableFrom(propertyType)) { return(new DatabaseReferenceField(database, instance, property, array_index)); } return(new UnsupportedField(property)); } catch (Exception) { return(new ErrorField(property)); } }
internal FixupBase(DataCoreDatabase database, object instance, PropertyInfo property) { Database = database; Instance = instance; Property = property; }
public DatabaseRecordSearchResult(DataCoreDatabase dataCore, DataCoreRecord record) { this.Database = dataCore; this.Record = record; }
public DatabaseNumberField(DataCoreDatabase database, object instance, PropertyInfo property, int arrayIndex = -1) : base(database, instance, property, arrayIndex) { Init(); }
//public DatabaseStructureView(DataCoreDatabase database, DataCoreRecord record, bool isRoot = false) // : this(database, new Pointer { StructIndex = record.StructIndex, VariantIndex = record.VariantIndex }, isRoot) //{ //} public DatabaseStructureView(DataCoreDatabase database, object instance, bool isRoot = false) { this.Database = database; this.Instance = instance; this.DataContext = this; InitializeComponent(); var type = instance.GetType(); #if DEBUG if (!typeof(IDataCoreStructure).IsAssignableFrom(type)) { throw new Exception("Invalid type used in DatabaseStructureView"); } #endif var fieldsStackPanel = new StackPanel(); if (database.ManagedStructureInheritedProperties.ContainsKey(type)) { var properties = database.ManagedStructureInheritedProperties[type]; foreach (var property in properties) { UIElement root_ui_element = null; var propertyType = property.PropertyType; if (DatabaseFieldEditorBase.IsTypeArray(propertyType)) { root_ui_element = new DatabaseArrayField(database, instance, property); } else { var property_field_ui = CreateUIElement(database, instance, property); if (property_field_ui == null) { TextBox textbox = new TextBox(); textbox.Text = $"{property.Name} {propertyType.Name} is unsupported"; property_field_ui = textbox; } root_ui_element = property_field_ui; } if (root_ui_element != null) { fieldsStackPanel.Children.Add(root_ui_element); } } if (isRoot) { scrollViewer.Content = fieldsStackPanel; } else { Root.Children.Clear(); Root.Children.Add(fieldsStackPanel); } } else { Crucible.MainWindow.SetStatus($"Invalid record {type.Name} what the heck!??? Please report this!!!!"); } }
private void LoadDatabaseFile() { #if !DEBUG try { #endif ClearView(); MainWindow.SetStatus($"Loading database {File.Name}", 0, 0, -1); var startTime = DateTime.Now; var statusTask = Task.Factory.StartNew(() => { #if !DEBUG try { #endif Task databaseRecordsTask; var gameDatabaseFile = File ?? MainWindow.FilesystemManager.P4KFilesystem["Data\\Game.dcb"]; var data = gameDatabaseFile.GetData(); var localDirectory = Path.Combine(CrucibleApplication.CurrentProjectDirectory, "datacore"); Directory.CreateDirectory(localDirectory); Database = new DataCoreDatabase( MainWindow.FilesystemManager.MajorVersion, MainWindow.FilesystemManager.MinorVersion, MainWindow.FilesystemManager.RevisionVersion, MainWindow.FilesystemManager.BuildVersion, localDirectory, data, DataCoreBinaryEditor2PluginSettings.Settings.UseDatabaseCache ? DataCoreDatabase.CacheMode.UseCache : DataCoreDatabase.CacheMode.NoCache ); // setup database //DatabaseRecordTreeViewItem databaseDefinitionsTreeViewRoot = new DatabaseRecordTreeViewItem(Database, null); DatabaseRecordTreeViewItem databaseRecordsTreeViewRoot = new DatabaseRecordTreeViewItem(Database, null); DatabaseRecordSearchResults = new List <DatabaseRecordSearchResult>(); databaseRecordsTask = Task.Factory.StartNew(() => { Dictionary <Type, DatabaseRecordTreeViewItem> recordTreeStructureGroups = new Dictionary <Type, DatabaseRecordTreeViewItem>(); // Database Tree foreach (var recordKeyPair in Database.ManagedGUIDTable) { var record = recordKeyPair.Value; var type = record.StructureType; if (!recordTreeStructureGroups.ContainsKey(type)) { DatabaseRecordTreeViewItem databaseMenuItem = new DatabaseRecordTreeViewItem(Database, null); databaseMenuItem.Title = type.Name; databaseRecordsTreeViewRoot.Items.Add(databaseMenuItem); recordTreeStructureGroups[record.StructureType] = databaseMenuItem; } } foreach (var recordKeyPair in Database.ManagedGUIDTable) { var record = recordKeyPair.Value; var rootMenuItem = recordTreeStructureGroups[record.StructureType]; DatabaseRecordTreeViewItem databaseMenuItem = new DatabaseRecordTreeViewItem(Database, record); databaseMenuItem.Record = record; rootMenuItem.Items.Add(databaseMenuItem); } // Database Search foreach (var recordKeyPair in Database.ManagedGUIDTable) { var record = recordKeyPair.Value; DatabaseRecordSearchResult DatabaseRecordSearchResult = new DatabaseRecordSearchResult(Database, record); DatabaseRecordSearchResults.Add(DatabaseRecordSearchResult); } databaseRecordsTreeViewRoot.Sort(true); }); //Task.WaitAll(new Task[] { databaseTypesTask, databaseRecordsTask }); databaseRecordsTask.Wait(); this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate() { //databaseDefinitionsTreeView.ItemsSource = databaseDefinitionsTreeViewRoot.Items; databaseRecordsTreeView.ItemsSource = databaseRecordsTreeViewRoot.Items; databaseRecordsSearchResults.ItemsSource = new List <DatabaseRecordSearchResult>(); // leave this empty, search will populate // Lets collect garbage because code is garbage GC.Collect(); GC.WaitForPendingFinalizers(); var deltaTime = DateTime.Now - startTime; MainWindow.SetStatus(String.Format($"Finished loading {File.Name} {{0:0.00}}s", deltaTime.TotalSeconds)); FinishedLoading(); //var character = databaseRecordsTreeViewRoot?.Items?.Where(item => item.Title.ToLowerInvariant() == "acpickupslist")?.FirstOrDefault(); //var chatacter_admin = character?.Items.Where(item => item.Title.ToLowerInvariant() == "competitivepickupslist")?.FirstOrDefault(); //if (chatacter_admin != null) //{ // OpenDatabaseRecord(chatacter_admin); //} #if DEBUG var entityclassdefinition = databaseRecordsTreeViewRoot?.Items?.Where(item => item.Title.ToLowerInvariant() == "entityclassdefinition")?.FirstOrDefault(); var aegs_idris = entityclassdefinition?.Items.Where(item => item.Title.ToLowerInvariant() == "aegs_idris")?.FirstOrDefault(); if (aegs_idris != null) { OpenDatabaseRecord(aegs_idris); } #endif })).Wait(); return; #if !DEBUG } catch (Exception e) { MainWindow.SetStatus($"Failed to load {File.FullPath}! Reason: {e.Message}"); FinishedLoading(); } #endif }); #if !DEBUG } catch (Exception e) { MainWindow.SetStatus($"Failed to load {File.FullPath}! Reason: {e.Message}"); FinishedLoading(); } #endif }
internal WeakPointerFixup(DataCoreDatabase database, object instance, PropertyInfo info, RawWeakPointer pointer) : base(database, instance, info) { Pointer = pointer; }
internal ReferenceFixup(DataCoreDatabase database, object instance, PropertyInfo info, RawReference reference) : base(database, instance, info) { Reference = reference; }