コード例 #1
0
        void packageManager_PackageInstalling(object sender, PackageOperationEventArgs e)
        {
            var package           = e.Package;
            var entryPoint        = package.Id + BonsaiExtension;
            var executablePackage = package.GetContentFiles().Any(file => file.EffectivePath == entryPoint);

            if (executablePackage)
            {
                galleryRepository.AddPackage(package);
                e.Cancel = true;
            }
            else
            {
                var installPath = e.InstallPath;
                var pivots      = OverlayHelper.FindPivots(package, installPath).ToArray();
                if (pivots.Length > 0)
                {
                    var overlayVersion = OverlayHelper.FindOverlayVersion(package);
                    var overlayManager = OverlayHelper.CreateOverlayManager(packageManager.SourceRepository, installPath);
                    overlayManager.Logger = packageManager.Logger;
                    foreach (var pivot in pivots)
                    {
                        var pivotPackage = overlayManager.SourceRepository.FindPackage(pivot, overlayVersion);
                        if (pivotPackage == null)
                        {
                            throw new InvalidOperationException(string.Format("The package '{0}' could not be found.", pivot));
                        }
                        overlayManager.InstallPackage(pivotPackage, false, false);
                    }
                }
            }
        }
コード例 #2
0
        void packageManager_PackageInstalled(object sender, PackageOperationEventArgs e)
        {
            var package       = e.Package;
            var taggedPackage = IsTaggedPackage(package);
            var installPath   = GetRelativePath(e.InstallPath);

            if (!packageConfiguration.Packages.Contains(package.Id))
            {
                packageConfiguration.Packages.Add(package.Id, package.Version.ToString());
            }
            else
            {
                packageConfiguration.Packages[package.Id].Version = package.Version.ToString();
            }

            AddContentFolders(e.InstallPath, ExtensionsDirectory);
            RegisterLibraryFolders(package, installPath);
            RegisterAssemblyLocations(package, e.InstallPath, installPath, false);
            var pivots = OverlayHelper.FindPivots(package, e.InstallPath).ToArray();

            if (pivots.Length > 0)
            {
                var overlayManager = OverlayHelper.CreateOverlayManager(packageManager.SourceRepository, e.InstallPath);
                foreach (var pivot in pivots)
                {
                    var pivotPackage = overlayManager.LocalRepository.FindPackage(pivot);
                    RegisterLibraryFolders(pivotPackage, installPath);
                    RegisterAssemblyLocations(pivotPackage, e.InstallPath, installPath, false);
                }
            }

            var assemblyLocations = GetCompatibleAssemblyReferences(package).Select(reference => reference.Path);

            RegisterAssemblyLocations(assemblyLocations, e.InstallPath, installPath, taggedPackage);
            packageConfiguration.Save();

            if (package.Id == bootstrapperPackageId && package.Version > bootstrapperVersion)
            {
                var bootstrapperFileName = Path.GetFileName(bootstrapperExePath);
                var bootstrapperFile     = package.GetFiles().FirstOrDefault(file => Path.GetFileName(file.Path).Equals(bootstrapperFileName, StringComparison.OrdinalIgnoreCase));
                if (bootstrapperFile == null)
                {
                    throw new InvalidOperationException(Resources.BootstrapperMissingFromPackage);
                }

                var backupExePath = bootstrapperExePath + OldExtension;
                File.Move(bootstrapperExePath, backupExePath);
                UpdateFile(bootstrapperExePath, bootstrapperFile);
            }
        }
コード例 #3
0
        void packageManager_PackageUninstalling(object sender, PackageOperationEventArgs e)
        {
            var package       = e.Package;
            var taggedPackage = IsTaggedPackage(package);
            var installPath   = GetRelativePath(e.InstallPath);

            packageConfiguration.Packages.Remove(package.Id);

            RemoveContentFolders(package, e.InstallPath, ExtensionsDirectory);
            RemoveLibraryFolders(package, installPath);
            RemoveAssemblyLocations(package, e.InstallPath, false);
            var pivots = OverlayHelper.FindPivots(package, e.InstallPath).ToArray();

            if (pivots.Length > 0)
            {
                var overlayManager = OverlayHelper.CreateOverlayManager(packageManager.SourceRepository, e.InstallPath);
                foreach (var pivot in pivots)
                {
                    var pivotPackage = overlayManager.LocalRepository.FindPackage(pivot);
                    RemoveLibraryFolders(pivotPackage, installPath);
                    RemoveAssemblyLocations(pivotPackage, e.InstallPath, false);
                }
            }

            var assemblyLocations = GetCompatibleAssemblyReferences(package).Select(reference => reference.Path);

            RemoveAssemblyLocations(assemblyLocations, e.InstallPath, taggedPackage);
            packageConfiguration.Save();

            if (pivots.Length > 0)
            {
                var overlayManager = OverlayHelper.CreateOverlayManager(packageManager.SourceRepository, e.InstallPath);
                overlayManager.Logger = packageManager.Logger;
                foreach (var pivot in pivots)
                {
                    overlayManager.UninstallPackage(pivot);
                }
            }
        }