Ejemplo n.º 1
0
        /// <summary>
        /// Constructs and scans a directory for compatible plugins
        /// </summary>
        /// <param name="dir">Directory to scan for DLLs</param>
        public PluginManager(string dir)
        {
            inst_ = this;

            string path = Path.Combine(Directory.GetCurrentDirectory(), dir);

            if (!Directory.Exists(path))
            {
                return;
            }

            foreach (string file in Directory.GetFiles(path))
            {
                if (Path.GetExtension(file).Equals(".dll") && File.Exists(file))
                {
                    try
                    {
                        Assembly        asm               = Assembly.LoadFile(file);
                        Type[]          types             = asm.GetExportedTypes();
                        FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(asm.Location);
                        PluginInfo      plugin            = new PluginInfo(asm.ManifestModule.Name, new string[] { myFileVersionInfo.ProductName, myFileVersionInfo.ProductVersion, myFileVersionInfo.CompanyName, myFileVersionInfo.LegalCopyright, myFileVersionInfo.Comments });

                        foreach (Type t in types)
                        {
                            if (t.GetInterface("PluginLib.IFileEditor") != null)
                            {
                                fileServices_.Add((PluginLib.IFileEditor)Activator.CreateInstance(t));
                                plugin.Components.Add(t.Name);
                            }
                            else if (t.GetInterface("PluginLib.ISearchService") != null)
                            {
                                searchServices_.Add((PluginLib.ISearchService)Activator.CreateInstance(t));
                                plugin.Components.Add(t.Name);
                            }
                            else if (t.GetInterface("PluginLib.ICompilerService") != null)
                            {
                                compilers_.Add((PluginLib.ICompilerService)Activator.CreateInstance(t));
                                plugin.Components.Add(t.Name);
                            }
                            else if (t.GetInterface("PluginLib.IInfoTab") != null)
                            {
                                infoTabs_.Add((PluginLib.IInfoTab)Activator.CreateInstance(t));
                                plugin.Components.Add(t.Name);
                            }
                        }

                        if (plugin.Components.Count > 0)
                        {
                            assemblies.Add(plugin);
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorHandler.inst().Error(ex);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception;

            if (ex != null)
            {
                ErrorHandler.inst().Error(ex);
            }
        }
Ejemplo n.º 3
0
        public void Save()
        {
            string fileName = GetAppDataPath("UserData.xml");

            try {
                System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(UserData));

                using (System.IO.FileStream file = new System.IO.FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None)) {
                    writer.Serialize(file, this);
                    file.Flush();
                    file.Close();
                }
            }
            catch (Exception ex) {
                ErrorHandler.inst().Error(ex);
            }
        }
Ejemplo n.º 4
0
        static UserData LoadUserData()
        {
            string fileName = GetAppDataPath("UserData.xml");

            try {
                if (File.Exists(fileName))
                {
                    System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(UserData));

                    UserData ud = new UserData();
                    using (System.IO.FileStream file = new System.IO.FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                        ud = (UserData)reader.Deserialize(file);
                        file.Close();
                    }

                    return(ud);
                }
                return(new UserData());
            }
            catch (Exception ex) {
                ErrorHandler.inst().Error(ex);
                return(new UserData());
            } finally { }
        }