//I assume you have a `Task.Run(() => Download(url, filePathDir);` calling this so it is on a background thread. public void Download(string url, string filePathDir) { WebClient wc = new WebClient(); Stream zipReadingStream = wc.OpenRead(url); ZipArchive zip = new ZipArchive(zipReadingStream); ZipFileExtensions.ExtractToDirectory(zip, filePathDir, _progress); }
protected void uploadFiles() { this.txtCaptcha.Text = ""; bool dataOkay = false; dataOkay = this.FileUpload1.HasFile; if (dataOkay) { try { string fileName = this.FileUpload1.FileName; //this.SequenceNames.Add(); this.FileUpload1.SaveAs(Path.Combine(this.ExpPath, fileName)); using (ZipArchive archive = ZipFile.OpenRead(Path.Combine(this.ExpPath, fileName))) { ZipFileExtensions.ExtractToDirectory(archive, ExpPath); } this.msg2.Visible = true; this.msg2.Text = "Files uploaded successfully."; } catch (System.Exception) { this.msg2.Visible = true; this.msg2.Text = "Error uploading files."; } } }
private static bool Extract(byte[] files, string directory) { using (var stream = new MemoryStream(files)) { var Zip = new ZipArchive(stream); ZipFileExtensions.ExtractToDirectory(Zip, directory); } return(true); }
private async Task <string> GetTextFromLaTeXZip(MemoryStream ms) { var tmpPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName().Replace(".", "")); Directory.CreateDirectory(tmpPath); try { try { ms.Seek(0, SeekOrigin.Begin); var zipFile = new ZipArchive(ms); ZipFileExtensions.ExtractToDirectory(zipFile, tmpPath, true); } catch (Exception) { _logger.LogInformation("Received file is not a zip file. GetTextFromLaTeXZip will return null."); return(null); } var tmpFile = Path.Combine(tmpPath, "main.tex"); if (!System.IO.File.Exists(tmpFile)) { _logger.LogInformation("main.tex not found in the received zip file. GetTextFromLaTeXZip will return null."); return(null); } RunCommand($"cd \"{tmpPath}\" && untex -m -o -e -a -i {tmpFile} > {tmpFile}.txt"); var textData = await System.IO.File.ReadAllBytesAsync(tmpFile + ".txt"); var text = Encoding.UTF8.GetString(textData); return(text); } catch (Exception ex) { _logger.LogWarning($"GetTextFromLaTeXZip failed: {ex}"); return(null); } finally { if (Directory.Exists(tmpPath)) { Directory.Delete(tmpPath, true); } } }
public void ExtractArchive(ZipArchive archive) { foreach (var entry in archive.Entries) { entry.ExtractToFile(""); // Noncompliant // ^^^^^^^^^^^^^^^^^^^^^^^ } for (int i = 0; i < archive.Entries.Count; i++) { archive.Entries[i].ExtractToFile(""); // Noncompliant } archive.Entries.ToList() .ForEach(e => e.ExtractToFile("")); // Noncompliant // ^^^^^^^^^^^^^^^^^^^ ZipFileExtensions.ExtractToDirectory(archive, ""); // Noncompliant archive.ExtractToDirectory(""); // Noncompliant }
public static bool downloadLibrary(Library lib, string targetFolder) { string versionedLibFolder = Path.Combine(targetFolder, Path.GetFileNameWithoutExtension(lib.url)); string unversionedLibFolder = versionedLibFolder.Substring(0, versionedLibFolder.LastIndexOf('-')); if (Directory.Exists(unversionedLibFolder)) { return(false); } WebClient client = null; MemoryStream zippedStream = null; ZipArchive libArchive = null; try { client = new WebClient(); zippedStream = new MemoryStream(client.DownloadData(lib.url)); libArchive = new ZipArchive(zippedStream); ZipFileExtensions.ExtractToDirectory(libArchive, targetFolder); Directory.Move(versionedLibFolder, unversionedLibFolder); return(true); } catch //(Exception ex) { return(false); } finally { if (Directory.Exists(versionedLibFolder)) { Directory.Delete(versionedLibFolder); } client?.Dispose(); zippedStream?.Dispose(); libArchive?.Dispose(); } }
public MEFLoader() { RemoveTrash(); #region Update process var baseUpdateDir = new DirectoryInfo("plugins\\updates"); if (baseUpdateDir.Exists) { foreach (var pluginContainer in baseUpdateDir.GetFiles("*.bpl")) { try { ValidatePluginContainer(pluginContainer); using (var zip = new ZipArchive(new FileStream(pluginContainer.FullName, FileMode.Open))) { var entry = zip.GetEntry("plugin.definition"); if (null != entry) { using (var tr = new System.IO.StreamReader(entry.Open())) { IniFile definition = new IniFile(tr); var name = definition.GetValue("plugin", "name"); var version = definition.GetValue("plugin", "version"); var bitness = definition.GetValue("plugin", "bitness"); var installpath = definition.GetValue("plugin", "installpath"); var contentfolder = definition.GetValue("plugin", "contentfolder"); Logger.Info(String.Format("Installing or updating plugin by plugincontainer.")); Logger.Info(String.Format(" Plugin container file: {0}", pluginContainer.FullName)); Logger.Info(String.Format(" Plugin bitness: {0}", bitness)); Logger.Info(String.Format(" Plugin installpath: {0}", installpath)); Logger.Info(String.Format(" Plugin version: {0}", version)); String target = Path.Combine(Environment.GetEnvironmentVariable("appdata"), "beRemote", "tmp", contentfolder); ZipFileExtensions.ExtractToDirectory(zip, target); var contentDir = new DirectoryInfo(Path.Combine(target, contentfolder)); var targetDir = new DirectoryInfo((installpath.StartsWith("\\")) ? installpath.Remove(0, 1) : installpath); foreach (var file in contentDir.GetFiles()) { file.MoveTo(Path.Combine(targetDir.FullName, file.Name)); } foreach (var dir in contentDir.GetDirectories()) { dir.MoveTo(Path.Combine(targetDir.FullName, dir.Name)); } Logger.Info(String.Format("Plugin installed, deleting container")); Directory.Delete(target, true); } } } pluginContainer.Delete(); } catch (Exception ex) { new beRemoteException(beRemoteExInfoPackage.SignificantInformationPackage, "Plugin container is invalid. Removing it from updater.", ex); pluginContainer.Delete(); } } } #endregion }