Exemple #1
0
        public static void Read()
        {
            string path = ApplicationRunTimeContext.GetProcessMainModuleDirectory() + @"\config.ini";

            if (File.Exists(path))
            {
                GlobalConfigInfoModel config = File.ReadAllText(path).ToInstance <GlobalConfigInfoModel>();
                if (config != null)
                {
                    StaticData.GlobalConfig = config;
                }
                else
                {
                    if (StaticData.GlobalConfig == null)
                    {
                        StaticData.GlobalConfig = new GlobalConfigInfoModel()
                        {
                            GlobalTheme = DevComponents.DotNetBar.eStyle.Office2007Blue
                        }
                    }
                    ;
                }
            }
            else
            {
                StaticData.GlobalConfig = new GlobalConfigInfoModel();
                Save();
            }
        }
Exemple #2
0
        internal void Init()
        {
            var root = ApplicationRunTimeContext.GetProcessMainModuleDirectory();

            var cat = new AggregateCatalog();

            cat.Catalogs.Add(new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()));
            cat.Catalogs.Add(new DirectoryCatalog(root, "BR*.dll"));

            var pluginDir = Path.Combine(root, "Plugins");

            if (Directory.Exists(pluginDir))
            {
                cat.Catalogs.Add(new DirectoryCatalog(pluginDir, "*.dll"));
            }

            _container = new CompositionContainer(cat);

            try
            {
                _container.ComposeParts(AppContext.Instance);
            }
            catch (ReflectionTypeLoadException loaderEx)
            {
                throw new Exception(loaderEx.LoaderExceptions.Select(s => s.ToString()).JoinAsString(";"), loaderEx);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #3
0
        public void Load()
        {
            var root = ApplicationRunTimeContext.GetProcessMainModuleDirectory();

            var builder = new ContainerBuilder();

            builder.RegisterInstance(this).AsImplementedInterfaces().SingleInstance();

            var list = new[]
            {
                Assembly.GetEntryAssembly(),
                Assembly.GetExecutingAssembly()
            }.Distinct();
            var extDir = Path.Combine(root, "extensions");

            if (Directory.Exists(extDir))
            {
                list = list.Union(Directory.GetFiles(extDir, "TOBA.*.dll", SearchOption.AllDirectories).Select(Assembly.LoadFile).ToArray());
            }

            var assemblies = list.ToArray();

            builder.RegisterAssemblyModules(assemblies);
            builder.RegisterAssemblyTypes(assemblies).
            Where(s =>
                  s.HasInterface <IExtension>() ||
                  s.HasInterface <IVerifyCodeRecognizeService>() ||
                  s.HasInterface <ISessionPresentor>() ||
                  s.HasInterface <IRequestInspector>()
                  ).
            AsImplementedInterfaces().
            SingleInstance();
            builder.RegisterAssemblyTypes(assemblies).
            Where(s =>
                  s.HasInterface <IRequireSessionInit>()
                  ).
            AsImplementedInterfaces().
            AsSelf();
            GlobalKernel = builder.Build();

            //初始化
            Extensions                 = GlobalKernel.Resolve <IExtension[]>();
            SessionPresentors          = GlobalKernel.Resolve <ISessionPresentor[]>();
            WebRequestInspectors       = GlobalKernel.Resolve <IRequestInspector[]>();
            VerifyCodeRecogniseService = GlobalKernel.Resolve <IVerifyCodeRecognizeService[]>();

            Extensions.ForEach(s => s.Connect());
        }
Exemple #4
0
        private void btnAutoFix_Click(object sender, EventArgs e)
        {
            var path = ApplicationRunTimeContext.GetProcessMainModulePath();

            var psi = new ProcessStartInfo(path, "-fixos");

            if (Environment.OSVersion.Version.Major > 5)
            {
                psi.Verb = "runas";
            }

            try
            {
                Process.Start(psi);
            }
            catch
            {
            }

            System.Environment.Exit(0);
        }
Exemple #5
0
        public static void Save(GlobalConfigInfoModel config)
        {
            string path = ApplicationRunTimeContext.GetProcessMainModuleDirectory() + @"\config.ini";

            IOUtility.WriteAllText(path, config.ToJson());
        }
Exemple #6
0
        void InitUI()
        {
            tsInfos.Click            += (s, e) => new EngineStatistics().ShowDialog(this);
            tsOption.Click           += (s, e) => new ConfigCenter().ShowDialog(this);
            tsDownloadManually.Click += (s, e) => new PromptTorrentInfo().ShowDialog(this);

            var opt = AppContext.Instance.Options;

            stStrictFilter.Checked     = opt.StrictFilter;
            stShowMultilineTab.Checked = opt.MultilineEngineTab;
            tsUsingFloat.Checked       = opt.UsingFloatTip;
            opt.PropertyChanged       += (s, e) =>
            {
                if (e.IsPropertyOf(opt, x => x.StrictFilter))
                {
                    stStrictFilter.Checked = opt.StrictFilter;
                }
                else if (e.IsPropertyOf(opt, x => x.MultilineEngineTab))
                {
                    stShowMultilineTab.Checked = opt.MultilineEngineTab;
                }
                else if (e.IsPropertyOf(opt, x => x.UsingFloatTip))
                {
                    tsUsingFloat.Checked = opt.UsingFloatTip;
                }
            };
            stStrictFilter.CheckedChanged     += (s, e) => opt.StrictFilter = stStrictFilter.Checked;
            stShowMultilineTab.CheckedChanged += (s, e) => opt.MultilineEngineTab = stShowMultilineTab.Checked;
            tsUsingFloat.CheckedChanged       += (s, e) => opt.UsingFloatTip = tsUsingFloat.Checked;
            stStatistics.Click += (s, e) => new EngineStatistics().ShowDialog(this);

            cbKey.AddDataBinding(opt, s => s.Text, s => s.LastSearchKey);
            cbKey.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
            cbKey.DataSource         = (opt.SearchTermsHistory ?? (opt.SearchTermsHistory = new List <string>()));
            cbKey.AutoCompleteSource = AutoCompleteSource.ListItems;
            opt.PropertyChanged     += (s, e) =>
            {
                if (e.PropertyName == "SearchTermsHistory")
                {
                    cbKey.DataSource = opt.SearchTermsHistory;
                }
            };

            if (opt.LoadPages == 0)
            {
                opt.LoadPages = 5;
            }
            cbLoadCount.DataSource = new[] { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 };
            cbLoadCount.DataBindings.Add("SelectedItem", opt, "LoadPages");

            var sortKeys = typeof(SortType).GetEnumDescription().Select(s => new KeyValuePair <SortType, string>((SortType)s.Value, s.DescriptionText)).ToArray();

            cbSort.DataSource    = sortKeys;
            cbSort.DisplayMember = "Value";
            cbSort.SelectedItem  = cbSort.Items.Cast <KeyValuePair <SortType, string>?>().FirstOrDefault(s => s.Value.Key == opt.SortType) ?? cbSort.Items[0];
            opt.PropertyChanged += (x, e) =>
            {
                cbSort.SelectedItem = cbSort.Items.Cast <KeyValuePair <SortType, string>?>().FirstOrDefault(s => s.Value.Key == opt.SortType) ?? cbSort.Items[0];
            };
            cbSort.SelectedIndexChanged += (s, e) =>
            {
                if (cbSort.SelectedItem == null)
                {
                    return;
                }

                opt.SortType = ((KeyValuePair <SortType, string>)cbSort.SelectedItem).Key;
            };
            cbSortDirection.AddDataBinding(opt, s => s.SelectedIndex, s => s.SortDirection);

            //标题
            Text = string.Format(Text, ApplicationRunTimeContext.GetProcessMainModule().FileVersionInfo.FileVersion, ApplicationRunTimeContext.GetProcessMainModule().FileVersionInfo.FileMajorPart);
            foreach (var label in ss.Items.OfType <ToolStripStatusLabel>().Where(s => s.IsLink && s.Tag != null))
            {
                label.Click += (s, e) =>
                {
                    Process.Start((s as ToolStripStatusLabel).Tag.ToString());
                };
            }
            tsEngineTest.Click += (s, e) =>
            {
                new EngineAvailabilityTest().ShowDialog();
            };

            pTip.KeepCenter();

            //TODO 干掉不支持的方法
            tsTools.Enabled = false;
        }