void OnBuildSelection(object sender, ToolStripItemClickedEventArgs ea) { try { var clientBuild = Convert.ToUInt32(ea.ClickedItem.Tag); _structures.Clear(); // Load XML Structures XmlDefinitionReader.Load("./structures.xml", clientBuild); // Look for dbc files PathToFiles = String.Format(@"dbc/{0}/", clientBuild); var dbcNames = FindFiles(PathToFiles); if (dbcNames == null || dbcNames.Length == 0) { throw new DbcNotFoundException(); } dbcNames = dbcNames.OrderBy(d => d).ToArray(); var structures = Assembly.GetExecutingAssembly().GetTypes() .Where(t => { var attr = Attribute.GetCustomAttribute(t, typeof(DbFileInfoAttribute), false) as DbFileInfoAttribute; return(t.IsClass && t.IsSealed && attr != null && attr.Build == clientBuild && attr.Enabled); }).ToArray(); var xmlStructures = XmlDefinitionReader.GetStructures(); if (structures.Length == 0) { throw new UnsupportedClientBuildException(clientBuild); } var items = new List <string>(); var coreStructuresCount = 0; for (var i = 0; i < structures.Length; ++i) { var attr = structures[i].GetCustomAttributes(typeof(DbFileInfoAttribute), false).First() as DbFileInfoAttribute; if (attr == null || !dbcNames.Contains(attr.FileName)) { continue; } items.Add(attr.FileName); _structures.Add(attr.FileName, structures[i]); ++coreStructuresCount; } // Override with XML structures for (var i = 0; i < xmlStructures.Count; ++i) { if (_structures.ContainsKey(xmlStructures.Keys.ElementAt(i))) { if (OverrideCoreDefinitions) { _structures[xmlStructures.Keys.ElementAt(i)] = xmlStructures.Values.ElementAt(i); --coreStructuresCount; } } else { items.Add(xmlStructures.Keys.ElementAt(i)); _structures.Add(xmlStructures.Keys.ElementAt(i), xmlStructures.Values.ElementAt(i)); --coreStructuresCount; } } FileSelectionBox.Enabled = true; FileSelectionBox.Items.Clear(); FileSelectionBox.Items.AddRange(items.ToArray()); StatusLabel.Text = String.Format(@"Version: {2}. {0} Core Definition(s) loaded. {1} XML Definition(s) loaded.", coreStructuresCount, items.Count - coreStructuresCount, clientBuild); } catch (DirectoryNotFoundException dnfe) { FileSelectionBox.Enabled = false; SqlExport.Enabled = SqlFilteredExport.Enabled = false; IdaExport.Enabled = false; StatusLabel.Text = dnfe.Message; } catch (UnsupportedClientBuildException ucbe) { FileSelectionBox.Enabled = false; SqlExport.Enabled = SqlFilteredExport.Enabled = false; IdaExport.Enabled = false; StatusLabel.Text = ucbe.Message; } catch (DbcNotFoundException) { StatusLabel.Text = @"No DBC file found in the provided path. Action cancelled."; } }
void OnBuildSelection(object sender, ToolStripItemClickedEventArgs ea) { try { var clientBuild = Convert.ToUInt32(ea.ClickedItem.Tag); _structures.Clear(); XmlDefinitionReader.Load("./structures.xml", clientBuild); FilesPath = String.Format(@"dbc/{0}/", clientBuild); string[] dbcNames = Directory.EnumerateFiles(FilesPath, "*.*", SearchOption.TopDirectoryOnly) .Where(s => s.EndsWith(".dbc", StringComparison.CurrentCultureIgnoreCase) || s.EndsWith(".db2", StringComparison.CurrentCultureIgnoreCase)) .Select(Path.GetFileName).ToArray(); if (dbcNames.Length == 0) { throw new DbcNotFoundException(); } dbcNames = dbcNames.OrderBy(d => d).ToArray(); var structures = Assembly.GetExecutingAssembly().GetTypes() .Where(t => { var attr = Attribute.GetCustomAttribute(t, typeof(DbFileInfoAttribute), false) as DbFileInfoAttribute; return(t.IsClass && t.IsSealed && attr != null && attr.Build == clientBuild && attr.Enabled); }).ToArray(); var xmlStructures = XmlDefinitionReader.GetStructures(); if (structures.Length == 0) { throw new UnsupportedClientBuildException(clientBuild); } var items = new string[structures.Length]; for (var i = 0; i < structures.Length; ++i) { var attr = structures[i].GetCustomAttributes(typeof(DbFileInfoAttribute), false).First() as DbFileInfoAttribute; if (attr == null || !dbcNames.Contains(attr.FileName)) { throw new DbcFileNameNotFoundException(attr.FileName); } items[i] = attr.FileName; if (!XmlOverrides.Checked || !xmlStructures.Keys.Contains(attr.FileName)) { _structures.Add(items[i], structures[i]); } else { _structures.Add(items[i], xmlStructures[attr.FileName].CreateType()); } } FileSelectionBox.Enabled = true; FileSelectionBox.Items.Clear(); FileSelectionBox.Items.AddRange(items); StatusLabel.Text = String.Empty; } catch (DirectoryNotFoundException dnfe) { FileSelectionBox.Enabled = false; SqlExport.Enabled = false; IdaExport.Enabled = false; StatusLabel.Text = dnfe.Message; } catch (UnsupportedClientBuildException ucbe) { FileSelectionBox.Enabled = false; SqlExport.Enabled = false; IdaExport.Enabled = false; StatusLabel.Text = ucbe.ToString(); } }