public SetupService ()
		{
			if (AddinManager.IsInitialized)
				registry = AddinManager.Registry;
			else
				registry = AddinRegistry.GetGlobalRegistry ();
			
			repositories = new RepositoryRegistry (this);
			store = new AddinStore (this);
		}
		internal override void Resolve (IProgressMonitor monitor, AddinStore service, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection installedRequired, DependencyCollection unresolved)
		{
			Addin ia = service.Registry.GetAddin (info.Id);
			
			if (ia != null) {
				Package p = AddinPackage.FromInstalledAddin (ia);
				if (!toUninstall.Contains (p))
					toUninstall.Add (p);
					
				if (!info.SupportsVersion (ia.Version)) {
				
					// This addin breaks the api of the currently installed one,
					// it has to be removed, together with all dependencies
					
					Addin[] ainfos = service.GetDependentAddins (info.Id, true);
					foreach (Addin ainfo in ainfos) {
						p = AddinPackage.FromInstalledAddin (ainfo);
						if (!toUninstall.Contains (p))
							toUninstall.Add (p);
					}
				}
			}
			
			foreach (Dependency dep in info.Dependencies) {
				service.ResolveDependency (monitor, dep, this, toInstall, toUninstall, installedRequired, unresolved);
			}
		}
		internal override void RollbackInstall (IProgressMonitor monitor, AddinStore service)
		{
			if (installed) {
				iaddin = service.Registry.GetAddin (info.Id);
				if (iaddin != null)
					CommitUninstall (monitor, service);
			}
		}
		internal override void PrepareInstall (IProgressMonitor monitor, AddinStore service)
		{
			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.");
						
			if (url != null)
				packFile = service.DownloadFile (monitor, url);
			
			tempFolder = CreateTempFolder ();

			// Extract the files			
			using (FileStream fs = new FileStream (packFile, FileMode.Open, FileAccess.Read)) {
				ZipFile zip = new ZipFile (fs);
				foreach (ZipEntry entry in zip) {
					string path = Path.Combine (tempFolder, entry.Name);
					string dir = Path.GetDirectoryName (path);
					if (!Directory.Exists (dir))
						Directory.CreateDirectory (dir);
						
					byte[] buffer = new byte [8192];
					int n=0;
					Stream inStream = zip.GetInputStream (entry);
					Stream outStream = null;
					try {
						outStream = File.Create (path);
						while ((n = inStream.Read (buffer, 0, buffer.Length)) > 0)
							outStream.Write (buffer, 0, n);
					} finally {
						inStream.Close ();
						if (outStream != null)
							outStream.Close ();
					}
				}
			}
			
			foreach (string s in Directory.GetFiles (tempFolder)) {
				if (Path.GetFileName (s) == "addin.info") {
					configFile = s;
					break;
				}
			}

			if (configFile == null)
				throw new InstallException ("Add-in information file not found in package.");
		}
Beispiel #5
0
		internal abstract void RollbackUninstall (IProgressMonitor monitor, AddinStore service);
Beispiel #6
0
		internal abstract void PrepareUninstall (IProgressMonitor monitor, AddinStore service);
Beispiel #7
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);
        }
Beispiel #8
0
        void BuildRepository(IProgressMonitor monitor, Repository rootrep, string rootPath, string relFilePath, ArrayList allAddins)
        {
            DateTime lastModified = DateTime.MinValue;

            string mainFile       = Path.Combine(rootPath, relFilePath);
            string mainPath       = Path.GetDirectoryName(mainFile);
            string supportFileDir = Path.Combine(mainPath, addinFilesDir);

            if (File.Exists(mainFile))
            {
                lastModified = File.GetLastWriteTime(mainFile);
            }

            Repository mainrep = (Repository)AddinStore.ReadObject(mainFile, typeof(Repository));

            if (mainrep == null)
            {
                mainrep = new Repository();
            }

            ReferenceRepositoryEntry repEntry = (ReferenceRepositoryEntry)rootrep.FindEntry(relFilePath);
            DateTime rootLastModified         = repEntry != null ? repEntry.LastModified : DateTime.MinValue;

            bool modified = false;

            monitor.Log.WriteLine("Checking directory: " + mainPath);
            foreach (string file in Directory.GetFiles(mainPath, "*.mpack"))
            {
                DateTime date  = File.GetLastWriteTime(file);
                string   fname = Path.GetFileName(file);
                PackageRepositoryEntry entry = (PackageRepositoryEntry)mainrep.FindEntry(fname);

                if (entry != null && date > rootLastModified)
                {
                    mainrep.RemoveEntry(entry);
                    DeleteSupportFiles(supportFileDir, entry.Addin);
                    entry = null;
                }

                if (entry == null)
                {
                    entry = new PackageRepositoryEntry();
                    AddinPackage p = (AddinPackage)Package.FromFile(file);
                    entry.Addin = (AddinInfo)p.Addin;
                    entry.Url   = fname;
                    entry.Addin.Properties.SetPropertyValue("DownloadSize", new FileInfo(file).Length.ToString());
                    ExtractSupportFiles(supportFileDir, file, entry.Addin);
                    mainrep.AddEntry(entry);
                    modified = true;
                    monitor.Log.WriteLine("Added addin: " + fname);
                }
                allAddins.Add(entry);
            }

            ArrayList toRemove = new ArrayList();

            foreach (PackageRepositoryEntry entry in mainrep.Addins)
            {
                if (!File.Exists(Path.Combine(mainPath, entry.Url)))
                {
                    toRemove.Add(entry);
                    modified = true;
                }
            }

            foreach (PackageRepositoryEntry entry in toRemove)
            {
                DeleteSupportFiles(supportFileDir, entry.Addin);
                mainrep.RemoveEntry(entry);
            }

            if (modified)
            {
                AddinStore.WriteObject(mainFile, mainrep);
                monitor.Log.WriteLine("Updated " + relFilePath);
                lastModified = File.GetLastWriteTime(mainFile);
            }

            if (repEntry != null)
            {
                if (repEntry.LastModified < lastModified)
                {
                    repEntry.LastModified = lastModified;
                }
            }
            else if (modified)
            {
                repEntry = new ReferenceRepositoryEntry();
                repEntry.LastModified = lastModified;
                repEntry.Url          = relFilePath;
                rootrep.AddEntry(repEntry);
            }

            foreach (string dir in Directory.GetDirectories(mainPath))
            {
                if (Path.GetFileName(dir) == addinFilesDir)
                {
                    continue;
                }
                string based = dir.Substring(rootPath.Length + 1);
                BuildRepository(monitor, rootrep, rootPath, Path.Combine(based, "main.mrep"), allAddins);
            }
        }
Beispiel #9
0
		internal override void PrepareUninstall (IProgressMonitor monitor, AddinStore service)
		{
		}
Beispiel #10
0
 internal override void CommitInstall(IProgressMonitor monitor, AddinStore service)
 {
     service.RegisterAddin(monitor, info, tempFolder);
     installed = true;
 }
Beispiel #11
0
        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.");
            }

            if (url != null)
            {
                packFile = service.DownloadFile(monitor, url);
            }

            tempFolder = CreateTempFolder();

            // Extract the files
            using (FileStream fs = new FileStream(packFile, FileMode.Open, FileAccess.Read)) {
                ZipFile zip = new ZipFile(fs);
                try {
                    foreach (ZipEntry entry in zip)
                    {
                        string name;
                        if (Path.PathSeparator == '\\')
                        {
                            name = entry.Name.Replace('/', '\\');
                        }
                        else
                        {
                            name = entry.Name.Replace('\\', '/');
                        }
                        string path = Path.Combine(tempFolder, name);
                        string dir  = Path.GetDirectoryName(path);
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        byte [] buffer    = new byte [8192];
                        int     n         = 0;
                        Stream  inStream  = zip.GetInputStream(entry);
                        Stream  outStream = null;
                        try {
                            outStream = File.Create(path);
                            while ((n = inStream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                outStream.Write(buffer, 0, n);
                            }
                        } finally {
                            inStream.Close();
                            if (outStream != null)
                            {
                                outStream.Close();
                            }
                        }
                    }
                } finally {
                    zip.Close();
                }
            }

            foreach (string s in Directory.GetFiles(tempFolder))
            {
                if (Path.GetFileName(s) == "addin.info")
                {
                    configFile = s;
                    break;
                }
            }

            if (configFile == null)
            {
                throw new InstallException("Add-in information file not found in package.");
            }
        }
 internal override void RollbackUninstall(IProgressMonitor monitor, AddinStore service)
 {
 }
 internal override void CommitUninstall(IProgressMonitor monitor, AddinStore service)
 {
 }
 internal override void PrepareUninstall(IProgressMonitor monitor, AddinStore service)
 {
 }
		internal override void CommitUninstall (IProgressMonitor monitor, AddinStore service)
		{
			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;
				File.Delete (path);
			}
			
			File.Delete (iaddin.AddinFile);
			
			if (Directory.GetFiles (basePath).Length == 0) {
				try {
					Directory.Delete (basePath);
				} catch {
					monitor.ReportWarning ("Directory " + basePath + " could not be deleted.");
				}
			}
			
			monitor.Log.WriteLine ("Done");
		}
		internal override void EndUninstall (IProgressMonitor monitor, AddinStore service)
		{
			if (tempFolder != null)
				Directory.Delete (tempFolder, true);
			tempFolder = null;
		}
Beispiel #17
0
		internal override void CommitUninstall (IProgressMonitor monitor, AddinStore service)
		{
		}
Beispiel #18
0
        internal override void CommitUninstall(IProgressMonitor monitor, AddinStore service)
        {
            if (disablingOnUninstall) {
                disablingOnUninstall = false;
                service.Registry.DisableAddin (info.Id, true);
                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);

            foreach (string path in GetInstalledFiles (conf))
                File.Delete (path);

            File.Delete (iaddin.AddinFile);

            RecDeleteDir (monitor, basePath);

            monitor.Log.WriteLine ("Done");
        }
Beispiel #19
0
		internal override void RollbackUninstall (IProgressMonitor monitor, AddinStore service)
		{
		}
Beispiel #20
0
		internal abstract void Resolve (IProgressMonitor monitor, AddinStore service, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection required, DependencyCollection unresolved);
 internal abstract void Resolve(IProgressMonitor monitor, AddinStore service, PackageCollection toInstall, PackageCollection toUninstall, PackageCollection required, DependencyCollection unresolved);
Beispiel #22
0
		internal abstract void CommitUninstall (IProgressMonitor monitor, AddinStore service);
 internal abstract void PrepareUninstall(IProgressMonitor monitor, AddinStore service);
