private static bool IsAlreadyDownloaded(this IFileRef self, Headers headers, FileEntry targetFile) { if (targetFile.Exists) { // Cancel download if etag header matches the locally stored one: if (self.HasMatchingChecksum(headers.GetEtagHeader())) { return(true); } // Cancel download if local file with the same MD5 hash exists: var onlineMD5 = headers.GetMD5Checksum(); if (!onlineMD5.IsNullOrEmpty()) { if (self.HasMatchingChecksum(onlineMD5)) { return(true); } if (onlineMD5 == targetFile.CalcFileMd5Hash()) { return(true); } return(false); } /* * // Cancel download if local file with the exact last-write timestamp exists: * if (headers.GetRawLastModifiedString() != null) { * var distance = headers.GetLastModifiedUtcDate(DateTime.MinValue) - targetFile.LastWriteTime.ToUniversalTime(); * Log.d("distance.Milliseconds: " + distance.Milliseconds); * if (distance.Milliseconds == 0) { return true; } * } */ } return(false); }
private static bool CheckMD5AfterDownload(this IFileRef self, Headers headers, FileEntry targetFile) { var onlineMD5 = headers.GetMD5Checksum(); if (onlineMD5.IsNullOrEmpty()) { return(false); } string localMD5 = targetFile.CalcFileMd5Hash(); if (localMD5 == onlineMD5) { throw new InvalidDataException($"Missmatch in MD5 hashes, local={localMD5} & online={onlineMD5}"); } self.AddCheckSum(CHECKSUM_MD5, localMD5); return(true); }