Esempio n. 1
0
        public void CancelUpdate(AddIn addIn)
        {
            if ((addIn != null) && (addIn.Action == AddInAction.Update))
            {
                CancelPendingUpdate(addIn);

                // If there is also a NuGet package installed for this, delete it as well
                IPackage addInPackage = GetNuGetPackageForAddIn(addIn, true);
                if (addInPackage != null)
                {
                    // Only remove this package, if really the same version is installed
                    string nuGetVersionInManifest = null;
                    if (addIn.Properties.Contains(ManagedAddIn.NuGetPackageVersionManifestAttribute))
                    {
                        nuGetVersionInManifest = addIn.Properties[ManagedAddIn.NuGetPackageVersionManifestAttribute];
                    }
                    if (nuGetVersionInManifest == addInPackage.Version.ToString())
                    {
                        _nuGet.Packages.UninstallPackage(addInPackage, true, false);
                    }
                }

                AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn);
                eventArgs.PreviousVersionRemains = true;
                _events.OnAddInUninstalled(eventArgs);
                _events.OnAddInStateChanged(eventArgs);
            }
        }
 public void OnAddInUninstalled(AddInInstallationEventArgs e)
 {
     if (AddInUninstalled != null)
     {
         SD.Log.DebugFormatted("[AddInManager2.Events] AddIn uninstalled: {0}", e.AddIn.Name);
         AddInUninstalled(this, e);
     }
 }
 public void OnAddInInstalled(AddInInstallationEventArgs e)
 {
     if (AddInInstalled != null)
     {
         SD.Log.DebugFormatted("[AddInManager2.Events] AddIn installed: {0}", e.AddIn.Name);
         AddInInstalled(this, e);
     }
 }
Esempio n. 4
0
        public void UninstallAddIn(AddIn addIn)
        {
            if ((addIn != null) && (addIn.Manifest.PrimaryIdentity != null))
            {
                SD.Log.DebugFormatted("[AddInManager2] Uninstalling AddIn {0}", addIn.Name);

                List <AddIn> addInList = new List <AddIn>();
                addInList.Add(addIn);
                _sdAddInManagement.RemoveExternalAddIns(addInList);

                CancelPendingUpdate(addIn);
                foreach (string identity in addIn.Manifest.Identities.Keys)
                {
                    // Remove the user AddIn
                    string targetDir = Path.Combine(_sdAddInManagement.UserInstallDirectory, identity);
                    if (Directory.Exists(targetDir))
                    {
                        if (!addIn.Enabled)
                        {
                            try
                            {
                                Directory.Delete(targetDir, true);
                                continue;
                            }
                            catch
                            {
                                // TODO Throw something?
                            }
                        }
                    }

                    _sdAddInManagement.RemoveUserAddInOnNextStart(identity);
                }

                // Successfully uninstalled
                AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn);
                _events.OnAddInUninstalled(eventArgs);
                _events.OnAddInStateChanged(eventArgs);
            }
        }
		private void InstalledAddInStateChanged(object sender, AddInInstallationEventArgs e)
		{
			UpdateInstallationState();
		}
		private void NuGetPackagesChanged(object sender, AddInInstallationEventArgs e)
		{
			ReadPackages();
		}
Esempio n. 7
0
		public void UninstallAddIn(AddIn addIn)
		{
			if ((addIn != null) && (addIn.Manifest.PrimaryIdentity != null))
			{
				SD.Log.DebugFormatted("[AddInManager2] Uninstalling AddIn {0}", addIn.Name);
				
				List<AddIn> addInList = new List<AddIn>();
				addInList.Add(addIn);
				_sdAddInManagement.RemoveExternalAddIns(addInList);
				
				CancelPendingUpdate(addIn);
				foreach (string identity in addIn.Manifest.Identities.Keys)
				{
					// Remove the user AddIn
					string targetDir = Path.Combine(_sdAddInManagement.UserInstallDirectory, identity);
					if (Directory.Exists(targetDir))
					{
						if (!addIn.Enabled)
						{
							try
							{
								Directory.Delete(targetDir, true);
								continue;
							}
							catch
							{
								// TODO Throw something?
							}
						}
					}
					
					_sdAddInManagement.RemoveUserAddInOnNextStart(identity);
				}
				
				// Successfully uninstalled
				AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn);
				_events.OnAddInUninstalled(eventArgs);
				_events.OnAddInStateChanged(eventArgs);
			}
		}
