static void Main(string[] args) { // to prevent loss of settings when on update if (Settings.Default.UpdateSettings) { Settings.Default.Upgrade(); Settings.Default.UpdateSettings = false; Settings.Default.last_version = "nope"; // to prevent nullreference in case settings file did not exist if (Settings.Default.HideBrowsers == null) Settings.Default.HideBrowsers = new StringCollection(); if (Settings.Default.AutoBrowser == null) Settings.Default.AutoBrowser = new StringCollection(); Settings.Default.Save(); } // check for update if (Settings.Default.check_update != "nope" && DateTime.Now.Subtract(time(Settings.Default.check_update)).TotalDays > 7) { var uc = new UpdateChecker(); Task.Factory.StartNew(() => uc.check()); } //checking if a url is being opened or app is ran from start menu (without arguments) if (args.Length > 0) { //check to see if auto select rules match url = args[0]; //add http:// to url if it is missing a protocol var uri = new UriBuilder(url).Uri; url = uri.ToString(); foreach (var sr in Settings.Default.AutoBrowser.Cast<string>() // 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))) { var pattern = sr[0]; var browser = sr[1]; // matching the domain to pattern if (DoesDomainMatchPattern(uri.Host, pattern)) { // ignore the display browser select entry to prevent app running itself 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; } } } } // display main form Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }
private void btn_check_update_Click(object sender, EventArgs e) { var btn = ((Button)sender); var uc = new UpdateChecker(); // color the button to indicate request, disable it to prevent multiple instances btn.BackColor = Color.Blue; btn.Enabled = false; // run inside a Task to prevent freezing the UI Task.Factory.StartNew(() => uc.check()).ContinueWith(x => { try { if (uc.Checked) { if (uc.Updated) MessageBox.Show(String.Format( "New Update Available!\nCurrent Version: {1}\nLast Version: {0}" + "\nto Update download and install the new version from project's github.", uc.LVer, uc.CVer)); else MessageBox.Show("You are running the lastest version."); } else MessageBox.Show("Unable to check for updates.\nPlease make sure you are connected to internet."); btn.UseVisualStyleBackColor = true; btn.Enabled = true; } catch (Exception) { } return x; }, TaskScheduler.FromCurrentSynchronizationContext()); }
static void Main(string[] args) { System.Diagnostics.Debug.WriteLine("Test"); // fix #28 LeaveDotsAndSlashesEscaped(); // to prevent loss of settings when on update if (Settings.Default.UpdateSettings) { Settings.Default.Upgrade(); Settings.Default.UpdateSettings = false; Settings.Default.last_version = "nope"; // to prevent nullreference in case settings file did not exist if (Settings.Default.HideBrowsers == null) { Settings.Default.HideBrowsers = new StringCollection(); } if (Settings.Default.AutoBrowser == null) { Settings.Default.AutoBrowser = new StringCollection(); } Settings.Default.Save(); } // check for update if (Settings.Default.check_update != "nope" && DateTime.Now.Subtract(time(Settings.Default.check_update)).TotalDays > 7) { var uc = new UpdateChecker(); Task.Factory.StartNew(() => uc.check()); } //checking if a url is being opened or app is ran from start menu (without arguments) if (args.Length > 0) { //check to see if auto select rules match url = args[0]; //add http:// to url if it is missing a protocol var uri = new UriBuilder(url).Uri; url = uri.AbsoluteUri; foreach (var sr in Settings.Default.AutoBrowser.Cast <string>() // 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))) { var pattern = sr[0]; var browser = sr[1]; // matching the domain to pattern if (DoesDomainMatchPattern(uri.Host, pattern)) { // ignore the display browser select entry to prevent app running itself 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; } } } } // display main form Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }