Example #1
0
        internal override void PrepareUninstall(IProgressMonitor monitor, AddinStore service)
        {
            iaddin = service.Registry.GetAddin(info.Id, true);
            if (iaddin == null)
            {
                throw new InstallException(string.Format("The add-in '{0}' is not installed.", info.Name));
            }

            AddinDescription conf = iaddin.Description;

            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));
                return;
            }

            // The add-in is a core application add-in. It can't be uninstalled, so it will be disabled.
            if (!service.IsUserAddin(iaddin.AddinFile))
            {
                disablingOnUninstall = true;
                return;
            }

            // If the add-in assemblies are loaded, or if there is any file with a write lock, delay the uninstallation
            HashSet <string> files = new HashSet <string> (GetInstalledFiles(conf));

            if (AddinManager.CheckAssembliesLoaded(files) || files.Any(f => HasWriteLock(f)))
            {
                uninstallingLoaded = true;
                return;
            }

            if (!service.HasWriteAccess(iaddin.AddinFile))
            {
                throw new InstallException(AddinStore.GetUninstallErrorNoRoot(info));
            }

            foreach (string path in GetInstalledFiles(conf))
            {
                if (!service.HasWriteAccess(path))
                {
                    throw new InstallException(AddinStore.GetUninstallErrorNoRoot(info));
                }
            }

            tempFolder = CreateTempFolder();
            CopyAddinFiles(monitor, conf, iaddin.AddinFile, tempFolder);
        }