• gshop.data 编辑器通杀版本 支持146-151版本


    EXE下载:http://files.cnblogs.com/xe2011/EXEgshop.dataeditorV1.42014-3-11-204242.7z

    C#:http://files.cnblogs.com/xe2011/script_gshop.dataeditorV1.42014-3-11-204242.7z

    本程序 是C#写的,系统必须安装了.net framework 2.0才能运行。
    如不能运行请安装.NET 2.0
    http://download.microsoft.com/download/5/6/7/567758a3-759e-473e-bf8f-52154438565a/dotnetfx.exe


    自动重命名批处理

    gSev.bat  自动对拖拽到它身上的文件重命名为gshopsev.data

    Shop.bat  自动对拖拽到它身上的文件重命名为gshop.data

    本程序 支持把 gshop.data直接拖拽到程序上进行读取。支持145-151版本的gshop.data的编辑, 一句话只要能打开,然后保存为一个文件,能在次打开就支持。

    编辑GSHOP.DATA的建议

    1 正确的文件是这样的

       1本程序 可以打开。  

      2 覆盖服务端关闭服务器 ,重启服务器 所有有服务都显示在线(绿色)

    2 每大修改一分部,保存一次,然后将保存的文件拖拽到本程序 上看是否能打开。不能打开 的一定不能进游戏,需要重试!

    3 部分物品堆叠上限是1 如果它的上限是1 你修改的数量大于1 则将无法进入游戏。

    这是无法进入游戏的主要原因 比如 白金护身符 默认的堆叠上限为1 你误改成2或者更高 地图服务就掉线,无法进入游戏,提示版本低

    4 在进行批量修改时一定要先 不选所有,然后再选要批量修改的。 5 建议修改gshop.data的时候不要修改 elements.data,反过来也是。

    【2014年3月8日】

    1 增加了查找物品的功能

    2 改变了保存文件的方式

     【2014年金3月3日】

     

    增加了导入和导出功能

    【2014年3月2日】

    本程序的前身 这个不知道是哪个大神写的

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    using System.Collections;//ArrayList
    using System.IO;//FileStream
    using System.Runtime.InteropServices;//Marshal
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                Height = 600;
            }
    
            private ArrayList lst = new ArrayList();
            public byte[] temp = new byte[4];
            public byte[] bt;
    
            private int amount;
            private int gshopItemsCount;//gshop.data所有物品个数 
            private UInt32 gshopdataVersion;//gshop版本
    
            private int no;
            private int maxno = 0;
            private gds tgds;
            private sgds tsgds;
            private FileStream wFile;
            private FileStream rFile;
            private TreeNode tn;
    
    
    
            public static object rawDeserialize(byte[] rawdatas, Type anytype)
            {
                int num = Marshal.SizeOf(anytype);
                object result;
                if (num > rawdatas.Length)
                {
                    result = null;
                }
                else
                {
                    IntPtr intPtr = Marshal.AllocHGlobal(num);
                    Marshal.Copy(rawdatas, 0, intPtr, num);
                    object obj = Marshal.PtrToStructure(intPtr, anytype);
                    Marshal.FreeHGlobal(intPtr);
                    result = obj;
                }
                return result;
            }
            public static byte[] rawSerialize(object obj)
            {
                int num = Marshal.SizeOf(obj);
                IntPtr intPtr = Marshal.AllocHGlobal(num);
                Marshal.StructureToPtr(obj, intPtr, false);
                byte[] array = new byte[num];
                Marshal.Copy(intPtr, array, 0, num);
                Marshal.FreeHGlobal(intPtr);
                return array;
            }
            public void show(int i)
            {
                numericUpDown3.Value = BitConverter.ToInt32(((gds)lst[i]).id, 0);
                numericUpDown4.Value = BitConverter.ToInt32(((gds)lst[i]).no, 0);
                numericUpDown5.Value = BitConverter.ToInt32(((gds)lst[i]).amount, 0);
                numericUpDown6.Value = (decimal)((double)BitConverter.ToInt32(((gds)lst[i]).price, 0) / 100.0);
                numericUpDown7.Value = BitConverter.ToInt32(((gds)lst[i]).time, 0);
                numericUpDown8.Value = BitConverter.ToInt32(((gds)lst[i]).zid, 0);
                numericUpDown9.Value = BitConverter.ToInt32(((gds)lst[i]).zam, 0);
                numericUpDown10.Value = (decimal)((double)BitConverter.ToInt32(((gds)lst[i]).zpr, 0) / 100.0);
                comboBox1.Text = comboBox1.Items[BitConverter.ToInt32(((gds)lst[i]).type, 0)].ToString();
                textBox1.Text = Encoding.Default.GetString(((gds)lst[i]).ic);
                textBox2.Text = Encoding.Unicode.GetString(((gds)lst[i]).explanation);
                textBox3.Text = Encoding.Unicode.GetString(((gds)lst[i]).name);
            }
    
            public void ldMulu1()
            {
                comboBox2.Items.Clear();
                for (int i = 0; i < 8; i++)
                {
                    comboBox2.Items.Add(treeView1.Nodes[i].Text);
                }
                comboBox2.SelectedIndex = 0;
            }
            public void ldMulu2()
            {
                comboBox3.Items.Clear();
                for (int i = 0; i < treeView1.Nodes[comboBox2.SelectedIndex].Nodes.Count; i++)
                {
                    comboBox3.Items.Add(treeView1.Nodes[comboBox2.SelectedIndex].Nodes[i].Text);
                }
                comboBox3.SelectedIndex = 0;
            }
            public void delmore()
            {
                for (int i = 0; i < treeView1.Nodes.Count; i++)
                {
                    for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                    {
                        for (int k = 0; k < treeView1.Nodes[i].Nodes[j].Nodes.Count; k++)
                        {
                            if (treeView1.Nodes[i].Nodes[j].Nodes[k].Checked)
                            {
                                treeView1.Nodes[i].Nodes[j].Nodes.RemoveAt(k);
                                doAmount(-1);
                                k--;
                            }
                        }
                    }
                }
            }
    
            public void doAmount(int i)
            {
                amount += i;
    
                numericUpDown2.Value = amount;
    
                gshopItemsCount = amount;
                //    toolStripStatusLabel2.Text = String.Format("物品:{0}",gshopItemsCount);
                groupBox1.Text = "版本:" + Convert.ToString(gshopdataVersion, 16).ToUpper() + String.Format("    物品:{0} 个", amount);
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2)
                {
                    tgds.id = BitConverter.GetBytes((int)numericUpDown3.Value);
                    tgds.no = BitConverter.GetBytes((int)numericUpDown4.Value);
                    tgds.amount = BitConverter.GetBytes((int)numericUpDown5.Value);
                    tgds.price = BitConverter.GetBytes((int)(numericUpDown6.Value * 100m));
                    tgds.time = BitConverter.GetBytes((int)numericUpDown7.Value);
                    tgds.zid = BitConverter.GetBytes((int)numericUpDown8.Value);
                    tgds.zam = BitConverter.GetBytes((int)numericUpDown9.Value);
                    tgds.zpr = BitConverter.GetBytes((int)(numericUpDown10.Value * 100m));
                    tgds.type = BitConverter.GetBytes(comboBox1.SelectedIndex);
                    tgds.ic = new byte[tgds.ic.Length];
                    Encoding.Default.GetBytes(textBox1.Text).CopyTo(tgds.ic, 0);
                    tgds.explanation = new byte[tgds.explanation.Length];
                    Encoding.Unicode.GetBytes(textBox2.Text).CopyTo(tgds.explanation, 0);
                    tgds.name = new byte[tgds.name.Length];
                    Encoding.Unicode.GetBytes(textBox3.Text).CopyTo(tgds.name, 0);
                    lst[Convert.ToInt32(treeView1.SelectedNode.Tag)] = tgds;
                    treeView1.SelectedNode.Text = Encoding.Unicode.GetString(tgds.name);
                }
                应用更新物品button1.Enabled = false;
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null && tgds.id != null)
                {
                    maxno++;
                    tn = new TreeNode();
                    if (treeView1.SelectedNode.Level == 1)
                    {
                        tgds.no = BitConverter.GetBytes(maxno);
                        tgds.cp = BitConverter.GetBytes(treeView1.SelectedNode.Parent.Index);
                        tgds.cs = BitConverter.GetBytes(treeView1.SelectedNode.Index);
                        tn.Text = Encoding.Unicode.GetString(tgds.name);
                        tn.Tag = lst.Count.ToString();
                        lst.Add(tgds);
                        treeView1.Nodes[treeView1.SelectedNode.Parent.Index].Nodes[treeView1.SelectedNode.Index].Nodes.Add(tn);
                    }
                    if (treeView1.SelectedNode.Level == 2)
                    {
                        tgds.no = BitConverter.GetBytes(maxno);
                        tn.Text = Encoding.Unicode.GetString(tgds.name);
                        tn.Tag = lst.Count.ToString();
                        lst.Add(tgds);
                        treeView1.Nodes[treeView1.SelectedNode.Parent.Parent.Index].Nodes[treeView1.SelectedNode.Parent.Index].Nodes.Add(tn);
                    }
                    doAmount(1);
                }
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2)
                {
                    treeView1.SelectedNode.Remove();
                    doAmount(-1);
    
    
                }
            }
    
            private void button5_Click(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null && treeView1.SelectedNode.Level < 2)
                {
                    treeView1.SelectedNode.Text = textBox4.Text;
                    ldMulu1();
                }
            }
    
            private void button6_Click(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null && treeView1.SelectedNode.Level < 2)
                {
                    if (treeView1.SelectedNode.Level == 1)
                    {
                        treeView1.Nodes[treeView1.SelectedNode.Parent.Index].Nodes.Add(textBox4.Text);
                    }
                    else
                    {
                        treeView1.Nodes[treeView1.SelectedNode.Index].Nodes.Add(textBox4.Text);
                    }
                    ldMulu1();
                }
            }
    
            private void button7_Click(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1)
                {
                    if (treeView1.SelectedNode.Nodes.Count > 1)
                    {
                        string s = String.Format("删除类别:{0}", treeView1.SelectedNode.Text);
    
                        if (MessageBox.Show(s, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            doAmount(-treeView1.SelectedNode.Nodes.Count);
                            treeView1.SelectedNode.Remove();
                            ldMulu1();
                        }
                    }
                    else
                    {
                        doAmount(-treeView1.SelectedNode.Nodes.Count);
                        treeView1.SelectedNode.Remove();
                        ldMulu1();
                    }
                }
            }
    
            private void button4_Click(object sender, EventArgs e)
            {
                maxno = 0;
                for (int i = 0; i < treeView1.Nodes.Count; i++)
                {
                    for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                    {
                        for (int k = 0; k < treeView1.Nodes[i].Nodes[j].Nodes.Count; k++)
                        {
                            maxno++;
                            tgds = (gds)lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)];
                            tgds.no = BitConverter.GetBytes(maxno);
                            lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)] = tgds;
                        }
                    }
                }
            }
    
            TreeNode theLastNode = null;//最后选择的节点(用于还原节点状态)
            private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
            {
                if (treeView1.SelectedNode.Level < 2)
                {
                    textBox4.Text = treeView1.SelectedNode.Text;
                }
                if (treeView1.SelectedNode.Level == 2)
                {
                    tgds = (gds)lst[Convert.ToInt32(treeView1.SelectedNode.Tag)];
                    show(Convert.ToInt32(treeView1.SelectedNode.Tag));
                    //     groupBox2.Text = "物品:" + treeView1.SelectedNode.Text;
                }
    
    
    
                toolTip1.SetToolTip(textBox1, textBox1.Text);
                toolTip1.SetToolTip(textBox2, textBox2.Text);
                toolTip1.SetToolTip(textBox3, textBox3.Text);
    
    
                if (this.treeView1.SelectedNode != null)
                {
                    theLastNode = treeView1.SelectedNode;
                }
    
    
                if (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2)
                    应用更新物品button1.Enabled = true;
                else
                    应用更新物品button1.Enabled = false;
            }
    
            private void treeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
            {
                e.Node.ForeColor = Color.Blue;
                e.Node.NodeFont = new Font("宋体", 9, FontStyle.Underline);
                if (theLastNode != null)
                {
                    theLastNode.ForeColor = SystemColors.WindowText;
                    theLastNode.NodeFont = new Font("宋体", 9, FontStyle.Regular);
                }
            }
    
    
            private void treeView1_BeforeCheck(object sender, TreeViewCancelEventArgs e)
            {
                //for (int i = 0; i < e.Node.Nodes.Count; i++)
                //{
                //    e.Node.Nodes[i].Checked = e.Node.Checked;
                //}
            }
    
            private void button8_Click(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null)
                {
                    TreeNode treeNode = new TreeNode();
                    if (treeView1.SelectedNode.Index != 0)
                    {
                        if (treeView1.SelectedNode.Index != 0)
                        {
                            treeNode = (TreeNode)treeView1.SelectedNode.Clone();
                            if (treeView1.SelectedNode.Level == 0)
                            {
                                treeView1.Nodes.Insert(treeView1.SelectedNode.PrevNode.Index, treeNode);
                            }
                            else
                            {
                                if (treeView1.SelectedNode.Level != 0)
                                {
                                    treeView1.SelectedNode.Parent.Nodes.Insert(treeView1.SelectedNode.PrevNode.Index, treeNode);
                                }
                            }
                            treeView1.SelectedNode.Remove();
                            treeView1.SelectedNode = treeNode;
                        }
                    }
                    ldMulu1();
                }
            }
    
            private void button9_Click(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null)
                {
                    TreeNode treeNode = new TreeNode();
                    if (treeView1.SelectedNode.Level == 0)
                    {
                        if (treeView1.SelectedNode.Index != treeView1.Nodes.Count - 1)
                        {
                            treeNode = (TreeNode)treeView1.SelectedNode.Clone();
                            treeView1.Nodes.Insert(treeView1.SelectedNode.NextNode.Index + 1, treeNode);
                            treeView1.SelectedNode.Remove();
                            treeView1.SelectedNode = treeNode;
                        }
                    }
                    else
                    {
                        if (treeView1.SelectedNode.Level != 0)
                        {
                            if (treeView1.SelectedNode.Index != treeView1.SelectedNode.Parent.Nodes.Count - 1)
                            {
                                treeNode = (TreeNode)treeView1.SelectedNode.Clone();
                                treeView1.SelectedNode.Parent.Nodes.Insert(treeView1.SelectedNode.NextNode.Index + 1, treeNode);
                                treeView1.SelectedNode.Remove();
                                treeView1.SelectedNode = treeNode;
                            }
                        }
                    }
                    ldMulu1();
                }
            }
    
            private void button10_Click(object sender, EventArgs e)
            {
                byte[] bytes = BitConverter.GetBytes((int)numericUpDown11.Value);
                for (int i = 0; i < treeView1.Nodes.Count; i++)
                {
                    for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                    {
                        for (int k = 0; k < treeView1.Nodes[i].Nodes[j].Nodes.Count; k++)
                        {
                            if (treeView1.Nodes[i].Nodes[j].Nodes[k].Checked)
                            {
                                tgds = (gds)lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)];
                                tgds.amount = bytes;
                                lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)] = tgds;
                            }
                        }
                    }
                }
            }
    
            private void button11_Click(object sender, EventArgs e)
            {
                byte[] bytes = BitConverter.GetBytes((int)(numericUpDown12.Value * 100m));
                for (int i = 0; i < treeView1.Nodes.Count; i++)
                {
                    for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                    {
                        for (int k = 0; k < treeView1.Nodes[i].Nodes[j].Nodes.Count; k++)
                        {
                            if (treeView1.Nodes[i].Nodes[j].Nodes[k].Checked)
                            {
                                tgds = (gds)lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)];
                                tgds.price = bytes;
                                lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)] = tgds;
                            }
                        }
                    }
                }
            }
    
            private void button12_Click(object sender, EventArgs e)
            {
                byte[] bytes = Encoding.Unicode.GetBytes(textBox5.Text);
                for (int i = 0; i < treeView1.Nodes.Count; i++)
                {
                    for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                    {
                        for (int k = 0; k < treeView1.Nodes[i].Nodes[j].Nodes.Count; k++)
                        {
                            if (treeView1.Nodes[i].Nodes[j].Nodes[k].Checked)
                            {
                                tgds = (gds)lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)];
                                tgds.explanation = new byte[tgds.explanation.Length];
                                bytes.CopyTo(tgds.explanation, 0);
                                lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)] = tgds;
                            }
                        }
                    }
                }
            }
    
            private void button13_Click(object sender, EventArgs e)
            {
                for (int i = 0; i < treeView1.Nodes.Count; i++)
                {
                    for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                    {
                        for (int k = 0; k < treeView1.Nodes[i].Nodes[j].Nodes.Count; k++)
                        {
                            if (treeView1.Nodes[i].Nodes[j].Nodes[k].Checked)
                            {
                                tn = treeView1.Nodes[i].Nodes[j].Nodes[k];
                                tn.Checked = false;
                                treeView1.Nodes[i].Nodes[j].Nodes.RemoveAt(k);
                                treeView1.Nodes[comboBox2.SelectedIndex].Nodes[comboBox3.SelectedIndex].Nodes.Add(tn);
                                k--;
                            }
                        }
                    }
                }
            }
    
            private void button14_Click(object sender, EventArgs e)
            {
                delmore();
            }
    
            private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (comboBox2.SelectedIndex > -1)
                {
                    ldMulu2();
                }
            }
    
    
    
            //OpenGshopdata
            private void OpenGshopdata(string sFileName)
            {
                try
                {
                    rFile = new FileStream(sFileName, FileMode.Open);
    
                    rFile.Seek(0L, SeekOrigin.Begin);
                    rFile.Read(temp, 0, 4);
    
                    //版本
                    gshopdataVersion = BitConverter.ToUInt32(temp, 0);
    
                    numericUpDown1.Value = BitConverter.ToUInt32(temp, 0);
                    // toolStripStatusLabel3.Text ="版本:" + Convert.ToString(gshopdataVersion, 16).ToUpper();
    
    
    
    
                    rFile.Read(temp, 0, 4);
                    amount = BitConverter.ToInt32(temp, 0);
    
                    ///
                    //总共物品个数
                    //    toolStripStatusLabel2.Text = String.Format("物品:{0}", amount);
                    numericUpDown2.Value = amount;////////////////
    
                    groupBox1.Text = "版本:" + Convert.ToString(gshopdataVersion, 16).ToUpper() + String.Format("    物品:{0} 个", amount);
    
    
                    bt = new byte[Marshal.SizeOf(typeof(gds))];
                    for (int i = 0; i < amount; i++)
                    {
                        rFile.Read(bt, 0, Marshal.SizeOf(typeof(gds)));
                        lst.Add((gds)Form1.rawDeserialize(bt, typeof(gds)));
                    }
    
                    bt = new byte[128];
                    byte[] array = new byte[4];
                    for (int i = 0; i < 8; i++)
                    {
                        rFile.Read(bt, 0, 128);
                        treeView1.Nodes.Add(Encoding.Unicode.GetString(bt));
                        comboBox2.Items.Add(Encoding.Unicode.GetString(bt));
                        rFile.Read(array, 0, 4);
                        int num = BitConverter.ToInt32(array, 0);
                        for (int j = 0; j < num; j++)
                        {
                            rFile.Read(bt, 0, 128);
                            treeView1.Nodes[i].Nodes.Add(Encoding.Unicode.GetString(bt));
                        }
                    }
    
                    rFile.Close();
                    for (int i = 0; i < amount; i++)
                    {
                        int num2 = BitConverter.ToInt32(((gds)lst[i]).no, 0);
                        if (maxno < num2)
                        {
                            maxno = num2;
                        }
                        tn = new TreeNode();
                        tn.Text = Encoding.Unicode.GetString(((gds)lst[i]).name);
                        tn.Tag = i.ToString();
                        treeView1.Nodes[BitConverter.ToInt32(((gds)lst[i]).cp, 0)].Nodes[BitConverter.ToInt32(((gds)lst[i]).cs, 0)].Nodes.Add(tn);
                    }
                    ldMulu1();
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
    
            //Savegshop.data
            private void SaveGshopdata(string sFileName)
            {
    
                try
                {
                    wFile = new FileStream(sFileName, FileMode.Create);
                    wFile.Seek(0L, SeekOrigin.Begin);
    
                    temp = BitConverter.GetBytes((int)numericUpDown1.Value);///////ver
    
    
                    wFile.Write(temp, 0, 4);
                    temp = BitConverter.GetBytes((int)numericUpDown2.Value);///////total count
    
    
                    wFile.Write(temp, 0, 4);
    
                    no = 0;
                    for (int i = 0; i < treeView1.Nodes.Count; i++)
                    {
                        for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                        {
                            for (int k = 0; k < treeView1.Nodes[i].Nodes[j].Nodes.Count; k++)
                            {
                                tgds = (gds)lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)];
                                no++;
                                tgds.cp = BitConverter.GetBytes(i);
                                tgds.cs = BitConverter.GetBytes(j);
                                bt = Form1.rawSerialize(tgds);
                                wFile.Write(bt, 0, Marshal.SizeOf(typeof(gds)));
                            }
                        }
                    }
    
                    bt = new byte[128];
                    byte[] array = new byte[4];
                    for (int i = 0; i < treeView1.Nodes.Count; i++)
                    {
                        bt = new byte[128];
                        Encoding.Unicode.GetBytes(treeView1.Nodes[i].Text).CopyTo(bt, 0);
                        wFile.Write(bt, 0, bt.Length);
                        wFile.Write(BitConverter.GetBytes(treeView1.Nodes[i].Nodes.Count), 0, 4);
                        for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                        {
                            bt = new byte[128];
                            Encoding.Unicode.GetBytes(treeView1.Nodes[i].Nodes[j].Text).CopyTo(bt, 0);
                            wFile.Write(bt, 0, 128);
                        }
                    }
                    wFile.Close();
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.ToString());
                }
    
            }
    
            //Save gshopsev.data
            private void SaveGshopSevData(string sFileName)
            {
                try
                {
                    wFile = new FileStream(sFileName, FileMode.Create);
                    wFile.Seek(0L, SeekOrigin.Begin);
    
                    wFile.Write(BitConverter.GetBytes((int)numericUpDown1.Value), 0, 4);////////////
                    wFile.Write(BitConverter.GetBytes((int)numericUpDown2.Value), 0, 4);/////////////////
    
                    bt = new byte[Marshal.SizeOf(typeof(sgds))];
                    no = 0;
                    for (int i = 0; i < treeView1.Nodes.Count; i++)
                    {
                        for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                        {
                            for (int k = 0; k < treeView1.Nodes[i].Nodes[j].Nodes.Count; k++)
                            {
                                tgds = (gds)lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)];
                                tsgds = default(sgds);
                                tsgds.no = BitConverter.GetBytes(no);
                                no++;
                                tsgds.cp = BitConverter.GetBytes(i);
                                tsgds.cs = BitConverter.GetBytes(j);
                                tsgds.id = tgds.id;
                                tsgds.amount = tgds.amount;
                                tsgds.price = tgds.price;
                                tsgds.v1 = tgds.v1;
                                tsgds.time = tgds.time;
                                tsgds.v2 = tgds.v2;
                                bt = Form1.rawSerialize(tsgds);
                                wFile.Write(bt, 0, Marshal.SizeOf(typeof(sgds)));
                                for (int l = 0; l < 4; l++)
                                {
                                    wFile.Write(BitConverter.GetBytes(4294967295u), 0, 4);
                                    for (int m = 0; m < 7; m++)
                                    {
                                        wFile.Write(BitConverter.GetBytes(0), 0, 4);
                                    }
                                }
                            }
                        }
                    }
                    wFile.Close();
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
    
            private void OpenGshopdata()
            {
                toolStripStatusLabel1.Text = "加载中...";
                sOpenFileName = openFileDialog1.FileName;
                Text = openFileDialog1.FileName + " - roman gshop Editor";
    
                ///
                treeView1.Nodes.Clear();
                lst.Clear();
                OpenGshopdata(openFileDialog1.FileName);
                ////
    
    
                toolStripStatusLabel1.Text = "加载完毕";
                timer1.Enabled = true;
    
                if (treeView1.Nodes.Count > 0)
                {
                    treeView1.Focus();
                    treeView1.SelectedNode = treeView1.Nodes[0];
                }
                numericUpDown1.Visible = true;
            }
            private void 打开OToolStripMenuItem1_Click(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    OpenGshopdata();
                }
            }
    
    
            private string CreateFile2(string sFileName)
            {
                string Dir = System.IO.Path.GetDirectoryName(sFileName) + "\";
                string FileTitle = "gshop";
                string FileExt = System.IO.Path.GetExtension(sFileName);
    
                string s1 = Dir + FileTitle + FileExt;
                int j = 2;
    
    
    
                if (System.IO.File.Exists(s1))
                {
                    string s = string.Format("{0}{1}_{2}{3}", Dir, j, FileTitle, FileExt);
                    while (System.IO.File.Exists(s))
                    {
                        j++;
                        s = string.Format("{0}{1}_{2}{3}", Dir, j, FileTitle, FileExt);
                    }
    
                    if (!System.IO.File.Exists(s))
                    {
                        //"D:AdministratorDesktopGSHOPDATAgshop.data"
                        ////"D:AdministratorDesktopGSHOPDATAgshopsev.data"
                        string gshopsevFileName = System.IO.Path.GetDirectoryName(s) + "\" + Convert.ToString(j) + "_gshopsev.data";
    
                        ////Savegshop.data
                        SaveGshopdata(s);
    
                        ////Save gshopsev.data
                        SaveGshopSevData(gshopsevFileName);
    
                        //MessageBox.Show(s);
                    }
                    return s;
                }
                else
                {
                    string gshopsevFileName = System.IO.Path.GetDirectoryName(s1) + "\gshopsev.data";
    
                    ////Savegshop.data
                    SaveGshopdata(s1);
                    //MessageBox.Show(s1);
    
                    ////Save gshopsev.data
                    SaveGshopSevData(gshopsevFileName);
                    return s1;
                }
            }
    
            private void SaveFile()
            {
                if (rFile != null)
                {
    
                    string s = CreateFile2(sOpenFileName);
                    //string s=saveFileName;
                    sOpenFileName = s;
                    string gshopFileTitle = System.IO.Path.GetFileName(s);
                    string gshopSevTitle = gshopFileTitle.Substring(0, gshopFileTitle.Length - 10) + "gshopsev.data";
                    string path = System.IO.Path.GetDirectoryName(s);
                    //MessageBox.Show(gshopFileTitle);
                    //MessageBox.Show(gshopSevTitle);
                    //MessageBox.Show(path);
    
                    MessageBox.Show("文件已保存!
    " + "客户端文件:" + gshopFileTitle +
                                   "
    服务端文件:" + gshopSevTitle +
                                   "
    存放的路径:" + path,
                                   "ROMAN提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    
                    timer1.Enabled = true;
    
                }
                else
                {
                    MessageBox.Show("null");
                }
            }
            private void 保存SToolStripMenuItem1_Click(object sender, EventArgs e)
            {
    
                SaveFile();
                toolStripStatusLabel1.Text = "保存成功";
            }
    
            private string sOpenFileName = "";
            private void 定位文件toolStripButton1_Click(object sender, EventArgs e)
            {
    
                if (System.IO.File.Exists(sOpenFileName))
                {
                    System.Diagnostics.Process.Start("explorer.exe", @"/select," + sOpenFileName);
                }
                //  Text = sOpenFileDir;
            }
    
    
    
            private void toolStripMenuItem2_Click(object sender, EventArgs e)
            {
                saveFileDialog1.Title = "导出";
                saveFileDialog1.FileName = "exportItem.data";
                if (rFile != null && saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
    
                    try
                    {
                        wFile = new FileStream(saveFileDialog1.FileName, FileMode.Create);
                        wFile.Seek(0L, SeekOrigin.Begin);
                        for (int i = 0; i < treeView1.Nodes.Count; i++)
                        {
                            for (int j = 0; j < treeView1.Nodes[i].Nodes.Count; j++)
                            {
                                for (int k = 0; k < treeView1.Nodes[i].Nodes[j].Nodes.Count; k++)
                                {
                                    if (treeView1.Nodes[i].Nodes[j].Nodes[k].Checked)
                                    {
                                        tgds = (gds)lst[Convert.ToInt32(treeView1.Nodes[i].Nodes[j].Nodes[k].Tag)];
                                        tgds.cp = BitConverter.GetBytes(i);
                                        tgds.cs = BitConverter.GetBytes(j);
                                        bt = Form1.rawSerialize(tgds);
                                        wFile.Write(bt, 0, Marshal.SizeOf(typeof(gds)));
                                    }
                                }
                            }
                        }
                        wFile.Close();
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
    
            private void toolStripMenuItem1_Click(object sender, EventArgs e)
            {
                if (rFile != null)
                {
                    if (treeView1.SelectedNode == null || treeView1.SelectedNode.Level != 1)
                    {
                        MessageBox.Show("请选中存放导入数据的目录!");
                    }
                    else
                    {
                        openFileDialog1.Title = "导入";
                        openFileDialog1.FileName = "exportItem.data";
                        if (openFileDialog1.ShowDialog() == DialogResult.OK)
                        {
                            try
                            {
                                rFile = new FileStream(openFileDialog1.FileName, FileMode.Open);
                                rFile.Seek(0L, SeekOrigin.Begin);
                                int num = Marshal.SizeOf(typeof(gds));
                                bt = new byte[num];
                                int num2 = 0;
                                while ((long)num2 < rFile.Length)
                                {
                                    rFile.Read(bt, 0, num);
                                    tgds = (gds)Form1.rawDeserialize(bt, typeof(gds));
                                    maxno++;
                                    tgds.no = BitConverter.GetBytes(maxno);
                                    tn = new TreeNode();
                                    tn.Text = Encoding.Unicode.GetString(tgds.name);
                                    tn.Tag = lst.Count.ToString();
                                    lst.Add(tgds);
                                    treeView1.SelectedNode.Nodes.Add(tn);
                                    doAmount(1);
                                    num2 += num;
                                }
                                rFile.Close();
                            }
                            catch (IOException ex)
                            {
                                MessageBox.Show(ex.ToString());
                            }
                        }
                    }
                }
            }
    
    
            private void textBox3_DoubleClick(object sender, EventArgs e)
            {
                textBox3.SelectAll();
            }
    
            private void textBox1_DoubleClick(object sender, EventArgs e)
            {
                textBox1.SelectAll();
            }
    
            private void textBox2_DoubleClick(object sender, EventArgs e)
            {
                textBox2.SelectAll();
            }
    
            private void 内容CToolStripMenuItem_Click(object sender, EventArgs e)
            {
                System.Diagnostics.Process.Start("iexplore.exe", "http://www.cnblogs.com/xe2011/p/3576727.html");
            }
    
            private void 置顶TToolStripMenuItem_Click(object sender, EventArgs e)
            {
                TopMost = 置顶TToolStripMenuItem.Checked;
            }
    
    
    
            private void 退出XToolStripMenuItem1_Click(object sender, EventArgs e)
            {
                Close();
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                toolStripStatusLabel1.Text = "Ready";
                timer1.Enabled = false;
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                toolStripStatusLabel1.Text = "Ready";
                toolStripStatusLabel2.Text = "";
                toolStripStatusLabel3.Text = "";
    
    
    
            }
            //CHECK NODE COUNT
            private int TreeviewCountCheckedNodes(TreeNodeCollection treeNodeCollection)
            {
                int countchecked = 0;
                if (treeNodeCollection != null)
                {
                    foreach (TreeNode node in treeNodeCollection)
                    {
                        if (node.Nodes.Count == 0 && node.Checked)
                        {
                            countchecked++;
                        }
                        else if (node.Nodes.Count > 0)
                        {
                            countchecked += TreeviewCountCheckedNodes(node.Nodes);
                        }
                    }
                }
                return countchecked;
            }
    
            private void timer2_Tick(object sender, EventArgs e)
            {
                try
                {
                    //状态设置
                    定位文件toolStripButton1.Enabled = System.IO.File.Exists(sOpenFileName);
    
                    保存SToolStripButton.Enabled = (rFile != null);
                    保存SToolStripMenuItem1.Enabled = (rFile != null);
    
                    修改类名称button.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level < 2);
                    button6.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level < 2);
                    textBox4.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level < 2);
    
                    button7.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1);
    
                    // 应用更新物品button1.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2);
                    button2.Enabled = (treeView1.SelectedNode != null && tgds.id != null);
                    button3.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2);
    
                    toolStripMenuItem1.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1);
                    toolStripMenuItem2.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1);
    
    
    
    
                    SearchNodeText.Enabled = textBox7.Text.Trim().Length > 0;
    
    
                    button8.Enabled = (treeView1.SelectedNode != null);
                    button9.Enabled = (treeView1.SelectedNode != null);
    
                    选中ToolStripMenuItem.Visible = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1);
                    清除ToolStripMenuItem.Visible = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1);
    
                    修改类名称button.Enabled = textBox4.Modified;
    
                    if (treeView1.Focused)
                    {
                        if (button7.Enabled)
                        {
                            删除类别TToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Delete;
                        }
                        else
                        {
                            删除类别TToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.None;
                        }
    
                        if (button3.Enabled)
                        {
                            删除物品CToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.Delete;
                        }
                        else
                        {
                            删除物品CToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.None;
                        }
                    }
                    else
                    {
                        删除物品CToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Keys.None;
                    }
                    int ChecknodeItemsCount = TreeviewCountCheckedNodes(treeView1.Nodes);
                    toolStripStatusLabel2.Text = "选中物品: " + Convert.ToString(ChecknodeItemsCount);
    
                    导入toolStripButton1.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1);
                    导出toolStripButton2.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level <= 2 && ChecknodeItemsCount >= 1);
    
    
                    if (ChecknodeItemsCount > 1)
                    {
                        this.toolStripStatusLabel2.ForeColor = System.Drawing.Color.Red;
                    }
                    else
                    {
                        this.toolStripStatusLabel2.ForeColor = System.Drawing.Color.Black;
                    }
    
                    groupBox3.Visible = (treeView1.SelectedNode.Level == 2) && (ChecknodeItemsCount > 1);
    
                    全选button16.Enabled = (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1);
                   
                    //Copy1.Enabled = treeView1.SelectedNode != null;
    
    
                    // toolTip1.SetToolTip(treeView1, textBox1.Text);
    
                }
                catch { }
            }
    
    
            public void CheckAllNodes(TreeNodeCollection nodes)
            {
                foreach (TreeNode node in nodes)
                {
                    node.Checked = true;
                    CheckChildren(node, true);
                }
            }
    
            public void UncheckAllNodes(TreeNodeCollection nodes)
            {
                foreach (TreeNode node in nodes)
                {
                    node.Checked = false;
                    CheckChildren(node, false);
                }
            }
    
            private void CheckChildren(TreeNode rootNode, bool isChecked)
            {
                foreach (TreeNode node in rootNode.Nodes)
                {
                    CheckChildren(node, isChecked);
                    node.Checked = isChecked;
                }
            }
            private void 全选button16_Click(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null)
                {
                    treeView1.SelectedNode.Checked = false;
                    if (treeView1.SelectedNode.Level == 1)
                        CheckAllChildNodes(treeView1.SelectedNode, true);
                }
            }
    
    
    
            private void textBox1_Enter(object sender, EventArgs e)
            {
                //BeginInvoke((Action)delegate
                //{
                //    textBox1.SelectAll();
                //});
            }
    
            private void textBox2_Enter(object sender, EventArgs e)
            {
                //BeginInvoke((Action)delegate
                //{
                //    textBox2.SelectAll();
                //});
            }
    
            private void treeView1_MouseDown(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    TreeNode tn = treeView1.GetNodeAt(e.X, e.Y);
                    if (tn != null) treeView1.SelectedNode = tn;
                }
            }
    
            private void treeView1_KeyDown(object sender, KeyEventArgs e)
            {
                if (treeView1.SelectedNode == null)
                    return;
    
                if (e.KeyCode == Keys.Enter)
                {
                        if (treeView1.SelectedNode.IsExpanded == false)
                            treeView1.SelectedNode.Expand();
                        else
                            treeView1.SelectedNode.Collapse();
                }
    
                //if (e.KeyCode == Keys.Space) 
                //{
                    
                //    treeView1.SelectedNode.Checked = false;
                //    全选button16_Click(sender, e);
    
                //    if (treeView1.SelectedNode.Checked == false)
                //    {
                        
                        
                //    }
                //    else
                //    {
                //        不选button17_Click(sender, e);
                //    }
                    
    
                //}
    
                if (e.KeyCode == Keys.Escape)
                {
                    不选button17_Click(sender, e);
                }
               
    
    
            }
    
            private void treeView1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == 13)
                {
                    e.Handled = true;
                }
            }
    
            private void textBox4_Enter(object sender, EventArgs e)
            {
                //BeginInvoke((Action)delegate
                //{
                //    textBox4.SelectAll();
                //});
            }
    
            public void CheckAllChildNodes(TreeNode treeNode, bool bChecked)
            {
                foreach (TreeNode node in treeNode.Nodes)
                {
                    node.Checked = bChecked;
    
                    if (node.Nodes.Count > 0)
                    {
                        this.CheckAllChildNodes(node, bChecked);
                    }
                }
            }
    
            private void 不选button17_Click(object sender, EventArgs e)
            {
                foreach (TreeNode tn in treeView1.Nodes)
                {
                    tn.Checked = false;
                    CheckAllChildNodes(tn, false);
                }
            }
    
            private void 清除当前ToolStripMenuItem_Click(object sender, EventArgs e)
            {
                CheckAllChildNodes(treeView1.SelectedNode, false);
            }
    
            private void Form1_DragDrop(object sender, DragEventArgs e)
            {
                string sFileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
                string sFileDir = System.IO.Path.GetDirectoryName(sFileName);
    
    
                openFileDialog1.FileName = sFileName;
                OpenGshopdata();
            }
    
            private void Form1_DragEnter(object sender, DragEventArgs e)
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                    e.Effect = DragDropEffects.Link;
                else e.Effect = DragDropEffects.None;
            }
    
            private void 重新启动RToolStripMenuItem_Click(object sender, EventArgs e)
            {
                string sFileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                Close();
                System.Diagnostics.Process.Start(sFileName);
            }
    
    
            private void textBox4_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (修改类名称button.Enabled)
                    {
                        button5_Click(sender, e);
                        textBox4.Modified = false;
                    }
                }
            }
    
            private void textBox3_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (应用更新物品button1.Enabled)
                    {
                        button1_Click(sender, e);
                        textBox3.Modified = false;
                    }
                }
            }
    
            private void textBox3_TextChanged(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2)
                    应用更新物品button1.Enabled = true;
            }
    
    
    
            private void SelectAll(NumericUpDown numericUpDown)
            {
                numericUpDown.Select(0, numericUpDown.Value.ToString().Length);
            }
    
            private void numericUpDown3_Enter(object sender, EventArgs e)
            {
                //BeginInvoke((Action)delegate
                //{
                //    SelectAll(numericUpDown3);
                //});
            }
    
            private void textBox4_DoubleClick(object sender, EventArgs e)
            {
                textBox4.SelectAll();
            }
    
            private void numericUpDown5_Enter(object sender, EventArgs e)
            {
                //BeginInvoke((Action)delegate
                //{
                //    SelectAll(numericUpDown5);
                //});
            }
    
            private void numericUpDown6_Enter(object sender, EventArgs e)
            {
                //BeginInvoke((Action)delegate
                //{
                //    SelectAll(numericUpDown6);
                //});
            }
    
            private void numericUpDown7_Enter(object sender, EventArgs e)
            {
                //BeginInvoke((Action)delegate
                //{
                //    SelectAll(numericUpDown7);
                //});
            }
    
            private void numericUpDown12_Enter(object sender, EventArgs e)
            {
                //BeginInvoke((Action)delegate
                //{
                //    SelectAll(numericUpDown12);
                //});
            }
    
            private void numericUpDown11_Enter(object sender, EventArgs e)
            {
                //BeginInvoke((Action)delegate
                //{
                //    SelectAll(numericUpDown11);
                //});
            }
    
     
            private void SearchNodes(string SearchText, TreeNode StartNode)
            {
                TreeNode node = null;
                while (StartNode != null)
                {
                    if (StartNode.Text.ToLower().Contains(SearchText.ToLower()))
                    {
                        CurrentNodeMatches.Add(StartNode);
                    }
    
                    if (StartNode.Nodes.Count != 0)
                    {
                        SearchNodes(SearchText, StartNode.Nodes[0]);//Recursive Search 
                    }
                    StartNode = StartNode.NextNode;
                }
            }
    
            private List<TreeNode> CurrentNodeMatches = new List<TreeNode>();
            private int LastNodeIndex = 0;
            private string LastSearchText;
    
            
            private void SearchNodeText_Click(object sender, EventArgs e)
            {
                treeView1.Focus();
                string searchText = this.textBox7.Text;
                if (String.IsNullOrEmpty(searchText))
                {
                    return;
                }
    
                if (LastSearchText != searchText)
                {
                    //It's a new Search
                    CurrentNodeMatches.Clear();
                    LastSearchText = searchText;
                    LastNodeIndex = 0;
                    SearchNodes(searchText, treeView1.Nodes[0]);
    
                }
    
                if (CurrentNodeMatches.Count == 0)
                    toolStripStatusLabel3.Text = "无查找记录!";
                else
                    toolStripStatusLabel3.Text = "";
                ///  MessageBox.Show("无查找记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    
                if (LastNodeIndex >= 0 && CurrentNodeMatches.Count > 0 && LastNodeIndex < CurrentNodeMatches.Count)
                {
                    TreeNode selectedNode = CurrentNodeMatches[LastNodeIndex];
                    LastNodeIndex++;
                    this.treeView1.SelectedNode = selectedNode;
                    this.treeView1.SelectedNode.Expand();
                    this.treeView1.Select();
                }
                else
                    LastNodeIndex = 0;  
            }
    
            private void textBox7_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    SearchNodeText_Click(sender, e);
                }
            }
    
            private void textBox7_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == 13)
                {
                    e.Handled = true;
                }
            }
    
            private void cOPYToolStripMenuItem_Click(object sender, EventArgs e)
            {
                if (treeView1.SelectedNode != null)
                {
                    string s = treeView1.SelectedNode.Text;
                    System.Windows.Forms.Clipboard.SetText(s);
                }
            }
    
            private void Form1_KeyDown(object sender, KeyEventArgs e)
            {
            
            }
    
        
    
            
        }
    }
    View Code
  • 相关阅读:
    Squid报错:error the requested url could not be retriveved
    理解交换机的工作原理
    1_bytes和str
    2_Linux操作系统和基础命令行
    1_Linux概述
    好用的手机浏览器
    笔记(一):做前端开发以来几乎每天用到的东西!
    笔记(一):做前端开发以来几乎每天用到的东西!
    积累: .net里有个线程安全的int+1类
    积累: .net里有个线程安全的int+1类
  • 原文地址:https://www.cnblogs.com/xe2011/p/3576727.html
Copyright © 2020-2023  润新知