Пример #1
0
        private static Package ProcessVsix(string sourceVsixPath)
        {
            string temp       = Path.GetTempPath();
            string tempFolder = Path.Combine(temp, Guid.NewGuid().ToString());

            try
            {
                Directory.CreateDirectory(tempFolder);
                ZipFile.ExtractToDirectory(sourceVsixPath, tempFolder);

                var     vsixFile       = Path.GetFileName(sourceVsixPath);
                var     vsixSourcePath = string.IsNullOrEmpty(_source) ? sourceVsixPath : Path.Combine(_source, vsixFile);
                var     parser         = new VsixManifestParser();
                Package package        = parser.CreateFromManifest(tempFolder, vsixFile, vsixSourcePath);


                if (!string.IsNullOrEmpty(package.Icon))
                {
                    string currentDir     = Path.GetDirectoryName(_outputFile);
                    string sourceIconPath = Path.Combine(tempFolder, package.Icon);

                    if (File.Exists(sourceIconPath))
                    {
                        string iconDir = Path.Combine(currentDir, "icons");
                        string icon    = Path.Combine(iconDir, package.ID + Path.GetExtension(package.Icon));

                        if (!Directory.Exists(iconDir))
                        {
                            DirectoryInfo dir = Directory.CreateDirectory(iconDir);
                            dir.Attributes |= FileAttributes.Hidden;
                        }

                        File.Copy(sourceIconPath, icon, true);
                    }
                }

                Console.WriteLine($"Parsed {package.FileName}");

                return(package);
            }
            finally
            {
                Directory.Delete(tempFolder, true);
            }
        }
Пример #2
0
        private static Package ProcessVsix(string sourceVsixPath)
        {
            string temp       = Path.GetTempPath();
            string tempFolder = Path.Combine(temp, Guid.NewGuid().ToString());

            try
            {
                Directory.CreateDirectory(tempFolder);
                ZipFile.ExtractToDirectory(sourceVsixPath, tempFolder);

                var vsixFile = Path.GetFileName(sourceVsixPath);

                string alternateDestination = Path.Combine(_source, vsixFile);

                // Append the relative path to source
                if (_recursive)
                {
                    string subFolder = sourceVsixPath.Substring(_dir.Length);

                    alternateDestination = Path.Combine(_source, subFolder);

                    if (Uri.IsWellFormedUriString(_source, UriKind.RelativeOrAbsolute))
                    {
                        UriBuilder uriBuilder = new UriBuilder(_source);

                        uriBuilder.Path = alternateDestination;

                        alternateDestination = uriBuilder.Uri.ToString();
                    }
                }

                var vsixSourcePath = string.IsNullOrEmpty(_source) ? sourceVsixPath : alternateDestination;

                var     parser  = new VsixManifestParser();
                Package package = parser.CreateFromManifest(tempFolder, vsixFile, vsixSourcePath);


                if (!string.IsNullOrEmpty(package.Icon))
                {
                    string currentDir     = Path.GetDirectoryName(_outputFile);
                    string sourceIconPath = Path.Combine(tempFolder, package.Icon);

                    if (File.Exists(sourceIconPath))
                    {
                        string iconDir = Path.Combine(currentDir, "icons");
                        string icon    = Path.Combine(iconDir, package.ID + Path.GetExtension(package.Icon));

                        if (!Directory.Exists(iconDir))
                        {
                            DirectoryInfo dir = Directory.CreateDirectory(iconDir);
                            dir.Attributes |= FileAttributes.Hidden;
                        }

                        File.Copy(sourceIconPath, icon, true);
                    }
                }

                Console.WriteLine($"Parsed {package.FileName}");

                return(package);
            }
            finally
            {
                Directory.Delete(tempFolder, true);
            }
        }