private void DownLoadFiles() { if (mUpdateList.Count <= 0) { mCompleteCall(); return; } FileUtils.CreateDirectory(Paths.PersistentDataPath); string path = mServerUrl + string.Format("{0}/{1}/{2}", Main.Inst.Version, Paths.PlatformName, "files.txt"); string savePath = Paths.PersistentDataPath + "files.txt"; bool state = HttpDownLoad.DownLoadFile(path, savePath); if (!state) { mErrorCall("热更差异化文件下载失败!"); return; } mProgress.Reset(); mProgress.TotalNum = mUpdateList.Count; foreach (var dic in mUpdateList) { mProgress.TotalSize += dic.Value.size; } foreach (var dic in mUpdateList) { var info = dic.Value; string url = mServerUrl + string.Format("{0}/{1}/", Main.Inst.Version, Paths.PlatformName); savePath = Paths.PersistentDataPath + info.name.Replace("\\", "/"); DownLoadManager.Inst.StartDownload(info.name, url, savePath, info.size, info.crc, OnProcess, OnFinish); } }
static void Main(string[] args) { logger.Info("-------------Starting NAV Download-------------"); DownloadLogVo downloadLogVo = new DownloadLogVo(); downloadLogVo.ID = DownloadLog.Add(); if (downloadLogVo.ID > 0) { HttpDownLoad dn = new HttpDownLoad(); DownloadTask dt = new DownloadTask(TaskType.MutualFund); if (dn.ExecuteDownLoadTask(dt, downloadLogVo)) { NAVUpload navUpload = new NAVUpload(); navUpload.CopyDataToWERPTempTable(); navUpload.UpdateWERPSchemeCode(); downloadLogVo.RejectedSchemesCount = navUpload.MoveRejectedRecords(downloadLogVo.ID); DownloadLog.Update(downloadLogVo); downloadLogVo.UpdatedSchemesCount = navUpload.UpdateSnapshot(); downloadLogVo.Is_WERP_Snapshot_Updated = true; DownloadLog.Update(downloadLogVo); //navUpload.UpdateHistoryTable(); } } logger.Info("-------------NAV Update Ends-------------"); }
public static async Task HttpDownLoadRecordTask(string url, string path, CancellationTokenSource cts) { var instance = new HttpDownLoad(url, path, true); var ctsEndTask = new CancellationTokenSource(); cts.Token.Register(() => { if (!ctsEndTask.IsCancellationRequested) { ctsEndTask.Cancel(); } }); ctsEndTask.Token.Register(() => { instance.Stop(); }); try { await instance.Start(); ctsEndTask.Cancel(); } catch { // ignored } }
void downloads() { GameObject middleLastObj = Middle.transform.GetChild(Middle.transform.childCount - 1).gameObject; if (middleLastObj == gameObject) { if (file == false) { http3 = new HttpDownLoad(); //下载bundle并LoadScene http3.DownLoad(RemoteIP + fileName, savePath, fileName, http3DownLoadState); //BUndle下载优先级最高 } else { load += func; if (file == true) { if (returnHall == false) { func(); } else { GameObject load = Instantiate(gameContrall.instant.Loading, GameObject.Find("Canvas").transform) as GameObject; gameContrall.instant.catchFish(changci, gameObject); } } } start_download = true; } }
async void Update() { while (true) { if (isFinished) { httpDownLoad.Close(); httpDownLoad = null; var savepath = Path.Combine(Application.persistentDataPath, fileName).Replace('\\', '/'); PlaceUnZipFiles(savepath); isFinished = false; } else { var state = model.GetState(); if (httpDownLoad != null) { if (httpDownLoad.Progress > 0.3f && httpDownLoad.Progress < 0.5f) { state.tip = $"下载及解压过程中请勿关闭软件[{HumanReadableFilesize((long)(httpDownLoad.fileLength))}/{HumanReadableFilesize(httpDownLoad.TotalLength)}]({HumanReadableFilesize(httpDownLoad.BytePerSecond)}/S)"; } else { state.tip = $"{tip}[{HumanReadableFilesize((long)(httpDownLoad.fileLength))}/{HumanReadableFilesize(httpDownLoad.TotalLength)}]({HumanReadableFilesize(httpDownLoad.BytePerSecond)}/S)"; } state.progress = httpDownLoad.Progress * 100; } model.SetState(state); } await new WaitForEndOfFrame(); } }
public override JobStatus Start(JobParams JP, out string ErrorMsg) { ErrorMsg = ""; logger.Info("-------------Starting NAV Download-------------"); DownloadLogVo downloadLogVo = new DownloadLogVo(); downloadLogVo.ID = DownloadLog.Add(); if (downloadLogVo.ID > 0) { HttpDownLoad dn = new HttpDownLoad(); DownloadTask dt = new DownloadTask(TaskType.MutualFund); if (dn.ExecuteDownLoadTask(dt, downloadLogVo)) { NAVUpload navUpload = new NAVUpload(); navUpload.CopyDataToWERPTempTable(); navUpload.UpdateWERPSchemeCode(); downloadLogVo.RejectedSchemesCount = navUpload.MoveRejectedRecords(downloadLogVo.ID); DownloadLog.Update(downloadLogVo); downloadLogVo.UpdatedSchemesCount = navUpload.UpdateSnapshot(); downloadLogVo.Is_WERP_Snapshot_Updated = true; DownloadLog.Update(downloadLogVo); //navUpload.UpdateHistoryTable(); } } logger.Info("-------------NAV Update Ends-------------"); return(JobStatus.SuccessFull); }
private void DoDownLoad(string strUrl, System.Action callBack) { Debug.Log("_DownLoad " + strUrl); HttpDownLoad _aHttpDownLoad = new HttpDownLoad(); _aHttpDownLoad.DownLoad(strUrl, ResourceManager.Instance.PersistentDataPath, callBack); }
void ComparerVersion() { if (!couldComparerVersion) { return; } couldComparerVersion = false; Logger.LogWarp.Log("ComparerVersion"); Logger.LogWarp.Log(Path.Combine(localDownLoadRoot, versionFileName)); string localVersion = GetGameVersion2(Path.Combine(localDownLoadRoot, versionFileName)); string serverVersion = GetGameVersion2(Path.Combine(localDownLoadRoot, versionFileNameTmp)); Logger.LogWarp.Log("localVersion=" + localVersion + " serverVersion=" + serverVersion); int retCode = ComparerVersion(serverVersion, localVersion); //服务器版本大 if (retCode >= 0) { var http = new HttpDownLoad(); Dictionary <string, string> urls = new Dictionary <string, string>(); urls.Add(this.serverDownloadUrl + this.assetbundleFileName, assetbundleFileNameTmp); urls.Add(this.serverDownloadUrl + this.bundleHashFileName, bundleHashFileNameTmp); urls.Add(this.serverDownloadUrl + this.manifestFileName, manifestFileNameTmp); http.DownLoads(urls, localDownLoadRoot, true, DownLoadDetailCallback); } else { updateFinished = true; } }
public void Update() { if (HttpCallBackList != null) { while (HttpCallBackList.Count > 0) { HttpCallBackList[0].Invoke(); HttpCallBackList.RemoveAt(0); } } if (HttpDownLoadList != null) { while (HttpDownLoadList.Count > 0 && !downLoad) { downLoad = true; curDownLoad = HttpDownLoadList[0]; HttpDownLoadList.RemoveAt(0); curDownLoad.Invoke(); } } if (HttpUpLoadList != null) { while (HttpUpLoadList.Count > 0 && !upLoad) { upLoad = true; curUpLoad = HttpUpLoadList[0]; HttpUpLoadList.RemoveAt(0); curUpLoad.Invoke(); } } }
public async Task HttpDownLoadTest() { const int roomId = 23058; var playUrl = BililiveApi.GetPlayUrlAsync(roomId).Result; Assert.IsTrue(playUrl.StartsWith(@"https://")); const string path = @"D:\Downloads\test.flv"; var instance = new HttpDownLoad(playUrl, path, true); #pragma warning disable 4014 Task.Delay(10000).ContinueWith(task => #pragma warning restore 4014 { instance.Dispose(); }); await instance.Start().ContinueWith(task => { Console.WriteLine(task.Status); Console.WriteLine(task.IsCanceled); Console.WriteLine(task.IsCompleted); Console.WriteLine(task.IsCompletedSuccessfully); instance.Dispose(); }); }
void Start() { http = new HttpDownLoad(); HttpDownLoad.ThreadParam param = new HttpDownLoad.ThreadParam(); param.m_nID = 1; param.m_strURL = @"http://127.0.0.1/SharpZipLib_0860_Bin.zip"; param.m_strSavePath = Application.streamingAssetsPath; param.callBack = ThreadCallBack; bool ret = ThreadPool.QueueUserWorkItem(http.DownLoad, param); if (!ret) { UnityEngine.Debug.LogError(""); } HttpDownLoad.ThreadParam param1 = new HttpDownLoad.ThreadParam(); param1.m_nID = 2; param1.m_strURL = @"http://127.0.0.1/main.6.com.top1game.rotdgp.zip"; param1.m_strSavePath = Application.streamingAssetsPath; param1.callBack = ThreadCallBack; bool ret1 = ThreadPool.QueueUserWorkItem(http.DownLoad, param1); if (!ret1) { UnityEngine.Debug.LogError(""); } }
//开启下载 public void DownloadNow() { //初始化 showProgress.Set_Progress("正在下载模型..."); //, CannelDownload); ndr = 0; http = new HttpDownLoad(); DebugLog.DebugLogInfo("开始下载!"); DownSwitch(); }
public void DownLoadServerVersionInfomation() { if (!couldDownLoadServerVersion) { return; } couldDownLoadServerVersion = false; var http = new HttpDownLoad(); http.DownLoad(this.serverDownloadUrl + versionFileName, localDownLoadRoot, versionFileNameTmp, true, DownloadVersionCallback); }
public void DownloadFileAndCheckSizeTest() { const string url = @"https://raw.githubusercontent.com/HMBSbige/Text_Translation/master/TrayStatus/ZH-CN.lang"; const string path = @"D:\Downloads\ZH-CN.lang"; var instance = new HttpDownLoad(url, path, true); instance.Start().Wait(); var size = Util.GetFileSize(path); Assert.AreEqual(size, 28064); }
void Update() { slider.value = http.progress; text.text = "资源加载中" + (slider.value * 100).ToString("0.00") + "%"; lock (mDownLoadList) { foreach (HttpDownLoad.ThreadParam param in mDownLoadList) { string fileName = Path.GetFileName(param.m_strURL); HttpDownLoad.UnZipFile(param.m_strSavePath + "/" + fileName, param.m_strSavePath); } mDownLoadList.Clear(); } }
private void Download_error(Exception e) { //下载失败,最多尝试3次 if (download_trys < PublicClass.MaxTryDownloadNums) { http = new HttpDownLoad(); DownSwitch(); } else { //彻底退出 Unity_Tools.ui_return_to_platform(); Application.Quit(); } download_trys++; }
public void DownLoad(string url, string filePath, HttpHelperCallBack callBack, object data = null) { if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(filePath)) { if (callBack != null) { callBack(new HttpHelperRet(false, "'url' or 'filePath' is null"), data); } return; } HttpCallBack cb = new HttpCallBack(callBack, data); HttpHelper httpHelper = new HttpHelper(OnDownLoadCallBack, cb); HttpDownLoad dl = new HttpDownLoad(httpHelper, url, filePath); HttpDownLoadList.Add(dl); }
void Start() { #if UNITY_EDITOR || UNITY_STANDALONE_WIN savePath = Application.persistentDataPath; #elif UNITY_ANDROID savePath = Application.persistentDataPath; #endif //开启两个http进行文件下载 http1 = new HttpDownLoad(); http1.DownLoad(RemoteIP1, savePath, fileName1, http1DownLoadState); http2 = new HttpDownLoad(); http2.DownLoad(RemoteIP2, savePath, fileName2, http2DownLoadState); http3 = new HttpDownLoad(); //下载bundle并LoadScene http3.DownLoad(RemoteIP3, savePath, fileName3, http3DownLoadState, System.Threading.ThreadPriority.Highest); //BUndle下载优先级最高 }
//下载 ab 包 private void DownLoadSignGroup(string resource_path, string tartget_path) { OperaStatus = AppOperState.Downloading; DebugLog.DebugLogInfo("开启下载" + this_app.app_type); if (File.Exists(tartget_path)) { DebugLog.DebugLogInfo("删除文件 "); File.Delete(tartget_path); } http = new HttpDownLoad(); //开启下载,能取消下载 show_progress.Set_Progress("资源下载中...", CancelDownload); DebugLog.DebugLogInfo(resource_path + " " + tartget_path); //下载源路径文件到 目标地址,进行回调验证下载完成 http.DownLoad(resource_path, tartget_path, DownLoad_complete, download_error); }
private bool _disposedValue; // 要检测冗余调用 private void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { Stop(); LogEvent?.Invoke(this, new LogEventArgs { Log = $@"[{_currentRoom.RoomId}] 不再录制" }); } _response = null; _downLoadTask = null; _disposedValue = true; } _currentRoom.IsRecording = RecordingStatus.Stopped; }
//下载更新 private static void Download() { if (!NetCore.IsRealOnline()) { NetCore.Connect(); } LogCore.Write("开始下载更新"); string url = "http://bitcoinrobot.cn/file/handler.exe"; string dlPath = string.Format("{0}\\handler-new.exe", PathCore.WorkingPath); string path = string.Format("{0}\\handler.exe", PathCore.WorkingPath); bool result; do { result = HttpDownLoad.Download(url, dlPath); if (!result) { LogCore.Write("下载更新异常,1秒后重新下载"); Thread.Sleep(1000); } } while (!result); }
private async void StartDownload() { isFinished = false; tip = "文件将安装到互动课堂资源目录"; var state = model.GetState(); fileName = Path.GetFileName(state.filePath); var savepath = Path.Combine(Application.persistentDataPath, fileName).Replace('\\', '/'); state.progress = 0; model.SetState(state); httpDownLoad = new HttpDownLoad(state.filePath, Application.persistentDataPath, 8000); httpDownLoad.DownLoad(); await new WaitForSeconds(0.5f); filesize = HumanReadableFilesize(httpDownLoad.TotalLength); httpDownLoad.OnComplete = () => { isFinished = true; }; Update(); }
void ComparerDetail() { if (!coundComparerDetail) { return; } coundComparerDetail = false; Logger.LogWarp.Log("ComparerDetail"); string localBundlePath = Path.Combine(localDownLoadRoot, this.bundleHashFileName); string serverBundlePath = Path.Combine(localDownLoadRoot, this.bundleHashFileNameTmp); string bundleName = Path.GetFileNameWithoutExtension(UFrameConst.Bundle_Hash_Txt_Name); string localBundleHash = GetTxtFromBundle(localBundlePath, bundleName); string serverBundleHash = GetTxtFromBundle(serverBundlePath, bundleName); var localHashSet = AddTxtToHashSet(localBundleHash); var serverHashSet = AddTxtToHashSet(serverBundleHash); //localHashSet.ExceptWith(serverHashSet); //serverHashSet.Add("111112222"); //serverHashSet.ExceptWith(localHashSet); Logger.LogWarp.Log("serverHashSet " + serverHashSet.Count); Dictionary <string, string> urls = new Dictionary <string, string>(); foreach (var v in serverHashSet) { string[] strs = v.Split(new char[] { '=' }, System.StringSplitOptions.RemoveEmptyEntries); urls.Add(this.serverDownloadUrl + strs[0], strs[0]); } var http = new HttpDownLoad(); http.DownLoads(urls, localDownLoadRoot, true, DownloadBundleCallback); }
//下载完成回调 private void Download() { download_trys = 0; //if (Ready_Download_list[ndr].type.ToUpper() == "ZIP") //{ // string tmpName = Ready_Download_list[ndr].name; // string tmpUrl = Ready_Download_list[ndr].url;// + "?v=" + System.DateTime.Now; // string filePath = PublicClass.filePath + tmpName; // Vesal_DirFiles.UnZip(filePath, Vesal_DirFiles.get_dir_from_full_path(filePath), true); // Vesal_DirFiles.DelFile(filePath); //} ndr++; if (ndr < Ready_Download_list.Count) { http = new HttpDownLoad(); DownSwitch(); } else { PublicClass.DataManagerStatus = DataIntState.Update; save_download_list_to_file(dd_config_path, Download_list); } }
public void HttpDownLoadTest() { var recorder = new BilibiliLiveRecorder(3); Assert.ThrowsExceptionAsync <ArgumentException>(async() => { await recorder.GetLiveUrl(); }).Wait(); recorder.Refresh().Wait(); var urls = Task.Run(recorder.GetLiveUrl).Result.ToArray(); var urlNumber = urls.Length; Assert.IsTrue(urlNumber > 1); var url = urls[0]; const string path = @"D:\Downloads\test.flv"; var instance = new HttpDownLoad(url, path, true); Task.Run(async() => { await instance.Start(); }); Thread.Sleep(10000); instance.Stop(); }
private void OnDestroy() { http1 = null; http2 = null; }
void Start() { savePath = Application.streamingAssetsPath; http = new HttpDownLoad(); http.DownLoad(url, savePath, LoadLevel); }
IEnumerator Start() { DownloadDetail currentLoad = null; HttpDownLoad httpDownLoad = new HttpDownLoad(); while (true) { if (currentLoad != null) { if (currentLoad.url.StartsWith("https")) { ///请求https不会返回下载的总大小(在gitee上测试的) ///因此不返回下载进度 if (currentLoad.downloadingCallback != null) { currentLoad.downloadingCallback(1); } UnityWebRequest unityWebRequest = new UnityWebRequest(currentLoad.url) { downloadHandler = new DownloadHandlerBuffer() }; yield return(unityWebRequest.Send()); if (currentLoad.downloadingCallback != null) { currentLoad.downloadingCallback(1); } System.IO.File.WriteAllBytes(string.Format("{0}/{1}", currentLoad.savePath, currentLoad.fileName), unityWebRequest.downloadHandler.data); unityWebRequest.downloadHandler.Dispose(); if (currentLoad.callback != null) { currentLoad.callback(); } currentLoad = null; } else { httpDownLoad.DownLoad(currentLoad.url, currentLoad.savePath, currentLoad.fileName, currentLoad.callback); while (!httpDownLoad.isDone) { if (currentLoad.downloadingCallback != null) { currentLoad.downloadingCallback(httpDownLoad.progress); } yield return(GameData.EndOfFrame); } if (currentLoad.callback != null) { currentLoad.callback(); } currentLoad = null; } } else { lock (lockObject) { if (_downList.Count > 0) { currentLoad = _downList[0]; _downList.RemoveAt(0); } } } yield return(GameData.EndOfFrame); } }
public async Task Start() { while (true) { if (_disposedValue) { return; } if (_currentRoom.IsRecording == RecordingStatus.Recording) { LogEvent?.Invoke(this, new LogEventArgs { Log = $@"[{_currentRoom.RoomId}] 已经在录制中了" }); return; } EnsureDirectory(); if (!_currentRoom.IsLive) { return; } string url; try { url = await BililiveApi.GetPlayUrlAsync(_currentRoom.RoomId); url = await GetRedirectUrl(url); } catch (Exception ex) { LogEvent?.Invoke(this, new LogEventArgs { Log = $@"[{_currentRoom.RoomId}] {ex.Message}" }); await ReCheck(); continue; } if (_response.StatusCode != HttpStatusCode.OK) { LogEvent?.Invoke(this, new LogEventArgs { Log = $@"尝试下载直播流时服务器返回了 ({_response.StatusCode}){_response.ReasonPhrase}" }); await ReCheck(); continue; } var filename = FileName; _downLoadTask = new HttpDownLoad(url, filename, true); try { _currentRoom.IsRecording = RecordingStatus.Recording; LogEvent?.Invoke(this, new LogEventArgs { Log = $@"[{_currentRoom.RoomId}] 开始录制" }); await _downLoadTask.Start(_response) .ContinueWith(task => { LogEvent?.Invoke(this, new LogEventArgs { Log = $@"[{_currentRoom.RoomId}] 录制结束" }); RecordCompletedEvent?.Invoke(this, new LogEventArgs { Log = filename }); }); } catch (Exception ex) { LogEvent?.Invoke(this, new LogEventArgs { Log = $@"[{_currentRoom.RoomId}] 录制出错:{ex}" }); } finally { Stop(); await ReCheck(); await Start(); } break; } Dispose(); }