public override async Task DownloadGameFiles(Progress <PatchProgress> progress) { await base.DownloadGameFiles(progress); GetMirrors(); if (status == PatcherStatus.MirrorsFailure) { return; } var tasks = new List <Task>(); ct = cts.Token; patchProgress.NewWork(progress, filesToUpdate.Count + filesNeeded.Count); foreach (var file in filesToUpdate) { RewrittenPatch patchInfo = file.Value; tasks.Add(Task.Run(() => AcquireFileAsync(patchInfo.Filename, patchInfo.CompPatchHash), ct) .ContinueWith(_ => patchProgress.FileProcessed(progress, ct))); } foreach (var file in filesNeeded) { RewrittenFile fileInfo = file.Value; tasks.Add(Task.Run(() => AcquireFileAsync(fileInfo.Dl, fileInfo.Hash), ct) .ContinueWith(_ => patchProgress.FileProcessed(progress, ct))); } await Task.WhenAll(tasks); }
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); } }