private Mutable(WarbendService warbend, Mutable parent, int index, string name, string path, string typeName, string label, int mutableCount) { this.warbend = warbend; Parent = parent; Index = index; Name = name; Path = path; TypeName = typeName; Label = label; MutableCount = mutableCount; IsArray = typeName?.Contains("array(") == true; mutables[path] = new WeakReference(this); Invalidate(); }
public MutableTreeNode(TreeView treeView, Mutable mutable) { Mutable = mutable; ToolTipText = mutable.TypeName; ImageKey = SelectedImageKey = treeView.ImageList.Images.ContainsKey(mutable.TypeName) ? mutable.TypeName : mutable.IsArray ? "array" : "record"; if (mutable.MutableCount > 0) { Nodes.Add(new LoadingTreeNode(treeView, this)); } ComputeText(); Settings.Default.PropertyChanged += Settings_PropertyChanged; }
public async Task LoadAsync(string fileName, string format = "binary") { foreach (var form in OwnedForms) { if (form is PropertyGridForm) { form.Close(); } } selection.Clear(); EnableUI(false); bool loaded = false; try { Text = Path.GetFileName(fileName) + " - " + initialTitle; treeView.BeginUpdate(); treeView.Nodes.Clear(); try { await warbend.LoadAsync(fileName, format); } catch (WarbendOperationException ex) { var msg = $"Error loading \"{fileName}\":\r\n\r\n{ex.Message}"; MessageBox.Show(this, msg, null, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } loaded = true; var game = new Mutable(warbend); var rootNode = new MutableTreeNode(treeView, game); treeView.Nodes.Add(rootNode); treeView.EndUpdate(); rootNode.Expand(); } catch (WarbendShuttingDownException) { loaded = false; } finally { EnableUI(true); if (!loaded) { Text = initialTitle; } } }
IEnumerable <Child> FetchChildren() { var isRecord = IsRecord; var items = warbend.FetchAsync(Path).GetAwaiter().GetResult(); int index = 0; foreach (JObject item in items) { var prop = item.Properties().First(); var name = prop.Name; if (name == "") { name = null; } var info = (JObject)prop.Value; var typeName = info.Value <string>("type"); object value; TypeConverter converter = null; if (info.Value <string>("path") is string path) { var label = info.Value <string>("name"); var mutableCount = info.Value <int>("mutableCount"); value = new Mutable(warbend, this, index, name, path, typeName, label, mutableCount); } else { Type type = null; if ((info.Value <JObject>("enum") ?? info.Value <JObject>("flags")) is JObject nameObj) { var baseTypeName = info.Value <string>("baseType"); type = types[baseTypeName]; var names = nameObj.Properties().ToDictionary( p => p.Name, p => Convert.ChangeType(p.Value.Value <string>(), type, CultureInfo.InvariantCulture)); if (info.ContainsKey("flags")) { converter = new FlagsTypeConverter(type, names); } else { converter = new EnumTypeConverter(type, names); } } else if (info.Value <string>("refPath") is string refPath) { var baseTypeName = info.Value <string>("baseType"); type = types[baseTypeName]; converter = new IdRefTypeConverter(warbend, type, refPath); } type = type ?? types[typeName]; var sval = info.Value <string>("value"); if (type == typeof(bool)) { value = sval != "0"; } else if (type == typeof(Color)) { value = Color.FromArgb((int)uint.Parse(sval)); } else { value = ((IConvertible)sval).ToType(type, CultureInfo.InvariantCulture); } } yield return(new Child(index, name, value, converter)); if (name != null) { namedChildren.Add(name, index); } ++index; } }
public ObjectPath this[Mutable parent, object selector] => new ObjectPath(parent, selector);
public ObjectPath(Mutable parent, object selector) { Parent = parent; Selector = selector; }