static void UnzipTo(string vsixPath, string path) { var decompressor = new ZipFileDecompressor(vsixPath); decompressor.UncompressToFolder(path); decompressor.Close(); }
private bool UnzipTemplate(string sourceZipFile, string unzipFolderPath) { // Try to unzip file to temp folder var compressor = new ZipFileDecompressor(sourceZipFile); try { tracer.Info( Resources.VsTemplateFileImporter_TraceUnzipTemplateFile, sourceZipFile, unzipFolderPath); compressor.UncompressToFolder(unzipFolderPath, true); return(true); } catch (ZipException ex) { tracer.Error( Resources.VsTemplateFileImporter_TraceFailedToUnzipToLocation, sourceZipFile, this.currentElement.InstanceName, unzipFolderPath, ex.Message); return(false); } finally { if (compressor != null) { compressor.Close(); } } }
private static string UncompressToTempDir(string templateFilename) { // Unzip temporarily to overwrite the .vstemplate later. var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); if (Directory.Exists(tempDir)) { Directory.Delete(tempDir, true); } if (File.Exists(tempDir)) { File.Delete(tempDir); } Directory.CreateDirectory(tempDir); var decompressor = new ZipFileDecompressor(templateFilename); try { decompressor.UncompressToFolder(tempDir); } finally { decompressor.Close(); decompressor = null; } return(tempDir); }
/// <summary> /// Extrait tous les fichiers dans le repertoire cible /// </summary> /// <param name="folder">Chemin du répertoire cible</param> /// <remarks> /// L'extraction est transactionelle, elle est d'abord effectuée dans un répertoire temporaire et /// si tout est ok, ce répertoire est déplacé sur le répetrtoire cible aprés suppression de celui-ci. /// De cette manière, le répertoire cible contient l'image exacte du fichier zip. /// /// <b>Nota :</b> Tous les fichiers extraits se trouve à la racine. /// </remarks> public void ExtractAll(string folder) { string tempFolder = folder; try { // Extraction dans un répertoire temporaire tempFolder = Path.GetTempFileName(); File.Delete(tempFolder); // Extraction dans un répertoire temporaire Directory.CreateDirectory(tempFolder); ZipFileDecompressor decompressor = new ZipFileDecompressor(_zipFileName); try { foreach (ZipEntry zipEntry in decompressor.ZipFileEntries) { ExtractEntry(tempFolder, decompressor, zipEntry); } } finally { decompressor.Close(); } if (Directory.Exists(tempFolder)) { // Rename try { Utils.MoveDirectory(folder, folder + ".bak"); } catch { } Utils.CopyDirectory(tempFolder, folder); } } catch { Utils.MoveDirectory(folder + ".bak", folder); } finally { Utils.RemoveDirectory(folder + ".bak"); Utils.RemoveDirectory(tempFolder); } }
/// <summary> /// Reads the .vstemplate file /// </summary> public static IVsTemplate Read(string templateFilename) { if (templateFilename.EndsWith(TemplateArchiveFileExtension, StringComparison.InvariantCultureIgnoreCase)) { var decompressor = new ZipFileDecompressor(templateFilename); try { // // See if we can find the topmost .vstemplate file. // ones in sub-directories do not need to have the WizardExtension added to them // var templateZipEntry = decompressor.ZipFileEntries .OfType<ZipEntry>() .FirstOrDefault(entry => entry.FileName.EndsWith(TemplateFileExtension, StringComparison.InvariantCultureIgnoreCase) && !entry.FileName.Contains(Path.AltDirectorySeparatorChar) ); if (templateZipEntry == null) { throw new InvalidOperationException(Resources.VsTemplateFile_ErrorNoTemplateInArchive); } var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); decompressor.UncompressZipEntry(templateZipEntry, tempPath, true); var unzippedFile = Path.Combine(tempPath, templateZipEntry.FileName); var template = ReadVsTemplate(unzippedFile); template.PhysicalPath = new FileInfo(templateFilename).FullName; template.TemplateFileName = Path.GetFileName(templateZipEntry.FileName); return template; } finally { decompressor.Close(); } } else if (templateFilename.EndsWith(TemplateFileExtension, StringComparison.InvariantCultureIgnoreCase)) { return ReadVsTemplate(templateFilename); } throw new InvalidOperationException(Resources.VsTemplateFile_ErrorUnsupportedVsTemplateExtension); }
/// <summary> /// Reads the .vstemplate file /// </summary> public static IVsTemplate Read(string templateFilename) { if (templateFilename.EndsWith(TemplateArchiveFileExtension, StringComparison.InvariantCultureIgnoreCase)) { var decompressor = new ZipFileDecompressor(templateFilename); try { // // See if we can find the topmost .vstemplate file. // ones in sub-directories do not need to have the WizardExtension added to them // var templateZipEntry = decompressor.ZipFileEntries .OfType <ZipEntry>() .FirstOrDefault(entry => entry.FileName.EndsWith(TemplateFileExtension, StringComparison.InvariantCultureIgnoreCase) && !entry.FileName.Contains(Path.AltDirectorySeparatorChar) ); if (templateZipEntry == null) { throw new InvalidOperationException(Resources.VsTemplateFile_ErrorNoTemplateInArchive); } var tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); decompressor.UncompressZipEntry(templateZipEntry, tempPath, true); var unzippedFile = Path.Combine(tempPath, templateZipEntry.FileName); var template = ReadVsTemplate(unzippedFile); template.PhysicalPath = new FileInfo(templateFilename).FullName; template.TemplateFileName = Path.GetFileName(templateZipEntry.FileName); return(template); } finally { decompressor.Close(); } } else if (templateFilename.EndsWith(TemplateFileExtension, StringComparison.InvariantCultureIgnoreCase)) { return(ReadVsTemplate(templateFilename)); } throw new InvalidOperationException(Resources.VsTemplateFile_ErrorUnsupportedVsTemplateExtension); }
/// <summary> /// Extrait un fichier /// </summary> /// <param name="folder">Répertoire cible</param> /// <param name="filterExtension">Filtre d'extension sous la forme (.xxx)</param> public void ExtractFileWithExtension(string folder, string filterExtension) { ZipFileDecompressor decompressor = new ZipFileDecompressor(_zipFileName); try { foreach (ZipEntry zipEntry in decompressor.ZipFileEntries) { if (filterExtension == null || zipEntry.IsADirectory || Utils.StringCompareEquals(filterExtension, Path.GetExtension(zipEntry.FileName))) { ExtractEntry(folder, decompressor, zipEntry); } } } finally { decompressor.Close(); } }
private static string UncompressToTempDir(string templateFilename) { // Unzip temporarily to overwrite the .vstemplate later. var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); if (Directory.Exists(tempDir)) Directory.Delete(tempDir, true); if (File.Exists(tempDir)) File.Delete(tempDir); Directory.CreateDirectory(tempDir); var decompressor = new ZipFileDecompressor(templateFilename); try { decompressor.UncompressToFolder(tempDir); } finally { decompressor.Close(); decompressor = null; } return tempDir; }
private bool UnzipTemplate(string sourceZipFile, string unzipFolderPath) { // Try to unzip file to temp folder var compressor = new ZipFileDecompressor(sourceZipFile); try { tracer.Info( Resources.VsTemplateFileImporter_TraceUnzipTemplateFile, sourceZipFile, unzipFolderPath); compressor.UncompressToFolder(unzipFolderPath, true); return true; } catch (ZipException ex) { tracer.Error( Resources.VsTemplateFileImporter_TraceFailedToUnzipToLocation, sourceZipFile, this.currentElement.InstanceName, unzipFolderPath, ex.Message); return false; } finally { if (compressor != null) { compressor.Close(); } } }