public void OnAddInInstalled(AddInInstallationEventArgs e) { if (AddInInstalled != null) { SD.Log.DebugFormatted("[AddInManager2.Events] AddIn installed: {0}", e.AddIn.Name); AddInInstalled(this, e); } }
private void NuGetPackagesChanged(object sender, AddInInstallationEventArgs e) { ReadPackages(); }
private void InstalledAddInStateChanged(object sender, AddInInstallationEventArgs e) { UpdateInstallationState(); }
public void UninstallAddIn(AddIn addIn) { if ((addIn != null) && (addIn.Manifest.PrimaryIdentity != null)) { SD.Log.DebugFormatted("[AddInManager2] Uninstalling AddIn {0}", addIn.Name); var addInList = new List<AddIn> { addIn }; _sdAddInManagement.RemoveExternalAddIns(addInList); CancelPendingUpdate(addIn); foreach (var identity in addIn.Manifest.Identities.Keys) { // Remove the user AddIn var 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 var eventArgs = new AddInInstallationEventArgs(addIn); _events.OnAddInUninstalled(eventArgs); _events.OnAddInStateChanged(eventArgs); } }
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(Resources.AddInManager2_InvalidPackage)); return null; } var addIn = _sdAddInManagement.Load(addInManifestFile); if (addIn.Manifest.PrimaryIdentity == null) { _events.OnAddInOperationError( new AddInOperationErrorEventArgs( new AddInLoadException(Resources.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 var identity = addIn.Manifest.PrimaryIdentity; AddIn foundAddIn = null; foreach (var treeAddIn in _sdAddInManagement.AddIns) { if (treeAddIn.Manifest.Identities.ContainsKey(identity)) { foundAddIn = treeAddIn; break; } } // Prevent this AddIn from being uninstalled, if marked for deinstallation foreach (var 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 var foundAddInManaged = new ManagedAddIn(foundAddIn); var 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 var 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(Resources.AddInManager2_InvalidPackage)); } return null; }
public AddIn InstallAddIn(string fileName) { if (fileName != null) { AddIn addIn; var 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( Resources.AddInManager_CannotInstallIntoApplicationDirectory)); return null; } // Load directly from location addIn = _sdAddInManagement.Load(fileName); installAsExternal = true; break; case ".vugenaddin": case ".zip": SD.Log.DebugFormatted("[AddInManager2] Trying to load {0} as local AddIn package.", fileName); // Try to load the *.vugenaddin 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(Resources.AddInManager2_InvalidPackage)); return null; } finally { if (zipFile != null) { zipFile.Close(); } } break; default: // Unknown format of file _events.OnAddInOperationError( new AddInOperationErrorEventArgs( Resources.AddInManager_UnknownFileFormat + " " + Path.GetExtension(fileName))); return null; } if (addIn != null) { if ((addIn.Manifest == null) || (addIn.Manifest.PrimaryIdentity == null)) { _events.OnAddInOperationError( new AddInOperationErrorEventArgs( new AddInLoadException(Resources.AddInManager_AddInMustHaveIdentity))); return null; } // Try to find this AddIn in current registry var identity = addIn.Manifest.PrimaryIdentity; AddIn foundAddIn = null; foreach (var treeAddIn in _sdAddInManagement.AddIns) { if (treeAddIn.Manifest.Identities.ContainsKey(identity)) { foundAddIn = treeAddIn; break; } } // Prevent this AddIn from being uninstalled, if marked for deinstallation foreach (var 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 }); } // Mark this AddIn var markedAddIn = new ManagedAddIn(addIn) { IsTemporary = true, IsUpdate = foundAddIn != null, OldVersion = (foundAddIn != null) ? foundAddIn.Version : null }; _addInsMarkedForInstall.Add(markedAddIn); // Successful installation var 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; }
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 var 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); } } var eventArgs = new AddInInstallationEventArgs(addIn) { PreviousVersionRemains = true }; _events.OnAddInUninstalled(eventArgs); _events.OnAddInStateChanged(eventArgs); } }