private void OnDownloadFailure(int downloadTaskId, DownloadTaskInfo downloadTaskInfo, DownloadErrorCode errorCode, string errorMessage) { var downloadContext = (DownloadContext)downloadTaskInfo.Context; var resourceGroup = m_ResourceGroupsBeingUpdated[downloadContext.ResourceGroupId]; resourceGroup.DownloadTaskIds.Remove(downloadTaskId); errorMessage = Utility.Text.Format( "Download failed for '{0}' from '{1}'. Inner error code is '{2}'. Inner error message is '{3}'.", downloadContext.ResourcePath, downloadTaskInfo.UrlStr, errorCode, errorMessage); if (downloadContext.RootUrlIndex >= RootUrls.Count - 1) { SingleFail(resourceGroup, downloadContext.ResourcePath, errorMessage); ClearBeingUpdated(resourceGroup.GroupId); Fail(resourceGroup, null, errorMessage); return; } downloadContext.RootUrlIndex++; var newDownloadTaskInfo = new DownloadTaskInfo( Utility.Text.Format("{0}/{1}_{2}{3}", RootUrls[downloadContext.RootUrlIndex], downloadContext.ResourcePath, downloadTaskInfo.Crc32.Value, Constant.ResourceFileExtension), downloadTaskInfo.SavePath, downloadTaskInfo.Size, downloadTaskInfo.Crc32, new DownloadCallbackSet { OnFailure = m_OnDownloadFailure, OnSuccess = m_OnDownloadSuccess, OnProgress = m_OnDownloadProgress, }, downloadContext); resourceGroup.DownloadTaskIds.Add(m_Owner.DownloadModule.StartDownloading(newDownloadTaskInfo)); }
public async Task DownLoadFile(string title, string videoSrcUrl, string mode, string downPath) { if (!string.IsNullOrEmpty(title)) { var downloader = new FlvDownloader(videoSrcUrl); var partUrls = new List <string>(); partUrls = await downloader.GetDownloadFiles(mode); if (partUrls != null && partUrls.Count > 0) { string newdir = Path.Combine(downPath, title); if (!Directory.Exists(newdir)) { Directory.CreateDirectory(newdir); } var taskInfo = new DownloadTaskInfo(title, newdir, partUrls); DownloadTaskList.Add(taskInfo); taskInfo.Start(); } } }
IEnumerator UpdateFile() { for (int i = 0; i < _downloadFiles.Count; i++) { DownloadTaskInfo taskInfo = _downloadFiles[i]; Debug.Log("downloading>>" + taskInfo.url); UnityWebRequest request = UnityWebRequest.Get(taskInfo.url); yield return(request); if (request.error != null) { // OnUpdateFailed(taskInfo.filePath); } else { File.WriteAllBytes(taskInfo.filePath, request.downloadHandler.data); if (onShowUpdateUI != null) { onShowUpdateUI(); } } yield return(null); } if (onUpdateEnd != null) { onUpdateEnd(); } }
public void AddNewDownloadTask(DownloadTaskInfo downloadTaskInfo) { Guid newTaskGuid = m_DownloadHelper.AddNewDownloadTask(downloadTaskInfo); ListViewItem item = new ListViewItem(); DownloadTaskStatistics downloadTaskStatistics = m_DownloadHelper.GetDownloadTaskStatistics(newTaskGuid); string fileName = downloadTaskInfo.DownloadFileInfo.FileName; string fileExtension = Path.GetExtension(fileName); item.ImageIndex = FileTypeImageList.GetImageIndexByExtention(fileExtension); item.Text = Path.GetFileName(fileName); item.SubItems.Add(ByteFormatter.ToString(downloadTaskStatistics.FileSize)); item.SubItems.Add(ByteFormatter.ToString(downloadTaskStatistics.TransferedDownload)); item.SubItems.Add(GetDownloadProgressText(downloadTaskStatistics)); item.SubItems.Add(TimeSpanFormatter.ToString(downloadTaskStatistics.RemainingTime)); item.SubItems.Add("0"); item.SubItems.Add("0"); item.SubItems.Add(string.Format(CultureInfo.CurrentCulture, "{0} {1}", downloadTaskStatistics.CreatedDate.ToShortDateString(), downloadTaskStatistics.CreatedDate.ToShortTimeString())); item.SubItems.Add(downloadTaskStatistics.DownloadTaskState.ToString()); item.SubItems.Add(GetResumeText(downloadTaskStatistics)); item.SubItems.Add(downloadTaskStatistics.FileUri.OriginalString); m_DownloadTaskItemMap[item] = newTaskGuid; lvwDownloadTasks.Items.Add(item); }
public void StartUpdatingResourceGroup(int groupId, ResourceGroupUpdateCallbackSet callbackSet, object context) { if (!IsReady) { throw new InvalidOperationException("Not ready."); } if (!AvailableResourceGroupIds.Contains(groupId)) { throw new ArgumentException(Utility.Text.Format("Resource group '{0}' is not available.", groupId)); } if (GetResourceGroupStatus(groupId) == ResourceGroupStatus.UpToDate) { throw new InvalidOperationException(Utility.Text.Format("Resource group '{0}' is already up-to-date.", groupId)); } if (AvailableResourceGroupIds.Contains(0) && groupId != 0 && GetResourceGroupStatus(0) != ResourceGroupStatus.UpToDate) { throw new InvalidOperationException("You have to update resource group 0 first."); } if (m_ResourceGroupsBeingUpdated.ContainsKey(groupId)) { throw new InvalidOperationException($"Resource group '{groupId}' is being updated."); } var resourceSummary = ResourceSummaries[groupId]; var resourceGroup = new ResourceGroupBeingUpdated { GroupId = groupId, Summary = resourceSummary, CallbackSet = callbackSet, CallbackContext = context, }; m_ResourceGroupsBeingUpdated.Add(groupId, resourceGroup); foreach (var resourceToUpdate in resourceSummary) { var downloadContext = new DownloadContext { RootUrlIndex = 0, ResourcePath = resourceToUpdate.Key, ResourceGroupId = groupId, }; var resourceInfo = m_Owner.m_RemoteIndex.ResourceInfos[resourceToUpdate.Key]; var downloadTaskInfo = new DownloadTaskInfo( Utility.Text.Format("{0}/{1}_{2}{3}", RootUrls[0], resourceToUpdate.Key, resourceInfo.Crc32, Constant.ResourceFileExtension), Path.Combine(m_Owner.ReadWritePath, resourceToUpdate.Key + Constant.ResourceFileExtension), resourceInfo.Size, resourceInfo.Crc32, new DownloadCallbackSet { OnFailure = m_OnDownloadFailure, OnSuccess = m_OnDownloadSuccess, OnProgress = m_OnDownloadProgress, }, downloadContext); resourceGroup.DownloadTaskIds.Add(m_Owner.DownloadModule.StartDownloading(downloadTaskInfo)); } }
private void Start() { for (int i = 0; i < m_DownloadInfos.Length; i++) { if (!m_DownloadInfos[i].IsActive) { continue; } var downloadTaskInfo = new DownloadTaskInfo( urlStr: m_DownloadInfos[i].UrlStr, savePath: Application.persistentDataPath + Path.DirectorySeparatorChar + m_DownloadInfos[i].SavePath, size: m_DownloadInfos[i].Size, crc32: m_DownloadInfos[i].CheckCrc32 ? m_DownloadInfos[i].Crc32 : (uint?)null, callbackSet: new DownloadCallbackSet { OnSuccess = OnDownloadSuccess, OnFailure = OnDownloadFailure, OnProgress = OnDownloadProgress, }, context: null); Container.Make <IDownloadService>().StartDownloading(downloadTaskInfo); } }
public void Run(AssetIndexRemoteFileInfo remoteIndexFileInfo, UpdateCheckCallbackSet callbackSet, object context) { if (Status != UpdateCheckerStatus.None) { throw new InvalidOperationException("Update checking already run."); } Status = UpdateCheckerStatus.Running; m_CallbackSet = callbackSet; m_Context = context; if (!m_Owner.UpdateIsEnabled) { UseInstallerResourcesOnly(); return; } m_RemoteIndexFileInfo = remoteIndexFileInfo ?? throw new InvalidOperationException("Remote index file info is invalid."); if (RootUrls.Count <= 0) { ResetStatus(); throw new InvalidOperationException("Root URL for any update server hasn't been set."); } if (!m_RootUrlsModified) { m_RootUrlsModified = true; for (int i = 0; i < RootUrls.Count; i++) { RootUrls[i] = new Uri(RootUrls[i], Utility.Text.Format(m_Owner.UpdateRelativePathFormat, m_Owner.RunningPlatform, Utility.Text.Format("{0}.{1}", m_Owner.BundleVersion, m_RemoteIndexFileInfo.InternalAssetVersion))); } } if (!CheckNeedDownloadRemoteIndex(remoteIndexFileInfo)) { CheckUpdate(); return; } m_DownloadRetryTimes = 0; m_DownloadTaskInfo = new DownloadTaskInfo( Utility.Text.Format("{0}/index_{1}.dat", RootUrls[m_RootUrlIndex].ToString(), m_RemoteIndexFileInfo.Crc32.ToString()), m_Owner.CachedRemoteIndexPath, m_RemoteIndexFileInfo.FileSize, m_RemoteIndexFileInfo.Crc32, new DownloadCallbackSet { OnSuccess = m_OnDownloadSuccess, OnFailure = m_OnDownloadFailure, OnProgress = null, }, null); m_Owner.DownloadService.StartDownloading(m_DownloadTaskInfo); }
private void OnDownloadProgress(int downloadTaskId, DownloadTaskInfo downloadTaskInfo, long downloadedSize) { var downloadContext = (DownloadContext)downloadTaskInfo.Context; var resourceGroup = m_ResourceGroupsBeingUpdated[downloadContext.ResourceGroupId]; resourceGroup.CallbackSet.OnSingleProgress?.Invoke(((DownloadContext)downloadTaskInfo.Context).ResourcePath, downloadedSize, downloadTaskInfo.Size, resourceGroup.CallbackContext); }
public CreateTaskWindow(DownloadTaskInfo info = null) { InitializeComponent(); Result = info; Loaded += (s, e) => { RegistMessage(); }; Closed += (s, e) => { UnregistMessage(); }; }
private void DrawWaitingDownloadTask(int taskId, DownloadTaskInfo downloadTaskInfo) { if (!DrawOneDownloadTaskHead(taskId, ref downloadTaskInfo)) { return; } EditorGUILayout.BeginHorizontal(); { GUILayout.Space(10f); DrawDownloadTaskInfo(downloadTaskInfo); } EditorGUILayout.EndHorizontal(); }
public void OnCreateTask() { var task = new DownloadTaskInfo(); GlobalMessageCenter.Instance.Send("CreateDownloadTask", task); if (task.IsValid) { var filesize = HttpDownload.HttpFileSplit.TryGetContentLength(task.RemotePath); if (filesize <= 0) { GlobalMessageCenter.Instance.Send("TaskError.Size"); return; } var blockSize = (filesize + 224) / 225; var downloadTask = new DownloadTask() { RemotePath = task.RemotePath, LocalPath = task.LocalPath, CfgPath = task.LocalPath + ".cfg", BlockSize = blockSize, }; if (downloadTask.InitTask()) { CurrentTask = downloadTask; CurrentRemotePath = CurrentTask.RemotePath; } ClearProgress(); if (task.IsEnableDistributed) { foreach (var info in PeerInfoList) { var peer = PeerInfo2Peer(info); var subtask = CurrentTask.GetSubTask(); InstPeer(peer, subtask, blockSize); if (subTask_[peer.EndPoint.ToString()] != null) { FileBlockTask f = new FileBlockTask(subTask_[peer.EndPoint.ToString()]); master.Send(peer, f.Encode()); } } } } }
private void OnDownloadFailure(int downloadTaskId, DownloadTaskInfo downloadTaskInfo, DownloadErrorCode errorCode, string errorMessage) { if (m_DownloadRetryTimes >= m_Owner.DownloadRetryCount) { m_DownloadRetryTimes = -1; m_RootUrlIndex++; if (m_RootUrlIndex >= RootUrls.Count) { ResetStatus(); errorMessage = Utility.Text.Format( "Cannot update remote index file. Error code is '{0}'. Error message is '{1}'.", errorCode, errorMessage); if (m_CallbackSet.OnFailure != null) { m_CallbackSet.OnFailure(errorMessage, m_Context); } else { throw new InvalidOperationException(errorMessage); } return; } } m_DownloadRetryTimes++; if (m_DownloadRetryTimes == 0) { m_DownloadTaskInfo = new DownloadTaskInfo( Utility.Text.Format("{0}/index_{1}.dat", RootUrls[m_RootUrlIndex].ToString(), m_RemoteIndexFileInfo.Crc32.ToString()), m_Owner.CachedRemoteIndexPath, m_RemoteIndexFileInfo.FileSize, m_RemoteIndexFileInfo.Crc32, new DownloadCallbackSet { OnSuccess = m_OnDownloadSuccess, OnFailure = m_OnDownloadFailure, OnProgress = null, }, null); } m_Owner.DownloadService.StartDownloading(m_DownloadTaskInfo); }
private void OnDownloadSuccess(int downloadTaskId, DownloadTaskInfo downloadTaskInfo) { var downloadContext = (DownloadContext)downloadTaskInfo.Context; var resourcePath = downloadContext.ResourcePath; var resourceGroupId = downloadContext.ResourceGroupId; var resourceGroup = m_ResourceGroupsBeingUpdated[resourceGroupId]; resourceGroup.DownloadTaskIds.Remove(downloadTaskId); var resourceSummary = resourceGroup.Summary; resourceSummary.ResourcePathToSizeMap.Remove(resourcePath); resourceSummary.RemainingSize -= downloadTaskInfo.Size; m_UpdatedBytesBeforeSavingReadWriteIndex += downloadTaskInfo.Size; m_Owner.m_ReadWriteIndex.ResourceInfos[resourcePath] = m_Owner.m_RemoteIndex.ResourceInfos[resourcePath]; if (resourceSummary.RemainingSize <= 0 || m_UpdatedBytesBeforeSavingReadWriteIndex >= m_Owner.UpdateSizeBeforeSavingReadWriteIndex) { m_UpdatedBytesBeforeSavingReadWriteIndex = 0; try { m_Owner.SaveReadWriteIndex(); } catch (Exception e) { string errorMessageFormat = "Cannot save read-write index. Inner exception is '{0}'."; SingleFail(resourceGroup, resourcePath, Utility.Text.Format(errorMessageFormat, e)); ClearBeingUpdated(resourceGroupId); Fail(resourceGroup, e, errorMessageFormat); return; } } resourceGroup.CallbackSet.OnSingleSuccess?.Invoke(resourcePath, downloadTaskInfo.Size, resourceGroup.CallbackContext); if (resourceSummary.RemainingSize <= 0L) { ClearBeingUpdated(resourceGroupId); resourceGroup.CallbackSet.OnAllSuccess?.Invoke(resourceGroup.CallbackContext); } }
private static void DrawDownloadTaskInfo(DownloadTaskInfo downloadTaskInfo) { EditorGUILayout.BeginVertical(); { var sb = StringBuilderCache.Acquire(); sb.AppendLine("URL: " + downloadTaskInfo.UrlStr); sb.AppendLine("Save Path: " + downloadTaskInfo.SavePath); if (downloadTaskInfo.Size > 0L) { sb.AppendFormat("Size: {0:N0}\n", downloadTaskInfo.Size); } if (downloadTaskInfo.Crc32 != null) { sb.AppendFormat("CRC 32: {0}\n", downloadTaskInfo.Crc32.Value); } EditorGUILayout.LabelField(StringBuilderCache.GetStringAndRelease(sb), EditorStyles.wordWrappedLabel); } EditorGUILayout.EndVertical(); }
private bool DrawOneDownloadTaskHead(int taskId, ref DownloadTaskInfo downloadTaskInfo) { var foldOut = m_DownloadTaskFoldouts.ContainsKey(taskId) && m_DownloadTaskFoldouts[taskId]; EditorGUILayout.BeginHorizontal(); { GUILayout.Space(10f); var newFoldOut = EditorGUILayout.Foldout(foldOut, Core.Utility.Text.Format("Task ID: {0} ({1})", taskId, Path.GetFileName(downloadTaskInfo.SavePath))); if (newFoldOut != foldOut || !m_DownloadTaskFoldouts.ContainsKey(taskId)) { m_DownloadTaskFoldouts[taskId] = newFoldOut; } if (GUILayout.Button("Stop", GUILayout.Width(60f))) { m_TaskIdToStop = taskId; } } EditorGUILayout.EndHorizontal(); return(foldOut); }
public ITaskMetadata Add(DownloadTaskInfo taskInfo) { throw new NotImplementedException(); }
private void btnOk_Click(object sender, EventArgs e) { DownloadTaskInfo = new DownloadTaskInfo(new DownloadFileInfo(new Uri(txtUrl.Text.Trim()), Path.Combine(txtDownloadFolder.Text.Trim(), txtFileName.Text.Trim()), (int)nudSegmentsCount.Value), cbStartNow.Checked); DialogResult = DialogResult.OK; }
private void OnDownloadSuccess(int downloadTaskId, DownloadTaskInfo taskInfo) { CheckUpdate(); }
private void OnDownloadFailure(int taskId, DownloadTaskInfo info, DownloadErrorCode errorCode, string errorMessage) { Debug.LogWarningFormat("Download '{0}' to '{1}' failed with error code '{2}' and message '{3}'.", info.UrlStr, info.SavePath, errorCode, errorMessage); }
private void OnDownloadSuccess(int taskId, DownloadTaskInfo info) { Debug.LogFormat("Download '{0}' to '{1}' succeeded.", info.UrlStr, info.SavePath); }
public int StartDownloading(DownloadTaskInfo downloadTaskInfo) { return(Module.StartDownloading(downloadTaskInfo)); }
private void OnDownloadProgress(int taskId, DownloadTaskInfo info, long downloadedSize) { // Debug.LogFormat("Download '{0}' progressed to {1} bytes.", info.UrlStr, downloadedSize); }