public static void Writer(DbDebugItem <int> debug, AbstractDb <int> db) { try { if (debug.FileType == FileType.Txt) { // Do not care about the loaded IDs, just write them where they belong _idToGroupName.Clear(); var itemDb = db.GetMeta <int>(ServerDbs.Items); AbstractDb <string> constantDb = db.GetDb <string>(ServerDbs.Constants); var affectedGroups = new HashSet <int>(); var nonNullGroups = new HashSet <int> { 1, 2, 3, 4, 6, 44, 28, 29, 30, 31, 34, 43 }; if (debug.DbSource == ServerDbs.ItemGroupsBlueBox) { affectedGroups = new HashSet <int> { 1 }; } else if (debug.DbSource == ServerDbs.ItemGroupsVioletBox) { affectedGroups = new HashSet <int> { 2 }; } else if (debug.DbSource == ServerDbs.ItemGroupsCardalbum) { affectedGroups = new HashSet <int> { 3, 44 }; } else if (debug.DbSource == ServerDbs.ItemGroupsFindingore) { affectedGroups = new HashSet <int> { 6 }; } else if (debug.DbSource == ServerDbs.ItemGroupsGiftBox) { affectedGroups = new HashSet <int> { 4, 28, 29, 30, 31, 34, 43 }; } else if (debug.DbSource == ServerDbs.ItemGroupsMisc) { affectedGroups = null; } else if (debug.DbSource == ServerDbs.ItemGroupsPackages) { affectedGroups = null; } if (affectedGroups != null) { while (true) { bool isModified = false; // Check if the group was modified or not foreach (var tuple in db.Table.FastItems.Where(p => affectedGroups.Contains(p.Key))) { if (!tuple.Normal) { isModified = true; break; } } if (isModified) { break; } // Check if the file has more groups than what it's supposed to HashSet <int> loadedIds = ((Utilities.Extension.Tuple <ServerDbs, HashSet <int> >)db.Attached[debug.DbSource]).Item2; foreach (var id in loadedIds) { if (!affectedGroups.Contains(id)) { isModified = true; break; } } if (isModified) { break; } foreach (var id in affectedGroups) { if (!loadedIds.Contains(id)) { isModified = true; break; } } if (isModified) { break; } return; } } else { while (true) { bool isModified = false; // Check if the group was modified or not foreach (var tuple in db.Table.FastItems.Where(p => !nonNullGroups.Contains(p.Key))) { bool isPackage = _isPackage((Dictionary <int, ReadableTuple <int> >)tuple.GetRawValue(1)); if (debug.DbSource == ServerDbs.ItemGroupsMisc && isPackage) { continue; } if (debug.DbSource == ServerDbs.ItemGroupsPackages && !isPackage) { continue; } if (!tuple.Normal) { isModified = true; break; } } if (isModified) { break; } return; } } using (StreamWriter writer = new StreamWriter(debug.FilePath)) { foreach (ReadableTuple <int> tup in db.Table.FastItems.OrderBy(p => p.Key)) { Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)tup.GetRawValue(1); int key = tup.GetKey <int>(); bool isPackage = _isPackage(dico); if ((affectedGroups != null && affectedGroups.Contains(key)) || (affectedGroups == null && debug.DbSource == ServerDbs.ItemGroupsGiftBox && isPackage == false) || (affectedGroups == null && debug.DbSource == ServerDbs.ItemGroupsPackages && isPackage == true)) { foreach (var pair in dico.OrderBy(p => p.Key)) { var dbTuple = itemDb.TryGetTuple(pair.Key); List <string> items = ServerItemGroupSubAttributes.AttributeList.Attributes.Select(p => pair.Value.GetValue <string>(p)).ToList(); RemoveDefaultValues(items); writer.WriteLine(_getWriterGroupName(key, constantDb) + "," + string.Join(",", items.ToArray()) + (dbTuple == null ? "" : "\t// " + dbTuple.GetValue(ServerItemAttributes.Name))); } writer.WriteLine(); } } } } else if (debug.FileType == FileType.Conf) { StringBuilder builder = new StringBuilder(); var dbItems = db.GetMeta <int>(ServerDbs.Items); List <string> aegisNames = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.AegisName.Index)).ToList(); List <string> names = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.Name.Index)).ToList(); foreach (int id in db.Table.FastItems.Select(p => p.Key).OrderBy(p => p)) { //bool isPackage = _isPackage((Dictionary<int, ReadableTuple<int>>)db.Table[id].GetRawValue(1)); // //if (debug.DbSource == ServerDbs.ItemGroupsMisc && isPackage) // continue; // //if (debug.DbSource == ServerDbs.ItemGroupsPackages && !isPackage) // continue; builder.AppendLine(ItemGroupParser.ToHerculesDbEntry(db, id, aegisNames, names)); builder.AppendLine(); } IOHelper.WriteAllText(debug.FilePath, builder.ToString()); } } catch (Exception err) { debug.ReportException(err); } }
private void _copy <TKey>() { // Only int tables are allowed... AbstractDb <TKey> db = _destDb.To <TKey>(); AbstractDb <TKey> sourceDb = _sourceDb.To <TKey>(); TKey newKey; TKey firstId = (TKey)(object)Int32.Parse(_tbNewId.Text); Regex aegisNameInput = null; Regex nameInput = null; try { db.Table.Commands.BeginNoDelay(); for (int i = 0; i < _tuples.Count; i++) { var item = _tuples[i]; TKey oldId = item.GetKey <TKey>(); newKey = (TKey)(object)((int)(object)firstId + i); if (!SdeAppConfiguration.CmdCopyToOverwrite) { if (db.Table.ContainsKey(newKey)) { continue; } } if (i == _tuples.Count - 1) { db.Table.Commands.CopyTupleTo(sourceDb.Table, oldId, newKey, (a, b, c, d, e) => _copyToCallback2(db, c, d, e)); } else { db.Table.Commands.CopyTupleTo(sourceDb.Table, oldId, newKey, (a, b, c, d, e) => _copyToCallback3(c, d, e)); } if ((ServerDbs.ServerItems & db.DbSource) != 0) { _autoField(ref aegisNameInput, () => SdeAppConfiguration.CmdCopyToAegisNameEnabled, () => SdeAppConfiguration.CmdCopyToAegisNameFormatInput, () => SdeAppConfiguration.CmdCopyToAegisNameFormatOutput, item, db, newKey, i, ServerItemAttributes.AegisName); _autoField(ref nameInput, () => SdeAppConfiguration.CmdCopyToNameEnabled, () => SdeAppConfiguration.CmdCopyToNameFormatInput, () => SdeAppConfiguration.CmdCopyToNameFormatOutput, item, db, newKey, i, ServerItemAttributes.Name); } } } catch (Exception err) { db.Table.Commands.CancelEdit(); ErrorHandler.HandleException(err); } finally { db.Table.Commands.End(); _tab.Filter(); } if ((ServerDbs.ServerItems & db.DbSource) != 0 && SdeAppConfiguration.CmdCopyToClientItems) { var cDb = db.GetDb <TKey>(ServerDbs.CItems); try { cDb.Table.Commands.Begin(); for (int i = 0; i < _tuples.Count; i++) { newKey = (TKey)(object)((int)(object)firstId + i); cDb.Table.Commands.CopyTupleTo(cDb.Table, _tuples[i].GetKey <TKey>(), newKey, (a, b, c, d, e) => _copyToCallback3(c, d, e)); } } catch (Exception err) { cDb.Table.Commands.CancelEdit(); ErrorHandler.HandleException(err); } finally { cDb.Table.Commands.End(); } } }