公司禁用用迅雷,禁用所有P2P协议的软件,自己写个断点续传的工具
2009-10-27 19:09
357 查看
目前仅支持HTTP协议
下一步的工作是支持FTP协议
再下一步的工作是对原始URL进行智能分析
发此文以抗议像吉日兄这样的总监或者老板
Code
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");
}
下一步的工作是支持FTP协议
再下一步的工作是对原始URL进行智能分析
发此文以抗议像吉日兄这样的总监或者老板
Code
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");
}
相关文章推荐
- 实现HTTP断点续传下载工具(附源代码)
- 怎样选择适合自己当前环境的软件配置管理工具
- 请问大家,知不知道,现在有没有点对点,P2P的流媒体软件吗?或者什么公司或者个人已经有产品了?
- 由于一个或多个其它网络页属性已经打开,这个属性页上的部分控件被禁用,要想使用这些软件,请先关闭所有属性页,然后将这个属性页重新打开
- 公司禁用即时通讯工具引发的思考
- wap获取手机号码,今天uc开启云加速,用公司的工具类获取是null,但是另外一个项目可以,应该这个项目的工具旧少了一些代码。。,网上找了 方法自己加可以
- <仅是自己做笔记。。。系列x>所有系列题目都来自v_JULY_v前辈的:精选微软等公司经典的算法面试100题
- 为什么大的网络公司都选择开源软件作为其主要开发工具和平台?
- 如何做一个软件项目经理? ----写给公司所有的开发人员
- LINQ技术、EF技术都出来蛮久了,软件开发者、软件公司是否还有必要有自己的代码生成器?
- android软件工程师请进(说说自己公司的软件人员配置)
- Java网络编程之实现HTTP断点续传下载工具(附源代码)
- Linux下多线程,断点续传,命令行下载工具axel
- 在你的solution里面到底有多少projects? 小型软件公司如何更快的建立自己的Framework.
- C#软件开发实例.私人订制自己的屏幕截图工具(八)添加键盘操作截图的功能
- 最近刚为公司完成的一款监视的小工具软件!用DELPHI 7 写的,可以从后台监控系统﹑键盘﹑鼠标﹑屏幕以及文件与目录!有源码!
- 类似迅雷下载实现大文件断点续传
- Java网络编程从入门到精通(24):实现HTTP断点续传下载工具(附源代码)
- 中国人自己的VB:HB++.(网络)应用软件的专业开发工具
- JSP禁用迅雷等下载工具下载文件,强制使用右键另存功能下载文件