public static void Decompress(FileInfo fileToDecompress, Subtitle subtitle) { string newFileName = String.Empty; try { using (FileStream originalFileStream = fileToDecompress.OpenRead()) { string currentFileName = fileToDecompress.FullName; newFileName = currentFileName.Remove(currentFileName.Length - fileToDecompress.Extension.Length); newFileName = Path.Combine(subtitle.ParentDirectoryPath, subtitle.FileName); using (FileStream decompressedFileStream = File.Create(newFileName)) { using (GZipStream decompressionStream = new GZipStream(originalFileStream, CompressionMode.Decompress)) { decompressionStream.CopyTo(decompressedFileStream); } } } } catch (Exception e) // Ako dekompresija ne uspije, probaj na drugi način { using (ZipArchive archive = ZipFile.OpenRead(fileToDecompress.FullName)) { foreach (ZipArchiveEntry entry in archive.Entries) { ZipFileExtensions.ExtractToFile(entry, newFileName, true); } } } }
private async Task HandleManagedDlls(PackageIdentity packageIdentity, List <ZipArchiveEntry> zipArchiveEntries) { var entriesWithTargetFramework = zipArchiveEntries .Select(e => new { TargetFramework = NuGetFramework.Parse(e.FullName.Split('/')[1]), Entry = e }).ToList(); if (_filterOurRefFiles) { entriesWithTargetFramework = entriesWithTargetFramework.Where(e => !string.Equals(e.Entry.FullName.Split('/')[0], "ref")).ToList(); } var compatibleEntries = entriesWithTargetFramework.Where(e => _compProvider.IsCompatible(_targetFramework, e.TargetFramework)).ToList(); var mostCompatibleFramework = _reducer.GetNearest(_targetFramework, compatibleEntries.Select(x => x.TargetFramework)); if (mostCompatibleFramework == null) { return; } var matchingEntries = entriesWithTargetFramework .Where(e => e.TargetFramework == mostCompatibleFramework).ToList(); if (matchingEntries.Any()) { var pluginAssemblies = new List <string>(); foreach (var e in matchingEntries) { ZipFileExtensions.ExtractToFile(e.Entry, Path.Combine(_root, e.Entry.Name), overwrite: true); var installedDllInfo = new DllInfo { RelativeFilePath = Path.Combine(packageIdentity.ToString(), e.Entry.FullName), FullFilePath = Path.Combine(_root, packageIdentity.ToString(), e.Entry.FullName), FileName = e.Entry.Name, TargetFrameworkName = e.TargetFramework.ToString(), TargetFrameworkShortName = e.TargetFramework.GetShortFolderName(), PackageIdentity = packageIdentity.Id, TargetVersion = e.TargetFramework.Version.ToString() }; InstalledDlls.Add(installedDllInfo); if (packageIdentity.Id == _pluginNuGetPackage.Identity.Id) { pluginAssemblies.Add(e.Entry.Name); } } await File.WriteAllLinesAsync(Path.Combine(_root, PluginAssemblyFilesFileName), pluginAssemblies); } }
// Read archive of KMZ file and save to upload folder private void ReadArchiveAndExport(string pathToimage) { using (ZipArchive archive = ZipFile.Open(path, ZipArchiveMode.Read)) { if (pathToimage != null && map != null) { ZipArchiveEntry entry = archive.GetEntry(pathToimage); string name = Path.GetRandomFileName() + "." + entry.Name; while (File.Exists(Path.Combine(rootPath, name))) { name = Path.GetRandomFileName() + "." + entry.Name; } ZipFileExtensions.ExtractToFile(entry, Path.Combine(rootPath, name)); map.PathToFile = Path.Combine(completePath, name); } } }
private static async Task DownloadData() { using (var client = new HttpClient()) { var response = await client.GetStreamAsync("https://github.com/luisquintanilla/machinelearning-samples/raw/AB1608219/samples/modelbuilder/MulticlassClassification_RestaurantViolations/RestaurantScores.zip"); using (var archive = new ZipArchive(response)) { foreach (var file in archive.Entries) { if (Path.GetExtension(file.FullName) == ".tsv") { ZipFileExtensions.ExtractToFile(file, GetAbsolutePath(TRAIN_DATA_FILEPATH)); } } } } }
public void ExtractEntry(ZipArchiveEntry entry) { string fullName; Stream stream; entry.ExtractToFile(""); // Noncompliant entry.ExtractToFile("", true); // Noncompliant ZipFileExtensions.ExtractToFile(entry, ""); // Noncompliant ZipFileExtensions.ExtractToFile(entry, "", true); // Noncompliant stream = entry.Open(); // Noncompliant entry.Delete(); // Compliant, method is not tracked fullName = entry.FullName; // Compliant, properties are not tracked ExtractToFile(entry); // Compliant, method is not tracked Invoke(ZipFileExtensions.ExtractToFile); // Compliant, not an invocation, but could be considered as FN }
private static string GetCliVersion(string path) { string cliVersion = string.Empty; foreach (string file in Directory.GetFiles(path, "*", SearchOption.AllDirectories)) { if (file.EndsWith(".zip")) { var zip = ZipFile.OpenRead(file); foreach (var entry in zip.Entries) { if (entry.Name == "func.dll") { ZipFileExtensions.ExtractToFile(entry, "func.dll", true); cliVersion = FileVersionInfo.GetVersionInfo(".\\func.dll").FileVersion; break; } } } } return(cliVersion); }