public override void CheckGameFiles(Progress <PatchProgress> progress) { base.CheckGameFiles(progress); string gamePath = config.ClashPath; patchProgress.NewWork(progress, patchManifest.Count); foreach (var file in patchManifest) { string localFilePath = gamePath + file.FilePath; // meh patchProgress.FileProcessed(progress); if (File.Exists(localFilePath)) { string fileHash = GamePatchUtils.GetSha1FileHash(localFilePath); if (fileHash == file.Sha1) { continue; } } filesNeeded.Add(file); } }
public override void CheckGameFiles(Progress <PatchProgress> progress) { base.CheckGameFiles(progress); patchProgress.NewWork(progress, patchManifest.Count); string gamePath = config.RewrittenPath; foreach (var file in patchManifest) { RewrittenFile fileObject = file.Value; //meh patchProgress.FileProcessed(progress); if (!fileObject.Only.Contains("win64")) { continue; } bool hasPatchAvailable = false; string localFile = gamePath + file.Key; if (File.Exists(localFile)) { string fileHash = GamePatchUtils.GetSha1FileHash(localFile); if (fileHash == fileObject.Hash) { continue; } foreach (var patch in fileObject.Patches) { if (fileHash == patch.Key) { hasPatchAvailable = true; patch.Value.FinalFileHash = fileObject.Hash; filesToUpdate.Add(file.Key, patch.Value); break; } } } if (!hasPatchAvailable) { filesNeeded.Add(file.Key, file.Value); } } }
public override void PatchGameFiles(Progress <PatchProgress> progress) { base.PatchGameFiles(progress); string rewrittenPath = config.RewrittenPath; patchProgress.NewWork(progress, filesToUpdate.Count + filesNeeded.Count); foreach (var file in filesToUpdate) { string fileName = file.Key; RewrittenPatch patchInfo = file.Value; string localFilePath = rewrittenPath + fileName; string extractedFilePath = rewrittenPath + patchInfo.Filename + ".extracted"; GamePatchUtils.Patch(extractedFilePath, localFilePath); string patchedFilePath = localFilePath + ".tmp"; if (GamePatchUtils.FileIsCorrect(patchedFilePath, patchInfo.FinalFileHash)) { File.Delete(localFilePath); File.Move(patchedFilePath, localFilePath); patchProgress.FileProcessed(progress); } else { File.Delete(patchedFilePath); status = PatcherStatus.PatchFailure; } File.Delete(extractedFilePath); } foreach (var file in filesNeeded) { string filename = file.Key; RewrittenFile fileInfo = file.Value; string localFilePath = rewrittenPath + filename; string extractedFilePath = rewrittenPath + fileInfo.Dl + ".extracted"; File.Delete(localFilePath); File.Move(extractedFilePath, localFilePath); patchProgress.FileProcessed(progress); } }
private async Task AcquireFileAsync(ClashFile file) { string fileToDownload = GamePatchUtils.GetSha1HashString(file.FilePath); string url = UpdateUrl + fileToDownload; string downloadedFilePath = config.ClashPath + fileToDownload; string extractedFilePath = downloadedFilePath + "~"; int downloadStatus = await fileDownloader.DownloadAsync(url, downloadedFilePath); if (downloadStatus != 0) { File.Delete(downloadedFilePath); status = PatcherStatus.FileDownloadFailure; cts.Cancel(); return; } if (!GamePatchUtils.FileIsCorrect(downloadedFilePath, file.CompressedSha1)) { status = PatcherStatus.FileDownloadFailure; cts.Cancel(); return; } if (GamePatchUtils.Extract(downloadedFilePath, extractedFilePath, "gzip") != 0) { status = PatcherStatus.FileDownloadFailure; cts.Cancel(); return; } if (GamePatchUtils.FileIsCorrect(extractedFilePath, file.Sha1)) { // Cheat a bit to avoid SHA1 hashes again file.FileName = fileToDownload + "~"; return; } status = PatcherStatus.FileDownloadFailure; cts.Cancel(); }
private async Task AcquireFileAsync(string fileToDownload, string compHash) { string rewrittenPath = config.RewrittenPath; string downloadedFilePath = rewrittenPath + fileToDownload; string extractedFilePath = downloadedFilePath + ".extracted"; foreach (string mirror in mirrors) { string url = mirror + fileToDownload; int downloadStatus = await fileDownloader.DownloadAsync(url, downloadedFilePath); if (downloadStatus != 0) { File.Delete(downloadedFilePath); continue; } // Patch hashes are compared to the downloaded file bool patch = GamePatchUtils.FileIsCorrect(downloadedFilePath, compHash); if (GamePatchUtils.Extract(downloadedFilePath, extractedFilePath, "bzip2") != 0) { continue; } // Full file hashes are compared to the extracted file if (patch || GamePatchUtils.FileIsCorrect(extractedFilePath, compHash)) { return; } File.Delete(extractedFilePath); } status = PatcherStatus.FileDownloadFailure; cts.Cancel(); }