protected override void _loadDb() { base._loadDb(); if (AllLoaders.GetServerType() == ServerType.RAthena) { DbDebugItem <int> debug = new DbDebugItem <int>(this); // These are all being read twice and assigned to their respective table if (debug.Load(ServerDbs.ItemsAvail)) { DbLoaderMethods.DbCommaRange(debug, AttributeList, ServerItemAttributes.Sprite.Index, 1, false); } if (debug.Load(ServerDbs.ItemsDelay)) { DbLoaderMethods.DbCommaRange(debug, AttributeList, ServerItemAttributes.Delay.Index, 1, false); } if (debug.Load(ServerDbs.ItemsNoUse)) { DbLoaderMethods.DbCommaLoader(debug, AttributeList, DbLoaderMethods.DbItemsNouseFunction, false); } if (debug.Load(ServerDbs.ItemsStack)) { DbLoaderMethods.DbCommaLoader(debug, AttributeList, DbLoaderMethods.DbItemsStackFunction, false); } if (debug.Load(ServerDbs.ItemsTrade)) { DbLoaderMethods.DbCommaLoader(debug, AttributeList, DbLoaderMethods.DbItemsTradeFunction, false); } if (debug.Load(ServerDbs.ItemsBuyingStore)) { DbLoaderMethods.DbCommaLoader(debug, AttributeList, DbLoaderMethods.DbItemsBuyingStoreFunction, false); } } }
/// <summary> /// Saves the database. /// </summary> /// <param name="progress">The progress object.</param> /// <param name="eraseCommands">if set to <c>true</c> [erase commands].</param> public virtual void Save(IProgress progress, bool eraseCommands) { string dbPath = Path.GetDirectoryName(ProjectConfiguration.DatabasePath); string subPath = ProjectConfiguration.DatabasePath.Replace(dbPath + "\\", ""); ServerType serverType = AllLoaders.GetServerType(); try { BackupEngine.Instance.Start(SdeFiles.ServerDbPath); var dbs = _dbs.Values.ToList(); for (int i = 0; i < dbs.Count; i++) { var db = dbs[i]; db.WriteDb(dbPath, subPath, serverType); progress.Progress = AProgress.LimitProgress((i + 1f) / dbs.Count * 100f); } if (eraseCommands) { AllLoaders.UpdateStoredFiles(); Commands.ClearCommands(); _dbs.Values.ToList().ForEach(p => p.ClearCommands()); _dbs.Values.ToList().ForEach(p => p.BaseTable.ClearTupleStates()); } } catch (Exception err) { ErrorHandler.HandleException(err); } finally { BackupEngine.Instance.Stop(); } }
protected override void _loadDb() { Attached["NumberOfAttributesToGuess"] = 18; DbDebugItem <int> debug = new DbDebugItem <int>(this); if (debug.Load(ServerDbs.Skills)) { DbLoaderMethods.DbCommaLoader(debug, this); } if (debug.Load(ServerDbs.SkillsNoDex)) { DbLoaderMethods.DbCommaRange(debug, AttributeList, ServerSkillAttributes.Cast.Index, 2); } if (AllLoaders.GetServerType() == ServerType.RAthena) { if (debug.Load(ServerDbs.SkillsNoCast)) { DbLoaderMethods.DbCommaNoCast(debug, AttributeList, ServerSkillAttributes.Flag.Index, 1); } } if (debug.Load(ServerDbs.SkillsCast)) { DbLoaderMethods.DbCommaRange(debug, AttributeList, ServerSkillAttributes.Cast.Index + 2, 6); } }
public static void DbItemsCommaWriter <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db) { try { StringBuilder builder = new StringBuilder(); if (debug.FileType == FileType.Txt) { if (AllLoaders.GetServerType() == ServerType.RAthena) { DbIntCommaRange(debug, db, 0, ServerItemAttributes.OnUnequipScript.Index + 1); return; } DbItemsWriterSub(builder, db, db.Table.FastItems.OrderBy(p => p.GetKey <TKey>()), ServerType.RAthena); File.WriteAllText(debug.FilePath, builder.ToString(), Encoding.Default); } else if (debug.FileType == FileType.Conf) { builder.AppendLineUnix("item_db: ("); builder.Append(SqlParser.HerculesItemsDbTxtHeader); DbItemsWriterSub(builder, db, db.Table.FastItems, ServerType.Hercules); builder.AppendLineUnix(")"); File.WriteAllText(debug.FilePath, builder.ToString(), Encoding.Default); } else if (debug.FileType == FileType.Sql) { SqlParser.DbSqlItems(debug, db); } } catch (Exception err) { debug.ReportException(err); } }
public DisplayLabel() { FocusVisualStyle = null; Margin = new Thickness(-4, -4, 0, -4); Padding = new Thickness(0); FontSize = 12; MouseEnter += delegate { if (_dbSource != null) { ToolTip = AllLoaders.DetectPath(_dbSource); } if (ToolTip == null) { ToolTip = "File not found. This database will be disabled."; } }; SizeChanged += delegate { if (!_isLoaded) { Grid presenter = WpfUtilities.FindParentControl <Grid>(this); TextBox box = (TextBox)presenter.Children[2]; if (box.Text == "Visible") { Foreground = _stateBrush; } else { Foreground = _stateInactiveBrush; } box.TextChanged += delegate { if (box.Text == "Visible") { Foreground = _stateBrush; } else { Foreground = _stateInactiveBrush; } }; _isLoaded = true; } }; }
public static bool IsTabEnabled(GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb) { if (AllLoaders.DetectPath(settings.DbData) == null) { return(false); } if (gdb.Attached["IsEnabled"] != null && !(bool)gdb.Attached["IsEnabled"]) { return(false); } if (!Boolean.Parse(ProjectConfiguration.ConfigAsker["[Server database editor - Enabled state - " + settings.DbData.DisplayName + "]", true.ToString()])) { return(false); } return(true); }
private void _miSelectInNotepad_Click(object sender, RoutedEventArgs e) { try { TValue item = _listView.SelectedItem as TValue; if (item != null) { string displayId = item.GetValue <string>(Settings.AttId); string path; if ((path = AllLoaders.DetectPath(Settings.DbData)) != null) { string[] lines = File.ReadAllLines(path); string line = lines.FirstOrDefault(p => p.StartsWith(displayId + ",")); if (line == null) { line = lines.FirstOrDefault(p => p.StartsWith(displayId + "\t")); } if (line == null) { line = lines.FirstOrDefault(p => p.Contains("Id: " + displayId)); } if (line == null) { line = lines.FirstOrDefault(p => p.StartsWith(displayId)); } if (line != null) { GTabsMaker.SelectInNotepadpp(path, (lines.ToList().IndexOf(line) + 1).ToString(CultureInfo.InvariantCulture)); } } } } catch (Exception err) { ErrorHandler.HandleException(err); } }
public bool Load(ServerDbs dbSource) { DbSource = dbSource; string path = AllLoaders.DetectPath(DbSource); TextFileHelper.LatestFile = path; if (String.IsNullOrEmpty(path)) { if (_db.ThrowFileNotFoundException) { DbLoaderErrorHandler.Handle("File not found '" + DbSource + "'.", ErrorLevel.NotSpecified); } return(false); } FileType = AllLoaders.GetFileType(path); FilePath = path; AllLoaders.StoreFile(FilePath); return(true); }
/// <summary> /// Reloads the database. /// </summary> /// <param name="progress">The progress object.</param> public void Reload(IProgress progress) { OnPreviewReloaded(); Commands.ClearCommands(); AllLoaders.ClearStoredFiles(); var dbs = _dbs.Values.ToList(); for (int i = 0; i < dbs.Count; i++) { var db = dbs[i]; if (db.CanBeLoaded) { db.Clear(); db.LoadDb(); progress.Progress = (i + 1f) / dbs.Count * 100f; } } OnReloaded(); }
public bool Write(string dbPath, string subPath, ServerType serverType, FileType fileType = FileType.Detect) { SubPath = subPath; string filename = DbSource.Filename; DestinationServer = serverType; FileType = fileType; if ((fileType & FileType.Detect) == FileType.Detect) { if ((DbSource.SupportedFileType & FileType.Txt) == FileType.Txt) { FileType = FileType.Txt; } if ((DbSource.SupportedFileType & FileType.Conf) == FileType.Conf) { if (serverType == ServerType.Hercules) { FileType = FileType.Conf; filename = DbSource.AlternativeName ?? filename; } } if (FileType == FileType.Detect) { FileType = FileType.Error; } } if (FileType == FileType.Error) { return(false); } if ((DbSource.SupportedFileType & FileType) != FileType) { return(false); } string ext = "." + FileType.ToString().ToLower(); IsRenewal = false; if ((FileType & FileType.Sql) == FileType.Sql) { if (subPath == "re") { FilePath = GrfPath.Combine(dbPath, filename + "_re" + ext); } else { FilePath = GrfPath.Combine(dbPath, filename + ext); } } else { if (DbSource.UseSubPath) { if (subPath == "re") { IsRenewal = true; } FilePath = GrfPath.Combine(dbPath, subPath, filename + ext); } else { FilePath = GrfPath.Combine(dbPath, filename + ext); } } TextFileHelper.LatestFile = FilePath; string logicalPath = AllLoaders.DetectPath(DbSource); OldPath = AllLoaders.GetStoredFile(logicalPath); if (OldPath == null || !File.Exists(OldPath)) { return(false); } if (_db.Attached["IsEnabled"] != null && !(bool)_db.Attached["IsEnabled"]) { return(false); } GrfPath.CreateDirectoryFromFile(FilePath); if (!_db.Table.Commands.IsModified && logicalPath.IsExtension(FilePath.GetExtension())) { BackupEngine.Instance.Backup(logicalPath); _db.DbDirectCopy(this, _db); return(false); } BackupEngine.Instance.Backup(logicalPath); return(true); }
public static void SInit <TKey>(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb) { settings.Style = "TabItemStyledLess"; settings.ContextMenu = new ContextMenu(); var menuItem = new MenuItem { Header = "Select '" + settings.DbData.Filename.Replace("_", "__") + "' in explorer", Icon = new Image { Source = (BitmapSource)ApplicationManager.PreloadResourceImage("arrowdown.png") } }; menuItem.Click += delegate { if (settings.DbData != null) { try { string path = AllLoaders.DetectPath(settings.DbData); if (path != null) { OpeningService.FilesOrFolders(path); } else { ErrorHandler.HandleException("File not found."); } } catch (Exception err) { ErrorHandler.HandleException(err); } } else { ErrorHandler.HandleException("File not found."); } }; settings.ContextMenu.Items.Add(menuItem); settings.Loaded += _loaded; if (tab == null || gdb == null) { return; } if (gdb.AttributeList.Attributes.Any(p => p.IsSkippable)) { foreach (var attributeIntern in gdb.AttributeList.Attributes.Where(p => p.IsSkippable)) { var attribute = attributeIntern; var menuItemSkippable = new MenuItem { Header = attribute.DisplayName + " [" + attribute.AttributeName + ", " + attribute.Index + "]", Icon = new Image { Source = (BitmapSource)ApplicationManager.PreloadResourceImage("add.png") } }; menuItemSkippable.IsEnabled = false; menuItemSkippable.Click += delegate { gdb.Attached["EntireRewrite"] = true; gdb.Attached[attribute.DisplayName] = gdb.Attached[attribute.DisplayName] != null && !(bool)gdb.Attached[attribute.DisplayName]; gdb.To <TKey>().TabGenerator.OnTabVisualUpdate(tab, settings, gdb); }; settings.ContextMenu.Items.Add(menuItemSkippable); } gdb.Attached.CollectionChanged += delegate { int index = 2; foreach (var attributeIntern in gdb.AttributeList.Attributes.Where(p => p.IsSkippable)) { var attribute = attributeIntern; int index1 = index; settings.ContextMenu.Dispatch(delegate { var menuItemSkippable = (MenuItem)settings.ContextMenu.Items[index1]; menuItemSkippable.IsEnabled = true; bool isSet = gdb.Attached[attribute.DisplayName] == null || (bool)gdb.Attached[attribute.DisplayName]; menuItemSkippable.Icon = new Image { Source = (BitmapSource)ApplicationManager.PreloadResourceImage(isSet ? "delete.png" : "add.png") }; }); index++; } }; } }
public SdeEditor() : base("Server database editor", "cde.ico", SizeToContent.Manual, ResizeMode.CanResize) { SplashDialog loading = new SplashDialog(); loading.Show(); Loaded += delegate { loading.Terminate(); }; string configFile = _parseCommandLineArguments(); GrfPath.Delete(ProjectConfiguration.DefaultFileName); if (configFile == null) { ProjectConfiguration.ConfigAsker = new ConfigAsker(ProjectConfiguration.DefaultFileName); } else if (File.Exists(configFile)) { ProjectConfiguration.ConfigAsker = new ConfigAsker(configFile); } InitializeComponent(); ShowInTaskbar = true; _asyncOperation = new AsyncOperation(_progressBar); _clientDatabase = new GenericDatabase(_metaGrf); _loadMenu(); _loadSettingsTab(); if (configFile != null) { ReloadSettings(configFile); } _loadGenericTab(); _clientDatabase.Modified += new BaseGenericDatabase.ClientDatabaseEventHandler(_clientDatabase_Modified); _cbAssociate.Checked -= new RoutedEventHandler(_cbAssociate_Checked); _cbAssociate.IsChecked = (SdeAppConfiguration.FileShellAssociated & FileAssociation.Sde) == FileAssociation.Sde; _cbAssociate.Checked += new RoutedEventHandler(_cbAssociate_Checked); ApplicationShortcut.Link(ApplicationShortcut.Undo, () => _clientDatabase.Commands.Undo(), this); ApplicationShortcut.Link(ApplicationShortcut.UndoGlobal, () => _clientDatabase.Commands.Undo(), this); ApplicationShortcut.Link(ApplicationShortcut.Redo, () => _clientDatabase.Commands.Redo(), this); ApplicationShortcut.Link(ApplicationShortcut.RedoGlobal, () => _clientDatabase.Commands.Redo(), this); ApplicationShortcut.Link(ApplicationShortcut.Search, () => _execute(v => v.Search()), this); ApplicationShortcut.Link(ApplicationShortcut.Delete, () => _execute(v => v.DeleteItems()), this); ApplicationShortcut.Link(ApplicationShortcut.Rename, () => _execute(v => v.ChangeId()), this); ApplicationShortcut.Link(ApplicationShortcut.NavigationBackward, () => _tabEngine.Undo(), this); ApplicationShortcut.Link(ApplicationShortcut.NavigationBackward2, () => _tabEngine.Redo(), this); ApplicationShortcut.Link(ApplicationShortcut.NavigationForward, () => _tabEngine.Redo(), this); ApplicationShortcut.Link(ApplicationShortcut.Change, () => _execute(v => v.ChangeId()), this); ApplicationShortcut.Link(ApplicationShortcut.Restrict, () => _execute(v => v.ShowSelectedOnly()), this); ApplicationShortcut.Link(ApplicationShortcut.CopyTo, () => _execute(v => v.CopyItemTo()), this); ApplicationShortcut.Link(ApplicationShortcut.New, () => _execute(v => v.AddNewItem()), this); ApplicationShortcut.Link(ApplicationShortcut.Save, () => _menuItemDatabaseSave_Click(this, null), this); ApplicationShortcut.Link(ApplicationShortcut.SaveAll, () => _menuItemDatabaseSaveAll_Click(this, null), this); SdeAppConfiguration.Bind(_cbStackTrace, () => Configuration.EnableDebuggerTrace, v => { Configuration.EnableDebuggerTrace = v; SdeErrorHandler.ShowStackTraceViewer(); }); _tnbUndo.SetUndo(_tabEngine); _tnbRedo.SetRedo(_tabEngine); _tmbUndo.SetUndo(_clientDatabase.Commands); _tmbRedo.SetRedo(_clientDatabase.Commands); Extensions.GenerateListViewTemplate(_debugList, new ListViewDataTemplateHelper.GeneralColumnInfo[] { new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "#", DisplayExpression = "ErrorNumber", SearchGetAccessor = "ErrorNumber", FixedWidth = 35, ToolTipBinding = "ErrorNumber", TextAlignment = TextAlignment.Right }, new ListViewDataTemplateHelper.ImageColumnInfo { Header = "", DisplayExpression = "DataImage", SearchGetAccessor = "Exception", FixedWidth = 20, MaxHeight = 24 }, new ListViewDataTemplateHelper.RangeColumnInfo { Header = "Exception", DisplayExpression = "Exception", SearchGetAccessor = "Exception", IsFill = true, TextAlignment = TextAlignment.Left, ToolTipBinding = "OriginalException", TextWrapping = TextWrapping.Wrap, MinWidth = 120 }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Id", DisplayExpression = "Id", SearchGetAccessor = "Id", FixedWidth = 90, TextAlignment = TextAlignment.Left, ToolTipBinding = "Id", TextWrapping = TextWrapping.Wrap }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "File", DisplayExpression = "FileName", SearchGetAccessor = "FilePath", FixedWidth = 130, TextAlignment = TextAlignment.Left, ToolTipBinding = "FilePath", TextWrapping = TextWrapping.Wrap }, new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Line", DisplayExpression = "Line", SearchGetAccessor = "Line", FixedWidth = 40, TextAlignment = TextAlignment.Left, ToolTipBinding = "Line" }, }, null, new string[] { "Added", "Blue", "Default", "Black" }); ApplicationShortcut.Link(ApplicationShortcut.Copy, () => WpfUtils.CopyContent(_debugList), _debugList); _debugItems = new ObservableCollection <DebugItemView>(); _debugList.ItemsSource = _debugItems; DbLoaderErrorHandler.ClearListeners(); DbLoaderErrorHandler.AddListener(this); _clientDatabase.PreviewReloaded += delegate { this.BeginDispatch(delegate { foreach (TabItem tabItem in _mainTabControl.Items) { tabItem.IsEnabled = true; var tabItemHeader = tabItem.Header as DisplayLabel; if (tabItemHeader != null) { tabItemHeader.ResetEnabled(); } } }); }; _clientDatabase.Reloaded += delegate { _mainTabControl.Dispatch(p => p.RaiseEvent(new SelectionChangedEventArgs(Selector.SelectionChangedEvent, new List <object>(), _mainTabControl.SelectedItem == null ? new List <object>() : new List <object> { _mainTabControl.SelectedItem }))); ServerType serverType = AllLoaders.GetServerType(); bool renewal = AllLoaders.GetIsRenewal(); string header = String.Format("Current ({0} - {1})", serverType == ServerType.RAthena ? "rA" : "Herc", renewal ? "Renewal" : "Pre-Renewal"); this.BeginDispatch(delegate { _menuItemExportDbCurrent.IsEnabled = true; _menuItemExportDbCurrent.Header = header; _menuItemExportSqlCurrent.IsEnabled = true; _menuItemExportSqlCurrent.Header = header; }); }; }
private void _menuItemExportSqlCurrent_Click(object sender, RoutedEventArgs e) { _export(AllLoaders.GetServerType(), AllLoaders.GetIsRenewal() ? "re" : "pre-re", FileType.Sql); }
public static void DbItemGroupWriter2 <TKey>(ReadableTuple <TKey> item, ServerType destServer, StringBuilder builder, BaseDb db, List <string> aegisNames, List <string> names) { var itemCopy = new ReadableTuple <TKey>(item.GetKey <TKey>(), item.Attributes); itemCopy.Copy(item); item = itemCopy; int key = item.GetKey <int>(); if (destServer == ServerType.RAthena) { var itemDb = db.GetMeta <int>(ServerDbs.Items); ServerType source = AllLoaders.GetServerType(); if (source == ServerType.Hercules) { List <string> constantsList = Constants.Keys.ToList(); Table <int, ReadableTuple <int> > table = db.GetMeta <int>(ServerDbs.Items); var tuple = item; var res2 = table.TryGetTuple(key); if (res2 != null) { string name = res2.GetValue(ServerItemAttributes.AegisName).ToString(); int low = Int32.MaxValue; int index = -1; for (int j = 0; j < Constants.Count; j++) { int dist = Methods.LevenshteinDistance(name, constantsList[j]); if (dist < low) { low = dist; index = j; } } string closestString = constantsList[index]; int groupId = Constants[closestString]; tuple.SetRawValue(0, groupId); } } Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)item.GetRawValue(1); key = item.GetKey <int>(); 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); builder.AppendLine(key + "," + string.Join(",", items.ToArray()) + (dbTuple == null ? "" : "\t// " + dbTuple.GetValue(ServerItemAttributes.Name))); } builder.AppendLine(); } else if (destServer == ServerType.Hercules) { builder.AppendLine(ItemGroupParser.ToHerculesDbEntry(db, item.GetKey <int>(), aegisNames, names)); builder.AppendLine(); } }
public static void DbItemGroupWriter <TKey>(DbDebugItem <TKey> debug, AbstractDb <TKey> db) { try { if (debug.FileType == FileType.Txt) { string currentDirectory = Path.GetDirectoryName(debug.FilePath); string parentDirectory = Path.GetDirectoryName(currentDirectory); var itemDb = db.GetMeta <int>(ServerDbs.Items); ServerType source = AllLoaders.GetServerType(); using (StreamWriter writerPrimary = new StreamWriter(debug.FilePath)) { // currentDirectory = something\db\pre-re // parentDirectory = something\db // outmostDirectory = something if (source == ServerType.Hercules) { // This means we read the file from Hercules db.Attached["0"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_bluebox.txt", new HashSet <int> { 1 }); db.Attached["1"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_violetbox.txt", new HashSet <int> { 2 }); db.Attached["2"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_cardalbum.txt", new HashSet <int> { 3, 44 }); db.Attached["3"] = new Tuple <string, HashSet <int> >("db/item_findingore.txt", new HashSet <int> { 6 }); db.Attached["4"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_giftbox.txt", new HashSet <int> { 4, 28, 29, 30, 31, 34, 43 }); db.Attached["5"] = new Tuple <string, HashSet <int> >("db/" + debug.SubPath + "/item_misc.txt", new HashSet <int> { 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }); } List <Tuple <string, HashSet <int> > > loadedItems = db.Attached.Values.OfType <Tuple <string, HashSet <int> > >().OrderBy(p => p.Item2.Count).ToList(); List <ReadableTuple <TKey> > allTuples; if (source == ServerType.Hercules) { allTuples = db.Table.FastItems.Select(p => db.Table.Copy(p.GetKey <TKey>())).ToList(); List <string> constantsList = Constants.Keys.ToList(); Dictionary <int, int> matches = new Dictionary <int, int>(); Table <int, ReadableTuple <int> > table = db.GetMeta <int>(ServerDbs.Items); for (int i = 0; i < allTuples.Count; i++) { var tuple = allTuples[i]; int key = tuple.GetKey <int>(); if (matches.ContainsKey(key)) { tuple.SetRawValue(0, matches[key]); continue; } var res2 = table.TryGetTuple(key); if (res2 != null) { string name = res2.GetValue(ServerItemAttributes.AegisName).ToString(); string closestString = Methods.ClosestString(name, constantsList); int groupId = Constants[closestString]; matches[key] = groupId; tuple.SetRawValue(0, matches[key]); } else { debug.ReportException("Key not found : " + key); } } } else { allTuples = db.Table.FastItems; } for (int i = 0; i < loadedItems.Count; i++) { var tuple = loadedItems[i]; string importPath = tuple.Item1.Trim(' ', '\t'); string temp = Path.GetDirectoryName(importPath); string outputPath = ""; var set = tuple.Item2; int level = 0; while (!string.IsNullOrEmpty(temp)) { temp = Path.GetDirectoryName(temp); level++; } string internalPath = ""; if (level == 2) { outputPath = "db/" + debug.SubPath + "/" + Path.GetFileName(importPath); internalPath = debug.SubPath + "/" + Path.GetFileName(importPath); } else if (level == 1) { outputPath = "db/" + Path.GetFileName(importPath); internalPath = Path.GetFileName(importPath); } string filePath = GrfPath.Combine(parentDirectory, internalPath); GrfPath.CreateDirectoryFromFile(filePath); List <ReadableTuple <TKey> > tuples; if (i == loadedItems.Count - 1) { //outputeverything tuples = allTuples; } else { tuples = allTuples.Where(p => set.Contains(p.GetKey <int>())).ToList(); for (int j = 0; j < tuples.Count; j++) { allTuples.Remove(tuples[j]); } } using (StreamWriter writer = new StreamWriter(filePath)) { foreach (ReadableTuple <TKey> tup in tuples.OrderBy(p => p.GetKey <TKey>())) { Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)tup.GetRawValue(1); int key = tup.GetKey <int>(); 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(key + "," + string.Join(",", items.ToArray()) + (dbTuple == null ? "" : "\t// " + dbTuple.GetValue(ServerItemAttributes.Name))); } writer.WriteLine(); } } writerPrimary.WriteLine("import: " + outputPath); } } } 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.GetKey <int>()).OrderBy(p => p)) { builder.AppendLine(ItemGroupParser.ToHerculesDbEntry(db, id, aegisNames, names)); builder.AppendLine(); } File.WriteAllText(debug.FilePath, builder.ToString(), Encoding.Default); } } catch (Exception err) { debug.ReportException(err); } }
public static void DbItemsWriterSub <TKey>(StringBuilder builder, AbstractDb <TKey> db, IEnumerable <ReadableTuple <TKey> > tuples, ServerType to) { if (to == ServerType.RAthena) { bool fromTxtDb = AllLoaders.DetectPath(db.DbSource).IsExtension(".txt"); foreach (ReadableTuple <TKey> tuple in tuples) { List <string> rawElements = tuple.GetRawElements().Take(22).Select(p => p.ToString()).ToList(); if (tuple.Normal && fromTxtDb) { builder.AppendLine(string.Join(",", rawElements.ToArray())); continue; } string script1 = tuple.GetValue <string>(19); string script2 = tuple.GetValue <string>(20); string script3 = tuple.GetValue <string>(21); string refine = tuple.GetValue <string>(17); if (refine == "") { refine = ""; } else if (refine == "true" || refine == "1") { refine = "1"; } else { refine = "0"; } builder.AppendLine(string.Join(",", new string[] { rawElements[0], rawElements[1], rawElements[2], _outputInteger(rawElements[3]), // Type _zeroDefault(rawElements[4]), _zeroDefault(rawElements[5]), String.IsNullOrEmpty(rawElements[6]) ? "0" : rawElements[6], _zeroDefault(rawElements[7]), _zeroDefault(rawElements[8]), _zeroDefault(rawElements[9]), _zeroDefault(rawElements[10]), // Slots String.IsNullOrEmpty(rawElements[11]) ? "0xFFFFFFFF" : !rawElements[11].StartsWith("0x") ? "0x" + Int32.Parse(rawElements[11]).ToString("X8") : rawElements[11], _hexToInt(rawElements[12]), // Upper _zeroDefault(rawElements[13]), _zeroDefault(_hexToInt(rawElements[14])), _zeroDefault(rawElements[15]), _zeroDefault(rawElements[16]), refine, _zeroDefault(rawElements[18]), String.IsNullOrEmpty(script1) ? "{}" : "{ " + script1 + " }", String.IsNullOrEmpty(script2) ? "{}" : "{ " + script2 + " }", String.IsNullOrEmpty(script3) ? "{}" : "{ " + script3 + " }" })); } } else if (to == ServerType.Hercules) { foreach (int id in tuples.Select(p => p.GetKey <int>()).OrderBy(p => p)) { builder.AppendLineUnix(ItemParser.ToHerculesEntry(db, id)); } } }