Example #1
0
        private static void AddChromeProfiles(List <Browser> browsers, string BrowserName, string VendorDataFolder, string IconFilename)
        {
            Browser BrowserChrome = browsers.FirstOrDefault(x => x.name == BrowserName);

            if (BrowserChrome != null)
            {
                string        ChromeUserDataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), VendorDataFolder);
                List <string> ChromeProfiles    = FindChromeProfiles(ChromeUserDataDir, IconFilename);

                if (ChromeProfiles.Count > 1)
                {
                    //add the Chrome instances and remove the default one
                    foreach (string Profile in ChromeProfiles)
                    {
                        browsers.Add(new Browser()
                        {
                            name           = BrowserName + " (" + GetChromeProfileName(ChromeUserDataDir + "\\" + Profile) + ")",
                            exec           = BrowserChrome.exec,
                            icon           = icon2String(IconExtractor.fromFile(ChromeUserDataDir + "\\" + Profile + "\\" + IconFilename)),
                            additionalArgs = String.Format("--profile-directory={0}", Profile)
                        });
                    }
                    browsers.Remove(BrowserChrome);
                    browsers = browsers.OrderBy(x => x.name).ToList();
                }
            }
        }
        //-------------------------------------------------------------------------------------------------------------
        private void BrowserSelectView_Load(object sender, EventArgs e)
        //-------------------------------------------------------------------------------------------------------------
        {
            AutoSize            = true;
            AutoSizeMode        = AutoSizeMode.GrowAndShrink;
            AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
            Icon        = IconExtractor.fromFile(Application.ExecutablePath); // set the form icon from .exe file icon
            KeyPreview  = true;
            MinimizeBox = false;
            MaximizeBox = false;
            Text        = BrowserSelectApp.launchWithUrl ? BrowserSelectApp.url : "Browser Select";

            // create a wildcard rule for this domain (create rule button)
            RulesEngine engine = new RulesEngine();

            autoRule = engine.GenerateRule(BrowserSelectApp.url);

            // add Settings button
            var settingsButtonControl = new SettingsButtonControl();

            Controls.Add(settingsButtonControl);
            tooltipUrl.SetToolTip(settingsButtonControl, BrowserSelectApp.url);

            RefreshBrowserListUI();
        }
Example #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);
        }
Example #4
0
        private void frm_About_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = IconExtractor.fromFile(Application.ExecutablePath).ToBitmap();
            var v = Application.ProductVersion;

            lab_ver.Text = "v" + v.Remove(v.Length - 2);
        }
Example #5
0
        public static List <Browser> find()
        {
            List <Browser> browsers = new List <Browser>();
            //special case , firefox+firefox developer both installed
            //(only works if firefox installed in default directory)
            var ff_path = Path.Combine(
                Program.ProgramFilesx86(),
                @"Mozilla Firefox\firefox.exe");

            if (File.Exists(ff_path))
            {
                browsers.Add(new Browser()
                {
                    name = "FireFox",
                    exec = ff_path,
                    icon = IconExtractor.fromFile(ff_path)
                });
            }
            //special case , Edge
            var edge_path = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                @"SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe");

            if (File.Exists(edge_path))
            {
                browsers.Add(new Browser()
                {
                    name = "Edge",
                    //exec=edge_path,
                    // http://answers.microsoft.com/en-us/insider/forum/insider_internet-insider_spartan/how-to-start-microsoft-edge-from-command-line/25d0ba93-4e8b-41cb-adde-461d8fb58ec1
                    exec = "edge",
                    icon = IconExtractor.fromFile(edge_path)
                });
            }

            //gather browsers from registry
            using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
                browsers.AddRange(find(hklm));
            using (RegistryKey hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32))
                browsers.AddRange(find(hkcu));

            //remove myself
            browsers = browsers.Where(x => Path.GetFileName(x.exec).ToLower() !=
                                      Path.GetFileName(Application.ExecutablePath).ToLower()).ToList();
            //remove duplicates
            browsers = browsers.GroupBy(browser => browser.exec)
                       .Select(group => group.First()).ToList();

            return(browsers);
        }
Example #6
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);
        }
