Пример #1
0
 public void OnEnd(fileinfo ff, bool isOK)
 {
     if (all_num > 0)
     {
         showProcess(num++, all_num);
     }
     if (!isOK)
     {
         if (ff != null)
         {
             Console.WriteLine("DOWNLOAD FAILED:" + Config.GetUrl(ff.name));
             errorlist.Add(ff);
         }
         else
         {
             Console.WriteLine("DOWNLOAD FAILED");
         }
     }
     else
     {
         if (ff != null)
         {
             Console.WriteLine("DOWNLOAD COMPLETE:" + ff.name);
         }
     }
 }
Пример #2
0
        public static bool DownLoad(string url, string filename, fileinfo ff)
        {
            if (myhttplistiner != null)
            {
                myhttplistiner.OnStart(url, filename);
            }
            bool isOK = false;

            try
            {
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }
                else
                {
                    MyUtil.createDir(filename);
                }
                HttpWebRequest Myrq = (HttpWebRequest)System.Net.HttpWebRequest.Create(url);
                Myrq.Timeout = 30000;
                //Myrq.UserAgent="Mozilla/5.0 (Windows NT 6.2; WOW64) "
                //	+"AppleWebKit/537.36 (KHTML, like Gecko) "
                //	+"Chrome/27.0.1453.94 Safari/537.36";
                if (MyHttp.isProxy)
                {
                    Myrq.Proxy = new WebProxy(MyHttp.proxyip, MyHttp.proxyport);
                }

                HttpWebResponse myrp       = (HttpWebResponse)Myrq.GetResponse();
                long            totalBytes = myrp.ContentLength;

                Stream st = myrp.GetResponseStream();
                Stream so = new System.IO.FileStream(filename + ".tmp", FileMode.Create);
                long   totalDownloadedByte = 0;
                byte[] by    = new byte[2048];
                int    osize = st.Read(by, 0, (int)by.Length);
                while (osize > 0)
                {
                    totalDownloadedByte = osize + totalDownloadedByte;
                    so.Write(by, 0, osize);
                    osize = st.Read(by, 0, (int)by.Length);
                }
                so.Close();
                st.Close();
                File.Delete(filename);
                File.Move(filename + ".tmp", filename);
            }
            catch (System.Exception)
            {
                isOK = false;
            }
            isOK = File.Exists(filename);
            if (myhttplistiner != null)
            {
                myhttplistiner.OnEnd(ff, isOK);
            }
            return(isOK);
        }
Пример #3
0
 public MyHttp(string url, string filename, fileinfo ff)
 {
     this._url      = url;
     this._filename = filename;
     this._ff       = ff;
 }