Esempio n. 1
0
File: setIP.cs Progetto: radtek/KGC
        private void setIP_Load(object sender, EventArgs e)
        {
            #region IP和端口信息的读取和档文件ipMsg.txt不存在时的初始化
            //读取ipMsg.txt中的IP配置
            try
            {
                string a1, a2, a3, a4, port;
                a1 = a2 = a3 = a4 = port = "";
                int b1, b2, b3, b4, i;
                b1 = b2 = b3 = b4 = i = 0;
                //自己写的文件读写类
                file re = new file();
                //reader()为返回从指定文件都出来的数据,其参数为文件路径
                //string read = re.reader("..\\..\\..\\..\\ipMsg.txt");
                //
                string read   = re.reader("ipMsg.txt");
                int    length = read.Length;

                while (true)
                {
                    if (b1 == 0 && b2 == 0 && b3 == 0)
                    {
                        if (read[i].ToString() == ".")
                        {
                            b1 = 1;
                            i++;
                        }
                        else
                        {
                            a1 += read[i];
                        }
                    }
                    if (b1 == 1 && b2 == 0 && b3 == 0)
                    {
                        if (read[i].ToString() == ".")
                        {
                            b2 = 1;
                            i++;
                        }
                        else
                        {
                            a2 += read[i];
                        }
                    }
                    if (b1 == 1 && b2 == 1 && b3 == 0)
                    {
                        if (read[i].ToString() == ".")
                        {
                            b3 = 1;
                            i++;
                        }
                        else
                        {
                            a3 += read[i];
                        }
                    }
                    if (b1 == 1 && b2 == 1 && b3 == 1 && b4 == 0)
                    {
                        if (read[i].ToString() == ":")
                        {
                            b4 = 1;
                            i++;
                        }
                        else
                        {
                            a4 += read[i];
                        }
                    }
                    if (b1 == 1 && b2 == 1 && b3 == 1 && b4 == 1)
                    {
                        if (i == length)
                        {
                            break;
                        }
                        else
                        {
                            port += read[i];
                        }
                    }
                    i++;
                }
                textBox1.Text = a1;
                textBox2.Text = a2;
                textBox3.Text = a3;
                textBox4.Text = a4;
                textBox5.Text = port;
            }
            //当文件不存在的时候新建初并始化ipMsg.txt
            catch
            {
                string ipStr = textBox1.Text.Trim() + "." + textBox2.Text.Trim() + "." + textBox3.Text.Trim() + "." + textBox4.Text.Trim() + ":" + textBox5.Text.Trim();
                //自己写的文件读写类
                file wd = new file();
                //writer()函数第一个参数为文件名字、第二个为要写如文件的名字
                wd.writer("ipMsg.txt", ipStr);
                //wd.writer("..\\..\\..\\..\\ipMsg.txt", ipStr);
            }
            #endregion
        }
Esempio n. 2
0
File: kgcKey.cs Progetto: radtek/KGC
        private void kgcKey_Load(object sender, EventArgs e)
        {
            file file = new file();

            textBox1.Text = des.Decrypt(file.reader("pk.txt"), "abcdefgh");
        }