public IEnumerable <IFile> Install(PackageDefinition package, DirectoryPath root) { var result = new List <FilePath>(); var paths = new FilePathCollection(PathComparer.Default); // InstallPackage the package. var packagePath = InstallPackage(package, root); var packageDirectory = _fileSystem.GetDirectory(packagePath); if (package.Filters != null && package.Filters.Count > 0) { // Get all files matching the filters. foreach (var filter in package.Filters) { var pattern = string.Concat(packagePath.FullPath, "/", filter.TrimStart('/', '\\')); paths.Add(_globber.GetFiles(pattern)); } } else { // Do a recursive search in the package directory. paths.Add(packageDirectory. GetFiles("*", SearchScope.Recursive) .Select(file => file.Path)); } if (paths.Count > 0) { result.AddRange(paths); } return(result.Select(path => _fileSystem.GetFile(path))); }
/// <summary> /// Installs the specified resource at the given location. /// </summary> /// <param name="package">The package reference.</param> /// <param name="type">The package type.</param> /// <param name="path">The location where to install the package.</param> /// <returns>The installed files.</returns> public IReadOnlyCollection <IFile> Install(PackageReference package, PackageType type, DirectoryPath path) { if (package == null) { throw new ArgumentNullException(nameof(package)); } if (path == null) { throw new ArgumentNullException(nameof(path)); } // Create the addin directory if it doesn't exist. path = GetPackagePath(path.MakeAbsolute(_environment), package); var root = _fileSystem.GetDirectory(path); if (!root.Exists) { _log.Debug("Creating directory {0}", path); root.Create(); } // Package already exist? var packagePath = GetPackagePath(root, package.Package); if (packagePath != null) { // Fetch available content from disc. var content = _contentResolver.GetFiles(packagePath, package, type); if (content.Any()) { _log.Debug("Package {0} has already been installed.", package.Package); return(content); } } // Install the package. InstallPackage(package, path); // Try locating the install folder again. packagePath = GetPackagePath(root, package.Package); // Get the files. var result = _contentResolver.GetFiles(packagePath, package, type); if (result.Count == 0) { if (type == PackageType.Addin) { var framework = _environment.Runtime.TargetFramework; _log.Warning("Could not find any assemblies compatible with {0}.", framework.FullName); } else if (type == PackageType.Tool) { const string format = "Could not find any relevant files for tool '{0}'. Perhaps you need an include parameter?"; _log.Warning(format, package.Package); } } return(result); }