private static async Task DownloadFile(string uniqueId, DbObject.BundleEntry bundleEntry) { // download file Console.WriteLine("downloading bundle:\"" + uniqueId + "\"."); // the actual download api call byte[] fileContents = await bundlesApi.GetBundleAsync(HttpUtility.UrlEncode(uniqueId)); // remove the ugly hard coded ".zip" by the file extension from the file details string destinationPath = Path.Combine(downloadFolder, uniqueId + ".zip"); using (FileStream writeStream = System.IO.File.Open(destinationPath, FileMode.Create)) { #if DEBUG Console.WriteLine("Saving file to:\"" + destinationPath + "\"."); #endif await writeStream.WriteAsync(fileContents, 0, fileContents.Length); } // TODO: move the unzip functionality to another place and control it by adding retrieving the bunlde details with the file extension // TODO: before unzipping ZipFile.ExtractToDirectory(destinationPath, Path.Combine(downloadFolder, uniqueId)); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Bundle download succeeded! (" + bundleEntry.uniqueId + ")"); Console.ResetColor(); DbReader.Save(db); }
private static async Task HandleBundle(BundleListInner bundle) { string name = Path.GetFileName(bundle.UniqueId); // download is needed if the bundle has no entry in the dbObject // this will redownload all bundles if the db has been reset even if the bundles are actually there if (!db.bundles.ContainsKey(bundle.UniqueId)) { DbObject.BundleEntry bundleEntry = new DbObject.BundleEntry(bundle.DisplayName, bundle.UniqueId); db.bundles.Add(name, bundleEntry); await DownloadFile(bundle.UniqueId, bundleEntry); } }