示例#1
0
        private HttpLoadHelper GetHttpLoadHelper(DownFileVO downFileVO, UpdateEventHandler completeLoadHandler, bool isLocal = true, bool needSave = false)
        {
            HttpLoadHelper htttpLoadHelper = new HttpLoadHelper();

            htttpLoadHelper.completeLoadHandler = completeLoadHandler;
            htttpLoadHelper.FileVO   = downFileVO;
            htttpLoadHelper.NeedSave = needSave;
            htttpLoadHelper.TimeOut  = timeOut;
            htttpLoadHelper.IsLocal  = isLocal;
            return(htttpLoadHelper);
        }
示例#2
0
    public override void GetWebFile(DownFileVO downFileVO, UpdateEventHandler completeLoadHandler, bool needSave)
    {
        try
        {
            string headHost   = ResUpdateManager.Instance.updateModel.HeadHost;
            string serverHost = ResUpdateManager.Instance.updateModel.ServerHost;
            int    port       = ResUpdateManager.Instance.updateModel.Port;

            this.completeLoadHandler = completeLoadHandler;
            this.bytes = new List <byte>();
            string query = string.Empty;
            string path  = "http://" + downFileVO.DownFilePath;
            query = "GET " + path.Replace(" ", "%20") + " HTTP/1.1\r\n" +
                    "Host: " + headHost + "\r\n" +
                    "User-Agent: undefined\r\n" +
                    "Cache-control: no-cache\r\n" +
                    "Connection: close\r\n" +
                    "\r\n";

            client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            client.Connect(serverHost, port);

            networkStream = new NetworkStream(client);

            byte[] bytes = Encoding.Default.GetBytes(query);
            networkStream.Write(bytes, 0, bytes.Length);

            BinaryReader bReader = new BinaryReader(networkStream, Encoding.Default);

            string response = "";
            string line;
            char   c;

            //read head
            do
            {
                line = "";
                c    = '\u0000';
                while (true)
                {
                    c = bReader.ReadChar();
                    if (c == '\r')
                    {
                        break;
                    }
                    line += c;
                }
                c         = bReader.ReadChar();
                response += line + "\r\n";
            }while (line.Length > 0);


            Regex  reContentLength = new Regex(@"(?<=Content-Length:\s)\d+", RegexOptions.IgnoreCase);
            string value           = reContentLength.Match(response).Value;
            if (!string.IsNullOrEmpty(value))
            {
                contentLength = uint.Parse(reContentLength.Match(response).Value);
            }
            else
            {
                contentLength = 0;
            }
            Main.RegisterUpdateCallback(this.Update);
        }
        catch (Exception ex)
        {
            string error = string.Format("TcpLoad version 开始下载失败,错误信息:{0}", ex.ToString());
            if (this.ErrorHandler != null)
            {
                this.ErrorHandler(error);
            }
        }
    }
示例#3
0
 public override void GetWebFile(DownFileVO downFileVO, UpdateEventHandler completeLoadHandler, bool needSave)
 {
     listHttpLoadHelper.Add(GetHttpLoadHelper(downFileVO, completeLoadHandler, false, needSave));
 }
示例#4
0
 public virtual void GetWebFile(DownFileVO downFileVO, UpdateEventHandler completeLoadHandler, bool needSave)
 {
 }