public static void ItemGroupCopyEntries(List <ReadableTuple <int> > items, BaseDb gdb, TabControl control, ServerType serverType) { var parent = WpfUtilities.FindDirectParentControl <SdeEditor>(control); parent.AsyncOperation.SetAndRunOperation(new GrfThread(delegate { items = items.OrderBy(p => p.GetKey <int>()).ToList(); StringBuilder builder = new StringBuilder(); try { AProgress.Init(parent); DbLoaderErrorHandler.Start(); var dbItems = gdb.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(); for (int i = 0; i < items.Count; i++) { AProgress.IsCancelling(parent); DbWriterMethods.DbItemGroupWriter2(items[i], serverType, builder, gdb, aegisNames, names); parent.Progress = (i + 1f) / items.Count * 100f; } } catch (OperationCanceledException) { } finally { AProgress.Finalize(parent); DbLoaderErrorHandler.Stop(); } Clipboard.SetText(builder.ToString()); }, parent, 200, null, true, true)); }
public bool ReportException(Exception item) { DbLoaderErrorHandler.HandleLoader(item.Message); NumberOfErrors--; if (NumberOfErrors < 0) { DbLoaderErrorHandler.Handle("Failed to read too many items, the db will stop loading.", ErrorLevel.Critical); return(false); } return(true); }
public bool ReportException(string item) { DbLoaderErrorHandler.Handle(item); NumberOfErrors--; if (NumberOfErrors < 0) { DbLoaderErrorHandler.Handle("Failed to read too many items, the db [" + DbSource + "] will stop loading.", ErrorLevel.Critical); return(false); } return(true); }
public bool ReportIdExceptionWithError(string exception, object item) { DbLoaderErrorHandler.Handle(exception, item.ToString()); NumberOfErrors--; if (NumberOfErrors < 0) { DbLoaderErrorHandler.Handle("Failed to read too many items, the db [" + DbSource + "] will stop loading.", ErrorLevel.Critical); return(false); } return(true); }
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); }
private void _addCustomTables() { foreach (string file in ProjectConfiguration.CustomTabs) { if (File.Exists(file)) { DbMaker maker = new DbMaker(file); if (maker.Init(_holder)) { this.Dispatch(() => maker.Add(_mainTabControl, _holder, _tabEngine, this)); } else { DbLoaderErrorHandler.Handle("Unable to parse the table for the file '" + file + "'."); } } else { DbLoaderErrorHandler.Handle("Couldn't find the file '" + file + "'."); } } }
private static void _trySetIfRefineable(ReadableTuple <int> tuple, StringBuilder builder, DbAttribute attribute, bool defaultValue) { int type = tuple.GetValue <int>(ServerItemAttributes.Type); bool val = tuple.GetValue <bool>(attribute); if (type != 4 && type != 5) { if (val) { // This is not supposed to be allowed, but... we'll let it slide DbLoaderErrorHandler.Handle("The refineable status on the item ID [" + tuple.GetKey <int>() + "] has been set to true but the item type is not an equipment. This is suspicious.", ErrorLevel.Warning); builder.AppendLineUnix("\t" + attribute.AttributeName + ": true"); } return; } if (val != defaultValue) { builder.Append("\t"); builder.Append(attribute.AttributeName); builder.Append(": "); builder.AppendLineUnix(val.ToString().ToLower()); } }
public override void SetValue(DbAttribute attribute, object value) { bool sameValue; try { sameValue = GetValue(attribute.Index).ToString() == value.ToString(); } catch { sameValue = false; } try { base.SetValue(attribute, value); } catch { DbLoaderErrorHandler.Handle(("Failed to set or parse the value for [" + GetKey <TKey>() + "] at '" + attribute.DisplayName + "'. Value entered is : " + (value ?? "")).RemoveBreakLines(), ErrorLevel.NotSpecified); base.SetValue(attribute, attribute.Default); } if (!sameValue) { Modified = true; } }
/// <summary> /// Converts a group from an ItemGroup to a Hercules entry /// </summary> /// <param name="gdb">The base db.</param> /// <param name="groupId">The group id.</param> /// <param name="aegisNames">The aegis names.</param> /// <param name="names">The names.</param> /// <returns>A string for an ItemGroup entry converted to Hercules's format</returns> public static string ToHerculesDbEntry(BaseDb gdb, int groupId, List <string> aegisNames, List <string> names) { StringBuilder builder = new StringBuilder(); var dbItems = gdb.GetMeta <int>(ServerDbs.Items); var dbGroups = gdb.Get <int>(ServerDbs.ItemGroups); if (groupId < 500) { var dbConstants = gdb.Get <string>(ServerDbs.Constants); string sId = groupId.ToString(CultureInfo.InvariantCulture); // The current db is from rAthena var tuple = dbConstants.FastItems.FirstOrDefault(p => p.GetValue <string>(1) == sId && p.GetKey <string>().StartsWith("IG_")); string constant = null; if (tuple != null) { constant = tuple.GetKey <string>().Substring(3); } else { var res = DbWriterMethods.Constants.Where(p => p.Value == groupId).ToList(); if (res.Count > 0) { constant = res[0].Key; } } if (constant != null) { string originalConstantValue = constant; ReadableTuple <int> tupleItem; // Attempts to retrieve the item based on the script tupleItem = dbItems.FastItems.FirstOrDefault(p => p.GetValue <string>(ServerItemAttributes.Script).IndexOf("getrandgroupitem(IG_" + originalConstantValue + ")", StringComparison.OrdinalIgnoreCase) > -1); if (tupleItem == null) { // Attempts to retrieve the item based on a formatted constant name (with underscore) StringBuilder temp = new StringBuilder(); temp.Append(constant[0]); for (int i = 1; i < constant.Length; i++) { if (constant[i] == '_') { i++; if (i < constant.Length) { temp.Append(constant[i]); } } else if (char.IsUpper(constant[i])) { temp.Append('_'); temp.Append(constant[i]); } else { temp.Append(constant[i]); } } constant = temp.ToString(); // Attempts to retrieve the item with the Old prefix string oldConstant = "Old_" + constant; // Attempts to retrieve the item without the Old prefix tupleItem = dbItems.FastItems.FirstOrDefault(p => p.GetStringValue(ServerItemAttributes.AegisName.Index) == oldConstant); if (tupleItem == null) { tupleItem = dbItems.FastItems.FirstOrDefault(p => p.GetStringValue(ServerItemAttributes.AegisName.Index) == constant); } } // Retrieve the closest item based on the names in the ItemDb. // It uses the Levenshtein distance algorithm to find the clostest match. // This method 'always' returns a value, but a warning is prompted to the user in the error console. if (tupleItem == null) { List <string> values1 = aegisNames; List <string> values2 = names; string closestMatch1 = Methods.ClosestString(originalConstantValue, values1); string closestMatch2 = Methods.ClosestString(originalConstantValue, values2); int lev1 = Methods.LevenshteinDistance(originalConstantValue, closestMatch1); int lev2 = Methods.LevenshteinDistance(originalConstantValue, closestMatch2); tupleItem = dbItems.FastItems[lev1 < lev2 ? values1.IndexOf(closestMatch1) : values2.IndexOf(closestMatch2)]; string closestMatch = tupleItem.GetValue <string>(ServerItemAttributes.AegisName); if (Math.Min(lev1, lev2) != 0 && closestMatch.Replace("_", "") != constant) { DbLoaderErrorHandler.Handle("A suspicious conversion occurred for the item [" + originalConstantValue + "]. The group item name is [" + tupleItem.GetValue <string>(ServerItemAttributes.AegisName) + "]."); } } builder.AppendLine(tupleItem.GetValue <string>(ServerItemAttributes.AegisName) + ": ("); Dictionary <int, ReadableTuple <int> > table = (Dictionary <int, ReadableTuple <int> >)dbGroups.GetTuple(groupId).GetRawValue(ServerItemGroupAttributes.Table.Index); foreach (var pair in table) { tupleItem = dbItems.TryGetTuple(pair.Key); string name = tupleItem == null ? "ID" + pair.Key : tupleItem.GetValue <string>(ServerItemAttributes.AegisName); if (pair.Value.GetValue <string>(ServerItemGroupSubAttributes.Rate) == "1") { builder.Append("\t\""); builder.Append(name); builder.AppendLine("\","); } else { builder.Append("\t(\""); builder.Append(name); builder.Append("\","); builder.Append(pair.Value.GetValue <string>(ServerItemGroupSubAttributes.Rate)); builder.AppendLine("),"); } } builder.Append(")"); } else { DbLoaderErrorHandler.Handle("Failed to find the constant name with the id [" + sId + "]."); } } else { // The current db is from Hercules var tuple = dbItems.TryGetTuple(groupId); if (tuple != null) { builder.AppendLine(tuple.GetValue <string>(ServerItemAttributes.AegisName) + ": ("); Dictionary <int, ReadableTuple <int> > table = (Dictionary <int, ReadableTuple <int> >)dbGroups.GetTuple(groupId).GetRawValue(ServerItemGroupAttributes.Table.Index); foreach (var pair in table) { tuple = dbItems.TryGetTuple(pair.Key); string name = tuple == null ? "ID" + pair.Key : tuple.GetValue <string>(ServerItemAttributes.AegisName); if (pair.Value.GetValue <string>(ServerItemGroupSubAttributes.Rate) == "1") { builder.Append("\t\""); builder.Append(name); builder.AppendLine("\","); } else { builder.Append("\t(\""); builder.Append(name); builder.Append("\","); builder.Append(pair.Value.GetValue <string>(ServerItemGroupSubAttributes.Rate)); builder.AppendLine("),"); } } builder.Append(")"); } else { DbLoaderErrorHandler.Handle("Failed to retrieve the item ID associated with the group ID.", groupId.ToString(CultureInfo.InvariantCulture), ErrorLevel.Critical); } } return(builder.ToString()); }
public void ReportIdException(string exception, object item, ErrorLevel errorLevel = ErrorLevel.Warning) { DbLoaderErrorHandler.Handle(exception, item.ToString(), errorLevel); }
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; }); }; }