Esempio n. 8
0
		public void CancelUpdate(AddIn addIn)
		{
			if ((addIn != null) && (addIn.Action == AddInAction.Update))
			{
				CancelPendingUpdate(addIn);
				
				// If there is also a NuGet package installed for this, delete it as well
				IPackage addInPackage = GetNuGetPackageForAddIn(addIn, true);
				if (addInPackage != null)
				{
					// Only remove this package, if really the same version is installed
					string nuGetVersionInManifest = null;
					if (addIn.Properties.Contains(ManagedAddIn.NuGetPackageVersionManifestAttribute))
					{
						nuGetVersionInManifest = addIn.Properties[ManagedAddIn.NuGetPackageVersionManifestAttribute];
					}
					if (nuGetVersionInManifest == addInPackage.Version.ToString())
					{
						_nuGet.Packages.UninstallPackage(addInPackage, true, false);
					}
				}
				
				AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn);
				eventArgs.PreviousVersionRemains = true;
				_events.OnAddInUninstalled(eventArgs);
				_events.OnAddInStateChanged(eventArgs);
			}
		}
Esempio n. 9
0
		public AddIn InstallAddIn(IPackage package, string packageDirectory)
		{
			// Lookup for .addin file in package output
			var addInManifestFile = Directory.EnumerateFiles(packageDirectory, "*.addin", SearchOption.TopDirectoryOnly).FirstOrDefault();
			if (addInManifestFile != null)
			{
				SD.Log.DebugFormatted("[AddInManager2] Installing AddIn from package {0} {1}", package.Id, package.Version.ToString());
				
				// Patch metadata of AddIn to have a permanent link to the NuGet package
				if (!PatchAddInManifest(addInManifestFile, package))
				{
					_events.OnAddInOperationError(
						new AddInOperationErrorEventArgs(
							SD.ResourceService.GetString("AddInManager2.InvalidPackage")));
					return null;
				}
				
				AddIn addIn = _sdAddInManagement.Load(addInManifestFile);
				if (addIn.Manifest.PrimaryIdentity == null)
				{
					_events.OnAddInOperationError(
						new AddInOperationErrorEventArgs(
							new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity"))));
					return null;
				}
				
				// Just for safety also patch the properties of AddIn object directly
				PatchAddInProperties(addIn, package);

				// Try to find this AddIn in current registry
				string identity = addIn.Manifest.PrimaryIdentity;
				AddIn foundAddIn = null;
				foreach (AddIn treeAddIn in _sdAddInManagement.AddIns)
				{
					if (treeAddIn.Manifest.Identities.ContainsKey(identity))
					{
						foundAddIn = treeAddIn;
						break;
					}
				}

				// Prevent this AddIn from being uninstalled, if marked for deinstallation
				foreach (string installedIdentity in addIn.Manifest.Identities.Keys)
				{
					_sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity);
				}
				
				// Create target directory for AddIn in user profile & copy package contents there
				CopyAddInFromPackage(addIn, packageDirectory);

				// Install the AddIn using manifest
				if (foundAddIn != null)
				{
					addIn.Action = AddInAction.Update;
					
					SD.Log.DebugFormatted("[AddInManager2] Marked AddIn {0} for update.", addIn.Name);
				}
				else
				{
					addIn.Action = AddInAction.Install;
					_sdAddInManagement.AddToTree(addIn);
				}
				
				// Some debug output about AddIn's manifest
				if ((addIn.Manifest != null) && !String.IsNullOrEmpty(addIn.Manifest.PrimaryIdentity))
				{
					SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states identity '{0}'",
					                      addIn.Manifest.PrimaryIdentity);
				}
				else
				{
					SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states no identity.");
				}
				
				if (addIn.Properties.Contains(ManagedAddIn.NuGetPackageIDManifestAttribute))
				{
					SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states NuGet ID '{0}'",
					                      addIn.Properties[ManagedAddIn.NuGetPackageIDManifestAttribute]);
				}
				else
				{
					SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states no NuGet ID.");
				}
				
				// Mark this AddIn
				ManagedAddIn foundAddInManaged = new ManagedAddIn(foundAddIn);
				ManagedAddIn markedAddIn = new ManagedAddIn(addIn)
				{
					InstallationSource = AddInInstallationSource.NuGetRepository,
					IsTemporary = true,
					IsUpdate = (foundAddIn != null),
					OldVersion = (foundAddIn != null) ?
						new Version(foundAddInManaged.LinkedNuGetPackageVersion ?? foundAddIn.Version.ToString()) : null
				};
				_addInsMarkedForInstall.Add(markedAddIn);
				
				// Successful installation
				AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn);
				_events.OnAddInInstalled(eventArgs);
				_events.OnAddInStateChanged(eventArgs);
				
				return addIn;
			}
			else
			{
				// This is not a valid SharpDevelop AddIn package!
				_events.OnAddInOperationError(
					new AddInOperationErrorEventArgs(
						SD.ResourceService.GetString("AddInManager2.InvalidPackage")));
			}

			return null;
		}
