internal Feed(BootstrapRequest request, Swidtag swidtag) : base(request, swidtag) { }
internal string DownloadAndValidateFile(Swidtag swidtag) { var file = DownLoadFileFromLinks(swidtag.Links.Where(each => each.Relationship == Iso19770_2.Relationship.InstallationMedia)); if (string.IsNullOrWhiteSpace(file)) { return null; } var payload = swidtag.Payload; if (payload == null) { //We let the providers that are already posted in the public continue to be installed. return file; } else { //validate the file hash var valid = ValidateFileHash(file, payload); if (!valid) { //if the hash does not match, delete the file in the temp folder file.TryHardToDelete(); return null; } return file; } }
/// <summary> /// Get a package provider from a given path. /// </summary> /// <param name="filePath"></param> /// <param name="suppressErrorsAndWarnings"></param> /// <param name="copyFileToTemp"></param> /// <returns></returns> internal Package GetProviderFromFile(string filePath, bool copyFileToTemp = false, bool suppressErrorsAndWarnings = false) { #if PORTABLE // not supported on core powershell return null; #else if (string.IsNullOrWhiteSpace(filePath) && !System.IO.File.Exists(filePath)) { Warning(Constants.Messages.FileNotFound, filePath); return null; } // support providers with .dll file extension only if (!Path.GetExtension(filePath).EqualsIgnoreCase(".dll")) { if (!suppressErrorsAndWarnings) { Warning(Resources.Messages.InvalidFileType, ".dll", filePath); } return null; } string tempFile = filePath; IEnumerable<XElement> manifests = Enumerable.Empty<XElement>(); if (copyFileToTemp) { try { // Manifest.LoadFrom() does not work with network share, so we need to copy the dll to temp location tempFile = CopyToTempLocation(filePath); if (string.IsNullOrWhiteSpace(tempFile) && !System.IO.File.Exists(tempFile)) { Warning(Constants.Messages.FileNotFound, tempFile); return null; } manifests = Manifest.LoadFrom(tempFile).ToArray(); } finally { if (!string.IsNullOrWhiteSpace(tempFile)) { tempFile.TryHardToDelete(); } } } else { // providers have the provider manifest embeded? manifests = Manifest.LoadFrom(filePath).ToArray(); } if (!manifests.Any()) { if (!suppressErrorsAndWarnings) { Warning(Resources.Messages.MissingProviderManifest, tempFile); } return null; } var source = new Uri(filePath); foreach (var manifest in manifests) { var swidTagObject = new Swidtag(manifest); if (Swidtag.IsSwidtag(manifest) && swidTagObject.IsApplicable(new Hashtable())) { return new Package(this, swidTagObject) { Location = source, Source = source.LocalPath }; } } return null; #endif }
internal Swid(BootstrapRequest request, IEnumerable<Uri> mirrors) { _request = request; _swidtag = DownloadSwidtag(mirrors); }
internal Swid(BootstrapRequest request, Swidtag swidtag) { _request = request; _swidtag = swidtag; }
internal Package(BootstrapRequest request, Swidtag swidtag) : base(request, swidtag) { }
/// <summary> /// Get a package provider from a given path. /// </summary> /// <param name="filePath"></param> /// <param name="suppressErrorsAndWarnings"></param> /// <param name="copyFileToTemp"></param> /// <returns></returns> internal Package GetProviderFromFile(string filePath, bool copyFileToTemp = false, bool suppressErrorsAndWarnings = false) { if (string.IsNullOrWhiteSpace(filePath) && !System.IO.File.Exists(filePath)) { Warning(Constants.Messages.FileNotFound, filePath); return(null); } // support providers with .dll file extention only if (!Path.GetExtension(filePath).EqualsIgnoreCase(".dll")) { if (!suppressErrorsAndWarnings) { Warning(Resources.Messages.InvalidFileType, ".dll", filePath); } return(null); } string tempFile = filePath; IEnumerable <XElement> manifests = Enumerable.Empty <XElement>(); if (copyFileToTemp) { try { // Manifest.LoadFrom() does not work with network share, so we need to copy the dll to temp location tempFile = CopyToTempLocation(filePath); if (string.IsNullOrWhiteSpace(tempFile) && !System.IO.File.Exists(tempFile)) { Warning(Constants.Messages.FileNotFound, tempFile); return(null); } manifests = Manifest.LoadFrom(tempFile).ToArray(); } finally { if (!string.IsNullOrWhiteSpace(tempFile)) { tempFile.TryHardToDelete(); } } } else { // providers have the provider manifest embeded? manifests = Manifest.LoadFrom(filePath).ToArray(); } if (!manifests.Any()) { if (!suppressErrorsAndWarnings) { Warning(Resources.Messages.MissingProviderManifest, tempFile); } return(null); } var source = new Uri(filePath); foreach (var manifest in manifests) { var swidTagObject = new Swidtag(manifest); if (Swidtag.IsSwidtag(manifest) && swidTagObject.IsApplicable(new Hashtable())) { return(new Package(this, swidTagObject) { Location = source, Source = source.LocalPath }); } } return(null); }
/// <summary> /// This initializes the provider registry with the list of package providers. /// (currently a hardcoded list, soon, registry driven) /// </summary> /// <param name="request"></param> internal void LoadProviders(IHostApi request) { if (request == null) { throw new ArgumentNullException("request"); } var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var providerAssemblies = (_initialized ? Enumerable.Empty <string>() : _defaultProviders) .Concat(GetProvidersFromRegistry(Registry.LocalMachine, "SOFTWARE\\MICROSOFT\\ONEGET")) .Concat(GetProvidersFromRegistry(Registry.CurrentUser, "SOFTWARE\\MICROSOFT\\ONEGET")) .Concat(AutoloadedAssemblyLocations.SelectMany(location => { if (Directory.Exists(location)) { return(Directory.EnumerateFiles(location).Where(each => !IsExcluded(each) && (each.EndsWith(".exe", StringComparison.CurrentCultureIgnoreCase) || each.EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase)))); } return(Enumerable.Empty <string>()); })); #if DEEP_DEBUG providerAssemblies = providerAssemblies.ToArray(); foreach (var each in providerAssemblies) { request.Debug("possible assembly: {0}".format(each)); } #endif // find modules that have manifests // todo: expand this out to validate the assembly is ok for this instance of OneGet. providerAssemblies = providerAssemblies.Where(each => Manifest.LoadFrom(each).Any(manifest => Swidtag.IsSwidtag(manifest) && new Swidtag(manifest).IsApplicable(new Hashtable()))); // add inbox assemblies (don't require manifests, because they are versioned with the core) #if !COMMUNITY_BUILD // todo: these should just be strong-named references. for now, just load them from the same directory. providerAssemblies = providerAssemblies.Concat(new[] { Path.Combine(baseDir, "Microsoft.OneGet.MetaProvider.PowerShell.dll"), Path.Combine(baseDir, "Microsoft.OneGet.ArchiverProviders.dll"), Path.Combine(baseDir, "Microsoft.OneGet.CoreProviders.dll"), Path.Combine(baseDir, "Microsoft.OneGet.MsuProvider.dll"), #if !CORE_CLR // can't load these providers here. Path.Combine(baseDir, "Microsoft.OneGet.MsiProvider.dll"), #endif }); #endif #if DEEP_DEBUG providerAssemblies = providerAssemblies.ToArray(); foreach (var each in providerAssemblies) { request.Debug("possible assembly with manifest: {0}".format(each)); } #endif providerAssemblies = providerAssemblies.OrderByDescending(each => { try { // try to get a version from the file first return((ulong)(FourPartVersion)FileVersionInfo.GetVersionInfo(each)); } catch { // otherwise we can't make a distinction. return((ulong)0); } }); providerAssemblies = providerAssemblies.Distinct(new PathEqualityComparer(PathCompareOption.FileWithoutExtension)); #if BEFORE_WE_HAD_MANIFESTS // hack to make sure we don't load the old version of the nuget provider // when we have the ability to examine a plugin without dragging it into the // primary appdomain, this won't be needed. FourPartVersion minimumnugetversion = "2.8.3.6"; providerAssemblies = providerAssemblies.Where(assemblyFile => { try { if ("nuget-anycpu".EqualsIgnoreCase(Path.GetFileNameWithoutExtension(assemblyFile)) && ((FourPartVersion)FileVersionInfo.GetVersionInfo(assemblyFile)) < minimumnugetversion) { return(false); } } catch { } return(true); }); #endif // there is no trouble with loading providers concurrently. #if DEBUG providerAssemblies.SerialForEach(providerAssemblyName => { #else providerAssemblies.ParallelForEach(providerAssemblyName => { #endif try { request.Debug(request.FormatMessageString("Trying provider assembly: {0}", providerAssemblyName)); if (TryToLoadProviderAssembly(providerAssemblyName, request)) { request.Debug(request.FormatMessageString("SUCCESS provider assembly: {0}", providerAssemblyName)); } else { request.Debug(request.FormatMessageString("FAILED provider assembly: {0}", providerAssemblyName)); } } catch { request.Error(Constants.Messages.ProviderPluginLoadFailure, ErrorCategory.InvalidOperation.ToString(), providerAssemblyName, request.FormatMessageString(Constants.Messages.ProviderPluginLoadFailure, providerAssemblyName)); } }); }