Beispiel #1
0
        private void Main_Load(object sender, EventArgs e)
        {
            // Enable web helper
            if (File.Exists(spotifyPrefsPath))
            {
                String[] lines = File.ReadAllLines(spotifyPrefsPath);
                for (int i = 0; i < lines.Length; i++)
                {
                    if (lines[i].Contains("webhelper.enabled") && lines[i].Contains("false"))
                    {
                        lines[i] = "webhelper.enabled=true";
                        File.WriteAllLines(spotifyPrefsPath, lines);
                        break;
                    }
                }
            }

            CheckUpdate();

            // Start Spotify and give EZBlocker higher priority
            try
            {
                if (File.Exists(spotifyPath) && GetHandle() == IntPtr.Zero)
                {
                    Process.Start(spotifyPath);
                }
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; // Windows throttles down when minimized to task tray, so make sure EZBlocker runs smoothly
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            // Extract dependencies
            try {
                if (!File.Exists(nircmdPath))
                {
                    File.WriteAllBytes(nircmdPath, Properties.Resources.nircmd32);
                }
                if (!File.Exists(jsonPath))
                {
                    File.WriteAllBytes(jsonPath, Properties.Resources.Newtonsoft_Json);
                }
                if (!File.Exists(coreaudioPath))
                {
                    File.WriteAllBytes(coreaudioPath, Properties.Resources.CoreAudio);
                }
            } catch (Exception ex)
            {
                Debug.WriteLine(ex);
                MessageBox.Show("Error loading EZBlocker dependencies. Please run EZBlocker as administrator or put EZBlocker in a user folder.");
            }

            // Set up UI
            SpotifyMuteCheckbox.Checked = Properties.Settings.Default.SpotifyMute;
            if (File.Exists(hostsPath))
            {
                string hostsFile = File.ReadAllText(hostsPath);
                BlockBannersCheckbox.Checked = adHosts.All(host => hostsFile.Contains("0.0.0.0 " + host));
            }

            // Google Analytics
            rnd       = new Random(Environment.TickCount);
            starttime = DateTime.Now.Ticks;
            if (String.IsNullOrEmpty(Properties.Settings.Default.UID))
            {
                Properties.Settings.Default.UID = rnd.Next(100000000, 999999999).ToString(); // Build unique visitorId;
                Properties.Settings.Default.Save();
            }
            visitorId = Properties.Settings.Default.UID;

            File.AppendAllText(logPath, "-----------\r\n");
            bool unsafeHeaders = WebHelperHook.SetAllowUnsafeHeaderParsing20();

            Debug.WriteLine("Unsafe Headers: " + unsafeHeaders);

            if (!hasNet45())
            {
                if (MessageBox.Show("You do not have .NET Framework 4.5. Download now?", "EZBlocker Error", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                {
                    Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=30653");
                }
                else
                {
                    MessageBox.Show("EZBlocker may not function properly without .NET Framework 4.5 or above.");
                }
            }

            Mute(0);

            MainTimer.Enabled = true;

            LogAction("/launch");
        }
Beispiel #2
0
        private void Main_Load(object sender, EventArgs e)
        {
            // Enable web helper
            if (File.Exists(spotifyPrefsPath))
            {
                String[] lines = File.ReadAllLines(spotifyPrefsPath);
                for (int i = 0; i < lines.Length; i++)
                {
                    if (lines[i].Contains("webhelper.enabled") && lines[i].Contains("false"))
                    {
                        lines[i] = "webhelper.enabled=true";
                        File.WriteAllLines(spotifyPrefsPath, lines);
                        break;
                    }
                }
            }

            CheckUpdate();

            // Start Spotify and give EZBlocker higher priority
            try
            {
                if (File.Exists(spotifyPath) && Process.GetProcessesByName("spotify").Length < 1)
                {
                    Process.Start(spotifyPath);
                }
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; // Windows throttles down when minimized to task tray, so make sure EZBlocker runs smoothly

                // Check for open.spotify.com in hosts
                String hostsContent = File.ReadAllText(hostsPath);
                if (hostsContent.Contains("open.spotify.com"))
                {
                    if (IsUserAnAdmin())
                    {
                        File.WriteAllText(hostsPath, hostsContent.Replace("open.spotify.com", "localhost"));
                        MessageBox.Show("An EZBlocker patch has been applied to your hosts file. If EZBlocker is stuck at 'Loading', please restart your computer.", "EZBlocker", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("EZBlocker has detected an error in your hosts file.\r\n\r\nPlease re-run EZBlocker as Administrator or remove 'open.spotify.com' from your hosts file.", "EZBlocker", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Application.Exit();
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            // Extract dependencies
            try {
                if (!File.Exists(nircmdPath))
                {
                    File.WriteAllBytes(nircmdPath, Properties.Resources.nircmd32);
                }
                if (!File.Exists(jsonPath))
                {
                    File.WriteAllBytes(jsonPath, Properties.Resources.Newtonsoft_Json);
                }
                if (!File.Exists(coreaudioPath))
                {
                    File.WriteAllBytes(coreaudioPath, Properties.Resources.CoreAudio);
                }
            } catch (Exception ex)
            {
                Debug.WriteLine(ex);
                MessageBox.Show("Error loading EZBlocker dependencies. Please run EZBlocker as administrator or put EZBlocker in a user folder.");
            }

            // Set up UI
            SpotifyMuteCheckbox.Checked = Properties.Settings.Default.SpotifyMute;
            if (File.Exists(hostsPath))
            {
                string hostsFile = File.ReadAllText(hostsPath);
                BlockBannersCheckbox.Checked = adHosts.All(host => hostsFile.Contains("0.0.0.0 " + host));
            }
            RegistryKey startupKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

            if (startupKey.GetValue("EZBlocker") != null)
            {
                if (startupKey.GetValue("EZBlocker").ToString() == "\"" + Application.ExecutablePath + "\"")
                {
                    StartupCheckbox.Checked = true;
                    this.WindowState        = FormWindowState.Minimized;
                }
                else // Reg value exists, but not in right path
                {
                    startupKey.DeleteValue("EZBlocker");
                }
            }

            // Google Analytics
            rnd       = new Random(Environment.TickCount);
            starttime = DateTime.Now.Ticks;
            if (String.IsNullOrEmpty(Properties.Settings.Default.UID))
            {
                Properties.Settings.Default.UID = rnd.Next(100000000, 999999999).ToString(); // Build unique visitorId;
                Properties.Settings.Default.Save();
            }
            visitorId = Properties.Settings.Default.UID;

            File.AppendAllText(logPath, "-----------\r\n");
            bool unsafeHeaders = WebHelperHook.SetAllowUnsafeHeaderParsing20();

            Debug.WriteLine("Unsafe Headers: " + unsafeHeaders);

            if (!hasNet45())
            {
                if (MessageBox.Show("You do not have .NET Framework 4.5. Download now?", "EZBlocker Error", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                {
                    Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=30653");
                }
                else
                {
                    MessageBox.Show("EZBlocker may not function properly without .NET Framework 4.5 or above.");
                }
            }

            Mute(0);

            MainTimer.Enabled = true;

            LogAction("/launch");
        }
Beispiel #3
0
        private void Main_Load(object sender, EventArgs e)
        {
            LogAction("/launch");

            CheckUpdate();

            // Enable web helper
            if (File.Exists(spotifyPrefsPath))
            {
                String[] lines = File.ReadAllLines(spotifyPrefsPath);
                for (int i = 0; i < lines.Length; i++)
                {
                    if (lines[i].Contains("webhelper.enabled") && lines[i].Contains("false"))
                    {
                        lines[i] = "webhelper.enabled=true";
                        File.WriteAllLines(spotifyPrefsPath, lines);
                        break;
                    }
                }
            }

            // Start Spotify and give EZBlocker higher priority
            try
            {
                if (File.Exists(spotifyPath))
                {
                    Process.Start(spotifyPath);
                }
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High; // Windows throttles down when minimized to task tray, so make sure EZBlocker runs smoothly
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }

            // Extract dependencies
            try {
                if (!File.Exists(nircmdPath))
                {
                    File.WriteAllBytes(nircmdPath, Properties.Resources.nircmd32);
                }
                if (!File.Exists(jsonPath))
                {
                    File.WriteAllBytes(jsonPath, Properties.Resources.Newtonsoft_Json);
                }
                if (!File.Exists(coreaudioPath))
                {
                    File.WriteAllBytes(coreaudioPath, Properties.Resources.CoreAudio);
                }
            } catch (Exception ex)
            {
                Debug.WriteLine(ex);
                MessageBox.Show("Error loading EZBlocker dependencies. Please run EZBlocker as administrator or put EZBlocker in a user folder.");
            }
            // Set up UI
            SpotifyMuteCheckbox.Checked = Properties.Settings.Default.SpotifyMute;
            if (File.Exists(hostsPath))
            {
                BlockBannersCheckbox.Checked = File.ReadAllText(hostsPath).Contains("doubleclick.net");
            }

            // Google Analytics
            rnd       = new Random(Environment.TickCount);
            starttime = DateTime.Now.Ticks;
            if (String.IsNullOrEmpty(Properties.Settings.Default.UID))
            {
                Properties.Settings.Default.UID = rnd.Next(100000000, 999999999).ToString(); // Build unique visitorId;
                Properties.Settings.Default.Save();
            }
            visitorId = Properties.Settings.Default.UID;

            File.AppendAllText(logPath, "-----------\r\n");
            bool unsafeHeaders = WebHelperHook.SetAllowUnsafeHeaderParsing20();

            Debug.WriteLine("Unsafe Headers: " + unsafeHeaders);

            Mute(0);

            MainTimer.Enabled = true;
        }