Esempio n. 10
0
		public AddIn InstallAddIn(string fileName)
		{
			if (fileName != null)
			{
				AddIn addIn = null;
				
				bool installAsExternal = false;
				
				switch (Path.GetExtension(fileName).ToLowerInvariant())
				{
					case ".addin":
						
						SD.Log.DebugFormatted("[AddInManager2] Loading {0} as manifest.", fileName);
						
						if (FileUtility.IsBaseDirectory(FileUtility.ApplicationRootPath, fileName))
						{
							// Don't allow to install AddIns from application root path
							_events.OnAddInOperationError(
								new AddInOperationErrorEventArgs(
									SD.ResourceService.GetString("AddInManager.CannotInstallIntoApplicationDirectory")));
							return null;
						}
						
						// Load directly from location
						addIn = _sdAddInManagement.Load(fileName);
						installAsExternal = true;
						
						break;
						
					case ".sdaddin":
					case ".zip":
						
						SD.Log.DebugFormatted("[AddInManager2] Trying to load {0} as local AddIn package.", fileName);
						
						// Try to load the *.sdaddin file as ZIP archive
						ZipFile zipFile = null;
						try
						{
							zipFile = new ZipFile(fileName);
							addIn = LoadAddInFromZip(zipFile);
						}
						catch (Exception)
						{
							// ZIP file seems not to be valid
							_events.OnAddInOperationError(
								new AddInOperationErrorEventArgs(
									SD.ResourceService.GetString("AddInManager2.InvalidPackage")));
							return null;
						}
						finally
						{
							if (zipFile != null)
							{
								zipFile.Close();
							}
						}
						
						break;
						
					default:
						// Unknown format of file
						_events.OnAddInOperationError(
							new AddInOperationErrorEventArgs(
								SD.ResourceService.GetString("AddInManager.UnknownFileFormat") + " " + Path.GetExtension(fileName)));
						return null;
				}
				
				if (addIn != null)
				{
					if ((addIn.Manifest == null) || (addIn.Manifest.PrimaryIdentity == null))
					{
						_events.OnAddInOperationError(
							new AddInOperationErrorEventArgs(
								new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity"))));
						return null;
					}

					// Try to find this AddIn in current registry
					string identity = addIn.Manifest.PrimaryIdentity;
					AddIn foundAddIn = null;
					foreach (AddIn treeAddIn in _sdAddInManagement.AddIns)
					{
						if (treeAddIn.Manifest.Identities.ContainsKey(identity))
						{
							foundAddIn = treeAddIn;
							break;
						}
					}

					// Prevent this AddIn from being uninstalled, if marked for deinstallation
					foreach (string installedIdentity in addIn.Manifest.Identities.Keys)
					{
						_sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity);
					}
					
					if (!installAsExternal)
					{
						// Create target directory for AddIn in user profile & copy package contents there
						CopyAddInFromZip(addIn, fileName);
						
						// Install the AddIn using manifest
						if (foundAddIn != null)
						{
							addIn.Action = AddInAction.Update;
						}
						else
						{
							addIn.Action = AddInAction.Install;
							_sdAddInManagement.AddToTree(addIn);
						}
					}
					else
					{
						// Only add a reference to an external manifest
						_sdAddInManagement.AddExternalAddIns(new AddIn[] { addIn });
					}
					
					// Mark this AddIn
					ManagedAddIn markedAddIn = new ManagedAddIn(addIn)
					{
						IsTemporary = true,
						IsUpdate = (foundAddIn != null),
						OldVersion = (foundAddIn != null) ? foundAddIn.Version : null
					};
					_addInsMarkedForInstall.Add(markedAddIn);
					
					// Successful installation
					AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn);
					_events.OnAddInInstalled(eventArgs);
					_events.OnAddInStateChanged(eventArgs);
					
					return addIn;
				}
			}

			// In successful cases we should have exited somewhere else, in error cases the error event was already fired.
			return null;
		}
