TreeNode AddNodeToNode(string Name, VDFData parentVDFDataStructure, TreeNodeVDFTag treeNodeTag, TreeNode nodeSelected) { TreeNode newTreeNode; if (treeNodeTag.TagType == TreeNodeVDFTag.Type.Node) //If we have the node itself selected on our Treeview, we just need to call the AddNodeToNode method directly. { newTreeNode = AddNodeToNode(Name, nodeSelected, parentVDFDataStructure, treeNodeTag.Token as VDFNode); } else { //We will need to retrieve the parent of this key for this one if the key is the one that is selected. if (nodeSelected.Parent == null) //Make sure that the parent of the TreeNode is set to another TreeNode { throw new NullReferenceException("TreeNode " + nodeSelected.Text + " parent property is not set!"); } VDFKey selectedKey = treeNodeTag.Token as VDFKey; //Cast our token to key first. if (selectedKey.Parent == null) { throw new NullReferenceException("Parent property of key " + selectedKey.Name + " is not set!"); } VDFNode parentNode = selectedKey.Parent; newTreeNode = AddNodeToNode(Name, nodeSelected.Parent, vdfData, parentNode); } return(newTreeNode); }
TreeNode CreateNewKey(string Name, string Value, TreeNodeVDFTag treeNodeTag, TreeNode nodeSelected) { TreeNode newTreeNode; if (treeNodeTag.TagType == TreeNodeVDFTag.Type.Node) //If the tag type of our selected tree node is a VDFNode. Then it's quite easy to create a new key for us. Just need to call the CreateNewKey method. { newTreeNode = CreateNewKey(Name, Value, treeNodeTag.Token as VDFNode, nodeSelected); } else { //We will need to retrieve the parent of this key for this one if the key is the one that is selected. if (nodeSelected.Parent == null) //Make sure that the parent of the TreeNode is set to another TreeNode { throw new NullReferenceException("TreeNode " + nodeSelected.Text + " parent property is not set!"); } VDFKey selectedKey = treeNodeTag.Token as VDFKey; //Cast our token to key first. if (selectedKey.Parent == null) { throw new NullReferenceException("Parent property of key " + selectedKey.Name + " is not set!"); } VDFNode parentNode = selectedKey.Parent; newTreeNode = CreateNewKey(Name, Value, parentNode, nodeSelected.Parent); } return(newTreeNode); }
void DeleteVDFKey(VDFKey keyToDelete, TreeNode treeNodeToDelete) { if (keyToDelete.Parent == null) { throw new NullReferenceException("Parent property of Key " + keyToDelete.Name + " is not set!"); } keyToDelete.RemoveKeyFromNode(); treeNodeToDelete.Parent.Nodes.Remove(treeNodeToDelete); }
void LoadVDFKeyToTreeView(VDFKey key, TreeNode parent) { if (parent == null) //Key must have a parent node. Throw an error if parent is set to null. { throw new ArgumentNullException("parent argument cannot be null!"); } TreeNode newTreeNode = new TreeNode(key.Name); newTreeNode.Tag = new TreeNodeVDFTag(TreeNodeVDFTag.Type.Key, key); parent.Nodes.Add(newTreeNode); }
void UpdateKeyInfo(string Name, string Value, VDFKey keyToUpdate, TreeNode treeNodeToUpdate) { if (Name != keyToUpdate.Name) //To prevent initializing a new string. Check if Name is just the same as the one on the node. { keyToUpdate.Name = Name; treeNodeToUpdate.Text = Name; } if (Value != keyToUpdate.Value) //Check if the value string is just the same on the VDFKey instance. { keyToUpdate.Value = Value; } }
TreeNode CreateNewKey(string Name, string Value, VDFNode parent, TreeNode parentTreeNode) { if (parent.Keys == null) { throw new NullReferenceException("Keys list of " + parent.Name + " node is set to null!"); } VDFKey newKey = new VDFKey(Name, Value, parent); //Create our key with the values passed on to us as arguments. parent.Keys.Add(newKey); TreeNode newTreeNode = new TreeNode(Name); newTreeNode.Tag = new TreeNodeVDFTag(TreeNodeVDFTag.Type.Key, newKey); //Store our VDFKey on the tag property of our newTreeNode. Make sure to use the TreeNodeVDFTag. parentTreeNode.Nodes.Add(newTreeNode); return(newTreeNode); }
/// <summary> /// Initializes the SteamApp class. /// </summary> /// <param name="vdfdata">The parsed VDF Data Structure.</param> /// <param name="LibPath">The path of the library containing the application.</param> void init(VDFData vdfdata, string LibPath) { if (vdfdata == null) { throw new ArgumentNullException("Argument VDF Data is set to null!"); } if (vdfdata.Nodes == null || vdfdata.Nodes.Count == 0) { throw new NullReferenceException("Nodes of VDFData is either null or empty!"); } _unparsedData = vdfdata; VDFNode vNode = vdfdata.Nodes.FindNode(MANIFEST_NODE); //Locate our root node. We can do nodes[0] as well and it'll be faster but just to be safe. if (vNode == null) { throw new NullReferenceException("Node " + MANIFEST_NODE + " is not found!"); } if (vNode.Keys == null || vNode.Keys.Count == 0) { throw new NullReferenceException("Node " + MANIFEST_NODE + " list of keys is either null or empty!"); } VDFKey vKey = vNode.Keys.FindKey(MANIFEST_KEY_NAME); //Locate our first key which will be the name of the app. if (vKey != null) { _Name = vKey.Value; } else { throw new NullReferenceException("Key pertaining to the name of the app is not found under " + MANIFEST_NODE + " node."); } vKey = vNode.Keys.FindKey(MANIFEST_KEY_APPID); if (vKey != null) { int tryresult; if (int.TryParse(vKey.Value, out tryresult)) { _AppID = tryresult; } else { throw new NullReferenceException("Key pertaining to the Application ID of the app under " + MANIFEST_NODE + " node is invalid!"); } } else { throw new NullReferenceException("Key pertaining to the Application ID of the app is not found under " + MANIFEST_NODE + " node."); } vKey = vNode.Keys.FindKey(MANIFEST_KEY_INSDIR); if (vKey != null) { _InstallDir = LibPath + "\\" + SteamAppsManager.STEAM_APPS_DIRNAME + "\\" + SteamAppsManager.STEAM_APPS_COMMON_DIRNAME + "\\" + vKey.Value; _InstallDirName = vKey.Value; } else { throw new NullReferenceException("Key pertaining to the directory name containing the app under " + MANIFEST_NODE + " node is not found!"); } }
void GUIUpdate_LoadKeyInfo(VDFKey key) { txtName.Text = key.Name; txtValue.Text = key.Value; }