Ejemplo n.º 1
0
        //-------------------------------------------------------------------------------------------------------------
        private void BrowserDownButton_Click(object sender, EventArgs e)
        //-------------------------------------------------------------------------------------------------------------
        {
            int idxSelected = BrowserList.SelectedIndex;

            if (idxSelected < (BrowserList.Items.Count - 1))
            {
                int idxNew = idxSelected + 1;

                BrowserModel browserSelected = new BrowserModel();
                browserSelected                = browsers[idxSelected];
                browsers[idxSelected]          = browsers[idxNew];
                BrowserList.Items[idxSelected] = browsers[idxNew];
                BrowserList.SetItemChecked(idxSelected, !Settings.Default.HiddenBrowsers.Contains(browsers[idxNew].Identifier));
                browsers[idxNew]          = browserSelected;
                BrowserList.Items[idxNew] = browsers[idxNew];
                BrowserList.SetItemChecked(idxNew, !Settings.Default.HiddenBrowsers.Contains(browsers[idxNew].Identifier));

                BrowserList.SelectedIndex = idxNew;

                isDirty      = true;
                isDirtyUI    = true;
                isDirtyCache = true;

                UpdateUIState();
            }
        }
Ejemplo n.º 2
0
        //-------------------------------------------------------------------------------------------------------------
        public void ShowAddRuleMenu(BrowserModel browser)
        //-------------------------------------------------------------------------------------------------------------
        {
            // check if desired pattern is ambiguous
            if (autoRule.mode == 3)
            {
                RulesEngine engine = new RulesEngine();

                // generate a context menu with tld_rule and second_rule as options
                // and call the overloaded AddRule with pattern as second arg on click
                ContextMenu menu = new ContextMenu((new[] { autoRule.firstRule, autoRule.secondRule })
                                                   .Select(x => new MenuItem(x, (s, e) => engine.AddRule("URL", x, browser))).ToArray());

                // display the context menu at mouse position
                menu.Show(this, PointToClient(Cursor.Position));
            }
            else if (autoRule.mode == 0)
            {
                // in case ambiguousness of pattern was not determined, should not happen
                MessageBox.Show(String.Format("Unable to generate rule from this url:\n" +
                                              "{0}",
                                              BrowserSelectApp.url));
            }
            else
            {
                // in case pattern was not ambiguous, just set the pattern as rule and open the url
                var         pattern = (autoRule.mode == 1) ? autoRule.firstRule : autoRule.secondRule;
                RulesEngine engine  = new RulesEngine();
                engine.AddRule("URL", pattern, browser);
            }
        }
Ejemplo n.º 3
0
        //-------------------------------------------------------------------------------------------------------------
        private bool AddChromiumProfiles(List <BrowserModel> browsers, BrowserModel browser)
        //-------------------------------------------------------------------------------------------------------------
        {
            if (browser == null)
            {
                return(false);
            }

            string vendorDataFolder = browser.exec.Replace(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "\\", ""); //bad assumption?

            vendorDataFolder = vendorDataFolder.Replace(Path.GetFileName(browser.exec), "");
            vendorDataFolder = vendorDataFolder.Replace("\\Application", ""); //cleaner way to do this?

            string chromiumUserDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), vendorDataFolder);

            chromiumUserDataFolder += "User Data";
            List <string> chromiumProfiles = FindChromiumProfiles(chromiumUserDataFolder, browser.profileIcon);

            //add the Chromium instances and remove the default one
            foreach (string profile in chromiumProfiles)
            {
                browsers.Add(new BrowserModel()
                {
                    name           = browser.name + " (" + GetChromiumProfileName(chromiumUserDataFolder + "\\" + profile) + ")",
                    exec           = browser.exec,
                    icon           = icon2String(IconExtractor.fromFile(chromiumUserDataFolder + "\\" + profile + "\\" + browser.profileIcon)),
                    additionalArgs = String.Format("--profile-directory={0}", profile)
                });
            }

            return(true);
        }