Beispiel #24
0
		internal virtual void EndInstall (IProgressMonitor monitor, AddinStore service)
		{
		}
 internal abstract void CommitUninstall(IProgressMonitor monitor, AddinStore service);
		internal override void CommitInstall (IProgressMonitor monitor, AddinStore service)
		{
			service.RegisterAddin (monitor, info, tempFolder);
			installed = true;
		}
 internal abstract void RollbackUninstall(IProgressMonitor monitor, AddinStore service);
		internal override void EndInstall (IProgressMonitor monitor, AddinStore service)
		{
			if (url != null && packFile != null)
				File.Delete (packFile);
			if (tempFolder != null)
				Directory.Delete (tempFolder, true);
		}
 internal virtual void EndUninstall(IProgressMonitor monitor, AddinStore service)
 {
 }
		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;
			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));
				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;
				if (!service.HasWriteAccess (path))
					throw new InstallException (AddinStore.GetUninstallErrorNoRoot (info));
			}
			
			tempFolder = CreateTempFolder ();
			CopyAddinFiles (monitor, conf, iaddin.AddinFile, tempFolder);
		}
        void BuildRepository(IProgressMonitor monitor, Repository rootrep, string rootPath, string relFilePath, ArrayList allAddins)
        {
            DateTime lastModified = DateTime.MinValue;

            string mainFile = Path.Combine(rootPath, relFilePath);
            string mainPath = Path.GetDirectoryName(mainFile);

            Repository mainrep = (Repository)AddinStore.ReadObject(mainFile, typeof(Repository));

            if (mainrep == null)
            {
                mainrep = new Repository();
            }

            bool modified = false;

            monitor.Log.WriteLine("Checking directory: " + mainPath);
            foreach (string file in Directory.GetFiles(mainPath, "*.mpack"))
            {
                string fname = Path.GetFileName(file);
                PackageRepositoryEntry entry = (PackageRepositoryEntry)mainrep.FindEntry(fname);
                if (entry == null)
                {
                    entry = new PackageRepositoryEntry();
                    AddinPackage p = (AddinPackage)Package.FromFile(file);
                    entry.Addin = (AddinInfo)p.Addin;
                    entry.Url   = fname;
                    mainrep.AddEntry(entry);
                    modified = true;
                    monitor.Log.WriteLine("Added addin: " + fname);
                }
                allAddins.Add(entry);

                DateTime date = File.GetLastWriteTime(file);
                if (date > lastModified)
                {
                    lastModified = date;
                }
            }

            ArrayList toRemove = new ArrayList();

            foreach (PackageRepositoryEntry entry in mainrep.Addins)
            {
                if (!File.Exists(Path.Combine(mainPath, entry.Url)))
                {
                    toRemove.Add(entry);
                }
            }

            foreach (PackageRepositoryEntry entry in toRemove)
            {
                mainrep.RemoveEntry(entry);
            }

            if (modified || toRemove.Count > 0)
            {
                AddinStore.WriteObject(mainFile, mainrep);
                monitor.Log.WriteLine("Updated " + relFilePath);
            }

            ReferenceRepositoryEntry repEntry = (ReferenceRepositoryEntry)rootrep.FindEntry(relFilePath);

            if (repEntry != null)
            {
                if (repEntry.LastModified < lastModified)
                {
                    repEntry.LastModified = lastModified;
                }
            }
            else
            {
                repEntry = new ReferenceRepositoryEntry();
                repEntry.LastModified = lastModified;
                repEntry.Url          = relFilePath;
                rootrep.AddEntry(repEntry);
            }

            foreach (string dir in Directory.GetDirectories(mainPath))
            {
                string based = dir.Substring(rootPath.Length + 1);
                BuildRepository(monitor, rootrep, rootPath, Path.Combine(based, "main.mrep"), allAddins);
            }
        }
		internal override void RollbackUninstall (IProgressMonitor monitor, AddinStore service)
		{
			if (tempFolder != null) {
				AddinDescription conf = iaddin.Description;
				string configFile = Path.Combine (tempFolder, Path.GetFileName (iaddin.AddinFile));
				
				string addinDir = Path.GetDirectoryName (iaddin.AddinFile);
				CopyAddinFiles (monitor, conf, configFile, addinDir);
			}
		}
 public SetupService(AddinRegistry registry)
 {
     this.registry = registry;
     repositories  = new RepositoryRegistry(this);
     store         = new AddinStore(this);
 }
Beispiel #34
0
 public SetupService(AddinRegistry registry)
 {
     this.registry = registry;
     repositories = new RepositoryRegistry (this);
     store = new AddinStore (this);
 }
Beispiel #35
0
        internal override void CommitUninstall(IProgressMonitor monitor, AddinStore service)
        {
            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;
                File.Delete (path);
            }

            File.Delete (iaddin.AddinFile);

            RecDeleteDir (monitor, basePath);

            monitor.Log.WriteLine ("Done");
        }