Skip to content

Commit

Permalink
修正断点续传可能导致的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiang Yin committed Dec 27, 2019
1 parent 27fd91e commit 1e8fbf0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 14 additions & 1 deletion GameFramework/Download/DownloadAgentHelperErrorEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,19 @@ public sealed class DownloadAgentHelperErrorEventArgs : GameFrameworkEventArgs
/// </summary>
public DownloadAgentHelperErrorEventArgs()
{
DeleteDownloading = false;
ErrorMessage = null;
}

/// <summary>
/// 获取是否需要删除正在下载的文件。
/// </summary>
public bool DeleteDownloading
{
get;
private set;
}

/// <summary>
/// 获取错误信息。
/// </summary>
Expand All @@ -32,11 +42,13 @@ public string ErrorMessage
/// <summary>
/// 创建下载代理辅助器错误事件。
/// </summary>
/// <param name="deleteDownloading">是否需要删除正在下载的文件。</param>
/// <param name="errorMessage">错误信息。</param>
/// <returns>创建的下载代理辅助器错误事件。</returns>
public static DownloadAgentHelperErrorEventArgs Create(string errorMessage)
public static DownloadAgentHelperErrorEventArgs Create(bool deleteDownloading, string errorMessage)
{
DownloadAgentHelperErrorEventArgs downloadAgentHelperErrorEventArgs = ReferencePool.Acquire<DownloadAgentHelperErrorEventArgs>();
downloadAgentHelperErrorEventArgs.DeleteDownloading = deleteDownloading;
downloadAgentHelperErrorEventArgs.ErrorMessage = errorMessage;
return downloadAgentHelperErrorEventArgs;
}
Expand All @@ -46,6 +58,7 @@ public static DownloadAgentHelperErrorEventArgs Create(string errorMessage)
/// </summary>
public override void Clear()
{
DeleteDownloading = false;
ErrorMessage = null;
}
}
Expand Down
11 changes: 8 additions & 3 deletions GameFramework/Download/DownloadManager.DownloadAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void Update(float elapseSeconds, float realElapseSeconds)
m_WaitTime += realElapseSeconds;
if (m_WaitTime >= m_Task.Timeout)
{
DownloadAgentHelperErrorEventArgs downloadAgentHelperErrorEventArgs = DownloadAgentHelperErrorEventArgs.Create("Timeout");
DownloadAgentHelperErrorEventArgs downloadAgentHelperErrorEventArgs = DownloadAgentHelperErrorEventArgs.Create(false, "Timeout");
OnDownloadAgentHelperError(this, downloadAgentHelperErrorEventArgs);
ReferencePool.Release(downloadAgentHelperErrorEventArgs);
}
Expand Down Expand Up @@ -224,7 +224,7 @@ public StartTaskStatus Start(DownloadTask task)
}
catch (Exception exception)
{
DownloadAgentHelperErrorEventArgs downloadAgentHelperErrorEventArgs = DownloadAgentHelperErrorEventArgs.Create(exception.ToString());
DownloadAgentHelperErrorEventArgs downloadAgentHelperErrorEventArgs = DownloadAgentHelperErrorEventArgs.Create(false, exception.ToString());
OnDownloadAgentHelperError(this, downloadAgentHelperErrorEventArgs);
ReferencePool.Release(downloadAgentHelperErrorEventArgs);
return StartTaskStatus.UnknownError;
Expand Down Expand Up @@ -301,7 +301,7 @@ private void OnDownloadAgentHelperUpdateBytes(object sender, DownloadAgentHelper
}
catch (Exception exception)
{
DownloadAgentHelperErrorEventArgs downloadAgentHelperErrorEventArgs = DownloadAgentHelperErrorEventArgs.Create(exception.ToString());
DownloadAgentHelperErrorEventArgs downloadAgentHelperErrorEventArgs = DownloadAgentHelperErrorEventArgs.Create(false, exception.ToString());
OnDownloadAgentHelperError(this, downloadAgentHelperErrorEventArgs);
ReferencePool.Release(downloadAgentHelperErrorEventArgs);
}
Expand Down Expand Up @@ -356,6 +356,11 @@ private void OnDownloadAgentHelperError(object sender, DownloadAgentHelperErrorE
m_FileStream = null;
}

if (e.DeleteDownloading)
{
File.Delete(Utility.Text.Format("{0}.download", m_Task.DownloadPath));
}

m_Task.Status = DownloadTaskStatus.Error;

if (DownloadAgentFailure != null)
Expand Down

0 comments on commit 1e8fbf0

Please sign in to comment.