diff options
author | Lluis Sanchez Gual <lluis@novell.com> | 2011-04-12 22:20:38 +0400 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@novell.com> | 2011-04-12 22:21:02 +0400 |
commit | f2faa0bf3d236f3d40745a992d37c38b0c61f107 (patch) | |
tree | f68d29e512974e83f317b35354aa53661f05b6ec | |
parent | dfef4db5a4613b071e3c17972279056f80f69617 (diff) |
Add support for delayed add-in uninstallation.
When trying to uninstall an add-in which has assemblies loaded in
memory, register them for deletion in the next registry update.
-rw-r--r-- | Mono.Addins.Setup/Mono.Addins.Setup/AddinPackage.cs | 61 |
1 files changed, 47 insertions, 14 deletions
diff --git a/Mono.Addins.Setup/Mono.Addins.Setup/AddinPackage.cs b/Mono.Addins.Setup/Mono.Addins.Setup/AddinPackage.cs index d5ccf3f..bfde245 100644 --- a/Mono.Addins.Setup/Mono.Addins.Setup/AddinPackage.cs +++ b/Mono.Addins.Setup/Mono.Addins.Setup/AddinPackage.cs @@ -39,6 +39,7 @@ using System.Net; using ICSharpCode.SharpZipLib.Zip; using Mono.Addins; using Mono.Addins.Description; +using System.Collections.Generic; namespace Mono.Addins.Setup { @@ -49,6 +50,7 @@ namespace Mono.Addins.Setup string url; string tempFolder; bool disablingOnUninstall; + bool uninstallingLoaded; string configFile; bool installed; Addin iaddin; @@ -118,6 +120,8 @@ namespace Mono.Addins.Setup internal override void PrepareInstall (IProgressMonitor monitor, AddinStore service) { + if (service.Registry.IsRegisteredForUninstall (info.Id)) + throw new InstallException ("The addin " + info.Name + " v" + info.Version + " is scheduled for uninstallation. Please restart the application before trying to install it again."); if (service.Registry.GetAddin (Mono.Addins.Addin.GetFullId (info.Namespace, info.Id, info.Version), true) != null) throw new InstallException ("The addin " + info.Name + " v" + info.Version + " is already installed."); @@ -220,7 +224,6 @@ namespace Mono.Addins.Setup throw new InstallException (string.Format ("The add-in '{0}' is not installed.", info.Name)); AddinDescription conf = iaddin.Description; - string basePath = Path.GetDirectoryName (conf.AddinFile); if (!File.Exists (iaddin.AddinFile)) { monitor.ReportWarning (string.Format ("The add-in '{0}' is scheduled for uninstalling, but the add-in file could not be found.", info.Name)); @@ -233,13 +236,16 @@ namespace Mono.Addins.Setup return; } + HashSet<string> files = new HashSet<string> (GetInstalledFiles (conf)); + if (AddinManager.CheckAssembliesLoaded (files)) { + uninstallingLoaded = true; + return; + } + if (!service.HasWriteAccess (iaddin.AddinFile)) throw new InstallException (AddinStore.GetUninstallErrorNoRoot (info)); - foreach (string relPath in conf.AllFiles) { - string path = Path.Combine (basePath, relPath); - if (!File.Exists (path)) - continue; + foreach (string path in GetInstalledFiles (conf)) { if (!service.HasWriteAccess (path)) throw new InstallException (AddinStore.GetUninstallErrorNoRoot (info)); } @@ -248,6 +254,28 @@ namespace Mono.Addins.Setup CopyAddinFiles (monitor, conf, iaddin.AddinFile, tempFolder); } + IEnumerable<string> GetInstalledFiles (AddinDescription conf) + { + string basePath = Path.GetDirectoryName (conf.AddinFile); + foreach (string relPath in conf.AllFiles) { + string afile = Path.Combine (basePath, relPath); + if (File.Exists (afile)) + yield return afile; + } + foreach (var p in conf.Properties) { + string file; + try { + file = Path.Combine (basePath, p.Value); + if (!File.Exists (file)) + file = null; + } catch { + file = null; + } + if (file != null) + yield return file; + } + } + internal override void CommitUninstall (IProgressMonitor monitor, AddinStore service) { if (disablingOnUninstall) { @@ -256,21 +284,26 @@ namespace Mono.Addins.Setup return; } + AddinDescription conf = iaddin.Description; + + string basePath = Path.GetDirectoryName (conf.AddinFile); + + if (uninstallingLoaded) { + List<string> files = new List<string> (); + files.Add (iaddin.AddinFile); + foreach (string f in GetInstalledFiles (conf)) + files.Add (f); + service.Registry.RegisterForUninstall (info.Id, files); + return; + } + if (tempFolder == null) return; monitor.Log.WriteLine ("Uninstalling " + info.Name + " v" + info.Version); - AddinDescription conf = iaddin.Description; - - string basePath = Path.GetDirectoryName (conf.AddinFile); - - foreach (string relPath in conf.AllFiles) { - string path = Path.Combine (basePath, relPath); - if (!File.Exists (path)) - continue; + foreach (string path in GetInstalledFiles (conf)) File.Delete (path); - } File.Delete (iaddin.AddinFile); |