Example #7
0
        private void Form1_Load(object sender, EventArgs e)
        {
            int width = 128;
            // add browserUC objects to the form
            int i = 0;

            foreach (var browser in browsers)
            {
                var buc = new BrowserUC(browser, i);
                width      = buc.Width; // buc.Width = 128*dpi Scale
                buc.Left   = width * i++;
                buc.Click += browser_click;
                this.Controls.Add(buc);
            }
            // resize the form
            //this.Width = i * 128 + 20 + 20;
            this.AutoSize   = true;
            this.KeyPreview = true;
            this.Text       = Program.url;
            // set the form icon from .exe file icon
            this.Icon = IconExtractor.fromFile(Application.ExecutablePath);
            // add vertical buttons to right of form
            this.Controls.Add(new ButtonsUC()
            {
                Left = i * width
            });

            // create a wildcard rule for this domain (always button)
            _alwaysRule = generate_rule(Program.url);

            // check for new version
            if (Settings.Default.last_version != "nope")
            {
                btn_help.BackgroundImage = Resources.update_available;
                btn_help.Click          -= btn_help_Click;
                btn_help.Click          += btn_update_click;
            }
            center_me();
        }
Example #8
0
        private void Form1_Load(object sender, EventArgs e)
        {
            int i = 0;

            foreach (var browser in browsers)
            {
                var buc = new BrowserUC(browser, i);
                buc.Left   = 128 * i++;
                buc.Click += browser_click;
                this.Controls.Add(buc);
            }
            this.Width      = i * 128 + 20 + 20;
            this.KeyPreview = true;
            this.Text       = Program.url;

            this.Icon = IconExtractor.fromFile(Application.ExecutablePath);

            add_button("About", show_about, 0);
            add_button("Settings", show_setting, 1);

            center_me();
        }
Example #9
0
        private static List <Browser> find(RegistryKey hklm)
        {
            List <Browser> browsers          = new List <Browser>();
            RegistryKey    webClientsRootKey = hklm.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");

            if (webClientsRootKey != null)
            {
                foreach (var subKeyName in webClientsRootKey.GetSubKeyNames())
                {
                    if (webClientsRootKey.OpenSubKey(subKeyName) != null)
                    {
                        if (webClientsRootKey.OpenSubKey(subKeyName).OpenSubKey("shell") != null)
                        {
                            if (webClientsRootKey.OpenSubKey(subKeyName).OpenSubKey("shell").OpenSubKey("open") != null)
                            {
                                if (webClientsRootKey.OpenSubKey(subKeyName).OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command") != null)
                                {
                                    string commandLineUri = (string)webClientsRootKey.OpenSubKey(subKeyName).OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command").GetValue(null);
                                    if (string.IsNullOrEmpty(commandLineUri))
                                    {
                                        continue;
                                    }
                                    commandLineUri = commandLineUri.Trim("\"".ToCharArray());
                                    browsers.Add(new Browser()
                                    {
                                        name = (string)webClientsRootKey.OpenSubKey(subKeyName).GetValue(null),
                                        exec = commandLineUri,
                                        //icon = Icon.ExtractAssociatedIcon(commandLineUri)
                                        icon = IconExtractor.fromFile(commandLineUri)
                                    });
                                }
                            }
                        }
                    }
                }
            }
            return(browsers);
        }
Example #10
0
 private void Form1_Load(object sender, EventArgs e)
 {
     this.AutoSize     = true;
     this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
     this.KeyPreview   = true;
     this.Text         = Program.url;
     // set the form icon from .exe file icon
     this.Icon = IconExtractor.fromFile(Application.ExecutablePath);
     // create a wildcard rule for this domain (always button)
     _alwaysRule = generate_rule(Program.url);
     // check for new version
     if (Settings.Default.last_version != "nope")
     {
         btn_help.BackgroundImage = Resources.update_available;
         btn_help.Click          -= btn_help_Click;
         btn_help.Click          += btn_update_click;
     }
     // add vertical buttons to right of form
     buc = new ButtonsUC(this);
     this.Controls.Add(buc);
     this.updateBrowsers();
     center_me();
 }
Example #11
0
 private void frm_About_Load(object sender, EventArgs e)
 {
     pictureBox1.Image = IconExtractor.fromFile(Application.ExecutablePath).ToBitmap();
 }
Example #12
0
        public static List <Browser> find(bool update = false)
        {
            List <Browser> browsers = new List <Browser>();

            if (Properties.Settings.Default.BrowserList != "" && !update)
            {
                browsers = JsonConvert.DeserializeObject <List <Browser> >(Properties.Settings.Default.BrowserList);
            }
            else
            {
                //special case , firefox+firefox developer both installed
                //(only works if firefox installed in default directory)
                var ff_path = Path.Combine(
                    Program.ProgramFilesx86(),
                    @"Mozilla Firefox\firefox.exe");
                if (File.Exists(ff_path))
                {
                    browsers.Add(new Browser()
                    {
                        name = "FireFox",
                        exec = ff_path,
                        icon = icon2String(IconExtractor.fromFile(ff_path))
                    });
                }
                //special case , Edge
                var edge_path = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                    @"SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe");
                if (File.Exists(edge_path))
                {
                    browsers.Add(new Browser()
                    {
                        name = "Edge",
                        // #34
                        exec = "shell:AppsFolder\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge",
                        icon = icon2String(IconExtractor.fromFile(edge_path))
                    });
                }

                //gather browsers from registry
                using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
                    browsers.AddRange(find(hklm));
                using (RegistryKey hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32))
                    browsers.AddRange(find(hkcu));

                //remove myself
                browsers = browsers.Where(x => Path.GetFileName(x.exec).ToLower() !=
                                          Path.GetFileName(Application.ExecutablePath).ToLower()).ToList();
                //remove duplicates
                browsers = browsers.GroupBy(browser => browser.exec)
                           .Select(group => group.First()).ToList();

                //check for edge chromium profiles
                AddChromeProfiles(browsers, "Microsoft Edge", @"Microsoft\Edge\User Data", "Edge Profile.ico");

                //Check for Chrome Profiles
                AddChromeProfiles(browsers, "Google Chrome", @"Google\Chrome\User Data", "Google Profile.ico");

                System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(browsers));
                Properties.Settings.Default.BrowserList = JsonConvert.SerializeObject(browsers);
                Properties.Settings.Default.Save();
            }

            return(browsers);
        }
