-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from Corona-Studio/download
Download
- Loading branch information
Showing
5 changed files
with
129 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 12 additions & 13 deletions
25
ProjBobcat/ProjBobcat/Exceptions/HashMismatchException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
using System; | ||
using System.Linq; | ||
using ProjBobcat.Class.Model.Downloading; | ||
|
||
namespace ProjBobcat.Exceptions; | ||
|
||
public sealed class HashMismatchException : Exception | ||
public sealed class HashMismatchException( | ||
string filePath, | ||
string expectedHash, | ||
string actualHash, | ||
AbstractDownloadBase downloadBase) | ||
: Exception(GetMessage(filePath, expectedHash, actualHash, downloadBase)) | ||
{ | ||
public HashMismatchException(string filePath, string expectedHash, string actualHash) : base(GetMessage(filePath, expectedHash, actualHash)) | ||
{ | ||
FilePath = filePath; | ||
ExpectedHash = expectedHash; | ||
ActualHash = actualHash; | ||
} | ||
|
||
public string FilePath { get; } | ||
public string ExpectedHash { get; } | ||
public string ActualHash { get; } | ||
|
||
static string GetMessage(string filePath, string expectedHash, string actualHash) | ||
static string GetMessage(string filePath, string expectedHash, string actualHash, AbstractDownloadBase downloadBase) | ||
{ | ||
return $""" | ||
文件 {filePath} 的哈希值不匹配。 | ||
期望哈希值:{expectedHash} | ||
实际哈希值:{actualHash} | ||
[{downloadBase.FinishedRangeStreams.Count} files in total] | ||
[{downloadBase.FinishedRangeStreams.Select(p => p.Value.Length).Sum()}/{downloadBase.UrlInfo?.FileLength ?? 0}] | ||
{string.Join("\n", downloadBase.FinishedRangeStreams.OrderBy(p => p.Key.Start).Select(p => $"{p.Key} {p.Value.Length}"))} | ||
"""; | ||
} | ||
} |