Mono.Addins.AddinRegistry.CreateHostAddinsFile C# (CSharp) Method

CreateHostAddinsFile() private method

private CreateHostAddinsFile ( string hostFile ) : bool
hostFile string
return bool
		internal bool CreateHostAddinsFile (string hostFile)
		{
			hostFile = Path.GetFullPath (hostFile);
			string baseName = Path.GetFileNameWithoutExtension (hostFile);
			if (!Directory.Exists (database.HostsPath))
				Directory.CreateDirectory (database.HostsPath);
			
			foreach (string s in Directory.GetFiles (database.HostsPath, baseName + "*.addins")) {
				try {
					using (StreamReader sr = new StreamReader (s)) {
						XmlTextReader tr = new XmlTextReader (sr);
						tr.MoveToContent ();
						string host = tr.GetAttribute ("host-reference");
						if (host == hostFile)
							return false;
					}
				}
				catch {
					// Ignore this file
				}
			}
			
			string file = Path.Combine (database.HostsPath, baseName) + ".addins";
			int n=1;
			while (File.Exists (file)) {
				file = Path.Combine (database.HostsPath, baseName) + "_" + n + ".addins";
				n++;
			}
			
			using (StreamWriter sw = new StreamWriter (file)) {
				XmlTextWriter tw = new XmlTextWriter (sw);
				tw.Formatting = Formatting.Indented;
				tw.WriteStartElement ("Addins");
				tw.WriteAttributeString ("host-reference", hostFile);
				tw.WriteStartElement ("Directory");
				tw.WriteAttributeString ("shared", "false");
				tw.WriteString (Path.GetDirectoryName (hostFile));
				tw.WriteEndElement ();
				tw.Close ();
			}
			return true;
		}
		

Usage Example

Example #1
0
        internal void Initialize(Assembly startupAsm, string customStartupDirectory, string configDir, string addinsDir, string databaseDir)
        {
            lock (LocalLock) {
                if (initialized)
                {
                    return;
                }

                Initialize(this);

                string asmFile = null;

                if (startupAsm != null)
                {
                    asmFile          = new Uri(startupAsm.CodeBase).LocalPath;
                    startupDirectory = System.IO.Path.GetDirectoryName(asmFile);
                }
                else
                {
                    startupDirectory = customStartupDirectory;
                }

                string customDir = Environment.GetEnvironmentVariable("MONO_ADDINS_REGISTRY");
                if (customDir != null && customDir.Length > 0)
                {
                    configDir = customDir;
                }

                if (string.IsNullOrEmpty(configDir))
                {
                    registry = AddinRegistry.GetGlobalRegistry(this, startupDirectory);
                }
                else
                {
                    registry = new AddinRegistry(this, configDir, startupDirectory, addinsDir, databaseDir);
                }

                if ((asmFile != null && registry.CreateHostAddinsFile(asmFile)) || registry.UnknownDomain)
                {
                    registry.Update(new ConsoleProgressStatus(false));
                }

                initialized = true;

                ActivateRoots();
                OnAssemblyLoaded(null, null);
                AppDomain.CurrentDomain.AssemblyLoad    += new AssemblyLoadEventHandler(OnAssemblyLoaded);
                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve;
            }
        }
All Usage Examples Of Mono.Addins.AddinRegistry::CreateHostAddinsFile