資源簡介
【版本已更新:http://download.csdn.net/source/1687395】
半成品,還有以下幾部分未完成:
1、斷點續傳;(方法都在,代碼沒調好,就先注釋掉了)
(就是保存當前下載信息,下次重新讀取,最簡單的做法就是序列化,要用到的自己改改調調就成)
2、自定義下載窗體;
(就像 MessageBox.Show() 一樣,已經做了一個簡單的Form)
3、部分細節沒做好,可能存在BUG;
(用著,遇到再說)
涉及的一些應用:
多線程 -- 沒用線程池,因為不好控制狀態;
事件驅動 -- 自我感覺不是很好,最好誰能改改;
另外,組件的封裝也沒仔細整理過~
期待有人能做個完美的組件。
應用范圍:文件下載、在線升級
(這個組件就是為了下載升級文件而做的……)
使用示例:(添加DLL引用)
List DTaskList = new List();
foreach ( …… )
{
DownloadMag.DTask dt = new DTask();
dt.Name = "任務名";
dt.FileName = "文件名";
dt.Size = 文件大小;
dt.URL = "下載地址";
dt.CRC32 = CRC32校驗值;
dt.SaveMode = true;
DTaskList.Add(dt);
}
new DownloadMag.DownloadForm(this).Show(DTaskList.ToArray(), "下載信息文件名");
沒時間修修改改,所以把這個半成品放出來了,也就當時拋磚引玉吧。
誰有興趣有空閑就提提意見,找找Bug,最好是把它做完美了 :)
意見請提到:http://blog.csdn.net/0xff/archive/2007/11/01/1861780.aspx

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.IO;
namespace?DownloadMag
{
????///?
????///?CRC32校驗
????///?
????public?sealed?class?CRC32
????{
????????static?CRC32()
????????{
????????????GetCRC32Table();
????????}
????????private?static?ulong[]?Crc32Table;
????????
????????///?
????????///?生成CRC32碼表
????????///?
????????private?static?void?GetCRC32Table()?
????????{
????????????ulong?Crc;
????????????Crc32Table?=?new?ulong[256];
????????????int?ij;
????????????for(i?=?0;i?256;?i++)?
????????????{
????????????????Crc?=?(ulong)i;
????????????????for?(j?=?8;?j?>?0;?j--)
????????????????{
????????????????????if?((Crc?&?1)?==?1)
????????????????????????Crc?=?(Crc?>>?1)?^?0xEDB88320;
????????????????????else
????????????????????????Crc?>>=?1;
????????????????}
????????????????Crc32Table[i]?=?Crc;
????????????}
????????}
????????///?
????????///?字節數組校驗
????????///?
????????///?ref?字節數組
????????///?
????????public?static?ulong?ByteCRC(ref?byte[]?buffer)
????????{
????????????ulong?value?=?0xffffffff;
????????????ulong?len?=?(ulong)buffer.Length;
????????????for?(ulong?i?=?0;?i?????????????{
????????????????value?=?(value?>>?8)?^?Crc32Table[(value?&?0xFF)?^?buffer[i]];
????????????}
????????????return?value?^?0xffffffff;
????????}
????????///?
????????///?字符串校驗
????????///?
????????///?字符串
????????///?
????????public?static?ulong?StringCRC(string?sInputString)
????????{
????????????byte[]?buffer?=?Encoding.ASCII.GetBytes(sInputString);
????????????return?ByteCRC(ref?buffer);
????????}
????????///?
????????///?文件校驗
????????///?
????????///?文件名
????????///?
????????public?static?ulong?FileCRC(string?sInputFilename)
????????{
????????????FileStream?inFile?=?new?System.IO.FileStream(sInputFilename?System.IO.FileMode.Open?System.IO.FileAccess.Read);
????????????byte[]?bInput?=?new?byte[inFile.Length];
????????????inFile.Read(bInput?0?bInput.Length);
????????????inFile.Close();
????????????return?ByteCRC(ref?bInput);
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1332??2007-11-01?17:43??Properties\AssemblyInfo.cs
?????文件???????2844??2007-08-08?15:45??Properties\Resources.Designer.cs
?????文件???????5817??2007-07-19?15:40??Properties\Resources.resx
?????文件???????2383??2007-08-14?13:39??CRC32.cs
?????文件??????27325??2007-11-01?17:21??Download.cs
?????文件??????13905??2007-11-01?17:18??DownloadForm.cs
?????文件??????37995??2007-08-26?14:08??DownloadForm.Designer.cs
?????文件??????26773??2007-08-26?14:08??DownloadForm.resx
?????文件???????3554??2007-11-01?17:43??DownloadMag.csproj
?????文件??????40407??2007-11-01?17:04??DTask.cs
?????文件??????10005??2007-09-23?15:09??MsgBox.cs
?????文件??????15339??2007-08-08?15:47??MsgBox.Designer.cs
?????文件??????47754??2007-07-26?09:56??MsgBox.resx
?????文件???????5270??2007-11-01?17:20??WMessage.cs
?????文件???????1406??2005-08-03?09:36??images\down.ico
?????文件???????1406??2005-08-03?09:36??images\ok.ico
?????文件???????1406??2005-08-03?09:36??images\point_blue.ico
?????文件???????1406??2005-08-03?09:36??images\point_cyan.ico
?????文件???????1406??2005-08-03?09:36??images\point_green.ico
?????文件???????1406??2005-08-03?09:36??images\point_red.ico
?????文件???????1406??2005-08-03?09:36??images\point_yellow.ico
?????文件???????1406??2005-08-03?09:36??images\right.ico
?????文件???????1406??2005-08-03?09:36??images\stop.ico
?????目錄??????????0??2007-11-01?17:44??Properties
?????目錄??????????0??2007-11-01?17:34??images
-----------?---------??----------?-----??----
???????????????253357????????????????????25
- 上一篇:C#銀行家算法界面
- 下一篇:C#多任務多線程組件V1.1源代碼
評論
共有 條評論