Example #13
0
        private static List <Browser> find(RegistryKey hklm)
        {
            List <Browser> browsers = new List <Browser>();
            // startmenu internet key
            RegistryKey smi = hklm.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");

            if (smi != null)
            {
                foreach (var browser in smi.GetSubKeyNames())
                {
                    try
                    {
                        var key  = smi.OpenSubKey(browser);
                        var name = (string)key.GetValue(null);
                        var cmd  = key.OpenSubKey("shell").OpenSubKey("open").OpenSubKey("command");
                        var exec = (string)cmd.GetValue(null);

                        // by this point if registry is missing keys we are alreay out of here
                        // because of the try catch, but there are still things that could go wrong

                        //0. check if it can handle the http protocol
                        var capabilities = key.OpenSubKey("Capabilities");
                        // IE does not have the capabilities subkey...
                        // so assume that the app can handle http if it doesn't
                        // advertise it's capablities
                        if (capabilities != null)
                        {
                            if ((string)capabilities.OpenSubKey("URLAssociations").GetValue("http") == null)
                            {
                                continue;
                            }
                        }
                        //1. check if path is not empty
                        if (string.IsNullOrWhiteSpace(exec))
                        {
                            continue;
                        }

                        //1.1. remove possible "%1" from the end
                        exec = exec.Replace("\"%1\"", "");
                        //1.2. remove possible quotes around address
                        exec = exec.Trim("\"".ToCharArray());
                        //2. check if path is valid
                        if (!File.Exists(exec))
                        {
                            continue;
                        }
                        //3. check if name is valid
                        if (string.IsNullOrWhiteSpace(name))
                        {
                            name = Path.GetFileNameWithoutExtension(exec);
                        }

                        browsers.Add(new Browser()
                        {
                            name = name,
                            exec = exec,
                            icon = icon2String(IconExtractor.fromFile(exec))
                        });
                    }
                    catch (NullReferenceException)
                    {
                    } // incomplete registry record for browser, ignore it
                    catch (Exception ex)
                    {
                        // todo: log errors
                    }
                }
            }
            return(browsers);
        }
