public FileInfo DownloadFileFromURLToPath(string url, string path, long fileSize) { if (comms.Cancel) { return(null); } if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(path)) { return(null); } downloadHandler.DownloadedFilePath = path; downloadHandler.DownloadedFilename = Path.GetFileName(path); downloadHandler.DownloadedFileSize = fileSize; if (comms.LogProgress) { downloadHandler.Progress = new DownloadProgress(downloadHandler); comms.SetProgress(downloadHandler.Progress); } if (IsGoogleDriveURL(url)) { url = PatchUtils.GetGoogleDriveDownloadLinkFromUrl(url); verifyDownloadSize = false; return(DownloadGoogleDriveFileFromURLToPath(url, path)); } else { verifyDownloadSize = true; return(DownloadFileFromURLToPathInternal(url, path)); } }
private bool ApplyDiffToFile(string filePath, string diffPath, string targetPath, int patchItemIndex) { PatchItem item = patchInfo.Files[patchItemIndex]; FileInfo targetFile = new FileInfo(targetPath); if (targetFile.Exists && targetFile.MatchesSignature(item.AfterFileSize, item.AfterMd5Hash)) { comms.Log(Localization.Get(StringId.AlreadyUpToDateXthFile, patchItemIndex + 1, patchInfo.Files.Count, item.Path)); return(true); } if (item.BeforeFileSize == 0L) { comms.Log(Localization.Get(StringId.CreatingXthFile, patchItemIndex + 1, patchInfo.Files.Count, item.Path)); Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); File.Copy(diffPath, targetPath, true); File.Delete(diffPath); return(true); } FileInfo localFile = new FileInfo(filePath); if (!localFile.Exists || !localFile.MatchesSignature(item.BeforeFileSize, item.BeforeMd5Hash)) { return(false); } comms.Log(Localization.Get(StringId.UpdatingXthFile, patchItemIndex + 1, patchInfo.Files.Count, item.Path)); FilePatchProgress progress = null; string tempOutputPath = diffPath + "_.tmp"; if (comms.LogProgress) { progress = new FilePatchProgress(Path.GetFileName(filePath)); comms.SetProgress(progress); } OctoUtils.ApplyDelta(filePath, tempOutputPath, diffPath, progress); FileInfo updatedFile = new FileInfo(tempOutputPath); if (!updatedFile.Exists || !updatedFile.MatchesSignature(item.AfterFileSize, item.AfterMd5Hash)) { return(false); } Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); File.Copy(tempOutputPath, targetPath, true); File.Delete(tempOutputPath); File.Delete(diffPath); return(true); }