private void Client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { if (e.Error == null) { byte[] dataArray = e.Result; //ставим правильную кодировку для данных, инчае будут string page = Encoding.UTF8.GetString(dataArray); //корикозябры вместо кириллицы HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(page); //делаем страницу из string DownloaderHtmlPageArgs args = new DownloaderHtmlPageArgs(doc); FinishDownload?.Invoke(this, args); //вызываем событие, аналог if(OnPageDow!=null) } else { Program.statusBarGlobal.Message = "Ошибка подключения при запросе списка торрентов"; } }
/// <summary> /// 下载资源包函数 /// </summary> /// <param name="finishDownload"></param> /// <returns></returns> public IEnumerator StartDownload() { Debug.Log("In Start DownLoad~~~~~~~~~~~~~~||"); m_AmountOfAB = m_DownloadAssetBundleInfos.Count; if (m_DownloadAssetBundleInfos == null || m_DownloadAssetBundleInfos.Count == 0) { m_IsDone = true; m_Error = null; m_Progress = 1; yield return(null); } Debug.Log("Show DownloadAsset Count:" + m_DownloadAssetBundleInfos.Count); foreach (KeyValuePair <string, AssetBundleInfo> assetBundle in m_DownloadAssetBundleInfos) { AssetBundleInfo strcAssetBundleInfo = assetBundle.Value; WWW w = new WWW(strcAssetBundleInfo.sPath); m_Size = w.bytesDownloaded; m_DownloadedBytes += w.bytesDownloaded; Debug.Log("Show strcAssetBundleInfo.sPath: " + strcAssetBundleInfo.sPath); yield return(w); if (w.error != null) { if (string.IsNullOrEmpty(m_Error)) { m_Error = assetBundle.Key + ":" + w.error + ";"; } else { m_Error += assetBundle.Key + ":" + w.error + ";"; } Debug.Log("m_Error: " + m_Error + "@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); } else if (w.isDone) { byte[] model = w.bytes; int length = model.Length; //写入文件到本地 string sAssetBundlePath = Application.persistentDataPath; CreateModelFile(sAssetBundlePath, assetBundle.Key, model, length); m_NumOfDowloadedAB++; m_Progress = (float)m_NumOfDowloadedAB / m_AmountOfAB; Debug.Log("Create File Over~~~~~~~~~~~~~~"); //写入本地记录 if (m_LocalAssetBundleInfos.ContainsKey(assetBundle.Key)) { m_LocalAssetBundleInfos[assetBundle.Key].sPath = strcAssetBundleInfo.sPath; m_LocalAssetBundleInfos[assetBundle.Key].sVersion = strcAssetBundleInfo.sVersion; } else { m_LocalAssetBundleInfos.Add(assetBundle.Key, assetBundle.Value); } //保存信息文件到本地 if (string.IsNullOrEmpty(m_Error) || !m_Error.Contains(assetBundle.Key)) { string fileName = Application.persistentDataPath + "/" + ConstString.sAssetBundleInfoXML; AssetBundleXMLUtils.saveLocalInfo(m_LocalAssetBundleInfos, fileName); } } } Debug.Log("DownLoad Done~~~~~~~~~~~"); m_IsDone = true; if (FinishDownloadDelegate != null) { FinishDownloadDelegate(); FinishDownloadDelegate = null; } }