Ejemplo n.º 1
0
 private TreeNodeCollection verifyReflexivesRecursive(BinaryReader br, TreeNodeCollection tnc, int baseOffset)
 {
     for (int i = 0; i < tnc.Count; i++)
     {
         TreeNode tn      = tnc[i];
         string[] offsets = tn.Name.Split('\\');
         if (tn.Nodes.Count > 0)
         {
             br.BaseStream.Position = baseOffset + int.Parse(offsets[offsets.Length - 1]);
             int count  = br.ReadInt32();
             int offset = br.ReadInt32() - meta.magic - meta.offset;
             if (count == 0)
             {
                 tnc.Remove(tn);
                 i--;
                 continue;
             }
             else
             {
                 tagInfo ti = (tagInfo)tn.Tag;
                 ti.chunkCount = count;
                 ti.offset     = offset;
                 tn.Text      += " [" + (ti.chunkSelection + 1).ToString() + "/" + ti.chunkCount.ToString() + "]";
                 TreeNodeCollection tnt = verifyReflexivesRecursive(br, tn.Nodes, offset);
                 TreeNode[]         tna = new TreeNode[tnt.Count];
                 tnt.CopyTo(tna, 0);
                 tn.Nodes.Clear();
                 tn.Nodes.AddRange(tna);
             }
         }
     }
     return(tnc);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks the stream against the treenodes and builds a new tree, removing any zero count reflexives
        /// </summary>
        /// <param name="br">The stream passed in as a BinaryReader</param>
        /// <param name="tnc">The TreeNodeCollection listing</param>
        /// <param name="baseOffset">the base offset in the stream for these nodes</param>
        private TreeNode[] verifyReflexives(BinaryReader br, TreeNodeCollection tnc, int baseOffset)
        {
            System.Collections.Generic.List <TreeNode> tnl = new System.Collections.Generic.List <TreeNode>();

            for (int i = 0; i < tnc.Count; i++)
            {
                // Clone each node (w/ sub-nodes) for top-level so we don't touch original tree
                TreeNode tn = (TreeNode)tnc[i].Clone();

                string[] offsets = tn.Name.Split('\\');
                if (tn.Nodes.Count > 0)
                {
                    br.BaseStream.Position = baseOffset + int.Parse(offsets[offsets.Length - 1]);
                    int count  = br.ReadInt32();
                    int offset = br.ReadInt32() - meta.magic - meta.offset;
                    if (count != 0)
                    {
                        tagInfo ti = (tagInfo)tn.Tag;
                        ti.chunkCount = count;
                        ti.offset     = offset;
                        int t = tn.Text.LastIndexOf("[");
                        if (t > -1)
                        {
                            tn.Text = tn.Text.Substring(0, t);
                        }
                        tn.Text += " [" + (ti.chunkSelection + 1).ToString() + "/" + ti.chunkCount.ToString() + "]";
                        TreeNodeCollection tnt = verifyReflexivesRecursive(br, tn.Nodes, offset);
                        TreeNode[]         tna = new TreeNode[tnt.Count];
                        tnt.CopyTo(tna, 0);
                        tn.Nodes.Clear();
                        tn.Nodes.AddRange(tna);
                        tnl.Add(tn);
                    }
                }
            }
            return(tnl.ToArray());
        }
Ejemplo n.º 3
0
        private void tvDestTags_AfterSelect(object sender, TreeViewEventArgs e)
        {
            int lastNode = tvDestTags.SelectedNode.Level;

            TreeNode[] tn = new TreeNode[lastNode + 1];
            tn[lastNode] = tvDestTags.SelectedNode;

            string[] offsets = tn[lastNode].Name.Split('\\');

            #region source data
            int baseOffsetS = 0;
            int baseOffsetD = 0;
            int chunkCountS = 0;
            int chunkCountD = 0;
            for (int x = 0; x < offsets.Length; x++)
            {
                tagInfo ti = ((tagInfo)tn[x].Tag);
                baseOffsetS = getOffset(fStream, baseOffsetS, int.Parse(offsets[x])) + ti.chunkSelection * ti.size;
                //baseOffsetD = getOffset(meta.MS, baseOffsetD, int.Parse(offsets[x])) + ti.chunkSelectionD * ti.size;
                if (x == offsets.Length - 1)
                {
                    chunkCountS = ti.chunkCount;
                }
            }

            /*
             * BinaryReader brS = new BinaryReader(fsS);
             * int baseOffsetS = 0;
             * int chunkCountS = 1;
             * if (sn.Parent != null)
             * {
             *  tagInfo ti = ((tagInfo)sn.Parent.Tag);
             *  baseOffsetS = ti.offset;
             *  // Don't show all for refelxives as we can't do full reflexives anyways
             *  if (sn.Nodes.Count == 0)
             *      chunkCountS = ti.chunkCount;
             *
             *  if (sn.Parent.Parent != null)
             *  {
             *      ti = (tagInfo)sn.Parent.Parent.Tag;
             *      if (comboBox1.Items.Count != ti.chunkCount)
             *      {
             *          comboBox1.Items.Clear();
             *          for (int i = 0; i < ti.chunkCount; i++)
             *              comboBox1.Items.Add(i + 1);
             *      }
             *      lblReflexiveNumber.Enabled = true;
             *      comboBox1.Enabled = true;
             *  }
             *  else
             *  {
             *      lblReflexiveNumber.Enabled = false;
             *      comboBox1.Enabled = false;
             *  }
             *
             * }
             *
             * int size = 0;
             * if (offsets.Length > 1)
             *  size = ((tagInfo)sn.Parent.Tag).size;
             * lbSourceIndices.Items.Clear();
             * for (int i = 0; i < chunkCountS; i++)
             * {
             *  brS.BaseStream.Position = baseOffsetS + int.Parse(offsets[offsets.Length - 1]) + i * size;
             *  lbSourceIndices.Items.Add(getDataFromBinaryStream(brS, sn.ToolTipText.Substring(1, sn.ToolTipText.IndexOf(']')-1 )));
             * }
             * brS.Close();
             */
            #endregion

            /*
             #region destination data
             * BinaryReader brD = new BinaryReader(meta.MS);
             * int baseOffsetD = 0;
             * int chunkCountD = 1;
             * for (int i = 0; i < offsets.Length - 1; i++)
             * {
             *  brD.BaseStream.Position = baseOffsetD + int.Parse(offsets[i]);
             *  if (tn[lastNode].Nodes.Count == 0)
             *      chunkCountD = brD.ReadInt32();
             *  else
             *      brD.ReadInt32();
             *  baseOffsetD = (brD.ReadInt32() - meta.magic - meta.offset);
             *  if (chunkCountD == 0)
             *      break;
             * }
             *
             * lbDestIndices.Items.Clear();
             * for (int i = 0; i < chunkCountD; i++)
             * {
             *  brD.BaseStream.Position = baseOffsetD + int.Parse(offsets[offsets.Length - 1]) + i * size;
             *  lbDestIndices.Items.Add(getDataFromBinaryStream(brD, tn[lastNode].ToolTipText.Substring(1, tn[lastNode].ToolTipText.IndexOf(']') - 1)));
             * }
             #endregion
             *
             *
             * MaxSelections = Math.Min(chunkCountS, chunkCountD);
             *
             * lblSourceDestDiff.Visible = false;
             * // If we have reflexive chunks or if it is a reflexive tag, disable the button
             * if (chunkCountS != 0)
             * {
             *  btnRestoreValues.Enabled = false;
             *  lblSourceDestDiff.ForeColor = System.Drawing.Color.Red;
             *  lblSourceDestDiff.Text = "No selections made";
             *  lblSourceDestDiff.Visible = true;
             *
             * }
             * else if (tn[lastNode].Nodes.Count > 0)
             *  btnRestoreValues.Enabled = false;
             * else
             *  btnRestoreValues.Enabled = true;
             *
             * btnSelectAll_Click(sender, e);
             */
        }
Ejemplo n.º 4
0
        private void tvSourceTags_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (tvSourceTags.SelectedNode == null)
            {
                return;
            }
            int lastNode = tvSourceTags.SelectedNode.Level;

            TreeNode[] tn = new TreeNode[lastNode + 1];
            tn[lastNode] = tvSourceTags.SelectedNode;
            for (int x = lastNode - 1; x >= 0; x--)
            {
                tn[x] = tn[x + 1].Parent;
            }


            string[] offsets = tn[lastNode].Name.Split('\\');

            #region source data
            int baseOffsetS = 0;
            int chunkCountS = 0;
            for (int x = 0; x < offsets.Length - 1; x++)
            {
                tagInfo ti = ((tagInfo)tn[x].Tag);
                baseOffsetS = getOffset(fStream, baseOffsetS, int.Parse(offsets[x])) + ti.chunkSelection * ti.size;
                if (x == offsets.Length - 2)
                {
                    chunkCountS = ti.chunkCount;
                }
            }

            int size = 0;
            if (offsets.Length > 1)
            {
                size = ((tagInfo)tn[lastNode - 1].Tag).size;
            }
            lbSourceIndices.Items.Clear();

            if (baseOffsetS != -1)
            {
                BinaryReader brS = new BinaryReader(fStream);
                for (int i = 0; i < chunkCountS; i++)
                {
                    brS.BaseStream.Position = baseOffsetS + int.Parse(offsets[offsets.Length - 1]) + i * size;
                    lbSourceIndices.Items.Add(getDataFromBinaryStream(brS, tn[lastNode].ToolTipText.Substring(1, tn[lastNode].ToolTipText.IndexOf(']') - 1)));
                }
            }

            if (lastNode != 0)
            {
                reflexiveData rd = ((reflexiveData)tn[lastNode - 1].Tag);
                baseOffsetS = rd.baseOffset;
                // Don't show all for refelxives as we can't do full reflexives anyways
                if (tn[lastNode].Nodes.Count == 0)
                {
                    chunkCountS = rd.chunkCount;
                }

                if (lastNode > 1)
                {
                    while (panel1.Controls.Count > lastNode - 1)
                    {
                        panel1.Controls.RemoveAt(panel1.Controls.Count - 1);
                    }
                    for (int x = 0; x <= lastNode - 2; x++)
                    {
                        rd = (reflexiveData)tn[x + 1].Tag;

                        ComboBox cb;
                        if (panel1.Controls.Count <= x)
                        {
                            cb                       = new ComboBox();
                            cb.Dock                  = DockStyle.Right;
                            cb.DropDownStyle         = ComboBoxStyle.DropDownList;
                            cb.Size                  = new System.Drawing.Size(80, 21);
                            cb.Size                  = new System.Drawing.Size(panel1.Width / (tn.Length - 2), 21);
                            cb.SelectedIndexChanged += new EventHandler(cbSourceReflexiveNumber_SelectedIndexChanged);
                            panel1.Controls.Add(cb);
                        }
                        else
                        {
                            cb      = (ComboBox)panel1.Controls[x];
                            cb.Size = new System.Drawing.Size(panel1.Width / (tn.Length - 2), 21);
                        }
                        if (rd.chunkCount == 0)
                        {
                            lblSourceReflexiveNumber.Enabled = false;
                            cb.Enabled = false;
                        }
                        else
                        {
                            if (cb.Items.Count != rd.chunkCount)
                            {
                                cb.Items.Clear();
                                for (int i = 0; i < rd.chunkCount; i++)
                                {
                                    cb.Items.Add((i + 1).ToString() + ": " + tn[x + 1].Text.Substring(0, tn[x + 1].Text.LastIndexOf('[')));
                                }
                                cb.SelectedIndex = 0;
                            }
                            lblSourceReflexiveNumber.Enabled = true;
                            cb.Enabled = true;
                        }
                    }
                }
                else
                {
                    lblSourceReflexiveNumber.Enabled = false;
                    cbSourceReflexiveNumber.Enabled  = false;
                }
            }
            #endregion
            loadValues(tn[lastNode], lbSourceIndices);

            btnSelectAll_Click(sender, e);
        }