コード例 #1
0
        string GetTmpFilePath(ABInfo abInfo)
        {
            string path = CUtils.PathCombine(outputPath, abInfo.abName);

            return(path);
        }
コード例 #2
0
        void OnDownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            WebDownload webd = (WebDownload)sender;

            object[]        arr    = (object[])webd.userData;
            ABInfo          abInfo = null;
            BackGroundQueue bQueue = null;

            webd.tryTimes++;
            int tryTimes = webd.tryTimes;

            if (arr != null && arr.Length >= 2)
            {
                abInfo = ((ABInfo)arr[0]);
                bQueue = (BackGroundQueue)arr[1];
            }

#if !HUGULA_RELEASE
            // Debug.LogFormat ("background ab:{0}\r\n is completed,error:{1}", abInfo.abName, e.Error==null? string.Empty : e.Error.Message);
#endif
            if (e.Error != null)
            {
                if (tryTimes <= hosts.Length * 3)
                {
                    int i = tryTimes % hosts.Length;
                    Debug.LogWarning(string.Format("background download error ab:{0}, tryTimes={1},host={2},error:{3}", abInfo.abName, webd.tryTimes, hosts[i], e.Error));
                    RealLoad(webd, abInfo, bQueue, hosts[i], tryTimes.ToString());
                    return;
                }
                else
                {
                    Debug.LogErrorFormat("background download error message {0} \r\n trace {1}", e.Error.Message, e.Error.StackTrace);
                    abInfo.state = ABInfoState.None; // none or fail?
                    webClients.Add(arr);
                    ReleaseWebDonwLoad(webd, abInfo);
                }
            }
            else
            {
                string   path    = GetTmpFilePath(abInfo);
                FileInfo tmpFile = new FileInfo(path);
                if (tmpFile.Length == abInfo.size) //check size
                {
                    abInfo.state = ABInfoState.Success;
                    webClients.Add(arr);
                    ReleaseWebDonwLoad(webd, abInfo);
                }
                else if (tryTimes <= hosts.Length * 3)
                {
                    int    i     = tryTimes % hosts.Length;
                    string error = string.Format("background complete length check is wrong ab:{0} ,(length:{1}!=size:{2}) crc={3},tryTimes{4},host:{5}", abInfo.abName, tmpFile.Length, abInfo.size, tryTimes, abInfo.crc32, hosts[i]);
                    Debug.LogWarning(error);
                    tmpFile.Delete();  //删除错误文件
                    RealLoad(webd, abInfo, bQueue, hosts[i], tryTimes.ToString());
                    return;
                }
                else
                {
                    string error = string.Format("background complete length check is wrong tryMaxTimes:{4} .ab:{0} (length:{1}!=size:{2}) crc={3},host:{5}", abInfo.abName, tmpFile.Length, abInfo.size, abInfo.crc32, tryTimes, hosts[tryTimes % hosts.Length]);
                    Debug.LogWarning(error);
                    abInfo.state = ABInfoState.None; // none or fail?
                    webClients.Add(arr);
                    ReleaseWebDonwLoad(webd, abInfo);
                }
            }
        }
コード例 #3
0
 void ReleaseWebDonwLoad(WebDownload webd, ABInfo aBInfo)
 {
     lock (syncRoot) {
         WebDownload.Release(webd);
     }
 }