Пример #1
0
        public ProjectVM(ConfuserProject proj, string fileName)
        {
            this.proj     = proj;
            this.fileName = fileName;

            ObservableCollection <ProjectModuleVM> modules = Utils.Wrap(proj, module => new ProjectModuleVM(this, module));

            modules.CollectionChanged += (sender, e) => IsModified = true;
            Modules = modules;

            ObservableCollection <StringItem> plugins = Utils.Wrap(proj.PluginPaths, path => new StringItem(path));

            plugins.CollectionChanged += (sender, e) => IsModified = true;
            Plugins = plugins;

            ObservableCollection <StringItem> probePaths = Utils.Wrap(proj.ProbePaths, path => new StringItem(path));

            probePaths.CollectionChanged += (sender, e) => IsModified = true;
            ProbePaths = probePaths;

            ObservableCollection <ProjectRuleVM> rules = Utils.Wrap(proj.Rules, rule => new ProjectRuleVM(this, rule));

            rules.CollectionChanged += (sender, e) => IsModified = true;
            Rules = rules;

            Protections = new ObservableCollection <ConfuserComponent>();
            Packers     = new ObservableCollection <ConfuserComponent>();
            ComponentDiscovery.LoadComponents(Protections, Packers, Assembly.Load("Confuser.Protections").Location);
            ComponentDiscovery.LoadComponents(Protections, Packers, Assembly.Load("Confuser.Renamer").Location);
        }
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            AddPlugin.Command = new RelayCommand(() =>
            {
                var ofd         = new VistaOpenFileDialog();
                ofd.Filter      = ".NET assemblies (*.exe, *.dll)|*.exe;*.dll|All Files (*.*)|*.*";
                ofd.Multiselect = true;
                if (ofd.ShowDialog() ?? false)
                {
                    foreach (var plugin in ofd.FileNames)
                    {
                        try
                        {
                            ComponentDiscovery.LoadComponents(project.Protections, project.Packers, plugin);
                            project.Plugins.Add(new StringItem(plugin));
                        }
                        catch
                        {
                            MessageBox.Show("Failed to load plugin '" + plugin + "'.");
                        }
                    }
                }
            });

            RemovePlugin.Command = new RelayCommand(() =>
            {
                var selIndex = PluginPaths.SelectedIndex;
                Debug.Assert(selIndex != -1);

                var plugin = project.Plugins[selIndex].Item;
                ComponentDiscovery.RemoveComponents(project.Protections, project.Packers, plugin);
                project.Plugins.RemoveAt(selIndex);

                PluginPaths.SelectedIndex = selIndex >= project.Plugins.Count ? project.Plugins.Count - 1 : selIndex;
            }, () => PluginPaths.SelectedIndex != -1);


            AddProbe.Command = new RelayCommand(() =>
            {
                var fbd = new VistaFolderBrowserDialog();
                if (fbd.ShowDialog() ?? false)
                {
                    project.ProbePaths.Add(new StringItem(fbd.SelectedPath));
                }
            });

            RemoveProbe.Command = new RelayCommand(() =>
            {
                var selIndex = ProbePaths.SelectedIndex;
                Debug.Assert(selIndex != -1);
                project.ProbePaths.RemoveAt(selIndex);
                ProbePaths.SelectedIndex = selIndex >= project.ProbePaths.Count ? project.ProbePaths.Count - 1 : selIndex;
            }, () => ProbePaths.SelectedIndex != -1);
        }
Пример #3
0
 void LoadPlugins()
 {
     foreach (var plugin in Project.Plugins)
     {
         try {
             ComponentDiscovery.LoadComponents(Project.Protections, Project.Packers, plugin.Item);
         }
         catch {
             MessageBox.Show("Failed to load plugin '" + plugin + "'.");
         }
     }
 }