Example #1
0
        public static bool SafetyDownloadFile(string strFileName, string strUrl, int trytimes = 5, string fileServerMD5 = "")
        {
            int  i = 0;
            bool result;

            while (i < trytimes)
            {
                i++;
                bool flag  = HttpbrokenDownloader.BrokenDownloadFile(strFileName, strUrl);
                bool flag2 = flag;
                if (flag2)
                {
                    bool flag3 = !string.IsNullOrEmpty(fileServerMD5);
                    if (flag3)
                    {
                        bool flag4 = MD5Helper.GetFileMD5(strFileName) != fileServerMD5;
                        if (flag4)
                        {
                            File.Delete(strFileName);
                            continue;
                        }
                    }
                    result = true;
                    return(result);
                }
                Thread.Sleep(1000);
            }
            result = true;
            return(result);
        }
Example #2
0
        private static bool DownloadRange(string strURL, string fname, int startindex, int endindex)
        {
            bool result;

            try
            {
                Uri            requestUri     = new Uri(strURL);
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUri);
                httpWebRequest.AddRange(startindex, endindex);
                using (Stream responseStream = httpWebRequest.GetResponse().GetResponseStream())
                {
                    int    num     = endindex - startindex;
                    byte[] array   = new byte[num];
                    int    datalen = responseStream.Read(array, 0, num);
                    HttpbrokenDownloader.WriteDataToFile(fname, startindex, array, datalen);
                }
                result = true;
            }
            catch
            {
                result = false;
            }
            return(result);
        }