Esempio n. 11
0
        public AddIn InstallAddIn(IPackage package, string packageDirectory)
        {
            // Lookup for .addin file in package output
            var addInManifestFile = Directory.EnumerateFiles(packageDirectory, "*.addin", SearchOption.TopDirectoryOnly).FirstOrDefault();

            if (addInManifestFile != null)
            {
                SD.Log.DebugFormatted("[AddInManager2] Installing AddIn from package {0} {1}", package.Id, package.Version.ToString());

                // Patch metadata of AddIn to have a permanent link to the NuGet package
                if (!PatchAddInManifest(addInManifestFile, package))
                {
                    _events.OnAddInOperationError(
                        new AddInOperationErrorEventArgs(
                            SD.ResourceService.GetString("AddInManager2.InvalidPackage")));
                    return(null);
                }

                AddIn addIn = _sdAddInManagement.Load(addInManifestFile);
                if (addIn.Manifest.PrimaryIdentity == null)
                {
                    _events.OnAddInOperationError(
                        new AddInOperationErrorEventArgs(
                            new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity"))));
                    return(null);
                }

                // Just for safety also patch the properties of AddIn object directly
                PatchAddInProperties(addIn, package);

                // Try to find this AddIn in current registry
                string identity   = addIn.Manifest.PrimaryIdentity;
                AddIn  foundAddIn = null;
                foreach (AddIn treeAddIn in _sdAddInManagement.AddIns)
                {
                    if (treeAddIn.Manifest.Identities.ContainsKey(identity))
                    {
                        foundAddIn = treeAddIn;
                        break;
                    }
                }

                // Prevent this AddIn from being uninstalled, if marked for deinstallation
                foreach (string installedIdentity in addIn.Manifest.Identities.Keys)
                {
                    _sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity);
                }

                // Create target directory for AddIn in user profile & copy package contents there
                CopyAddInFromPackage(addIn, packageDirectory);

                // Install the AddIn using manifest
                if (foundAddIn != null)
                {
                    addIn.Action = AddInAction.Update;

                    SD.Log.DebugFormatted("[AddInManager2] Marked AddIn {0} for update.", addIn.Name);
                }
                else
                {
                    addIn.Action = AddInAction.Install;
                    _sdAddInManagement.AddToTree(addIn);
                }

                // Some debug output about AddIn's manifest
                if ((addIn.Manifest != null) && !String.IsNullOrEmpty(addIn.Manifest.PrimaryIdentity))
                {
                    SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states identity '{0}'",
                                          addIn.Manifest.PrimaryIdentity);
                }
                else
                {
                    SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states no identity.");
                }

                if (addIn.Properties.Contains(ManagedAddIn.NuGetPackageIDManifestAttribute))
                {
                    SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states NuGet ID '{0}'",
                                          addIn.Properties[ManagedAddIn.NuGetPackageIDManifestAttribute]);
                }
                else
                {
                    SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states no NuGet ID.");
                }

                // Mark this AddIn
                ManagedAddIn foundAddInManaged = new ManagedAddIn(foundAddIn);
                ManagedAddIn markedAddIn       = new ManagedAddIn(addIn)
                {
                    InstallationSource = AddInInstallationSource.NuGetRepository,
                    IsTemporary        = true,
                    IsUpdate           = (foundAddIn != null),
                    OldVersion         = (foundAddIn != null) ?
                                         new Version(foundAddInManaged.LinkedNuGetPackageVersion ?? foundAddIn.Version.ToString()) : null
                };
                _addInsMarkedForInstall.Add(markedAddIn);

                // Successful installation
                AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn);
                _events.OnAddInInstalled(eventArgs);
                _events.OnAddInStateChanged(eventArgs);

                return(addIn);
            }
            else
            {
                // This is not a valid SharpDevelop AddIn package!
                _events.OnAddInOperationError(
                    new AddInOperationErrorEventArgs(
                        SD.ResourceService.GetString("AddInManager2.InvalidPackage")));
            }

            return(null);
        }
