public static void CheckAttributeRestrictions <TKey>(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, GTabSettings <TKey, ReadableTuple <TKey> > settings, BaseDb gdb) { foreach (var attributeS in settings.AttributeList.Attributes) { DbAttribute attribute = attributeS; if (attribute.Requirements.Renewal == RenewalType.Both && attribute.Requirements.Server == ServerType.Both) { continue; } tab.PropertiesGrid.Dispatch(delegate { var gridAttributes = GetAll(tab.PropertiesGrid, attribute); RenewalType rType = DbPathLocator.GetIsRenewal() ? RenewalType.Renewal : RenewalType.PreRenewal; ServerType sType = DbPathLocator.GetServerType(); gridAttributes.ForEach(p => p.IsEnabled = false); if ((attribute.Requirements.Renewal & rType) == rType && (attribute.Requirements.Server & sType) == sType) { gridAttributes.ForEach(p => p.IsEnabled = true); } else { gridAttributes.ForEach(p => p.IsEnabled = false); } }); } }
public void Show(ServerType serverType, bool?renewal, params DbAttribute[] attributes) { bool enable = DbPathLocator.GetServerType() == serverType; if (renewal == null || renewal.Value == DbPathLocator.GetIsRenewal()) { Show(enable, attributes); } }
private static ServerType _convertServerType(string type) { ServerType sType = (ServerType)Enum.Parse(typeof(ServerType), type); if (sType == ServerType.Unknown) { sType = DbPathLocator.GetServerType(); } return(sType); }
/// <summary> /// Saves the database. /// </summary> /// <param name="ap">The progress object.</param> /// <param name="progress"> </param> public virtual void Save(AsyncOperation ap, IProgress progress) { string dbPath = GrfPath.GetDirectoryName(ProjectConfiguration.DatabasePath); string subPath = ProjectConfiguration.DatabasePath.Replace(dbPath, "").TrimStart('\\', '/'); ServerType serverType = DbPathLocator.GetServerType(); DbDebugHelper.OnUpdate("Saving tables."); MetaGrf.Clear(); try { BackupEngine.Instance.Start(ProjectConfiguration.DatabasePath); var dbs = _dbs.Values.ToList(); IOHelper.SetupFileManager(); for (int i = 0; i < dbs.Count; i++) { var db = dbs[i]; db.WriteDb(dbPath, subPath, serverType); if (progress != null) { progress.Progress = AProgress.LimitProgress((i + 1f) / dbs.Count * 100f); } } foreach (var db in dbs) { db.SaveCommandIndex(); } Commands.SaveCommandIndex(); } catch (Exception err) { ErrorHandler.HandleException(err); } finally { if (ap != null && progress != null) { progress.Progress = ap.ProgressBar.GetIntermediateState("Backup manager"); } BackupEngine.Instance.Stop(); DbDebugHelper.OnUpdate("Finished saving tables."); } }
public static void DbItemsWriter(DbDebugItem <int> debug, AbstractDb <int> db) { try { StringBuilder builder = new StringBuilder(); if (debug.FileType == FileType.Txt) { if (DbPathLocator.GetServerType() == ServerType.RAthena) { DbIOMethods.DbWriterComma(debug, db, 0, ServerItemAttributes.OnUnequipScript.Index + 1, (tuple, items) => { if (db.ProjectDatabase.IsRenewal) { string value = tuple.GetValue <string>(ServerItemAttributes.Matk) ?? ""; if (value == "" || value == "0") { return; } string atk = items[ServerItemAttributes.Attack.Index].ToString(); items[ServerItemAttributes.Attack.Index] = (atk == "" ? "0" : atk) + ":" + value; } }); return; } DbItemsWriterSub(builder, db, db.Table.FastItems.OrderBy(p => p.GetKey <int>()), ServerType.RAthena); FtpHelper.WriteAllText(debug.FilePath, builder.ToString()); } else if (debug.FileType == FileType.Conf) { DbIOMethods.DbIOWriterConf(debug, db, (r, q) => WriteEntry(db, r, q)); } else if (debug.FileType == FileType.Sql) { SqlParser.DbSqlItems(debug, db); } } catch (Exception err) { debug.ReportException(err); } }
public SdeEditor() : base("Server database editor", "cde.ico", SizeToContent.Manual, ResizeMode.CanResize) { SplashDialog loading = new SplashDialog(); loading.Show(); Loaded += delegate { loading.Terminate(); }; try { ApplicationShortcut.OverrideBindings(SdeAppConfiguration.Remapper); } catch (Exception err) { SdeAppConfiguration.Remapper.Clear(); ApplicationShortcut.OverrideBindings(SdeAppConfiguration.Remapper); ErrorHandler.HandleException("Failed to load the custom key bindings. The bindings will be reset to their default values.", err); } string configFile = _parseCommandLineArguments(); GrfPath.Delete(ProjectConfiguration.DefaultFileName); InitializeComponent(); Instance = this; ShowInTaskbar = true; _asyncOperation = new AsyncOperation(_progressBar); _clientDatabase = new SdeDatabase(_metaGrf); _loadMenu(); if (configFile == null) { ProjectConfiguration.ConfigAsker = new ConfigAsker(ProjectConfiguration.DefaultFileName); if (SdeAppConfiguration.AlwaysReopenLatestProject) { if (_recentFilesManager.Files.Count > 0 && File.Exists(_recentFilesManager.Files[0])) { ProjectConfiguration.ConfigAsker = new ConfigAsker(configFile = _recentFilesManager.Files[0]); } } } else if (File.Exists(configFile)) { ProjectConfiguration.ConfigAsker = new ConfigAsker(configFile); } _loadSettingsTab(); if (configFile != null) { ReloadSettings(configFile); } _loadGenericTab(); _clientDatabase.Commands.ModifiedStateChanged += new AbstractCommand <IGenericDbCommand> .AbstractCommandsEventHandler(_commands_ModifiedStateChanged); 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.Replace, () => { if (_menuItemReplaceAll.IsEnabled) { _menuItemReplaceAll_Click(this, null); } }, this); ApplicationShortcut.Link(ApplicationShortcut.FromString("Ctrl-Enter", "Select next entry"), () => _execute(v => v.SelectNext()), this); ApplicationShortcut.Link(ApplicationShortcut.FromString("Ctrl-Shift-Enter", "Select previous entry"), () => _execute(v => v.SelectPrevious()), this); Configuration.EnableDebuggerTrace = false; _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 = 145, 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; DbIOErrorHandler.ClearListeners(); DbIOErrorHandler.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 = DbPathLocator.GetServerType(); bool renewal = DbPathLocator.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; }); }; SelectionChanged += _sdeEditor_SelectionChanged; }
public static void Writer2 <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 = DbPathLocator.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(); } }
private void _menuItemExportSqlCurrent_Click(object sender, RoutedEventArgs e) { _export(DbPathLocator.GetServerType(), DbPathLocator.GetIsRenewal() ? "re" : "pre-re", FileType.Sql); }
public GenericFlagDialog(DbAttribute attribute, string text, Type enumType, FlagTypeData flagTypeData, string description) : base(description, "cde.ico", SizeToContent.WidthAndHeight, ResizeMode.CanResize) { InitializeComponent(); _value = text.ToLong(); if (flagTypeData != null) { List <long> valuesEnum = flagTypeData.Values.Where(p => (p.DataFlag & FlagDataProperty.Hide) == 0).Select(p => p.Value).ToList(); var values = flagTypeData.Values.Where(p => (p.DataFlag & FlagDataProperty.Hide) == 0).ToList(); GridIndexProvider provider = _findGrid(values); var toolTips = new string[values.Count]; for (int i = 0; i < values.Count; i++) { toolTips[i] = _getTooltip(values[i].Description); } AbstractProvider iProvider = new DefaultIndexProvider(0, values.Count); ToolTipsBuilder.Initialize(toolTips, this); int row; int col; for (int i = 0; i < values.Count; i++) { provider.Next(out row, out col); int index = (int)iProvider.Next(); CheckBox box = new CheckBox { Content = values[index].Name, Margin = new Thickness(3, 6, 3, 6), VerticalAlignment = VerticalAlignment.Center }; var menu = new ContextMenu(); MenuItem item = new MenuItem(); item.Header = "Restrict search to [" + values[index].Name + "]"; box.ContextMenu = menu; menu.Items.Add(item); item.Click += delegate { var selected = SdeEditor.Instance.Tabs.FirstOrDefault(p => p.IsSelected); if (selected != null) { selected._dbSearchPanel._searchTextBox.Text = "([" + attribute.AttributeName + "] & " + "Flags." + values[index].Name + ") != 0"; } }; box.Tag = valuesEnum[index]; WpfUtils.AddMouseInOutEffectsBox(box); _boxes.Add(box); _upperGrid.Children.Add(box); WpfUtilities.SetGridPosition(box, row, 2 * col); } _boxes.ForEach(_addEvents); } else { if (enumType.BaseType != typeof(Enum)) { throw new Exception("Invalid argument type, excepted an enum."); } if (enumType == typeof(MobModeType)) { if (DbPathLocator.GetServerType() == ServerType.RAthena && !ProjectConfiguration.UseOldRAthenaMode) { enumType = typeof(MobModeTypeNew); } } List <long> valuesEnum = Enum.GetValues(enumType).Cast <int>().Select(p => (long)p).ToList(); var values = Enum.GetValues(enumType).Cast <Enum>().ToList(); string[] commands = Description.GetAnyDescription(enumType).Split('#'); if (commands.Any(p => p.StartsWith("max_col_width:"))) { _maxColWidth = Int32.Parse(commands.First(p => p.StartsWith("max_col_width")).Split(':')[1]); } GridIndexProvider provider = _findGrid(values); var toolTips = new string[values.Count]; if (!commands.Contains("disable_tooltips")) { for (int i = 0; i < values.Count; i++) { toolTips[i] = _getTooltip(Description.GetDescription(values[i])); } } AbstractProvider iProvider = new DefaultIndexProvider(0, values.Count); if (commands.Any(p => p.StartsWith("order:"))) { List <int> order = commands.First(p => p.StartsWith("order:")).Split(':')[1].Split(',').Select(Int32.Parse).ToList(); for (int i = 0; i < values.Count; i++) { if (!order.Contains(i)) { order.Add(i); } } iProvider = new SpecifiedIndexProvider(order); } ToolTipsBuilder.Initialize(toolTips, this); int row; int col; ServerType currentType = DbPathLocator.GetServerType(); for (int i = 0; i < values.Count; i++) { provider.Next(out row, out col); int index = (int)iProvider.Next(); CheckBox box = new CheckBox { Content = _getDisplay(Description.GetDescription(values[index])), Margin = new Thickness(3, 6, 3, 6), VerticalAlignment = VerticalAlignment.Center }; ServerType type = _getEmuRestrition(Description.GetDescription(values[index])); if ((type & currentType) != currentType) { box.IsEnabled = false; } var menu = new ContextMenu(); MenuItem item = new MenuItem(); item.Header = "Restrict search to [" + _getDisplay(Description.GetDescription(values[index])) + "]"; box.ContextMenu = menu; menu.Items.Add(item); item.Click += delegate { var selected = SdeEditor.Instance.Tabs.FirstOrDefault(p => p.IsSelected); if (selected != null) { selected._dbSearchPanel._searchTextBox.Text = "([" + attribute.AttributeName + "] & " + valuesEnum[index] + ") != 0"; } }; box.Tag = valuesEnum[index]; WpfUtils.AddMouseInOutEffectsBox(box); _boxes.Add(box); _upperGrid.Children.Add(box); WpfUtilities.SetGridPosition(box, row, 2 * col); } _boxes.ForEach(_addEvents); } }
public GenericFlagDialog(string text, Type enumType) : base(_getDisplay(Description.GetAnyDescription(enumType)), "cde.ico", SizeToContent.WidthAndHeight, ResizeMode.CanResize) { InitializeComponent(); _value = text.ToInt(); if (enumType.BaseType != typeof(Enum)) { throw new Exception("Invalid argument type, excepted an enum."); } if (enumType == typeof(MobModeType)) { if (DbPathLocator.GetServerType() == ServerType.RAthena && !ProjectConfiguration.UseOldRAthenaMode) { enumType = typeof(MobModeTypeNew); } } var values = Enum.GetValues(enumType).Cast <Enum>().ToList(); var valuesEnum = Enum.GetValues(enumType).Cast <int>().ToList(); string[] commands = Description.GetAnyDescription(enumType).Split('#'); if (commands.Any(p => p.StartsWith("max_col_width:"))) { _maxColWidth = Int32.Parse(commands.First(p => p.StartsWith("max_col_width")).Split(':')[1]); } GridIndexProvider provider = _findGrid(values); var toolTips = new string[values.Count]; if (!commands.Contains("disable_tooltips")) { for (int i = 0; i < values.Count; i++) { toolTips[i] = _getTooltip(Description.GetDescription(values[i])); } } AbstractProvider iProvider = new DefaultIndexProvider(0, values.Count); if (commands.Any(p => p.StartsWith("order:"))) { List <int> order = commands.First(p => p.StartsWith("order:")).Split(':')[1].Split(',').Select(Int32.Parse).ToList(); for (int i = 0; i < values.Count; i++) { if (!order.Contains(i)) { order.Add(i); } } iProvider = new SpecifiedIndexProvider(order); } ToolTipsBuilder.Initialize(toolTips, this); int row; int col; ServerType currentType = DbPathLocator.GetServerType(); for (int i = 0; i < values.Count; i++) { provider.Next(out row, out col); int index = (int)iProvider.Next(); CheckBox box = new CheckBox { Content = _getDisplay(Description.GetDescription(values[index])), Margin = new Thickness(3, 6, 3, 6), VerticalAlignment = VerticalAlignment.Center }; ServerType type = _getEmuRestrition(Description.GetDescription(values[index])); if ((type & currentType) != currentType) { box.IsEnabled = false; } box.Tag = valuesEnum[index]; WpfUtils.AddMouseInOutEffectsBox(box); _boxes.Add(box); _upperGrid.Children.Add(box); WpfUtilities.SetGridPosition(box, row, 2 * col); } _boxes.ForEach(_addEvents); }