Example #14
0
        public static List <Browser> find(bool update = false)
        {
            List <Browser> browsers = new List <Browser>();

            if (Properties.Settings.Default.BrowserList != "" && !update)
            {
                browsers = JsonConvert.DeserializeObject <List <Browser> >(Properties.Settings.Default.BrowserList);
            }
            else
            {
                //special case , firefox+firefox developer both installed
                //(only works if firefox installed in default directory)
                var ff_path = Path.Combine(
                    Program.ProgramFilesx86(),
                    @"Mozilla Firefox\firefox.exe");
                if (File.Exists(ff_path))
                {
                    browsers.Add(new Browser()
                    {
                        name = "FireFox",
                        exec = ff_path,
                        icon = icon2String(IconExtractor.fromFile(ff_path))
                    });
                }
                //special case , Edge
                var edge_path = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                    @"SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe");
                if (File.Exists(edge_path))
                {
                    browsers.Add(new Browser()
                    {
                        name = "Edge",
                        // #34
                        exec = "shell:AppsFolder\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge",
                        icon = icon2String(IconExtractor.fromFile(edge_path))
                    });
                }

                //gather browsers from registry
                using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
                    browsers.AddRange(find(hklm));
                using (RegistryKey hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32))
                    browsers.AddRange(find(hkcu));

                //remove myself
                browsers = browsers.Where(x => Path.GetFileName(x.exec).ToLower() !=
                                          Path.GetFileName(Application.ExecutablePath).ToLower()).ToList();
                //remove duplicates
                browsers = browsers.GroupBy(browser => browser.exec)
                           .Select(group => group.First()).ToList();
                //Check for Chrome Profiles
                Browser BrowserChrome = browsers.FirstOrDefault(x => x.name == "Google Chrome");
                if (BrowserChrome != null)
                {
                    string        ChromeUserDataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Google\Chrome\User Data");
                    List <string> ChromeProfiles    = FindChromeProfiles(ChromeUserDataDir);

                    if (ChromeProfiles.Count > 1)
                    {
                        //add the Chrome instances and remove the default one
                        foreach (string Profile in ChromeProfiles)
                        {
                            browsers.Add(new Browser()
                            {
                                name           = "Chrome (" + GetChromeProfileName(ChromeUserDataDir + "\\" + Profile) + ")",
                                exec           = BrowserChrome.exec,
                                icon           = icon2String(IconExtractor.fromFile(ChromeUserDataDir + "\\" + Profile + "\\Google Profile.ico")),
                                additionalArgs = String.Format("--profile-directory={0}", Profile)
                            });
                        }
                        browsers.Remove(BrowserChrome);
                        browsers = browsers.OrderBy(x => x.name).ToList();
                    }
                }

                System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(browsers));
                Properties.Settings.Default.BrowserList = JsonConvert.SerializeObject(browsers);
                Properties.Settings.Default.Save();
            }

            return(browsers);
        }
Example #15
0
        //-------------------------------------------------------------------------------------------------------------
        public List <BrowserModel> FindBrowsers(bool update = false)
        //-------------------------------------------------------------------------------------------------------------
        {
            List <BrowserModel> browsers = new List <BrowserModel>();

            if (Settings.Default.CachedBrowserList != "" && !update)
            {
                browsers = JsonConvert.DeserializeObject <List <BrowserModel> >(Settings.Default.CachedBrowserList);
            }
            else
            {
                //special case Edge (Classic)
                var edge_path = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                    @"SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe");
                if (File.Exists(edge_path))
                {
                    browsers.Add(new BrowserModel()
                    {
                        name = "Edge (Classic)",
                        // #34
                        exec = "shell:AppsFolder\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge",
                        icon = icon2String(IconExtractor.fromFile(edge_path))
                    });
                }

                //gather browsers from registry
                using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
                    browsers.AddRange(FindRegisteredBrowsers(hklm));
                using (RegistryKey hkcu = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32))
                    browsers.AddRange(FindRegisteredBrowsers(hkcu));

                //remove BrowserSelect app itself
                browsers = browsers.Where(x => Path.GetFileName(x.exec).ToLower() !=
                                          Path.GetFileName(Application.ExecutablePath).ToLower()).ToList();

                //remove duplicates
                browsers = browsers.GroupBy(browser => browser.exec)
                           .Select(group => group.First()).ToList();

                List <BrowserModel> browsersToAdd    = new List <BrowserModel>();
                List <BrowserModel> browsersToRemove = new List <BrowserModel>();
                //check for Edge (Chromium) profiles
                foreach (BrowserModel browser in browsers)
                {
                    if (browser.name.Contains("Microsoft Edge"))
                    {
                        if (AddChromiumProfiles(browsersToAdd, browser))
                        {
                            browsersToRemove.Add(browser);
                        }
                    }
                }

                //check for Chrome Profiles
                foreach (BrowserModel browser in browsers)
                {
                    if (browser.name.Contains("Google Chrome"))
                    {
                        if (AddChromiumProfiles(browsersToAdd, browser))
                        {
                            browsersToRemove.Add(browser);
                        }
                    }
                }

                //check for Firefox Profiles
                foreach (BrowserModel browser in browsers)
                {
                    if (browser.name.Contains("Firefox"))
                    {
                        if (AddFirefoxProfiles(browsersToAdd, browser))
                        {
                            browsersToRemove.Add(browser);
                        }
                    }
                }

                if (browsersToAdd.Count > 0)
                {
                    browsers.AddRange(browsersToAdd);
                }

                if (browsersToRemove.Count > 0)
                {
                    foreach (BrowserModel browser in browsersToRemove)
                    {
                        browsers.Remove(browser);
                    }
                }

                //sort
                browsers.Sort();

                System.Diagnostics.Debug.WriteLine(JsonConvert.SerializeObject(browsers));
                Settings.Default.CachedBrowserList = JsonConvert.SerializeObject(browsers);
                Settings.Default.Save();
            }

            return(browsers);
        }