Esempio n. 12
0
        public AddIn InstallAddIn(string fileName)
        {
            if (fileName != null)
            {
                AddIn addIn = null;

                bool installAsExternal = false;

                switch (Path.GetExtension(fileName).ToLowerInvariant())
                {
                case ".addin":

                    SD.Log.DebugFormatted("[AddInManager2] Loading {0} as manifest.", fileName);

                    if (FileUtility.IsBaseDirectory(FileUtility.ApplicationRootPath, fileName))
                    {
                        // Don't allow to install AddIns from application root path
                        _events.OnAddInOperationError(
                            new AddInOperationErrorEventArgs(
                                SD.ResourceService.GetString("AddInManager.CannotInstallIntoApplicationDirectory")));
                        return(null);
                    }

                    // Load directly from location
                    addIn             = _sdAddInManagement.Load(fileName);
                    installAsExternal = true;

                    break;

                case ".sdaddin":
                case ".zip":

                    SD.Log.DebugFormatted("[AddInManager2] Trying to load {0} as local AddIn package.", fileName);

                    // Try to load the *.sdaddin file as ZIP archive
                    ZipFile zipFile = null;
                    try
                    {
                        zipFile = new ZipFile(fileName);
                        addIn   = LoadAddInFromZip(zipFile);
                    }
                    catch (Exception)
                    {
                        // ZIP file seems not to be valid
                        _events.OnAddInOperationError(
                            new AddInOperationErrorEventArgs(
                                SD.ResourceService.GetString("AddInManager2.InvalidPackage")));
                        return(null);
                    }
                    finally
                    {
                        if (zipFile != null)
                        {
                            zipFile.Close();
                        }
                    }

                    break;

                default:
                    // Unknown format of file
                    _events.OnAddInOperationError(
                        new AddInOperationErrorEventArgs(
                            SD.ResourceService.GetString("AddInManager.UnknownFileFormat") + " " + Path.GetExtension(fileName)));
                    return(null);
                }

                if (addIn != null)
                {
                    if ((addIn.Manifest == null) || (addIn.Manifest.PrimaryIdentity == null))
                    {
                        _events.OnAddInOperationError(
                            new AddInOperationErrorEventArgs(
                                new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity"))));
                        return(null);
                    }

                    // Try to find this AddIn in current registry
                    string identity   = addIn.Manifest.PrimaryIdentity;
                    AddIn  foundAddIn = null;
                    foreach (AddIn treeAddIn in _sdAddInManagement.AddIns)
                    {
                        if (treeAddIn.Manifest.Identities.ContainsKey(identity))
                        {
                            foundAddIn = treeAddIn;
                            break;
                        }
                    }

                    // Prevent this AddIn from being uninstalled, if marked for deinstallation
                    foreach (string installedIdentity in addIn.Manifest.Identities.Keys)
                    {
                        _sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity);
                    }

                    if (!installAsExternal)
                    {
                        // Create target directory for AddIn in user profile & copy package contents there
                        CopyAddInFromZip(addIn, fileName);

                        // Install the AddIn using manifest
                        if (foundAddIn != null)
                        {
                            addIn.Action = AddInAction.Update;
                        }
                        else
                        {
                            addIn.Action = AddInAction.Install;
                            _sdAddInManagement.AddToTree(addIn);
                        }
                    }
                    else
                    {
                        // Only add a reference to an external manifest
                        _sdAddInManagement.AddExternalAddIns(new AddIn[] { addIn });
                    }

                    // Mark this AddIn
                    ManagedAddIn markedAddIn = new ManagedAddIn(addIn)
                    {
                        IsTemporary = true,
                        IsUpdate    = (foundAddIn != null),
                        OldVersion  = (foundAddIn != null) ? foundAddIn.Version : null
                    };
                    _addInsMarkedForInstall.Add(markedAddIn);

                    // Successful installation
                    AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn);
                    _events.OnAddInInstalled(eventArgs);
                    _events.OnAddInStateChanged(eventArgs);

                    return(addIn);
                }
            }

            // In successful cases we should have exited somewhere else, in error cases the error event was already fired.
            return(null);
        }