private void _addRange() { var tab = _tab.To <int>(); var range = FormatConverters.IntOrHexConverter(_tbRange.Text); var from = FormatConverters.IntOrHexConverter(_tbFrom.Text); var table = tab.GetDb <int>((ServerDbs)_destTable.SelectedItem).Table; try { table.Commands.Begin(); for (int i = 0; i < range; i++) { var tuple = new ReadableTuple <int>(i + from, tab.DbComponent.AttributeList); if (_based != null) { tuple.Copy(_based); tuple.SetRawValue(0, i + from); } tuple.Added = true; table.Commands.AddTuple(i + from, tuple); } } catch (Exception err) { table.Commands.CancelEdit(); ErrorHandler.HandleException(err); } finally { table.Commands.End(); tab.Filter(); } }
public void AddItem(string itemId, string itemProperty, bool selectId, DbAttribute attribute) { Table <int, ReadableTuple <int> > btable = _table; try { DropEditDialog dialog = new DropEditDialog(itemId, itemProperty, _configuration.SubTableServerDbSearch, _tab.ProjectDatabase, selectId) { Element2 = attribute.DisplayName }; dialog.Owner = WpfUtilities.TopWindow; if (dialog.ShowDialog() == true) { string sid = dialog.Id; string svalue = dialog.DropChance; int value; int id; Int32.TryParse(sid, out id); Int32.TryParse(svalue, out value); if (id <= 0) { return; } ReadableTuple <int> tuple = new ReadableTuple <int>(id, _configuration.SubTableAttributeList); tuple.SetRawValue(attribute, value); tuple.SetRawValue(_configuration.SubTableParentAttribute, ((ReadableTuple <int>)_tab.List.SelectedItem).Key); tuple.Added = true; btable.Commands.AddTupleDico((ReadableTuple <int>)_tab.List.SelectedItem, _configuration.AttributeTable, id, tuple, _addedItem); } } catch (Exception err) { ErrorHandler.HandleException(err); } btable.Commands.EndEdit(); }
private void _updateTable(ReadableTuple <TKey> item) { Dictionary <int, ReadableTuple <int> > groups = (Dictionary <int, ReadableTuple <int> >)item.GetRawValue(1); if (groups == null) { groups = new Dictionary <int, ReadableTuple <int> >(); item.SetRawValue(1, groups); } SearchEngine.Filter(this); //SearchEngine.FilterFinished += (s, l) => { // _lv.Dispatch(p => { // // //_lv.OnResize(new SizeChangedInfo(_lv, new Size(_lv.Width, _lv.Height), true, false)); // //_lv.Measure(new Size(_lv.Width, _lv.Height)); // }); //}; }
public void PasteItems() { try { string data = Clipboard.GetText(); _table.Commands.Begin(); try { Dictionary <int, ReadableTuple <int> > dico = _getSelectedGroups(); using (StreamReader reader = new StreamReader(new MemoryStream(Encoding.Default.GetBytes(data)))) { while (!reader.EndOfStream) { string line = reader.ReadLine(); if (String.IsNullOrEmpty(line)) { break; } if (line.Length > 1 && line[0] == '/' && line[1] == '/') { continue; } string[] elements = line.Split(','); try { int id = Int32.Parse(elements[0]); if (dico.ContainsKey(id)) { ReadableTuple <int> tuple = dico[id]; for (int i = 1; i < elements.Length && i < _configuration.MaxElementsToCopy; i++) { _table.Commands.SetDico((ReadableTuple <int>)_tab.List.SelectedItem, _configuration.AttributeTable, tuple, tuple.Attributes[i], elements[i]); } tuple.SetRawValue(_configuration.SubTableParentAttribute, ((ReadableTuple <int>)_tab.List.SelectedItem).GetValue <int>(0)); } else { // New value ReadableTuple <int> newValue = new ReadableTuple <int>(id, _configuration.SubTableAttributeList); for (int i = 1; i < elements.Length && i < _configuration.MaxElementsToCopy; i++) { newValue.SetRawValue(i, elements[i]); } newValue.SetRawValue(_configuration.SubTableParentAttribute, ((ReadableTuple <int>)_tab.List.SelectedItem).GetValue <int>(0)); newValue.Added = true; _table.Commands.AddTupleDico(_tab.List.SelectedItem as ReadableTuple <int>, _configuration.AttributeTable, id, newValue, _addedItem); } } catch { // invalid item } } } } catch (Exception err) { ErrorHandler.HandleException(err); } finally { _table.Commands.End(); } } catch (Exception err) { ErrorHandler.HandleException(err); } }
public static void Loader(DbDebugItem <int> debug, AbstractDb <int> db) { //foreach (DbAttribute attribute in ServerItemGroupSubAttributes.AttributeList.Attributes) { // db.Attached[attribute.DisplayName] = false; //} if (debug.FileType == FileType.Txt) { _loadItemsGroupdDb(db, debug.DbSource, debug.FilePath); } else if (debug.FileType == FileType.Conf) { Table <int, ReadableTuple <int> > itemsDb = db.GetMeta <int>(ServerDbs.Items); var items = itemsDb.FastItems; int index = ServerItemAttributes.AegisName.Index; // The reverse table is used for an optimization // All the items are stored in a dictionary by their name instead of their ID _reverseTable = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); foreach (var item in items) { _reverseTable[item.GetStringValue(index)] = item.Key; } var ele = new LibconfigParser(debug.FilePath); var table = debug.AbsractDb.Table; foreach (ParserKeyValue group in ele.Output.OfType <ParserKeyValue>()) { string groupAegisName = group.Key; int groupId = _aegisNameToId(groupAegisName); if (groupId == -1) { debug.ReportIdException("Item ID '" + groupAegisName + "' couldn't be found.", groupAegisName, ErrorLevel.Critical); continue; } if (!table.ContainsKey(groupId)) { ReadableTuple <int> tupleParent = new ReadableTuple <int>(groupId, db.AttributeList); tupleParent.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >()); table.Add(groupId, tupleParent); } var dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(groupId, ServerItemGroupAttributes.Table); foreach (var itemEntry in group.Value) { string itemName; int quantity; if (itemEntry is ParserList) { ParserList list = (ParserList)itemEntry; itemName = list.Objects[0].ObjectValue; quantity = Int32.Parse(list.Objects[1].ObjectValue); } else if (itemEntry is ParserString) { itemName = itemEntry.ObjectValue; quantity = 1; } else { debug.ReportIdException("Unknown item entry in group '" + groupAegisName + "'.", groupAegisName, ErrorLevel.Critical); continue; } int itemId = _aegisNameToId(itemName); if (itemId == -1) { debug.ReportIdException("Failed to parse the item '" + itemName + "'.", itemName, ErrorLevel.Critical); continue; } ReadableTuple <int> tuple = new ReadableTuple <int>(itemId, ServerItemGroupSubAttributes.AttributeList); tuple.SetRawValue(ServerItemGroupSubAttributes.Rate, quantity); tuple.SetRawValue(ServerItemGroupSubAttributes.ParentGroup, groupId); dico[itemId] = tuple; } } } }
private static void _loadItemsGroupdDb(AbstractDb <int> db, ServerDbs serverDb, string file) { int numberOfErrors = 3; TextFileHelper.LatestFile = file; if (String.IsNullOrEmpty(file)) { DbIOErrorHandler.Handle(StackTraceException.GetStrackTraceException(), "File not found " + ServerDbs.ItemGroups + ".", ErrorLevel.NotSpecified); return; } var itemDb1 = db.ProjectDatabase.GetDb <int>(ServerDbs.Items); var itemDb2 = db.ProjectDatabase.GetDb <int>(ServerDbs.Items2); if (!itemDb1.IsLoaded) { itemDb1.LoadDb(); } if (!itemDb2.IsLoaded) { itemDb2.LoadDb(); } var itemDb = new MetaTable <int>(ServerItemAttributes.AttributeList); itemDb.AddTable(itemDb1.Table); itemDb.AddTable(itemDb2.Table); itemDb.MergeOnce(); Dictionary <string, ReadableTuple <int> > bufferredTuples = new Dictionary <string, ReadableTuple <int> >(); foreach (var tuple in itemDb.FastItems) { bufferredTuples[tuple.GetStringValue(ServerItemAttributes.AegisName.Index)] = tuple; } var table = db.Table; if (db.Attached[serverDb] == null) { db.Attached[serverDb] = new Utilities.Extension.Tuple <ServerDbs, HashSet <int> >(serverDb, new HashSet <int>()); } HashSet <int> loadedIds = ((Utilities.Extension.Tuple <ServerDbs, HashSet <int> >)db.Attached[serverDb]).Item2; foreach (string[] elements in TextFileHelper.GetElementsByCommas(IOHelper.ReadAllBytes(file))) { try { int itemId; int iItemId; if (Int32.TryParse(elements[0], out iItemId)) { itemId = iItemId; } else { var constantDb = db.ProjectDatabase.GetDb <string>(ServerDbs.Constants); if (!constantDb.IsLoaded) { constantDb.LoadDb(); } var tuple = constantDb.Table.TryGetTuple(elements[0]); if (tuple == null) { if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0])) { return; } continue; } itemId = tuple.GetValue <int>(1); } string orate = elements[2]; int nameId; int rate; if (Int32.TryParse(elements[1], out nameId)) { } else { var tuple = bufferredTuples[elements[1]]; if (tuple == null) { if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0])) { return; } continue; } nameId = tuple.Key; } Int32.TryParse(orate, out rate); var id = (object)itemId; loadedIds.Add((int)id); if (!table.ContainsKey(itemId)) { ReadableTuple <int> tuple = new ReadableTuple <int>(itemId, db.AttributeList); tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >()); table.Add(itemId, tuple); } Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(itemId, ServerItemGroupAttributes.Table); ReadableTuple <int> newTuple = new ReadableTuple <int>(nameId, ServerItemGroupSubAttributes.AttributeList); List <DbAttribute> attributes = new List <DbAttribute>(ServerItemGroupSubAttributes.AttributeList.Attributes); for (int i = 2; i < elements.Length; i++) { newTuple.SetRawValue(attributes[i - 1], elements[i]); } newTuple.SetRawValue(ServerItemGroupSubAttributes.ParentGroup, itemId); dico[nameId] = newTuple; } catch { if (DbPathLocator.GenericErrorHandler(ref numberOfErrors, elements[0])) { return; } } } }
public static void Loader(DbDebugItem <int> debug, AbstractDb <int> db, int groupId) { bool hasGuessedAttributes = false; List <DbAttribute> attributes = new List <DbAttribute>(ServerMobGroupSubAttributes.AttributeList.Attributes.Where(p => p.Visibility == VisibleState.Visible)); var table = db.Table; if (!table.ContainsKey(groupId)) { ReadableTuple <int> tuple = new ReadableTuple <int>(groupId, db.AttributeList); tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >()); table.Add(groupId, tuple); } var dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(groupId, ServerMobGroupAttributes.Table); foreach (string[] elements in TextFileHelper.GetElementsByCommas(IOHelper.ReadAllBytes(debug.FilePath))) { try { if (!hasGuessedAttributes) { db.Attached["Scanned"] = null; DbIOMethods.GuessAttributes(elements, attributes, -1, db); hasGuessedAttributes = true; } if (attributes.Count == 4) { // rAthena int id = Int32.Parse(elements[1]); ReadableTuple <int> tuple = new ReadableTuple <int>(id, ServerMobGroupSubAttributes.AttributeList); tuple.SetRawValue(ServerMobGroupSubAttributes.Rate, elements[3]); tuple.SetRawValue(ServerMobGroupSubAttributes.DummyName, elements[2]); tuple.SetRawValue(ServerMobGroupSubAttributes.ParentGroup, groupId); dico[id] = tuple; } else { // Hercules int id = Int32.Parse(elements[0]); ReadableTuple <int> tuple = new ReadableTuple <int>(id, ServerMobGroupSubAttributes.AttributeList); tuple.SetRawValue(ServerMobGroupSubAttributes.Rate, elements[2]); tuple.SetRawValue(ServerMobGroupSubAttributes.DummyName, elements[1]); tuple.SetRawValue(ServerMobGroupSubAttributes.ParentGroup, groupId); dico[id] = tuple; } } catch { if (elements.Length <= 0) { if (!debug.ReportIdException("#")) { return; } } else if (!debug.ReportIdException(elements[0])) { return; } } } }
private static void _loadItemsGroupdDb <TKey>(AbstractDb <TKey> db, string file) { int numberOfErrors = 3; TextFileHelper.LatestFile = file; if (String.IsNullOrEmpty(file)) { DbLoaderErrorHandler.Handle("File not found " + ServerDbs.ItemGroups + ".", ErrorLevel.NotSpecified); return; } var itemDb1 = db.Database.GetDb <int>(ServerDbs.Items); var itemDb2 = db.Database.GetDb <int>(ServerDbs.Items); if (!itemDb1.IsLoaded) { itemDb1.LoadDb(); } if (!itemDb2.IsLoaded) { itemDb2.LoadDb(); } var itemDb = new MetaTable <int>(ServerItemAttributes.AttributeList); itemDb.AddTable(itemDb1.Table); itemDb.AddTable(itemDb2.Table); var table = db.Table; HashSet <int> loadedIds = ((Tuple <string, HashSet <int> >)db.Attached[file]).Item2; foreach (string[] elements in TextFileHelper.GetElementsByCommas(File.ReadAllBytes(file))) { try { TKey itemId; int iItemId; if (Int32.TryParse(elements[0], out iItemId)) { itemId = (TKey)(object)iItemId; } else { var constantDb = db.Database.GetDb <string>(ServerDbs.Constants); if (!constantDb.IsLoaded) { constantDb.LoadDb(); } var tuple = constantDb.Table.TryGetTuple(elements[0]); if (tuple == null) { if (AllLoaders.GenericErrorHandler(ref numberOfErrors, elements[0])) { return; } continue; } itemId = (TKey)(object)tuple.GetValue <int>(1); } string orate = elements[2]; int nameId; int rate; if (Int32.TryParse(elements[1], out nameId)) { } else { var tuple = itemDb.FastItems.FirstOrDefault(p => p.GetStringValue(ServerItemAttributes.AegisName.Index) == elements[1]); if (tuple == null) { if (AllLoaders.GenericErrorHandler(ref numberOfErrors, elements[0])) { return; } continue; } nameId = tuple.GetKey <int>(); } Int32.TryParse(orate, out rate); var id = (object)itemId; loadedIds.Add((int)id); if (!table.ContainsKey(itemId)) { ReadableTuple <TKey> tuple = new ReadableTuple <TKey>(itemId, db.AttributeList); tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >()); table.Add(itemId, tuple); } Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(itemId, ServerItemGroupAttributes.Table); ReadableTuple <int> newTuple = new ReadableTuple <int>(nameId, ServerItemGroupSubAttributes.AttributeList); List <DbAttribute> attributes = new List <DbAttribute>(ServerItemGroupSubAttributes.AttributeList.Attributes); for (int i = 2; i < elements.Length; i++) { db.Attached[attributes[i - 1].DisplayName] = true; newTuple.SetRawValue(attributes[i - 1], elements[i]); } dico[nameId] = newTuple; } catch { if (AllLoaders.GenericErrorHandler(ref numberOfErrors, elements[0])) { return; } } } }
public static void DbItemGroups <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db) { foreach (DbAttribute attribute in ServerItemGroupSubAttributes.AttributeList.Attributes) { db.Attached[attribute.DisplayName] = false; } if (debug.FileType == FileType.Txt) { if (db.Attached["FromUserRawInput"] != null && (bool)db.Attached["FromUserRawInput"]) { _loadItemsGroupdDb(db, debug.FilePath); return; } using (StreamReader reader = new StreamReader(File.OpenRead(debug.FilePath))) { string line; while (!reader.EndOfStream) { line = reader.ReadLine(); if (line != null && line.StartsWith("import: ")) { string dbPath = AllLoaders.DetectPathAll(line.Replace("import: ", "")); if (dbPath == null) { ErrorHandler.HandleException("Couldn't find the file '" + line.Replace("import: ", "") + "'."); } else { db.Attached[dbPath] = new Tuple <string, HashSet <int> >(line.Replace("import: ", ""), new HashSet <int>()); _loadItemsGroupdDb(db, dbPath); } } } } } else if (debug.FileType == FileType.Conf) { ItemGroupParser itemHelper = new ItemGroupParser(); Table <int, ReadableTuple <int> > itemsDb = db.GetMeta <int>(ServerDbs.Items); int index = ServerItemAttributes.AegisName.Index; var table = db.Table; var items = itemsDb.FastItems; // The reverse table is used for an optimization (~3 seconds to ~50 ms) // All the items are stored in a dictionary by their name instead of their ID TkDictionary <string, int> reverseTable = new TkDictionary <string, int>(); foreach (var item in items) { reverseTable[item.GetStringValue(index).ToLowerInvariant()] = item.GetKey <int>(); } #if SDE_DEBUG Z.StopAndRemoveWithoutDisplay(-1); Z.StopAndRemoveWithoutDisplay(-2); Z.StopAndRemoveWithoutDisplay(-3); CLHelper.CR(-2); #endif foreach (string elements in TextFileHelper.GetElementsByParenthesis(File.ReadAllBytes(debug.FilePath))) { #if SDE_DEBUG CLHelper.CS(-2); CLHelper.CR(-1); CLHelper.CR(-3); #endif if (!itemHelper.Init(debug, elements)) { return; } #if SDE_DEBUG CLHelper.CS(-3); #endif try { Tuple tupleItem = itemsDb.TryGetTuple(reverseTable[itemHelper.Id.ToLowerInvariant()]); if (tupleItem == null) { if (itemHelper.Id.StartsWith("ID")) { int ival; if (Int32.TryParse(itemHelper.Id.Substring(2), out ival)) { tupleItem = itemsDb.TryGetTuple(ival); } if (tupleItem == null) { debug.ReportIdException("Item ID '" + ival + "' couldn't be found.", itemHelper.Id, ErrorLevel.Critical); continue; } } if (tupleItem == null) { debug.ReportIdException("Item ID '" + itemHelper.Id + "' couldn't be found.", itemHelper.Id, ErrorLevel.Critical); continue; } } TKey itemId = tupleItem.GetKey <TKey>(); if (!table.ContainsKey(itemId)) { ReadableTuple <TKey> tuple = new ReadableTuple <TKey>(itemId, db.AttributeList); tuple.SetRawValue(ServerItemGroupAttributes.Table, new Dictionary <int, ReadableTuple <int> >()); table.Add(itemId, tuple); } for (int i = 0; i < itemHelper.Quantities.Count; i++) { string onameId = itemHelper.Quantities[i].Item1; string orate = itemHelper.Quantities[i].Item2; int id = 0; int rate; tupleItem = itemsDb.TryGetTuple(reverseTable[onameId.ToLowerInvariant()]); if (tupleItem == null) { if (onameId.StartsWith("ID")) { if (!Int32.TryParse(onameId.Substring(2), out id)) { debug.ReportIdException("Item ID '" + itemHelper.Quantities[i].Item1 + "' couldn't be found in group '" + itemHelper.Id + "'.", itemHelper.Id, ErrorLevel.Critical); continue; } } else { debug.ReportIdException("Item ID '" + itemHelper.Quantities[i].Item1 + "' couldn't be found in group '" + itemHelper.Id + "'.", itemHelper.Id, ErrorLevel.Critical); continue; } } int nameId = tupleItem == null ? id : tupleItem.GetKey <int>(); Int32.TryParse(orate, out rate); Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)table.GetRaw(itemId, ServerItemGroupAttributes.Table); ReadableTuple <int> tuple = new ReadableTuple <int>(nameId, ServerItemGroupSubAttributes.AttributeList); tuple.SetRawValue(ServerItemGroupSubAttributes.Rate, rate); dico[nameId] = tuple; } } catch { if (!debug.ReportIdException(itemHelper.Id)) { return; } } #if SDE_DEBUG CLHelper.CS(-1); CLHelper.CR(-2); #endif } #if SDE_DEBUG CLHelper.CS(-2); CLHelper.CS(-3); CLHelper.WA = ", method core : " + CLHelper.CD(-1) + "ms, loop getter : " + CLHelper.CD(-2) + "ms, internal parser : " + CLHelper.CD(-3); #endif } }