前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >公司禁用用迅雷,禁用所有P2P协议的软件,自己写个断点续传的工具

公司禁用用迅雷,禁用所有P2P协议的软件,自己写个断点续传的工具

作者头像
liulun
发布2022-05-09 11:15:46
3870
发布2022-05-09 11:15:46
举报
文章被收录于专栏:liulunliulun

目前仅支持HTTP协议

下一步的工作是支持FTP协议

再下一步的工作是对原始URL进行智能分析

发此文以抗议像吉日兄这样的总监或者老板

代码语言:javascript
复制
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();            
        }
        private void DownLoad()
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("D:\\中转\\data.xml");
            XmlNodeList nodeList = xmlDoc.SelectSingleNode("data").ChildNodes;
            XmlElement xe = (XmlElement)nodeList.Item(nodeList.Count - 1);
            if (xe.GetAttribute("is_finish").Equals("true"))
            {
                MessageBox.Show("none task in the list");
                return;
            }
            string StrFileName = "D:\\中转\\" + xe.GetAttribute("name"); 
            string StrUrl = xe.GetAttribute("address");
            long lStartPos = 0;
            System.IO.FileStream fs;
            if (System.IO.File.Exists(StrFileName))
            {
                fs = System.IO.File.OpenWrite(StrFileName);
                lStartPos = fs.Length;
                fs.Seek(lStartPos, System.IO.SeekOrigin.Current); //移动文件流中的当前指针
            }
            else
            {
                fs = new System.IO.FileStream(StrFileName, System.IO.FileMode.Create);
                lStartPos = 0;
            }
            //打开网络连接
            try
            {
                System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(StrUrl);
                if (lStartPos > 0)
                    request.AddRange((int)lStartPos); //设置Range值
                //向服务器请求,获得服务器回应数据流
                System.IO.Stream ns = request.GetResponse().GetResponseStream();
                byte[] nbytes = new byte[512];
                int nReadSize = 0;
                nReadSize = ns.Read(nbytes, 0, 512);                
                while (nReadSize > 0)
                {
                    fs.Write(nbytes, 0, nReadSize);
                    nReadSize = ns.Read(nbytes, 0, 512);
                }
                fs.Close();
                ns.Close();
                EditNode();
                MessageBox.Show("Down Ok!");
            }
            catch (Exception ex)
            {
                fs.Close();
                MessageBox.Show("Down Error!");
            }
        }
        private void notifyIcon1_MouseClick(object sender, MouseEventArgs e)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("D:\\中转\\data.xml");
            XmlNodeList nodeList = xmlDoc.SelectSingleNode("data").ChildNodes;
            XmlElement xe = (XmlElement)nodeList.Item(nodeList.Count - 1);
            string StrFileName = "D:\\中转\\" + xe.GetAttribute("name");
            FileInfo fi = new FileInfo(StrFileName);
            DialogResult dr = MessageBox.Show(this, string.Format("already:{0}kb\nOK:exit\ncancel:continue", fi.Length / 1024), "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
            if (!dr.Equals(DialogResult.Cancel))
            {
                this.Close();
                this.Dispose();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            if (!string.IsNullOrEmpty(textBox1.Text.Trim())&&!string.IsNullOrEmpty(textBox2.Text.Trim()))
            {
                InsertNode();
            }
            System.Threading.Thread obj = new System.Threading.Thread(new System.Threading.ThreadStart(this.DownLoad));
            //设置为前台线程,即使主方法执行结束了我的线程仍在执行
            obj.IsBackground = true;
            obj.Start();
        }
        private void EditNode()
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("D:\\中转\\data.xml");
            XmlNodeList nodeList = xmlDoc.SelectSingleNode("data").ChildNodes;
            XmlElement xe = (XmlElement)nodeList.Item(nodeList.Count - 1);
            xe.SetAttribute("is_finish", "true");
            xmlDoc.Save("D:\\中转\\data.xml");//保存。
        }
        private void InsertNode()
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("D:\\中转\\data.xml");
            XmlNode root = xmlDoc.SelectSingleNode("data");
            XmlElement xe1 = xmlDoc.CreateElement("file");
            xe1.SetAttribute("name", textBox1.Text.Trim());
            xe1.SetAttribute("address", textBox2.Text.Trim());
            xe1.SetAttribute("is_finish", "false");
            root.AppendChild(xe1);
            xmlDoc.Save("D:\\中转\\data.xml");
        }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2009-10-27,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档