private Dictionary <string, string> GetAnkiMediaMapping(ZipArchiveEntry entry, StorageFolder deckFolder) { Dictionary <string, string> numToName = new Dictionary <string, string>(); try { entry.ExtractToFile(deckFolder.Path + "/" + entry.Name, true); using (FileStream mediaMapFile = new FileStream(deckFolder.Path + "/" + "media", FileMode.Open)) { //WARNING: Java ver needs opposite mapping since their extraction method requires it. JsonObject json = JsonObject.Parse(AnkiCore.Sync.HttpSyncer.Stream2String(mediaMapFile)); string name; string num; foreach (var jr in json) { num = jr.Key; name = jr.Value.GetString(); numToName.Add(num, name); } } File.Delete(deckFolder.Path + "/" + entry.Name); return(numToName); } catch { return(null); } }
private static void ExtractEntry(Package package, ZipArchiveEntry entry) { var fileName = entry.FullName.Replace("GameData/", string.Empty); var destinationFilePath = $"{Config.Current.GameDataDirectory}/{fileName}"; var destinationDirectoryName = Path.GetDirectoryName(destinationFilePath); try { Directory.CreateDirectory(destinationDirectoryName); if (Path.GetFileName(fileName) != string.Empty) { entry.ExtractToFile(destinationFilePath, true); package.ExtractedFiles.Add(fileName); if (Path.GetExtension(fileName).ToLower() == ".version") { package.VersionFiles.Add(fileName); } Debug.Log($"Extracted File: '{fileName}'"); } } catch (Exception ex) { Debug.LogException(ex); } }
public static void UnZipNotFolderEntries(ZipArchive zipFile, string absolutePathTargetDirectory, string[] zipEntries, Dictionary <string, string> zipEntryToFilenameMap) { if (zipEntryToFilenameMap == null) { zipEntryToFilenameMap = new Dictionary <string, string>(); } foreach (string requestedEntry in zipEntries) { ZipArchiveEntry entry = zipFile.GetEntry(requestedEntry); if (entry != null) { string name = entry.Name; if (zipEntryToFilenameMap.ContainsKey(name)) { name = zipEntryToFilenameMap[name]; } if (!IsZipEntryFolder(entry)) { entry.ExtractToFile(absolutePathTargetDirectory + "\\" + name); } } } }
public async Task <bool> ExtractEntry(ZipArchiveEntry entry, int tryNum) { var name = (entry.FullName == "update.exe") ? "update2.exe" : entry.FullName; var targPath = Path.Combine("./", name); Directory.CreateDirectory(Path.GetDirectoryName(targPath)); try { entry.ExtractToFile(targPath, true); Console.WriteLine($"{name} extracted..."); return(true); } catch (Exception ex) { if (ex is DirectoryNotFoundException) { return(true); } if (tryNum++ > 3) { Console.WriteLine(""); return(false); } else { Console.WriteLine($"Waiting for {name}... {ex}"); await Task.Delay(3000); return(await ExtractEntry(entry, tryNum)); } } }
private static List <ContentTopic> GetTopicsFromZipFile(string zipPath) { List <ContentTopic> topics = new List <ContentTopic>(); #if ENABLE_WINMD_SUPPORT StorageFolder temporaryFolder = ApplicationData.Current.TemporaryFolder; using (ZipArchive archive = ZipFile.OpenRead(zipPath)) { ZipArchiveEntry entry = archive.Entries.FirstOrDefault(e => e.FullName == "topics.json"); if (entry != null) { // Gets the full path to ensure that relative segments are removed. string destinationPath = Path.GetFullPath(Path.Combine(temporaryFolder.Path, entry.FullName)); // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that // are case-insensitive. if (destinationPath.StartsWith(temporaryFolder.Path, StringComparison.Ordinal)) { entry.ExtractToFile(destinationPath, true); if (File.Exists(destinationPath)) { using (var file = File.OpenText(destinationPath)) { var serializer = new JsonSerializer(); topics = (List <ContentTopic>)serializer.Deserialize(file, typeof(List <ContentTopic>)); } File.Delete(destinationPath); } } } } #endif return(topics); }
private static string ExtractEntry(string extractPath, ZipArchiveEntry entry) { // Gets the full path to ensure that relative segments are removed. string destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName)); // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that // are case-insensitive. if (destinationPath.StartsWith(extractPath, StringComparison.Ordinal)) { bool stop = false; int tries = 0; while (!stop) { try { tries++; entry.ExtractToFile(destinationPath, true); LOGGER.Info($"File '{entry.Name}' was successfully extracted"); stop = true; } catch (Exception) when(tries <= 12) { Thread.Sleep(5000); } } } return(destinationPath); }
private static void ExtractFile(ZipArchiveEntry entry, string outputFilename) { if (File.Exists(outputFilename)) { byte[] zipFileData = new byte[entry.Length]; using (Stream fileStream = entry.Open()) { fileStream.Read(zipFileData, 0, (int)entry.Length); } string diskFileSha1 = GetSha1Hash(File.ReadAllBytes(outputFilename)); string zipFileSha1 = GetSha1Hash(zipFileData); if (diskFileSha1 != zipFileSha1) { try { File.Delete(outputFilename); } catch { } try { File.WriteAllBytes(outputFilename, zipFileData); } catch { } } } else { try { //On Mono, using overwrite = true for ExtractToFile crashes/kills any currently running instance that uses the file. //This is probably a Mono bug? //Better to attempt a delete & then extract, like now (and like it used to be) entry.ExtractToFile(outputFilename); } catch { } } }
/// <summary> /// Transform imported .zip files into maintenance report in docx file /// </summary> /// <param name="sender"></param> /// <param name="e"></param private void Start_OnMouseDown(object sender, MouseButtonEventArgs e) { string krcName, krcSerialNo, krcVersion, krcTech; if (zipCounter > 0) { for (int i = 0; i < zipCounter; i++) { using (ZipArchive archive = ZipFile.OpenRead(filePath[i])) //Open .zip in read mode { // TODO: Victor, aqui ya tiene el .zip abierto. Habría que hacer una bifurcacion: ZipArchiveEntry entry = archive.GetEntry("am.ini"); if (entry != null) { string tempFile = Path.GetTempFileName(); entry.ExtractToFile(tempFile, true); string content = File.ReadAllText(tempFile); krcName = Libs.StringManipulation.GetBetween(content, "RobName=", "IRSerialNr="); krcSerialNo = Libs.StringManipulation.GetBetween(content, "IRSerialNr=", "[Version]"); krcVersion = Libs.StringManipulation.GetBetween(content, "[Version]", "[TechPacks]"); krcTech = Libs.StringManipulation.GetBetween(content, "[TechPacks]", null); //Check? Trace.WriteLine(krcSerialNo.TrimEnd('\n')); File.Copy("plantillainforme.docx", krcName.TrimEnd('\r', '\n') + " Informe de mantenimiento.docx"); } } } } }
public Song Process(FileInfo archive, int id) { _id = id; //empty temp folder foreach (FileInfo enumerateFile in _tempDirectory.EnumerateFiles()) { enumerateFile.Delete(); } Song song; using (ZipArchive zip = ZipFile.OpenRead(archive.FullName)) { //check if the zip contains an mp3 file ZipArchiveEntry mp3File = zip.Entries.FirstOrDefault(entry => entry.Name.EndsWith(".mp3", StringComparison.InvariantCultureIgnoreCase)); if (mp3File == null) { ConsoleHelper.WriteError("Archive contains no mp3 file!"); return(null); } //grab the first beatmap List <ZipArchiveEntry> containsBeatmaps = zip.Entries.Where(entry => entry.Name.Contains(".osu", StringComparison.InvariantCultureIgnoreCase)).ToList(); if (!containsBeatmaps.Any()) { ConsoleHelper.WriteError("Archive contains no beatmaps!"); return(null); } List <ZipArchiveEntry> beatmaps = containsBeatmaps.Where(ContainsTaikoBeatmap).ToList(); if (!beatmaps.Any()) { ConsoleHelper.WriteError("Archive contains no Osu!Taiko beatmaps!!"); return(null); } song = GetSongData(GetIniData(beatmaps.FirstOrDefault())); //initial load for the metadata if (song != null) { song.Courses = ProcessCourses(beatmaps); if (song.Courses != null) { mp3File.ExtractToFile($"{_tempDirectory}\\main.mp3"); } else { ConsoleHelper.WriteError("Failed to find courses!"); song = null; } } } return(song); }
public void Decompress() { if (OsmFile.Extension != ".zip") { return; } DirectoryInfo osmFileDir = new DirectoryInfo(OsmFile.DirectoryName); try { ZipArchive archive = ZipFile.OpenRead(OsmFile.FullName); ZipArchiveEntry entry = archive.Entries[0]; string fileName = string.Format("{0}\\{1}", osmFileDir.FullName, entry.FullName); entry.ExtractToFile(fileName); FileInfo unzippedFile = new FileInfo(fileName); if (unzippedFile.Exists) { archive.Dispose(); archive = null; OsmFile.Delete(); OsmFile = unzippedFile; Zipped = false; } else { throw new Exception("Unable to decompress OSM file."); } } catch (Exception ex) { LogHelper.LogException(ex); } }
private string UnpackAndGetFileName(ZipArchiveEntry entry, string destinationDirectory) { string pathToUnpackedFile = Path.Combine(destinationDirectory, entry.Name); entry.ExtractToFile(pathToUnpackedFile); return(pathToUnpackedFile); }
public async Task <bool> ExtractEntry(ZipArchiveEntry entry, int tryNum) { var name = (entry.FullName == "update.exe") ? "update2.exe" : entry.FullName; var targPath = Path.Combine("./", name); Directory.CreateDirectory(Path.GetDirectoryName(targPath)); try { entry.ExtractToFile(targPath, true); StatusLabel.Text = name + " Extracted..."; return(true); } catch (Exception e) { if (e is DirectoryNotFoundException) { return(true); } if (tryNum++ > 3) { Console.WriteLine("Could not replace " + targPath + "!"); return(false); } else { StatusLabel.Text = "Waiting for " + name + "..." + e.ToString(); await Task.Delay(3000); return(await ExtractEntry(entry, tryNum)); } } }
private static void ExtrairArquivo() { string folderPathDownload = @"D:\Arquivos\"; string filePath = folderPathDownload; Console.WriteLine("Digite o nome do arquivo .zip"); string filename = Console.ReadLine(); filePath += filename; try { if (File.Exists(filePath) && filePath.EndsWith(".zip")) { string fileImg = filePath.Substring(0, filePath.Length - 4) + ".img"; if (!File.Exists(fileImg)) { ZipArchive archive = ZipFile.OpenRead(filePath); ZipArchiveEntry entry = archive.Entries[0]; if (entry.FullName.EndsWith(".img", StringComparison.OrdinalIgnoreCase)) { entry.ExtractToFile(Path.Combine(folderPathDownload, fileImg), true); } Console.WriteLine("Sucesso"); } } else { Console.WriteLine("Arquivo não encontrado ou em formato incorreto!!!!"); } } catch (InvalidDataException e) { Console.WriteLine("Erro " + e); } }
/// <summary> /// Extracts the specified <paramref name="file"/> from the specified <paramref name="zipFile"/> to the specified /// <paramref name="destination"/>, overwriting the file if <paramref name="overwrite"/> is true. /// </summary> /// <param name="zipFile">The zip file from which to extract the file.</param> /// <param name="file">The file to extract from the zip file.</param> /// <param name="destination">The destination directory.</param> /// <param name="overwrite">True if an existing file should be overwritten, false otherwise.</param> /// <returns> /// A Result containing the result of the operation and the fully qualified filename of the extracted file. /// </returns> public virtual IResult <string> ExtractZipFile(string zipFile, string file, string destination, bool overwrite = true) { logger.EnterMethod(xLogger.Params(zipFile, file, destination, overwrite)); logger.Debug($"Extracting file '{file}' from zip file '{zipFile}' into directory '{destination}'..."); IResult <string> retVal = new Result <string>(); try { logger.Trace($"Opening zip file '{zipFile}'..."); using (ZipArchive archive = ZipFile.Open(zipFile, ZipArchiveMode.Read)) { ZipArchiveEntry entry = archive.GetEntry(file); string extractedFile = Path.Combine(destination, entry.Name); logger.Trace($"Extracting file '{file}'..."); entry.ExtractToFile(extractedFile, overwrite); retVal.ReturnValue = extractedFile; } } catch (Exception ex) { logger.Exception(LogLevel.Trace, ex); retVal.AddError(ex.Message); retVal.AddError($"Failed to extract file '{Path.GetFileName(file)}' from zip file '{Path.GetFileName(zipFile)}'."); } retVal.LogResult(logger.Debug); logger.ExitMethod(retVal.ResultCode); return(retVal); }
private static void ExtractZip(string dirpath, string tempFile) { SetPercentage(0); using var stream = new FileStream(tempFile, FileMode.Open, FileAccess.Read); using var zip = new ZipArchive(stream); int total_entry_count = zip.Entries.Count; string fullName = Directory.CreateDirectory(dirpath).FullName; for (int i = 0; i < total_entry_count; i++) { ZipArchiveEntry entry = zip.Entries[i]; string fullPath = Path.GetFullPath(Path.Combine(fullName, entry.FullName)); if (!fullPath.StartsWith(fullName)) { throw new IOException("Extracting Zip entry would have resulted in a file outside the specified destination directory."); } if (Path.GetFileName(fullPath).Length != 0) { Directory.CreateDirectory(Path.GetDirectoryName(fullPath)); entry.ExtractToFile(fullPath, true); } else { if (entry.Length != 0) { throw new IOException("Zip entry name ends in directory separator character but contains data."); } Directory.CreateDirectory(fullPath); } SetPercentage(((i + 1) / total_entry_count) * 100); } }
private List <string> ExtractToFiles(ZipArchiveEntry entry, OSPlatform os, List <string> files) { List <string> extractedFiles = new List <string>(); foreach (string zipFile in files) { string tmpFile = zipFile; if (os != OSPlatform.Windows) { tmpFile = zipFile.Replace('\\', Path.DirectorySeparatorChar); } string file = Path.GetFullPath(Path.Combine(_destination, tmpFile)); string folder = Path.GetDirectoryName(file); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } string fullDestDirPath = Path.GetFullPath(_destination + Path.DirectorySeparatorChar); if (!file.StartsWith(fullDestDirPath)) { throw new System.InvalidOperationException($"Entry is outside the target dir: {file}"); } DoLogInfo($"inflating: {file}"); entry.ExtractToFile(file, true); extractedFiles.Add(file); } return(extractedFiles); }
public static void WriteToDirectory(ZipArchiveEntry entry, string destDirectory) { string destFileName = Path.Combine(destDirectory, entry.FullName); entry.ExtractToFile(destFileName); }
/// <summary> /// Unzip all the files inside the zip filePath that match the Driver Downloader PartialName property /// </summary> /// <param name="fullPath">The path of the zip file</param> public static string UnZipDriverFile(this IDriverDownloader driverDownloader, string fullPath) { try { using (ZipArchive Zip = ZipFile.OpenRead(fullPath)) { ZipArchiveEntry entry = Zip .Entries.FirstOrDefault(n => n.Name.Contains(driverDownloader.PartialName)); if (entry != null) { string driverPath = Path.Combine(Path.GetDirectoryName(fullPath), entry?.Name); entry?.ExtractToFile(driverPath); return(driverPath); } else { throw new Exception("The driver has not been downloaded"); } } } catch (Exception) { throw; } }
public ImageBlock(int id, XElement node, Content content) { ID = id; Content = content; Text = " "; foreach (XAttribute attribute in node.Attributes()) { switch (attribute.Name.ToString()) { case "src": Source = attribute.Value; break; case "alt": Text = attribute.Value; break; } } Sentences = new LinkedList <Sentence>(); foreach (int startIdx in Split(Text)) { new Sentence(startIdx, this); } if (!File.Exists(ImageResource)) { using (ZipArchive archive = ZipFile.Open(ProjectInfo.EpubPath, ZipArchiveMode.Read)) { String imgZipPath = Path.Combine(ProjectInfo.PackageName, Source); ZipArchiveEntry imgEntry = archive.GetEntry(imgZipPath.Replace('\\', '/')); if (imgEntry != null) { imgEntry.ExtractToFile(ImageResource); } } } }
private void UnzipWithEvents(ZipArchiveEntry entry, ILoadDirectory destination, IDataLoadJob job) { //create a task string entryDestination = Path.Combine(destination.ForLoading.FullName, entry.Name); Task unzipJob = Task.Factory.StartNew(() => entry.ExtractToFile(entryDestination, true)); //create a stopwatch to time how long bits take Stopwatch s = new Stopwatch(); s.Start(); FileInfo f = new FileInfo(entryDestination); _entriesUnzipped.Add(f); //monitor it while (!unzipJob.IsCompleted) { Thread.Sleep(200); if (f.Exists) { job.OnProgress(this, new ProgressEventArgs(entryDestination, new ProgressMeasurement((int)(f.Length / 1000), ProgressType.Kilobytes), s.Elapsed)); } } s.Stop(); }
/// <summary> /// Runs the steup.exe from the update archive, and closes this application /// </summary> public static void RunUpdate() { // Ensure we have an update available, and we didnt cancel the download if (!UpdateAvailable || (AsyncArgs?.Cancelled ?? true)) { return; } // Extract setup.exe string exFile = Path.Combine(Program.DocumentsFolder, "setup.exe"); using (ZipArchive file = ZipFile.Open(UpdateFileLocation, ZipArchiveMode.Read)) { ZipArchiveEntry setupFile = file.Entries.FirstOrDefault(x => x.FullName == "setup.exe"); if (setupFile != null) { // Extract and start the new update installer setupFile.ExtractToFile(exFile, true); Process installer = Process.Start(exFile); installer.WaitForInputIdle(); // Exit the application Application.Exit(); } else { throw new Exception("The Setup.exe file appears to be missing from the update archive!"); } } }
private bool HandleGameFileIWad(IGameFile gameFile, StringBuilder sb, LauncherPath gameFileDirectory, LauncherPath tempDirectory) { try { using (ZipArchive za = ZipFile.OpenRead(Path.Combine(gameFileDirectory.GetFullPath(), gameFile.FileName))) { ZipArchiveEntry zae = za.Entries.First(); string extractFile = Path.Combine(tempDirectory.GetFullPath(), zae.Name); if (ExtractFiles) { zae.ExtractToFile(extractFile, true); } sb.Append(string.Format(" -iwad \"{0}\" ", extractFile)); } } catch (FileNotFoundException) { LastError = string.Format("File not found: {0}", gameFile.FileName); return(false); } catch { LastError = string.Format("There was an issue with the IWad: {0}. Corrupted file?", gameFile.FileName); return(false); } return(true); }
/// <summary> /// Updates the Manifest.xml file of the datapackage to be uploaded with the original file name of the related data message before the upload /// </summary> /// <param name="archive">The data package which is being prepared for upload</param> /// <param name="dataMessage">The data message object containing the inforation related to the file which is getting uploaded</param> /// <param name="fileNameInPackageOrig">Original file name in the package</param> /// <returns>Final file name in the package</returns> private string UpdateManifestFile(ZipArchive archive, DataMessage dataMessage, string fileNameInPackageOrig) { if (archive is null || dataMessage is null) { return(fileNameInPackageOrig); } // This modification will cause that the original file name is used in the package that is going to be uploaded to D365 // Get the manifest.xml entery ZipArchiveEntry manifestEntry = archive.GetEntry("Manifest.xml"); // Save the Manifest.xml as temporary file string tempManifestFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); string tempManifestFileNameNew = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); manifestEntry.ExtractToFile(tempManifestFileName, true); // Modify the file name to the original filename XmlDocument tempXmlDocManifest = new XmlDocument(); using (var tempManifestFile = new StreamReader(tempManifestFileName)) { tempXmlDocManifest.Load(new XmlTextReader(tempManifestFile) { Namespaces = false }); tempXmlDocManifest.SelectSingleNode("//InputFilePath[1]").InnerText = Path.GetFileName(dataMessage.FullPath); // Save the document to a file and auto-indent the output. using XmlTextWriter writer = new XmlTextWriter(tempManifestFileNameNew, null); writer.Namespaces = false; writer.Formatting = System.Xml.Formatting.Indented; tempXmlDocManifest.Save(writer); } // Delete the Manifest.xml from the archive file manifestEntry.Delete(); // Add a new Manifest.xml based on the adjusted file archive.CreateEntryFromFile(tempManifestFileNameNew, "Manifest.xml"); // Delete the tempoirary file File.Delete(tempManifestFileName); File.Delete(tempManifestFileNameNew); // Adapt the fileNameInPackage string fileNameInPackage = Path.GetFileName(dataMessage.FullPath); // Check if package template contains input file and remove it first. It should not be there in the first place. ZipArchiveEntry entry = archive.GetEntry(fileNameInPackage); if (entry != null) { entry.Delete(); Log.WarnFormat(CultureInfo.InvariantCulture, string.Format(Resources.Job_0_Package_template_contains_input_file_1_Please_remove_it_from_the_template, fileNameInPackage)); } return(fileNameInPackage); }
private static void ExtractFile(ZipArchiveEntry entry, string filename) { if (!Directory.Exists(Path.GetDirectoryName(filename))) { Directory.CreateDirectory(Path.GetDirectoryName(filename)); } entry.ExtractToFile(filename, true); }
public async Task SaveImageAsync(StorageFile file, uint width) { try { //if (!System.IO.File.Exists(file.Path)) Content.ExtractToFile(file.Path, true); } catch { } }
/// <summary> /// Safely extracts a single file from a zip file /// </summary> /// <param name="file"> /// The zip entry we are pulling the file from /// </param> /// <param name="destinationPath"> /// The root of where the file is going /// </param> /// <param name="overwriteMethod"> /// Specifies how we are going to handle an existing file. /// The default is Overwrite.IfNewer. /// </param> public static void ImprovedExtractToFile(ZipArchiveEntry file, string destinationPath, Overwrite overwriteMethod = Overwrite.IfNewer) { //Gets the complete path for the destination file, including any //relative paths that were in the zip file string destinationFileName = Path.Combine(destinationPath, file.FullName); //Gets just the new path, minus the file name so we can create the //directory if it does not exist string destinationFilePath = Path.GetDirectoryName(destinationFileName); //Creates the directory (if it doesn't exist) for the new path Directory.CreateDirectory(destinationFilePath); //Determines what to do with the file based upon the //method of overwriting chosen switch (overwriteMethod) { case Overwrite.Always: //Just put the file in and overwrite anything that is found file.ExtractToFile(destinationFileName, true); break; case Overwrite.IfNewer: //Checks to see if the file exists, and if so, if it should //be overwritten if (!File.Exists(destinationFileName) || File.GetLastWriteTime(destinationFileName) < file.LastWriteTime) { //Either the file didn't exist or this file is newer, so //we will extract it and overwrite any existing file file.ExtractToFile(destinationFileName, true); } break; case Overwrite.Never: //Put the file in if it is new but ignores the //file if it already exists if (!File.Exists(destinationFileName)) { file.ExtractToFile(destinationFileName); } break; default: break; } }
public static ThemeResult ExtractTheme(string zipPath, string themeId, ThemeConfig preloadedTheme = null) { if (!File.Exists(zipPath)) { return(new ThemeResult(new FailedToFindLocation(themeId, zipPath))); } string themePath = Path.Combine("themes", themeId); ThemeResult result; try { using (ZipArchive archive = ZipFile.OpenRead(zipPath)) { if (preloadedTheme == null) { try { ZipArchiveEntry themeJson = archive.Entries.Single( entry => Path.GetExtension(entry.Name) == ".json"); themeJson.ExtractToFile(Path.Combine(themePath, "theme.json"), true); } catch (InvalidOperationException) { return(new ThemeResult(new NoThemeJSONInZIP(themeId, zipPath))); } result = TryLoad(themeId); } else { Directory.CreateDirectory(themePath); result = new ThemeResult(preloadedTheme); } ZipArchiveEntry[] imageEntries = archive.Entries.Where( entry => Path.GetDirectoryName(entry.FullName) == "" && Path.GetExtension(entry.Name) != ".json").ToArray(); if (imageEntries.Length == 0) { return(new ThemeResult(new NoImagesInZIP(themeId, zipPath))); } foreach (ZipArchiveEntry imageEntry in imageEntries) { imageEntry.ExtractToFile(Path.Combine(themePath, imageEntry.Name), true); } } } catch (InvalidDataException) { return(new ThemeResult(new InvalidZIP(themeId, zipPath))); } return(result); }
public static async Task ExtractToFileAsync(this ZipArchiveEntry source, string destinationFileName, bool overwrite, CancellationToken cancellationToken = default, bool deleteAtCancellation = false) { try { await Task.Run(() => source.ExtractToFile(destinationFileName, overwrite), cancellationToken); } catch { if (deleteAtCancellation) { await FileAsync.TryAndRetryDeleteAsync(destinationFileName); } } }
private static async Task ExtractZipEntry(StorageFolder temporaryOutputFolder, ZipArchiveEntry entry, string relativePath) { var relativeFolderPath = Path.GetDirectoryName(relativePath); var filename = Path.GetFileName(relativePath); if (string.IsNullOrEmpty(relativeFolderPath)) { var outputPath = Path.Combine(temporaryOutputFolder.Path, filename); entry.ExtractToFile(outputPath, true); } else { var folder = await temporaryOutputFolder.CreateFolderAsync(relativeFolderPath, CreationCollisionOption.OpenIfExists); var outputPath = Path.Combine(folder.Path, filename); entry.ExtractToFile(outputPath, true); } }
public void WriteStream() { if (File.Exists(GeneralInfo.GetPathInGameDir(Path)) && !allowOverwrite) { return; } zipEntry.ExtractToFile(GeneralInfo.GetPathInGameDir(Path), true); }