private void InstallAssemblyProvider(DynamicElement provider, string fastPath, BootstrapRequest request) { if (!Directory.Exists(request.DestinationPath)) { request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.DestinationPathNotSet); return; } var targetFilename = provider.XPath("/swid:SoftwareIdentity/swid:Meta[@targetFilename]").GetAttribute("targetFilename"); if (string.IsNullOrEmpty(targetFilename)) { request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.InvalidFilename); return; } targetFilename = Path.GetFileName(targetFilename); var targetFile = Path.Combine(request.DestinationPath, targetFilename); string tmpFile = null; var failedBecauseInvalid = false; // download the file foreach (var link in provider.XPath("/swid:SoftwareIdentity/swid:Link[@rel = 'installationmedia']")) { var href = link.Attributes["href"]; if (string.IsNullOrEmpty(href) || !Uri.IsWellFormedUriString(href, UriKind.Absolute)) { request.Debug("Bad or missing uri: {0}", href); continue; } try { tmpFile = targetFilename.GenerateTemporaryFilename(); request.Debug("Downloading '{0}' to '{1}'", href, tmpFile); if (!request.DownloadFileToLocation(new Uri(href), tmpFile)) { request.Debug("Failed download of '{0}'", href); continue; } request.Debug("Verifying the package"); var valid = request.IsSignedAndTrusted(tmpFile, request); if (!valid) { request.Debug("Not Valid file '{0}' => '{1}'", href, tmpFile); failedBecauseInvalid = true; request.Warning(Constants.Messages.FileFailedVerification, href); #if !DEBUG tmpFile.TryHardToDelete(); continue; #endif } // looks good! let's keep it if (File.Exists(targetFile)) { request.Debug("Removing old file '{0}'", targetFile); targetFile.TryHardToDelete(); } // is that file still there? if (File.Exists(targetFile)) { request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.UnableToRemoveFile, targetFile); return; } request.Debug("Copying file '{0}' to '{1}'", tmpFile, targetFile); File.Copy(tmpFile, targetFile); if (File.Exists(targetFile)) { // looks good to me. request.YieldFromSwidtag(provider, null, null, null, fastPath); PackageManager._instance.LoadProviders(request); return; } } catch (Exception e) { e.Dump(); } finally { if (!string.IsNullOrEmpty(tmpFile)) { tmpFile.TryHardToDelete(); } } } if (failedBecauseInvalid) { request.Error(ErrorCategory.InvalidData, fastPath, Constants.Messages.FileFailedVerification, fastPath); } }
private void InstallProviderFromInstaller(DynamicElement provider, string fastPath, BootstrapRequest request) { string tmpFile = null; var failedBecauseInvalid = false; // download the file foreach (var link in provider.XPath("/swid:SoftwareIdentity/swid:Link[@rel = 'installationmedia']")) { var href = link.Attributes["href"]; if (string.IsNullOrEmpty(href) || !Uri.IsWellFormedUriString(href, UriKind.Absolute)) { request.Debug("Bad or missing uri: {0}", href); continue; } var artifact = link.Attributes["artifact"]; try { tmpFile = artifact.GenerateTemporaryFilename(); request.Debug("Downloading '{0}' to '{1}'", href, tmpFile); if (!request.DownloadFileToLocation(new Uri(href), tmpFile)) { request.Debug("Failed download of '{0}'", href); continue; } request.Debug("Verifying the package"); var valid = request.IsSignedAndTrusted(tmpFile, request); if (!valid) { request.Debug("Not Valid file '{0}' => '{1}'", href, tmpFile); failedBecauseInvalid = true; request.Warning(Constants.Messages.FileFailedVerification, href); #if !DEBUG tmpFile.TryHardToDelete(); continue; #endif } // we have a valid file. // run the installer if (request.Install(tmpFile, "", request)) { // it installed ok! request.YieldFromSwidtag(provider, null, null, null, fastPath); PackageManager._instance.LoadProviders(request); } else { request.Error(ErrorCategory.InvalidOperation, fastPath, Constants.Messages.FailedProviderBootstrap, fastPath); } } catch (Exception e) { e.Dump(); } finally { if (!string.IsNullOrEmpty(tmpFile)) { tmpFile.TryHardToDelete(); } } } if (failedBecauseInvalid) { request.Error(ErrorCategory.InvalidData, fastPath, Constants.Messages.FileFailedVerification, fastPath); } }