diff --git a/BrowserSelect/Browser.cs b/BrowserSelect/Browser.cs index f6dc422..499917b 100644 --- a/BrowserSelect/Browser.cs +++ b/BrowserSelect/Browser.cs @@ -233,12 +233,13 @@ private static List find(RegistryKey hklm) icon = icon2String(IconExtractor.fromFile(exec)) }); } - catch (NullReferenceException) + catch (NullReferenceException ex) { + System.Diagnostics.Debug.WriteLine(ex); } // incomplete registry record for browser, ignore it catch (Exception ex) { - // todo: log errors + System.Diagnostics.Debug.WriteLine(ex); } } return browsers; diff --git a/BrowserSelect/BrowserSelect.csproj b/BrowserSelect/BrowserSelect.csproj index 497770e..4f9905f 100644 --- a/BrowserSelect/BrowserSelect.csproj +++ b/BrowserSelect/BrowserSelect.csproj @@ -9,8 +9,9 @@ Properties BrowserSelect BrowserSelect - v4.0 + v4.7.2 512 + AnyCPU @@ -21,6 +22,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU @@ -30,16 +32,21 @@ TRACE prompt 4 + false bs.ico - - ..\packages\Newtonsoft.Json.11.0.2\lib\net40\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + @@ -70,6 +77,18 @@ Form1.cs + + Form + + + frm_settings_urlexpander.cs + + + Form + + + frm_SplashScreen.cs + Form @@ -110,6 +129,12 @@ Form1.cs + + frm_settings_urlexpander.cs + + + frm_SplashScreen.cs + frm_About.cs diff --git a/BrowserSelect/Form1.cs b/BrowserSelect/Form1.cs index 420c3e4..71872e2 100644 --- a/BrowserSelect/Form1.cs +++ b/BrowserSelect/Form1.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; +using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Windows.Forms; using BrowserSelect.Properties; +using Newtonsoft.Json; using SHDocVw; namespace BrowserSelect @@ -19,6 +21,7 @@ public partial class Form1 : Form public Form1() { InitializeComponent(); + MaximizeBox = false; } public void updateBrowsers() @@ -50,15 +53,18 @@ public void updateBrowsers() } 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); + if (Program.url != "") + { + _alwaysRule = generate_rule(Program.url); + this.Text = Program.url; + } // check for new version if (Settings.Default.last_version != "nope") { @@ -118,12 +124,22 @@ public void add_rule(Browser b, string pattern) private void save_rule(string pattern, Browser b) { - // save a rule and save app settings - Settings.Default.AutoBrowser.Add((new AutoMatchRule() + // add a rule and save app settings + DataTable rules; + if (Settings.Default.Rules != null && Settings.Default.Rules != "") + rules = (DataTable)JsonConvert.DeserializeObject(Settings.Default.Rules, (typeof(DataTable))); + else { - Pattern = pattern, - Browser = b.name - }).ToString()); + rules = new DataTable(); + rules.Columns.Add("Type"); + rules.Columns.Add("Match"); + rules.Columns.Add("Pattern"); + rules.Columns.Add("Browser"); + } + if (pattern.StartsWith("*.")) + pattern = pattern.Substring(2); + rules.Rows.Add("Ends With", "Domain", pattern, b.name); + Settings.Default.Rules = JsonConvert.SerializeObject(rules); Settings.Default.Save(); } @@ -161,7 +177,9 @@ e.g. sealake.vic.au or something.fun.ir x = parts[count - 2]; //second-level y = parts[count - 3]; //third-level } - catch (IndexOutOfRangeException) { } // in case domain did not have 3 parts.. (e.g. localhost, google.com) + catch (IndexOutOfRangeException ex) { + Debug.WriteLine(ex); + } // in case domain did not have 3 parts.. (e.g. localhost, google.com) // creating the patterns var rule_tld = String.Format("*.{0}.{1}", x, tld); @@ -253,7 +271,12 @@ public static void open_url(Browser b, bool incognito = false) } else { - Process.Start(b.exec, Program.Args2Str(args)); + ProcessStartInfo startInfo = new ProcessStartInfo(b.exec); + // Clicking MS Edge takes more than 4 seconds to load, even with an existing window + // Disabling UseShellExecute to create the process directly from the browser executable file + startInfo.UseShellExecute = false; + startInfo.Arguments = Program.Args2Str(args); + Process.Start(startInfo); } Application.Exit(); } @@ -284,7 +307,15 @@ private void center_me() var top = wa.Height / 2 + wa.Top - Height / 2; this.Location = new Point(left, top); - this.Activate(); + + + // Borrowed from https://stackoverflow.com/a/5853542 + // Get the window to the front + this.TopMost = true; + this.TopMost = false; + + // "Steal" the focus + this.Activate(); } private void btn_help_Click(object sender, EventArgs e) diff --git a/BrowserSelect/Program.cs b/BrowserSelect/Program.cs index 8239032..86628d5 100644 --- a/BrowserSelect/Program.cs +++ b/BrowserSelect/Program.cs @@ -7,12 +7,25 @@ using System.Threading.Tasks; using System.Windows.Forms; using BrowserSelect.Properties; +using System.Web; +using System.Net; +using System.Threading; +using Newtonsoft.Json; +using System.Data; namespace BrowserSelect { static class Program { - public static string url = "http://google.com/"; + public static string url = ""; + public static HttpWebRequest webRequestThread = null; + public static bool uriExpanderThreadStop = false; + public static (string name, string domain)[] defaultUriExpander = new(string name, string domain)[] + { + ("Outlook safe links", "safelinks.protection.outlook.com")//, + //("Test1", "test.com"), + //("Test2", "test2.com") + }; /// /// The main entry point for the application. @@ -20,9 +33,6 @@ static class Program [STAThread] static void Main(string[] args) { - - // fix #28 - LeaveDotsAndSlashesEscaped(); // to prevent loss of settings when on update if (Settings.Default.UpdateSettings) { @@ -43,6 +53,35 @@ static void Main(string[] args) var uc = new UpdateChecker(); Task.Factory.StartNew(() => uc.check()); } + //load URL Shortners + string[] defultUrlShortners = new string[] { + "adf.ly", + "bit.do", + "bit.ly", + "goo.gl", + "ht.ly", + "is.gd", + "ity.im", + "lnk.co", + "ow.ly", + "q.gs", + "rb.gy", + "rotf.lol", + "t.co", + "tiny.one", + "tinyurl.com" + }; + if (Settings.Default.URLShortners == null) + { + StringCollection url_shortners = new StringCollection(); + url_shortners.AddRange(defultUrlShortners); + Settings.Default.URLShortners = url_shortners; + Settings.Default.Save(); + } + + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + //checking if a url is being opened or app is ran from start menu (without arguments) if (args.Length > 0) { @@ -50,40 +89,88 @@ static void Main(string[] args) url = args[0]; //add http:// to url if it is missing a protocol var uri = new UriBuilder(url).Uri; + uri = UriExpander(uri); + if (Settings.Default.ExpandUrl != null && Settings.Default.ExpandUrl != "Never") + uri = UriFollowRedirects(uri); url = uri.AbsoluteUri; - foreach (var sr in Settings.Default.AutoBrowser.Cast() - // maybe i should use a better way to split the pattern and browser name ? - .Select(x => x.Split(new[] { "[#!][$~][?_]" }, StringSplitOptions.None)) - // to make sure * doesn't match when non-* rules exist. - .OrderBy(x => ((x[0].Contains("*")) ? 1 : 0) + (x[0] == "*" ? 1 : 0))) + //if we loaded the browser finish execution here... + if (load_browser(uri)) + return; + } + + // display main form + //Application.EnableVisualStyles(); + //Application.SetCompatibleTextRenderingDefault(false); + if (url == "" && (Boolean)Settings.Default.LaunchToSettings) + Application.Run(new frm_settings()); + else + Application.Run(new Form1()); + } + + private static Boolean load_browser(Uri uri) + { + if (Settings.Default.Rules != null && Settings.Default.Rules != "") + { + DataTable rules = (DataTable)JsonConvert.DeserializeObject(Settings.Default.Rules, (typeof(DataTable))); + foreach (DataRow rule in rules.Rows) { - var pattern = sr[0]; - var browser = sr[1]; + Boolean rule_match = false; + string match_type = (string)rule["Type"]; + string match = (string)rule["Match"]; + string pattern = (string)rule["Pattern"]; + + string test_uri = ""; + if (match == "Domain") + test_uri = uri.Host; + else if (match == "URL Path") + test_uri = uri.PathAndQuery; + else if (match == "Full URL") + test_uri = uri.AbsoluteUri; - // matching the domain to pattern - if (DoesDomainMatchPattern(uri.Host, pattern)) + switch (match_type) { - // ignore the display browser select entry to prevent app running itself + case "Ends With": + if (test_uri.EndsWith(pattern, StringComparison.OrdinalIgnoreCase)) + rule_match = true; + break; + case "Starts With": + if (test_uri.StartsWith(pattern, StringComparison.OrdinalIgnoreCase)) + rule_match = true; + break; + case "Contains": + if (test_uri.IndexOf(pattern, StringComparison.OrdinalIgnoreCase) >= 0) + rule_match = true; + break; + case "Matches": + if (test_uri.Equals(pattern, StringComparison.OrdinalIgnoreCase)) + rule_match = true; + break; + case "RegEx": + Regex regex = new Regex(pattern, RegexOptions.IgnoreCase); + if (regex.IsMatch(test_uri)) + rule_match = true; + break; + } + + if (rule_match) + { + System.Diagnostics.Debug.WriteLine(test_uri + " " + match_type + " " + pattern); + string browser = (string)rule["Browser"]; if (browser != "display BrowserSelect") - { - //todo: handle the case if browser is not found (e.g. imported settings or uninstalled browser) Form1.open_url((Browser)browser); - return; - } - else - { - // simply break the loop to let the app display selection dialogue - break; - } + return true; } } } - - // display main form - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + if (Settings.Default.DefaultBrowser != null && + Settings.Default.DefaultBrowser != "" && + Settings.Default.DefaultBrowser != "display BrowserSelect") + { + Form1.open_url((Browser)Settings.Default.DefaultBrowser); + return true; + } + return false; } // from : http://stackoverflow.com/a/250400/1461004 @@ -146,66 +233,126 @@ public static string ProgramFilesx86() return Environment.GetEnvironmentVariable("ProgramFiles"); } - - /// - /// Checks if a wildcard string matches a domain - /// taken from http://madskristensen.net/post/wildcard-search-for-domains-in-c - /// - public static bool DoesDomainMatchPattern(string domain, string domainToCheck) + private static Uri UriExpander(Uri uri) { - if (domainToCheck.Contains("*")) + List enabled_url_expanders = new List(); + if (Settings.Default.URLProcessors != null) { - string checkDomain = domainToCheck; - if (checkDomain.StartsWith("*.")) - checkDomain = "*" + checkDomain.Substring(2, checkDomain.Length - 2); - return DoesWildcardMatch(domain, checkDomain); + foreach ((string name, string domain) in defaultUriExpander) + { + if (Settings.Default.URLProcessors.Contains(name)) + { + enabled_url_expanders.Add(domain); + } + } } - else + + System.Diagnostics.Debug.WriteLine("URLExpander: " + uri.Host); + if (uri.Host.EndsWith("safelinks.protection.outlook.com") && + enabled_url_expanders.Contains("safelinks.protection.outlook.com")) { - return domainToCheck.Equals(domain, StringComparison.OrdinalIgnoreCase); + var queryDict = HttpUtility.ParseQueryString(uri.Query); + if (queryDict != null && queryDict.Get("url") != null) + { + uri = new UriBuilder(HttpUtility.UrlDecode(queryDict.Get("url"))).Uri; + } } + + return uri; } - /// - /// Performs a wildcard (*) search on any string. - /// - public static bool DoesWildcardMatch(string originalString, string searchString) + + private static Uri UriFollowRedirects(Uri uri, int num_redirects = 0) { - if (!searchString.StartsWith("*")) + int max_redirects = 20; + if (num_redirects >= max_redirects) { - int stop = searchString.IndexOf('*'); - if (!originalString.StartsWith(searchString.Substring(0, stop))) - return false; + return uri; } - if (!searchString.EndsWith("*")) + System.Diagnostics.Debug.WriteLine("Url " + num_redirects + " " + uri.Host); + StringCollection url_shortners = Settings.Default.URLShortners; + Form SplashScreen = null; + if (!Program.uriExpanderThreadStop && + (url_shortners.Contains(uri.Host) || Settings.Default.ExpandUrl == "Follow all redirects")) { - int start = searchString.LastIndexOf('*') + 1; - if (!originalString.EndsWith(searchString.Substring(start, searchString.Length - start))) - return false; + //Thread.Sleep(2000); + if (num_redirects == 0) + { + SplashScreen = new frm_SplashScreen(); + var splashThread = new Thread(new ThreadStart(() => Application.Run(SplashScreen))); + splashThread.Start(); + } + HttpWebResponse response = MyWebRequest(uri); + if (response != null) + { + if ((int)response.StatusCode > 299 && (int)response.StatusCode < 400) + { + uri = UriFollowRedirects(new UriBuilder(response.Headers["Location"]).Uri, (num_redirects + 1)); + } + else + { + uri = response.ResponseUri; + } + } } - Regex regex = new Regex(searchString.Replace(@".", @"\.").Replace(@"*", @".*")); - return regex.IsMatch(originalString); + + if (num_redirects == 0) + { + if (SplashScreen != null && !SplashScreen.Disposing && !SplashScreen.IsDisposed) + try + { + Program.uriExpanderThreadStop = true; + SplashScreen.Invoke(new Action(() => SplashScreen.Close())); + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine(ex); + } + } + return uri; } - // https://stackoverflow.com/a/7202560/1461004 - private static void LeaveDotsAndSlashesEscaped() + private static HttpWebResponse MyWebRequest(Uri uri) { - var getSyntaxMethod = - typeof(UriParser).GetMethod("GetSyntax", BindingFlags.Static | BindingFlags.NonPublic); - if (getSyntaxMethod == null) + //Support TLS1.2 - updated .Net framework - no longer needed + //ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | (SecurityProtocolType)768 | (SecurityProtocolType)3072 | SecurityProtocolType.Ssl3; //SecurityProtocolType.Tls12; + var webRequest = (HttpWebRequest)WebRequest.Create(uri.AbsoluteUri); + // Set timeout - needs to be high enough for HTTP request to succeed on slow network connections, + // but fast enough not to slow down BrowserSelect startup too much. + // 2 seconds seems about right + webRequest.Timeout = 2000; + //webRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv: 85.0) Gecko/20100101 Firefox/85.0"; + webRequest.AllowAutoRedirect = false; + HttpWebResponse response = null; + try + { + var ar = webRequest.BeginGetResponse(null, null); + Program.webRequestThread = webRequest; + ThreadPool.RegisterWaitForSingleObject(ar.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), webRequest, webRequest.Timeout, true); + response = (HttpWebResponse)webRequest.EndGetResponse(ar); + response.Close(); + } + catch (WebException ex) { - throw new MissingMethodException("UriParser", "GetSyntax"); + // We are mostly catch up webRequest.Abort() or webRequest errors here (e.g. untrusted certificates) + // No action required. + System.Diagnostics.Debug.WriteLine(ex); } - var uriParser = getSyntaxMethod.Invoke(null, new object[] { "http" }); + return response; + } - var setUpdatableFlagsMethod = - uriParser.GetType().GetMethod("SetUpdatableFlags", BindingFlags.Instance | BindingFlags.NonPublic); - if (setUpdatableFlagsMethod == null) + // Abort the request if the timer fires. + private static void TimeoutCallback(object state, bool timedOut) + { + if (timedOut) { - throw new MissingMethodException("UriParser", "SetUpdatableFlags"); + HttpWebRequest request = state as HttpWebRequest; + if (request != null) + { + System.Diagnostics.Debug.WriteLine("Timed out, aborting HTTP request..."); + request.Abort(); + } } - - setUpdatableFlagsMethod.Invoke(uriParser, new object[] { 0 }); } } } diff --git a/BrowserSelect/Properties/Resources.Designer.cs b/BrowserSelect/Properties/Resources.Designer.cs index 7326a8f..a95b47d 100644 --- a/BrowserSelect/Properties/Resources.Designer.cs +++ b/BrowserSelect/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace BrowserSelect.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/BrowserSelect/Properties/Settings.Designer.cs b/BrowserSelect/Properties/Settings.Designer.cs index b9cdc52..dc94734 100644 --- a/BrowserSelect/Properties/Settings.Designer.cs +++ b/BrowserSelect/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace BrowserSelect.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -92,5 +92,75 @@ public string BrowserList { this["BrowserList"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Never")] + public string ExpandUrl { + get { + return ((string)(this["ExpandUrl"])); + } + set { + this["ExpandUrl"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public global::System.Collections.Specialized.StringCollection URLShortners { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["URLShortners"])); + } + set { + this["URLShortners"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + public global::System.Collections.Specialized.StringCollection URLProcessors { + get { + return ((global::System.Collections.Specialized.StringCollection)(this["URLProcessors"])); + } + set { + this["URLProcessors"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string DefaultBrowser { + get { + return ((string)(this["DefaultBrowser"])); + } + set { + this["DefaultBrowser"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string Rules { + get { + return ((string)(this["Rules"])); + } + set { + this["Rules"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool LaunchToSettings { + get { + return ((bool)(this["LaunchToSettings"])); + } + set { + this["LaunchToSettings"] = value; + } + } } } diff --git a/BrowserSelect/Properties/Settings.settings b/BrowserSelect/Properties/Settings.settings index 076050b..1f458fd 100644 --- a/BrowserSelect/Properties/Settings.settings +++ b/BrowserSelect/Properties/Settings.settings @@ -20,5 +20,23 @@ + + Never + + + + + + + + + + + + + + + False + \ No newline at end of file diff --git a/BrowserSelect/UpdateChecker.cs b/BrowserSelect/UpdateChecker.cs index 9ce5962..7ce49b1 100644 --- a/BrowserSelect/UpdateChecker.cs +++ b/BrowserSelect/UpdateChecker.cs @@ -36,7 +36,7 @@ string get_last_version() var req = (HttpWebRequest)WebRequest.Create("https://github.com/zumoshi/BrowserSelect/releases/latest"); // make webrequest use tls 1.2 instead of ssl3 (#43) ServicePointManager.Expect100Continue = true; - ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072; + //ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072; req.Method = "HEAD"; req.AllowAutoRedirect = false; using (var res = req.GetResponse()) @@ -53,7 +53,9 @@ void get_versions() current_version = ((Func)((x) => x.Substring(0, x.Length - 2)))(Application.ProductVersion); init = true; } - catch (Exception) { } + catch (Exception ex) { + System.Diagnostics.Debug.WriteLine(ex); + } } bool new_version() diff --git a/BrowserSelect/app.config b/BrowserSelect/app.config index 2ebf191..dcc6f6f 100644 --- a/BrowserSelect/app.config +++ b/BrowserSelect/app.config @@ -1,8 +1,8 @@ - + - -
+ +
@@ -19,6 +19,18 @@ + + Never + + + + + + + + + False + - \ No newline at end of file + diff --git a/BrowserSelect/frm_SplashScreen.Designer.cs b/BrowserSelect/frm_SplashScreen.Designer.cs new file mode 100644 index 0000000..8da7c94 --- /dev/null +++ b/BrowserSelect/frm_SplashScreen.Designer.cs @@ -0,0 +1,69 @@ + +namespace BrowserSelect +{ + partial class frm_SplashScreen + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frm_SplashScreen)); + this.label1 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(13, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(171, 17); + this.label1.TabIndex = 0; + this.label1.Text = "URL Expander - loading..."; + this.label1.UseWaitCursor = true; + // + // frm_SplashScreen + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(251, 69); + this.Controls.Add(this.label1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.Name = "frm_SplashScreen"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "BrowserSelect"; + this.UseWaitCursor = true; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frm_SplashScreen_FormClosing); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + } +} \ No newline at end of file diff --git a/BrowserSelect/frm_SplashScreen.cs b/BrowserSelect/frm_SplashScreen.cs new file mode 100644 index 0000000..b9063cb --- /dev/null +++ b/BrowserSelect/frm_SplashScreen.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace BrowserSelect +{ + public partial class frm_SplashScreen : Form + { + public frm_SplashScreen() + { + InitializeComponent(); + Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location); + } + + private void frm_SplashScreen_FormClosing(object sender, System.ComponentModel.CancelEventArgs e) + { + if (!Program.uriExpanderThreadStop) + { + System.Diagnostics.Debug.WriteLine("FormCosing, Abort HTTPWebrequest..."); + Program.uriExpanderThreadStop = true; + Program.webRequestThread.Abort(); + } + e.Cancel = false; + } + } +} diff --git a/BrowserSelect/frm_SplashScreen.resx b/BrowserSelect/frm_SplashScreen.resx new file mode 100644 index 0000000..ec2d462 --- /dev/null +++ b/BrowserSelect/frm_SplashScreen.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + True + + \ No newline at end of file diff --git a/BrowserSelect/frm_settings.Designer.cs b/BrowserSelect/frm_settings.Designer.cs index 9e93958..c57193e 100644 --- a/BrowserSelect/frm_settings.Designer.cs +++ b/BrowserSelect/frm_settings.Designer.cs @@ -26,22 +26,29 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frm_settings)); this.btn_setdefault = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.browser_filter = new System.Windows.Forms.CheckedListBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.chk_launch_settings = new System.Windows.Forms.CheckBox(); + this.btn_expandurls = new System.Windows.Forms.Button(); this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.label3 = new System.Windows.Forms.Label(); + this.cmbo_default_browser = new System.Windows.Forms.ComboBox(); this.btn_cancel = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.btn_apply = new System.Windows.Forms.Button(); this.gv_filters = new System.Windows.Forms.DataGridView(); + this.type = new System.Windows.Forms.DataGridViewComboBoxColumn(); + this.match = new System.Windows.Forms.DataGridViewComboBoxColumn(); this.pattern = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.browser = new System.Windows.Forms.DataGridViewComboBoxColumn(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.chk_check_update = new System.Windows.Forms.CheckBox(); this.btn_check_update = new System.Windows.Forms.Button(); this.btn_refresh = new System.Windows.Forms.Button(); + this.btn_up = new System.Windows.Forms.Button(); + this.btn_down = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); @@ -51,10 +58,10 @@ private void InitializeComponent() { // // btn_setdefault // - this.btn_setdefault.Location = new System.Drawing.Point(6, 87); + this.btn_setdefault.Location = new System.Drawing.Point(6, 47); this.btn_setdefault.Name = "btn_setdefault"; this.btn_setdefault.Size = new System.Drawing.Size(135, 31); - this.btn_setdefault.TabIndex = 0; + this.btn_setdefault.TabIndex = 2; this.btn_setdefault.Text = "Set as Default Browser"; this.btn_setdefault.UseVisualStyleBackColor = true; this.btn_setdefault.Click += new System.EventHandler(this.btn_setdefault_Click); @@ -63,19 +70,9 @@ private void InitializeComponent() { // this.label1.Location = new System.Drawing.Point(6, 16); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(135, 75); + this.label1.Size = new System.Drawing.Size(135, 28); this.label1.TabIndex = 1; - this.label1.Text = "BrowserSelect must be set as default browser for it to function correctly. this b" + - "utton will set it as the default browser."; - // - // label2 - // - this.label2.Location = new System.Drawing.Point(12, 316); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(150, 56); - this.label2.TabIndex = 2; - this.label2.Text = "if you have feature requests,bug reports or suggestions please submit an issue on" + - " the project\'s Github."; + this.label1.Text = "BrowserSelect must be the default browser."; // // groupBox1 // @@ -83,7 +80,7 @@ private void InitializeComponent() { this.groupBox1.Location = new System.Drawing.Point(12, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(150, 125); - this.groupBox1.TabIndex = 3; + this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Select Browsers"; // @@ -94,25 +91,50 @@ private void InitializeComponent() { this.browser_filter.Location = new System.Drawing.Point(3, 16); this.browser_filter.Name = "browser_filter"; this.browser_filter.Size = new System.Drawing.Size(144, 106); - this.browser_filter.TabIndex = 0; + this.browser_filter.TabIndex = 1; this.browser_filter.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.browser_filter_ItemCheck); // // groupBox2 // + this.groupBox2.Controls.Add(this.chk_launch_settings); + this.groupBox2.Controls.Add(this.btn_expandurls); this.groupBox2.Controls.Add(this.btn_setdefault); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Location = new System.Drawing.Point(15, 143); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(147, 123); - this.groupBox2.TabIndex = 0; + this.groupBox2.Size = new System.Drawing.Size(147, 157); + this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; - this.groupBox2.Text = "Default Browser"; + this.groupBox2.Text = "Options"; + // + // chk_launch_settings + // + this.chk_launch_settings.AutoSize = true; + this.chk_launch_settings.Location = new System.Drawing.Point(9, 122); + this.chk_launch_settings.Name = "chk_launch_settings"; + this.chk_launch_settings.Size = new System.Drawing.Size(131, 30); + this.chk_launch_settings.TabIndex = 4; + this.chk_launch_settings.Text = "launch straight to\r\nsettings when no URL"; + this.chk_launch_settings.UseVisualStyleBackColor = true; + this.chk_launch_settings.CheckedChanged += new System.EventHandler(this.chk_launch_settings_CheckedChanged); + // + // btn_expandurls + // + this.btn_expandurls.Location = new System.Drawing.Point(6, 84); + this.btn_expandurls.Name = "btn_expandurls"; + this.btn_expandurls.Size = new System.Drawing.Size(135, 31); + this.btn_expandurls.TabIndex = 3; + this.btn_expandurls.Text = "URL Expander Config"; + this.btn_expandurls.UseVisualStyleBackColor = true; + this.btn_expandurls.Click += new System.EventHandler(this.btn_expandurls_Click); // // groupBox3 // this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox3.Controls.Add(this.label3); + this.groupBox3.Controls.Add(this.cmbo_default_browser); this.groupBox3.Controls.Add(this.btn_cancel); this.groupBox3.Controls.Add(this.button1); this.groupBox3.Controls.Add(this.linkLabel1); @@ -120,16 +142,37 @@ private void InitializeComponent() { this.groupBox3.Controls.Add(this.gv_filters); this.groupBox3.Location = new System.Drawing.Point(168, 12); this.groupBox3.Name = "groupBox3"; - this.groupBox3.Size = new System.Drawing.Size(444, 360); - this.groupBox3.TabIndex = 4; + this.groupBox3.Size = new System.Drawing.Size(526, 360); + this.groupBox3.TabIndex = 3; this.groupBox3.TabStop = false; this.groupBox3.Text = "Auto Select Filters"; // + // label3 + // + this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(6, 336); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(85, 13); + this.label3.TabIndex = 11; + this.label3.Text = "Default Browser:"; + // + // cmbo_default_browser + // + this.cmbo_default_browser.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.cmbo_default_browser.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cmbo_default_browser.DropDownWidth = 130; + this.cmbo_default_browser.FormattingEnabled = true; + this.cmbo_default_browser.Location = new System.Drawing.Point(97, 331); + this.cmbo_default_browser.Name = "cmbo_default_browser"; + this.cmbo_default_browser.Size = new System.Drawing.Size(130, 21); + this.cmbo_default_browser.TabIndex = 10; + // // btn_cancel // this.btn_cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btn_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btn_cancel.Location = new System.Drawing.Point(282, 331); + this.btn_cancel.Location = new System.Drawing.Point(364, 331); this.btn_cancel.Name = "btn_cancel"; this.btn_cancel.Size = new System.Drawing.Size(75, 23); this.btn_cancel.TabIndex = 8; @@ -139,8 +182,8 @@ private void InitializeComponent() { // // button1 // - this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.button1.Location = new System.Drawing.Point(6, 331); + this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.button1.Location = new System.Drawing.Point(283, 331); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 7; @@ -151,10 +194,10 @@ private void InitializeComponent() { // linkLabel1 // this.linkLabel1.Dock = System.Windows.Forms.DockStyle.Top; - this.linkLabel1.LinkArea = new System.Windows.Forms.LinkArea(212, 235); + this.linkLabel1.LinkArea = new System.Windows.Forms.LinkArea(247, 17); this.linkLabel1.Location = new System.Drawing.Point(3, 16); this.linkLabel1.Name = "linkLabel1"; - this.linkLabel1.Size = new System.Drawing.Size(438, 40); + this.linkLabel1.Size = new System.Drawing.Size(520, 40); this.linkLabel1.TabIndex = 6; this.linkLabel1.TabStop = true; this.linkLabel1.Text = resources.GetString("linkLabel1.Text"); @@ -165,10 +208,10 @@ private void InitializeComponent() { // this.btn_apply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btn_apply.Enabled = false; - this.btn_apply.Location = new System.Drawing.Point(363, 331); + this.btn_apply.Location = new System.Drawing.Point(445, 331); this.btn_apply.Name = "btn_apply"; this.btn_apply.Size = new System.Drawing.Size(75, 23); - this.btn_apply.TabIndex = 5; + this.btn_apply.TabIndex = 9; this.btn_apply.Text = "Apply"; this.btn_apply.UseVisualStyleBackColor = true; this.btn_apply.Click += new System.EventHandler(this.btn_apply_Click); @@ -180,17 +223,52 @@ private void InitializeComponent() { | System.Windows.Forms.AnchorStyles.Right))); this.gv_filters.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.gv_filters.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.type, + this.match, this.pattern, this.browser}); this.gv_filters.Location = new System.Drawing.Point(6, 59); this.gv_filters.Name = "gv_filters"; - this.gv_filters.Size = new System.Drawing.Size(432, 266); - this.gv_filters.TabIndex = 1; + this.gv_filters.RowHeadersWidth = 30; + this.gv_filters.Size = new System.Drawing.Size(514, 266); + this.gv_filters.TabIndex = 6; this.gv_filters.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.gv_filters_CellBeginEdit); + this.gv_filters.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.gv_filters_CellClick); + this.gv_filters.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.gv_filters_CellEnter); this.gv_filters.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.gv_filters_DataError); this.gv_filters.UserAddedRow += new System.Windows.Forms.DataGridViewRowEventHandler(this.gv_filters_CellBeginEdit); this.gv_filters.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(this.gv_filters_CellBeginEdit); // + // type + // + this.type.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; + this.type.DataPropertyName = "Type"; + this.type.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.type.HeaderText = "Type"; + this.type.Items.AddRange(new object[] { + "Contains", + "Matches", + "Ends With", + "Starts With", + "RegEx"}); + this.type.MinimumWidth = 80; + this.type.Name = "type"; + this.type.Width = 80; + // + // match + // + this.match.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; + this.match.DataPropertyName = "Match"; + this.match.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.match.HeaderText = "Match"; + this.match.Items.AddRange(new object[] { + "Domain", + "URL Path", + "Full URL"}); + this.match.MinimumWidth = 80; + this.match.Name = "match"; + this.match.Width = 80; + // // pattern // this.pattern.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; @@ -203,18 +281,19 @@ private void InitializeComponent() { // this.browser.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; this.browser.DataPropertyName = "Browser"; + this.browser.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.browser.HeaderText = "Browser"; + this.browser.MinimumWidth = 100; this.browser.Name = "browser"; - this.browser.Width = 51; // // groupBox4 // this.groupBox4.Controls.Add(this.chk_check_update); this.groupBox4.Controls.Add(this.btn_check_update); - this.groupBox4.Location = new System.Drawing.Point(12, 272); + this.groupBox4.Location = new System.Drawing.Point(12, 331); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(150, 41); - this.groupBox4.TabIndex = 5; + this.groupBox4.TabIndex = 2; this.groupBox4.TabStop = false; this.groupBox4.Text = "Update checker"; // @@ -224,7 +303,7 @@ private void InitializeComponent() { this.chk_check_update.Location = new System.Drawing.Point(12, 16); this.chk_check_update.Name = "chk_check_update"; this.chk_check_update.Size = new System.Drawing.Size(58, 17); - this.chk_check_update.TabIndex = 1; + this.chk_check_update.TabIndex = 4; this.chk_check_update.Text = "enable"; this.chk_check_update.UseVisualStyleBackColor = true; this.chk_check_update.CheckedChanged += new System.EventHandler(this.chk_check_update_CheckedChanged); @@ -234,7 +313,7 @@ private void InitializeComponent() { this.btn_check_update.Location = new System.Drawing.Point(69, 12); this.btn_check_update.Name = "btn_check_update"; this.btn_check_update.Size = new System.Drawing.Size(75, 23); - this.btn_check_update.TabIndex = 0; + this.btn_check_update.TabIndex = 5; this.btn_check_update.Text = "check now"; this.btn_check_update.UseVisualStyleBackColor = true; this.btn_check_update.Click += new System.EventHandler(this.btn_check_update_Click); @@ -244,25 +323,48 @@ private void InitializeComponent() { this.btn_refresh.Location = new System.Drawing.Point(104, 7); this.btn_refresh.Name = "btn_refresh"; this.btn_refresh.Size = new System.Drawing.Size(59, 19); - this.btn_refresh.TabIndex = 2; + this.btn_refresh.TabIndex = 0; this.btn_refresh.Text = "Refresh"; this.btn_refresh.UseVisualStyleBackColor = true; this.btn_refresh.Click += new System.EventHandler(this.btn_refresh_Click); // + // btn_up + // + this.btn_up.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btn_up.Location = new System.Drawing.Point(704, 168); + this.btn_up.Name = "btn_up"; + this.btn_up.Size = new System.Drawing.Size(48, 23); + this.btn_up.TabIndex = 4; + this.btn_up.Text = "Up"; + this.btn_up.UseVisualStyleBackColor = true; + this.btn_up.Click += new System.EventHandler(this.btn_up_Click); + // + // btn_down + // + this.btn_down.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btn_down.Location = new System.Drawing.Point(704, 200); + this.btn_down.Name = "btn_down"; + this.btn_down.Size = new System.Drawing.Size(48, 23); + this.btn_down.TabIndex = 5; + this.btn_down.Text = "Down"; + this.btn_down.UseVisualStyleBackColor = true; + this.btn_down.Click += new System.EventHandler(this.btn_down_Click); + // // frm_settings // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btn_cancel; - this.ClientSize = new System.Drawing.Size(624, 381); + this.ClientSize = new System.Drawing.Size(761, 381); + this.Controls.Add(this.btn_down); + this.Controls.Add(this.btn_up); this.Controls.Add(this.btn_refresh); this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); - this.Controls.Add(this.label2); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; - this.MinimumSize = new System.Drawing.Size(358, 414); + this.MinimumSize = new System.Drawing.Size(353, 399); this.Name = "frm_settings"; this.Text = "Settings"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frm_settings_FormClosing); @@ -270,7 +372,9 @@ private void InitializeComponent() { this.Load += new System.EventHandler(this.frm_settings_Load); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.gv_filters)).EndInit(); this.groupBox4.ResumeLayout(false); this.groupBox4.PerformLayout(); @@ -282,7 +386,6 @@ private void InitializeComponent() { private System.Windows.Forms.Button btn_setdefault; private System.Windows.Forms.Label label1; - private System.Windows.Forms.Label label2; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.CheckedListBox browser_filter; private System.Windows.Forms.GroupBox groupBox2; @@ -292,11 +395,19 @@ private void InitializeComponent() { private System.Windows.Forms.Button button1; private System.Windows.Forms.LinkLabel linkLabel1; private System.Windows.Forms.Button btn_apply; - private System.Windows.Forms.DataGridViewTextBoxColumn pattern; - private System.Windows.Forms.DataGridViewComboBoxColumn browser; private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.CheckBox chk_check_update; private System.Windows.Forms.Button btn_check_update; private System.Windows.Forms.Button btn_refresh; + private System.Windows.Forms.Button btn_expandurls; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.ComboBox cmbo_default_browser; + private System.Windows.Forms.Button btn_up; + private System.Windows.Forms.Button btn_down; + private System.Windows.Forms.DataGridViewComboBoxColumn type; + private System.Windows.Forms.DataGridViewComboBoxColumn match; + private System.Windows.Forms.DataGridViewTextBoxColumn pattern; + private System.Windows.Forms.DataGridViewComboBoxColumn browser; + private System.Windows.Forms.CheckBox chk_launch_settings; } } \ No newline at end of file diff --git a/BrowserSelect/frm_settings.cs b/BrowserSelect/frm_settings.cs index 3161c1c..1084fbf 100644 --- a/BrowserSelect/frm_settings.cs +++ b/BrowserSelect/frm_settings.cs @@ -1,12 +1,14 @@ using System; using System.Collections.Generic; +using System.Data; using System.Diagnostics; using System.Drawing; -using System.Runtime.InteropServices; +using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using BrowserSelect.Properties; using Microsoft.Win32; +using Newtonsoft.Json; namespace BrowserSelect { @@ -14,14 +16,21 @@ public partial class frm_settings : Form { public Form1 mainForm; + private DataTable rules; + + public frm_settings() + { + InitializeComponent(); + this.Icon = Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location); + } public frm_settings(Form mainForm) { this.mainForm = (Form1)mainForm; InitializeComponent(); + this.Icon = Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location); } - private List rules = new List(); private void frm_settings_Load(object sender, EventArgs e) { //check if browser select is the default browser or not @@ -38,24 +47,149 @@ private void frm_settings_Load(object sender, EventArgs e) //populate list of browsers for Rule List ComboBox var browsers = BrowserFinder.find(); - var c = ((DataGridViewComboBoxColumn)gv_filters.Columns["browser"]); + DataGridViewComboBoxColumn c = ((DataGridViewComboBoxColumn)gv_filters.Columns["browser"]); + List enabled_browsers = new List(); foreach (Browser b in browsers) { browser_filter.Items.Add(b, !Settings.Default.HideBrowsers.Contains(b.Identifier)); c.Items.Add(b.ToString()); + enabled_browsers.Add(b.ToString()); } // add browser select to the list c.Items.Add("display BrowserSelect"); + enabled_browsers.Add("display BrowserSelect"); + cmbo_default_browser.DataSource = enabled_browsers; + if (Settings.Default.DefaultBrowser == null || + Settings.Default.DefaultBrowser == "" || + !enabled_browsers.Contains(Settings.Default.DefaultBrowser)) + cmbo_default_browser.SelectedItem = "display BrowserSelect"; + else + cmbo_default_browser.SelectedItem = Settings.Default.DefaultBrowser; //populate Rules in the gridview - foreach (var rule in Settings.Default.AutoBrowser) - rules.Add(rule); - var bs = new BindingSource(); - bs.DataSource = rules; - gv_filters.DataSource = bs; + if (Settings.Default.Rules != null && Settings.Default.Rules != "") + load_rules(); + else if (Settings.Default.AutoBrowser != null) + { + load_legacy_rules(); + Settings.Default.DefaultBrowser = cmbo_default_browser.SelectedItem.ToString(); + save_rules(); + Settings.Default.Save(); + } chk_check_update.Checked = Settings.Default.check_update != "nope"; + chk_launch_settings.Checked = (Boolean)Settings.Default.LaunchToSettings; + } + + private Boolean check_rules() + { + Boolean rules_ok = true; + for (int row_num = 0; row_num < gv_filters.Rows.Count-1; ++row_num) + { + for (int col_num = 0; col_num < gv_filters.Columns.Count; ++col_num) + { + if (gv_filters[col_num, row_num].Value == null || gv_filters[col_num, row_num].Value.ToString() == "") + { + rules_ok = false; + gv_filters[col_num, row_num].Style.BackColor = Color.Tomato; + } + else + gv_filters[col_num, row_num].Style.BackColor = SystemColors.Window; + } + } + return rules_ok; + } + + /* + * Cells that are highlighted by check_rules are returned to normal when clicked. + */ + private void gv_filters_CellEnter(object sender, DataGridViewCellEventArgs e) + { + ((DataGridView)sender).CurrentCell.Style.BackColor = SystemColors.Window; + } + + /* + * Expand combobox when the cells is clicked. + * Note: Tried this on Enter but it meant cells were expanded in unwanted circumstances (e.g. on Form Load). + */ + private void gv_filters_CellClick(object sender, DataGridViewCellEventArgs e) + { + bool validClick = (e.RowIndex != -1 && e.ColumnIndex != -1); //Make sure the clicked row/column is valid. + var dgv = sender as DataGridView; + + // Check to make sure the cell clicked is the cell containing the combobox + if (e.ColumnIndex > 0 && dgv.Columns[e.ColumnIndex] is DataGridViewComboBoxColumn && validClick) + { + dgv.BeginEdit(true); + ((ComboBox)dgv.EditingControl).DroppedDown = true; + } + } + + private void save_rules() + { + Settings.Default.Rules = JsonConvert.SerializeObject(rules); + } + + private void load_rules() + { + rules = (DataTable)JsonConvert.DeserializeObject(Settings.Default.Rules, (typeof(DataTable))); + gv_filters.DataSource = rules; + } + + private void load_legacy_rules() + { + rules = new DataTable(); + for (int i = 0; i < gv_filters.Columns.Count; ++i) + { + rules.Columns.Add(new DataColumn(gv_filters.Columns[i].DataPropertyName)); + } + gv_filters.AutoGenerateColumns = false; + foreach (string rule in Settings.Default.AutoBrowser) + { + string[] ss = rule.Split(new[] { "[#!][$~][?_]" }, StringSplitOptions.None); + string pattern = ss[0]; + string browser = ss[1]; + string comp_type; + if (pattern == "*") + cmbo_default_browser.SelectedItem = browser; + else + { + int count = 0; + foreach (var c in pattern.ToCharArray()) + if (c == '*') + count++; + + //replace "*." at start of string with "*" to align with legacy code + if (pattern.StartsWith("*.")) + pattern = "*" + pattern.Substring(2, pattern.Length - 2); + + if (!pattern.Contains("*")) + comp_type = "Matches"; + else if (pattern.StartsWith("*") && count == 1) + { + comp_type = "Ends With"; + pattern = pattern.Substring(1, pattern.Length - 1); + } + else if (pattern.EndsWith("*") && count == 1) + { + comp_type = "Starts With"; + pattern = pattern.Substring(0, pattern.Length - 1); + } + else if (pattern.StartsWith("*") && pattern.EndsWith("*") && count == 2) + { + comp_type = "Contains"; + pattern = pattern.Substring(1, pattern.Length - 2); + } + else + { + comp_type = "RegEx"; + pattern = pattern.Replace(@".", @"\.").Replace(@"*", @".*"); + } + rules.Rows.Add(comp_type, "Domain", pattern, browser); + } + } + gv_filters.DataSource = rules; } private void btn_setdefault_Click(object sender, EventArgs e) @@ -112,32 +246,15 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs private void btn_apply_Click(object sender, EventArgs e) { - //save rules - - //clear rules (instead of checking for changes we just overwrite the whole ruleset) - Settings.Default.AutoBrowser.Clear(); - foreach (var rule in rules) + if (check_rules()) { - //check if rule has both pattern and browser defined - if (rule.valid()) - //add it to rule list - Settings.Default.AutoBrowser.Add(rule.ToString()); - else - { - //ignore rule if both pattern and browser is empty otherwise inform user of missing part - var err = rule.error(); - if (err.Length > 0) - { - MessageBox.Show("Invalid Rule: " + err); - } - } - + save_rules(); + Settings.Default.DefaultBrowser = cmbo_default_browser.SelectedItem.ToString(); + Settings.Default.Save(); + //Enabled property of apply button is used as a flag for unsaved changes + btn_apply.Enabled = false; + btn_cancel.Text = "Close"; } - //save rules - Settings.Default.Save(); - //Enabled property of apply button is used as a flag for unsaved changes - btn_apply.Enabled = false; - btn_cancel.Text = "Close"; } private frm_help_rules _frmHelp; @@ -202,10 +319,13 @@ private void btn_check_update_Click(object sender, EventArgs e) btn.UseVisualStyleBackColor = true; btn.Enabled = true; } - catch (Exception) { } + catch (Exception ex) { + Debug.WriteLine(ex); + } return x; }, TaskScheduler.FromCurrentSynchronizationContext()); } + private void chk_check_update_CheckedChanged(object sender, EventArgs e) { Settings.Default.check_update = (((CheckBox)sender).Checked) ? "0" : "nope"; @@ -226,55 +346,88 @@ private void btn_refresh_Click(object sender, EventArgs e) // add browser select to the list c.Items.Add("display BrowserSelect"); - this.mainForm.updateBrowsers(); + if (mainForm != null) + this.mainForm.updateBrowsers(); + else + browsers = BrowserFinder.find().Where(b => !Settings.Default.HideBrowsers.Contains(b.Identifier)).ToList(); } private void gv_filters_DataError(object sender, DataGridViewDataErrorEventArgs e) { // to prevent System.ArgumentException: DataGridViewComboBoxCell value is not valid MessageBoxes } - } - class AutoMatchRule - { - public string Pattern { get; set; } - public string Browser { get; set; } - - public static implicit operator AutoMatchRule(System.String s) - { - var ss = s.Split(new[] { "[#!][$~][?_]" }, StringSplitOptions.None); - return new AutoMatchRule() - { - Pattern = ss[0], - Browser = ss[1] - }; - } - public override string ToString() + private void btn_expandurls_Click(object sender, EventArgs e) { - return Pattern + "[#!][$~][?_]" + Browser; + (new frm_settings_urlexpander()).ShowDialog(); } - public string error() + private void btn_up_Click(object sender, EventArgs e) { - if (!string.IsNullOrEmpty(Pattern)) - return string.Format("You forgot to select a Browser for '{0}' rule.", Pattern); - else if (!string.IsNullOrEmpty(Browser)) - return "one of your rules has an Empty pattern. please refer to Help for more information."; - else - return ""; + DataGridView dgv = gv_filters; + try + { + int totalRows = dgv.Rows.Count; + // get index of the row for the selected cell + int rowIndex = dgv.SelectedCells[0].OwningRow.Index; + if (rowIndex == 0) + return; + // get index of the column for the selected cell + int colIndex = dgv.SelectedCells[0].OwningColumn.Index; + DataRow selectedRow = rules.Rows[rowIndex]; + DataRow row = rules.NewRow(); + for (int i = 0; i < gv_filters.Columns.Count; ++i) + row[i] = selectedRow[i]; + rules.Rows.Remove(selectedRow); + rules.Rows.InsertAt(row, rowIndex - 1); + dgv.ClearSelection(); + dgv.Rows[rowIndex - 1].Cells[colIndex].Selected = true; + dgv.CurrentCell = dgv[colIndex, rowIndex - 1]; + //set the unsaved changes flag to true + btn_apply.Enabled = true; + btn_cancel.Text = "Cancel"; + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } } - public bool valid() + private void btn_down_Click(object sender, EventArgs e) { - try //because they may be null + DataGridView dgv = gv_filters; + try { - return Browser.Length > 0 && Pattern.Length > 0; + int totalRows = dgv.Rows.Count; + // get index of the row for the selected cell + int rowIndex = dgv.SelectedCells[0].OwningRow.Index; + if (rowIndex == totalRows - 1) + return; + // get index of the column for the selected cell + int colIndex = dgv.SelectedCells[0].OwningColumn.Index; + DataRow selectedRow = rules.Rows[rowIndex]; + DataRow row = rules.NewRow(); + for (int i = 0; i < gv_filters.Columns.Count; ++i) + row[i] = selectedRow[i]; + rules.Rows.Remove(selectedRow); + rules.Rows.InsertAt(row, rowIndex + 1); + dgv.ClearSelection(); + dgv.Rows[rowIndex + 1].Cells[colIndex].Selected = true; + dgv.CurrentCell = dgv[colIndex, rowIndex + 1]; + //set the unsaved changes flag to true + btn_apply.Enabled = true; + btn_cancel.Text = "Cancel"; } - catch + catch (Exception ex) { - return false; + Debug.WriteLine(ex); } + } + private void chk_launch_settings_CheckedChanged(object sender, EventArgs e) + { + Settings.Default.LaunchToSettings = ((CheckBox)sender).Checked; + Settings.Default.Save(); } } } diff --git a/BrowserSelect/frm_settings.resx b/BrowserSelect/frm_settings.resx index c6db7be..df781b5 100644 --- a/BrowserSelect/frm_settings.resx +++ b/BrowserSelect/frm_settings.resx @@ -118,9 +118,15 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - Using this section you can add rules that based on them browser select will automatically choose a browser instead of displaying the list for you to choose manually. more information and examples can be found on the project's github. + Using this section you can add rules to enable BrowserSelect to automatically choose a browser instead of displaying the browser list. More information and examples on filters, plus feature requests, bug reports or suggestions can be found on the project's github. + + True + + + True + True diff --git a/BrowserSelect/frm_settings_urlexpander.Designer.cs b/BrowserSelect/frm_settings_urlexpander.Designer.cs new file mode 100644 index 0000000..61dcbfb --- /dev/null +++ b/BrowserSelect/frm_settings_urlexpander.Designer.cs @@ -0,0 +1,181 @@ + +namespace BrowserSelect +{ + partial class frm_settings_urlexpander + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.gv_url_shortners = new System.Windows.Forms.DataGridView(); + this.Domain = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.btn_cancel = new System.Windows.Forms.Button(); + this.btn_ok = new System.Windows.Forms.Button(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.chk_box_url_expanders = new System.Windows.Forms.CheckedListBox(); + this.cmbo_expand_url = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.gv_url_shortners)).BeginInit(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.SuspendLayout(); + // + // gv_url_shortners + // + this.gv_url_shortners.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.gv_url_shortners.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.gv_url_shortners.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Domain}); + this.gv_url_shortners.Location = new System.Drawing.Point(6, 19); + this.gv_url_shortners.Name = "gv_url_shortners"; + this.gv_url_shortners.RowHeadersWidth = 30; + this.gv_url_shortners.Size = new System.Drawing.Size(366, 177); + this.gv_url_shortners.TabIndex = 0; + this.gv_url_shortners.EnabledChanged += new System.EventHandler(this.DataGridView_EnabledChanged); + // + // Domain + // + this.Domain.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Domain.DataPropertyName = "Domain"; + this.Domain.HeaderText = "Domain"; + this.Domain.MinimumWidth = 10; + this.Domain.Name = "Domain"; + // + // btn_cancel + // + this.btn_cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btn_cancel.Location = new System.Drawing.Point(313, 285); + this.btn_cancel.Name = "btn_cancel"; + this.btn_cancel.Size = new System.Drawing.Size(75, 23); + this.btn_cancel.TabIndex = 3; + this.btn_cancel.Text = "Cancel"; + this.btn_cancel.UseVisualStyleBackColor = true; + this.btn_cancel.Click += new System.EventHandler(this.btn_cancel_Click); + // + // btn_ok + // + this.btn_ok.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btn_ok.Location = new System.Drawing.Point(232, 285); + this.btn_ok.Name = "btn_ok"; + this.btn_ok.Size = new System.Drawing.Size(75, 23); + this.btn_ok.TabIndex = 2; + this.btn_ok.Text = "&OK"; + this.btn_ok.UseVisualStyleBackColor = true; + this.btn_ok.Click += new System.EventHandler(this.btn_ok_Click); + // + // groupBox1 + // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.gv_url_shortners); + this.groupBox1.Location = new System.Drawing.Point(10, 10); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(378, 202); + this.groupBox1.TabIndex = 3; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "URL Shortners"; + // + // groupBox2 + // + this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox2.Controls.Add(this.chk_box_url_expanders); + this.groupBox2.Location = new System.Drawing.Point(10, 215); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(378, 64); + this.groupBox2.TabIndex = 4; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Custom URL Processors"; + // + // chk_box_url_expanders + // + this.chk_box_url_expanders.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.chk_box_url_expanders.CheckOnClick = true; + this.chk_box_url_expanders.FormattingEnabled = true; + this.chk_box_url_expanders.Location = new System.Drawing.Point(6, 18); + this.chk_box_url_expanders.Name = "chk_box_url_expanders"; + this.chk_box_url_expanders.Size = new System.Drawing.Size(366, 34); + this.chk_box_url_expanders.TabIndex = 1; + // + // cmbo_expand_url + // + this.cmbo_expand_url.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.cmbo_expand_url.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cmbo_expand_url.FormattingEnabled = true; + this.cmbo_expand_url.Location = new System.Drawing.Point(92, 286); + this.cmbo_expand_url.Name = "cmbo_expand_url"; + this.cmbo_expand_url.Size = new System.Drawing.Size(130, 21); + this.cmbo_expand_url.TabIndex = 5; + this.cmbo_expand_url.SelectedIndexChanged += new System.EventHandler(this.cmbo_expand_url_SelectedIndexChanged); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(7, 290); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(85, 13); + this.label1.TabIndex = 6; + this.label1.Text = "Expander URLs:"; + // + // frm_settings_urlexpander + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(400, 314); + this.Controls.Add(this.label1); + this.Controls.Add(this.cmbo_expand_url); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.btn_cancel); + this.Controls.Add(this.btn_ok); + this.Controls.Add(this.groupBox1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; + this.Margin = new System.Windows.Forms.Padding(2); + this.Name = "frm_settings_urlexpander"; + this.Text = "URL Expander Config"; + this.Load += new System.EventHandler(this.frm_settings_urlexpander_Load); + ((System.ComponentModel.ISupportInitialize)(this.gv_url_shortners)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.groupBox2.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.DataGridView gv_url_shortners; + private System.Windows.Forms.DataGridViewTextBoxColumn Domain; + private System.Windows.Forms.Button btn_cancel; + private System.Windows.Forms.Button btn_ok; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.CheckedListBox chk_box_url_expanders; + private System.Windows.Forms.ComboBox cmbo_expand_url; + private System.Windows.Forms.Label label1; + } +} \ No newline at end of file diff --git a/BrowserSelect/frm_settings_urlexpander.cs b/BrowserSelect/frm_settings_urlexpander.cs new file mode 100644 index 0000000..6385a9b --- /dev/null +++ b/BrowserSelect/frm_settings_urlexpander.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BrowserSelect +{ + public partial class frm_settings_urlexpander : Form + { + public frm_settings_urlexpander() + { + InitializeComponent(); + } + + private void frm_settings_urlexpander_Load(object sender, EventArgs e) + { + cmbo_expand_url.DataSource = (new string[] { "Never", "URL shortners", "Follow all redirects" }); + if (Properties.Settings.Default.ExpandUrl == null || Properties.Settings.Default.ExpandUrl == "") + cmbo_expand_url.SelectedItem = "Never"; + else + cmbo_expand_url.SelectedItem = Properties.Settings.Default.ExpandUrl; + gv_url_shortners.Enabled = ((string)cmbo_expand_url.SelectedItem == "URL shortners"); + + if (Properties.Settings.Default.URLShortners != null) + { + foreach (String url in Properties.Settings.Default.URLShortners) + gv_url_shortners.Rows.Add(url); + } + chk_box_url_expanders.DataSource = Program.defaultUriExpander.Select(ele => ele.name).ToList(); + for (int i = 0; i < chk_box_url_expanders.Items.Count; i++) + { + StringCollection url_processors; + if (Properties.Settings.Default.URLProcessors == null) + url_processors = new StringCollection(); + else + url_processors = Properties.Settings.Default.URLProcessors; + chk_box_url_expanders.SetItemChecked(i, url_processors.Contains(chk_box_url_expanders.Items[i].ToString())); + } + } + + private void btn_ok_Click(object sender, EventArgs e) + { + if (Properties.Settings.Default.URLShortners != null) + Properties.Settings.Default.URLShortners.Clear(); + StringCollection url_shortners = new StringCollection(); + foreach (DataGridViewRow row in gv_url_shortners.Rows) + { + if (row.Cells[0].Value != null) + url_shortners.Add(row.Cells[0].Value.ToString()); + } + Properties.Settings.Default.URLShortners = url_shortners; + Properties.Settings.Default.ExpandUrl = (string)((ComboBox)cmbo_expand_url).SelectedItem; + StringCollection url_processors = new StringCollection(); + for (int i = 0; i < chk_box_url_expanders.Items.Count; i++) + { + if (chk_box_url_expanders.GetItemChecked(i)) + url_processors.Add(chk_box_url_expanders.Items[i].ToString()); + } + Properties.Settings.Default.URLProcessors = url_processors; + Properties.Settings.Default.Save(); + Close(); + } + + private void btn_cancel_Click(object sender, EventArgs e) + { + Close(); + } + + private void cmbo_expand_url_SelectedIndexChanged(object sender, EventArgs e) + { + gv_url_shortners.Enabled = ((string)cmbo_expand_url.SelectedItem == "URL shortners"); + } + + private void DataGridView_EnabledChanged(object sender, EventArgs e) + { + DataGridView dgv = sender as DataGridView; + if (!dgv.Enabled) + { + dgv.DefaultCellStyle.BackColor = SystemColors.Control; + dgv.DefaultCellStyle.ForeColor = SystemColors.GrayText; + dgv.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.Control; + dgv.ColumnHeadersDefaultCellStyle.ForeColor = SystemColors.GrayText; + dgv.CurrentCell = null; + dgv.ReadOnly = true; + dgv.EnableHeadersVisualStyles = false; + } + else + { + dgv.DefaultCellStyle.BackColor = SystemColors.Window; + dgv.DefaultCellStyle.ForeColor = SystemColors.ControlText; + dgv.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.Window; + dgv.ColumnHeadersDefaultCellStyle.ForeColor = SystemColors.ControlText; + dgv.ReadOnly = false; + dgv.EnableHeadersVisualStyles = true; + } + } + } +} diff --git a/BrowserSelect/frm_settings_urlexpander.resx b/BrowserSelect/frm_settings_urlexpander.resx new file mode 100644 index 0000000..c67944b --- /dev/null +++ b/BrowserSelect/frm_settings_urlexpander.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + \ No newline at end of file diff --git a/BrowserSelect/packages.config b/BrowserSelect/packages.config index 1df47c7..b25a761 100644 --- a/BrowserSelect/packages.config +++ b/BrowserSelect/packages.config @@ -1,5 +1,6 @@  - - + + + \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index d60c8e5..b31e1e6 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -8,7 +8,7 @@ Properties Tests Tests - v4.0 + v4.7.2 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 10.0 @@ -16,6 +16,7 @@ $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages False UnitTest + true @@ -25,6 +26,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -33,12 +35,14 @@ TRACE prompt 4 + false 3.5 +