public ExtensionInstance?LoadExtension(string path)
        {
            if (!File.Exists(path))
            {
                return(null);
            }

            if (Path.GetExtension(path).Equals(".zip", StringComparison.OrdinalIgnoreCase))
            {
                var provider = new ZipFileProvider(path);

                try
                {
                    return(_factory.Create(provider, path));
                }

                // If the manifest file couldn't be found, let's try looking at one layer deep with the name
                // of the file as the first folder. This is what happens when you create a zip file from a folder
                // with Windows or 7-zip
                catch (UpgradeException ex) when(ex.InnerException is FileNotFoundException)
                {
                    var subpath     = Path.GetFileNameWithoutExtension(path);
                    var subprovider = new SubFileProvider(provider, subpath);

                    return(_factory.Create(subprovider, path));
                }
            }

            return(null);
        }
        public ExtensionInstance?LoadExtension(string path)
        {
            if (Directory.Exists(path))
            {
                return(_factory.Create(new PhysicalFileProvider(path), path));
            }

            return(null);
        }
        private ExtensionInstance LoadOptionsExtension(IEnumerable <AdditionalOption> values)
        {
            var collection = values.Select(v => new KeyValuePair <string, string>(v.Name, v.Value));
            var config     = new ConfigurationBuilder()
                             .AddInMemoryCollection(collection)
                             .Build();

#pragma warning disable CA2000 // Dispose objects before losing scope
            return(_factory.Create(new PhysicalFileProvider(Environment.CurrentDirectory), Environment.CurrentDirectory, config));

#pragma warning restore CA2000 // Dispose objects before losing scope
        }
Example #4
0
        public ExtensionInstance?LoadExtension(string path)
        {
            if (!File.Exists(path))
            {
                return(null);
            }

            var filename = Path.GetFileName(path);

            if (ExtensionInstance.ManifestFileName.Equals(filename, StringComparison.OrdinalIgnoreCase))
            {
                var dir = Path.GetDirectoryName(path) ?? string.Empty;
                return(_factory.Create(new PhysicalFileProvider(dir), dir));
            }

            return(null);
        }