Skip to content

Commit

Permalink
Minor verifyDownload logic change
Browse files Browse the repository at this point in the history
  • Loading branch information
loc0 committed Jun 15, 2019
1 parent 33e662d commit 84022dc
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions codeWithMoshDownloader/codeWithMoshDownloader/Downloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ private async Task<bool> DownloadFile(GenericFile downloadInfo, string sectionPa

bool result = await DownloadClient(downloadInfo.Url, filePath);

result = VerifyDownload(result, filePath, downloadSize);
if (result)
{
result = VerifyDownload(filePath, downloadSize);
}

if (result && _unZip && Path.GetExtension(downloadInfo.FileName) == ".zip")
{
Expand All @@ -221,24 +224,18 @@ private async Task<bool> DownloadFile(GenericFile downloadInfo, string sectionPa
return result;
}

private static bool VerifyDownload(bool result, string filePath, long? downloadSize)
private static bool VerifyDownload(string filePath, long? downloadSize)
{
if (result)
{
long fileSize = new FileInfo(filePath).Length;
long fileSize = new FileInfo(filePath).Length;

if (downloadSize != fileSize)
{
Console.WriteLine("[download] Download failed\n");
result = false;
}
else
{
Console.Write("[download] Download complete\n");
}
if (downloadSize != fileSize)
{
Console.WriteLine("[download] Download failed\n");
return false;
}

return result;
Console.Write("[download] Download complete\n");
return true;
}

private bool FileExists(string filePath, long? downloadSize)
Expand Down Expand Up @@ -332,7 +329,10 @@ private async Task<bool> DownloadFile(WistiaDownloadInfo wistiaDownloadInfo, str

bool result = await DownloadClient(wistiaDownloadInfo.Url, filePath);

result = VerifyDownload(result, filePath, wistiaDownloadInfo.FileSize);
if (result)
{
result = VerifyDownload(filePath, wistiaDownloadInfo.FileSize);
}

return result;
}
Expand Down

0 comments on commit 84022dc

Please sign in to comment.