yyl
2026-04-24 97de31e9a015cf139f5293a22e1575a43dfb6733
Main/System/AssetVersion/DownloadHotMgr.cs
@@ -329,30 +329,41 @@
        this.state = TaskState.Working;
        FileExtersion.MakeSureDirectory(tempFile);
        Debug.LogFormat("开始获取头信息:{0}", remoteUrl);
        using (var www = UnityWebRequest.Head(remoteUrl))
        try
        {
            www.timeout = DownloadHotMgr.TimeOut;
            await www.SendWebRequest();
            if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
            using (var www = UnityWebRequest.Head(remoteUrl))
            {
                Debug.LogErrorFormat("头信息获取失败:{0};error:{1}", remoteUrl, www.error);
                requestHeaderOk = false;
                SetFailed(www.error);
                www.timeout = DownloadHotMgr.TimeOut;
                await www.SendWebRequest();
                if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError)
                {
                    Debug.LogErrorFormat("头信息获取失败:{0};error:{1}", remoteUrl, www.error);
                    requestHeaderOk = false;
                    SetFailed(www.error);
                    www.Dispose();
                    return;
                }
                long.TryParse(www.GetResponseHeader(HttpHeader.ContentLength), out this.remoteLength);
                this.remoteLastModified = DateTime.Parse(www.GetResponseHeader(HttpHeader.LastModified));
                var acceptRange = www.GetResponseHeader(HttpHeader.AcceptRanges);
                this.isAcceptRange = acceptRange != "none";
                Debug.LogFormat("头信息获取成功:{0};大小:{1};修改时间:{2};是否支持续传:{3}", remoteUrl, remoteLength, remoteLastModified, acceptRange);
                requestHeaderOk = true;
                state = TaskState.Wait;
                www.Dispose();
                await UniTask.CompletedTask;
            }
            long.TryParse(www.GetResponseHeader(HttpHeader.ContentLength), out this.remoteLength);
            this.remoteLastModified = DateTime.Parse(www.GetResponseHeader(HttpHeader.LastModified));
            var acceptRange = www.GetResponseHeader(HttpHeader.AcceptRanges);
            this.isAcceptRange = acceptRange != "none";
            Debug.LogFormat("头信息获取成功:{0};大小:{1};修改时间:{2};是否支持续传:{3}", remoteUrl, remoteLength, remoteLastModified, acceptRange);
            requestHeaderOk = true;
            state = TaskState.Wait;
            www.Dispose();
        }
        catch (Exception e)
        {
            Debug.LogError("[DownloadHotTask] Co_GetHeader 异常\nURL: " + remoteUrl + "\nlocalFile: " + localFile + "\n错误: " + e.Message + "\n" + e.StackTrace);
            requestHeaderOk = false;
            SetFailed(e.Message);
        }
    }
    private async UniTask Co_DownloadFile()
    {
        try
        {
        state = TaskState.Working;
        while (TimeUtility.AllSeconds < beginTickCount + 5)//限制重新下载的时间间隔
        {
@@ -367,7 +378,7 @@
        if (!requestHeaderOk)//头文件获取失败
        {
            onCompleted?.Invoke(this);
            await UniTask.CompletedTask;
            return;
        }
        try
        {
@@ -422,7 +433,7 @@
        Debug.LogFormat("下载请求范围:{0} ;bytes={1}", remoteUrl, LocalLength);
        var localLength = LocalLength;
        this.downloadedBytes = localLength;
        fileRequest.SendWebRequest();
        _ = fileRequest.SendWebRequest();
        while (!fileRequest.isDone)
        {
            var length = localLength + (long)fileRequest.downloadedBytes;//本地文件大小+本次下载的数据大小
@@ -470,6 +481,13 @@
            SetFailed("下载完成但是文件不存在");
        }
        onCompleted?.Invoke(this);
        }
        catch (Exception e)
        {
            Debug.LogError("[DownloadHotTask] Co_DownloadFile 异常\nURL: " + remoteUrl + "\nlocalFile: " + localFile + "\n错误: " + e.Message + "\n" + e.StackTrace);
            SetFailed(e.Message);
            onCompleted?.Invoke(this);
        }
    }
    private async UniTask Move(string sourceFile, string destFile)