/// <summary> /// Gets all unpatched files from a file collection. /// </summary> /// <param name="collection">The collection of files</param> /// <returns>A <see cref="IFileManifestCollection"/> with unpatched files</returns> private async Task <IFileManifestCollection> GetUnpatchedFiles(IFileManifestCollection collection) { var unpatched = new List <FileManifest>(); Parallel.ForEach(collection.Files, new ParallelOptions() { MaxDegreeOfParallelism = (int)Math.Round(Environment.ProcessorCount / 2.0) }, file => { string path = GetCorrectFilePath(file.Filename); // First check if the file exists // then check if the hashes are the same if (File.Exists(path) && Cryptography.CalculateSha256(path) == file.Sha256) { } else { unpatched.Add(file); } }); return(new FileManifestCollection(unpatched.ToArray())); }
/// <summary> /// Downloads all unpatched files /// </summary> /// <param name="collection">The file manifest collection</param> private async Task DownloadUnpatchedFiles(IFileManifestCollection collection) { // Make sure download folder is created Directory.CreateDirectory(Path.Combine(_downloadPath, "")); Directory.CreateDirectory(Path.Combine(_downloadPath, "config")); Directory.CreateDirectory(Path.Combine(_downloadPath, "resources", "default")); foreach (var file in collection.Files) { // Download started OnFileStartDownload(this, new FileManifestEventArgs(file)); // Begin downloading await DownloadFile(file); // Download finished OnFileDownloaded(this, new FileManifestEventArgs(file)); // Delay to give webserver some time to rest await Task.Delay(3000); } }