Esempio n. 1
0
        public static void LoadPlugins()
        {
            PluginList.Clear();
            Type[] types = Utils.GetTypesInNamespace("Plugin", "HelperProject.HelperLibrary.Plugins");

            foreach (Type type in types)
            {
                if (Utils.HasInheritedClass(type.ToString(), "Plugin"))
                {
                    Plugin plugin = (Plugin)Activator.CreateInstance(type);
                    PluginList.Add(plugin);
                }
            }

            if (Directory.Exists(DefaultInfo.ImportedPluginsLocation))
            {
                List <string> subDirs = new List <string>(Directory.GetDirectories(DefaultInfo.ImportedPluginsLocation));
                foreach (string dir in subDirs)
                {
                    try
                    {
                        string    xmlPath = Path.Combine(dir, "setup.xml");
                        XMLPlugin plugin  = new XMLPlugin(xmlPath, imported: true);
                        PluginList.Add(plugin.plugin);
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
        }
// ReSharper restore FieldCanBeMadeReadOnly.Local

    public frmMain()
    {
      InitializeComponent();
      _frmMySettings = new FrmSettings( _mySettings );
      _patchIcons = new ImageList();
      _patchIcons.Images.Add( Resources.Checked_Shield_Green );
      _patchIcons.Images.Add( Resources.Shield_Red );
      if ( !File.Exists( _rootProgDir + @"\XML\CenRep.xml" ) ) return;
      plugin = new XMLPlugin(_rootProgDir + @"\XML\CenRep.xml", "CENREP");
      _phones = new XMLPlugin(_rootProgDir + @"\XML\Phones.xml", "PHONES");
      plugin.Filter = "";
      _phones.Filter = "";
      cmbName.Items.Clear();
      
      for (int i = 0; i < _phones.Count; i++)
      {
// ReSharper disable PossibleNullReferenceException
        cmbName.Items.Add(_phones[i].Attribute("type").Value);
// ReSharper restore PossibleNullReferenceException
      }
      lstCenRep.LargeImageList = _patchIcons;
      lstCenRep.SmallImageList = _patchIcons;

      if (_mySettings.AttachDirectory != "")
        if (!Directory.Exists(_mySettings.AttachDirectory))
        {
          try
          {
            Directory.CreateDirectory(_mySettings.AttachDirectory);
          }
          catch (Exception)
          {
            MessageBox.Show(Resources.frmMain_AttachDoesnotExists, Resources.frmInternalEditor_frmInternalEditor_WARNING);
            _mySettings.AttachDirectory = "";
            _mySettings.Save();
           }
        }
      if(_mySettings.BackupPath !="")
        if (!Directory.Exists(_mySettings.BackupPath))
        {
          try
          {
            Directory.CreateDirectory(_mySettings.BackupPath);
          }
          catch (Exception)
          {
            MessageBox.Show(
              Resources.frmMain_Backupdoeasnotexists,
              Resources.frmInternalEditor_frmInternalEditor_WARNING);
            _mySettings.BackupPath = "";
            _mySettings.AutoBackup = false;
            _mySettings.Save();
            throw;
          }
        }
    }
        private bool verifySetupFile(string setupPath)
        {
            try
            {
                XMLPlugin setupFile = new XMLPlugin(setupPath);
                plugin = setupFile.plugin;
            }
            catch (Exception ex)
            {
                Dialogs.ErrorMessage(ex.Message);
                return(false);
            }

            return(true);
        }