/// <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);
        }
Beispiel #2
0
        /// <summary>
        /// Extracts the entry.
        /// </summary>
        /// <param name="folder">The folder.</param>
        /// <param name="decompressor">The decompressor.</param>
        /// <param name="zipEntry">The zip entry.</param>
        private void ExtractEntry(string folder, ZipFileDecompressor decompressor, ZipEntry zipEntry)
        {
            if (!_preservePath)
            {
                // Si on ne veut pas conserver le chemin, on ignore les répertoires et on force le chemin
                //  du fichier
                if (zipEntry.IsADirectory)
                {
                    return;
                }
                // Forcage du nom du fichier (la propriété est 'internal')
                FieldInfo fi = typeof(ZipEntry).GetField("_fileName", BindingFlags.Instance | BindingFlags.NonPublic);
                fi.SetValue(zipEntry, Path.GetFileName(zipEntry.FileName));
            }

            decompressor.UncompressZipEntry(zipEntry, folder, true);
        }
Beispiel #3
0
        /// <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);
        }