Exemplo n.º 1
0
        private void button_import_Click(object sender, System.EventArgs e)
        {
            OpenCfgFileDlg dlg = new OpenCfgFileDlg();

            dlg.Font = GuiUtil.GetDefaultFont();

            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
            {
                return;
            }

            this.Mime      = dlg.textBox_mime.Text;
            this.LocalPath = dlg.textBox_localPath.Text;
            using (Stream s = File.OpenRead(this.LocalPath))
            {
                if (s.Length > 1024 * 1024)
                {
                    MessageBox.Show(this, "配置文件尺寸不能大于1M");
                    return;
                }

                byte[] buffer = new byte[s.Length];
                s.Read(buffer, 0, (int)s.Length);

                this.Stream = new MemoryStream(buffer);
            }

            //
            if (this.IsText == true)
            {
                if (this.Stream != null)
                {
                    this.Stream.Seek(0, SeekOrigin.Begin);
                    using (StreamReader sr = new StreamReader(this.Stream, Encoding.UTF8))
                    {
                        this.textBox_content.Text = sr.ReadToEnd();
                    }
                }
            }

            button_OK.Enabled = true;
        }
Exemplo n.º 2
0
        private void button_import_Click(object sender, System.EventArgs e)
        {
            OpenCfgFileDlg dlg = new OpenCfgFileDlg();
            dlg.Font = GuiUtil.GetDefaultFont();

            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
                return;

            this.Mime = dlg.textBox_mime.Text;
            this.LocalPath = dlg.textBox_localPath.Text;
            using (Stream s = File.OpenRead(this.LocalPath))
            {
                if (s.Length > 1024 * 1024)
                {
                    MessageBox.Show(this, "配置文件尺寸不能大于1M");
                    return;
                }

                byte[] buffer = new byte[s.Length];
                s.Read(buffer, 0, (int)s.Length);

                this.Stream = new MemoryStream(buffer);
            }

            //
            if (this.IsText == true)
            {
                if (this.Stream != null)
                {
                    this.Stream.Seek(0, SeekOrigin.Begin);
                    using (StreamReader sr = new StreamReader(this.Stream, Encoding.UTF8))
                    {
                        this.textBox_content.Text = sr.ReadToEnd();
                    }
                }
            }

            button_OK.Enabled = true;
        }