Ejemplo n.º 4
0
        //-------------------------------------------------------------------------------------------------------------
        public void AddRule(string type, string pattern, BrowserModel browser)
        //-------------------------------------------------------------------------------------------------------------
        {
            SaveRule(type, pattern, browser);

            UrlProcessor processor = new UrlProcessor();

            processor.OpenUrl(browser);
        }
Ejemplo n.º 5
0
 //-------------------------------------------------------------------------------------------------------------
 private void SaveRule(string type, string pattern, BrowserModel browser)
 //-------------------------------------------------------------------------------------------------------------
 {
     // save a rule and save app settings
     Settings.Default.Rules.Add((new RuleModel()
     {
         Type = type,
         Pattern = pattern,
         Browser = browser.name
     }).ToString());
     Settings.Default.Save();
 }
Ejemplo n.º 6
0
        //-------------------------------------------------------------------------------------------------------------
        public BrowserButtonControl(BrowserModel browser, int index)
        //-------------------------------------------------------------------------------------------------------------
        {
            InitializeComponent();

            this.browser = browser;

            BrowserLabel.Text       = browser.name;
            ShortcutLabel.Text      = "( " + Convert.ToString(index + 1) + "," + String.Join(",", browser.shortcuts) + " )";
            ShortcutLabel.ForeColor = Color.FromKnownColor(KnownColor.GrayText);
            BrowserIcon.Image       = browser.string2Icon();//.ToBitmap();
            BrowserIcon.SizeMode    = PictureBoxSizeMode.Zoom;
        }
Ejemplo n.º 7
0
        //-------------------------------------------------------------------------------------------------------------
        public void OpenUrl(BrowserModel browser, bool incognito = false)
        //-------------------------------------------------------------------------------------------------------------
        {
            var args = new List <string>();

            if (!string.IsNullOrEmpty(browser.additionalArgs))
            {
                args.Add(browser.additionalArgs);
            }
            if (incognito)
            {
                args.Add(browser.privateArg);
            }
            if (browser.exec.ToLower().EndsWith("brave.exe"))
            {
                args.Add("--");
            }
            args.Add(BrowserSelectApp.url.Replace("\"", "%22"));

            if (browser.exec.EndsWith("iexplore.exe") && !incognito)
            {
                // IE tends to open in a new window instead of a new tab
                // code borrowed from http://stackoverflow.com/a/3713470/1461004
                bool         found = false;
                ShellWindows iExplorerInstances = new ShellWindows();
                foreach (InternetExplorer iExplorer in iExplorerInstances)
                {
                    if (iExplorer.Name.EndsWith("Internet Explorer"))
                    {
                        iExplorer.Navigate(BrowserSelectApp.url, 0x800);
                        // for issue #10 (bring IE to focus after opening link)
                        ForegroundAgent.RestoreWindow(iExplorer.HWND);
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    Process.Start(browser.exec, args2Str(args));
                }
            }
            else
            {
                Process.Start(browser.exec, args2Str(args));
            }

            Application.Exit();
        }
Ejemplo n.º 8
0
        //-------------------------------------------------------------------------------------------------------------
        private bool AddFirefoxProfiles(List <BrowserModel> browsers, BrowserModel browser)
        //-------------------------------------------------------------------------------------------------------------
        {
            if (browser == null)
            {
                return(false);
            }

            var     iniFile   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Mozilla\Firefox\profiles.ini");
            var     iniParser = new FileIniDataParser();
            IniData iniData   = iniParser.ReadFile(iniFile);

            string defaultProfile = null;

            foreach (var section in iniData.Sections)
            {
                if (section.SectionName.StartsWith("Install"))
                {
                    defaultProfile = section.Keys["Default"];
                }
            }
            foreach (var section in iniData.Sections)
            {
                if (section.SectionName.StartsWith("Profile"))
                {
                    if (section.Keys["Path"] == defaultProfile)
                    {
                        continue;
                    }

                    browsers.Add(new BrowserModel()
                    {
                        name           = browser.name + " (" + section.Keys["Name"] + ")",
                        exec           = browser.exec,
                        icon           = icon2String(IconExtractor.fromFile(browser.exec)),
                        additionalArgs = String.Format("-P \"{0}\" -new-tab", section.Keys["Name"])
                    });
                }
            }

            return(true);
        }